1 /*****************************************************************************
2 * window.cpp: Window class
3 *****************************************************************************
4 * Copyright (C) 2003 VideoLAN
5 * $Id: window.cpp,v 1.3 2003/03/19 18:14:48 karibu 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 // OS specific messages processing
233 return ProcessOSEvent( evt );
236 //---------------------------------------------------------------------------
237 bool Window::ChangeAlpha( int time )
239 if( time >= EndTime )
243 SetTransparency( EndAlpha );
249 int NewAlpha = StartAlpha + (EndAlpha - StartAlpha) * (time - StartTime)
250 / (EndTime - StartTime);
251 if( NewAlpha != Alpha )
252 SetTransparency( NewAlpha );
253 if( NewAlpha == EndAlpha )
260 //---------------------------------------------------------------------------
261 void Window::RefreshImage( int x, int y, int w, int h )
265 // Create Bitmap Buffer
266 Graphics *Buffer = (Graphics *)new OSGraphics( w, h, this );
268 // Draw every control
269 for( i = 0; i < ControlList.size(); i++ )
270 ControlList[i]->Draw( x, y, w, h, Buffer );
272 // Copy buffer in Image
273 Image->CopyFrom( x, y, w, h, Buffer, 0, 0, SRC_COPY );
278 //---------------------------------------------------------------------------
279 void Window::Refresh( int x, int y, int w, int h )
284 // Refresh buffer image
285 RefreshImage( x, y, w, h );
290 // And copy buffer to window
291 RefreshFromImage( x, y, w, h );
294 //---------------------------------------------------------------------------
295 void Window::RefreshAll()
297 Refresh( 0, 0, Width, Height );
299 //---------------------------------------------------------------------------
300 void Window::MouseDown( int x, int y, int button )
302 // Checking event in controls
304 for( int i = ControlList.size() - 1; i >= 0 ; i-- )
306 if( ControlList[i]->MouseDown( x, y, button ) )
312 //---------------------------------------------------------------------------
313 void Window::MouseMove( int x, int y, int button )
317 // Move window if selected !
323 // Checking event in controls
324 for( i = ControlList.size() - 1; i >= 0 ; i-- )
326 ControlList[i]->MouseMove( x, y, button );
329 // Checking help text
330 for( i = ControlList.size() - 1; i >= 0 ; i-- )
332 if( ControlList[i]->MouseOver( x, y ) )
334 if( ControlList[i]->SendNewHelpText() )
341 // If help text not found, change it to ""
344 p_intf->p_sys->p_theme->EvtBank->Get( "help" )
345 ->PostTextMessage( " " );
348 // Checking for change in Tool Tip
349 for( i = ControlList.size() - 1; i >= 0 ; i-- )
351 if( ControlList[i]->ToolTipTest( x, y ) )
355 // If no change, delete tooltip text
357 ChangeToolTipText( "none" );
359 //---------------------------------------------------------------------------
360 void Window::MouseUp( int x, int y, int button )
364 // Move window if selected !
368 Fade( NormalAlpha, 100 );
370 // Check for magnetism
371 p_intf->p_sys->p_theme->CheckAnchors();
373 WindowMoving = false;
376 // Checking event in controls
377 for( i = ControlList.size() - 1; i >= 0 ; i-- )
379 if( ControlList[i]->MouseUp( x, y, button ) )
383 //---------------------------------------------------------------------------
384 void Window::MouseDblClick( int x, int y, int button )
388 // Checking event in controls
389 for( i = ControlList.size() - 1; i >= 0 ; i-- )
391 if( ControlList[i]->MouseDblClick( x, y, button ) )
395 //---------------------------------------------------------------------------
398 // Get size of window
401 // Refresh Image buffer
402 RefreshImage( 0, 0, Width, Height );
404 // Move window as it hasn't been moved yet
407 //---------------------------------------------------------------------------
408 void Window::ReSize()
417 // Search size of window and negative values to move all
418 for( i = 0; i < ControlList.size(); i++ )
420 #define min(a,b) ((a)<(b))?(a):(b)
421 #define max(a,b) ((a)>(b))?(a):(b)
422 w = max( w, ControlList[i]->Left + ControlList[i]->Width );
423 h = max( h, ControlList[i]->Top + ControlList[i]->Height );
424 MinX = min( MinX, ControlList[i]->Left );
425 MinY = min( MinY, ControlList[i]->Top );
438 // Move window and controls !
439 if( MinX != 0 || MinY != 0 )
441 Move( Left + MinX, Top + MinY );
442 for( i = 0; i < ControlList.size(); i++ )
443 ControlList[i]->MoveRelative( -MinX, -MinY );
446 // Create buffer image for repainting if size has changed
447 if( w != Width || h != Height )
449 // Change image buffer
451 delete (OSGraphics *)Image;
452 Image = (Graphics *)new OSGraphics( w, h, this );
459 //---------------------------------------------------------------------------
460 void Window::GetSize( int &w, int &h )
465 //---------------------------------------------------------------------------
466 void Window::GetPos( int &x, int &y )
471 //---------------------------------------------------------------------------