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