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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 *****************************************************************************/
26 #include "builder.hpp"
27 #include "builder_data.hpp"
28 #include "interpreter.hpp"
29 #include "skin_parser.hpp"
30 #include "../src/file_bitmap.hpp"
31 #include "../src/os_factory.hpp"
32 #include "../src/generic_bitmap.hpp"
33 #include "../src/top_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 "../commands/cmd_generic.hpp"
42 #include "../controls/ctrl_button.hpp"
43 #include "../controls/ctrl_checkbox.hpp"
44 #include "../controls/ctrl_image.hpp"
45 #include "../controls/ctrl_list.hpp"
46 #include "../controls/ctrl_move.hpp"
47 #include "../controls/ctrl_resize.hpp"
48 #include "../controls/ctrl_slider.hpp"
49 #include "../controls/ctrl_radialslider.hpp"
50 #include "../controls/ctrl_text.hpp"
51 #include "../controls/ctrl_tree.hpp"
52 #include "../controls/ctrl_video.hpp"
53 #include "../utils/bezier.hpp"
54 #include "../utils/position.hpp"
55 #include "../utils/var_bool.hpp"
56 #include "../utils/var_text.hpp"
58 #include "vlc_image.h"
61 Builder::Builder( intf_thread_t *pIntf, const BuilderData &rData,
62 const string &rPath ):
63 SkinObject( pIntf ), m_rData( rData ), m_path( rPath ), m_pTheme( NULL )
65 m_pImageHandler = image_HandlerCreate( pIntf );
70 if( m_pImageHandler ) image_HandlerDelete( m_pImageHandler );
73 CmdGeneric *Builder::parseAction( const string &rAction )
75 return Interpreter::instance( getIntf() )->parseAction( rAction, m_pTheme );
80 #define ADD_OBJECTS( type ) \
81 list<BuilderData::type>::const_iterator it##type; \
82 for( it##type = m_rData.m_list##type.begin(); \
83 it##type != m_rData.m_list##type.end(); it##type++ ) \
85 add##type( *it##type ); \
89 Theme *Builder::build()
91 m_pTheme = new Theme( getIntf() );
92 if( m_pTheme == NULL )
97 // Create everything from the data in the XML
99 ADD_OBJECTS( IniFile );
100 ADD_OBJECTS( Bitmap );
101 ADD_OBJECTS( SubBitmap );
102 ADD_OBJECTS( BitmapFont );
104 ADD_OBJECTS( Window );
105 // XXX: PopupMenus are created after the windows, so that the Win32Factory
106 // (at least) can give a valid window handle to the OSPopup objects
107 ADD_OBJECTS( PopupMenu );
108 ADD_OBJECTS( Layout );
109 ADD_OBJECTS( Anchor );
110 ADD_OBJECTS( Button );
111 ADD_OBJECTS( Checkbox );
112 ADD_OBJECTS( Image );
114 ADD_OBJECTS( RadialSlider );
115 ADD_OBJECTS( Slider );
118 ADD_OBJECTS( Video );
119 // MenuItems must be created after all the rest, so that the IDs of the
120 // other elements exist and can be parsed in the actions
121 ADD_OBJECTS( MenuItem );
122 ADD_OBJECTS( MenuSeparator );
128 // Macro to get a bitmap by its ID in the builder
129 #define GET_BMP( pBmp, id ) \
132 pBmp = m_pTheme->getBitmapById(id); \
135 msg_Err( getIntf(), "unknown bitmap id: %s", id.c_str() ); \
140 void Builder::addTheme( const BuilderData::Theme &rData )
142 WindowManager &rManager = m_pTheme->getWindowManager();
143 rManager.setMagnetValue( rData.m_magnet );
144 rManager.setAlphaValue( rData.m_alpha );
145 rManager.setMoveAlphaValue( rData.m_moveAlpha );
146 GenericFont *pFont = getFont( rData.m_tooltipfont );
149 rManager.createTooltip( *pFont );
153 msg_Warn( getIntf(), "invalid tooltip font: %s",
154 rData.m_tooltipfont.c_str() );
159 void Builder::addIniFile( const BuilderData::IniFile &rData )
161 // Parse the INI file
162 IniFile iniFile( getIntf(), rData.m_id, getFilePath( rData.m_file ) );
167 void Builder::addBitmap( const BuilderData::Bitmap &rData )
169 GenericBitmap *pBmp =
170 new FileBitmap( getIntf(), m_pImageHandler,
171 getFilePath( rData.m_fileName ), rData.m_alphaColor,
172 rData.m_nbFrames, rData.m_fps );
173 if( !pBmp->getData() )
179 m_pTheme->m_bitmaps[rData.m_id] = GenericBitmapPtr( pBmp );
183 void Builder::addSubBitmap( const BuilderData::SubBitmap &rData )
185 if( m_pTheme->m_bitmaps.find( rData.m_id ) != m_pTheme->m_bitmaps.end() )
187 msg_Dbg( getIntf(), "bitmap %s already exists", rData.m_id.c_str() );
191 // Get the parent bitmap
192 GenericBitmap *pParentBmp = NULL;
193 GET_BMP( pParentBmp, rData.m_parent );
195 // Copy a region of the parent bitmap to the new one
197 new BitmapImpl( getIntf(), rData.m_width, rData.m_height,
198 rData.m_nbFrames, rData.m_fps );
199 bool res = pBmp->drawBitmap( *pParentBmp, rData.m_x, rData.m_y, 0, 0,
200 rData.m_width, rData.m_height );
203 // Invalid sub-bitmap
205 msg_Warn( getIntf(), "sub-bitmap %s ignored", rData.m_id.c_str() );
208 m_pTheme->m_bitmaps[rData.m_id] = GenericBitmapPtr( pBmp );
212 void Builder::addBitmapFont( const BuilderData::BitmapFont &rData )
214 if( m_pTheme->m_fonts.find( rData.m_id ) != m_pTheme->m_fonts.end() )
216 msg_Dbg( getIntf(), "font %s already exists", rData.m_id.c_str() );
220 GenericBitmap *pBmp =
221 new FileBitmap( getIntf(), m_pImageHandler,
222 getFilePath( rData.m_file ), 0 );
223 if( !pBmp->getData() )
230 m_pTheme->m_bitmaps[rData.m_id] = GenericBitmapPtr( pBmp );
232 GenericFont *pFont = new BitmapFont( getIntf(), *pBmp, rData.m_type );
235 m_pTheme->m_fonts[rData.m_id] = GenericFontPtr( pFont );
244 void Builder::addFont( const BuilderData::Font &rData )
246 // Try to load the font from the theme directory
247 GenericFont *pFont = new FT2Font( getIntf(),
248 getFilePath( rData.m_fontFile ),
252 m_pTheme->m_fonts[rData.m_id] = GenericFontPtr( pFont );
258 // Font not found; try in the resource path
259 OSFactory *pOSFactory = OSFactory::instance( getIntf() );
260 const list<string> &resPath = pOSFactory->getResourcePath();
261 const string &sep = pOSFactory->getDirSeparator();
263 list<string>::const_iterator it;
264 for( it = resPath.begin(); it != resPath.end(); it++ )
266 string path = (*it) + sep + "fonts" + sep + rData.m_fontFile;
267 pFont = new FT2Font( getIntf(), path, rData.m_size );
270 // Font loaded successfully
271 m_pTheme->m_fonts[rData.m_id] = GenericFontPtr( pFont );
283 void Builder::addPopupMenu( const BuilderData::PopupMenu &rData )
285 Popup *pPopup = new Popup( getIntf(), m_pTheme->getWindowManager() );
287 m_pTheme->m_popups[rData.m_id] = PopupPtr( pPopup );
291 void Builder::addMenuItem( const BuilderData::MenuItem &rData )
293 Popup *pPopup = m_pTheme->getPopupById( rData.m_popupId );
296 msg_Err( getIntf(), "unknown popup id: %s", rData.m_popupId.c_str() );
300 CmdGeneric *pCommand = parseAction( rData.m_action );
301 if( pCommand == NULL )
303 msg_Err( getIntf(), "invalid action: %s", rData.m_action.c_str() );
307 pPopup->addItem( rData.m_label, *pCommand, rData.m_pos );
311 void Builder::addMenuSeparator( const BuilderData::MenuSeparator &rData )
313 Popup *pPopup = m_pTheme->getPopupById( rData.m_popupId );
316 msg_Err( getIntf(), "unknown popup id: %s", rData.m_popupId.c_str() );
320 pPopup->addSeparator( rData.m_pos );
324 void Builder::addWindow( const BuilderData::Window &rData )
327 new TopWindow( getIntf(), rData.m_xPos, rData.m_yPos,
328 m_pTheme->getWindowManager(),
329 rData.m_dragDrop, rData.m_playOnDrop,
332 m_pTheme->m_windows[rData.m_id] = TopWindowPtr( pWin );
336 void Builder::addLayout( const BuilderData::Layout &rData )
338 TopWindow *pWin = m_pTheme->getWindowById( rData.m_windowId );
341 msg_Err( getIntf(), "unknown window id: %s", rData.m_windowId.c_str() );
345 int minWidth = rData.m_minWidth != -1 ? rData.m_minWidth : rData.m_width;
346 int maxWidth = rData.m_maxWidth != -1 ? rData.m_maxWidth : rData.m_width;
347 int minHeight = rData.m_minHeight != -1 ? rData.m_minHeight :
349 int maxHeight = rData.m_maxHeight != -1 ? rData.m_maxHeight :
351 GenericLayout *pLayout = new GenericLayout( getIntf(), rData.m_width,
353 minWidth, maxWidth, minHeight,
355 m_pTheme->m_layouts[rData.m_id] = GenericLayoutPtr( pLayout );
357 // Attach the layout to its window
358 m_pTheme->getWindowManager().addLayout( *pWin, *pLayout );
362 void Builder::addAnchor( const BuilderData::Anchor &rData )
364 GenericLayout *pLayout = m_pTheme->getLayoutById( rData.m_layoutId );
365 if( pLayout == NULL )
367 msg_Err( getIntf(), "unknown layout id: %s", rData.m_layoutId.c_str() );
371 Bezier *pCurve = getPoints( rData.m_points.c_str() );
374 msg_Err( getIntf(), "invalid format in tag points=\"%s\"",
375 rData.m_points.c_str() );
378 m_pTheme->m_curves.push_back( BezierPtr( pCurve ) );
380 Anchor *pAnc = new Anchor( getIntf(), rData.m_xPos, rData.m_yPos,
381 rData.m_range, rData.m_priority,
383 pLayout->addAnchor( pAnc );
387 void Builder::addButton( const BuilderData::Button &rData )
389 // Get the bitmaps of the button
390 GenericBitmap *pBmpUp = NULL;
391 GET_BMP( pBmpUp, rData.m_upId );
393 GenericBitmap *pBmpDown = pBmpUp;
394 GET_BMP( pBmpDown, rData.m_downId );
396 GenericBitmap *pBmpOver = pBmpUp;
397 GET_BMP( pBmpOver, rData.m_overId );
399 GenericLayout *pLayout = m_pTheme->getLayoutById( rData.m_layoutId );
400 if( pLayout == NULL )
402 msg_Err( getIntf(), "unknown layout id: %s", rData.m_layoutId.c_str() );
406 CmdGeneric *pCommand = parseAction( rData.m_actionId );
407 if( pCommand == NULL )
409 msg_Err( getIntf(), "invalid action: %s", rData.m_actionId.c_str() );
413 // Get the visibility variable
414 // XXX check when it is null
415 Interpreter *pInterpreter = Interpreter::instance( getIntf() );
416 VarBool *pVisible = pInterpreter->getVarBool( rData.m_visible, m_pTheme );
418 CtrlButton *pButton = new CtrlButton( getIntf(), *pBmpUp, *pBmpOver,
419 *pBmpDown, *pCommand, UString( getIntf(), rData.m_tooltip.c_str() ),
420 UString( getIntf(), rData.m_help.c_str() ), pVisible );
422 // Compute the position of the control
423 // XXX (we suppose all the images have the same size...)
424 const Position pos = makePosition( rData.m_leftTop, rData.m_rightBottom,
425 rData.m_xPos, rData.m_yPos,
427 pBmpUp->getHeight(), *pLayout );
429 pLayout->addControl( pButton, pos, rData.m_layer );
431 m_pTheme->m_controls[rData.m_id] = CtrlGenericPtr( pButton );
435 void Builder::addCheckbox( const BuilderData::Checkbox &rData )
437 // Get the bitmaps of the checkbox
438 GenericBitmap *pBmpUp1 = NULL;
439 GET_BMP( pBmpUp1, rData.m_up1Id );
441 GenericBitmap *pBmpDown1 = pBmpUp1;
442 GET_BMP( pBmpDown1, rData.m_down1Id );
444 GenericBitmap *pBmpOver1 = pBmpUp1;
445 GET_BMP( pBmpOver1, rData.m_over1Id );
447 GenericBitmap *pBmpUp2 = NULL;
448 GET_BMP( pBmpUp2, rData.m_up2Id );
450 GenericBitmap *pBmpDown2 = pBmpUp2;
451 GET_BMP( pBmpDown2, rData.m_down2Id );
453 GenericBitmap *pBmpOver2 = pBmpUp2;
454 GET_BMP( pBmpOver2, rData.m_over2Id );
456 GenericLayout *pLayout = m_pTheme->getLayoutById( rData.m_layoutId );
457 if( pLayout == NULL )
459 msg_Err( getIntf(), "unknown layout id: %s", rData.m_layoutId.c_str() );
463 CmdGeneric *pCommand1 = parseAction( rData.m_action1 );
464 if( pCommand1 == NULL )
466 msg_Err( getIntf(), "invalid action: %s", rData.m_action1.c_str() );
470 CmdGeneric *pCommand2 = parseAction( rData.m_action2 );
471 if( pCommand2 == NULL )
473 msg_Err( getIntf(), "invalid action: %s", rData.m_action2.c_str() );
477 // Get the state variable
478 Interpreter *pInterpreter = Interpreter::instance( getIntf() );
479 VarBool *pVar = pInterpreter->getVarBool( rData.m_state, m_pTheme );
482 // TODO: default state
486 // Get the visibility variable
487 // XXX check when it is null
488 VarBool *pVisible = pInterpreter->getVarBool( rData.m_visible, m_pTheme );
490 // Create the control
491 CtrlCheckbox *pCheckbox = new CtrlCheckbox( getIntf(), *pBmpUp1,
492 *pBmpOver1, *pBmpDown1, *pBmpUp2, *pBmpOver2, *pBmpDown2, *pCommand1,
493 *pCommand2, UString( getIntf(), rData.m_tooltip1.c_str() ),
494 UString( getIntf(), rData.m_tooltip2.c_str() ), *pVar,
495 UString( getIntf(), rData.m_help.c_str() ), pVisible );
497 // Compute the position of the control
498 // XXX (we suppose all the images have the same size...)
499 const Position pos = makePosition( rData.m_leftTop, rData.m_rightBottom,
500 rData.m_xPos, rData.m_yPos,
502 pBmpUp1->getHeight(), *pLayout );
504 pLayout->addControl( pCheckbox, pos, rData.m_layer );
506 m_pTheme->m_controls[rData.m_id] = CtrlGenericPtr( pCheckbox );
510 void Builder::addImage( const BuilderData::Image &rData )
512 GenericBitmap *pBmp = NULL;
513 GET_BMP( pBmp, rData.m_bmpId );
515 GenericLayout *pLayout = m_pTheme->getLayoutById( rData.m_layoutId );
516 if( pLayout == NULL )
518 msg_Err( getIntf(), "unknown layout id: %s", rData.m_layoutId.c_str() );
522 TopWindow *pWindow = m_pTheme->getWindowById( rData.m_windowId );
523 if( pWindow == NULL )
525 msg_Err( getIntf(), "unknown window id: %s", rData.m_windowId.c_str() );
529 CmdGeneric *pCommand = parseAction( rData.m_action2Id );
530 if( pCommand == NULL )
532 msg_Err( getIntf(), "invalid action: %s", rData.m_action2Id.c_str() );
536 // Get the visibility variable
537 // XXX check when it is null
538 Interpreter *pInterpreter = Interpreter::instance( getIntf() );
539 VarBool *pVisible = pInterpreter->getVarBool( rData.m_visible, m_pTheme );
541 CtrlImage::resize_t resizeMethod =
542 (rData.m_resize == "scale" ? CtrlImage::kScale : CtrlImage::kMosaic);
543 CtrlImage *pImage = new CtrlImage( getIntf(), *pBmp, *pCommand,
544 resizeMethod, UString( getIntf(), rData.m_help.c_str() ), pVisible );
546 // Compute the position of the control
547 const Position pos = makePosition( rData.m_leftTop, rData.m_rightBottom,
549 rData.m_yPos, pBmp->getWidth(),
550 pBmp->getHeight(), *pLayout );
552 // XXX: test to be changed! XXX
553 if( rData.m_actionId == "move" )
555 CtrlMove *pMove = new CtrlMove( getIntf(), m_pTheme->getWindowManager(),
556 *pImage, *pWindow, UString( getIntf(), rData.m_help.c_str() ),
558 pLayout->addControl( pMove, pos, rData.m_layer );
560 else if( rData.m_actionId == "resizeS" )
562 CtrlResize *pResize = new CtrlResize( getIntf(), *pImage, *pLayout,
563 UString( getIntf(), rData.m_help.c_str() ), pVisible,
564 CtrlResize::kResizeS );
565 pLayout->addControl( pResize, pos, rData.m_layer );
567 else if( rData.m_actionId == "resizeE" )
569 CtrlResize *pResize = new CtrlResize( getIntf(), *pImage, *pLayout,
570 UString( getIntf(), rData.m_help.c_str() ), pVisible,
571 CtrlResize::kResizeE );
572 pLayout->addControl( pResize, pos, rData.m_layer );
574 else if( rData.m_actionId == "resizeSE" )
576 CtrlResize *pResize = new CtrlResize( getIntf(), *pImage, *pLayout,
577 UString( getIntf(), rData.m_help.c_str() ), pVisible,
578 CtrlResize::kResizeSE );
579 pLayout->addControl( pResize, pos, rData.m_layer );
583 pLayout->addControl( pImage, pos, rData.m_layer );
586 m_pTheme->m_controls[rData.m_id] = CtrlGenericPtr( pImage );
590 void Builder::addText( const BuilderData::Text &rData )
592 GenericLayout *pLayout = m_pTheme->getLayoutById( rData.m_layoutId );
593 if( pLayout == NULL )
595 msg_Err( getIntf(), "unknown layout id: %s", rData.m_layoutId.c_str() );
599 GenericFont *pFont = getFont( rData.m_fontId );
602 msg_Err( getIntf(), "unknown font id: %s", rData.m_fontId.c_str() );
606 // Convert the scrolling mode
607 CtrlText::Scrolling_t scrolling;
608 if( rData.m_scrolling == "auto" )
609 scrolling = CtrlText::kAutomatic;
610 else if( rData.m_scrolling == "manual" )
611 scrolling = CtrlText::kManual;
612 else if( rData.m_scrolling == "none" )
613 scrolling = CtrlText::kNone;
616 msg_Err( getIntf(), "invalid scrolling mode: %s",
617 rData.m_scrolling.c_str() );
621 // Convert the alignment
622 CtrlText::Align_t alignment;
623 if( rData.m_alignment == "left" )
624 alignment = CtrlText::kLeft;
625 else if( rData.m_alignment == "center" || rData.m_alignment == "centre" )
626 alignment = CtrlText::kCenter;
627 else if( rData.m_alignment == "right" )
628 alignment = CtrlText::kRight;
631 msg_Err( getIntf(), "invalid alignment: %s",
632 rData.m_alignment.c_str() );
636 // Create a text variable
637 VarText *pVar = new VarText( getIntf() );
638 m_pTheme->m_vars.push_back( VariablePtr( pVar ) );
640 // Get the visibility variable
641 // XXX check when it is null
642 Interpreter *pInterpreter = Interpreter::instance( getIntf() );
643 VarBool *pVisible = pInterpreter->getVarBool( rData.m_visible, m_pTheme );
645 CtrlText *pText = new CtrlText( getIntf(), *pVar, *pFont,
646 UString( getIntf(), rData.m_help.c_str() ), rData.m_color, pVisible,
647 scrolling, alignment );
649 int height = pFont->getSize();
651 // Compute the position of the control
652 const Position pos = makePosition( rData.m_leftTop, rData.m_rightBottom,
653 rData.m_xPos, rData.m_yPos,
654 rData.m_width, height,
657 pLayout->addControl( pText, pos, rData.m_layer );
659 // Set the text of the control
660 UString msg( getIntf(), rData.m_text.c_str() );
663 m_pTheme->m_controls[rData.m_id] = CtrlGenericPtr( pText );
667 void Builder::addRadialSlider( const BuilderData::RadialSlider &rData )
669 // Get the bitmaps of the slider
670 GenericBitmap *pSeq = NULL;
671 GET_BMP( pSeq, rData.m_sequence );
673 GenericLayout *pLayout = m_pTheme->getLayoutById( rData.m_layoutId );
674 if( pLayout == NULL )
676 msg_Err( getIntf(), "unknown layout id: %s", rData.m_layoutId.c_str() );
680 // Get the variable associated to the slider
681 Interpreter *pInterpreter = Interpreter::instance( getIntf() );
682 VarPercent *pVar = pInterpreter->getVarPercent( rData.m_value, m_pTheme );
685 msg_Err( getIntf(), "unknown slider value: %s", rData.m_value.c_str() );
689 // Get the visibility variable
690 // XXX check when it is null
691 VarBool *pVisible = pInterpreter->getVarBool( rData.m_visible, m_pTheme );
693 // Create the control
694 CtrlRadialSlider *pRadial =
695 new CtrlRadialSlider( getIntf(), *pSeq, rData.m_nbImages, *pVar,
696 rData.m_minAngle, rData.m_maxAngle,
697 UString( getIntf(), rData.m_help.c_str() ),
700 // XXX: resizing is not supported
701 // Compute the position of the control
703 makePosition( rData.m_leftTop, rData.m_rightBottom, rData.m_xPos,
704 rData.m_yPos, pSeq->getWidth(),
705 pSeq->getHeight() / rData.m_nbImages, *pLayout );
707 pLayout->addControl( pRadial, pos, rData.m_layer );
709 m_pTheme->m_controls[rData.m_id] = CtrlGenericPtr( pRadial );
713 void Builder::addSlider( const BuilderData::Slider &rData )
715 // Add the background first, so that we will still have something almost
716 // functional if the cursor cannot be created properly (this happens for
717 // some winamp2 skins, where the images of the cursor are not always
720 // Get the bitmaps of the background
721 GenericBitmap *pBgImage = NULL;
722 if( rData.m_imageId != "none" )
724 GET_BMP( pBgImage, rData.m_imageId );
727 GenericLayout *pLayout = m_pTheme->getLayoutById( rData.m_layoutId );
728 if( pLayout == NULL )
730 msg_Err( getIntf(), "unknown layout id: %s", rData.m_layoutId.c_str() );
734 Bezier *pCurve = getPoints( rData.m_points.c_str() );
737 msg_Err( getIntf(), "invalid format in tag points=\"%s\"",
738 rData.m_points.c_str() );
741 m_pTheme->m_curves.push_back( BezierPtr( pCurve ) );
743 // Get the visibility variable
744 // XXX check when it is null
745 Interpreter *pInterpreter = Interpreter::instance( getIntf() );
746 VarBool *pVisible = pInterpreter->getVarBool( rData.m_visible, m_pTheme );
748 // Get the variable associated to the slider
749 VarPercent *pVar = pInterpreter->getVarPercent( rData.m_value, m_pTheme );
752 msg_Err( getIntf(), "unknown slider value: %s", rData.m_value.c_str() );
756 // Create the background control
757 CtrlSliderBg *pBackground = new CtrlSliderBg( getIntf(),
758 *pCurve, *pVar, rData.m_thickness, pBgImage, rData.m_nbHoriz,
759 rData.m_nbVert, rData.m_padHoriz, rData.m_padVert,
760 pVisible, UString( getIntf(), rData.m_help.c_str() ) );
762 // Compute the position of the control
763 const Position pos = makePosition( rData.m_leftTop, rData.m_rightBottom,
764 rData.m_xPos, rData.m_yPos,
765 pCurve->getWidth(), pCurve->getHeight(),
768 pLayout->addControl( pBackground, pos, rData.m_layer );
770 m_pTheme->m_controls[rData.m_id + "_bg"] = CtrlGenericPtr( pBackground );
772 // Get the bitmaps of the cursor
773 GenericBitmap *pBmpUp = NULL;
774 GET_BMP( pBmpUp, rData.m_upId );
776 GenericBitmap *pBmpDown = pBmpUp;
777 GET_BMP( pBmpDown, rData.m_downId );
779 GenericBitmap *pBmpOver = pBmpUp;
780 GET_BMP( pBmpOver, rData.m_overId );
782 // Create the cursor control
783 CtrlSliderCursor *pCursor = new CtrlSliderCursor( getIntf(), *pBmpUp,
784 *pBmpOver, *pBmpDown, *pCurve, *pVar, pVisible,
785 UString( getIntf(), rData.m_tooltip.c_str() ),
786 UString( getIntf(), rData.m_help.c_str() ) );
788 pLayout->addControl( pCursor, pos, rData.m_layer );
790 m_pTheme->m_controls[rData.m_id] = CtrlGenericPtr( pCursor );
792 // Associate the cursor to the background
793 pBackground->associateCursor( *pCursor );
797 void Builder::addList( const BuilderData::List &rData )
799 // Get the background bitmap, if any
800 GenericBitmap *pBgBmp = NULL;
801 GET_BMP( pBgBmp, rData.m_bgImageId );
803 GenericLayout *pLayout = m_pTheme->getLayoutById( rData.m_layoutId );
804 if( pLayout == NULL )
806 msg_Err( getIntf(), "unknown layout id: %s", rData.m_layoutId.c_str() );
810 GenericFont *pFont = getFont( rData.m_fontId );
813 msg_Err( getIntf(), "unknown font id: %s", rData.m_fontId.c_str() );
817 // Get the list variable
818 Interpreter *pInterpreter = Interpreter::instance( getIntf() );
819 VarList *pVar = pInterpreter->getVarList( rData.m_var, m_pTheme );
822 msg_Err( getIntf(), "no such list variable: %s", rData.m_var.c_str() );
826 // Get the visibility variable
827 // XXX check when it is null
828 VarBool *pVisible = pInterpreter->getVarBool( rData.m_visible, m_pTheme );
830 // Get the color values
831 uint32_t fgColor = getColor( rData.m_fgColor );
832 uint32_t playColor = getColor( rData.m_playColor );
833 uint32_t bgColor1 = getColor( rData.m_bgColor1 );
834 uint32_t bgColor2 = getColor( rData.m_bgColor2 );
835 uint32_t selColor = getColor( rData.m_selColor );
837 // Create the list control
838 CtrlList *pList = new CtrlList( getIntf(), *pVar, *pFont, pBgBmp,
839 fgColor, playColor, bgColor1, bgColor2, selColor,
840 UString( getIntf(), rData.m_help.c_str() ), pVisible );
842 // Compute the position of the control
843 const Position pos = makePosition( rData.m_leftTop, rData.m_rightBottom,
844 rData.m_xPos, rData.m_yPos,
845 rData.m_width, rData.m_height,
848 pLayout->addControl( pList, pos, rData.m_layer );
850 m_pTheme->m_controls[rData.m_id] = CtrlGenericPtr( pList );
853 void Builder::addTree( const BuilderData::Tree &rData )
855 // Get the bitmaps, if any
856 GenericBitmap *pBgBmp = NULL;
857 GenericBitmap *pItemBmp = NULL;
858 GenericBitmap *pOpenBmp = NULL;
859 GenericBitmap *pClosedBmp = NULL;
860 GET_BMP( pBgBmp, rData.m_bgImageId );
861 GET_BMP( pItemBmp, rData.m_itemImageId );
862 GET_BMP( pOpenBmp, rData.m_openImageId );
863 GET_BMP( pClosedBmp, rData.m_closedImageId );
865 GenericLayout *pLayout = m_pTheme->getLayoutById( rData.m_layoutId );
866 if( pLayout == NULL )
868 msg_Err( getIntf(), "unknown layout id: %s", rData.m_layoutId.c_str() );
872 GenericFont *pFont = getFont( rData.m_fontId );
875 msg_Err( getIntf(), "unknown font id: %s", rData.m_fontId.c_str() );
879 // Get the list variable
880 Interpreter *pInterpreter = Interpreter::instance( getIntf() );
881 VarTree *pVar = pInterpreter->getVarTree( rData.m_var, m_pTheme );
884 msg_Err( getIntf(), "no such list variable: %s", rData.m_var.c_str() );
888 // Get the visibility variable
889 // XXX check when it is null
890 VarBool *pVisible = pInterpreter->getVarBool( rData.m_visible, m_pTheme );
891 VarBool *pFlat = pInterpreter->getVarBool( rData.m_flat, m_pTheme );
893 // Get the color values
894 uint32_t fgColor = getColor( rData.m_fgColor );
895 uint32_t playColor = getColor( rData.m_playColor );
896 uint32_t bgColor1 = getColor( rData.m_bgColor1 );
897 uint32_t bgColor2 = getColor( rData.m_bgColor2 );
898 uint32_t selColor = getColor( rData.m_selColor );
900 // Create the list control
901 CtrlTree *pTree = new CtrlTree( getIntf(), *pVar, *pFont, pBgBmp,
902 pItemBmp, pOpenBmp, pClosedBmp,
903 fgColor, playColor, bgColor1, bgColor2, selColor,
904 UString( getIntf(), rData.m_help.c_str() ), pVisible, pFlat );
906 // Compute the position of the control
907 const Position pos = makePosition( rData.m_leftTop, rData.m_rightBottom,
908 rData.m_xPos, rData.m_yPos,
909 rData.m_width, rData.m_height,
912 pLayout->addControl( pTree, pos, rData.m_layer );
914 m_pTheme->m_controls[rData.m_id] = CtrlGenericPtr( pTree );
917 void Builder::addVideo( const BuilderData::Video &rData )
919 GenericLayout *pLayout = m_pTheme->getLayoutById( rData.m_layoutId );
920 if( pLayout == NULL )
922 msg_Err( getIntf(), "unknown layout id: %s", rData.m_layoutId.c_str() );
926 // Get the visibility variable
927 // XXX check when it is null
928 Interpreter *pInterpreter = Interpreter::instance( getIntf() );
929 VarBool *pVisible = pInterpreter->getVarBool( rData.m_visible, m_pTheme );
931 CtrlVideo *pVideo = new CtrlVideo( getIntf(), *pLayout,
932 rData.m_autoResize, UString( getIntf(), rData.m_help.c_str() ),
935 // Compute the position of the control
936 const Position pos = makePosition( rData.m_leftTop, rData.m_rightBottom,
937 rData.m_xPos, rData.m_yPos,
938 rData.m_width, rData.m_height,
941 pLayout->addControl( pVideo, pos, rData.m_layer );
943 m_pTheme->m_controls[rData.m_id] = CtrlGenericPtr( pVideo );
947 const Position Builder::makePosition( const string &rLeftTop,
948 const string &rRightBottom,
949 int xPos, int yPos, int width,
950 int height, const Box &rBox ) const
952 int left = 0, top = 0, right = 0, bottom = 0;
953 Position::Ref_t refLeftTop = Position::kLeftTop;
954 Position::Ref_t refRightBottom = Position::kLeftTop;
956 int boxWidth = rBox.getWidth();
957 int boxHeight = rBox.getHeight();
959 // Position of the left top corner
960 if( rLeftTop == "lefttop" )
964 refLeftTop = Position::kLeftTop;
966 else if( rLeftTop == "righttop" )
968 left = xPos - boxWidth + 1;
970 refLeftTop = Position::kRightTop;
972 else if( rLeftTop == "leftbottom" )
975 top = yPos - boxHeight + 1;
976 refLeftTop = Position::kLeftBottom;
978 else if( rLeftTop == "rightbottom" )
980 left = xPos - boxWidth + 1;
981 top = yPos - boxHeight + 1;
982 refLeftTop = Position::kRightBottom;
985 // Position of the right bottom corner
986 if( rRightBottom == "lefttop" )
988 right = xPos + width - 1;
989 bottom = yPos + height - 1;
990 refRightBottom = Position::kLeftTop;
992 else if( rRightBottom == "righttop" )
994 right = xPos + width - boxWidth;
995 bottom = yPos + height - 1;
996 refRightBottom = Position::kRightTop;
998 else if( rRightBottom == "leftbottom" )
1000 right = xPos + width - 1;
1001 bottom = yPos + height - boxHeight;
1002 refRightBottom = Position::kLeftBottom;
1004 else if( rRightBottom == "rightbottom" )
1006 right = xPos + width - boxWidth;
1007 bottom = yPos + height - boxHeight;
1008 refRightBottom = Position::kRightBottom;
1011 return Position( left, top, right, bottom, rBox, refLeftTop,
1016 GenericFont *Builder::getFont( const string &fontId )
1018 GenericFont *pFont = m_pTheme->getFontById(fontId);
1019 if( !pFont && fontId == "defaultfont" )
1021 // Get the resource path and try to load the default font
1022 OSFactory *pOSFactory = OSFactory::instance( getIntf() );
1023 const list<string> &resPath = pOSFactory->getResourcePath();
1024 const string &sep = pOSFactory->getDirSeparator();
1026 list<string>::const_iterator it;
1027 for( it = resPath.begin(); it != resPath.end(); it++ )
1029 string path = (*it) + sep + "fonts" + sep + "FreeSans.ttf";
1030 pFont = new FT2Font( getIntf(), path, 12 );
1033 // Font loaded successfully
1034 m_pTheme->m_fonts["defaultfont"] = GenericFontPtr( pFont );
1045 msg_Err( getIntf(), "failed to open the default font" );
1052 string Builder::getFilePath( const string &rFileName ) const
1054 OSFactory *pFactory = OSFactory::instance( getIntf() );
1055 return m_path + pFactory->getDirSeparator() + rFileName;
1060 Bezier *Builder::getPoints( const char *pTag ) const
1062 vector<float> xBez, yBez;
1066 if( sscanf( pTag, "(%d,%d)%n", &x, &y, &n ) < 1 )
1071 if( x < 0 || y < 0 )
1074 "Slider points cannot have negative coordinates!" );
1078 xBez.push_back( x );
1079 yBez.push_back( y );
1085 if( *(pTag++) != ',' )
1091 // Create the Bezier curve
1092 return new Bezier( getIntf(), xBez, yBez );
1096 uint32_t Builder::getColor( const string &rVal ) const
1098 // Check it the value is a registered constant
1099 Interpreter *pInterpreter = Interpreter::instance( getIntf() );
1100 string val = pInterpreter->getConstant( rVal );
1102 // Convert to an int value
1103 return SkinParser::convertColor( val.c_str() );