]> git.sesse.net Git - vlc/blob - modules/gui/skins/parser/wrappers.cpp
6d615be7b2f6ffaa15ae78d5cdf84e25ff9f26ad
[vlc] / modules / gui / skins / parser / wrappers.cpp
1 /*****************************************************************************
2  * wrappers.cpp: Wrappers around C++ objects
3  *****************************************************************************
4  * Copyright (C) 2003 VideoLAN
5  * $Id: wrappers.cpp,v 1.12 2003/06/22 12:46:49 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 //--- GENERAL ---------------------------------------------------------------
28 #include <stdlib.h>
29 #include <string>
30 using namespace std;
31
32 //--- VLC -------------------------------------------------------------------
33 #include <vlc/intf.h>
34 extern intf_thread_t *g_pIntf;
35
36 //--- SKIN ------------------------------------------------------------------
37 #include "../src/anchor.h"
38 #include "../src/banks.h"
39 #include "../controls/controls.h"
40 #include "../src/font.h"
41 #include "../os_font.h"
42 #include "../src/window.h"
43 #include "../src/theme.h"
44 #include "../src/skin_common.h"
45 #include "wrappers.h"
46
47
48 //---------------------------------------------------------------------------
49 // Local prototypes
50 //---------------------------------------------------------------------------
51 static bool ConvertBoolean( const char *value );
52 static int  ConvertColor( const char *transcolor );
53 static int  CheckCoords( const char *coord );
54 static void ConvertCoords( char *coord, double *p_coord );
55 static int  ConvertAlign( char *align );
56
57 //---------------------------------------------------------------------------
58 // Wrappers
59 //---------------------------------------------------------------------------
60 void AddBitmap( char *name, char *file, char *transcolor )
61 {
62     g_pIntf->p_sys->p_theme->BmpBank->Add( name, file,
63                                            ConvertColor( transcolor ) );
64 }
65 //---------------------------------------------------------------------------
66 void AddEvent( char *name, char *event, char *key )
67 {
68     g_pIntf->p_sys->p_theme->EvtBank->Add( name, event, key );
69 }
70 //---------------------------------------------------------------------------
71 void AddFont( char *name, char *font, char *size, char *color,
72               char *weight, char *italic, char *underline )
73 {
74     g_pIntf->p_sys->p_theme->FntBank->Add(
75         name, font, atoi( size ), ConvertColor( color ), atoi( weight ),
76         ConvertBoolean( italic ), ConvertBoolean( underline ) );
77 }
78 //---------------------------------------------------------------------------
79 void AddThemeInfo( char *name, char *author, char *email, char *webpage )
80 {
81     g_pIntf->p_sys->p_theme->ChangeClientWindowName(
82         "VLC Media Player - " + (string)name );
83 }
84 //---------------------------------------------------------------------------
85 void StartWindow( char *name, char *x, char *y, char *visible, char *fadetime,
86     char *alpha, char *movealpha, char *dragdrop )
87 {
88     g_pIntf->p_sys->p_theme->AddWindow( name, atoi( x ), atoi( y ),
89         ConvertBoolean( visible ), atoi( fadetime ), atoi( alpha ),
90         atoi( movealpha ), ConvertBoolean( dragdrop ) );
91 }
92 //---------------------------------------------------------------------------
93 void EndWindow()
94 {
95 }
96 //---------------------------------------------------------------------------
97 void StartTheme( char *magnet )
98 {
99     g_pIntf->p_sys->p_theme->StartTheme( atoi( magnet ) );
100 }
101 //---------------------------------------------------------------------------
102 void EndTheme()
103 {
104 }
105 //---------------------------------------------------------------------------
106 void StartControlGroup( char *x, char *y )
107 {
108     g_pIntf->p_sys->p_theme->OffBank->PushOffSet( atoi( x ), atoi( y ) );
109 }
110 //---------------------------------------------------------------------------
111 void EndControlGroup()
112 {
113     g_pIntf->p_sys->p_theme->OffBank->PopOffSet();
114 }
115
116 //---------------------------------------------------------------------------
117 void AddAnchor( char *x, char *y, char *len, char *priority )
118 {
119     int XOff, YOff;
120     SkinWindow *vlcWin = g_pIntf->p_sys->p_theme->WindowList.back();
121
122     g_pIntf->p_sys->p_theme->OffBank->GetOffSet( XOff, YOff );
123     
124     vlcWin->AnchorList.push_back( new Anchor( g_pIntf, atoi( x ) + XOff,
125                                   atoi( y ) + YOff, atoi( len ),
126                                   atoi( priority ), vlcWin ) );
127 }
128 //---------------------------------------------------------------------------
129
130
131
132
133 //---------------------------------------------------------------------------
134 // CONTROLS
135 //---------------------------------------------------------------------------
136 void AddImage( char *id, char *visible, char *x, char *y, char *image,
137     char *event, char *help )
138 {
139     int XOff, YOff;
140     SkinWindow *vlcWin = g_pIntf->p_sys->p_theme->WindowList.back();
141
142     g_pIntf->p_sys->p_theme->OffBank->GetOffSet( XOff, YOff );
143
144     vlcWin->ControlList.push_back( new ControlImage( id,
145         ConvertBoolean( visible ), atoi( x ) + XOff,
146         atoi( y ) + YOff, image, event, help, vlcWin ) );
147 }
148 //---------------------------------------------------------------------------
149 void AddRectangle( char *id, char *visible, char *x, char *y, char *w, char *h,
150     char *color, char *event, char *help )
151 {
152     int XOff, YOff;
153     SkinWindow *vlcWin = g_pIntf->p_sys->p_theme->WindowList.back();
154
155     g_pIntf->p_sys->p_theme->OffBank->GetOffSet( XOff, YOff );
156
157     vlcWin->ControlList.push_back( new ControlRectangle( id,
158         ConvertBoolean( visible ), atoi( x ) + XOff, atoi( y ) + YOff,
159         atoi( w ), atoi( h ), ConvertColor( color ), event, help, vlcWin ) );
160 }
161 //---------------------------------------------------------------------------
162 void AddButton(
163     char *id,
164     char *visible,
165     char *x, char *y,
166     char *up, char *down, char *disabled,
167     char *onclick, char *onmouseover, char *onmouseout,
168     char *tooltiptext, char *help )
169 {
170     int XOff, YOff;
171     SkinWindow *vlcWin = g_pIntf->p_sys->p_theme->WindowList.back();
172
173     g_pIntf->p_sys->p_theme->OffBank->GetOffSet( XOff, YOff );
174
175     vlcWin->ControlList.push_back( new ControlButton(
176         id,
177         ConvertBoolean( visible ),
178         atoi( x ) + XOff, atoi( y ) + YOff,
179         up, down, disabled,
180         onclick, onmouseover, onmouseout,
181         tooltiptext, help,
182         vlcWin ) );
183 }
184 //---------------------------------------------------------------------------
185 void AddCheckBox(
186     char *id,
187     char *visible,
188     char *x, char *y,
189     char *img1, char *img2,
190     char *clickimg1, char *clickimg2, char *disabled1, char *disabled2,
191     char *onclick1, char *onclick2, char *onmouseover1, char *onmouseout1,
192     char *onmouseover2, char *onmouseout2,
193     char *tooltiptext1, char *tooltiptext2, char *help )
194 {
195     int XOff, YOff;
196     SkinWindow *vlcWin = g_pIntf->p_sys->p_theme->WindowList.back();
197
198     g_pIntf->p_sys->p_theme->OffBank->GetOffSet( XOff, YOff );
199
200     vlcWin->ControlList.push_back( new ControlCheckBox(
201         id,
202         ConvertBoolean( visible ),
203         atoi( x ) + XOff, atoi( y ) + YOff,
204         img1, img2, clickimg1, clickimg2, disabled1, disabled2,
205         onclick1, onclick2, onmouseover1, onmouseout1, onmouseover2,
206         onmouseout2,
207         tooltiptext1, tooltiptext2, help, vlcWin ) );
208 }
209 //---------------------------------------------------------------------------
210 void AddSlider( char *id, char *visible, char *x, char *y, char *type, char *up,
211     char *down, char *abs, char *ord, char *tooltiptext, char *help )
212 {
213     int XOff, YOff, i;
214     int res1 = CheckCoords( abs );
215     int res2 = CheckCoords( ord );
216     if( res1 < 2 || res2 < 2 )
217     {
218         msg_Warn( g_pIntf, "Cannot add slider: not enough points" );
219         return;
220     }
221     if( res1 != res2 )
222     {
223         msg_Warn( g_pIntf, "Cannot add slider: invalid list of points" );
224         return;
225     }
226
227     // now, res1 == res2
228     double *p_abs, *p_ord;
229     p_abs = new double[res1];
230     p_ord = new double[res1];
231     ConvertCoords( abs, p_abs );
232     ConvertCoords( ord, p_ord );
233
234     SkinWindow *vlcWin = g_pIntf->p_sys->p_theme->WindowList.back();
235
236     // Move control
237     g_pIntf->p_sys->p_theme->OffBank->GetOffSet( XOff, YOff );
238     for( i = 0; i < res1; i++ )
239     {
240         p_abs[i] += XOff + atoi(x);
241         p_ord[i] += YOff + atoi(y);
242     }
243
244     // Create Control
245     if( g_pIntf->p_sys->p_theme->ConstructPlaylist )
246     {
247         GenericControl *playlist = vlcWin->ControlList.back();
248         ( (ControlPlayList *)playlist )->InitSliderCurve( p_abs, p_ord, res1,
249                                                           up, down );
250     }
251     else
252     {
253         vlcWin->ControlList.push_back( new ControlSlider( id,
254             ConvertBoolean( visible ), type, up, down, p_abs, p_ord, res1,
255             tooltiptext, help, vlcWin ) );
256     }
257
258     delete[] p_abs;
259     delete[] p_ord;
260 }
261 //---------------------------------------------------------------------------
262 void AddPlayList( char *id, char *visible, char *x, char *y, char *width,
263     char *infowidth, char *font, char *playfont, char *selcolor, char *abs,
264     char *ord, char *longfilename, char *help )
265 {
266     g_pIntf->p_sys->p_theme->ConstructPlaylist = true;
267
268     int XOff, YOff, i;
269     int res1 = CheckCoords( abs );
270     int res2 = CheckCoords( ord );
271     if( res1 < 2 || res2 < 2 )
272     {
273         msg_Warn( g_pIntf, "Cannot add slider: not enough points" );
274         return;
275     }
276     if( res1 != res2 )
277     {
278         msg_Warn( g_pIntf, "Cannot add slider: invalid list of points" );
279         return;
280     }
281
282     // now, res1 == res2
283     double *p_abs, *p_ord;
284     p_abs = new double[res1];
285     p_ord = new double[res1];
286     ConvertCoords( abs, p_abs );
287     ConvertCoords( ord, p_ord );
288
289     SkinWindow *vlcWin = g_pIntf->p_sys->p_theme->WindowList.back();
290
291     // Move control
292     g_pIntf->p_sys->p_theme->OffBank->GetOffSet( XOff, YOff );
293     for( i = 0; i < res1; i++ )
294     {
295         p_abs[i] += XOff + atoi(x);
296         p_ord[i] += YOff + atoi(y);
297     }
298
299     // Move control
300     g_pIntf->p_sys->p_theme->OffBank->GetOffSet( XOff, YOff );
301
302     vlcWin->ControlList.push_back( new ControlPlayList( id,
303         ConvertBoolean( visible ), atoi( width ), atoi( infowidth ), font,
304         playfont, ConvertColor( selcolor ), p_abs, p_ord, res1,
305         ConvertBoolean( longfilename ), help, vlcWin ) );
306
307     delete[] p_abs;
308     delete[] p_ord;
309
310 }
311 //---------------------------------------------------------------------------
312 void AddPlayListEnd()
313 {
314     g_pIntf->p_sys->p_theme->ConstructPlaylist = false;
315 }
316 //---------------------------------------------------------------------------
317 void AddText( char *id, char *visible, char *x, char *y, char *text, char *font,
318     char *align, char *width, char *display, char *scroll, char *scrollspace,
319     char *help )
320 {
321     int XOff, YOff;
322     SkinWindow *vlcWin = g_pIntf->p_sys->p_theme->WindowList.back();
323
324     g_pIntf->p_sys->p_theme->OffBank->GetOffSet( XOff, YOff );
325
326     vlcWin->ControlList.push_back( new ControlText( id,
327         ConvertBoolean( visible ), atoi( x ) + XOff,
328         atoi( y ) + YOff, text, font, ConvertAlign( align ), atoi( width ),
329         display, ConvertBoolean( scroll ), atoi( scrollspace ), help,
330         vlcWin ) );
331 }
332 //---------------------------------------------------------------------------
333
334
335
336
337 //---------------------------------------------------------------------------
338 // Useful functions
339 //---------------------------------------------------------------------------
340 static bool ConvertBoolean( const char *value )
341 {
342     return strcmp( value, "true" ) == 0;
343 }
344 //---------------------------------------------------------------------------
345 static int ConvertColor( const char *transcolor )
346 {
347     int iRed, iGreen, iBlue;
348     iRed = iGreen = iBlue = 0;
349     sscanf( transcolor, "#%2X%2X%2X", &iRed, &iGreen, &iBlue );
350     return ( 65536 * iBlue + 256 * iGreen + iRed );
351 }
352 //---------------------------------------------------------------------------
353 // Check that abs and ord contain the same number of comas
354 static int CheckCoords( const char *coord )
355 {
356     int i_coord = 1;
357     while( coord && *coord )
358     {
359         if( *coord == ',' )
360             i_coord++;
361         coord++;
362     }
363     return i_coord;
364 }
365 //---------------------------------------------------------------------------
366 static void ConvertCoords( char *coord, double *p_coord )
367 {
368     int i = 0;
369     char *ptr = coord;
370
371     while( coord && *coord )
372     {
373         if( *coord == ',' )
374         {
375             *coord = '\0';
376             p_coord[i] = atof( ptr );
377             i++;
378             ptr = coord + 1;
379         }
380         coord++;
381     }
382     p_coord[i] = atof( ptr );
383 }
384 //---------------------------------------------------------------------------
385 static int ConvertAlign( char *align )
386 {
387     if( strcmp( align, "left" ) == 0 )
388         return VLC_FONT_ALIGN_LEFT;
389     else if( strcmp( align, "right" ) == 0 )
390         return VLC_FONT_ALIGN_RIGHT;
391     else if( strcmp( align, "center" ) == 0 )
392         return VLC_FONT_ALIGN_CENTER;
393     else
394         return VLC_FONT_ALIGN_LEFT;
395 }
396 //---------------------------------------------------------------------------