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