]> git.sesse.net Git - vlc/blob - modules/gui/skins/controls/generic.cpp
* fixed some constructors and destructors
[vlc] / modules / gui / skins / controls / generic.cpp
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 $
6  *
7  * Authors: Olivier Teulière <ipkiss@via.ecp.fr>
8  *          Emmanuel Puig    <karibu@via.ecp.fr>
9  *
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.
14  *
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.
19  *
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,
23  * USA.
24  *****************************************************************************/
25
26
27 //--- VLC -------------------------------------------------------------------
28 #include <vlc/intf.h>
29
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"
38 #include "generic.h"
39 #include "../src/window.h"
40 #include "../src/theme.h"
41 #include "../src/skin_common.h"
42
43
44 //---------------------------------------------------------------------------
45 // Generic Control
46 //---------------------------------------------------------------------------
47 GenericControl::GenericControl( string id, bool visible, string help,
48                                 SkinWindow *Parent )
49 {
50     ID      = id;
51     Visible = visible;
52     Help    = help;
53     ParentWindow = Parent;
54     Left    = 0;
55     Top     = 0;
56     Width   = 0;
57     Height  = 0;
58     State   = 0;
59     Img     = NULL;
60     p_intf  = Parent->GetIntf();
61 }
62 //---------------------------------------------------------------------------
63 GenericControl::~GenericControl()
64 {
65     if( Img != NULL )
66         delete[] Img;
67 }
68 //---------------------------------------------------------------------------
69 bool GenericControl::GenericProcessEvent( Event *evt )
70 {
71     switch( evt->GetMessage() )
72     {
73         case CTRL_ID_VISIBLE:
74             if( (GenericControl *)evt->GetParam1() == this )
75             {
76                 if( ( evt->GetParam2() == 0 && Visible ) ||
77                     ( evt->GetParam2() == 1 && !Visible ) ||
78                     ( evt->GetParam2() == 2 ) )
79                 {
80                     Visible = !Visible;
81                     ParentWindow->Refresh( Left, Top, Width, Height );
82                 }
83             }
84             return false;
85
86         case CTRL_ID_MOVE:
87             if( (GenericControl *)evt->GetParam1() == this )
88             {
89                 int x = evt->GetParam2() & 0x7FFF;
90                 int y = evt->GetParam2() >> 16 & 0x7FFF;
91                 if( evt->GetParam2() & 0x8000 )
92                     x = -x;
93                 if( evt->GetParam2() >> 16 & 0x8000 )
94                     y = -y;
95                 MoveRelative( x, y );
96                 ParentWindow->ReSize();
97                 ParentWindow->RefreshAll();
98             }
99             return false;
100
101         default:
102             return ProcessEvent( evt );
103     }
104
105 }
106 //---------------------------------------------------------------------------
107 bool GenericControl::IsID( string id )
108 {
109     if( ID == "none" || ID != id )
110     {
111         return false;
112     }
113     else
114     {
115         return true;
116     }
117 }
118 //---------------------------------------------------------------------------
119 void GenericControl::Init()
120 {
121 }
122 //---------------------------------------------------------------------------
123 bool GenericControl::ProcessEvent( Event *evt )
124 {
125     return false;
126 }
127 //---------------------------------------------------------------------------
128 bool GenericControl::MouseUp( int x, int y, int button )
129 {
130     return false;
131 }
132 //---------------------------------------------------------------------------
133 bool GenericControl::MouseDown( int x, int y, int button )
134 {
135     return false;
136 }
137 //---------------------------------------------------------------------------
138 bool GenericControl::MouseMove( int x, int y, int button )
139 {
140     return false;
141 }
142 //---------------------------------------------------------------------------
143 bool GenericControl::MouseOver( int x, int y )
144 {
145     return false;
146 }
147 //---------------------------------------------------------------------------
148 bool GenericControl::MouseDblClick( int x, int y, int button )
149 {
150     return false;
151 }
152 //---------------------------------------------------------------------------
153 bool GenericControl::MouseScroll( int x, int y, int direction )
154 {
155     return false;
156 }
157 //---------------------------------------------------------------------------
158 bool GenericControl::SendNewHelpText()
159 {
160     if( Help != "" )
161     {
162         p_intf->p_sys->p_theme->EvtBank->Get( "help" )
163             ->PostTextMessage( Help );
164         return true;
165     }
166     return false;
167 }
168 //---------------------------------------------------------------------------
169 bool GenericControl::ToolTipTest( int x, int y )
170 {
171     return false;
172 }
173 //---------------------------------------------------------------------------
174 void GenericControl::Enable( Event *event, bool enabled )
175 {
176 }
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 )
180 {
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);
186 }
187 //---------------------------------------------------------------------------
188 void GenericControl::Move( int left, int top )
189 {
190     MoveRelative( left - Left, top - Top );
191 }
192 //---------------------------------------------------------------------------
193 void GenericControl::MoveRelative( int xOff, int yOff )
194 {
195     Left += xOff;
196     Top  += yOff;
197 }
198 //---------------------------------------------------------------------------
199 Region *GenericControl::CreateRegionFromBmp( Bitmap *bmp, int MoveX, int MoveY )
200 {
201     // Initialization
202         Region *Buffer;
203         int w, h;
204         int x = 0, y = 0, x_first = 0;
205         bmp->GetSize( w, h );
206
207         Buffer = (Region *)new OSRegion;
208
209     // Parse bitmap
210         for( y = 0; y < h; y++ )
211         {
212             for( x = 0; x < w; x++ )
213             {
214
215                 if( bmp->GetBmpPixel( x, y ) == bmp->GetAlphaColor() )
216                 {
217                     if( x_first != x )
218                     {
219                         Buffer->AddRectangle( x_first + MoveX, y + MoveY,
220                                               x + MoveX, y + 1 + MoveY );
221                     }
222                     x_first = x + 1;
223                 }
224             }
225             if( x_first != w )
226             {
227                 Buffer->AddRectangle( x_first + MoveX, y + MoveY,
228                                         w + MoveX, y + 1 + MoveY );
229             }
230             x_first = 0;
231         }
232     // End of parsing
233     return Buffer;
234 }
235 //---------------------------------------------------------------------------
236