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 rData.m_nbFrames, rData.m_fps );
151 if( !pBmp->getData() )
157 m_pTheme->m_bitmaps[rData.m_id] = GenericBitmapPtr( pBmp );
161 void Builder::addSubBitmap( const BuilderData::SubBitmap &rData )
163 if( m_pTheme->m_bitmaps.find( rData.m_id ) != m_pTheme->m_bitmaps.end() )
165 msg_Dbg( getIntf(), "Bitmap %s already exists", rData.m_id.c_str() );
169 // Get the parent bitmap
170 GenericBitmap *pParentBmp = NULL;
171 GET_BMP( pParentBmp, rData.m_parent );
173 // Copy a region of the parent bitmap to the new one
175 new BitmapImpl( getIntf(), rData.m_width, rData.m_height,
176 rData.m_nbFrames, rData.m_fps );
177 bool res = pBmp->drawBitmap( *pParentBmp, rData.m_x, rData.m_y, 0, 0,
178 rData.m_width, rData.m_height );
181 // Invalid sub-bitmap
183 msg_Warn( getIntf(), "SubBitmap %s ignored", rData.m_id.c_str() );
186 m_pTheme->m_bitmaps[rData.m_id] = GenericBitmapPtr( pBmp );
190 void Builder::addBitmapFont( const BuilderData::BitmapFont &rData )
192 if( m_pTheme->m_fonts.find( rData.m_id ) != m_pTheme->m_fonts.end() )
194 msg_Dbg( getIntf(), "Font %s already exists", rData.m_id.c_str() );
198 GenericBitmap *pBmp =
199 new FileBitmap( getIntf(), m_pImageHandler,
200 getFilePath( rData.m_file ), 0 );
201 if( !pBmp->getData() )
208 m_pTheme->m_bitmaps[rData.m_id] = GenericBitmapPtr( pBmp );
210 GenericFont *pFont = new BitmapFont( getIntf(), *pBmp, rData.m_type );
213 m_pTheme->m_fonts[rData.m_id] = GenericFontPtr( pFont );
222 void Builder::addFont( const BuilderData::Font &rData )
224 // Try to load the font from the theme directory
225 GenericFont *pFont = new FT2Font( getIntf(),
226 getFilePath( rData.m_fontFile ),
230 m_pTheme->m_fonts[rData.m_id] = GenericFontPtr( pFont );
236 // Font not found; try in the resource path
237 OSFactory *pOSFactory = OSFactory::instance( getIntf() );
238 const list<string> &resPath = pOSFactory->getResourcePath();
239 const string &sep = pOSFactory->getDirSeparator();
241 list<string>::const_iterator it;
242 for( it = resPath.begin(); it != resPath.end(); it++ )
244 string path = (*it) + sep + "fonts" + sep + rData.m_fontFile;
245 pFont = new FT2Font( getIntf(), path, rData.m_size );
248 // Font loaded successfully
249 m_pTheme->m_fonts[rData.m_id] = GenericFontPtr( pFont );
261 void Builder::addWindow( const BuilderData::Window &rData )
264 new TopWindow( getIntf(), rData.m_xPos, rData.m_yPos,
265 m_pTheme->getWindowManager(),
266 rData.m_dragDrop, rData.m_playOnDrop,
269 m_pTheme->m_windows[rData.m_id] = TopWindowPtr( pWin );
273 void Builder::addLayout( const BuilderData::Layout &rData )
275 TopWindow *pWin = m_pTheme->getWindowById(rData.m_windowId);
278 msg_Err( getIntf(), "unknown window id: %s", rData.m_windowId.c_str() );
282 int minWidth = rData.m_minWidth != -1 ? rData.m_minWidth : rData.m_width;
283 int maxWidth = rData.m_maxWidth != -1 ? rData.m_maxWidth : rData.m_width;
284 int minHeight = rData.m_minHeight != -1 ? rData.m_minHeight :
286 int maxHeight = rData.m_maxHeight != -1 ? rData.m_maxHeight :
288 GenericLayout *pLayout = new GenericLayout( getIntf(), rData.m_width,
290 minWidth, maxWidth, minHeight,
292 m_pTheme->m_layouts[rData.m_id] = GenericLayoutPtr( pLayout );
294 // Attach the layout to its window
295 m_pTheme->getWindowManager().addLayout( *pWin, *pLayout );
299 void Builder::addAnchor( const BuilderData::Anchor &rData )
301 GenericLayout *pLayout = m_pTheme->getLayoutById(rData.m_layoutId);
302 if( pLayout == NULL )
304 msg_Err( getIntf(), "unknown layout id: %s", rData.m_layoutId.c_str() );
308 Bezier *pCurve = getPoints( rData.m_points.c_str() );
311 msg_Err( getIntf(), "Invalid format in tag points=\"%s\"",
312 rData.m_points.c_str() );
315 m_pTheme->m_curves.push_back( BezierPtr( pCurve ) );
317 Anchor *pAnc = new Anchor( getIntf(), rData.m_xPos, rData.m_yPos,
318 rData.m_range, rData.m_priority,
320 pLayout->addAnchor( pAnc );
324 void Builder::addButton( const BuilderData::Button &rData )
326 // Get the bitmaps of the button
327 GenericBitmap *pBmpUp = NULL;
328 GET_BMP( pBmpUp, rData.m_upId );
330 GenericBitmap *pBmpDown = pBmpUp;
331 GET_BMP( pBmpDown, rData.m_downId );
333 GenericBitmap *pBmpOver = pBmpUp;
334 GET_BMP( pBmpOver, rData.m_overId );
336 GenericLayout *pLayout = m_pTheme->getLayoutById(rData.m_layoutId);
337 if( pLayout == NULL )
339 msg_Err( getIntf(), "unknown layout id: %s", rData.m_layoutId.c_str() );
343 CmdGeneric *pCommand = parseAction( rData.m_actionId );
344 if( pCommand == NULL )
346 msg_Err( getIntf(), "Invalid action: %s", rData.m_actionId.c_str() );
350 // Get the visibility variable
351 // XXX check when it is null
352 Interpreter *pInterpreter = Interpreter::instance( getIntf() );
353 VarBool *pVisible = pInterpreter->getVarBool( rData.m_visible, m_pTheme );
355 CtrlButton *pButton = new CtrlButton( getIntf(), *pBmpUp, *pBmpOver,
356 *pBmpDown, *pCommand, UString( getIntf(), rData.m_tooltip.c_str() ),
357 UString( getIntf(), rData.m_help.c_str() ), pVisible );
359 // Compute the position of the control
360 // XXX (we suppose all the images have the same size...)
361 const Position pos = makePosition( rData.m_leftTop, rData.m_rightBottom,
362 rData.m_xPos, rData.m_yPos,
364 pBmpUp->getHeight(), *pLayout );
366 pLayout->addControl( pButton, pos, rData.m_layer );
368 m_pTheme->m_controls[rData.m_id] = CtrlGenericPtr( pButton );
372 void Builder::addCheckbox( const BuilderData::Checkbox &rData )
374 // Get the bitmaps of the checkbox
375 GenericBitmap *pBmpUp1 = NULL;
376 GET_BMP( pBmpUp1, rData.m_up1Id );
378 GenericBitmap *pBmpDown1 = pBmpUp1;
379 GET_BMP( pBmpDown1, rData.m_down1Id );
381 GenericBitmap *pBmpOver1 = pBmpUp1;
382 GET_BMP( pBmpOver1, rData.m_over1Id );
384 GenericBitmap *pBmpUp2 = NULL;
385 GET_BMP( pBmpUp2, rData.m_up2Id );
387 GenericBitmap *pBmpDown2 = pBmpUp2;
388 GET_BMP( pBmpDown2, rData.m_down2Id );
390 GenericBitmap *pBmpOver2 = pBmpUp2;
391 GET_BMP( pBmpOver2, rData.m_over2Id );
393 GenericLayout *pLayout = m_pTheme->getLayoutById(rData.m_layoutId);
394 if( pLayout == NULL )
396 msg_Err( getIntf(), "unknown layout id: %s", rData.m_layoutId.c_str() );
400 CmdGeneric *pCommand1 = parseAction( rData.m_action1 );
401 if( pCommand1 == NULL )
403 msg_Err( getIntf(), "Invalid action: %s", rData.m_action1.c_str() );
407 CmdGeneric *pCommand2 = parseAction( rData.m_action2 );
408 if( pCommand2 == NULL )
410 msg_Err( getIntf(), "Invalid action: %s", rData.m_action2.c_str() );
414 // Get the state variable
415 Interpreter *pInterpreter = Interpreter::instance( getIntf() );
416 VarBool *pVar = pInterpreter->getVarBool( rData.m_state, m_pTheme );
419 // TODO: default state
423 // Get the visibility variable
424 // XXX check when it is null
425 VarBool *pVisible = pInterpreter->getVarBool( rData.m_visible, m_pTheme );
427 // Create the control
428 CtrlCheckbox *pCheckbox = new CtrlCheckbox( getIntf(), *pBmpUp1,
429 *pBmpOver1, *pBmpDown1, *pBmpUp2, *pBmpOver2, *pBmpDown2, *pCommand1,
430 *pCommand2, UString( getIntf(), rData.m_tooltip1.c_str() ),
431 UString( getIntf(), rData.m_tooltip2.c_str() ), *pVar,
432 UString( getIntf(), rData.m_help.c_str() ), pVisible );
434 // Compute the position of the control
435 // XXX (we suppose all the images have the same size...)
436 const Position pos = makePosition( rData.m_leftTop, rData.m_rightBottom,
437 rData.m_xPos, rData.m_yPos,
439 pBmpUp1->getHeight(), *pLayout );
441 pLayout->addControl( pCheckbox, pos, rData.m_layer );
443 m_pTheme->m_controls[rData.m_id] = CtrlGenericPtr( pCheckbox );
447 void Builder::addImage( const BuilderData::Image &rData )
449 GenericBitmap *pBmp = NULL;
450 GET_BMP( pBmp, rData.m_bmpId );
452 GenericLayout *pLayout = m_pTheme->getLayoutById(rData.m_layoutId);
453 if( pLayout == NULL )
455 msg_Err( getIntf(), "unknown layout id: %s", rData.m_layoutId.c_str() );
459 TopWindow *pWindow = m_pTheme->getWindowById(rData.m_windowId);
460 if( pWindow == NULL )
462 msg_Err( getIntf(), "unknown window id: %s", rData.m_windowId.c_str() );
466 CmdGeneric *pCommand = parseAction( rData.m_action2Id );
467 if( pCommand == NULL )
469 msg_Err( getIntf(), "Invalid action: %s", rData.m_action2Id.c_str() );
473 // Get the visibility variable
474 // XXX check when it is null
475 Interpreter *pInterpreter = Interpreter::instance( getIntf() );
476 VarBool *pVisible = pInterpreter->getVarBool( rData.m_visible, m_pTheme );
478 CtrlImage::resize_t resizeMethod =
479 (rData.m_resize == "scale" ? CtrlImage::kScale : CtrlImage::kMosaic);
480 CtrlImage *pImage = new CtrlImage( getIntf(), *pBmp, *pCommand,
481 resizeMethod, UString( getIntf(), rData.m_help.c_str() ), pVisible );
483 // Compute the position of the control
484 const Position pos = makePosition( rData.m_leftTop, rData.m_rightBottom,
486 rData.m_yPos, pBmp->getWidth(),
487 pBmp->getHeight(), *pLayout );
489 // XXX: test to be changed! XXX
490 if( rData.m_actionId == "move" )
492 CtrlMove *pMove = new CtrlMove( getIntf(), m_pTheme->getWindowManager(),
493 *pImage, *pWindow, UString( getIntf(), rData.m_help.c_str() ),
495 pLayout->addControl( pMove, pos, rData.m_layer );
497 else if( rData.m_actionId == "resizeS" )
499 CtrlResize *pResize = new CtrlResize( getIntf(), *pImage, *pLayout,
500 UString( getIntf(), rData.m_help.c_str() ), NULL,
501 CtrlResize::kResizeS );
502 pLayout->addControl( pResize, pos, rData.m_layer );
504 else if( rData.m_actionId == "resizeE" )
506 CtrlResize *pResize = new CtrlResize( getIntf(), *pImage, *pLayout,
507 UString( getIntf(), rData.m_help.c_str() ), NULL,
508 CtrlResize::kResizeE );
509 pLayout->addControl( pResize, pos, rData.m_layer );
511 else if( rData.m_actionId == "resizeSE" )
513 CtrlResize *pResize = new CtrlResize( getIntf(), *pImage, *pLayout,
514 UString( getIntf(), rData.m_help.c_str() ), NULL,
515 CtrlResize::kResizeSE );
516 pLayout->addControl( pResize, pos, rData.m_layer );
520 pLayout->addControl( pImage, pos, rData.m_layer );
523 m_pTheme->m_controls[rData.m_id] = CtrlGenericPtr( pImage );
527 void Builder::addText( const BuilderData::Text &rData )
529 GenericLayout *pLayout = m_pTheme->getLayoutById(rData.m_layoutId);
530 if( pLayout == NULL )
532 msg_Err( getIntf(), "unknown layout id: %s", rData.m_layoutId.c_str() );
536 GenericFont *pFont = getFont( rData.m_fontId );
539 msg_Err( getIntf(), "Unknown font id: %s", rData.m_fontId.c_str() );
543 // Convert the scrolling mode
544 CtrlText::Scrolling_t scrolling;
545 if( rData.m_scrolling == "auto" )
546 scrolling = CtrlText::kAutomatic;
547 else if( rData.m_scrolling == "manual" )
548 scrolling = CtrlText::kManual;
549 else if( rData.m_scrolling == "none" )
550 scrolling = CtrlText::kNone;
553 msg_Err( getIntf(), "Invalid scrolling mode: %s",
554 rData.m_scrolling.c_str() );
558 // Convert the alignment
559 CtrlText::Align_t alignment;
560 if( rData.m_alignment == "left" )
561 alignment = CtrlText::kLeft;
562 else if( rData.m_alignment == "center" || rData.m_alignment == "centre" )
563 alignment = CtrlText::kCenter;
564 else if( rData.m_alignment == "right" )
565 alignment = CtrlText::kRight;
568 msg_Err( getIntf(), "Invalid alignment: %s",
569 rData.m_alignment.c_str() );
573 // Create a text variable
574 VarText *pVar = new VarText( getIntf() );
575 m_pTheme->m_vars.push_back( VariablePtr( pVar ) );
577 // Get the visibility variable
578 // XXX check when it is null
579 Interpreter *pInterpreter = Interpreter::instance( getIntf() );
580 VarBool *pVisible = pInterpreter->getVarBool( rData.m_visible, m_pTheme );
582 CtrlText *pText = new CtrlText( getIntf(), *pVar, *pFont,
583 UString( getIntf(), rData.m_help.c_str() ), rData.m_color, pVisible,
584 scrolling, alignment );
586 int height = pFont->getSize();
588 // Compute the position of the control
589 const Position pos = makePosition( rData.m_leftTop, rData.m_rightBottom,
590 rData.m_xPos, rData.m_yPos,
591 rData.m_width, height,
594 pLayout->addControl( pText, pos, rData.m_layer );
596 // Set the text of the control
597 UString msg( getIntf(), rData.m_text.c_str() );
600 m_pTheme->m_controls[rData.m_id] = CtrlGenericPtr( pText );
604 void Builder::addRadialSlider( const BuilderData::RadialSlider &rData )
606 // Get the bitmaps of the slider
607 GenericBitmap *pSeq = NULL;
608 GET_BMP( pSeq, rData.m_sequence );
610 GenericLayout *pLayout = m_pTheme->getLayoutById(rData.m_layoutId);
611 if( pLayout == NULL )
613 msg_Err( getIntf(), "unknown layout id: %s", rData.m_layoutId.c_str() );
617 // Get the variable associated to the slider
618 Interpreter *pInterpreter = Interpreter::instance( getIntf() );
619 VarPercent *pVar = pInterpreter->getVarPercent( rData.m_value, m_pTheme );
622 msg_Err( getIntf(), "Unknown slider value: %s", rData.m_value.c_str() );
626 // Get the visibility variable
627 // XXX check when it is null
628 VarBool *pVisible = pInterpreter->getVarBool( rData.m_visible, m_pTheme );
630 // Create the control
631 CtrlRadialSlider *pRadial =
632 new CtrlRadialSlider( getIntf(), *pSeq, rData.m_nbImages, *pVar,
633 rData.m_minAngle, rData.m_maxAngle,
634 UString( getIntf(), rData.m_help.c_str() ),
637 // XXX: resizing is not supported
638 // Compute the position of the control
640 makePosition( rData.m_leftTop, rData.m_rightBottom, rData.m_xPos,
641 rData.m_yPos, pSeq->getWidth(),
642 pSeq->getHeight() / rData.m_nbImages, *pLayout );
644 pLayout->addControl( pRadial, pos, rData.m_layer );
646 m_pTheme->m_controls[rData.m_id] = CtrlGenericPtr( pRadial );
650 void Builder::addSlider( const BuilderData::Slider &rData )
652 // Add the background first, so that we will still have something almost
653 // functional if the cursor cannot be created properly (this happens for
654 // some winamp2 skins, where the images of the cursor are not always
657 // Get the bitmaps of the background
658 GenericBitmap *pBgImage = NULL;
659 if( rData.m_imageId != "none" )
661 GET_BMP( pBgImage, rData.m_imageId );
664 GenericLayout *pLayout = m_pTheme->getLayoutById(rData.m_layoutId);
665 if( pLayout == NULL )
667 msg_Err( getIntf(), "unknown layout id: %s", rData.m_layoutId.c_str() );
671 Bezier *pCurve = getPoints( rData.m_points.c_str() );
674 msg_Err( getIntf(), "Invalid format in tag points=\"%s\"",
675 rData.m_points.c_str() );
678 m_pTheme->m_curves.push_back( BezierPtr( pCurve ) );
680 // Get the visibility variable
681 // XXX check when it is null
682 Interpreter *pInterpreter = Interpreter::instance( getIntf() );
683 VarBool *pVisible = pInterpreter->getVarBool( rData.m_visible, m_pTheme );
685 // Get the variable associated to the slider
686 VarPercent *pVar = pInterpreter->getVarPercent( rData.m_value, m_pTheme );
689 msg_Err( getIntf(), "Unknown slider value: %s", rData.m_value.c_str() );
693 // Create the background control
694 CtrlSliderBg *pBackground = new CtrlSliderBg( getIntf(),
695 *pCurve, *pVar, rData.m_thickness, pBgImage, rData.m_nbHoriz,
696 rData.m_nbVert, rData.m_padHoriz, rData.m_padVert,
697 pVisible, UString( getIntf(), rData.m_help.c_str() ) );
699 // Compute the position of the control
700 const Position pos = makePosition( rData.m_leftTop, rData.m_rightBottom,
701 rData.m_xPos, rData.m_yPos,
702 pCurve->getWidth(), pCurve->getHeight(),
705 pLayout->addControl( pBackground, pos, rData.m_layer );
707 m_pTheme->m_controls[rData.m_id + "_bg"] = CtrlGenericPtr( pBackground );
709 // Get the bitmaps of the cursor
710 GenericBitmap *pBmpUp = NULL;
711 GET_BMP( pBmpUp, rData.m_upId );
713 GenericBitmap *pBmpDown = pBmpUp;
714 GET_BMP( pBmpDown, rData.m_downId );
716 GenericBitmap *pBmpOver = pBmpUp;
717 GET_BMP( pBmpOver, rData.m_overId );
719 // Create the cursor control
720 CtrlSliderCursor *pCursor = new CtrlSliderCursor( getIntf(), *pBmpUp,
721 *pBmpOver, *pBmpDown, *pCurve, *pVar, pVisible,
722 UString( getIntf(), rData.m_tooltip.c_str() ),
723 UString( getIntf(), rData.m_help.c_str() ) );
725 pLayout->addControl( pCursor, pos, rData.m_layer );
727 m_pTheme->m_controls[rData.m_id] = CtrlGenericPtr( pCursor );
729 // Associate the cursor to the background
730 pBackground->associateCursor( *pCursor );
734 void Builder::addList( const BuilderData::List &rData )
736 // Get the background bitmap, if any
737 GenericBitmap *pBgBmp = NULL;
738 GET_BMP( pBgBmp, rData.m_bgImageId );
740 GenericLayout *pLayout = m_pTheme->getLayoutById(rData.m_layoutId);
741 if( pLayout == NULL )
743 msg_Err( getIntf(), "unknown layout id: %s", rData.m_layoutId.c_str() );
747 GenericFont *pFont = getFont( rData.m_fontId );
750 msg_Err( getIntf(), "Unknown font id: %s", rData.m_fontId.c_str() );
754 // Get the list variable
755 Interpreter *pInterpreter = Interpreter::instance( getIntf() );
756 VarList *pVar = pInterpreter->getVarList( rData.m_var, m_pTheme );
759 msg_Err( getIntf(), "No such list variable: %s", rData.m_var.c_str() );
763 // Get the visibility variable
764 // XXX check when it is null
765 VarBool *pVisible = pInterpreter->getVarBool( rData.m_visible, m_pTheme );
767 // Create the list control
768 CtrlList *pList = new CtrlList( getIntf(), *pVar, *pFont, pBgBmp,
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( pList, pos, rData.m_layer );
781 m_pTheme->m_controls[rData.m_id] = CtrlGenericPtr( pList );
784 void Builder::addTree( const BuilderData::Tree &rData )
786 // Get the bitmaps, if any
787 GenericBitmap *pBgBmp = NULL;
788 GenericBitmap *pItemBmp = NULL;
789 GenericBitmap *pOpenBmp = NULL;
790 GenericBitmap *pClosedBmp = NULL;
791 GET_BMP( pBgBmp, rData.m_bgImageId );
792 GET_BMP( pItemBmp, rData.m_itemImageId );
793 GET_BMP( pOpenBmp, rData.m_openImageId );
794 GET_BMP( pClosedBmp, rData.m_closedImageId );
796 GenericLayout *pLayout = m_pTheme->getLayoutById(rData.m_layoutId);
797 if( pLayout == NULL )
799 msg_Err( getIntf(), "unknown layout id: %s", rData.m_layoutId.c_str() );
803 GenericFont *pFont = getFont( rData.m_fontId );
806 msg_Err( getIntf(), "Unknown font id: %s", rData.m_fontId.c_str() );
810 // Get the list variable
811 Interpreter *pInterpreter = Interpreter::instance( getIntf() );
812 VarTree *pVar = pInterpreter->getVarTree( rData.m_var, m_pTheme );
815 msg_Err( getIntf(), "No such list variable: %s", rData.m_var.c_str() );
819 // Get the visibility variable
820 // XXX check when it is null
821 VarBool *pVisible = pInterpreter->getVarBool( rData.m_visible, m_pTheme );
823 // Create the list control
824 CtrlTree *pTree = new CtrlTree( getIntf(), *pVar, *pFont, pBgBmp,
825 pItemBmp, pOpenBmp, pClosedBmp,
826 rData.m_fgColor, rData.m_playColor, rData.m_bgColor1,
827 rData.m_bgColor2, rData.m_selColor,
828 UString( getIntf(), rData.m_help.c_str() ), pVisible );
830 // Compute the position of the control
831 const Position pos = makePosition( rData.m_leftTop, rData.m_rightBottom,
832 rData.m_xPos, rData.m_yPos,
833 rData.m_width, rData.m_height,
836 pLayout->addControl( pTree, pos, rData.m_layer );
838 m_pTheme->m_controls[rData.m_id] = CtrlGenericPtr( pTree );
841 void Builder::addVideo( const BuilderData::Video &rData )
843 GenericLayout *pLayout = m_pTheme->getLayoutById(rData.m_layoutId);
844 if( pLayout == NULL )
846 msg_Err( getIntf(), "unknown layout id: %s", rData.m_layoutId.c_str() );
850 // Get the visibility variable
851 // XXX check when it is null
852 Interpreter *pInterpreter = Interpreter::instance( getIntf() );
853 VarBool *pVisible = pInterpreter->getVarBool( rData.m_visible, m_pTheme );
855 CtrlVideo *pVideo = new CtrlVideo( getIntf(), *pLayout,
856 rData.m_autoResize, UString( getIntf(), rData.m_help.c_str() ),
859 // Compute the position of the control
860 const Position pos = makePosition( rData.m_leftTop, rData.m_rightBottom,
861 rData.m_xPos, rData.m_yPos,
862 rData.m_width, rData.m_height,
865 pLayout->addControl( pVideo, pos, rData.m_layer );
867 m_pTheme->m_controls[rData.m_id] = CtrlGenericPtr( pVideo );
871 const Position Builder::makePosition( const string &rLeftTop,
872 const string &rRightBottom,
873 int xPos, int yPos, int width,
874 int height, const Box &rBox ) const
876 int left = 0, top = 0, right = 0, bottom = 0;
877 Position::Ref_t refLeftTop = Position::kLeftTop;
878 Position::Ref_t refRightBottom = Position::kLeftTop;
880 int boxWidth = rBox.getWidth();
881 int boxHeight = rBox.getHeight();
883 // Position of the left top corner
884 if( rLeftTop == "lefttop" )
888 refLeftTop = Position::kLeftTop;
890 else if( rLeftTop == "righttop" )
892 left = xPos - boxWidth + 1;
894 refLeftTop = Position::kRightTop;
896 else if( rLeftTop == "leftbottom" )
899 top = yPos - boxHeight + 1;
900 refLeftTop = Position::kLeftBottom;
902 else if( rLeftTop == "rightbottom" )
904 left = xPos - boxWidth + 1;
905 top = yPos - boxHeight + 1;
906 refLeftTop = Position::kRightBottom;
909 // Position of the right bottom corner
910 if( rRightBottom == "lefttop" )
912 right = xPos + width - 1;
913 bottom = yPos + height - 1;
914 refRightBottom = Position::kLeftTop;
916 else if( rRightBottom == "righttop" )
918 right = xPos + width - boxWidth;
919 bottom = yPos + height - 1;
920 refRightBottom = Position::kRightTop;
922 else if( rRightBottom == "leftbottom" )
924 right = xPos + width - 1;
925 bottom = yPos + height - boxHeight;
926 refRightBottom = Position::kLeftBottom;
928 else if( rRightBottom == "rightbottom" )
930 right = xPos + width - boxWidth;
931 bottom = yPos + height - boxHeight;
932 refRightBottom = Position::kRightBottom;
935 return Position( left, top, right, bottom, rBox, refLeftTop,
940 GenericFont *Builder::getFont( const string &fontId )
942 GenericFont *pFont = m_pTheme->getFontById(fontId);
943 if( !pFont && fontId == "defaultfont" )
945 // Get the resource path and try to load the default font
946 OSFactory *pOSFactory = OSFactory::instance( getIntf() );
947 const list<string> &resPath = pOSFactory->getResourcePath();
948 const string &sep = pOSFactory->getDirSeparator();
950 list<string>::const_iterator it;
951 for( it = resPath.begin(); it != resPath.end(); it++ )
953 string path = (*it) + sep + "fonts" + sep + "FreeSans.ttf";
954 pFont = new FT2Font( getIntf(), path, 12 );
957 // Font loaded successfully
958 m_pTheme->m_fonts["defaultfont"] = GenericFontPtr( pFont );
969 msg_Err( getIntf(), "Failed to open the default font" );
976 string Builder::getFilePath( const string &rFileName ) const
978 OSFactory *pFactory = OSFactory::instance( getIntf() );
979 return m_path + pFactory->getDirSeparator() + rFileName;
984 Bezier *Builder::getPoints( const char *pTag ) const
986 vector<float> xBez, yBez;
990 if( sscanf( pTag, "(%d,%d)%n", &x, &y, &n ) < 1 )
998 "Slider points cannot have negative coordinates!" );
1002 xBez.push_back( x );
1003 yBez.push_back( y );
1009 if( *(pTag++) != ',' )
1015 // Create the Bezier curve
1016 return new Bezier( getIntf(), xBez, yBez );