1 /*****************************************************************************
2 * window.cpp: Window class
3 *****************************************************************************
4 * Copyright (C) 2003 VideoLAN
5 * $Id: window.cpp,v 1.11 2003/04/15 20:33:58 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"
45 //---------------------------------------------------------------------------
47 //---------------------------------------------------------------------------
48 Window::Window( intf_thread_t *_p_intf, int x, int y, bool visible,
49 int transition, int normalalpha, int movealpha, bool dragdrop )
53 // Set position parameters
62 Transition = transition;
65 NormalAlpha = normalalpha;
66 MoveAlpha = movealpha;
78 OnStartThemeVisible = visible;
86 //---------------------------------------------------------------------------
89 // Destroy the controls
90 for( unsigned int i = 0; i < ControlList.size(); i++ )
91 delete ControlList[i];
93 //---------------------------------------------------------------------------
103 SetTransparency( 0 );
104 OSAPI_PostMessage( this, WINDOW_SHOW, 0, 0 );
105 Fade( NormalAlpha, Transition );
109 OSAPI_PostMessage( this, WINDOW_SHOW, 0, 0 );
112 //---------------------------------------------------------------------------
118 Fade( 0, Transition, WINDOW_HIDE );
120 OSAPI_PostMessage( this, WINDOW_FADE, WINDOW_HIDE, 1242 );
122 //---------------------------------------------------------------------------
129 //---------------------------------------------------------------------------
138 OSAPI_PostMessage( NULL, VLC_TEST_ALL_CLOSED, 0, 0 );
140 //---------------------------------------------------------------------------
141 void Window::Fade( int To, int Time, unsigned int evt )
145 StartTime = OSAPI_GetTime();
146 EndTime = StartTime + Time;
149 OSAPI_PostMessage( this, WINDOW_FADE, evt, Lock );
151 //---------------------------------------------------------------------------
152 bool Window::ProcessEvent( Event *evt )
155 unsigned int msg = evt->GetMessage();
156 unsigned int p1 = evt->GetParam1();
157 int p2 = evt->GetParam2();
159 // Send event to control if necessary
160 if( msg > VLC_CONTROL )
162 for( i = 0; i < ControlList.size(); i++ )
163 ControlList[i]->GenericProcessEvent( evt );
167 // Message processing
171 if( Lock == p2 && ChangeAlpha( OSAPI_GetTime() ) )
173 OSAPI_PostMessage( this, WINDOW_FADE, p1, p2 );
177 OSAPI_PostMessage( this, p1, 0, 0 );
182 WindowManualMoveInit();
185 Fade( MoveAlpha, 100 );
233 MouseMove( -1, -1, 0 );
241 // OS specific messages processing
242 return ProcessOSEvent( evt );
245 //---------------------------------------------------------------------------
246 bool Window::ChangeAlpha( int time )
248 if( time >= EndTime )
252 SetTransparency( EndAlpha );
258 int NewAlpha = StartAlpha + (EndAlpha - StartAlpha) * (time - StartTime)
259 / (EndTime - StartTime);
260 if( NewAlpha != Alpha )
261 SetTransparency( NewAlpha );
262 if( NewAlpha == EndAlpha )
269 //---------------------------------------------------------------------------
270 void Window::RefreshImage( int x, int y, int w, int h )
274 // Create Bitmap Buffer
275 Graphics *Buffer = (Graphics *)new OSGraphics( w, h, this );
277 // Draw every control
278 for( i = 0; i < ControlList.size(); i++ )
279 ControlList[i]->Draw( x, y, w, h, Buffer );
281 // Copy buffer in Image
282 Image->CopyFrom( x, y, w, h, Buffer, 0, 0, SRC_COPY );
287 //---------------------------------------------------------------------------
288 void Window::Refresh( int x, int y, int w, int h )
293 // Refresh buffer image
294 RefreshImage( x, y, w, h );
299 // And copy buffer to window
300 RefreshFromImage( x, y, w, h );
303 //---------------------------------------------------------------------------
304 void Window::RefreshAll()
306 Refresh( 0, 0, Width, Height );
308 //---------------------------------------------------------------------------
309 void Window::MouseDown( int x, int y, int button )
311 // Checking event in controls
312 for( int i = ControlList.size() - 1; i >= 0 ; i-- )
314 if( ControlList[i]->MouseDown( x, y, button ) )
321 //---------------------------------------------------------------------------
322 void Window::MouseMove( int x, int y, int button )
326 // Move window if selected !
332 // Checking event in controls
333 for( i = ControlList.size() - 1; i >= 0 ; i-- )
335 ControlList[i]->MouseMove( x, y, button );
338 // Checking help text
339 for( i = ControlList.size() - 1; i >= 0 ; i-- )
341 if( ControlList[i]->MouseOver( x, y ) )
343 if( ControlList[i]->SendNewHelpText() )
350 // If help text not found, change it to ""
353 p_intf->p_sys->p_theme->EvtBank->Get( "help" )
354 ->PostTextMessage( " " );
357 // Checking for change in Tool Tip
358 for( i = ControlList.size() - 1; i >= 0 ; i-- )
360 if( ControlList[i]->ToolTipTest( x, y ) )
364 // If no change, delete tooltip text
366 ChangeToolTipText( "none" );
368 //---------------------------------------------------------------------------
369 void Window::MouseUp( int x, int y, int button )
373 // Move window if selected !
377 Fade( NormalAlpha, 100 );
379 // Check for magnetism
380 p_intf->p_sys->p_theme->CheckAnchors();
382 WindowMoving = false;
385 // Checking event in controls
386 for( i = ControlList.size() - 1; i >= 0 ; i-- )
388 if( ControlList[i]->MouseUp( x, y, button ) )
392 //---------------------------------------------------------------------------
393 void Window::MouseDblClick( int x, int y, int button )
397 // Checking event in controls
398 for( i = ControlList.size() - 1; i >= 0 ; i-- )
400 if( ControlList[i]->MouseDblClick( x, y, button ) )
404 //---------------------------------------------------------------------------
407 // Get size of window
410 // Refresh Image buffer
411 RefreshImage( 0, 0, Width, Height );
413 fprintf(stderr, "kludge in window.cpp!\n");
414 RefreshFromImage( 0, 0, Width, Height );
415 // Move window as it hasn't been moved yet
418 //---------------------------------------------------------------------------
419 void Window::ReSize()
428 // Search size of window and negative values to move all
429 for( i = 0; i < ControlList.size(); i++ )
431 #define min(a,b) ((a)<(b))?(a):(b)
432 #define max(a,b) ((a)>(b))?(a):(b)
433 w = max( w, ControlList[i]->Left + ControlList[i]->Width );
434 h = max( h, ControlList[i]->Top + ControlList[i]->Height );
435 MinX = min( MinX, ControlList[i]->Left );
436 MinY = min( MinY, ControlList[i]->Top );
449 // Move window and controls !
450 if( MinX != 0 || MinY != 0 )
452 Move( Left + MinX, Top + MinY );
453 for( i = 0; i < ControlList.size(); i++ )
454 ControlList[i]->MoveRelative( -MinX, -MinY );
457 // Create buffer image for repainting if size has changed
458 if( w != Width || h != Height )
460 // Change image buffer
462 delete (OSGraphics *)Image;
463 Image = (Graphics *)new OSGraphics( w, h, this );
470 //---------------------------------------------------------------------------
471 void Window::GetSize( int &w, int &h )
476 //---------------------------------------------------------------------------
477 void Window::GetPos( int &x, int &y )
482 //---------------------------------------------------------------------------