X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=modules%2Fgui%2Fskins%2Fsrc%2Fwindow.cpp;h=4e38c35e8e4c637c6d0b183813861f6e93e8e306;hb=1decbca7433a9ef29ce97dd8803ff4acffe091e1;hp=a529d1d029f68eeef33da0d9e50ded928ad8aac2;hpb=5e0f6df763e4f25fb233ee9ec4df8518b78e1cf4;p=vlc diff --git a/modules/gui/skins/src/window.cpp b/modules/gui/skins/src/window.cpp index a529d1d029..4e38c35e8e 100644 --- a/modules/gui/skins/src/window.cpp +++ b/modules/gui/skins/src/window.cpp @@ -2,10 +2,11 @@ * window.cpp: Window class ***************************************************************************** * Copyright (C) 2003 VideoLAN - * $Id: window.cpp,v 1.14 2003/04/16 19:22:53 karibu Exp $ + * $Id: window.cpp,v 1.31 2003/06/22 00:00:28 asmax Exp $ * * Authors: Olivier Teulière * Emmanuel Puig + * Cyril Deguet * * 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 @@ -29,15 +30,16 @@ //--- SKIN ------------------------------------------------------------------ #include "anchor.h" -#include "generic.h" +#include "../controls/generic.h" #include "window.h" #include "event.h" -#include "os_api.h" +#include "../os_api.h" #include "graphics.h" -#include "os_graphics.h" +#include "../os_graphics.h" #include "banks.h" #include "theme.h" #include "skin_common.h" +#include "dialogs.h" #include @@ -45,7 +47,7 @@ //--------------------------------------------------------------------------- // Skinable Window //--------------------------------------------------------------------------- -Window::Window( intf_thread_t *_p_intf, int x, int y, bool visible, +SkinWindow::SkinWindow( intf_thread_t *_p_intf, int x, int y, bool visible, int transition, int normalalpha, int movealpha, bool dragdrop ) { p_intf = _p_intf; @@ -84,21 +86,26 @@ Window::Window( intf_thread_t *_p_intf, int x, int y, bool visible, ToolTipText = "none"; } //--------------------------------------------------------------------------- -Window::~Window() +SkinWindow::~SkinWindow() { + if( Image ) + { + delete Image; + } // Destroy the controls for( unsigned int i = 0; i < ControlList.size(); i++ ) delete ControlList[i]; } //--------------------------------------------------------------------------- -void Window::Open() +void SkinWindow::Open() { if( !Hidden ) return; Changing = true; - if( Transition ) +#ifdef WIN32 + if( Transition && IS_WINNT ) { SetTransparency( 0 ); OSAPI_PostMessage( this, WINDOW_SHOW, 0, 0 ); @@ -106,28 +113,34 @@ void Window::Open() } else { +#endif OSAPI_PostMessage( this, WINDOW_SHOW, 0, 0 ); +#ifdef WIN32 } +#endif + } //--------------------------------------------------------------------------- -void Window::Close() +void SkinWindow::Close() { Changing = true; - if( Transition ) +#ifdef WIN32 + if( Transition && IS_WINNT ) Fade( 0, Transition, WINDOW_HIDE ); else +#endif OSAPI_PostMessage( this, WINDOW_FADE, WINDOW_HIDE, 1242 ); } //--------------------------------------------------------------------------- -void Window::Show() +void SkinWindow::Show() { Changing = false; Hidden = false; OSShow( true ); } //--------------------------------------------------------------------------- -void Window::Hide() +void SkinWindow::Hide() { if( Hidden ) return; @@ -138,18 +151,24 @@ void Window::Hide() OSAPI_PostMessage( NULL, VLC_TEST_ALL_CLOSED, 0, 0 ); } //--------------------------------------------------------------------------- -void Window::Fade( int To, int Time, unsigned int evt ) +void SkinWindow::Fade( int To, int Time, unsigned int evt ) { - StartAlpha = Alpha; - EndAlpha = To; - StartTime = OSAPI_GetTime(); - EndTime = StartTime + Time; - Lock++; + // No fading effect on win9x +#ifdef WIN32 + if( IS_WINNT ) + { + StartAlpha = Alpha; + EndAlpha = To; + StartTime = OSAPI_GetTime(); + EndTime = StartTime + Time; + Lock++; - OSAPI_PostMessage( this, WINDOW_FADE, evt, Lock ); + OSAPI_PostMessage( this, WINDOW_FADE, evt, Lock ); + } +#endif } //--------------------------------------------------------------------------- -bool Window::ProcessEvent( Event *evt ) +bool SkinWindow::ProcessEvent( Event *evt ) { unsigned int i; unsigned int msg = evt->GetMessage(); @@ -243,41 +262,46 @@ bool Window::ProcessEvent( Event *evt ) } } //--------------------------------------------------------------------------- -bool Window::ChangeAlpha( int time ) +bool SkinWindow::ChangeAlpha( int time ) { - if( time >= EndTime ) +#ifdef WIN32 + if( IS_WINNT ) { - if( Lock ) + if( time >= EndTime ) { - SetTransparency( EndAlpha ); - Lock = 0; + if( Lock ) + { + SetTransparency( EndAlpha ); + Lock = 0; + } + return false; } - return false; - } - int NewAlpha = StartAlpha + (EndAlpha - StartAlpha) * (time - StartTime) - / (EndTime - StartTime); - if( NewAlpha != Alpha ) - SetTransparency( NewAlpha ); - if( NewAlpha == EndAlpha ) - { - Lock = 0; - return false; + int NewAlpha = StartAlpha + (EndAlpha - StartAlpha) * (time - StartTime) + / (EndTime - StartTime); + if( NewAlpha != Alpha ) + SetTransparency( NewAlpha ); + if( NewAlpha == EndAlpha ) + { + Lock = 0; + return false; + } } +#endif return true; } //--------------------------------------------------------------------------- -void Window::RefreshImage( int x, int y, int w, int h ) +void SkinWindow::RefreshImage( int x, int y, int w, int h ) { unsigned int i; -fprintf(stderr, "refr %d %d %d %d\n", x,y,w,h); // Create Bitmap Buffer - Graphics *Buffer = (Graphics *)new OSGraphics( w, h, this ); + Graphics *Buffer = (Graphics *)new OSGraphics( p_intf, w, h, this ); +// Graphics *Buffer = (Graphics *)new OSGraphics( w, h, this ); // Draw every control - for( i = 0; i < ControlList.size(); i++ ) - ControlList[i]->Draw( x, y, w, h, Buffer ); + for( i = 0; i < ControlList.size(); i++ ) + ControlList[i]->Draw( x, y, w, h, Buffer ); // Copy buffer in Image Image->CopyFrom( x, y, w, h, Buffer, 0, 0, SRC_COPY ); @@ -286,7 +310,7 @@ fprintf(stderr, "refr %d %d %d %d\n", x,y,w,h); delete Buffer; } //--------------------------------------------------------------------------- -void Window::Refresh( int x, int y, int w, int h ) +void SkinWindow::Refresh( int x, int y, int w, int h ) { if( Image == NULL ) return; @@ -297,32 +321,31 @@ void Window::Refresh( int x, int y, int w, int h ) if( Hidden ) return; - fprintf( stderr, "Refresh: %i %i %i %i\n", x, y, w, h ); - // And copy buffer to window RefreshFromImage( x, y, w, h ); - } //--------------------------------------------------------------------------- -void Window::RefreshAll() +void SkinWindow::RefreshAll() { Refresh( 0, 0, Width, Height ); } //--------------------------------------------------------------------------- -void Window::MouseDown( int x, int y, int button ) +void SkinWindow::MouseDown( int x, int y, int button ) { // Checking event in controls - for( int i = ControlList.size() - 1; i >= 0 ; i-- ) + for( int i = ControlList.size() - 1; i >= 0; i-- ) { - if( ControlList[i]->MouseDown( x, y, button ) ) + if( ControlList[i]->IsVisible() && + ControlList[i]->MouseDown( x, y, button ) ) { - return; + msg_Dbg( p_intf, "Mouse down (ID=%s)", + ControlList[i]->GetId().c_str() ); + break; } } - } //--------------------------------------------------------------------------- -void Window::MouseMove( int x, int y, int button ) +void SkinWindow::MouseMove( int x, int y, int button ) { int i; @@ -333,20 +356,22 @@ void Window::MouseMove( int x, int y, int button ) } // Checking event in controls - for( i = ControlList.size() - 1; i >= 0 ; i-- ) + for( i = ControlList.size() - 1; i >= 0; i-- ) { - ControlList[i]->MouseMove( x, y, button ); + if( ControlList[i]->IsVisible() && + ControlList[i]->MouseMove( x, y, button ) ) + { + break; + } } // Checking help text - for( i = ControlList.size() - 1; i >= 0 ; i-- ) + for( i = ControlList.size() - 1; i >= 0; i-- ) { - if( ControlList[i]->MouseOver( x, y ) ) + if( ControlList[i]->IsVisible() && ControlList[i]->MouseOver( x, y ) ) { - if( ControlList[i]->SendNewHelpText() ) - { - break; - } + ControlList[i]->SendNewHelpText(); + break; } } @@ -358,10 +383,13 @@ void Window::MouseMove( int x, int y, int button ) } // Checking for change in Tool Tip - for( i = ControlList.size() - 1; i >= 0 ; i-- ) + for( i = ControlList.size() - 1; i >= 0; i-- ) { - if( ControlList[i]->ToolTipTest( x, y ) ) + if( ControlList[i]->IsVisible() && + ControlList[i]->ToolTipTest( x, y ) ) + { break; + } } // If no change, delete tooltip text @@ -369,7 +397,7 @@ void Window::MouseMove( int x, int y, int button ) ChangeToolTipText( "none" ); } //--------------------------------------------------------------------------- -void Window::MouseUp( int x, int y, int button ) +void SkinWindow::MouseUp( int x, int y, int button ) { int i; @@ -386,34 +414,64 @@ void Window::MouseUp( int x, int y, int button ) } // Checking event in controls - for( i = ControlList.size() - 1; i >= 0 ; i-- ) + for( i = ControlList.size() - 1; i >= 0; i-- ) { - fprintf( stderr, " -> Control\n" ); - if( ControlList[i]->MouseUp( x, y, button ) ) + if( ControlList[i]->IsVisible() && + ControlList[i]->MouseUp( x, y, button ) ) { - int x, y; - //ControlList[i]->GetSize( x, y ); - fprintf( stderr, " x: %i\n y: %i\n", - ControlList[i]->Left, ControlList[i]->Top ); - - return; + msg_Dbg( p_intf, "Mouse up (ID=%s)", + ControlList[i]->GetId().c_str() ); + break; } } + + if( i < 0 && button == MOUSE_RIGHT ) + { + p_intf->p_sys->p_dialogs->ShowPopup(); + } } //--------------------------------------------------------------------------- -void Window::MouseDblClick( int x, int y, int button ) +void SkinWindow::MouseDblClick( int x, int y, int button ) { int i; // Checking event in controls - for( i = ControlList.size() - 1; i >= 0 ; i-- ) + for( i = ControlList.size() - 1; i >= 0; i-- ) { - if( ControlList[i]->MouseDblClick( x, y, button ) ) - return; + if( ControlList[i]->IsVisible() && + ControlList[i]->MouseDblClick( x, y, button ) ) + { + msg_Dbg( p_intf, "Double click (ID=%s)", + ControlList[i]->GetId().c_str() ); + } } } //--------------------------------------------------------------------------- -void Window::Init() +void SkinWindow::MouseScroll( int x, int y, int direction ) +{ + // Checking event in controls + for( int i = ControlList.size() - 1; i >= 0; i-- ) + { + if( ControlList[i]->IsVisible() && + ControlList[i]->MouseScroll( x, y, direction ) ) + { + break; + } + } + + // Checking for change in Tool Tip + for( int i = ControlList.size() - 1; i >= 0; i-- ) + { + if( ControlList[i]->IsVisible() && + ControlList[i]->ToolTipTest( x, y ) ) + { + break; + } + } + +} +//--------------------------------------------------------------------------- +void SkinWindow::Init() { // Get size of window ReSize(); @@ -425,7 +483,7 @@ void Window::Init() Move( Left, Top ); } //--------------------------------------------------------------------------- -void Window::ReSize() +void SkinWindow::ReSize() { // Initialization unsigned int i; @@ -439,10 +497,10 @@ void Window::ReSize() { #define min(a,b) ((a)<(b))?(a):(b) #define max(a,b) ((a)>(b))?(a):(b) - w = max( w, ControlList[i]->Left + ControlList[i]->Width ); - h = max( h, ControlList[i]->Top + ControlList[i]->Height ); - MinX = min( MinX, ControlList[i]->Left ); - MinY = min( MinY, ControlList[i]->Top ); + w = max( w, ControlList[i]->GetLeft() + ControlList[i]->GetWidth() ); + h = max( h, ControlList[i]->GetTop() + ControlList[i]->GetHeight() ); + MinX = min( MinX, ControlList[i]->GetLeft() ); + MinY = min( MinY, ControlList[i]->GetTop() ); #undef max #undef min } @@ -469,24 +527,60 @@ void Window::ReSize() // Change image buffer if( Image != NULL ) delete (OSGraphics *)Image; - Image = (Graphics *)new OSGraphics( w, h, this ); - + Image = (Graphics *)new OSGraphics( p_intf, w, h, this ); Size( w, h ); } } //--------------------------------------------------------------------------- -void Window::GetSize( int &w, int &h ) +void SkinWindow::GetSize( int &w, int &h ) { w = Width; h = Height; } //--------------------------------------------------------------------------- -void Window::GetPos( int &x, int &y ) +void SkinWindow::GetPos( int &x, int &y ) { x = Left; y = Top; } -//--------------------------------------------------------------------------- +//--------------------------------------------------------------------------- +// List of all the Skin Windows (singleton) +//--------------------------------------------------------------------------- +SkinWindowList *SkinWindowList::_instance = NULL; +//--------------------------------------------------------------------------- +SkinWindowList::SkinWindowList() +{ +} +//--------------------------------------------------------------------------- +SkinWindowList *SkinWindowList::Instance() +{ + if( _instance == NULL ) + { + _instance = new SkinWindowList; + } + return _instance; +} +//--------------------------------------------------------------------------- +void SkinWindowList::Add( SkinWindow *win ) +{ + _list.push_back( win ); +} +//--------------------------------------------------------------------------- +SkinWindow *SkinWindowList::Back() +{ + return _list.back(); +} +//--------------------------------------------------------------------------- +list::const_iterator SkinWindowList::Begin() +{ + return _list.begin(); +} +//--------------------------------------------------------------------------- +list::const_iterator SkinWindowList::End() +{ + return _list.end(); +} +//---------------------------------------------------------------------------