]> git.sesse.net Git - vlc/blob - modules/gui/skins2/parser/builder.cpp
* skins2/parser/builder*: All the controls now have a 'visible' attribute
[vlc] / modules / gui / skins2 / parser / builder.cpp
1 /*****************************************************************************
2  * builder.cpp
3  *****************************************************************************
4  * Copyright (C) 2003 VideoLAN
5  * $Id$
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 <string.h>
26 #include "builder.hpp"
27 #include "builder_data.hpp"
28 #include "interpreter.hpp"
29 #include "../src/png_bitmap.hpp"
30 #include "../src/os_factory.hpp"
31 #include "../src/generic_bitmap.hpp"
32 #include "../src/top_window.hpp"
33 #include "../src/anchor.hpp"
34 #include "../src/ft2_font.hpp"
35 #include "../src/theme.hpp"
36 #include "../controls/ctrl_button.hpp"
37 #include "../controls/ctrl_checkbox.hpp"
38 #include "../controls/ctrl_image.hpp"
39 #include "../controls/ctrl_list.hpp"
40 #include "../controls/ctrl_move.hpp"
41 #include "../controls/ctrl_resize.hpp"
42 #include "../controls/ctrl_slider.hpp"
43 #include "../controls/ctrl_radialslider.hpp"
44 #include "../controls/ctrl_text.hpp"
45 #include "../controls/ctrl_video.hpp"
46 #include "../utils/position.hpp"
47 #include "../utils/var_bool.hpp"
48 #include "../utils/var_text.hpp"
49
50
51 Builder::Builder( intf_thread_t *pIntf, const BuilderData &rData):
52     SkinObject( pIntf ), m_rData( rData ), m_pTheme( NULL )
53 {
54 }
55
56
57 CmdGeneric *Builder::parseAction( const string &rAction )
58 {
59     return Interpreter::instance( getIntf() )->parseAction( rAction, m_pTheme );
60 }
61
62
63 // Useful macro
64 #define ADD_OBJECTS( type ) \
65     list<BuilderData::type>::const_iterator it##type; \
66     for( it##type = m_rData.m_list##type.begin(); \
67          it##type != m_rData.m_list##type.end(); it##type++ ) \
68     { \
69         add##type( *it##type ); \
70     }
71
72
73 Theme *Builder::build()
74 {
75     m_pTheme = new Theme( getIntf() );
76     if( m_pTheme == NULL )
77     {
78         return NULL;
79     }
80
81     // Create everything from the data in the XML
82     ADD_OBJECTS( Theme );
83     ADD_OBJECTS( Bitmap );
84     ADD_OBJECTS( Font );
85     ADD_OBJECTS( Window );
86     ADD_OBJECTS( Layout );
87     ADD_OBJECTS( Anchor );
88     ADD_OBJECTS( Button );
89     ADD_OBJECTS( Checkbox );
90     ADD_OBJECTS( Image );
91     ADD_OBJECTS( Text );
92     ADD_OBJECTS( RadialSlider );
93     ADD_OBJECTS( Slider );
94     ADD_OBJECTS( List );
95     ADD_OBJECTS( Video );
96
97     return m_pTheme;
98 }
99
100
101 // Macro to get a bitmap by its ID in the builder
102 #define GET_BMP( pBmp, id ) \
103     if( id != "none" ) \
104     { \
105         pBmp = m_pTheme->m_bitmaps[id].get(); \
106         if( pBmp == NULL ) \
107         { \
108             msg_Err( getIntf(), "unknown bitmap id: %s", id.c_str() ); \
109             return; \
110         } \
111     }
112
113 void Builder::addTheme( const BuilderData::Theme &rData )
114 {
115     WindowManager &rManager = m_pTheme->getWindowManager();
116     rManager.setMagnetValue( rData.m_magnet );
117     rManager.setAlphaValue( rData.m_alpha );
118     rManager.setMoveAlphaValue( rData.m_moveAlpha );
119     GenericFont *pFont = getFont( rData.m_tooltipfont );
120     if( pFont )
121     {
122         rManager.createTooltip( *pFont );
123     }
124     else
125     {
126         msg_Warn( getIntf(), "Invalid tooltip font: %s",
127                   rData.m_tooltipfont.c_str() );
128     }
129 }
130
131
132 void Builder::addBitmap( const BuilderData::Bitmap &rData )
133 {
134     GenericBitmap *pBmp = new PngBitmap( getIntf(), rData.m_fileName,
135                                          rData.m_alphaColor );
136     m_pTheme->m_bitmaps[rData.m_id] = GenericBitmapPtr( pBmp );
137 }
138
139
140 void Builder::addFont( const BuilderData::Font &rData )
141 {
142     GenericFont *pFont = new FT2Font( getIntf(), rData.m_fontFile,
143                                       rData.m_size );
144     if( pFont->init() )
145     {
146         m_pTheme->m_fonts[rData.m_id] = GenericFontPtr( pFont );
147     }
148     else
149     {
150         delete pFont;
151     }
152 }
153
154
155 void Builder::addWindow( const BuilderData::Window &rData )
156 {
157     TopWindow *pWin =
158         new TopWindow( getIntf(), rData.m_xPos, rData.m_yPos,
159                            m_pTheme->getWindowManager(),
160                            rData.m_dragDrop, rData.m_playOnDrop );
161
162     m_pTheme->m_windows[rData.m_id] = TopWindowPtr( pWin );
163 }
164
165
166 void Builder::addLayout( const BuilderData::Layout &rData )
167 {
168     TopWindow *pWin = m_pTheme->m_windows[rData.m_windowId].get();
169     if( pWin == NULL )
170     {
171         msg_Err( getIntf(), "unknown window id: %s", rData.m_windowId.c_str() );
172         return;
173     }
174
175     int minWidth = rData.m_minWidth != -1 ? rData.m_minWidth : rData.m_width;
176     int maxWidth = rData.m_maxWidth != -1 ? rData.m_maxWidth : rData.m_width;
177     int minHeight = rData.m_minHeight != -1 ? rData.m_minHeight :
178                     rData.m_height;
179     int maxHeight = rData.m_maxHeight != -1 ? rData.m_maxHeight :
180                     rData.m_height;
181     GenericLayout *pLayout = new GenericLayout( getIntf(), rData.m_width,
182                                                 rData.m_height,
183                                                 minWidth, maxWidth, minHeight,
184                                                 maxHeight );
185     m_pTheme->m_layouts[rData.m_id] = GenericLayoutPtr( pLayout );
186
187     // Attach the layout to its window
188     pWin->setActiveLayout( pLayout );
189 }
190
191
192 void Builder::addAnchor( const BuilderData::Anchor &rData )
193 {
194     TopWindow *pWin = m_pTheme->m_windows[rData.m_windowId].get();
195     if( pWin == NULL )
196     {
197         msg_Err( getIntf(), "unknown window id: %s", rData.m_windowId.c_str() );
198         return;
199     }
200
201     Bezier *pCurve = getPoints( rData.m_points.c_str() );
202     if( pCurve == NULL )
203     {
204         msg_Err( getIntf(), "Invalid format in tag points=\"%s\"",
205                  rData.m_points.c_str() );
206         return;
207     }
208     m_pTheme->m_curves.push_back( BezierPtr( pCurve ) );
209
210     Anchor *pAnc = new Anchor( getIntf(), rData.m_xPos, rData.m_yPos,
211                                rData.m_range, rData.m_priority,
212                                *pCurve, *pWin );
213     pWin->addAnchor( pAnc );
214 }
215
216
217 void Builder::addButton( const BuilderData::Button &rData )
218 {
219     // Get the bitmaps of the button
220     GenericBitmap *pBmpUp = NULL;
221     GET_BMP( pBmpUp, rData.m_upId );
222
223     GenericBitmap *pBmpDown = pBmpUp;
224     GET_BMP( pBmpDown, rData.m_downId );
225
226     GenericBitmap *pBmpOver = pBmpUp;
227     GET_BMP( pBmpOver, rData.m_overId );
228
229     GenericLayout *pLayout = m_pTheme->m_layouts[rData.m_layoutId].get();
230     if( pLayout == NULL )
231     {
232         msg_Err( getIntf(), "unknown layout id: %s", rData.m_layoutId.c_str() );
233         return;
234     }
235
236     CmdGeneric *pCommand = parseAction( rData.m_actionId );
237     if( pCommand == NULL )
238     {
239         msg_Err( getIntf(), "Invalid action: %s", rData.m_actionId.c_str() );
240         return;
241     }
242
243     // Get the visibility variable
244     // XXX check when it is null
245     Interpreter *pInterpreter = Interpreter::instance( getIntf() );
246     VarBool *pVisible = pInterpreter->getVarBool( rData.m_visible, m_pTheme );
247
248     CtrlButton *pButton = new CtrlButton( getIntf(), *pBmpUp, *pBmpOver,
249         *pBmpDown, *pCommand, UString( getIntf(), rData.m_tooltip.c_str() ),
250         UString( getIntf(), rData.m_help.c_str() ), pVisible );
251
252     // Compute the position of the control
253     // XXX (we suppose all the images have the same size...)
254     const Position pos = makePosition( rData.m_leftTop, rData.m_rightBottom,
255                                        rData.m_xPos, rData.m_yPos,
256                                        pBmpUp->getWidth(),
257                                        pBmpUp->getHeight(), *pLayout );
258
259     pLayout->addControl( pButton, pos, rData.m_layer );
260
261     m_pTheme->m_controls[rData.m_id] = CtrlGenericPtr( pButton );
262 }
263
264
265 void Builder::addCheckbox( const BuilderData::Checkbox &rData )
266 {
267     // Get the bitmaps of the checkbox
268     GenericBitmap *pBmpUp1 = NULL;
269     GET_BMP( pBmpUp1, rData.m_up1Id );
270
271     GenericBitmap *pBmpDown1 = pBmpUp1;
272     GET_BMP( pBmpDown1, rData.m_down1Id );
273
274     GenericBitmap *pBmpOver1 = pBmpUp1;
275     GET_BMP( pBmpOver1, rData.m_over1Id );
276
277     GenericBitmap *pBmpUp2 = NULL;
278     GET_BMP( pBmpUp2, rData.m_up2Id );
279
280     GenericBitmap *pBmpDown2 = pBmpUp2;
281     GET_BMP( pBmpDown2, rData.m_down2Id );
282
283     GenericBitmap *pBmpOver2 = pBmpUp2;
284     GET_BMP( pBmpOver2, rData.m_over2Id );
285
286     GenericLayout *pLayout = m_pTheme->m_layouts[rData.m_layoutId].get();
287     if( pLayout == NULL )
288     {
289         msg_Err( getIntf(), "unknown layout id: %s", rData.m_layoutId.c_str() );
290         return;
291     }
292
293     CmdGeneric *pCommand1 = parseAction( rData.m_action1 );
294     if( pCommand1 == NULL )
295     {
296         msg_Err( getIntf(), "Invalid action: %s", rData.m_action1.c_str() );
297         return;
298     }
299
300     CmdGeneric *pCommand2 = parseAction( rData.m_action2 );
301     if( pCommand2 == NULL )
302     {
303         msg_Err( getIntf(), "Invalid action: %s", rData.m_action2.c_str() );
304         return;
305     }
306
307     // Get the state variable
308     Interpreter *pInterpreter = Interpreter::instance( getIntf() );
309     VarBool *pVar = pInterpreter->getVarBool( rData.m_state, m_pTheme );
310     if( pVar == NULL )
311     {
312         // TODO: default state
313         return;
314     }
315
316     // Get the visibility variable
317     // XXX check when it is null
318     VarBool *pVisible = pInterpreter->getVarBool( rData.m_visible, m_pTheme );
319
320     // Create the control
321     CtrlCheckbox *pCheckbox = new CtrlCheckbox( getIntf(), *pBmpUp1,
322         *pBmpOver1, *pBmpDown1, *pBmpUp2, *pBmpOver2, *pBmpDown2, *pCommand1,
323         *pCommand2, UString( getIntf(), rData.m_tooltip1.c_str() ),
324         UString( getIntf(), rData.m_tooltip2.c_str() ), *pVar,
325         UString( getIntf(), rData.m_help.c_str() ), pVisible );
326
327     // Compute the position of the control
328     // XXX (we suppose all the images have the same size...)
329     const Position pos = makePosition( rData.m_leftTop, rData.m_rightBottom,
330                                        rData.m_xPos, rData.m_yPos,
331                                        pBmpUp1->getWidth(),
332                                        pBmpUp1->getHeight(), *pLayout );
333
334     pLayout->addControl( pCheckbox, pos, rData.m_layer );
335
336     m_pTheme->m_controls[rData.m_id] = CtrlGenericPtr( pCheckbox );
337 }
338
339
340 void Builder::addImage( const BuilderData::Image &rData )
341 {
342     GenericBitmap *pBmp = NULL;
343     GET_BMP( pBmp, rData.m_bmpId );
344
345     GenericLayout *pLayout = m_pTheme->m_layouts[rData.m_layoutId].get();
346     if( pLayout == NULL )
347     {
348         msg_Err( getIntf(), "unknown layout id: %s", rData.m_layoutId.c_str() );
349         return;
350     }
351
352     TopWindow *pWindow = m_pTheme->m_windows[rData.m_windowId].get();
353     if( pWindow == NULL )
354     {
355         msg_Err( getIntf(), "unknown window id: %s", rData.m_windowId.c_str() );
356         return;
357     }
358
359     // Get the visibility variable
360     // XXX check when it is null
361     Interpreter *pInterpreter = Interpreter::instance( getIntf() );
362     VarBool *pVisible = pInterpreter->getVarBool( rData.m_visible, m_pTheme );
363
364     CtrlImage *pImage = new CtrlImage( getIntf(), *pBmp,
365         UString( getIntf(), rData.m_help.c_str() ), pVisible );
366
367     // Compute the position of the control
368     const Position pos = makePosition( rData.m_leftTop, rData.m_rightBottom,
369                                        rData.m_xPos,
370                                        rData.m_yPos, pBmp->getWidth(),
371                                        pBmp->getHeight(), *pLayout );
372
373     // XXX: test to be changed! XXX
374     if( rData.m_actionId == "move" )
375     {
376         CtrlMove *pMove = new CtrlMove( getIntf(), m_pTheme->getWindowManager(),
377              *pImage, *pWindow, UString( getIntf(), rData.m_help.c_str() ),
378              NULL);
379         pLayout->addControl( pMove, pos, rData.m_layer );
380     }
381     else if( rData.m_actionId == "resize" )
382     {
383         CtrlResize *pResize = new CtrlResize( getIntf(), *pImage, *pLayout,
384                 UString( getIntf(), rData.m_help.c_str() ), NULL );
385         pLayout->addControl( pResize, pos, rData.m_layer );
386     }
387     else
388     {
389         pLayout->addControl( pImage, pos, rData.m_layer );
390     }
391
392     m_pTheme->m_controls[rData.m_id] = CtrlGenericPtr( pImage );
393 }
394
395
396 void Builder::addText( const BuilderData::Text &rData )
397 {
398     GenericLayout *pLayout = m_pTheme->m_layouts[rData.m_layoutId].get();
399     if( pLayout == NULL )
400     {
401         msg_Err( getIntf(), "unknown layout id: %s", rData.m_layoutId.c_str() );
402         return;
403     }
404
405     GenericFont *pFont = getFont( rData.m_fontId );
406     if( pFont == NULL )
407     {
408         msg_Err( getIntf(), "Unknown font id: %s", rData.m_fontId.c_str() );
409         return;
410     }
411
412     // Create a text variable
413     VarText *pVar = new VarText( getIntf() );
414     UString msg( getIntf(), rData.m_text.c_str() );
415     pVar->set( msg );
416     m_pTheme->m_vars.push_back( VariablePtr( pVar ) );
417
418     // Get the visibility variable
419     // XXX check when it is null
420     Interpreter *pInterpreter = Interpreter::instance( getIntf() );
421     VarBool *pVisible = pInterpreter->getVarBool( rData.m_visible, m_pTheme );
422
423     CtrlText *pText = new CtrlText( getIntf(), *pVar, *pFont,
424         UString( getIntf(), rData.m_help.c_str() ), rData.m_color, pVisible );
425
426     int height = pFont->getSize();
427
428     pLayout->addControl( pText, Position( rData.m_xPos, rData.m_yPos,
429                                           rData.m_xPos + rData.m_width,
430                                           rData.m_yPos + height, *pLayout ),
431                          rData.m_layer );
432
433     m_pTheme->m_controls[rData.m_id] = CtrlGenericPtr( pText );
434 }
435
436
437 void Builder::addRadialSlider( const BuilderData::RadialSlider &rData )
438 {
439     // Get the bitmaps of the slider
440     GenericBitmap *pSeq = NULL;
441     GET_BMP( pSeq, rData.m_sequence );
442
443     GenericLayout *pLayout = m_pTheme->m_layouts[rData.m_layoutId].get();
444     if( pLayout == NULL )
445     {
446         msg_Err( getIntf(), "unknown layout id: %s", rData.m_layoutId.c_str() );
447         return;
448     }
449
450     // Get the variable associated to the slider
451     Interpreter *pInterpreter = Interpreter::instance( getIntf() );
452     VarPercent *pVar = pInterpreter->getVarPercent( rData.m_value, m_pTheme );
453     if( pVar == NULL )
454     {
455         msg_Err( getIntf(), "Unknown slider value: %s", rData.m_value.c_str() );
456         return;
457     }
458
459     // Get the visibility variable
460     // XXX check when it is null
461     VarBool *pVisible = pInterpreter->getVarBool( rData.m_visible, m_pTheme );
462
463     // Create the control
464     CtrlRadialSlider *pRadial =
465         new CtrlRadialSlider( getIntf(), *pSeq, rData.m_nbImages, *pVar,
466                               rData.m_minAngle, rData.m_maxAngle,
467                               UString( getIntf(), rData.m_help.c_str() ),
468                               pVisible );
469
470     // XXX: resizing is not supported
471     // Compute the position of the control
472     const Position pos =
473         makePosition( rData.m_leftTop, rData.m_rightBottom, rData.m_xPos,
474                       rData.m_yPos, pSeq->getWidth(),
475                       pSeq->getHeight() / rData.m_nbImages, *pLayout );
476
477     pLayout->addControl( pRadial, pos, rData.m_layer );
478
479     m_pTheme->m_controls[rData.m_id] = CtrlGenericPtr( pRadial );
480 }
481
482
483 void Builder::addSlider( const BuilderData::Slider &rData )
484 {
485     // Get the bitmaps of the slider
486     GenericBitmap *pBmpUp = NULL;
487     GET_BMP( pBmpUp, rData.m_upId );
488
489     GenericBitmap *pBmpDown = pBmpUp;
490     GET_BMP( pBmpDown, rData.m_downId );
491
492     GenericBitmap *pBmpOver = pBmpUp;
493     GET_BMP( pBmpOver, rData.m_overId );
494
495     GenericLayout *pLayout = m_pTheme->m_layouts[rData.m_layoutId].get();
496     if( pLayout == NULL )
497     {
498         msg_Err( getIntf(), "unknown layout id: %s", rData.m_layoutId.c_str() );
499         return;
500     }
501
502     Bezier *pCurve = getPoints( rData.m_points.c_str() );
503     if( pCurve == NULL )
504     {
505         msg_Err( getIntf(), "Invalid format in tag points=\"%s\"",
506                  rData.m_points.c_str() );
507         return;
508     }
509     m_pTheme->m_curves.push_back( BezierPtr( pCurve ) );
510
511     // Get the visibility variable
512     // XXX check when it is null
513     Interpreter *pInterpreter = Interpreter::instance( getIntf() );
514     VarBool *pVisible = pInterpreter->getVarBool( rData.m_visible, m_pTheme );
515
516     // Get the variable associated to the slider
517     VarPercent *pVar = pInterpreter->getVarPercent( rData.m_value, m_pTheme );
518     if( pVar == NULL )
519     {
520         msg_Err( getIntf(), "Unknown slider value: %s", rData.m_value.c_str() );
521         return;
522     }
523
524     // Create the cursor and background controls
525     CtrlSliderCursor *pCursor = new CtrlSliderCursor( getIntf(), *pBmpUp,
526         *pBmpOver, *pBmpDown, *pCurve, *pVar, pVisible,
527         UString( getIntf(), rData.m_tooltip.c_str() ),
528         UString( getIntf(), rData.m_help.c_str() ) );
529
530     CtrlSliderBg *pBackground = new CtrlSliderBg( getIntf(), *pCursor,
531         *pCurve, *pVar, rData.m_thickness, pVisible,
532         UString( getIntf(), rData.m_help.c_str() ) );
533
534     // Compute the position of the control
535     const Position pos = makePosition( rData.m_leftTop, rData.m_rightBottom,
536                                        rData.m_xPos, rData.m_yPos,
537                                        pCurve->getWidth(), pCurve->getHeight(),
538                                        *pLayout );
539
540     pLayout->addControl( pBackground, pos, rData.m_layer );
541     pLayout->addControl( pCursor, pos, rData.m_layer );
542
543     m_pTheme->m_controls[rData.m_id] = CtrlGenericPtr( pCursor );
544     m_pTheme->m_controls[rData.m_id + "_bg"] = CtrlGenericPtr( pBackground );
545 }
546
547
548 void Builder::addList( const BuilderData::List &rData )
549 {
550     GenericLayout *pLayout = m_pTheme->m_layouts[rData.m_layoutId].get();
551     if( pLayout == NULL )
552     {
553         msg_Err( getIntf(), "unknown layout id: %s", rData.m_layoutId.c_str() );
554         return;
555     }
556
557     GenericFont *pFont = getFont( rData.m_fontId );
558     if( pFont == NULL )
559     {
560         msg_Err( getIntf(), "Unknown font id: %s", rData.m_fontId.c_str() );
561         return;
562     }
563
564     // Get the list variable
565     Interpreter *pInterpreter = Interpreter::instance( getIntf() );
566     VarList *pVar = pInterpreter->getVarList( rData.m_var, m_pTheme );
567     if( pVar == NULL )
568     {
569         msg_Err( getIntf(), "No such list variable: %s", rData.m_var.c_str() );
570         return;
571     }
572
573     // Get the visibility variable
574     // XXX check when it is null
575     VarBool *pVisible = pInterpreter->getVarBool( rData.m_visible, m_pTheme );
576
577     // Create the list control
578     CtrlList *pList = new CtrlList( getIntf(), *pVar, *pFont,
579        rData.m_fgColor, rData.m_playColor, rData.m_bgColor1,
580        rData.m_bgColor2, rData.m_selColor,
581        UString( getIntf(), rData.m_help.c_str() ), pVisible );
582
583     // Compute the position of the control
584     const Position pos = makePosition( rData.m_leftTop, rData.m_rightBottom,
585                                        rData.m_xPos, rData.m_yPos,
586                                        rData.m_width, rData.m_height,
587                                        *pLayout );
588
589     pLayout->addControl( pList, pos, rData.m_layer );
590
591     m_pTheme->m_controls[rData.m_id] = CtrlGenericPtr( pList );
592 }
593
594
595 void Builder::addVideo( const BuilderData::Video &rData )
596 {
597     GenericLayout *pLayout = m_pTheme->m_layouts[rData.m_layoutId].get();
598     if( pLayout == NULL )
599     {
600         msg_Err( getIntf(), "unknown layout id: %s", rData.m_layoutId.c_str() );
601         return;
602     }
603
604     // Get the visibility variable
605     // XXX check when it is null
606     Interpreter *pInterpreter = Interpreter::instance( getIntf() );
607     VarBool *pVisible = pInterpreter->getVarBool( rData.m_visible, m_pTheme );
608
609     CtrlVideo *pVideo = new CtrlVideo( getIntf(),
610         UString( getIntf(), rData.m_help.c_str() ), pVisible );
611
612     // Compute the position of the control
613     const Position pos = makePosition( rData.m_leftTop, rData.m_rightBottom,
614                                        rData.m_xPos, rData.m_yPos,
615                                        rData.m_width, rData.m_height,
616                                        *pLayout );
617
618     pLayout->addControl( pVideo, pos, rData.m_layer );
619
620     m_pTheme->m_controls[rData.m_id] = CtrlGenericPtr( pVideo );
621 }
622
623
624 const Position Builder::makePosition( const string &rLeftTop,
625                                       const string &rRightBottom,
626                                       int xPos, int yPos, int width,
627                                       int height, const Box &rBox ) const
628 {
629     int left = 0, top = 0, right = 0, bottom = 0;
630     Position::Ref_t refLeftTop = Position::kLeftTop;
631     Position::Ref_t refRightBottom = Position::kLeftTop;
632
633     int boxWidth = rBox.getWidth();
634     int boxHeight = rBox.getHeight();
635
636     // Position of the left top corner
637     if( rLeftTop == "lefttop" )
638     {
639         left = xPos;
640         top = yPos;
641         refLeftTop = Position::kLeftTop;
642     }
643     else if( rLeftTop == "righttop" )
644     {
645         left = xPos - boxWidth + 1;
646         top = yPos;
647         refLeftTop = Position::kRightTop;
648     }
649     else if( rLeftTop == "leftbottom" )
650     {
651         left = xPos;
652         top = yPos - boxHeight + 1;
653         refLeftTop = Position::kLeftBottom;
654     }
655     else if( rLeftTop == "rightbottom" )
656     {
657         left = xPos - boxWidth + 1;
658         top = yPos - boxHeight + 1;
659         refLeftTop = Position::kRightBottom;
660     }
661
662     // Position of the right bottom corner
663     if( rRightBottom == "lefttop" )
664     {
665         right = xPos + width - 1;
666         bottom = yPos + height - 1;
667         refRightBottom = Position::kLeftTop;
668     }
669     else if( rRightBottom == "righttop" )
670     {
671         right = xPos + width - boxWidth;
672         bottom = yPos + height - 1;
673         refRightBottom = Position::kRightTop;
674     }
675     else if( rRightBottom == "leftbottom" )
676     {
677         right = xPos + width - 1;
678         bottom = yPos + height - boxHeight;
679         refRightBottom = Position::kLeftBottom;
680     }
681     else if( rRightBottom == "rightbottom" )
682     {
683         right = xPos + width - boxWidth;
684         bottom = yPos + height - boxHeight;
685         refRightBottom = Position::kRightBottom;
686     }
687
688     return Position( left, top, right, bottom, rBox, refLeftTop,
689                      refRightBottom );
690 }
691
692
693 GenericFont *Builder::getFont( const string &fontId )
694 {
695     GenericFont *pFont = m_pTheme->m_fonts[fontId].get();
696     if( !pFont && fontId == "defaultfont" )
697     {
698 #ifdef WIN32_SKINS
699         string defaultFont = (string)getIntf()->p_libvlc->psz_vlcpath +
700                              "\\skins2\\fonts\\FreeSans.ttf";
701 #else
702         string defaultFont = (string)DATA_PATH + "/skins2/fonts/FreeSans.ttf";
703 #endif
704         pFont = new FT2Font( getIntf(), defaultFont, 12 );
705         if( pFont->init() )
706         {
707             m_pTheme->m_fonts["defaultfont"] = GenericFontPtr( pFont );
708         }
709         else
710         {
711             delete pFont;
712             pFont = NULL;
713         }
714     }
715     return pFont;
716 }
717
718
719 Bezier *Builder::getPoints( const char *pTag ) const
720 {
721     vector<float> xBez, yBez;
722     int x, y, n;
723     while( 1 )
724     {
725         if( sscanf( pTag, "(%d,%d)%n", &x, &y, &n ) < 1 )
726         {
727             return NULL;
728         }
729 #if 0
730         if( x < 0 || y < 0 )
731         {
732             msg_Err( getIntf(),
733                      "Slider points cannot have negative coordinates!" );
734             return NULL;
735         }
736 #endif
737         xBez.push_back( x );
738         yBez.push_back( y );
739         pTag += n;
740         if( *pTag == '\0' )
741         {
742             break;
743         }
744         if( *(pTag++) != ',' )
745         {
746             return NULL;
747         }
748     }
749
750     // Create the Bezier curve
751     return new Bezier( getIntf(), xBez, yBez );
752 }
753