]> git.sesse.net Git - vlc/blob - modules/gui/skins2/parser/builder.cpp
06196f9c350e1980dfb12af2c7a8bdd79b3f5872
[vlc] / modules / gui / skins2 / parser / builder.cpp
1 /*****************************************************************************
2  * builder.cpp
3  *****************************************************************************
4  * Copyright (C) 2003 the VideoLAN team
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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23  *****************************************************************************/
24
25 #include "builder.hpp"
26 #include "builder_data.hpp"
27 #include "interpreter.hpp"
28 #include "skin_parser.hpp"
29 #include "../src/file_bitmap.hpp"
30 #include "../src/os_factory.hpp"
31 #include "../src/generic_bitmap.hpp"
32 #include "../src/top_window.hpp"
33 #include "../src/fsc_window.hpp"
34 #include "../src/anchor.hpp"
35 #include "../src/bitmap_font.hpp"
36 #include "../src/ft2_font.hpp"
37 #include "../src/ini_file.hpp"
38 #include "../src/generic_layout.hpp"
39 #include "../src/popup.hpp"
40 #include "../src/theme.hpp"
41 #include "../src/window_manager.hpp"
42 #include "../src/vout_manager.hpp"
43 #include "../commands/cmd_generic.hpp"
44 #include "../controls/ctrl_button.hpp"
45 #include "../controls/ctrl_checkbox.hpp"
46 #include "../controls/ctrl_image.hpp"
47 #include "../controls/ctrl_list.hpp"
48 #include "../controls/ctrl_move.hpp"
49 #include "../controls/ctrl_resize.hpp"
50 #include "../controls/ctrl_slider.hpp"
51 #include "../controls/ctrl_radialslider.hpp"
52 #include "../controls/ctrl_text.hpp"
53 #include "../controls/ctrl_tree.hpp"
54 #include "../controls/ctrl_video.hpp"
55 #include "../utils/bezier.hpp"
56 #include "../utils/position.hpp"
57 #include "../utils/var_bool.hpp"
58 #include "../utils/var_text.hpp"
59
60 #include <vlc_image.h>
61 #include <fstream>
62
63
64 Builder::Builder( intf_thread_t *pIntf, const BuilderData &rData,
65                   const string &rPath ):
66     SkinObject( pIntf ), m_rData( rData ), m_path( rPath ), m_pTheme( NULL )
67 {
68     m_pImageHandler = image_HandlerCreate( pIntf );
69 }
70
71 Builder::~Builder()
72 {
73     if( m_pImageHandler ) image_HandlerDelete( m_pImageHandler );
74 }
75
76 CmdGeneric *Builder::parseAction( const string &rAction )
77 {
78     return Interpreter::instance( getIntf() )->parseAction( rAction, m_pTheme );
79 }
80
81 template<class T> inline
82 void Builder::add_objects(const std::list<T> &list,
83                           void (Builder::*addfn)(const T &))
84 {
85     typename std::list<T>::const_iterator i;
86     for( i = list.begin(); i != list.end(); ++i )
87         (this->*addfn)( *i );
88 }
89
90 Theme *Builder::build()
91 {
92 #define ADD_OBJECTS( type ) \
93     add_objects(m_rData.m_list##type,&Builder::add##type)
94
95     m_pTheme = new (std::nothrow) Theme( getIntf() );
96     if( m_pTheme == NULL )
97         return NULL;
98
99     // Create everything from the data in the XML
100     ADD_OBJECTS( Theme );
101     ADD_OBJECTS( IniFile );
102     ADD_OBJECTS( Bitmap );
103     ADD_OBJECTS( SubBitmap );
104     ADD_OBJECTS( BitmapFont );
105     ADD_OBJECTS( Font );
106     ADD_OBJECTS( Window );
107     // XXX: PopupMenus are created after the windows, so that the Win32Factory
108     // (at least) can give a valid window handle to the OSPopup objects
109     ADD_OBJECTS( PopupMenu );
110     ADD_OBJECTS( Layout );
111     ADD_OBJECTS( Panel );
112     ADD_OBJECTS( Anchor );
113     ADD_OBJECTS( Button );
114     ADD_OBJECTS( Checkbox );
115     ADD_OBJECTS( Image );
116     ADD_OBJECTS( Text );
117     ADD_OBJECTS( RadialSlider );
118     ADD_OBJECTS( Slider );
119     ADD_OBJECTS( List );
120     ADD_OBJECTS( Tree );
121     ADD_OBJECTS( Video );
122     // MenuItems must be created after all the rest, so that the IDs of the
123     // other elements exist and can be parsed in the actions
124     ADD_OBJECTS( MenuItem );
125     ADD_OBJECTS( MenuSeparator );
126
127     return m_pTheme;
128
129 #undef  ADD_OBJECTS
130 }
131
132
133 // Macro to get a bitmap by its ID in the builder
134 #define GET_BMP( pBmp, id ) \
135     if( id != "none" ) \
136     { \
137         pBmp = m_pTheme->getBitmapById(id); \
138         if( pBmp == NULL ) \
139         { \
140             msg_Err( getIntf(), "unknown bitmap id: %s", id.c_str() ); \
141             return; \
142         } \
143     }
144
145 // macro to check bitmap size consistency for button and checkbox
146 #define CHECK_BMP( pBmp, pBmpRef, id) \
147     if( pBmp != pBmpRef ) \
148     { \
149         int w_ref = pBmpRef->getWidth(); \
150         int h_ref = pBmpRef->getHeight() / pBmpRef->getNbFrames(); \
151         int w = pBmp->getWidth(); \
152         int h = pBmp->getHeight() / pBmp->getNbFrames(); \
153         if( w != w_ref || h != h_ref ) \
154             msg_Err( getIntf(), "pls, check bitmap sizes for id: %s", id.c_str() ); \
155     }
156
157 // macro to check resize policy of button and checkbox
158 #define CHECK_RESIZE_POLICY( lefttop, rightbottom, xkeepratio, ykeepratio, id )\
159     if( (!xkeepratio && lefttop != rightbottom) || \
160         (!ykeepratio && lefttop != rightbottom) ) \
161     { \
162         msg_Err( getIntf(), "pls, check resize policy for id: %s", \
163                             id.c_str() ); \
164         rightbottom = lefttop; \
165     }
166
167 // Macro to get the parent box of a control, given the panel ID
168 #define GET_BOX( pRect, id, pLayout ) \
169     if( id == "none" ) \
170         pRect = &pLayout->getRect(); \
171     else \
172     { \
173         const Position *pParent = \
174             m_pTheme->getPositionById( rData.m_panelId ); \
175         if( pParent == NULL ) \
176         { \
177             msg_Err( getIntf(), "parent panel could not be found: %s", \
178                      rData.m_panelId.c_str() ); \
179             return; \
180         } \
181         pRect = pParent; \
182     }
183
184
185 void Builder::addTheme( const BuilderData::Theme &rData )
186 {
187     WindowManager &rManager = m_pTheme->getWindowManager();
188     rManager.setMagnetValue( rData.m_magnet );
189     rManager.setAlphaValue( rData.m_alpha );
190     rManager.setMoveAlphaValue( rData.m_moveAlpha );
191     GenericFont *pFont = getFont( rData.m_tooltipfont );
192     if( pFont )
193     {
194         rManager.createTooltip( *pFont );
195     }
196     else
197     {
198         msg_Warn( getIntf(), "invalid tooltip font: %s",
199                   rData.m_tooltipfont.c_str() );
200     }
201 }
202
203
204 void Builder::addIniFile( const BuilderData::IniFile &rData )
205 {
206     // Parse the INI file
207     string full_path = getFilePath( rData.m_file );
208     if( !full_path.size() )
209         return;
210
211     IniFile iniFile( getIntf(), rData.m_id, full_path );
212     iniFile.parseFile();
213 }
214
215
216 void Builder::addBitmap( const BuilderData::Bitmap &rData )
217 {
218     string full_path = getFilePath( rData.m_fileName );
219     if( !full_path.size() )
220         return;
221
222     GenericBitmap *pBmp =
223         new FileBitmap( getIntf(), m_pImageHandler,
224                         full_path, rData.m_alphaColor,
225                         rData.m_nbFrames, rData.m_fps, rData.m_nbLoops );
226     if( !pBmp->getData() )
227     {
228         // Invalid bitmap
229         delete pBmp;
230         return;
231     }
232     m_pTheme->m_bitmaps[rData.m_id] = GenericBitmapPtr( pBmp );
233 }
234
235
236 void Builder::addSubBitmap( const BuilderData::SubBitmap &rData )
237 {
238     if( m_pTheme->m_bitmaps.find( rData.m_id ) != m_pTheme->m_bitmaps.end() )
239     {
240         msg_Dbg( getIntf(), "bitmap %s already exists", rData.m_id.c_str() );
241         return;
242     }
243
244     // Get the parent bitmap
245     GenericBitmap *pParentBmp = NULL;
246     GET_BMP( pParentBmp, rData.m_parent );
247
248     // Copy a region of the parent bitmap to the new one
249     BitmapImpl *pBmp =
250         new BitmapImpl( getIntf(), rData.m_width, rData.m_height,
251                         rData.m_nbFrames, rData.m_fps, rData.m_nbLoops );
252     bool res = pBmp->drawBitmap( *pParentBmp, rData.m_x, rData.m_y, 0, 0,
253                                  rData.m_width, rData.m_height );
254     if( !res )
255     {
256         // Invalid sub-bitmap
257         delete pBmp;
258         msg_Warn( getIntf(), "sub-bitmap %s ignored", rData.m_id.c_str() );
259         return;
260     }
261     m_pTheme->m_bitmaps[rData.m_id] = GenericBitmapPtr( pBmp );
262 }
263
264
265 void Builder::addBitmapFont( const BuilderData::BitmapFont &rData )
266 {
267     if( m_pTheme->m_fonts.find( rData.m_id ) != m_pTheme->m_fonts.end() )
268     {
269         msg_Dbg( getIntf(), "font %s already exists", rData.m_id.c_str() );
270         return;
271     }
272
273     string full_path = getFilePath( rData.m_file );
274     if( !full_path.size() )
275         return;
276
277     GenericBitmap *pBmp =
278         new FileBitmap( getIntf(), m_pImageHandler, full_path, 0 );
279     if( !pBmp->getData() )
280     {
281         // Invalid bitmap
282         delete pBmp;
283         return;
284     }
285
286     m_pTheme->m_bitmaps[rData.m_id] = GenericBitmapPtr( pBmp );
287
288     GenericFont *pFont = new BitmapFont( getIntf(), *pBmp, rData.m_type );
289     if( pFont->init() )
290     {
291         m_pTheme->m_fonts[rData.m_id] = GenericFontPtr( pFont );
292     }
293     else
294     {
295         delete pFont;
296     }
297 }
298
299
300 void Builder::addFont( const BuilderData::Font &rData )
301 {
302     // Try to load the font from the theme directory
303     string full_path = getFilePath( rData.m_fontFile );
304     if( full_path.size() )
305     {
306         GenericFont *pFont = new FT2Font( getIntf(), full_path, rData.m_size );
307         if( pFont->init() )
308         {
309             m_pTheme->m_fonts[rData.m_id] = GenericFontPtr( pFont );
310             return;
311         }
312         delete pFont;
313     }
314
315     // Font not found; try in the resource path
316     OSFactory *pOSFactory = OSFactory::instance( getIntf() );
317     const list<string> &resPath = pOSFactory->getResourcePath();
318     const string &sep = pOSFactory->getDirSeparator();
319
320     list<string>::const_iterator it;
321     for( it = resPath.begin(); it != resPath.end(); ++it )
322     {
323         string path = (*it) + sep + "fonts" + sep + rData.m_fontFile;
324         GenericFont *pFont = new FT2Font( getIntf(), path, rData.m_size );
325         if( pFont->init() )
326         {
327             // Font loaded successfully
328             m_pTheme->m_fonts[rData.m_id] = GenericFontPtr( pFont );
329             return;
330         }
331         delete pFont;
332     }
333 }
334
335
336 void Builder::addPopupMenu( const BuilderData::PopupMenu &rData )
337 {
338     Popup *pPopup = new Popup( getIntf(), m_pTheme->getWindowManager() );
339
340     m_pTheme->m_popups[rData.m_id] = PopupPtr( pPopup );
341 }
342
343
344 void Builder::addMenuItem( const BuilderData::MenuItem &rData )
345 {
346     Popup *pPopup = m_pTheme->getPopupById( rData.m_popupId );
347     if( pPopup == NULL )
348     {
349         msg_Err( getIntf(), "unknown popup id: %s", rData.m_popupId.c_str() );
350         return;
351     }
352
353     CmdGeneric *pCommand = parseAction( rData.m_action );
354     if( pCommand == NULL )
355     {
356         msg_Err( getIntf(), "invalid action: %s", rData.m_action.c_str() );
357         return;
358     }
359
360     pPopup->addItem( rData.m_label, *pCommand, rData.m_pos );
361 }
362
363
364 void Builder::addMenuSeparator( const BuilderData::MenuSeparator &rData )
365 {
366     Popup *pPopup = m_pTheme->getPopupById( rData.m_popupId );
367     if( pPopup == NULL )
368     {
369         msg_Err( getIntf(), "unknown popup id: %s", rData.m_popupId.c_str() );
370         return;
371     }
372
373     pPopup->addSeparator( rData.m_pos );
374 }
375
376
377 void Builder::addWindow( const BuilderData::Window &rData )
378 {
379     TopWindow *pWin;
380     if( rData.m_id == "fullscreenController" )
381     {
382         pWin = new FscWindow( getIntf(), rData.m_xPos, rData.m_yPos,
383                        m_pTheme->getWindowManager(),
384                        rData.m_dragDrop, rData.m_playOnDrop,
385                        rData.m_visible );
386     }
387     else
388     {
389         pWin = new TopWindow( getIntf(), rData.m_xPos, rData.m_yPos,
390                        m_pTheme->getWindowManager(),
391                        rData.m_dragDrop, rData.m_playOnDrop,
392                        rData.m_visible );
393     }
394     m_pTheme->m_windows[rData.m_id] = TopWindowPtr( pWin );
395 }
396
397
398 void Builder::addLayout( const BuilderData::Layout &rData )
399 {
400     TopWindow *pWin = m_pTheme->getWindowById( rData.m_windowId );
401     if( pWin == NULL )
402     {
403         msg_Err( getIntf(), "unknown window id: %s", rData.m_windowId.c_str() );
404         return;
405     }
406
407     int minWidth = rData.m_minWidth != -1 ? rData.m_minWidth : rData.m_width;
408     int maxWidth = rData.m_maxWidth != -1 ? rData.m_maxWidth : rData.m_width;
409     int minHeight = rData.m_minHeight != -1 ? rData.m_minHeight :
410                     rData.m_height;
411     int maxHeight = rData.m_maxHeight != -1 ? rData.m_maxHeight :
412                     rData.m_height;
413     GenericLayout *pLayout = new GenericLayout( getIntf(), rData.m_width,
414                                                 rData.m_height,
415                                                 minWidth, maxWidth, minHeight,
416                                                 maxHeight );
417     m_pTheme->m_layouts[rData.m_id] = GenericLayoutPtr( pLayout );
418
419     // Attach the layout to its window
420     m_pTheme->getWindowManager().addLayout( *pWin, *pLayout );
421 }
422
423
424 void Builder::addAnchor( const BuilderData::Anchor &rData )
425 {
426     GenericLayout *pLayout = m_pTheme->getLayoutById( rData.m_layoutId );
427     if( pLayout == NULL )
428     {
429         msg_Err( getIntf(), "unknown layout id: %s", rData.m_layoutId.c_str() );
430         return;
431     }
432
433     Bezier *pCurve = getPoints( rData.m_points.c_str() );
434     if( pCurve == NULL )
435     {
436         msg_Err( getIntf(), "invalid format in tag points=\"%s\"",
437                  rData.m_points.c_str() );
438         return;
439     }
440     m_pTheme->m_curves.push_back( BezierPtr( pCurve ) );
441
442     // Compute the position of the anchor
443     const Position pos = makePosition( rData.m_leftTop, rData.m_leftTop,
444                                        rData.m_xPos, rData.m_yPos,
445                                        pCurve->getWidth(),
446                                        pCurve->getHeight(),
447                                        pLayout->getRect() );
448
449     Anchor *pAnc = new Anchor( getIntf(), pos, rData.m_range, rData.m_priority,
450                                *pCurve, *pLayout );
451     pLayout->addAnchor( pAnc );
452 }
453
454
455 void Builder::addButton( const BuilderData::Button &rData )
456 {
457     // Get the bitmaps of the button
458     GenericBitmap *pBmpUp = NULL;
459     GET_BMP( pBmpUp, rData.m_upId );
460
461     GenericBitmap *pBmpDown = pBmpUp;
462     GET_BMP( pBmpDown, rData.m_downId );
463
464     GenericBitmap *pBmpOver = pBmpUp;
465     GET_BMP( pBmpOver, rData.m_overId );
466
467     GenericLayout *pLayout = m_pTheme->getLayoutById( rData.m_layoutId );
468     if( pLayout == NULL )
469     {
470         msg_Err( getIntf(), "unknown layout id: %s", rData.m_layoutId.c_str() );
471         return;
472     }
473
474     CmdGeneric *pCommand = parseAction( rData.m_actionId );
475     if( pCommand == NULL )
476     {
477         msg_Err( getIntf(), "invalid action: %s", rData.m_actionId.c_str() );
478         return;
479     }
480
481     // Get the visibility variable
482     // XXX check when it is null
483     Interpreter *pInterpreter = Interpreter::instance( getIntf() );
484     VarBool *pVisible = pInterpreter->getVarBool( rData.m_visible, m_pTheme );
485
486     CtrlButton *pButton = new CtrlButton( getIntf(), *pBmpUp, *pBmpOver,
487         *pBmpDown, *pCommand, UString( getIntf(), rData.m_tooltip.c_str() ),
488         UString( getIntf(), rData.m_help.c_str() ), pVisible );
489     m_pTheme->m_controls[rData.m_id] = CtrlGenericPtr( pButton );
490
491     // width and height are set up from the 'up' bitmap size
492     int width = pBmpUp->getWidth();
493     int height = pBmpUp->getHeight() / pBmpUp->getNbFrames();
494     bool xkeepratio = rData.m_xKeepRatio;
495     bool ykeepratio = rData.m_yKeepRatio;
496     string lefttop( rData.m_leftTop );
497     string rightbottom( rData.m_rightBottom );
498
499     // various checks to help skin developers debug their skin
500     CHECK_BMP( pBmpDown, pBmpUp, rData.m_id );
501     CHECK_BMP( pBmpOver, pBmpUp, rData.m_id );
502     CHECK_RESIZE_POLICY( lefttop, rightbottom, xkeepratio, ykeepratio,
503                          rData.m_id );
504
505     // Compute the position of the control
506     // XXX (we suppose all the images have the same size...)
507     const GenericRect *pRect;
508     GET_BOX( pRect, rData.m_panelId , pLayout);
509     const Position pos = makePosition( lefttop, rightbottom,
510                              rData.m_xPos, rData.m_yPos, width, height,
511                              *pRect, xkeepratio, ykeepratio );
512
513     pLayout->addControl( pButton, pos, rData.m_layer );
514 }
515
516
517 void Builder::addCheckbox( const BuilderData::Checkbox &rData )
518 {
519     // Get the bitmaps of the checkbox
520     GenericBitmap *pBmpUp1 = NULL;
521     GET_BMP( pBmpUp1, rData.m_up1Id );
522
523     GenericBitmap *pBmpDown1 = pBmpUp1;
524     GET_BMP( pBmpDown1, rData.m_down1Id );
525
526     GenericBitmap *pBmpOver1 = pBmpUp1;
527     GET_BMP( pBmpOver1, rData.m_over1Id );
528
529     GenericBitmap *pBmpUp2 = NULL;
530     GET_BMP( pBmpUp2, rData.m_up2Id );
531
532     GenericBitmap *pBmpDown2 = pBmpUp2;
533     GET_BMP( pBmpDown2, rData.m_down2Id );
534
535     GenericBitmap *pBmpOver2 = pBmpUp2;
536     GET_BMP( pBmpOver2, rData.m_over2Id );
537
538     GenericLayout *pLayout = m_pTheme->getLayoutById( rData.m_layoutId );
539     if( pLayout == NULL )
540     {
541         msg_Err( getIntf(), "unknown layout id: %s", rData.m_layoutId.c_str() );
542         return;
543     }
544
545     CmdGeneric *pCommand1 = parseAction( rData.m_action1 );
546     if( pCommand1 == NULL )
547     {
548         msg_Err( getIntf(), "invalid action: %s", rData.m_action1.c_str() );
549         return;
550     }
551
552     CmdGeneric *pCommand2 = parseAction( rData.m_action2 );
553     if( pCommand2 == NULL )
554     {
555         msg_Err( getIntf(), "invalid action: %s", rData.m_action2.c_str() );
556         return;
557     }
558
559     // Get the state variable
560     Interpreter *pInterpreter = Interpreter::instance( getIntf() );
561     VarBool *pVar = pInterpreter->getVarBool( rData.m_state, m_pTheme );
562     if( pVar == NULL )
563     {
564         // TODO: default state
565         return;
566     }
567
568     // Get the visibility variable
569     // XXX check when it is null
570     VarBool *pVisible = pInterpreter->getVarBool( rData.m_visible, m_pTheme );
571
572     // width and height are set up from the 'up1' bitmap size
573     int width = pBmpUp1->getWidth();
574     int height = pBmpUp1->getHeight() / pBmpUp1->getNbFrames();
575     bool xkeepratio = rData.m_xKeepRatio;
576     bool ykeepratio = rData.m_yKeepRatio;
577     string lefttop( rData.m_leftTop );
578     string rightbottom( rData.m_rightBottom );
579
580
581     // various checks to help skin developers debug their skin
582     CHECK_BMP( pBmpDown1, pBmpUp1, rData.m_id );
583     CHECK_BMP( pBmpOver1, pBmpUp1, rData.m_id );
584     CHECK_BMP( pBmpUp2, pBmpUp1, rData.m_id );
585     CHECK_BMP( pBmpDown2, pBmpUp1, rData.m_id );
586     CHECK_BMP( pBmpOver2, pBmpUp1, rData.m_id );
587     CHECK_RESIZE_POLICY( lefttop, rightbottom, xkeepratio, ykeepratio,
588                          rData.m_id );
589
590     // Create the control
591     CtrlCheckbox *pCheckbox = new CtrlCheckbox( getIntf(), *pBmpUp1,
592         *pBmpOver1, *pBmpDown1, *pBmpUp2, *pBmpOver2, *pBmpDown2, *pCommand1,
593         *pCommand2, UString( getIntf(), rData.m_tooltip1.c_str() ),
594         UString( getIntf(), rData.m_tooltip2.c_str() ), *pVar,
595         UString( getIntf(), rData.m_help.c_str() ), pVisible );
596     m_pTheme->m_controls[rData.m_id] = CtrlGenericPtr( pCheckbox );
597
598     // Compute the position of the control
599     // XXX (we suppose all the images have the same size...)
600     const GenericRect *pRect;
601     GET_BOX( pRect, rData.m_panelId , pLayout);
602     const Position pos = makePosition( lefttop, rightbottom,
603                              rData.m_xPos, rData.m_yPos, width, height,
604                              *pRect, xkeepratio, ykeepratio );
605
606     pLayout->addControl( pCheckbox, pos, rData.m_layer );
607 }
608
609
610 void Builder::addImage( const BuilderData::Image &rData )
611 {
612     GenericBitmap *pBmp = NULL;
613     GET_BMP( pBmp, rData.m_bmpId );
614
615     GenericLayout *pLayout = m_pTheme->getLayoutById( rData.m_layoutId );
616     if( pLayout == NULL )
617     {
618         msg_Err( getIntf(), "unknown layout id: %s", rData.m_layoutId.c_str() );
619         return;
620     }
621
622     TopWindow *pWindow = m_pTheme->getWindowById( rData.m_windowId );
623     if( pWindow == NULL )
624     {
625         msg_Err( getIntf(), "unknown window id: %s", rData.m_windowId.c_str() );
626         return;
627     }
628
629     CmdGeneric *pCommand = parseAction( rData.m_action2Id );
630     if( pCommand == NULL )
631     {
632         msg_Err( getIntf(), "invalid action: %s", rData.m_action2Id.c_str() );
633         return;
634     }
635
636     // Get the visibility variable
637     // XXX check when it is null
638     Interpreter *pInterpreter = Interpreter::instance( getIntf() );
639     VarBool *pVisible = pInterpreter->getVarBool( rData.m_visible, m_pTheme );
640
641     CtrlImage::resize_t resizeMethod =
642         rData.m_resize == "scale"  ? CtrlImage::kScale :
643         rData.m_resize == "mosaic" ? CtrlImage::kMosaic :
644                                      CtrlImage::kScaleAndRatioPreserved;
645     CtrlImage *pImage = new CtrlImage( getIntf(), *pBmp, *pCommand,
646         resizeMethod, UString( getIntf(), rData.m_help.c_str() ), pVisible,
647         rData.m_art );
648     m_pTheme->m_controls[rData.m_id] = CtrlGenericPtr( pImage );
649
650     // Compute the position of the control
651     const GenericRect *pRect;
652     int width = (rData.m_width > 0) ? rData.m_width : pBmp->getWidth();
653     int height = (rData.m_height > 0) ? rData.m_height : pBmp->getHeight();
654     GET_BOX( pRect, rData.m_panelId , pLayout);
655     const Position pos = makePosition( rData.m_leftTop, rData.m_rightBottom,
656                                        rData.m_xPos, rData.m_yPos,
657                                        width, height,
658                                        *pRect, rData.m_xKeepRatio,
659                                        rData.m_yKeepRatio );
660
661     if( rData.m_actionId == "move" )
662     {
663         CtrlMove *pMove = new CtrlMove( getIntf(), m_pTheme->getWindowManager(),
664              *pImage, *pWindow, UString( getIntf(), rData.m_help.c_str() ),
665              pVisible );
666         m_pTheme->m_controls[rData.m_id + "_move"] = CtrlGenericPtr( pMove );
667         pLayout->addControl( pMove, pos, rData.m_layer );
668     }
669     else if( rData.m_actionId == "resizeS" )
670     {
671         CtrlResize *pResize = new CtrlResize( getIntf(),
672                 m_pTheme->getWindowManager(), *pImage, *pLayout,
673                 UString( getIntf(), rData.m_help.c_str() ), pVisible,
674                 WindowManager::kResizeS );
675         m_pTheme->m_controls[rData.m_id + "_rsz"] = CtrlGenericPtr( pResize );
676         pLayout->addControl( pResize, pos, rData.m_layer );
677     }
678     else if( rData.m_actionId == "resizeE" )
679     {
680         CtrlResize *pResize = new CtrlResize( getIntf(),
681                 m_pTheme->getWindowManager(), *pImage, *pLayout,
682                 UString( getIntf(), rData.m_help.c_str() ), pVisible,
683                 WindowManager::kResizeE );
684         m_pTheme->m_controls[rData.m_id + "_rsz"] = CtrlGenericPtr( pResize );
685         pLayout->addControl( pResize, pos, rData.m_layer );
686     }
687     else if( rData.m_actionId == "resizeSE" )
688     {
689         CtrlResize *pResize = new CtrlResize( getIntf(),
690                 m_pTheme->getWindowManager(), *pImage, *pLayout,
691                 UString( getIntf(), rData.m_help.c_str() ), pVisible,
692                 WindowManager::kResizeSE );
693         m_pTheme->m_controls[rData.m_id + "_rsz"] = CtrlGenericPtr( pResize );
694         pLayout->addControl( pResize, pos, rData.m_layer );
695     }
696     else
697     {
698         pLayout->addControl( pImage, pos, rData.m_layer );
699     }
700 }
701
702
703 void Builder::addPanel( const BuilderData::Panel &rData )
704 {
705     // This method makes the assumption that the Panels are created in the
706     // order of the XML, because each child Panel expects its parent Panel
707     // in order to be fully created
708
709     GenericLayout *pLayout = m_pTheme->getLayoutById( rData.m_layoutId );
710     if( pLayout == NULL )
711     {
712         msg_Err( getIntf(), "unknown layout id: %s", rData.m_layoutId.c_str() );
713         return;
714     }
715
716     const GenericRect *pRect;
717     GET_BOX( pRect, rData.m_panelId , pLayout);
718     Position *pPos =
719         new Position( makePosition( rData.m_leftTop, rData.m_rightBottom,
720                                     rData.m_xPos, rData.m_yPos,
721                                     rData.m_width, rData.m_height,
722                                     *pRect, rData.m_xKeepRatio,
723                                     rData.m_yKeepRatio ) );
724     m_pTheme->m_positions[rData.m_id] = PositionPtr( pPos );
725 }
726
727
728 void Builder::addText( const BuilderData::Text &rData )
729 {
730     GenericLayout *pLayout = m_pTheme->getLayoutById( rData.m_layoutId );
731     if( pLayout == NULL )
732     {
733         msg_Err( getIntf(), "unknown layout id: %s", rData.m_layoutId.c_str() );
734         return;
735     }
736
737     GenericFont *pFont = getFont( rData.m_fontId );
738     if( pFont == NULL )
739     {
740         msg_Err( getIntf(), "unknown font id: %s", rData.m_fontId.c_str() );
741         return;
742     }
743
744     // Convert the scrolling mode
745     CtrlText::Scrolling_t scrolling;
746     if( rData.m_scrolling == "auto" )
747         scrolling = CtrlText::kAutomatic;
748     else if( rData.m_scrolling == "manual" )
749         scrolling = CtrlText::kManual;
750     else if( rData.m_scrolling == "none" )
751         scrolling = CtrlText::kNone;
752     else
753     {
754         msg_Err( getIntf(), "invalid scrolling mode: %s",
755                  rData.m_scrolling.c_str() );
756         return;
757     }
758
759     // Convert the alignment
760     CtrlText::Align_t alignment;
761     if( rData.m_alignment == "left" )
762         alignment = CtrlText::kLeft;
763     else if( rData.m_alignment == "center" || rData.m_alignment == "centre" )
764         alignment = CtrlText::kCenter;
765     else if( rData.m_alignment == "right" )
766         alignment = CtrlText::kRight;
767     else
768     {
769         msg_Err( getIntf(), "invalid alignment: %s",
770                  rData.m_alignment.c_str() );
771         return;
772     }
773
774     // Create a text variable
775     VarText *pVar = new VarText( getIntf() );
776     m_pTheme->m_vars.push_back( VariablePtr( pVar ) );
777
778     // Set the text of the control
779     UString msg( getIntf(), rData.m_text.c_str() );
780     pVar->set( msg );
781
782     // Get the visibility variable
783     // XXX check when it is null
784     Interpreter *pInterpreter = Interpreter::instance( getIntf() );
785     VarBool *pVisible = pInterpreter->getVarBool( rData.m_visible, m_pTheme );
786     VarBool *pFocus = pInterpreter->getVarBool( rData.m_focus, m_pTheme );
787
788     CtrlText *pText = new CtrlText( getIntf(), *pVar, *pFont,
789         UString( getIntf(), rData.m_help.c_str() ), rData.m_color,
790         pVisible, pFocus, scrolling, alignment );
791     m_pTheme->m_controls[rData.m_id] = CtrlGenericPtr( pText );
792
793     int height = pFont->getSize();
794
795     // Compute the position of the control
796     const GenericRect *pRect;
797     GET_BOX( pRect, rData.m_panelId , pLayout);
798     const Position pos = makePosition( rData.m_leftTop, rData.m_rightBottom,
799                                        rData.m_xPos, rData.m_yPos,
800                                        rData.m_width, height, *pRect,
801                                        rData.m_xKeepRatio, rData.m_yKeepRatio );
802
803     pLayout->addControl( pText, pos, rData.m_layer );
804
805 }
806
807
808 void Builder::addRadialSlider( const BuilderData::RadialSlider &rData )
809 {
810     // Get the bitmaps of the slider
811     GenericBitmap *pSeq = NULL;
812     GET_BMP( pSeq, rData.m_sequence );
813
814     GenericLayout *pLayout = m_pTheme->getLayoutById( rData.m_layoutId );
815     if( pLayout == NULL )
816     {
817         msg_Err( getIntf(), "unknown layout id: %s", rData.m_layoutId.c_str() );
818         return;
819     }
820
821     // Get the variable associated to the slider
822     Interpreter *pInterpreter = Interpreter::instance( getIntf() );
823     VarPercent *pVar = pInterpreter->getVarPercent( rData.m_value, m_pTheme );
824     if( pVar == NULL )
825     {
826         msg_Err( getIntf(), "unknown slider value: %s", rData.m_value.c_str() );
827         return;
828     }
829
830     // Get the visibility variable
831     // XXX check when it is null
832     VarBool *pVisible = pInterpreter->getVarBool( rData.m_visible, m_pTheme );
833
834     // Create the control
835     CtrlRadialSlider *pRadial =
836         new CtrlRadialSlider( getIntf(), *pSeq, rData.m_nbImages, *pVar,
837                               rData.m_minAngle, rData.m_maxAngle,
838                               UString( getIntf(), rData.m_help.c_str() ),
839                               pVisible );
840     m_pTheme->m_controls[rData.m_id] = CtrlGenericPtr( pRadial );
841
842     // XXX: resizing is not supported
843     // Compute the position of the control
844     const GenericRect *pRect;
845     GET_BOX( pRect, rData.m_panelId , pLayout);
846     const Position pos = makePosition( rData.m_leftTop, rData.m_rightBottom,
847                                        rData.m_xPos, rData.m_yPos,
848                                        pSeq->getWidth(),
849                                        pSeq->getHeight() / rData.m_nbImages,
850                                        *pRect,
851                                        rData.m_xKeepRatio, rData.m_yKeepRatio );
852
853     pLayout->addControl( pRadial, pos, rData.m_layer );
854 }
855
856
857 void Builder::addSlider( const BuilderData::Slider &rData )
858 {
859     // Add the background first, so that we will still have something almost
860     // functional if the cursor cannot be created properly (this happens for
861     // some winamp2 skins, where the images of the cursor are not always
862     // present)
863
864     // Get the bitmaps of the background
865     GenericBitmap *pBgImage = NULL;
866     GET_BMP( pBgImage, rData.m_imageId );
867
868     GenericLayout *pLayout = m_pTheme->getLayoutById( rData.m_layoutId );
869     if( pLayout == NULL )
870     {
871         msg_Err( getIntf(), "unknown layout id: %s", rData.m_layoutId.c_str() );
872         return;
873     }
874
875     Bezier *pCurve = getPoints( rData.m_points.c_str() );
876     if( pCurve == NULL )
877     {
878         msg_Err( getIntf(), "invalid format in tag points=\"%s\"",
879                  rData.m_points.c_str() );
880         return;
881     }
882     m_pTheme->m_curves.push_back( BezierPtr( pCurve ) );
883
884     // Get the visibility variable
885     // XXX check when it is null
886     Interpreter *pInterpreter = Interpreter::instance( getIntf() );
887     VarBool *pVisible = pInterpreter->getVarBool( rData.m_visible, m_pTheme );
888
889     // Get the variable associated to the slider
890     VarPercent *pVar = pInterpreter->getVarPercent( rData.m_value, m_pTheme );
891     if( pVar == NULL )
892     {
893         msg_Err( getIntf(), "unknown slider value: %s", rData.m_value.c_str() );
894         return;
895     }
896
897     // Create the background control
898     CtrlSliderBg *pBackground = new CtrlSliderBg( getIntf(),
899         *pCurve, *pVar, rData.m_thickness, pBgImage, rData.m_nbHoriz,
900         rData.m_nbVert, rData.m_padHoriz, rData.m_padVert,
901         pVisible, UString( getIntf(), rData.m_help.c_str() ) );
902     m_pTheme->m_controls[rData.m_id + "_bg"] = CtrlGenericPtr( pBackground );
903
904     // Compute the position of the control
905     const GenericRect *pRect;
906     GET_BOX( pRect, rData.m_panelId , pLayout);
907     const Position pos = makePosition( rData.m_leftTop, rData.m_rightBottom,
908                                        rData.m_xPos, rData.m_yPos,
909                                        pCurve->getWidth(), pCurve->getHeight(),
910                                        *pRect,
911                                        rData.m_xKeepRatio, rData.m_yKeepRatio );
912
913     pLayout->addControl( pBackground, pos, rData.m_layer );
914
915     // Get the bitmaps of the cursor
916     GenericBitmap *pBmpUp = NULL;
917     GET_BMP( pBmpUp, rData.m_upId );
918
919     GenericBitmap *pBmpDown = pBmpUp;
920     GET_BMP( pBmpDown, rData.m_downId );
921
922     GenericBitmap *pBmpOver = pBmpUp;
923     GET_BMP( pBmpOver, rData.m_overId );
924
925     // Create the cursor control
926     CtrlSliderCursor *pCursor = new CtrlSliderCursor( getIntf(), *pBmpUp,
927         *pBmpOver, *pBmpDown, *pCurve, *pVar, pVisible,
928         UString( getIntf(), rData.m_tooltip.c_str() ),
929         UString( getIntf(), rData.m_help.c_str() ) );
930     m_pTheme->m_controls[rData.m_id] = CtrlGenericPtr( pCursor );
931
932     pLayout->addControl( pCursor, pos, rData.m_layer );
933
934     // Associate the cursor to the background
935     pBackground->associateCursor( *pCursor );
936 }
937
938
939 void Builder::addList( const BuilderData::List &rData )
940 {
941     // Get the background bitmap, if any
942     GenericBitmap *pBgBmp = NULL;
943     GET_BMP( pBgBmp, rData.m_bgImageId );
944
945     GenericLayout *pLayout = m_pTheme->getLayoutById( rData.m_layoutId );
946     if( pLayout == NULL )
947     {
948         msg_Err( getIntf(), "unknown layout id: %s", rData.m_layoutId.c_str() );
949         return;
950     }
951
952     GenericFont *pFont = getFont( rData.m_fontId );
953     if( pFont == NULL )
954     {
955         msg_Err( getIntf(), "unknown font id: %s", rData.m_fontId.c_str() );
956         return;
957     }
958
959     // Get the list variable
960     Interpreter *pInterpreter = Interpreter::instance( getIntf() );
961     VarList *pVar = pInterpreter->getVarList( rData.m_var, m_pTheme );
962     if( pVar == NULL )
963     {
964         msg_Err( getIntf(), "no such list variable: %s", rData.m_var.c_str() );
965         return;
966     }
967
968     // Get the visibility variable
969     // XXX check when it is null
970     VarBool *pVisible = pInterpreter->getVarBool( rData.m_visible, m_pTheme );
971
972     // Get the color values
973     uint32_t fgColor = getColor( rData.m_fgColor );
974     uint32_t playColor = getColor( rData.m_playColor );
975     uint32_t bgColor1 = getColor( rData.m_bgColor1 );
976     uint32_t bgColor2 = getColor( rData.m_bgColor2 );
977     uint32_t selColor = getColor( rData.m_selColor );
978
979     // Create the list control
980     CtrlList *pList = new CtrlList( getIntf(), *pVar, *pFont, pBgBmp,
981        fgColor, playColor, bgColor1, bgColor2, selColor,
982        UString( getIntf(), rData.m_help.c_str() ), pVisible );
983     m_pTheme->m_controls[rData.m_id] = CtrlGenericPtr( pList );
984
985     // Compute the position of the control
986     const GenericRect *pRect;
987     GET_BOX( pRect, rData.m_panelId , pLayout);
988     const Position pos = makePosition( rData.m_leftTop, rData.m_rightBottom,
989                                        rData.m_xPos, rData.m_yPos,
990                                        rData.m_width, rData.m_height,
991                                        *pRect,
992                                        rData.m_xKeepRatio, rData.m_yKeepRatio );
993
994     pLayout->addControl( pList, pos, rData.m_layer );
995 }
996
997 void Builder::addTree( const BuilderData::Tree &rData )
998 {
999     // Get the bitmaps, if any
1000     GenericBitmap *pBgBmp = NULL;
1001     GenericBitmap *pItemBmp = NULL;
1002     GenericBitmap *pOpenBmp = NULL;
1003     GenericBitmap *pClosedBmp = NULL;
1004     GET_BMP( pBgBmp, rData.m_bgImageId );
1005     GET_BMP( pItemBmp, rData.m_itemImageId );
1006     GET_BMP( pOpenBmp, rData.m_openImageId );
1007     GET_BMP( pClosedBmp, rData.m_closedImageId );
1008
1009     GenericLayout *pLayout = m_pTheme->getLayoutById( rData.m_layoutId );
1010     if( pLayout == NULL )
1011     {
1012         msg_Err( getIntf(), "unknown layout id: %s", rData.m_layoutId.c_str() );
1013         return;
1014     }
1015
1016     GenericFont *pFont = getFont( rData.m_fontId );
1017     if( pFont == NULL )
1018     {
1019         msg_Err( getIntf(), "unknown font id: %s", rData.m_fontId.c_str() );
1020         return;
1021     }
1022
1023     // Get the list variable
1024     Interpreter *pInterpreter = Interpreter::instance( getIntf() );
1025     VarTree *pVar = pInterpreter->getVarTree( rData.m_var, m_pTheme );
1026     if( pVar == NULL )
1027     {
1028         msg_Err( getIntf(), "no such list variable: %s", rData.m_var.c_str() );
1029         return;
1030     }
1031
1032     // Get the visibility variable
1033     // XXX check when it is null
1034     VarBool *pVisible = pInterpreter->getVarBool( rData.m_visible, m_pTheme );
1035     VarBool *pFlat = pInterpreter->getVarBool( rData.m_flat, m_pTheme );
1036
1037     // Get the color values
1038     uint32_t fgColor = getColor( rData.m_fgColor );
1039     uint32_t playColor = getColor( rData.m_playColor );
1040     uint32_t bgColor1 = getColor( rData.m_bgColor1 );
1041     uint32_t bgColor2 = getColor( rData.m_bgColor2 );
1042     uint32_t selColor = getColor( rData.m_selColor );
1043
1044     // Create the list control
1045     CtrlTree *pTree = new CtrlTree( getIntf(), *pVar, *pFont, pBgBmp,
1046        pItemBmp, pOpenBmp, pClosedBmp,
1047        fgColor, playColor, bgColor1, bgColor2, selColor,
1048        UString( getIntf(), rData.m_help.c_str() ), pVisible, pFlat );
1049     m_pTheme->m_controls[rData.m_id] = CtrlGenericPtr( pTree );
1050
1051     // Compute the position of the control
1052     const GenericRect *pRect;
1053     GET_BOX( pRect, rData.m_panelId , pLayout);
1054     const Position pos = makePosition( rData.m_leftTop, rData.m_rightBottom,
1055                                        rData.m_xPos, rData.m_yPos,
1056                                        rData.m_width, rData.m_height,
1057                                        *pRect,
1058                                        rData.m_xKeepRatio, rData.m_yKeepRatio );
1059
1060     pLayout->addControl( pTree, pos, rData.m_layer );
1061 }
1062
1063 void Builder::addVideo( const BuilderData::Video &rData )
1064 {
1065     GenericLayout *pLayout = m_pTheme->getLayoutById( rData.m_layoutId );
1066     if( pLayout == NULL )
1067     {
1068         msg_Err( getIntf(), "unknown layout id: %s", rData.m_layoutId.c_str() );
1069         return;
1070     }
1071
1072     BuilderData::Video Data = rData;
1073     if( Data.m_autoResize )
1074     {
1075         // force autoresize to false if the control is not able to
1076         // freely resize within its container
1077         if( Data.m_xKeepRatio || Data.m_yKeepRatio ||
1078             !( Data.m_leftTop == "lefttop" &&
1079                Data.m_rightBottom == "rightbottom" ) )
1080         {
1081             msg_Err( getIntf(),
1082                 "video: resize policy and autoresize are not compatible" );
1083             Data.m_autoResize = false;
1084         }
1085     }
1086     if( !(Data.m_width > 0 && Data.m_height > 0) )
1087     {
1088         msg_Err( getIntf(),
1089             "pls, provide a valid size for the video control id: %s "
1090              "(dropping the video control)", Data.m_id.c_str() );
1091         return;
1092     }
1093
1094     // Get the visibility variable
1095     // XXX check when it is null
1096     Interpreter *pInterpreter = Interpreter::instance( getIntf() );
1097     VarBool *pVisible = pInterpreter->getVarBool( Data.m_visible, m_pTheme );
1098
1099     CtrlVideo *pVideo = new CtrlVideo( getIntf(), *pLayout,
1100         Data.m_autoResize, UString( getIntf(), Data.m_help.c_str() ),
1101         pVisible );
1102     m_pTheme->m_controls[Data.m_id] = CtrlGenericPtr( pVideo );
1103
1104     // Compute the position of the control
1105     const GenericRect *pRect;
1106     GET_BOX( pRect, rData.m_panelId , pLayout);
1107     const Position pos = makePosition( Data.m_leftTop, Data.m_rightBottom,
1108                                        Data.m_xPos, Data.m_yPos,
1109                                        Data.m_width, Data.m_height,
1110                                        *pRect,
1111                                        Data.m_xKeepRatio, Data.m_yKeepRatio );
1112
1113     pLayout->addControl( pVideo, pos, Data.m_layer );
1114 }
1115
1116
1117 const Position Builder::makePosition( const string &rLeftTop,
1118                                       const string &rRightBottom,
1119                                       int xPos, int yPos, int width,
1120                                       int height, const GenericRect &rRect,
1121                                       bool xKeepRatio, bool yKeepRatio ) const
1122 {
1123     int left = 0, top = 0, right = 0, bottom = 0;
1124     Position::Ref_t refLeftTop = Position::kLeftTop;
1125     Position::Ref_t refRightBottom = Position::kLeftTop;
1126
1127     int boxWidth = rRect.getWidth();
1128     int boxHeight = rRect.getHeight();
1129
1130     // Position of the left top corner
1131     if( rLeftTop == "lefttop" )
1132     {
1133         left = xPos;
1134         top = yPos;
1135         refLeftTop = Position::kLeftTop;
1136     }
1137     else if( rLeftTop == "righttop" )
1138     {
1139         left = xPos - boxWidth + 1;
1140         top = yPos;
1141         refLeftTop = Position::kRightTop;
1142     }
1143     else if( rLeftTop == "leftbottom" )
1144     {
1145         left = xPos;
1146         top = yPos - boxHeight + 1;
1147         refLeftTop = Position::kLeftBottom;
1148     }
1149     else if( rLeftTop == "rightbottom" )
1150     {
1151         left = xPos - boxWidth + 1;
1152         top = yPos - boxHeight + 1;
1153         refLeftTop = Position::kRightBottom;
1154     }
1155
1156     // Position of the right bottom corner
1157     if( rRightBottom == "lefttop" )
1158     {
1159         right = xPos + width - 1;
1160         bottom = yPos + height - 1;
1161         refRightBottom = Position::kLeftTop;
1162     }
1163     else if( rRightBottom == "righttop" )
1164     {
1165         right = xPos + width - boxWidth;
1166         bottom = yPos + height - 1;
1167         refRightBottom = Position::kRightTop;
1168     }
1169     else if( rRightBottom == "leftbottom" )
1170     {
1171         right = xPos + width - 1;
1172         bottom = yPos + height - boxHeight;
1173         refRightBottom = Position::kLeftBottom;
1174     }
1175     else if( rRightBottom == "rightbottom" )
1176     {
1177         right = xPos + width - boxWidth;
1178         bottom = yPos + height - boxHeight;
1179         refRightBottom = Position::kRightBottom;
1180     }
1181
1182     // In "keep ratio" mode, overwrite the previously computed values with the
1183     // actual ones
1184     // XXX: this coupling between makePosition and the Position class should
1185     // be reduced...
1186     if( xKeepRatio )
1187     {
1188         left = xPos;
1189         right = xPos + width;
1190     }
1191     if( yKeepRatio )
1192     {
1193         top = yPos;
1194         bottom = yPos + height;
1195     }
1196
1197     return Position( left, top, right, bottom, rRect, refLeftTop,
1198                      refRightBottom, xKeepRatio, yKeepRatio );
1199 }
1200
1201
1202 GenericFont *Builder::getFont( const string &fontId )
1203 {
1204     GenericFont *pFont = m_pTheme->getFontById(fontId);
1205     if( !pFont && fontId == "defaultfont" )
1206     {
1207         // Get the resource path and try to load the default font
1208         OSFactory *pOSFactory = OSFactory::instance( getIntf() );
1209         const list<string> &resPath = pOSFactory->getResourcePath();
1210         const string &sep = pOSFactory->getDirSeparator();
1211
1212         list<string>::const_iterator it;
1213         for( it = resPath.begin(); it != resPath.end(); ++it )
1214         {
1215             string path = (*it) + sep + "fonts" + sep + "FreeSans.ttf";
1216             pFont = new FT2Font( getIntf(), path, 12 );
1217             if( pFont->init() )
1218             {
1219                 // Font loaded successfully
1220                 m_pTheme->m_fonts["defaultfont"] = GenericFontPtr( pFont );
1221                 break;
1222             }
1223             else
1224             {
1225                 delete pFont;
1226                 pFont = NULL;
1227             }
1228         }
1229         if( !pFont )
1230         {
1231             msg_Err( getIntf(), "failed to open the default font" );
1232         }
1233     }
1234     return pFont;
1235 }
1236
1237
1238 string Builder::getFilePath( const string &rFileName ) const
1239 {
1240     OSFactory *pFactory = OSFactory::instance( getIntf() );
1241     const string &sep = pFactory->getDirSeparator();
1242
1243     string file = rFileName;
1244     if( file.find( "\\" ) != string::npos )
1245     {
1246         // For skins to be valid on both Linux and Win32,
1247         // slash should be used as path separator for both OSs.
1248         msg_Warn( getIntf(), "use of '/' is preferred to '\\' for paths" );
1249         string::size_type pos;
1250         while( ( pos = file.find( "\\" ) ) != string::npos )
1251            file[pos] = '/';
1252     }
1253
1254 #if defined( _WIN32 ) || defined( __OS2__ )
1255     string::size_type pos;
1256     while( ( pos = file.find( "/" ) ) != string::npos )
1257        file.replace( pos, 1, sep );
1258 #endif
1259
1260     string full_path = m_path + sep + sFromLocale( file );
1261
1262     // check that the file exists and can be read
1263     if( ifstream( full_path.c_str() ).fail() )
1264     {
1265         msg_Err( getIntf(), "missing file: %s", file.c_str() );
1266         full_path = "";
1267     }
1268
1269     return full_path;
1270 }
1271
1272
1273
1274 Bezier *Builder::getPoints( const char *pTag ) const
1275 {
1276     vector<float> xBez, yBez;
1277     int x, y, n;
1278     while( 1 )
1279     {
1280         if( sscanf( pTag, "(%d,%d)%n", &x, &y, &n ) < 1 )
1281         {
1282             return NULL;
1283         }
1284
1285         xBez.push_back( x );
1286         yBez.push_back( y );
1287         pTag += n;
1288         if( *pTag == '\0' )
1289         {
1290             break;
1291         }
1292         if( *(pTag++) != ',' )
1293         {
1294             return NULL;
1295         }
1296     }
1297
1298     // Create the Bezier curve
1299     return new Bezier( getIntf(), xBez, yBez );
1300 }
1301
1302
1303 uint32_t Builder::getColor( const string &rVal ) const
1304 {
1305     // Check it the value is a registered constant
1306     Interpreter *pInterpreter = Interpreter::instance( getIntf() );
1307     string val = pInterpreter->getConstant( rVal );
1308
1309     // Convert to an int value
1310     return SkinParser::convertColor( val.c_str() );
1311 }
1312