]> git.sesse.net Git - vlc/blob - modules/gui/skins/controls/generic.cpp
* repaired basic_skins
[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.7 2003/05/31 23:23:59 ipkiss 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 void GenericControl::Init()
108 {
109 }
110 //---------------------------------------------------------------------------
111 bool GenericControl::ProcessEvent( Event *evt )
112 {
113     return false;
114 }
115 //---------------------------------------------------------------------------
116 bool GenericControl::MouseUp( int x, int y, int button )
117 {
118     return false;
119 }
120 //---------------------------------------------------------------------------
121 bool GenericControl::MouseDown( int x, int y, int button )
122 {
123     return false;
124 }
125 //---------------------------------------------------------------------------
126 bool GenericControl::MouseMove( int x, int y, int button )
127 {
128     return false;
129 }
130 //---------------------------------------------------------------------------
131 bool GenericControl::MouseOver( int x, int y )
132 {
133     return false;
134 }
135 //---------------------------------------------------------------------------
136 bool GenericControl::MouseDblClick( int x, int y, int button )
137 {
138     return false;
139 }
140 //---------------------------------------------------------------------------
141 bool GenericControl::MouseScroll( int x, int y, int direction )
142 {
143     return false;
144 }
145 //---------------------------------------------------------------------------
146 bool GenericControl::SendNewHelpText()
147 {
148     if( Help != "" )
149     {
150         p_intf->p_sys->p_theme->EvtBank->Get( "help" )
151             ->PostTextMessage( Help );
152         return true;
153     }
154     return false;
155 }
156 //---------------------------------------------------------------------------
157 bool GenericControl::ToolTipTest( int x, int y )
158 {
159     return false;
160 }
161 //---------------------------------------------------------------------------
162 void GenericControl::Enable( Event *event, bool enabled )
163 {
164 }
165 //---------------------------------------------------------------------------
166 bool GenericControl::GetIntersectRgn( int x1, int y1, int w1, int h1, int x2,
167     int y2, int w2, int h2, int &x, int &y, int &w, int &h )
168 {
169     if( x1 < x2 )       {x = x2;}      else {x = x1;}
170     if( y1 < y2 )       {y = y2;}      else {y = y1;}
171     if( x1+w1 < x2+w2 ) {w = x1+w1-x;} else {w = x2+w2-x;}
172     if( y1+h1 < y2+h2 ) {h = y1+h1-y;} else {h = y2+h2-y;}
173     return (w > 0 && h > 0);
174 }
175 //---------------------------------------------------------------------------
176 void GenericControl::Move( int left, int top )
177 {
178     MoveRelative( left - Left, top - Top );
179 }
180 //---------------------------------------------------------------------------
181 void GenericControl::MoveRelative( int xOff, int yOff )
182 {
183     Left += xOff;
184     Top  += yOff;
185 }
186 //---------------------------------------------------------------------------
187 SkinRegion *GenericControl::CreateRegionFromBmp( Bitmap *bmp, int MoveX, int MoveY )
188 {
189     // Initialization
190         SkinRegion *Buffer;
191         int w, h;
192         int x = 0, y = 0, x_first = 0;
193         bmp->GetSize( w, h );
194
195         Buffer = (SkinRegion *)new OSRegion;
196
197     // Parse bitmap
198         for( y = 0; y < h; y++ )
199         {
200             for( x = 0; x < w; x++ )
201             {
202
203                 if( bmp->GetBmpPixel( x, y ) == bmp->GetAlphaColor() )
204                 {
205                     if( x_first != x )
206                     {
207                         Buffer->AddRectangle( x_first + MoveX, y + MoveY,
208                                               x + MoveX, y + 1 + MoveY );
209                     }
210                     x_first = x + 1;
211                 }
212             }
213             if( x_first != w )
214             {
215                 Buffer->AddRectangle( x_first + MoveX, y + MoveY,
216                                         w + MoveX, y + 1 + MoveY );
217             }
218             x_first = 0;
219         }
220     // End of parsing
221     return Buffer;
222 }
223 //---------------------------------------------------------------------------
224