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 == "autooff" )
611 scrolling = CtrlText::kAutomaticOff;
612 else if( rData.m_scrolling == "manual" )
613 scrolling = CtrlText::kManual;
614 else if( rData.m_scrolling == "none" )
615 scrolling = CtrlText::kNone;
618 msg_Err( getIntf(), "invalid scrolling mode: %s",
619 rData.m_scrolling.c_str() );
623 // Convert the alignment
624 CtrlText::Align_t alignment;
625 if( rData.m_alignment == "left" )
626 alignment = CtrlText::kLeft;
627 else if( rData.m_alignment == "center" || rData.m_alignment == "centre" )
628 alignment = CtrlText::kCenter;
629 else if( rData.m_alignment == "right" )
630 alignment = CtrlText::kRight;
633 msg_Err( getIntf(), "invalid alignment: %s",
634 rData.m_alignment.c_str() );
638 // Create a text variable
639 VarText *pVar = new VarText( getIntf() );
640 m_pTheme->m_vars.push_back( VariablePtr( pVar ) );
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 );
647 CtrlText *pText = new CtrlText( getIntf(), *pVar, *pFont,
648 UString( getIntf(), rData.m_help.c_str() ), rData.m_color, pVisible,
649 scrolling, alignment );
651 int height = pFont->getSize();
653 // Compute the position of the control
654 const Position pos = makePosition( rData.m_leftTop, rData.m_rightBottom,
655 rData.m_xPos, rData.m_yPos,
656 rData.m_width, height,
659 pLayout->addControl( pText, pos, rData.m_layer );
661 // Set the text of the control
662 UString msg( getIntf(), rData.m_text.c_str() );
665 m_pTheme->m_controls[rData.m_id] = CtrlGenericPtr( pText );
669 void Builder::addRadialSlider( const BuilderData::RadialSlider &rData )
671 // Get the bitmaps of the slider
672 GenericBitmap *pSeq = NULL;
673 GET_BMP( pSeq, rData.m_sequence );
675 GenericLayout *pLayout = m_pTheme->getLayoutById( rData.m_layoutId );
676 if( pLayout == NULL )
678 msg_Err( getIntf(), "unknown layout id: %s", rData.m_layoutId.c_str() );
682 // Get the variable associated to the slider
683 Interpreter *pInterpreter = Interpreter::instance( getIntf() );
684 VarPercent *pVar = pInterpreter->getVarPercent( rData.m_value, m_pTheme );
687 msg_Err( getIntf(), "unknown slider value: %s", rData.m_value.c_str() );
691 // Get the visibility variable
692 // XXX check when it is null
693 VarBool *pVisible = pInterpreter->getVarBool( rData.m_visible, m_pTheme );
695 // Create the control
696 CtrlRadialSlider *pRadial =
697 new CtrlRadialSlider( getIntf(), *pSeq, rData.m_nbImages, *pVar,
698 rData.m_minAngle, rData.m_maxAngle,
699 UString( getIntf(), rData.m_help.c_str() ),
702 // XXX: resizing is not supported
703 // Compute the position of the control
705 makePosition( rData.m_leftTop, rData.m_rightBottom, rData.m_xPos,
706 rData.m_yPos, pSeq->getWidth(),
707 pSeq->getHeight() / rData.m_nbImages, *pLayout );
709 pLayout->addControl( pRadial, pos, rData.m_layer );
711 m_pTheme->m_controls[rData.m_id] = CtrlGenericPtr( pRadial );
715 void Builder::addSlider( const BuilderData::Slider &rData )
717 // Add the background first, so that we will still have something almost
718 // functional if the cursor cannot be created properly (this happens for
719 // some winamp2 skins, where the images of the cursor are not always
722 // Get the bitmaps of the background
723 GenericBitmap *pBgImage = NULL;
724 if( rData.m_imageId != "none" )
726 GET_BMP( pBgImage, rData.m_imageId );
729 GenericLayout *pLayout = m_pTheme->getLayoutById( rData.m_layoutId );
730 if( pLayout == NULL )
732 msg_Err( getIntf(), "unknown layout id: %s", rData.m_layoutId.c_str() );
736 Bezier *pCurve = getPoints( rData.m_points.c_str() );
739 msg_Err( getIntf(), "invalid format in tag points=\"%s\"",
740 rData.m_points.c_str() );
743 m_pTheme->m_curves.push_back( BezierPtr( pCurve ) );
745 // Get the visibility variable
746 // XXX check when it is null
747 Interpreter *pInterpreter = Interpreter::instance( getIntf() );
748 VarBool *pVisible = pInterpreter->getVarBool( rData.m_visible, m_pTheme );
750 // Get the variable associated to the slider
751 VarPercent *pVar = pInterpreter->getVarPercent( rData.m_value, m_pTheme );
754 msg_Err( getIntf(), "unknown slider value: %s", rData.m_value.c_str() );
758 // Create the background control
759 CtrlSliderBg *pBackground = new CtrlSliderBg( getIntf(),
760 *pCurve, *pVar, rData.m_thickness, pBgImage, rData.m_nbHoriz,
761 rData.m_nbVert, rData.m_padHoriz, rData.m_padVert,
762 pVisible, UString( getIntf(), rData.m_help.c_str() ) );
764 // Compute the position of the control
765 const Position pos = makePosition( rData.m_leftTop, rData.m_rightBottom,
766 rData.m_xPos, rData.m_yPos,
767 pCurve->getWidth(), pCurve->getHeight(),
770 pLayout->addControl( pBackground, pos, rData.m_layer );
772 m_pTheme->m_controls[rData.m_id + "_bg"] = CtrlGenericPtr( pBackground );
774 // Get the bitmaps of the cursor
775 GenericBitmap *pBmpUp = NULL;
776 GET_BMP( pBmpUp, rData.m_upId );
778 GenericBitmap *pBmpDown = pBmpUp;
779 GET_BMP( pBmpDown, rData.m_downId );
781 GenericBitmap *pBmpOver = pBmpUp;
782 GET_BMP( pBmpOver, rData.m_overId );
784 // Create the cursor control
785 CtrlSliderCursor *pCursor = new CtrlSliderCursor( getIntf(), *pBmpUp,
786 *pBmpOver, *pBmpDown, *pCurve, *pVar, pVisible,
787 UString( getIntf(), rData.m_tooltip.c_str() ),
788 UString( getIntf(), rData.m_help.c_str() ) );
790 pLayout->addControl( pCursor, pos, rData.m_layer );
792 m_pTheme->m_controls[rData.m_id] = CtrlGenericPtr( pCursor );
794 // Associate the cursor to the background
795 pBackground->associateCursor( *pCursor );
799 void Builder::addList( const BuilderData::List &rData )
801 // Get the background bitmap, if any
802 GenericBitmap *pBgBmp = NULL;
803 GET_BMP( pBgBmp, rData.m_bgImageId );
805 GenericLayout *pLayout = m_pTheme->getLayoutById( rData.m_layoutId );
806 if( pLayout == NULL )
808 msg_Err( getIntf(), "unknown layout id: %s", rData.m_layoutId.c_str() );
812 GenericFont *pFont = getFont( rData.m_fontId );
815 msg_Err( getIntf(), "unknown font id: %s", rData.m_fontId.c_str() );
819 // Get the list variable
820 Interpreter *pInterpreter = Interpreter::instance( getIntf() );
821 VarList *pVar = pInterpreter->getVarList( rData.m_var, m_pTheme );
824 msg_Err( getIntf(), "no such list variable: %s", rData.m_var.c_str() );
828 // Get the visibility variable
829 // XXX check when it is null
830 VarBool *pVisible = pInterpreter->getVarBool( rData.m_visible, m_pTheme );
832 // Get the color values
833 uint32_t fgColor = getColor( rData.m_fgColor );
834 uint32_t playColor = getColor( rData.m_playColor );
835 uint32_t bgColor1 = getColor( rData.m_bgColor1 );
836 uint32_t bgColor2 = getColor( rData.m_bgColor2 );
837 uint32_t selColor = getColor( rData.m_selColor );
839 // Create the list control
840 CtrlList *pList = new CtrlList( getIntf(), *pVar, *pFont, pBgBmp,
841 fgColor, playColor, bgColor1, bgColor2, selColor,
842 UString( getIntf(), rData.m_help.c_str() ), pVisible );
844 // Compute the position of the control
845 const Position pos = makePosition( rData.m_leftTop, rData.m_rightBottom,
846 rData.m_xPos, rData.m_yPos,
847 rData.m_width, rData.m_height,
850 pLayout->addControl( pList, pos, rData.m_layer );
852 m_pTheme->m_controls[rData.m_id] = CtrlGenericPtr( pList );
855 void Builder::addTree( const BuilderData::Tree &rData )
857 // Get the bitmaps, if any
858 GenericBitmap *pBgBmp = NULL;
859 GenericBitmap *pItemBmp = NULL;
860 GenericBitmap *pOpenBmp = NULL;
861 GenericBitmap *pClosedBmp = NULL;
862 GET_BMP( pBgBmp, rData.m_bgImageId );
863 GET_BMP( pItemBmp, rData.m_itemImageId );
864 GET_BMP( pOpenBmp, rData.m_openImageId );
865 GET_BMP( pClosedBmp, rData.m_closedImageId );
867 GenericLayout *pLayout = m_pTheme->getLayoutById( rData.m_layoutId );
868 if( pLayout == NULL )
870 msg_Err( getIntf(), "unknown layout id: %s", rData.m_layoutId.c_str() );
874 GenericFont *pFont = getFont( rData.m_fontId );
877 msg_Err( getIntf(), "unknown font id: %s", rData.m_fontId.c_str() );
881 // Get the list variable
882 Interpreter *pInterpreter = Interpreter::instance( getIntf() );
883 VarTree *pVar = pInterpreter->getVarTree( rData.m_var, m_pTheme );
886 msg_Err( getIntf(), "no such list variable: %s", rData.m_var.c_str() );
890 // Get the visibility variable
891 // XXX check when it is null
892 VarBool *pVisible = pInterpreter->getVarBool( rData.m_visible, m_pTheme );
893 VarBool *pFlat = pInterpreter->getVarBool( rData.m_flat, m_pTheme );
895 // Get the color values
896 uint32_t fgColor = getColor( rData.m_fgColor );
897 uint32_t playColor = getColor( rData.m_playColor );
898 uint32_t bgColor1 = getColor( rData.m_bgColor1 );
899 uint32_t bgColor2 = getColor( rData.m_bgColor2 );
900 uint32_t selColor = getColor( rData.m_selColor );
902 // Create the list control
903 CtrlTree *pTree = new CtrlTree( getIntf(), *pVar, *pFont, pBgBmp,
904 pItemBmp, pOpenBmp, pClosedBmp,
905 fgColor, playColor, bgColor1, bgColor2, selColor,
906 UString( getIntf(), rData.m_help.c_str() ), pVisible, pFlat );
908 // Compute the position of the control
909 const Position pos = makePosition( rData.m_leftTop, rData.m_rightBottom,
910 rData.m_xPos, rData.m_yPos,
911 rData.m_width, rData.m_height,
914 pLayout->addControl( pTree, pos, rData.m_layer );
916 m_pTheme->m_controls[rData.m_id] = CtrlGenericPtr( pTree );
919 void Builder::addVideo( const BuilderData::Video &rData )
921 GenericLayout *pLayout = m_pTheme->getLayoutById( rData.m_layoutId );
922 if( pLayout == NULL )
924 msg_Err( getIntf(), "unknown layout id: %s", rData.m_layoutId.c_str() );
928 // Get the visibility variable
929 // XXX check when it is null
930 Interpreter *pInterpreter = Interpreter::instance( getIntf() );
931 VarBool *pVisible = pInterpreter->getVarBool( rData.m_visible, m_pTheme );
933 CtrlVideo *pVideo = new CtrlVideo( getIntf(), *pLayout,
934 rData.m_autoResize, UString( getIntf(), rData.m_help.c_str() ),
937 // Compute the position of the control
938 const Position pos = makePosition( rData.m_leftTop, rData.m_rightBottom,
939 rData.m_xPos, rData.m_yPos,
940 rData.m_width, rData.m_height,
943 pLayout->addControl( pVideo, pos, rData.m_layer );
945 m_pTheme->m_controls[rData.m_id] = CtrlGenericPtr( pVideo );
949 const Position Builder::makePosition( const string &rLeftTop,
950 const string &rRightBottom,
951 int xPos, int yPos, int width,
952 int height, const Box &rBox ) const
954 int left = 0, top = 0, right = 0, bottom = 0;
955 Position::Ref_t refLeftTop = Position::kLeftTop;
956 Position::Ref_t refRightBottom = Position::kLeftTop;
958 int boxWidth = rBox.getWidth();
959 int boxHeight = rBox.getHeight();
961 // Position of the left top corner
962 if( rLeftTop == "lefttop" )
966 refLeftTop = Position::kLeftTop;
968 else if( rLeftTop == "righttop" )
970 left = xPos - boxWidth + 1;
972 refLeftTop = Position::kRightTop;
974 else if( rLeftTop == "leftbottom" )
977 top = yPos - boxHeight + 1;
978 refLeftTop = Position::kLeftBottom;
980 else if( rLeftTop == "rightbottom" )
982 left = xPos - boxWidth + 1;
983 top = yPos - boxHeight + 1;
984 refLeftTop = Position::kRightBottom;
987 // Position of the right bottom corner
988 if( rRightBottom == "lefttop" )
990 right = xPos + width - 1;
991 bottom = yPos + height - 1;
992 refRightBottom = Position::kLeftTop;
994 else if( rRightBottom == "righttop" )
996 right = xPos + width - boxWidth;
997 bottom = yPos + height - 1;
998 refRightBottom = Position::kRightTop;
1000 else if( rRightBottom == "leftbottom" )
1002 right = xPos + width - 1;
1003 bottom = yPos + height - boxHeight;
1004 refRightBottom = Position::kLeftBottom;
1006 else if( rRightBottom == "rightbottom" )
1008 right = xPos + width - boxWidth;
1009 bottom = yPos + height - boxHeight;
1010 refRightBottom = Position::kRightBottom;
1013 return Position( left, top, right, bottom, rBox, refLeftTop,
1018 GenericFont *Builder::getFont( const string &fontId )
1020 GenericFont *pFont = m_pTheme->getFontById(fontId);
1021 if( !pFont && fontId == "defaultfont" )
1023 // Get the resource path and try to load the default font
1024 OSFactory *pOSFactory = OSFactory::instance( getIntf() );
1025 const list<string> &resPath = pOSFactory->getResourcePath();
1026 const string &sep = pOSFactory->getDirSeparator();
1028 list<string>::const_iterator it;
1029 for( it = resPath.begin(); it != resPath.end(); it++ )
1031 string path = (*it) + sep + "fonts" + sep + "FreeSans.ttf";
1032 pFont = new FT2Font( getIntf(), path, 12 );
1035 // Font loaded successfully
1036 m_pTheme->m_fonts["defaultfont"] = GenericFontPtr( pFont );
1047 msg_Err( getIntf(), "failed to open the default font" );
1054 string Builder::getFilePath( const string &rFileName ) const
1056 OSFactory *pFactory = OSFactory::instance( getIntf() );
1057 return m_path + pFactory->getDirSeparator() + rFileName;
1062 Bezier *Builder::getPoints( const char *pTag ) const
1064 vector<float> xBez, yBez;
1068 if( sscanf( pTag, "(%d,%d)%n", &x, &y, &n ) < 1 )
1073 if( x < 0 || y < 0 )
1076 "Slider points cannot have negative coordinates!" );
1080 xBez.push_back( x );
1081 yBez.push_back( y );
1087 if( *(pTag++) != ',' )
1093 // Create the Bezier curve
1094 return new Bezier( getIntf(), xBez, yBez );
1098 uint32_t Builder::getColor( const string &rVal ) const
1100 // Check it the value is a registered constant
1101 Interpreter *pInterpreter = Interpreter::instance( getIntf() );
1102 string val = pInterpreter->getConstant( rVal );
1104 // Convert to an int value
1105 return SkinParser::convertColor( val.c_str() );