]> git.sesse.net Git - vlc/blob - modules/gui/skins2/parser/wrappers.cpp
* all: brand new skins interface ( still _experimental_) for x11 and
[vlc] / modules / gui / skins2 / parser / wrappers.cpp
1 /*****************************************************************************
2  * wrappers.cpp
3  *****************************************************************************
4  * Copyright (C) 2003 VideoLAN
5  * $Id: wrappers.cpp,v 1.1 2004/01/03 23:31:33 asmax Exp $
6  *
7  * Authors: Cyril Deguet     <asmax@via.ecp.fr>
8  *          Olivier Teulière <ipkiss@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, USA.
23  *****************************************************************************/
24
25 #include <math.h>
26 #include "wrappers.h"
27 #include "parser_context.hpp"
28
29 // Current DTD version
30 #define SKINS_DTD_VERSION "2.0"
31
32 // Local functions
33 static bool ConvertBoolean( const char *value );
34 static int  ConvertColor( const char *transcolor );
35
36 // Useful macros
37 #define DATA ((ParserContext*)pContext)->m_data
38 #define WIN_ID ((ParserContext*)pContext)->m_curWindowId
39 #define LAY_ID ((ParserContext*)pContext)->m_curLayoutId
40 #define CUR_LIST ((ParserContext*)pContext)->m_curListId
41 #define X_OFFSET ((ParserContext*)pContext)->m_xOffset
42 #define Y_OFFSET ((ParserContext*)pContext)->m_yOffset
43 #define LAYER ((ParserContext*)pContext)->m_curLayer
44
45
46 void AddBitmap( void *pContext, char *name, char *file,
47                 char *transcolor )
48 {
49     const BuilderData::Bitmap bitmap( name, file,
50                                       ConvertColor( transcolor ) );
51     DATA.m_listBitmap.push_back( bitmap );
52 }
53
54
55 void AddEvent( void *pContext, char *name, char *event, char *key )
56 {
57 //    const BuilderData:: Command( name, event, key );
58 }
59
60
61 void AddFont( void *pContext, char *name, char *font, char *size,
62               char *color, char *italic, char *underline )
63 {
64     const BuilderData::Font fontData( name, font, atoi( size ) );
65     DATA.m_listFont.push_back( fontData );
66 }
67
68
69 void AddThemeInfo( void *pContext, char *name, char *author,
70                    char *email, char *webpage )
71 {
72     msg_Warn( ((ParserContext*)pContext)->m_pIntf,
73               "skin: %s  author: %s", name, author );
74 }
75
76
77 void StartWindow( void *pContext, char *name, char *x, char *y,
78                   char *visible, char *dragdrop, char *playOnDrop )
79 {
80     const BuilderData::Window window( name, atoi( x ) + X_OFFSET,
81         atoi( y ) + Y_OFFSET, ConvertBoolean( visible ),
82         ConvertBoolean( dragdrop ), ConvertBoolean( playOnDrop ));
83     DATA.m_listWindow.push_back( window );
84     WIN_ID = name;
85 }
86
87
88 void EndWindow( void *pContext )
89 {
90 //    ((Builder*)pContext)->endWindow();
91 }
92
93
94 void StartLayout( void *pContext, char *id, char *width, char *height,
95                   char *minwidth, char *maxwidth, char *minheight,
96                   char *maxheight )
97 {
98     const BuilderData::Layout layout( id, atoi( width ), atoi( height ),
99                                       atoi( minwidth ), atoi( maxwidth ),
100                                       atoi( minheight ), atoi( maxheight ),
101                                       WIN_ID );
102     DATA.m_listLayout.push_back( layout );
103     LAY_ID = id;
104     LAYER = 0;
105 }
106
107
108 void EndLayout( void *pContext )
109 {
110 //    ((Builder*)pContext)->endLayout();
111 }
112
113
114 void StartTheme( void *pContext, char *version, char *magnet,
115                  char *alpha, char *movealpha, char *fadetime )
116 {
117     // Check the version
118     if( strcmp( version, SKINS_DTD_VERSION ) )
119     {
120         msg_Err( ((ParserContext*)pContext)->m_pIntf, "Bad theme version :"
121                  " %s (you need version %s)", version, SKINS_DTD_VERSION );
122     }
123     const BuilderData::Theme theme( atoi( magnet ),
124         atoi( alpha ), atoi( movealpha ), atoi( fadetime ) );
125     DATA.m_listTheme.push_back( theme );
126 }
127
128
129 void EndTheme( void *pContext )
130 {
131  //   ((Builder*)pContext)->endTheme();
132 }
133
134
135 void StartGroup( void *pContext, char *x, char *y )
136 {
137     X_OFFSET += atoi( x );
138     Y_OFFSET += atoi( y );
139     ((ParserContext*)pContext)->m_xOffsetList.push_back( atoi( x ) );
140     ((ParserContext*)pContext)->m_yOffsetList.push_back( atoi( y ) );
141 }
142
143
144 void EndGroup( void *pContext )
145 {
146     X_OFFSET -= ((ParserContext*)pContext)->m_xOffsetList.back();
147     Y_OFFSET -= ((ParserContext*)pContext)->m_yOffsetList.back();
148     ((ParserContext*)pContext)->m_xOffsetList.pop_back();
149     ((ParserContext*)pContext)->m_yOffsetList.pop_back();
150 }
151
152
153 void AddAnchor( void *pContext, char *x, char *y, char *len,
154                 char *priority )
155 {
156     const BuilderData::Anchor anchor( atoi( x ) + X_OFFSET,
157         atoi( y ) + Y_OFFSET, atoi( len ), atoi( priority ), WIN_ID );
158     DATA.m_listAnchor.push_back( anchor );
159 }
160
161
162 //---------------------------------------------------------------------------
163 // CONTROLS
164 //---------------------------------------------------------------------------
165 void AddImage( void *pContext, char *id, char *visible, char *x,
166                char *y, char *lefttop, char *rightbottom, char *image,
167                char *event, char *help )
168 {
169     const BuilderData::Image imageData( id, atoi( x ) + X_OFFSET,
170         atoi( y ) + Y_OFFSET, lefttop, rightbottom, ConvertBoolean( visible ),
171         image, event, help, LAYER, WIN_ID, LAY_ID );
172     LAYER++;
173     DATA.m_listImage.push_back( imageData );
174 }
175
176
177 void AddRectangle( void *pContext, char *id, char *visible, char *x,
178                    char *y, char *w, char *h, char *color, char *event,
179                    char *help )
180 {
181 //    msg_Warn( ((Builder*)pContext)->getIntf(), "Do we _really_ need a Rectangle control?" );
182 }
183
184
185 void AddButton( void *pContext,
186     char *id,
187     char *x, char *y, char *lefttop, char *rightbottom,
188     char *up, char *down, char *over,
189     char *action, char *tooltiptext, char *help )
190 {
191     const BuilderData::Button button( id, atoi( x ) + X_OFFSET,
192         atoi( y ) + Y_OFFSET, lefttop, rightbottom, up, down, over, action,
193         tooltiptext, help, LAYER, WIN_ID, LAY_ID );
194     LAYER++;
195     DATA.m_listButton.push_back( button );
196 }
197
198
199 void AddCheckBox( void *pContext, char *id,
200                   char *x, char *y, char *lefttop, char *rightbottom,
201                   char *up1, char *down1, char *over1, char *up2,
202                   char *down2, char *over2, char *state, char *action1,
203                   char *action2, char *tooltiptext1, char *tooltiptext2,
204                   char *help )
205 {
206     const BuilderData::Checkbox checkbox( id, atoi( x ) + X_OFFSET,
207         atoi( y ) + Y_OFFSET, lefttop, rightbottom, up1, down1, over1, up2,
208         down2, over2, state, action1, action2, tooltiptext1, tooltiptext2,
209         help, LAYER, WIN_ID, LAY_ID );
210     LAYER++;
211     DATA.m_listCheckbox.push_back( checkbox );
212 }
213
214
215 void AddSlider( void *pContext, char *id, char *visible, char *x, char *y,
216                 char *lefttop, char *rightbottom,
217                 char *up, char *down, char *over, char *points,
218                 char *thickness, char *value, char *tooltiptext, char *help )
219 {
220     string newValue = value;
221     if( CUR_LIST != "" )
222     {
223         // Slider associated to a list
224         // XXX
225         newValue = "playlist.slider";
226     }
227     const BuilderData::Slider slider( id, visible, atoi( x ) + X_OFFSET,
228         atoi( y ) + Y_OFFSET, lefttop, rightbottom, up, down, over, points,
229         atoi( thickness ), newValue, tooltiptext, help, LAYER, WIN_ID, LAY_ID );
230     LAYER++;
231     DATA.m_listSlider.push_back( slider );
232 }
233
234
235 void AddRadialSlider( void *pContext, char *id, char *visible, char *x, char *y,
236                       char *lefttop, char *rightbottom, char *sequence,
237                       char *nbImages, char *minAngle, char *maxAngle,
238                       char *value, char *tooltiptext, char *help )
239 {
240     const BuilderData::RadialSlider radial( id, visible, atoi( x ) + X_OFFSET,
241         atoi( y ) + Y_OFFSET, lefttop, rightbottom, sequence, atoi( nbImages ),
242         atof( minAngle ) * M_PI / 180, atof( maxAngle ) * M_PI / 180, value,
243         tooltiptext, help, LAYER, WIN_ID, LAY_ID );
244     LAYER++;
245     DATA.m_listRadialSlider.push_back( radial );
246 }
247
248
249 void AddPlaylist( void *pContext, char *id, char *visible, char *x,
250                   char *y, char *width, char *height, char *lefttop,
251                   char *rightbottom, char *font, char *var, char *fgcolor,
252                   char *playcolor, char *bgcolor1, char *bgcolor2,
253                   char *selcolor, char *help )
254 {
255     const BuilderData::List listData( id, atoi( x ) + X_OFFSET,
256         atoi( y ) + Y_OFFSET, atoi( width), atoi( height ), lefttop,
257         rightbottom, font, var, ConvertColor( fgcolor ),
258         ConvertColor( playcolor ), ConvertColor( bgcolor1 ),
259         ConvertColor( bgcolor2 ), ConvertColor( selcolor ), help, LAYER,
260         WIN_ID, LAY_ID );
261     LAYER++;
262     CUR_LIST = id;
263     DATA.m_listList.push_back( listData );
264 }
265
266
267 void AddPlaylistEnd( void *pContext )
268 {
269     CUR_LIST = "";
270 }
271
272
273 void AddText( void *pContext, char *id, char *visible, char *x,
274               char *y, char *text, char *font, char *align, char *width,
275               char *display, char *scroll, char *scrollspace, char *help )
276 {
277     const BuilderData::Text textData( id, atoi( x ) + X_OFFSET,
278         atoi( y ) + Y_OFFSET, font, text, atoi( width ), help, LAYER, WIN_ID,
279         LAY_ID );
280     LAYER++;
281     DATA.m_listText.push_back( textData );
282 }
283
284
285
286
287 //---------------------------------------------------------------------------
288 // Useful functions
289 //---------------------------------------------------------------------------
290
291 static bool ConvertBoolean( const char *value )
292 {
293     return strcmp( value, "true" ) == 0;
294 }
295
296
297 static int ConvertColor( const char *transcolor )
298 {
299     unsigned long iRed, iGreen, iBlue;
300     iRed = iGreen = iBlue = 0;
301     sscanf( transcolor, "#%2lX%2lX%2lX", &iRed, &iGreen, &iBlue );
302     return ( iRed << 16 | iGreen << 8 | iBlue );
303 }
304