1 /*****************************************************************************
2 * generic.cpp: Generic control, parent of the others
3 *****************************************************************************
4 * Copyright (C) 2003 VideoLAN
5 * $Id: generic.cpp,v 1.5 2003/04/23 10:29:52 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 ------------------------------------------------------------------
31 #include "../os_api.h"
32 #include "../src/bitmap.h"
33 #include "../os_bitmap.h"
34 #include "../src/banks.h"
35 #include "../src/graphics.h"
36 #include "../os_graphics.h"
37 #include "../src/event.h"
39 #include "../src/window.h"
40 #include "../src/theme.h"
41 #include "../src/skin_common.h"
44 //---------------------------------------------------------------------------
46 //---------------------------------------------------------------------------
47 GenericControl::GenericControl( string id, bool visible, string help,
53 ParentWindow = Parent;
60 p_intf = Parent->GetIntf();
62 //---------------------------------------------------------------------------
63 GenericControl::~GenericControl()
68 //---------------------------------------------------------------------------
69 bool GenericControl::GenericProcessEvent( Event *evt )
71 switch( evt->GetMessage() )
74 if( (GenericControl *)evt->GetParam1() == this )
76 if( ( evt->GetParam2() == 0 && Visible ) ||
77 ( evt->GetParam2() == 1 && !Visible ) ||
78 ( evt->GetParam2() == 2 ) )
81 ParentWindow->Refresh( Left, Top, Width, Height );
87 if( (GenericControl *)evt->GetParam1() == this )
89 int x = evt->GetParam2() & 0x7FFF;
90 int y = evt->GetParam2() >> 16 & 0x7FFF;
91 if( evt->GetParam2() & 0x8000 )
93 if( evt->GetParam2() >> 16 & 0x8000 )
96 ParentWindow->ReSize();
97 ParentWindow->RefreshAll();
102 return ProcessEvent( evt );
106 //---------------------------------------------------------------------------
107 bool GenericControl::IsID( string id )
109 if( ID == "none" || ID != id )
118 //---------------------------------------------------------------------------
119 void GenericControl::Init()
122 //---------------------------------------------------------------------------
123 bool GenericControl::ProcessEvent( Event *evt )
127 //---------------------------------------------------------------------------
128 bool GenericControl::MouseUp( int x, int y, int button )
132 //---------------------------------------------------------------------------
133 bool GenericControl::MouseDown( int x, int y, int button )
137 //---------------------------------------------------------------------------
138 bool GenericControl::MouseMove( int x, int y, int button )
142 //---------------------------------------------------------------------------
143 bool GenericControl::MouseOver( int x, int y )
147 //---------------------------------------------------------------------------
148 bool GenericControl::MouseDblClick( int x, int y, int button )
152 //---------------------------------------------------------------------------
153 bool GenericControl::MouseScroll( int x, int y, int direction )
157 //---------------------------------------------------------------------------
158 bool GenericControl::SendNewHelpText()
162 p_intf->p_sys->p_theme->EvtBank->Get( "help" )
163 ->PostTextMessage( Help );
168 //---------------------------------------------------------------------------
169 bool GenericControl::ToolTipTest( int x, int y )
173 //---------------------------------------------------------------------------
174 void GenericControl::Enable( Event *event, bool enabled )
177 //---------------------------------------------------------------------------
178 bool GenericControl::GetIntersectRgn( int x1, int y1, int w1, int h1, int x2,
179 int y2, int w2, int h2, int &x, int &y, int &w, int &h )
181 if( x1 < x2 ) {x = x2;} else {x = x1;}
182 if( y1 < y2 ) {y = y2;} else {y = y1;}
183 if( x1+w1 < x2+w2 ) {w = x1+w1-x;} else {w = x2+w2-x;}
184 if( y1+h1 < y2+h2 ) {h = y1+h1-y;} else {h = y2+h2-y;}
185 return (w > 0 && h > 0);
187 //---------------------------------------------------------------------------
188 void GenericControl::Move( int left, int top )
190 MoveRelative( left - Left, top - Top );
192 //---------------------------------------------------------------------------
193 void GenericControl::MoveRelative( int xOff, int yOff )
198 //---------------------------------------------------------------------------
199 Region *GenericControl::CreateRegionFromBmp( Bitmap *bmp, int MoveX, int MoveY )
204 int x = 0, y = 0, x_first = 0;
205 bmp->GetSize( w, h );
207 Buffer = (Region *)new OSRegion;
210 for( y = 0; y < h; y++ )
212 for( x = 0; x < w; x++ )
215 if( bmp->GetBmpPixel( x, y ) == bmp->GetAlphaColor() )
219 Buffer->AddRectangle( x_first + MoveX, y + MoveY,
220 x + MoveX, y + 1 + MoveY );
227 Buffer->AddRectangle( x_first + MoveX, y + MoveY,
228 w + MoveX, y + 1 + MoveY );
235 //---------------------------------------------------------------------------