1 /*****************************************************************************
2 * window.cpp: Window class
3 *****************************************************************************
4 * Copyright (C) 2003 VideoLAN
5 * $Id: window.cpp,v 1.7 2003/04/13 20:07:34 asmax Exp $
7 * Authors: Olivier Teulière <ipkiss@via.ecp.fr>
8 * Emmanuel Puig <karibu@via.ecp.fr>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111,
24 *****************************************************************************/
27 //--- VLC -------------------------------------------------------------------
30 //--- SKIN ------------------------------------------------------------------
37 #include "os_graphics.h"
40 #include "skin_common.h"
44 //---------------------------------------------------------------------------
46 //---------------------------------------------------------------------------
47 Window::Window( intf_thread_t *_p_intf, int x, int y, bool visible,
48 int transition, int normalalpha, int movealpha, bool dragdrop )
52 // Set position parameters
61 Transition = transition;
64 NormalAlpha = normalalpha;
65 MoveAlpha = movealpha;
77 OnStartThemeVisible = visible;
85 //---------------------------------------------------------------------------
88 // Destroy the controls
89 for( unsigned int i = 0; i < ControlList.size(); i++ )
90 delete ControlList[i];
92 //---------------------------------------------------------------------------
102 SetTransparency( 0 );
103 OSAPI_PostMessage( this, WINDOW_SHOW, 0, 0 );
104 Fade( NormalAlpha, Transition );
108 OSAPI_PostMessage( this, WINDOW_SHOW, 0, 0 );
111 //---------------------------------------------------------------------------
117 Fade( 0, Transition, WINDOW_HIDE );
119 OSAPI_PostMessage( this, WINDOW_FADE, WINDOW_HIDE, 1242 );
121 //---------------------------------------------------------------------------
128 //---------------------------------------------------------------------------
137 OSAPI_PostMessage( NULL, VLC_TEST_ALL_CLOSED, 0, 0 );
139 //---------------------------------------------------------------------------
140 void Window::Fade( int To, int Time, unsigned int evt )
144 StartTime = OSAPI_GetTime();
145 EndTime = StartTime + Time;
148 OSAPI_PostMessage( this, WINDOW_FADE, evt, Lock );
150 //---------------------------------------------------------------------------
151 bool Window::ProcessEvent( Event *evt )
154 unsigned int msg = evt->GetMessage();
155 unsigned int p1 = evt->GetParam1();
156 int p2 = evt->GetParam2();
158 // Send event to control if necessary
159 if( msg > VLC_CONTROL )
161 for( i = 0; i < ControlList.size(); i++ )
162 ControlList[i]->GenericProcessEvent( evt );
166 // Message processing
170 if( Lock == p2 && ChangeAlpha( OSAPI_GetTime() ) )
172 OSAPI_PostMessage( this, WINDOW_FADE, p1, p2 );
176 OSAPI_PostMessage( this, p1, 0, 0 );
181 WindowManualMoveInit();
184 Fade( MoveAlpha, 100 );
232 MouseMove( -1, -1, 0 );
240 // OS specific messages processing
241 return ProcessOSEvent( evt );
244 //---------------------------------------------------------------------------
245 bool Window::ChangeAlpha( int time )
247 if( time >= EndTime )
251 SetTransparency( EndAlpha );
257 int NewAlpha = StartAlpha + (EndAlpha - StartAlpha) * (time - StartTime)
258 / (EndTime - StartTime);
259 if( NewAlpha != Alpha )
260 SetTransparency( NewAlpha );
261 if( NewAlpha == EndAlpha )
268 //---------------------------------------------------------------------------
269 void Window::RefreshImage( int x, int y, int w, int h )
273 // Create Bitmap Buffer
274 Graphics *Buffer = (Graphics *)new OSGraphics( w, h, this );
276 // Draw every control
277 for( i = 0; i < ControlList.size(); i++ )
278 ControlList[i]->Draw( x, y, w, h, Buffer );
280 // Copy buffer in Image
281 Image->CopyFrom( x, y, w, h, Buffer, 0, 0, SRC_COPY );
286 //---------------------------------------------------------------------------
287 void Window::Refresh( int x, int y, int w, int h )
292 // Refresh buffer image
293 RefreshImage( x, y, w, h );
298 // And copy buffer to window
299 RefreshFromImage( x, y, w, h );
302 //---------------------------------------------------------------------------
303 void Window::RefreshAll()
305 Refresh( 0, 0, Width, Height );
307 //---------------------------------------------------------------------------
308 void Window::MouseDown( int x, int y, int button )
310 // Checking event in controls
312 for( int i = ControlList.size() - 1; i >= 0 ; i-- )
314 if( ControlList[i]->MouseDown( x, y, button ) )
320 //---------------------------------------------------------------------------
321 void Window::MouseMove( int x, int y, int button )
325 // Move window if selected !
331 // Checking event in controls
332 for( i = ControlList.size() - 1; i >= 0 ; i-- )
334 ControlList[i]->MouseMove( x, y, button );
337 // Checking help text
338 for( i = ControlList.size() - 1; i >= 0 ; i-- )
340 if( ControlList[i]->MouseOver( x, y ) )
342 if( ControlList[i]->SendNewHelpText() )
349 // If help text not found, change it to ""
352 p_intf->p_sys->p_theme->EvtBank->Get( "help" )
353 ->PostTextMessage( " " );
356 // Checking for change in Tool Tip
357 for( i = ControlList.size() - 1; i >= 0 ; i-- )
359 if( ControlList[i]->ToolTipTest( x, y ) )
363 // If no change, delete tooltip text
365 ChangeToolTipText( "none" );
367 //---------------------------------------------------------------------------
368 void Window::MouseUp( int x, int y, int button )
372 // Move window if selected !
376 Fade( NormalAlpha, 100 );
378 // Check for magnetism
379 p_intf->p_sys->p_theme->CheckAnchors();
381 WindowMoving = false;
384 // Checking event in controls
385 for( i = ControlList.size() - 1; i >= 0 ; i-- )
387 if( ControlList[i]->MouseUp( x, y, button ) )
391 //---------------------------------------------------------------------------
392 void Window::MouseDblClick( int x, int y, int button )
396 // Checking event in controls
397 for( i = ControlList.size() - 1; i >= 0 ; i-- )
399 if( ControlList[i]->MouseDblClick( x, y, button ) )
403 //---------------------------------------------------------------------------
406 // Get size of window
409 // Refresh Image buffer
410 RefreshImage( 0, 0, Width, Height );
412 // Move window as it hasn't been moved yet
415 //---------------------------------------------------------------------------
416 void Window::ReSize()
425 // Search size of window and negative values to move all
426 for( i = 0; i < ControlList.size(); i++ )
428 #define min(a,b) ((a)<(b))?(a):(b)
429 #define max(a,b) ((a)>(b))?(a):(b)
430 w = max( w, ControlList[i]->Left + ControlList[i]->Width );
431 h = max( h, ControlList[i]->Top + ControlList[i]->Height );
432 MinX = min( MinX, ControlList[i]->Left );
433 MinY = min( MinY, ControlList[i]->Top );
446 // Move window and controls !
447 if( MinX != 0 || MinY != 0 )
449 Move( Left + MinX, Top + MinY );
450 for( i = 0; i < ControlList.size(); i++ )
451 ControlList[i]->MoveRelative( -MinX, -MinY );
454 // Create buffer image for repainting if size has changed
455 if( w != Width || h != Height )
457 // Change image buffer
459 delete (OSGraphics *)Image;
460 Image = (Graphics *)new OSGraphics( w, h, this );
467 //---------------------------------------------------------------------------
468 void Window::GetSize( int &w, int &h )
473 //---------------------------------------------------------------------------
474 void Window::GetPos( int &x, int &y )
479 //---------------------------------------------------------------------------