]> git.sesse.net Git - vlc/blob - modules/gui/skins/parser/wrappers.cpp
* modules/gui/skins/*: Added a "playondrop" attribute to the "Window"
[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.13 2003/10/22 19:12:56 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 //--- 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, char *playondrop )
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         ConvertBoolean( playondrop ) );
92 }
93 //---------------------------------------------------------------------------
94 void EndWindow()
95 {
96 }
97 //---------------------------------------------------------------------------
98 void StartTheme( char *magnet )
99 {
100     g_pIntf->p_sys->p_theme->StartTheme( atoi( magnet ) );
101 }
102 //---------------------------------------------------------------------------
103 void EndTheme()
104 {
105 }
106 //---------------------------------------------------------------------------
107 void StartControlGroup( char *x, char *y )
108 {
109     g_pIntf->p_sys->p_theme->OffBank->PushOffSet( atoi( x ), atoi( y ) );
110 }
111 //---------------------------------------------------------------------------
112 void EndControlGroup()
113 {
114     g_pIntf->p_sys->p_theme->OffBank->PopOffSet();
115 }
116
117 //---------------------------------------------------------------------------
118 void AddAnchor( char *x, char *y, char *len, char *priority )
119 {
120     int XOff, YOff;
121     SkinWindow *vlcWin = g_pIntf->p_sys->p_theme->WindowList.back();
122
123     g_pIntf->p_sys->p_theme->OffBank->GetOffSet( XOff, YOff );
124     
125     vlcWin->AnchorList.push_back( new Anchor( g_pIntf, atoi( x ) + XOff,
126                                   atoi( y ) + YOff, atoi( len ),
127                                   atoi( priority ), vlcWin ) );
128 }
129 //---------------------------------------------------------------------------
130
131
132
133
134 //---------------------------------------------------------------------------
135 // CONTROLS
136 //---------------------------------------------------------------------------
137 void AddImage( char *id, char *visible, char *x, char *y, char *image,
138     char *event, char *help )
139 {
140     int XOff, YOff;
141     SkinWindow *vlcWin = g_pIntf->p_sys->p_theme->WindowList.back();
142
143     g_pIntf->p_sys->p_theme->OffBank->GetOffSet( XOff, YOff );
144
145     vlcWin->ControlList.push_back( new ControlImage( id,
146         ConvertBoolean( visible ), atoi( x ) + XOff,
147         atoi( y ) + YOff, image, event, help, vlcWin ) );
148 }
149 //---------------------------------------------------------------------------
150 void AddRectangle( char *id, char *visible, char *x, char *y, char *w, char *h,
151     char *color, char *event, char *help )
152 {
153     int XOff, YOff;
154     SkinWindow *vlcWin = g_pIntf->p_sys->p_theme->WindowList.back();
155
156     g_pIntf->p_sys->p_theme->OffBank->GetOffSet( XOff, YOff );
157
158     vlcWin->ControlList.push_back( new ControlRectangle( id,
159         ConvertBoolean( visible ), atoi( x ) + XOff, atoi( y ) + YOff,
160         atoi( w ), atoi( h ), ConvertColor( color ), event, help, vlcWin ) );
161 }
162 //---------------------------------------------------------------------------
163 void AddButton(
164     char *id,
165     char *visible,
166     char *x, char *y,
167     char *up, char *down, char *disabled,
168     char *onclick, char *onmouseover, char *onmouseout,
169     char *tooltiptext, char *help )
170 {
171     int XOff, YOff;
172     SkinWindow *vlcWin = g_pIntf->p_sys->p_theme->WindowList.back();
173
174     g_pIntf->p_sys->p_theme->OffBank->GetOffSet( XOff, YOff );
175
176     vlcWin->ControlList.push_back( new ControlButton(
177         id,
178         ConvertBoolean( visible ),
179         atoi( x ) + XOff, atoi( y ) + YOff,
180         up, down, disabled,
181         onclick, onmouseover, onmouseout,
182         tooltiptext, help,
183         vlcWin ) );
184 }
185 //---------------------------------------------------------------------------
186 void AddCheckBox(
187     char *id,
188     char *visible,
189     char *x, char *y,
190     char *img1, char *img2,
191     char *clickimg1, char *clickimg2, char *disabled1, char *disabled2,
192     char *onclick1, char *onclick2, char *onmouseover1, char *onmouseout1,
193     char *onmouseover2, char *onmouseout2,
194     char *tooltiptext1, char *tooltiptext2, char *help )
195 {
196     int XOff, YOff;
197     SkinWindow *vlcWin = g_pIntf->p_sys->p_theme->WindowList.back();
198
199     g_pIntf->p_sys->p_theme->OffBank->GetOffSet( XOff, YOff );
200
201     vlcWin->ControlList.push_back( new ControlCheckBox(
202         id,
203         ConvertBoolean( visible ),
204         atoi( x ) + XOff, atoi( y ) + YOff,
205         img1, img2, clickimg1, clickimg2, disabled1, disabled2,
206         onclick1, onclick2, onmouseover1, onmouseout1, onmouseover2,
207         onmouseout2,
208         tooltiptext1, tooltiptext2, help, vlcWin ) );
209 }
210 //---------------------------------------------------------------------------
211 void AddSlider( char *id, char *visible, char *x, char *y, char *type, char *up,
212     char *down, char *abs, char *ord, char *tooltiptext, char *help )
213 {
214     int XOff, YOff, i;
215     int res1 = CheckCoords( abs );
216     int res2 = CheckCoords( ord );
217     if( res1 < 2 || res2 < 2 )
218     {
219         msg_Warn( g_pIntf, "Cannot add slider: not enough points" );
220         return;
221     }
222     if( res1 != res2 )
223     {
224         msg_Warn( g_pIntf, "Cannot add slider: invalid list of points" );
225         return;
226     }
227
228     // now, res1 == res2
229     double *p_abs, *p_ord;
230     p_abs = new double[res1];
231     p_ord = new double[res1];
232     ConvertCoords( abs, p_abs );
233     ConvertCoords( ord, p_ord );
234
235     SkinWindow *vlcWin = g_pIntf->p_sys->p_theme->WindowList.back();
236
237     // Move control
238     g_pIntf->p_sys->p_theme->OffBank->GetOffSet( XOff, YOff );
239     for( i = 0; i < res1; i++ )
240     {
241         p_abs[i] += XOff + atoi(x);
242         p_ord[i] += YOff + atoi(y);
243     }
244
245     // Create Control
246     if( g_pIntf->p_sys->p_theme->ConstructPlaylist )
247     {
248         GenericControl *playlist = vlcWin->ControlList.back();
249         ( (ControlPlayList *)playlist )->InitSliderCurve( p_abs, p_ord, res1,
250                                                           up, down );
251     }
252     else
253     {
254         vlcWin->ControlList.push_back( new ControlSlider( id,
255             ConvertBoolean( visible ), type, up, down, p_abs, p_ord, res1,
256             tooltiptext, help, vlcWin ) );
257     }
258
259     delete[] p_abs;
260     delete[] p_ord;
261 }
262 //---------------------------------------------------------------------------
263 void AddPlayList( char *id, char *visible, char *x, char *y, char *width,
264     char *infowidth, char *font, char *playfont, char *selcolor, char *abs,
265     char *ord, char *longfilename, char *help )
266 {
267     g_pIntf->p_sys->p_theme->ConstructPlaylist = true;
268
269     int XOff, YOff, i;
270     int res1 = CheckCoords( abs );
271     int res2 = CheckCoords( ord );
272     if( res1 < 2 || res2 < 2 )
273     {
274         msg_Warn( g_pIntf, "Cannot add slider: not enough points" );
275         return;
276     }
277     if( res1 != res2 )
278     {
279         msg_Warn( g_pIntf, "Cannot add slider: invalid list of points" );
280         return;
281     }
282
283     // now, res1 == res2
284     double *p_abs, *p_ord;
285     p_abs = new double[res1];
286     p_ord = new double[res1];
287     ConvertCoords( abs, p_abs );
288     ConvertCoords( ord, p_ord );
289
290     SkinWindow *vlcWin = g_pIntf->p_sys->p_theme->WindowList.back();
291
292     // Move control
293     g_pIntf->p_sys->p_theme->OffBank->GetOffSet( XOff, YOff );
294     for( i = 0; i < res1; i++ )
295     {
296         p_abs[i] += XOff + atoi(x);
297         p_ord[i] += YOff + atoi(y);
298     }
299
300     // Move control
301     g_pIntf->p_sys->p_theme->OffBank->GetOffSet( XOff, YOff );
302
303     vlcWin->ControlList.push_back( new ControlPlayList( id,
304         ConvertBoolean( visible ), atoi( width ), atoi( infowidth ), font,
305         playfont, ConvertColor( selcolor ), p_abs, p_ord, res1,
306         ConvertBoolean( longfilename ), help, vlcWin ) );
307
308     delete[] p_abs;
309     delete[] p_ord;
310
311 }
312 //---------------------------------------------------------------------------
313 void AddPlayListEnd()
314 {
315     g_pIntf->p_sys->p_theme->ConstructPlaylist = false;
316 }
317 //---------------------------------------------------------------------------
318 void AddText( char *id, char *visible, char *x, char *y, char *text, char *font,
319     char *align, char *width, char *display, char *scroll, char *scrollspace,
320     char *help )
321 {
322     int XOff, YOff;
323     SkinWindow *vlcWin = g_pIntf->p_sys->p_theme->WindowList.back();
324
325     g_pIntf->p_sys->p_theme->OffBank->GetOffSet( XOff, YOff );
326
327     vlcWin->ControlList.push_back( new ControlText( id,
328         ConvertBoolean( visible ), atoi( x ) + XOff,
329         atoi( y ) + YOff, text, font, ConvertAlign( align ), atoi( width ),
330         display, ConvertBoolean( scroll ), atoi( scrollspace ), help,
331         vlcWin ) );
332 }
333 //---------------------------------------------------------------------------
334
335
336
337
338 //---------------------------------------------------------------------------
339 // Useful functions
340 //---------------------------------------------------------------------------
341 static bool ConvertBoolean( const char *value )
342 {
343     return strcmp( value, "true" ) == 0;
344 }
345 //---------------------------------------------------------------------------
346 static int ConvertColor( const char *transcolor )
347 {
348     int iRed, iGreen, iBlue;
349     iRed = iGreen = iBlue = 0;
350     sscanf( transcolor, "#%2X%2X%2X", &iRed, &iGreen, &iBlue );
351     return ( 65536 * iBlue + 256 * iGreen + iRed );
352 }
353 //---------------------------------------------------------------------------
354 // Check that abs and ord contain the same number of comas
355 static int CheckCoords( const char *coord )
356 {
357     int i_coord = 1;
358     while( coord && *coord )
359     {
360         if( *coord == ',' )
361             i_coord++;
362         coord++;
363     }
364     return i_coord;
365 }
366 //---------------------------------------------------------------------------
367 static void ConvertCoords( char *coord, double *p_coord )
368 {
369     int i = 0;
370     char *ptr = coord;
371
372     while( coord && *coord )
373     {
374         if( *coord == ',' )
375         {
376             *coord = '\0';
377             p_coord[i] = atof( ptr );
378             i++;
379             ptr = coord + 1;
380         }
381         coord++;
382     }
383     p_coord[i] = atof( ptr );
384 }
385 //---------------------------------------------------------------------------
386 static int ConvertAlign( char *align )
387 {
388     if( strcmp( align, "left" ) == 0 )
389         return VLC_FONT_ALIGN_LEFT;
390     else if( strcmp( align, "right" ) == 0 )
391         return VLC_FONT_ALIGN_RIGHT;
392     else if( strcmp( align, "center" ) == 0 )
393         return VLC_FONT_ALIGN_CENTER;
394     else
395         return VLC_FONT_ALIGN_LEFT;
396 }
397 //---------------------------------------------------------------------------