1 /*****************************************************************************
3 *****************************************************************************
4 * Copyright (C) 2003 the VideoLAN team
7 * Authors: Cyril Deguet <asmax@via.ecp.fr>
8 * Olivier Teulière <ipkiss@via.ecp.fr>
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.
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.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
23 *****************************************************************************/
26 #include "builder.hpp"
27 #include "builder_data.hpp"
28 #include "interpreter.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/anchor.hpp"
34 #include "../src/bitmap_font.hpp"
35 #include "../src/ft2_font.hpp"
36 #include "../src/theme.hpp"
37 #include "../controls/ctrl_button.hpp"
38 #include "../controls/ctrl_checkbox.hpp"
39 #include "../controls/ctrl_image.hpp"
40 #include "../controls/ctrl_list.hpp"
41 #include "../controls/ctrl_move.hpp"
42 #include "../controls/ctrl_resize.hpp"
43 #include "../controls/ctrl_slider.hpp"
44 #include "../controls/ctrl_radialslider.hpp"
45 #include "../controls/ctrl_text.hpp"
46 #include "../controls/ctrl_tree.hpp"
47 #include "../controls/ctrl_video.hpp"
48 #include "../utils/position.hpp"
49 #include "../utils/var_bool.hpp"
50 #include "../utils/var_text.hpp"
52 #include "vlc_image.h"
55 Builder::Builder( intf_thread_t *pIntf, const BuilderData &rData,
56 const string &rPath ):
57 SkinObject( pIntf ), m_rData( rData ), m_path( rPath ), m_pTheme( NULL )
59 m_pImageHandler = image_HandlerCreate( pIntf );
64 if( m_pImageHandler ) image_HandlerDelete( m_pImageHandler );
67 CmdGeneric *Builder::parseAction( const string &rAction )
69 return Interpreter::instance( getIntf() )->parseAction( rAction, m_pTheme );
74 #define ADD_OBJECTS( type ) \
75 list<BuilderData::type>::const_iterator it##type; \
76 for( it##type = m_rData.m_list##type.begin(); \
77 it##type != m_rData.m_list##type.end(); it##type++ ) \
79 add##type( *it##type ); \
83 Theme *Builder::build()
85 m_pTheme = new Theme( getIntf() );
86 if( m_pTheme == NULL )
91 // Create everything from the data in the XML
93 ADD_OBJECTS( Bitmap );
94 ADD_OBJECTS( SubBitmap );
95 ADD_OBJECTS( BitmapFont );
97 ADD_OBJECTS( Window );
98 ADD_OBJECTS( Layout );
99 ADD_OBJECTS( Anchor );
100 ADD_OBJECTS( Button );
101 ADD_OBJECTS( Checkbox );
102 ADD_OBJECTS( Image );
104 ADD_OBJECTS( RadialSlider );
105 ADD_OBJECTS( Slider );
108 ADD_OBJECTS( Video );
114 // Macro to get a bitmap by its ID in the builder
115 #define GET_BMP( pBmp, id ) \
118 pBmp = m_pTheme->getBitmapById(id); \
121 msg_Err( getIntf(), "unknown bitmap id: %s", id.c_str() ); \
126 void Builder::addTheme( const BuilderData::Theme &rData )
128 WindowManager &rManager = m_pTheme->getWindowManager();
129 rManager.setMagnetValue( rData.m_magnet );
130 rManager.setAlphaValue( rData.m_alpha );
131 rManager.setMoveAlphaValue( rData.m_moveAlpha );
132 GenericFont *pFont = getFont( rData.m_tooltipfont );
135 rManager.createTooltip( *pFont );
139 msg_Warn( getIntf(), "Invalid tooltip font: %s",
140 rData.m_tooltipfont.c_str() );
145 void Builder::addBitmap( const BuilderData::Bitmap &rData )
147 GenericBitmap *pBmp =
148 new FileBitmap( getIntf(), m_pImageHandler,
149 getFilePath( rData.m_fileName ), rData.m_alphaColor );
150 if( !pBmp->getData() )
156 m_pTheme->m_bitmaps[rData.m_id] = GenericBitmapPtr( pBmp );
160 void Builder::addSubBitmap( const BuilderData::SubBitmap &rData )
162 if( m_pTheme->m_bitmaps.find( rData.m_id ) != m_pTheme->m_bitmaps.end() )
164 msg_Dbg( getIntf(), "Bitmap %s already exists", rData.m_id.c_str() );
168 // Get the parent bitmap
169 GenericBitmap *pParentBmp = NULL;
170 GET_BMP( pParentBmp, rData.m_parent );
172 // Copy a region of the parent bitmap to the new one
174 new BitmapImpl( getIntf(), rData.m_width, rData.m_height );
175 bool res = pBmp->drawBitmap( *pParentBmp, rData.m_x, rData.m_y, 0, 0,
176 rData.m_width, rData.m_height );
179 // Invalid sub-bitmap
181 msg_Warn( getIntf(), "SubBitmap %s ignored", rData.m_id.c_str() );
184 m_pTheme->m_bitmaps[rData.m_id] = GenericBitmapPtr( pBmp );
188 void Builder::addBitmapFont( const BuilderData::BitmapFont &rData )
190 if( m_pTheme->m_fonts.find( rData.m_id ) != m_pTheme->m_fonts.end() )
192 msg_Dbg( getIntf(), "Font %s already exists", rData.m_id.c_str() );
196 GenericBitmap *pBmp =
197 new FileBitmap( getIntf(), m_pImageHandler,
198 getFilePath( rData.m_file ), 0 );
199 if( !pBmp->getData() )
206 m_pTheme->m_bitmaps[rData.m_id] = GenericBitmapPtr( pBmp );
208 GenericFont *pFont = new BitmapFont( getIntf(), *pBmp, rData.m_type );
211 m_pTheme->m_fonts[rData.m_id] = GenericFontPtr( pFont );
220 void Builder::addFont( const BuilderData::Font &rData )
222 // Try to load the font from the theme directory
223 GenericFont *pFont = new FT2Font( getIntf(),
224 getFilePath( rData.m_fontFile ),
228 m_pTheme->m_fonts[rData.m_id] = GenericFontPtr( pFont );
234 // Font not found; try in the resource path
235 OSFactory *pOSFactory = OSFactory::instance( getIntf() );
236 const list<string> &resPath = pOSFactory->getResourcePath();
237 const string &sep = pOSFactory->getDirSeparator();
239 list<string>::const_iterator it;
240 for( it = resPath.begin(); it != resPath.end(); it++ )
242 string path = (*it) + sep + "fonts" + sep + rData.m_fontFile;
243 pFont = new FT2Font( getIntf(), path, rData.m_size );
246 // Font loaded successfully
247 m_pTheme->m_fonts[rData.m_id] = GenericFontPtr( pFont );
259 void Builder::addWindow( const BuilderData::Window &rData )
262 new TopWindow( getIntf(), rData.m_xPos, rData.m_yPos,
263 m_pTheme->getWindowManager(),
264 rData.m_dragDrop, rData.m_playOnDrop,
267 m_pTheme->m_windows[rData.m_id] = TopWindowPtr( pWin );
271 void Builder::addLayout( const BuilderData::Layout &rData )
273 TopWindow *pWin = m_pTheme->getWindowById(rData.m_windowId);
276 msg_Err( getIntf(), "unknown window id: %s", rData.m_windowId.c_str() );
280 int minWidth = rData.m_minWidth != -1 ? rData.m_minWidth : rData.m_width;
281 int maxWidth = rData.m_maxWidth != -1 ? rData.m_maxWidth : rData.m_width;
282 int minHeight = rData.m_minHeight != -1 ? rData.m_minHeight :
284 int maxHeight = rData.m_maxHeight != -1 ? rData.m_maxHeight :
286 GenericLayout *pLayout = new GenericLayout( getIntf(), rData.m_width,
288 minWidth, maxWidth, minHeight,
290 m_pTheme->m_layouts[rData.m_id] = GenericLayoutPtr( pLayout );
292 // Attach the layout to its window
293 m_pTheme->getWindowManager().addLayout( *pWin, *pLayout );
297 void Builder::addAnchor( const BuilderData::Anchor &rData )
299 GenericLayout *pLayout = m_pTheme->getLayoutById(rData.m_layoutId);
300 if( pLayout == NULL )
302 msg_Err( getIntf(), "unknown layout id: %s", rData.m_layoutId.c_str() );
306 Bezier *pCurve = getPoints( rData.m_points.c_str() );
309 msg_Err( getIntf(), "Invalid format in tag points=\"%s\"",
310 rData.m_points.c_str() );
313 m_pTheme->m_curves.push_back( BezierPtr( pCurve ) );
315 Anchor *pAnc = new Anchor( getIntf(), rData.m_xPos, rData.m_yPos,
316 rData.m_range, rData.m_priority,
318 pLayout->addAnchor( pAnc );
322 void Builder::addButton( const BuilderData::Button &rData )
324 // Get the bitmaps of the button
325 GenericBitmap *pBmpUp = NULL;
326 GET_BMP( pBmpUp, rData.m_upId );
328 GenericBitmap *pBmpDown = pBmpUp;
329 GET_BMP( pBmpDown, rData.m_downId );
331 GenericBitmap *pBmpOver = pBmpUp;
332 GET_BMP( pBmpOver, rData.m_overId );
334 GenericLayout *pLayout = m_pTheme->getLayoutById(rData.m_layoutId);
335 if( pLayout == NULL )
337 msg_Err( getIntf(), "unknown layout id: %s", rData.m_layoutId.c_str() );
341 CmdGeneric *pCommand = parseAction( rData.m_actionId );
342 if( pCommand == NULL )
344 msg_Err( getIntf(), "Invalid action: %s", rData.m_actionId.c_str() );
348 // Get the visibility variable
349 // XXX check when it is null
350 Interpreter *pInterpreter = Interpreter::instance( getIntf() );
351 VarBool *pVisible = pInterpreter->getVarBool( rData.m_visible, m_pTheme );
353 CtrlButton *pButton = new CtrlButton( getIntf(), *pBmpUp, *pBmpOver,
354 *pBmpDown, *pCommand, UString( getIntf(), rData.m_tooltip.c_str() ),
355 UString( getIntf(), rData.m_help.c_str() ), pVisible );
357 // Compute the position of the control
358 // XXX (we suppose all the images have the same size...)
359 const Position pos = makePosition( rData.m_leftTop, rData.m_rightBottom,
360 rData.m_xPos, rData.m_yPos,
362 pBmpUp->getHeight(), *pLayout );
364 pLayout->addControl( pButton, pos, rData.m_layer );
366 m_pTheme->m_controls[rData.m_id] = CtrlGenericPtr( pButton );
370 void Builder::addCheckbox( const BuilderData::Checkbox &rData )
372 // Get the bitmaps of the checkbox
373 GenericBitmap *pBmpUp1 = NULL;
374 GET_BMP( pBmpUp1, rData.m_up1Id );
376 GenericBitmap *pBmpDown1 = pBmpUp1;
377 GET_BMP( pBmpDown1, rData.m_down1Id );
379 GenericBitmap *pBmpOver1 = pBmpUp1;
380 GET_BMP( pBmpOver1, rData.m_over1Id );
382 GenericBitmap *pBmpUp2 = NULL;
383 GET_BMP( pBmpUp2, rData.m_up2Id );
385 GenericBitmap *pBmpDown2 = pBmpUp2;
386 GET_BMP( pBmpDown2, rData.m_down2Id );
388 GenericBitmap *pBmpOver2 = pBmpUp2;
389 GET_BMP( pBmpOver2, rData.m_over2Id );
391 GenericLayout *pLayout = m_pTheme->getLayoutById(rData.m_layoutId);
392 if( pLayout == NULL )
394 msg_Err( getIntf(), "unknown layout id: %s", rData.m_layoutId.c_str() );
398 CmdGeneric *pCommand1 = parseAction( rData.m_action1 );
399 if( pCommand1 == NULL )
401 msg_Err( getIntf(), "Invalid action: %s", rData.m_action1.c_str() );
405 CmdGeneric *pCommand2 = parseAction( rData.m_action2 );
406 if( pCommand2 == NULL )
408 msg_Err( getIntf(), "Invalid action: %s", rData.m_action2.c_str() );
412 // Get the state variable
413 Interpreter *pInterpreter = Interpreter::instance( getIntf() );
414 VarBool *pVar = pInterpreter->getVarBool( rData.m_state, m_pTheme );
417 // TODO: default state
421 // Get the visibility variable
422 // XXX check when it is null
423 VarBool *pVisible = pInterpreter->getVarBool( rData.m_visible, m_pTheme );
425 // Create the control
426 CtrlCheckbox *pCheckbox = new CtrlCheckbox( getIntf(), *pBmpUp1,
427 *pBmpOver1, *pBmpDown1, *pBmpUp2, *pBmpOver2, *pBmpDown2, *pCommand1,
428 *pCommand2, UString( getIntf(), rData.m_tooltip1.c_str() ),
429 UString( getIntf(), rData.m_tooltip2.c_str() ), *pVar,
430 UString( getIntf(), rData.m_help.c_str() ), pVisible );
432 // Compute the position of the control
433 // XXX (we suppose all the images have the same size...)
434 const Position pos = makePosition( rData.m_leftTop, rData.m_rightBottom,
435 rData.m_xPos, rData.m_yPos,
437 pBmpUp1->getHeight(), *pLayout );
439 pLayout->addControl( pCheckbox, pos, rData.m_layer );
441 m_pTheme->m_controls[rData.m_id] = CtrlGenericPtr( pCheckbox );
445 void Builder::addImage( const BuilderData::Image &rData )
447 GenericBitmap *pBmp = NULL;
448 GET_BMP( pBmp, rData.m_bmpId );
450 GenericLayout *pLayout = m_pTheme->getLayoutById(rData.m_layoutId);
451 if( pLayout == NULL )
453 msg_Err( getIntf(), "unknown layout id: %s", rData.m_layoutId.c_str() );
457 TopWindow *pWindow = m_pTheme->getWindowById(rData.m_windowId);
458 if( pWindow == NULL )
460 msg_Err( getIntf(), "unknown window id: %s", rData.m_windowId.c_str() );
464 // Get the visibility variable
465 // XXX check when it is null
466 Interpreter *pInterpreter = Interpreter::instance( getIntf() );
467 VarBool *pVisible = pInterpreter->getVarBool( rData.m_visible, m_pTheme );
469 CtrlImage::resize_t resizeMethod =
470 (rData.m_resize == "scale" ? CtrlImage::kScale : CtrlImage::kMosaic);
471 CtrlImage *pImage = new CtrlImage( getIntf(), *pBmp, resizeMethod,
472 UString( getIntf(), rData.m_help.c_str() ), pVisible );
474 // Compute the position of the control
475 const Position pos = makePosition( rData.m_leftTop, rData.m_rightBottom,
477 rData.m_yPos, pBmp->getWidth(),
478 pBmp->getHeight(), *pLayout );
480 // XXX: test to be changed! XXX
481 if( rData.m_actionId == "move" )
483 CtrlMove *pMove = new CtrlMove( getIntf(), m_pTheme->getWindowManager(),
484 *pImage, *pWindow, UString( getIntf(), rData.m_help.c_str() ),
486 pLayout->addControl( pMove, pos, rData.m_layer );
488 else if( rData.m_actionId == "resizeSE" )
490 CtrlResize *pResize = new CtrlResize( getIntf(), *pImage, *pLayout,
491 UString( getIntf(), rData.m_help.c_str() ), NULL );
492 pLayout->addControl( pResize, pos, rData.m_layer );
496 pLayout->addControl( pImage, pos, rData.m_layer );
499 m_pTheme->m_controls[rData.m_id] = CtrlGenericPtr( pImage );
503 void Builder::addText( const BuilderData::Text &rData )
505 GenericLayout *pLayout = m_pTheme->getLayoutById(rData.m_layoutId);
506 if( pLayout == NULL )
508 msg_Err( getIntf(), "unknown layout id: %s", rData.m_layoutId.c_str() );
512 GenericFont *pFont = getFont( rData.m_fontId );
515 msg_Err( getIntf(), "Unknown font id: %s", rData.m_fontId.c_str() );
519 // Create a text variable
520 VarText *pVar = new VarText( getIntf() );
521 UString msg( getIntf(), rData.m_text.c_str() );
523 m_pTheme->m_vars.push_back( VariablePtr( pVar ) );
525 // Get the visibility variable
526 // XXX check when it is null
527 Interpreter *pInterpreter = Interpreter::instance( getIntf() );
528 VarBool *pVisible = pInterpreter->getVarBool( rData.m_visible, m_pTheme );
530 CtrlText *pText = new CtrlText( getIntf(), *pVar, *pFont,
531 UString( getIntf(), rData.m_help.c_str() ), rData.m_color, pVisible );
533 int height = pFont->getSize();
535 // Compute the position of the control
536 const Position pos = makePosition( rData.m_leftTop, rData.m_rightBottom,
537 rData.m_xPos, rData.m_yPos,
538 rData.m_width, height,
541 pLayout->addControl( pText, pos, rData.m_layer );
543 m_pTheme->m_controls[rData.m_id] = CtrlGenericPtr( pText );
547 void Builder::addRadialSlider( const BuilderData::RadialSlider &rData )
549 // Get the bitmaps of the slider
550 GenericBitmap *pSeq = NULL;
551 GET_BMP( pSeq, rData.m_sequence );
553 GenericLayout *pLayout = m_pTheme->getLayoutById(rData.m_layoutId);
554 if( pLayout == NULL )
556 msg_Err( getIntf(), "unknown layout id: %s", rData.m_layoutId.c_str() );
560 // Get the variable associated to the slider
561 Interpreter *pInterpreter = Interpreter::instance( getIntf() );
562 VarPercent *pVar = pInterpreter->getVarPercent( rData.m_value, m_pTheme );
565 msg_Err( getIntf(), "Unknown slider value: %s", rData.m_value.c_str() );
569 // Get the visibility variable
570 // XXX check when it is null
571 VarBool *pVisible = pInterpreter->getVarBool( rData.m_visible, m_pTheme );
573 // Create the control
574 CtrlRadialSlider *pRadial =
575 new CtrlRadialSlider( getIntf(), *pSeq, rData.m_nbImages, *pVar,
576 rData.m_minAngle, rData.m_maxAngle,
577 UString( getIntf(), rData.m_help.c_str() ),
580 // XXX: resizing is not supported
581 // Compute the position of the control
583 makePosition( rData.m_leftTop, rData.m_rightBottom, rData.m_xPos,
584 rData.m_yPos, pSeq->getWidth(),
585 pSeq->getHeight() / rData.m_nbImages, *pLayout );
587 pLayout->addControl( pRadial, pos, rData.m_layer );
589 m_pTheme->m_controls[rData.m_id] = CtrlGenericPtr( pRadial );
593 void Builder::addSlider( const BuilderData::Slider &rData )
595 // Add the background first, so that we will still have something almost
596 // functional if the cursor cannot be created properly (this happens for
597 // some winamp2 skins, where the images of the cursor are not always
600 // Get the bitmaps of the background
601 GenericBitmap *pBgImage = NULL;
602 if( rData.m_imageId != "none" )
604 GET_BMP( pBgImage, rData.m_imageId );
607 GenericLayout *pLayout = m_pTheme->getLayoutById(rData.m_layoutId);
608 if( pLayout == NULL )
610 msg_Err( getIntf(), "unknown layout id: %s", rData.m_layoutId.c_str() );
614 Bezier *pCurve = getPoints( rData.m_points.c_str() );
617 msg_Err( getIntf(), "Invalid format in tag points=\"%s\"",
618 rData.m_points.c_str() );
621 m_pTheme->m_curves.push_back( BezierPtr( pCurve ) );
623 // Get the visibility variable
624 // XXX check when it is null
625 Interpreter *pInterpreter = Interpreter::instance( getIntf() );
626 VarBool *pVisible = pInterpreter->getVarBool( rData.m_visible, m_pTheme );
628 // Get the variable associated to the slider
629 VarPercent *pVar = pInterpreter->getVarPercent( rData.m_value, m_pTheme );
632 msg_Err( getIntf(), "Unknown slider value: %s", rData.m_value.c_str() );
636 // Create the background control
637 CtrlSliderBg *pBackground = new CtrlSliderBg( getIntf(),
638 *pCurve, *pVar, rData.m_thickness, pBgImage, rData.m_nbHoriz,
639 rData.m_nbVert, rData.m_padHoriz, rData.m_padVert,
640 pVisible, UString( getIntf(), rData.m_help.c_str() ) );
642 // Compute the position of the control
643 const Position pos = makePosition( rData.m_leftTop, rData.m_rightBottom,
644 rData.m_xPos, rData.m_yPos,
645 pCurve->getWidth(), pCurve->getHeight(),
648 pLayout->addControl( pBackground, pos, rData.m_layer );
650 m_pTheme->m_controls[rData.m_id + "_bg"] = CtrlGenericPtr( pBackground );
652 // Get the bitmaps of the cursor
653 GenericBitmap *pBmpUp = NULL;
654 GET_BMP( pBmpUp, rData.m_upId );
656 GenericBitmap *pBmpDown = pBmpUp;
657 GET_BMP( pBmpDown, rData.m_downId );
659 GenericBitmap *pBmpOver = pBmpUp;
660 GET_BMP( pBmpOver, rData.m_overId );
662 // Create the cursor control
663 CtrlSliderCursor *pCursor = new CtrlSliderCursor( getIntf(), *pBmpUp,
664 *pBmpOver, *pBmpDown, *pCurve, *pVar, pVisible,
665 UString( getIntf(), rData.m_tooltip.c_str() ),
666 UString( getIntf(), rData.m_help.c_str() ) );
668 pLayout->addControl( pCursor, pos, rData.m_layer );
670 m_pTheme->m_controls[rData.m_id] = CtrlGenericPtr( pCursor );
672 // Associate the cursor to the background
673 pBackground->associateCursor( *pCursor );
677 void Builder::addList( const BuilderData::List &rData )
679 // Get the background bitmap, if any
680 GenericBitmap *pBgBmp = NULL;
681 GET_BMP( pBgBmp, rData.m_bgImageId );
683 GenericLayout *pLayout = m_pTheme->getLayoutById(rData.m_layoutId);
684 if( pLayout == NULL )
686 msg_Err( getIntf(), "unknown layout id: %s", rData.m_layoutId.c_str() );
690 GenericFont *pFont = getFont( rData.m_fontId );
693 msg_Err( getIntf(), "Unknown font id: %s", rData.m_fontId.c_str() );
697 // Get the list variable
698 Interpreter *pInterpreter = Interpreter::instance( getIntf() );
699 VarList *pVar = pInterpreter->getVarList( rData.m_var, m_pTheme );
702 msg_Err( getIntf(), "No such list variable: %s", rData.m_var.c_str() );
706 // Get the visibility variable
707 // XXX check when it is null
708 VarBool *pVisible = pInterpreter->getVarBool( rData.m_visible, m_pTheme );
710 // Create the list control
711 CtrlList *pList = new CtrlList( getIntf(), *pVar, *pFont, pBgBmp,
712 rData.m_fgColor, rData.m_playColor, rData.m_bgColor1,
713 rData.m_bgColor2, rData.m_selColor,
714 UString( getIntf(), rData.m_help.c_str() ), pVisible );
716 // Compute the position of the control
717 const Position pos = makePosition( rData.m_leftTop, rData.m_rightBottom,
718 rData.m_xPos, rData.m_yPos,
719 rData.m_width, rData.m_height,
722 pLayout->addControl( pList, pos, rData.m_layer );
724 m_pTheme->m_controls[rData.m_id] = CtrlGenericPtr( pList );
727 void Builder::addTree( const BuilderData::Tree &rData )
729 // Get the bitmaps, if any
730 GenericBitmap *pBgBmp = NULL;
731 GenericBitmap *pItemBmp = NULL;
732 GenericBitmap *pOpenBmp = NULL;
733 GenericBitmap *pClosedBmp = NULL;
734 GET_BMP( pBgBmp, rData.m_bgImageId );
735 GET_BMP( pItemBmp, rData.m_itemImageId );
736 GET_BMP( pOpenBmp, rData.m_openImageId );
737 GET_BMP( pClosedBmp, rData.m_closedImageId );
739 GenericLayout *pLayout = m_pTheme->getLayoutById(rData.m_layoutId);
740 if( pLayout == NULL )
742 msg_Err( getIntf(), "unknown layout id: %s", rData.m_layoutId.c_str() );
746 GenericFont *pFont = getFont( rData.m_fontId );
749 msg_Err( getIntf(), "Unknown font id: %s", rData.m_fontId.c_str() );
753 // Get the list variable
754 Interpreter *pInterpreter = Interpreter::instance( getIntf() );
755 VarTree *pVar = pInterpreter->getVarTree( rData.m_var, m_pTheme );
758 msg_Err( getIntf(), "No such list variable: %s", rData.m_var.c_str() );
762 // Get the visibility variable
763 // XXX check when it is null
764 VarBool *pVisible = pInterpreter->getVarBool( rData.m_visible, m_pTheme );
766 // Create the list control
767 CtrlTree *pTree = new CtrlTree( getIntf(), *pVar, *pFont, pBgBmp,
768 pItemBmp, pOpenBmp, pClosedBmp,
769 rData.m_fgColor, rData.m_playColor, rData.m_bgColor1,
770 rData.m_bgColor2, rData.m_selColor,
771 UString( getIntf(), rData.m_help.c_str() ), pVisible );
773 // Compute the position of the control
774 const Position pos = makePosition( rData.m_leftTop, rData.m_rightBottom,
775 rData.m_xPos, rData.m_yPos,
776 rData.m_width, rData.m_height,
779 pLayout->addControl( pTree, pos, rData.m_layer );
781 m_pTheme->m_controls[rData.m_id] = CtrlGenericPtr( pTree );
784 void Builder::addVideo( const BuilderData::Video &rData )
786 GenericLayout *pLayout = m_pTheme->getLayoutById(rData.m_layoutId);
787 if( pLayout == NULL )
789 msg_Err( getIntf(), "unknown layout id: %s", rData.m_layoutId.c_str() );
793 // Get the visibility variable
794 // XXX check when it is null
795 Interpreter *pInterpreter = Interpreter::instance( getIntf() );
796 VarBool *pVisible = pInterpreter->getVarBool( rData.m_visible, m_pTheme );
798 CtrlVideo *pVideo = new CtrlVideo( getIntf(), *pLayout,
799 rData.m_autoResize, UString( getIntf(), rData.m_help.c_str() ),
802 // Compute the position of the control
803 const Position pos = makePosition( rData.m_leftTop, rData.m_rightBottom,
804 rData.m_xPos, rData.m_yPos,
805 rData.m_width, rData.m_height,
808 pLayout->addControl( pVideo, pos, rData.m_layer );
810 m_pTheme->m_controls[rData.m_id] = CtrlGenericPtr( pVideo );
814 const Position Builder::makePosition( const string &rLeftTop,
815 const string &rRightBottom,
816 int xPos, int yPos, int width,
817 int height, const Box &rBox ) const
819 int left = 0, top = 0, right = 0, bottom = 0;
820 Position::Ref_t refLeftTop = Position::kLeftTop;
821 Position::Ref_t refRightBottom = Position::kLeftTop;
823 int boxWidth = rBox.getWidth();
824 int boxHeight = rBox.getHeight();
826 // Position of the left top corner
827 if( rLeftTop == "lefttop" )
831 refLeftTop = Position::kLeftTop;
833 else if( rLeftTop == "righttop" )
835 left = xPos - boxWidth + 1;
837 refLeftTop = Position::kRightTop;
839 else if( rLeftTop == "leftbottom" )
842 top = yPos - boxHeight + 1;
843 refLeftTop = Position::kLeftBottom;
845 else if( rLeftTop == "rightbottom" )
847 left = xPos - boxWidth + 1;
848 top = yPos - boxHeight + 1;
849 refLeftTop = Position::kRightBottom;
852 // Position of the right bottom corner
853 if( rRightBottom == "lefttop" )
855 right = xPos + width - 1;
856 bottom = yPos + height - 1;
857 refRightBottom = Position::kLeftTop;
859 else if( rRightBottom == "righttop" )
861 right = xPos + width - boxWidth;
862 bottom = yPos + height - 1;
863 refRightBottom = Position::kRightTop;
865 else if( rRightBottom == "leftbottom" )
867 right = xPos + width - 1;
868 bottom = yPos + height - boxHeight;
869 refRightBottom = Position::kLeftBottom;
871 else if( rRightBottom == "rightbottom" )
873 right = xPos + width - boxWidth;
874 bottom = yPos + height - boxHeight;
875 refRightBottom = Position::kRightBottom;
878 return Position( left, top, right, bottom, rBox, refLeftTop,
883 GenericFont *Builder::getFont( const string &fontId )
885 GenericFont *pFont = m_pTheme->getFontById(fontId);
886 if( !pFont && fontId == "defaultfont" )
888 // Get the resource path and try to load the default font
889 OSFactory *pOSFactory = OSFactory::instance( getIntf() );
890 const list<string> &resPath = pOSFactory->getResourcePath();
891 const string &sep = pOSFactory->getDirSeparator();
893 list<string>::const_iterator it;
894 for( it = resPath.begin(); it != resPath.end(); it++ )
896 string path = (*it) + sep + "fonts" + sep + "FreeSans.ttf";
897 pFont = new FT2Font( getIntf(), path, 12 );
900 // Font loaded successfully
901 m_pTheme->m_fonts["defaultfont"] = GenericFontPtr( pFont );
912 msg_Err( getIntf(), "Failed to open the default font" );
919 string Builder::getFilePath( const string &rFileName ) const
921 OSFactory *pFactory = OSFactory::instance( getIntf() );
922 return m_path + pFactory->getDirSeparator() + rFileName;
927 Bezier *Builder::getPoints( const char *pTag ) const
929 vector<float> xBez, yBez;
933 if( sscanf( pTag, "(%d,%d)%n", &x, &y, &n ) < 1 )
941 "Slider points cannot have negative coordinates!" );
952 if( *(pTag++) != ',' )
958 // Create the Bezier curve
959 return new Bezier( getIntf(), xBez, yBez );