1 /*****************************************************************************
2 * window.cpp: Window class
3 *****************************************************************************
4 * Copyright (C) 2003 VideoLAN
5 * $Id: window.cpp,v 1.13 2003/04/16 15:34:36 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"
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 fprintf(stderr, "refr %d %d %d %d\n", x,y,w,h);
275 // Create Bitmap Buffer
276 Graphics *Buffer = (Graphics *)new OSGraphics( w, h, this );
278 // Draw every control
279 for( i = 0; i < ControlList.size(); i++ )
280 ControlList[i]->Draw( x, y, w, h, Buffer );
282 // Copy buffer in Image
283 Image->CopyFrom( x, y, w, h, Buffer, 0, 0, SRC_COPY );
288 //---------------------------------------------------------------------------
289 void Window::Refresh( int x, int y, int w, int h )
294 // Refresh buffer image
295 RefreshImage( x, y, w, h );
300 // And copy buffer to window
301 RefreshFromImage( x, y, w, h );
304 //---------------------------------------------------------------------------
305 void Window::RefreshAll()
307 Refresh( 0, 0, Width, Height );
309 //---------------------------------------------------------------------------
310 void Window::MouseDown( int x, int y, int button )
312 // Checking event in controls
313 for( int i = ControlList.size() - 1; i >= 0 ; i-- )
315 if( ControlList[i]->MouseDown( x, y, button ) )
322 //---------------------------------------------------------------------------
323 void Window::MouseMove( int x, int y, int button )
327 // Move window if selected !
333 // Checking event in controls
334 for( i = ControlList.size() - 1; i >= 0 ; i-- )
336 ControlList[i]->MouseMove( x, y, button );
339 // Checking help text
340 for( i = ControlList.size() - 1; i >= 0 ; i-- )
342 if( ControlList[i]->MouseOver( x, y ) )
344 if( ControlList[i]->SendNewHelpText() )
351 // If help text not found, change it to ""
354 p_intf->p_sys->p_theme->EvtBank->Get( "help" )
355 ->PostTextMessage( " " );
358 // Checking for change in Tool Tip
359 for( i = ControlList.size() - 1; i >= 0 ; i-- )
361 if( ControlList[i]->ToolTipTest( x, y ) )
365 // If no change, delete tooltip text
367 ChangeToolTipText( "none" );
369 //---------------------------------------------------------------------------
370 void Window::MouseUp( int x, int y, int button )
374 // Move window if selected !
378 Fade( NormalAlpha, 100 );
380 // Check for magnetism
381 p_intf->p_sys->p_theme->CheckAnchors();
383 WindowMoving = false;
386 // Checking event in controls
387 for( i = ControlList.size() - 1; i >= 0 ; i-- )
389 if( ControlList[i]->MouseUp( x, y, button ) )
393 //---------------------------------------------------------------------------
394 void Window::MouseDblClick( int x, int y, int button )
398 // Checking event in controls
399 for( i = ControlList.size() - 1; i >= 0 ; i-- )
401 if( ControlList[i]->MouseDblClick( x, y, button ) )
405 //---------------------------------------------------------------------------
408 // Get size of window
411 // Refresh Image buffer
412 RefreshImage( 0, 0, Width, Height );
414 // Move window as it hasn't been moved yet
417 //---------------------------------------------------------------------------
418 void Window::ReSize()
427 // Search size of window and negative values to move all
428 for( i = 0; i < ControlList.size(); i++ )
430 #define min(a,b) ((a)<(b))?(a):(b)
431 #define max(a,b) ((a)>(b))?(a):(b)
432 w = max( w, ControlList[i]->Left + ControlList[i]->Width );
433 h = max( h, ControlList[i]->Top + ControlList[i]->Height );
434 MinX = min( MinX, ControlList[i]->Left );
435 MinY = min( MinY, ControlList[i]->Top );
448 // Move window and controls !
449 if( MinX != 0 || MinY != 0 )
451 Move( Left + MinX, Top + MinY );
452 for( i = 0; i < ControlList.size(); i++ )
453 ControlList[i]->MoveRelative( -MinX, -MinY );
456 // Create buffer image for repainting if size has changed
457 if( w != Width || h != Height )
459 // Change image buffer
461 delete (OSGraphics *)Image;
462 Image = (Graphics *)new OSGraphics( w, h, this );
469 //---------------------------------------------------------------------------
470 void Window::GetSize( int &w, int &h )
475 //---------------------------------------------------------------------------
476 void Window::GetPos( int &x, int &y )
481 //---------------------------------------------------------------------------