playlist.cpp
来自「VLC媒体播放程序」· C++ 代码 · 共 578 行 · 第 1/2 页
CPP
578 行
/***************************************************************************** * playlist.cpp: Playlist control ***************************************************************************** * Copyright (C) 2003 VideoLAN * $Id: playlist.cpp,v 1.15 2003/06/23 20:35:36 asmax Exp $ * * Authors: Olivier Teuli鑢e <ipkiss@via.ecp.fr> * Emmanuel Puig <karibu@via.ecp.fr> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, * USA. *****************************************************************************///--- GENERAL ---------------------------------------------------------------#include <math.h>//--- VLC -------------------------------------------------------------------#include <vlc/intf.h>//--- SKIN ------------------------------------------------------------------#include "../os_api.h"#include "../src/bitmap.h"#include "../src/banks.h"#include "../src/bezier.h"#include "../src/graphics.h"#include "../os_graphics.h"#include "../src/font.h"#include "../os_font.h"#include "generic.h"#include "slider.h"#include "playlist.h"#include "../src/event.h"#include "../src/theme.h"#include "../src/window.h"#include "../src/skin_common.h"//---------------------------------------------------------------------------// Control Playlist//---------------------------------------------------------------------------ControlPlayList::ControlPlayList( string id, bool visible, int width, int infowidth, string font, string playfont, int selcolor, double *ptx, double *pty, int nb, bool longfilename, string help, SkinWindow *Parent ) : GenericControl( id, visible, help, Parent ){ Left = 0; Top = 0; Column = 1; Line = 1; Margin = 1; Enabled = true; FontName = font; PlayFontName = playfont; // Text zone CaseWidth = width; InfoWidth = infowidth; NumWidth = 0; FileWidth = 0; CaseHeight = 1; NumOfItems = 0; SelectColor = selcolor; TextCurve = new Bezier( ptx, pty, nb, BEZIER_PTS_Y ); LongFileName = longfilename; // Scroll StartIndex = 0;}//---------------------------------------------------------------------------ControlPlayList::~ControlPlayList(){ if( CaseLeft ) { delete[] CaseLeft; } if( CaseRight ) { delete[] CaseRight; } if( CaseTextLeft ) { delete[] CaseTextLeft; } if( Slider ) { delete Slider; } if( TextClipRgn ) { delete TextClipRgn; } if( PlayList != NULL ) { vlc_object_release( PlayList ); }}//---------------------------------------------------------------------------void ControlPlayList::Init(){ int i, j, h; int *x, *y; // Font & events UpdateEvent = p_intf->p_sys->p_theme->EvtBank->Get( "playlist_refresh" ); TextFont = p_intf->p_sys->p_theme->FntBank->Get( FontName ); if( PlayFontName == "none" ) PlayFont = p_intf->p_sys->p_theme->FntBank->Get( FontName ); else PlayFont = p_intf->p_sys->p_theme->FntBank->Get( PlayFontName ); TextFont->GetSize( "lp", h, CaseHeight ); // Get bitmap from list Img = NULL; // Get points for Text curve h = TextCurve->GetNumOfDifferentPoints(); x = new int[h + 1]; y = new int[h + 1]; TextCurve->GetDifferentPoints( x, y, 0, 0 ); // Get top of first point TextCurve->GetPoint( 0, i, TextTop ); // Set number of lines Line = 0; for( i = 0; i < h; i++ ) { if( ( Line + 1 ) * CaseHeight < y[i] - TextTop ) Line++; } CaseLeft = new int[Line]; CaseRight = new int[Line]; CaseTextLeft = new int[Line]; for( i = 0; i < Line; i++ ) { CaseLeft[i] = x[i * CaseHeight]; CaseTextLeft[i] = x[i * CaseHeight]; for( j = 1; j < CaseHeight; j++ ) { if( x[i * CaseHeight + j] < CaseLeft[i] ) CaseLeft[i] = x[i * CaseHeight + j]; if( x[i * CaseHeight + j] > CaseTextLeft[i] ) CaseTextLeft[i] = x[i * CaseHeight + j]; } CaseRight[i] = CaseTextLeft[i] + CaseWidth; } // Get size of text zone TextHeight = Line * CaseHeight; TextLeft = CaseLeft[0]; TextWidth = CaseRight[0]; for( i = 1; i < Line; i++ ) { if( CaseLeft[i] < TextLeft ) TextLeft = CaseLeft[i]; if( CaseRight[i] > TextWidth ) TextWidth = CaseRight[i]; } TextWidth -= TextLeft; // Set Text Clipping Region TextClipRgn = (SkinRegion *)new OSRegion; for( i = 0; i < Line; i++ ) { for( j = 0; j < CaseHeight; j++ ) { h = i * CaseHeight + j; TextClipRgn->AddRectangle( x[h] - TextLeft, h, CaseWidth, 1 ); } } // Curve is no more needed so delete it delete TextCurve; delete[] x; delete[] y; // Get size of control Left = Slider->GetLeft(); Top = Slider->GetTop(); Width = Slider->GetLeft() + Slider->GetWidth(); Height = Slider->GetTop() + Slider->GetHeight(); if( TextLeft < Left ) Left = TextLeft; if( TextTop < Top ) Top = TextTop; if( TextLeft + TextWidth > Width ) Width = TextLeft + TextWidth; if( TextTop + TextHeight > Height ) Height = TextTop + TextHeight; Width -= Left; Height -= Top; // Getting playlist PlayList = (playlist_t *) vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE ); if( PlayList == NULL ) msg_Err( p_intf, "cannot find a playlist object" ); Slider->Init(); Slider->Enable( p_intf->p_sys->p_theme->EvtBank->Get( "none" ), true ); RefreshList();}//---------------------------------------------------------------------------bool ControlPlayList::ProcessEvent( Event *evt ){ switch( evt->GetMessage() ) { case CTRL_ENABLED: Enable( (Event*)evt->GetParam1(), (bool)evt->GetParam2() ); break; case CTRL_SYNCHRO: if( UpdateEvent->IsEqual( (Event*)evt->GetParam1() ) ) { RefreshList(); RefreshAll(); } break; case PLAYLIST_ID_DEL: if( (GenericControl *)evt->GetParam1() == this ) { for( int i = PlayList->i_size - 1; i >= 0; i-- ) { if( Select[i] && i != PlayList->i_index ) playlist_Delete( PlayList, i ); } RefreshList(); RefreshAll(); } break; } return false;}//---------------------------------------------------------------------------void ControlPlayList::RefreshList(){ vlc_mutex_lock( &PlayList->object_lock ); if( NumOfItems != PlayList->i_size ) { if( NumOfItems > 0 ) delete[] Select; NumOfItems = PlayList->i_size; if( PlayList->i_size > 0 ) { Select = new bool[NumOfItems]; for( int i = 0; i < NumOfItems; i++ ) Select[i] = false; int h; sprintf( Num, " %i", NumOfItems + 1 ); TextFont->GetSize( Num, NumWidth, h); FileWidth = CaseWidth - NumWidth - InfoWidth; } int Range = PlayList->i_size - Line * Column; if( Range < 0 ) Range = 0; Slider->ChangeSliderRange( Range ); StartIndex = Slider->GetCursorPosition(); } vlc_mutex_unlock( &PlayList->object_lock );}//---------------------------------------------------------------------------void ControlPlayList::RefreshAll(){ ParentWindow->Refresh( TextLeft, TextTop, TextWidth, TextHeight );}//---------------------------------------------------------------------------void ControlPlayList::Draw( int x, int y, int w, int h, Graphics *dest ){
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?