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 *****************************************************************************/
25 #include "builder.hpp"
26 #include "builder_data.hpp"
27 #include "interpreter.hpp"
28 #include "skin_parser.hpp"
29 #include "../src/file_bitmap.hpp"
30 #include "../src/os_factory.hpp"
31 #include "../src/generic_bitmap.hpp"
32 #include "../src/top_window.hpp"
33 #include "../src/anchor.hpp"
34 #include "../src/bitmap_font.hpp"
35 #include "../src/ft2_font.hpp"
36 #include "../src/ini_file.hpp"
37 #include "../src/generic_layout.hpp"
38 #include "../src/popup.hpp"
39 #include "../src/theme.hpp"
40 #include "../src/window_manager.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( Panel );
110 ADD_OBJECTS( Anchor );
111 ADD_OBJECTS( Button );
112 ADD_OBJECTS( Checkbox );
113 ADD_OBJECTS( Image );
115 ADD_OBJECTS( RadialSlider );
116 ADD_OBJECTS( Slider );
119 ADD_OBJECTS( Video );
120 // MenuItems must be created after all the rest, so that the IDs of the
121 // other elements exist and can be parsed in the actions
122 ADD_OBJECTS( MenuItem );
123 ADD_OBJECTS( MenuSeparator );
129 // Macro to get a bitmap by its ID in the builder
130 #define GET_BMP( pBmp, id ) \
133 pBmp = m_pTheme->getBitmapById(id); \
136 msg_Err( getIntf(), "unknown bitmap id: %s", id.c_str() ); \
142 // Macro to get the parent box of a control, given the panel ID
143 #define GET_BOX( pRect, id, pLayout ) \
145 pRect = &pLayout->getRect(); \
148 const Position *pParent = \
149 m_pTheme->getPositionById( rData.m_panelId ); \
150 if( pParent == NULL ) \
152 msg_Err( getIntf(), "parent panel could not be found: %s", \
153 rData.m_panelId.c_str() ); \
160 void Builder::addTheme( const BuilderData::Theme &rData )
162 WindowManager &rManager = m_pTheme->getWindowManager();
163 rManager.setMagnetValue( rData.m_magnet );
164 rManager.setAlphaValue( rData.m_alpha );
165 rManager.setMoveAlphaValue( rData.m_moveAlpha );
166 GenericFont *pFont = getFont( rData.m_tooltipfont );
169 rManager.createTooltip( *pFont );
173 msg_Warn( getIntf(), "invalid tooltip font: %s",
174 rData.m_tooltipfont.c_str() );
179 void Builder::addIniFile( const BuilderData::IniFile &rData )
181 // Parse the INI file
182 IniFile iniFile( getIntf(), rData.m_id, getFilePath( rData.m_file ) );
187 void Builder::addBitmap( const BuilderData::Bitmap &rData )
189 GenericBitmap *pBmp =
190 new FileBitmap( getIntf(), m_pImageHandler,
191 getFilePath( rData.m_fileName ), rData.m_alphaColor,
192 rData.m_nbFrames, rData.m_fps );
193 if( !pBmp->getData() )
199 m_pTheme->m_bitmaps[rData.m_id] = GenericBitmapPtr( pBmp );
203 void Builder::addSubBitmap( const BuilderData::SubBitmap &rData )
205 if( m_pTheme->m_bitmaps.find( rData.m_id ) != m_pTheme->m_bitmaps.end() )
207 msg_Dbg( getIntf(), "bitmap %s already exists", rData.m_id.c_str() );
211 // Get the parent bitmap
212 GenericBitmap *pParentBmp = NULL;
213 GET_BMP( pParentBmp, rData.m_parent );
215 // Copy a region of the parent bitmap to the new one
217 new BitmapImpl( getIntf(), rData.m_width, rData.m_height,
218 rData.m_nbFrames, rData.m_fps );
219 bool res = pBmp->drawBitmap( *pParentBmp, rData.m_x, rData.m_y, 0, 0,
220 rData.m_width, rData.m_height );
223 // Invalid sub-bitmap
225 msg_Warn( getIntf(), "sub-bitmap %s ignored", rData.m_id.c_str() );
228 m_pTheme->m_bitmaps[rData.m_id] = GenericBitmapPtr( pBmp );
232 void Builder::addBitmapFont( const BuilderData::BitmapFont &rData )
234 if( m_pTheme->m_fonts.find( rData.m_id ) != m_pTheme->m_fonts.end() )
236 msg_Dbg( getIntf(), "font %s already exists", rData.m_id.c_str() );
240 GenericBitmap *pBmp =
241 new FileBitmap( getIntf(), m_pImageHandler,
242 getFilePath( rData.m_file ), 0 );
243 if( !pBmp->getData() )
250 m_pTheme->m_bitmaps[rData.m_id] = GenericBitmapPtr( pBmp );
252 GenericFont *pFont = new BitmapFont( getIntf(), *pBmp, rData.m_type );
255 m_pTheme->m_fonts[rData.m_id] = GenericFontPtr( pFont );
264 void Builder::addFont( const BuilderData::Font &rData )
266 // Try to load the font from the theme directory
267 GenericFont *pFont = new FT2Font( getIntf(),
268 getFilePath( rData.m_fontFile ),
272 m_pTheme->m_fonts[rData.m_id] = GenericFontPtr( pFont );
278 // Font not found; try in the resource path
279 OSFactory *pOSFactory = OSFactory::instance( getIntf() );
280 const list<string> &resPath = pOSFactory->getResourcePath();
281 const string &sep = pOSFactory->getDirSeparator();
283 list<string>::const_iterator it;
284 for( it = resPath.begin(); it != resPath.end(); it++ )
286 string path = (*it) + sep + "fonts" + sep + rData.m_fontFile;
287 pFont = new FT2Font( getIntf(), path, rData.m_size );
290 // Font loaded successfully
291 m_pTheme->m_fonts[rData.m_id] = GenericFontPtr( pFont );
303 void Builder::addPopupMenu( const BuilderData::PopupMenu &rData )
305 Popup *pPopup = new Popup( getIntf(), m_pTheme->getWindowManager() );
307 m_pTheme->m_popups[rData.m_id] = PopupPtr( pPopup );
311 void Builder::addMenuItem( const BuilderData::MenuItem &rData )
313 Popup *pPopup = m_pTheme->getPopupById( rData.m_popupId );
316 msg_Err( getIntf(), "unknown popup id: %s", rData.m_popupId.c_str() );
320 CmdGeneric *pCommand = parseAction( rData.m_action );
321 if( pCommand == NULL )
323 msg_Err( getIntf(), "invalid action: %s", rData.m_action.c_str() );
327 pPopup->addItem( rData.m_label, *pCommand, rData.m_pos );
331 void Builder::addMenuSeparator( const BuilderData::MenuSeparator &rData )
333 Popup *pPopup = m_pTheme->getPopupById( rData.m_popupId );
336 msg_Err( getIntf(), "unknown popup id: %s", rData.m_popupId.c_str() );
340 pPopup->addSeparator( rData.m_pos );
344 void Builder::addWindow( const BuilderData::Window &rData )
347 new TopWindow( getIntf(), rData.m_xPos, rData.m_yPos,
348 m_pTheme->getWindowManager(),
349 rData.m_dragDrop, rData.m_playOnDrop,
352 m_pTheme->m_windows[rData.m_id] = TopWindowPtr( pWin );
356 void Builder::addLayout( const BuilderData::Layout &rData )
358 TopWindow *pWin = m_pTheme->getWindowById( rData.m_windowId );
361 msg_Err( getIntf(), "unknown window id: %s", rData.m_windowId.c_str() );
365 int minWidth = rData.m_minWidth != -1 ? rData.m_minWidth : rData.m_width;
366 int maxWidth = rData.m_maxWidth != -1 ? rData.m_maxWidth : rData.m_width;
367 int minHeight = rData.m_minHeight != -1 ? rData.m_minHeight :
369 int maxHeight = rData.m_maxHeight != -1 ? rData.m_maxHeight :
371 GenericLayout *pLayout = new GenericLayout( getIntf(), rData.m_width,
373 minWidth, maxWidth, minHeight,
375 m_pTheme->m_layouts[rData.m_id] = GenericLayoutPtr( pLayout );
377 // Attach the layout to its window
378 m_pTheme->getWindowManager().addLayout( *pWin, *pLayout );
382 void Builder::addAnchor( const BuilderData::Anchor &rData )
384 GenericLayout *pLayout = m_pTheme->getLayoutById( rData.m_layoutId );
385 if( pLayout == NULL )
387 msg_Err( getIntf(), "unknown layout id: %s", rData.m_layoutId.c_str() );
391 Bezier *pCurve = getPoints( rData.m_points.c_str() );
394 msg_Err( getIntf(), "invalid format in tag points=\"%s\"",
395 rData.m_points.c_str() );
398 m_pTheme->m_curves.push_back( BezierPtr( pCurve ) );
400 // Compute the position of the anchor
401 const Position pos = makePosition( rData.m_leftTop, rData.m_leftTop,
402 rData.m_xPos, rData.m_yPos,
405 pLayout->getRect() );
407 Anchor *pAnc = new Anchor( getIntf(), pos, rData.m_range, rData.m_priority,
409 pLayout->addAnchor( pAnc );
413 void Builder::addButton( const BuilderData::Button &rData )
415 // Get the bitmaps of the button
416 GenericBitmap *pBmpUp = NULL;
417 GET_BMP( pBmpUp, rData.m_upId );
419 GenericBitmap *pBmpDown = pBmpUp;
420 GET_BMP( pBmpDown, rData.m_downId );
422 GenericBitmap *pBmpOver = pBmpUp;
423 GET_BMP( pBmpOver, rData.m_overId );
425 GenericLayout *pLayout = m_pTheme->getLayoutById( rData.m_layoutId );
426 if( pLayout == NULL )
428 msg_Err( getIntf(), "unknown layout id: %s", rData.m_layoutId.c_str() );
432 CmdGeneric *pCommand = parseAction( rData.m_actionId );
433 if( pCommand == NULL )
435 msg_Err( getIntf(), "invalid action: %s", rData.m_actionId.c_str() );
439 // Get the visibility variable
440 // XXX check when it is null
441 Interpreter *pInterpreter = Interpreter::instance( getIntf() );
442 VarBool *pVisible = pInterpreter->getVarBool( rData.m_visible, m_pTheme );
444 CtrlButton *pButton = new CtrlButton( getIntf(), *pBmpUp, *pBmpOver,
445 *pBmpDown, *pCommand, UString( getIntf(), rData.m_tooltip.c_str() ),
446 UString( getIntf(), rData.m_help.c_str() ), pVisible );
447 m_pTheme->m_controls[rData.m_id] = CtrlGenericPtr( pButton );
449 // Compute the position of the control
450 // XXX (we suppose all the images have the same size...)
451 const GenericRect *pRect;
452 GET_BOX( pRect, rData.m_panelId , pLayout);
453 const Position pos = makePosition( rData.m_leftTop, rData.m_rightBottom,
454 rData.m_xPos, rData.m_yPos,
456 pBmpUp->getHeight(), *pRect,
457 rData.m_xKeepRatio, rData.m_yKeepRatio );
459 pLayout->addControl( pButton, pos, rData.m_layer );
463 void Builder::addCheckbox( const BuilderData::Checkbox &rData )
465 // Get the bitmaps of the checkbox
466 GenericBitmap *pBmpUp1 = NULL;
467 GET_BMP( pBmpUp1, rData.m_up1Id );
469 GenericBitmap *pBmpDown1 = pBmpUp1;
470 GET_BMP( pBmpDown1, rData.m_down1Id );
472 GenericBitmap *pBmpOver1 = pBmpUp1;
473 GET_BMP( pBmpOver1, rData.m_over1Id );
475 GenericBitmap *pBmpUp2 = NULL;
476 GET_BMP( pBmpUp2, rData.m_up2Id );
478 GenericBitmap *pBmpDown2 = pBmpUp2;
479 GET_BMP( pBmpDown2, rData.m_down2Id );
481 GenericBitmap *pBmpOver2 = pBmpUp2;
482 GET_BMP( pBmpOver2, rData.m_over2Id );
484 GenericLayout *pLayout = m_pTheme->getLayoutById( rData.m_layoutId );
485 if( pLayout == NULL )
487 msg_Err( getIntf(), "unknown layout id: %s", rData.m_layoutId.c_str() );
491 CmdGeneric *pCommand1 = parseAction( rData.m_action1 );
492 if( pCommand1 == NULL )
494 msg_Err( getIntf(), "invalid action: %s", rData.m_action1.c_str() );
498 CmdGeneric *pCommand2 = parseAction( rData.m_action2 );
499 if( pCommand2 == NULL )
501 msg_Err( getIntf(), "invalid action: %s", rData.m_action2.c_str() );
505 // Get the state variable
506 Interpreter *pInterpreter = Interpreter::instance( getIntf() );
507 VarBool *pVar = pInterpreter->getVarBool( rData.m_state, m_pTheme );
510 // TODO: default state
514 // Get the visibility variable
515 // XXX check when it is null
516 VarBool *pVisible = pInterpreter->getVarBool( rData.m_visible, m_pTheme );
518 // Create the control
519 CtrlCheckbox *pCheckbox = new CtrlCheckbox( getIntf(), *pBmpUp1,
520 *pBmpOver1, *pBmpDown1, *pBmpUp2, *pBmpOver2, *pBmpDown2, *pCommand1,
521 *pCommand2, UString( getIntf(), rData.m_tooltip1.c_str() ),
522 UString( getIntf(), rData.m_tooltip2.c_str() ), *pVar,
523 UString( getIntf(), rData.m_help.c_str() ), pVisible );
524 m_pTheme->m_controls[rData.m_id] = CtrlGenericPtr( pCheckbox );
526 // Compute the position of the control
527 // XXX (we suppose all the images have the same size...)
528 const GenericRect *pRect;
529 GET_BOX( pRect, rData.m_panelId , pLayout);
530 const Position pos = makePosition( rData.m_leftTop, rData.m_rightBottom,
531 rData.m_xPos, rData.m_yPos,
533 pBmpUp1->getHeight(), *pRect,
534 rData.m_xKeepRatio, rData.m_yKeepRatio );
536 pLayout->addControl( pCheckbox, pos, rData.m_layer );
540 void Builder::addImage( const BuilderData::Image &rData )
542 GenericBitmap *pBmp = NULL;
543 GET_BMP( pBmp, rData.m_bmpId );
545 GenericLayout *pLayout = m_pTheme->getLayoutById( rData.m_layoutId );
546 if( pLayout == NULL )
548 msg_Err( getIntf(), "unknown layout id: %s", rData.m_layoutId.c_str() );
552 TopWindow *pWindow = m_pTheme->getWindowById( rData.m_windowId );
553 if( pWindow == NULL )
555 msg_Err( getIntf(), "unknown window id: %s", rData.m_windowId.c_str() );
559 CmdGeneric *pCommand = parseAction( rData.m_action2Id );
560 if( pCommand == NULL )
562 msg_Err( getIntf(), "invalid action: %s", rData.m_action2Id.c_str() );
566 // Get the visibility variable
567 // XXX check when it is null
568 Interpreter *pInterpreter = Interpreter::instance( getIntf() );
569 VarBool *pVisible = pInterpreter->getVarBool( rData.m_visible, m_pTheme );
571 CtrlImage::resize_t resizeMethod =
572 (rData.m_resize == "scale" ? CtrlImage::kScale : CtrlImage::kMosaic);
573 CtrlImage *pImage = new CtrlImage( getIntf(), *pBmp, *pCommand,
574 resizeMethod, UString( getIntf(), rData.m_help.c_str() ), pVisible );
575 m_pTheme->m_controls[rData.m_id] = CtrlGenericPtr( pImage );
577 // Compute the position of the control
578 const GenericRect *pRect;
579 GET_BOX( pRect, rData.m_panelId , pLayout);
580 const Position pos = makePosition( rData.m_leftTop, rData.m_rightBottom,
581 rData.m_xPos, rData.m_yPos,
582 pBmp->getWidth(), pBmp->getHeight(),
583 *pRect, rData.m_xKeepRatio,
584 rData.m_yKeepRatio );
586 if( rData.m_actionId == "move" )
588 CtrlMove *pMove = new CtrlMove( getIntf(), m_pTheme->getWindowManager(),
589 *pImage, *pWindow, UString( getIntf(), rData.m_help.c_str() ),
591 m_pTheme->m_controls[rData.m_id + "_move"] = CtrlGenericPtr( pMove );
592 pLayout->addControl( pMove, pos, rData.m_layer );
594 else if( rData.m_actionId == "resizeS" )
596 CtrlResize *pResize = new CtrlResize( getIntf(),
597 m_pTheme->getWindowManager(), *pImage, *pLayout,
598 UString( getIntf(), rData.m_help.c_str() ), pVisible,
599 WindowManager::kResizeS );
600 m_pTheme->m_controls[rData.m_id + "_rsz"] = CtrlGenericPtr( pResize );
601 pLayout->addControl( pResize, pos, rData.m_layer );
603 else if( rData.m_actionId == "resizeE" )
605 CtrlResize *pResize = new CtrlResize( getIntf(),
606 m_pTheme->getWindowManager(), *pImage, *pLayout,
607 UString( getIntf(), rData.m_help.c_str() ), pVisible,
608 WindowManager::kResizeE );
609 m_pTheme->m_controls[rData.m_id + "_rsz"] = CtrlGenericPtr( pResize );
610 pLayout->addControl( pResize, pos, rData.m_layer );
612 else if( rData.m_actionId == "resizeSE" )
614 CtrlResize *pResize = new CtrlResize( getIntf(),
615 m_pTheme->getWindowManager(), *pImage, *pLayout,
616 UString( getIntf(), rData.m_help.c_str() ), pVisible,
617 WindowManager::kResizeSE );
618 m_pTheme->m_controls[rData.m_id + "_rsz"] = CtrlGenericPtr( pResize );
619 pLayout->addControl( pResize, pos, rData.m_layer );
623 pLayout->addControl( pImage, pos, rData.m_layer );
628 void Builder::addPanel( const BuilderData::Panel &rData )
630 // This method makes the assumption that the Panels are created in the
631 // order of the XML, because each child Panel expects its parent Panel
632 // in order to be fully created
634 GenericLayout *pLayout = m_pTheme->getLayoutById( rData.m_layoutId );
635 if( pLayout == NULL )
637 msg_Err( getIntf(), "unknown layout id: %s", rData.m_layoutId.c_str() );
641 const GenericRect *pRect;
642 GET_BOX( pRect, rData.m_panelId , pLayout);
644 new Position( makePosition( rData.m_leftTop, rData.m_rightBottom,
645 rData.m_xPos, rData.m_yPos,
646 rData.m_width, rData.m_height,
647 *pRect, rData.m_xKeepRatio,
648 rData.m_yKeepRatio ) );
649 m_pTheme->m_positions[rData.m_id] = PositionPtr( pPos );
653 void Builder::addText( const BuilderData::Text &rData )
655 GenericLayout *pLayout = m_pTheme->getLayoutById( rData.m_layoutId );
656 if( pLayout == NULL )
658 msg_Err( getIntf(), "unknown layout id: %s", rData.m_layoutId.c_str() );
662 GenericFont *pFont = getFont( rData.m_fontId );
665 msg_Err( getIntf(), "unknown font id: %s", rData.m_fontId.c_str() );
669 // Convert the scrolling mode
670 CtrlText::Scrolling_t scrolling;
671 if( rData.m_scrolling == "auto" )
672 scrolling = CtrlText::kAutomatic;
673 else if( rData.m_scrolling == "manual" )
674 scrolling = CtrlText::kManual;
675 else if( rData.m_scrolling == "none" )
676 scrolling = CtrlText::kNone;
679 msg_Err( getIntf(), "invalid scrolling mode: %s",
680 rData.m_scrolling.c_str() );
684 // Convert the alignment
685 CtrlText::Align_t alignment;
686 if( rData.m_alignment == "left" )
687 alignment = CtrlText::kLeft;
688 else if( rData.m_alignment == "center" || rData.m_alignment == "centre" )
689 alignment = CtrlText::kCenter;
690 else if( rData.m_alignment == "right" )
691 alignment = CtrlText::kRight;
694 msg_Err( getIntf(), "invalid alignment: %s",
695 rData.m_alignment.c_str() );
699 // Create a text variable
700 VarText *pVar = new VarText( getIntf() );
701 m_pTheme->m_vars.push_back( VariablePtr( pVar ) );
703 // Get the visibility variable
704 // XXX check when it is null
705 Interpreter *pInterpreter = Interpreter::instance( getIntf() );
706 VarBool *pVisible = pInterpreter->getVarBool( rData.m_visible, m_pTheme );
708 CtrlText *pText = new CtrlText( getIntf(), *pVar, *pFont,
709 UString( getIntf(), rData.m_help.c_str() ), rData.m_color, pVisible,
710 scrolling, alignment );
711 m_pTheme->m_controls[rData.m_id] = CtrlGenericPtr( pText );
713 int height = pFont->getSize();
715 // Compute the position of the control
716 const GenericRect *pRect;
717 GET_BOX( pRect, rData.m_panelId , pLayout);
718 const Position pos = makePosition( rData.m_leftTop, rData.m_rightBottom,
719 rData.m_xPos, rData.m_yPos,
720 rData.m_width, height, *pRect,
721 rData.m_xKeepRatio, rData.m_yKeepRatio );
723 pLayout->addControl( pText, pos, rData.m_layer );
725 // Set the text of the control
726 UString msg( getIntf(), rData.m_text.c_str() );
731 void Builder::addRadialSlider( const BuilderData::RadialSlider &rData )
733 // Get the bitmaps of the slider
734 GenericBitmap *pSeq = NULL;
735 GET_BMP( pSeq, rData.m_sequence );
737 GenericLayout *pLayout = m_pTheme->getLayoutById( rData.m_layoutId );
738 if( pLayout == NULL )
740 msg_Err( getIntf(), "unknown layout id: %s", rData.m_layoutId.c_str() );
744 // Get the variable associated to the slider
745 Interpreter *pInterpreter = Interpreter::instance( getIntf() );
746 VarPercent *pVar = pInterpreter->getVarPercent( rData.m_value, m_pTheme );
749 msg_Err( getIntf(), "unknown slider value: %s", rData.m_value.c_str() );
753 // Get the visibility variable
754 // XXX check when it is null
755 VarBool *pVisible = pInterpreter->getVarBool( rData.m_visible, m_pTheme );
757 // Create the control
758 CtrlRadialSlider *pRadial =
759 new CtrlRadialSlider( getIntf(), *pSeq, rData.m_nbImages, *pVar,
760 rData.m_minAngle, rData.m_maxAngle,
761 UString( getIntf(), rData.m_help.c_str() ),
763 m_pTheme->m_controls[rData.m_id] = CtrlGenericPtr( pRadial );
765 // XXX: resizing is not supported
766 // Compute the position of the control
767 const GenericRect *pRect;
768 GET_BOX( pRect, rData.m_panelId , pLayout);
769 const Position pos = makePosition( rData.m_leftTop, rData.m_rightBottom,
770 rData.m_xPos, rData.m_yPos,
772 pSeq->getHeight() / rData.m_nbImages,
774 rData.m_xKeepRatio, rData.m_yKeepRatio );
776 pLayout->addControl( pRadial, pos, rData.m_layer );
780 void Builder::addSlider( const BuilderData::Slider &rData )
782 // Add the background first, so that we will still have something almost
783 // functional if the cursor cannot be created properly (this happens for
784 // some winamp2 skins, where the images of the cursor are not always
787 // Get the bitmaps of the background
788 GenericBitmap *pBgImage = NULL;
789 if( rData.m_imageId != "none" )
791 GET_BMP( pBgImage, rData.m_imageId );
794 GenericLayout *pLayout = m_pTheme->getLayoutById( rData.m_layoutId );
795 if( pLayout == NULL )
797 msg_Err( getIntf(), "unknown layout id: %s", rData.m_layoutId.c_str() );
801 Bezier *pCurve = getPoints( rData.m_points.c_str() );
804 msg_Err( getIntf(), "invalid format in tag points=\"%s\"",
805 rData.m_points.c_str() );
808 m_pTheme->m_curves.push_back( BezierPtr( pCurve ) );
810 // Get the visibility variable
811 // XXX check when it is null
812 Interpreter *pInterpreter = Interpreter::instance( getIntf() );
813 VarBool *pVisible = pInterpreter->getVarBool( rData.m_visible, m_pTheme );
815 // Get the variable associated to the slider
816 VarPercent *pVar = pInterpreter->getVarPercent( rData.m_value, m_pTheme );
819 msg_Err( getIntf(), "unknown slider value: %s", rData.m_value.c_str() );
823 // Create the background control
824 CtrlSliderBg *pBackground = new CtrlSliderBg( getIntf(),
825 *pCurve, *pVar, rData.m_thickness, pBgImage, rData.m_nbHoriz,
826 rData.m_nbVert, rData.m_padHoriz, rData.m_padVert,
827 pVisible, UString( getIntf(), rData.m_help.c_str() ) );
828 m_pTheme->m_controls[rData.m_id + "_bg"] = CtrlGenericPtr( pBackground );
830 // Compute the position of the control
831 const GenericRect *pRect;
832 GET_BOX( pRect, rData.m_panelId , pLayout);
833 const Position pos = makePosition( rData.m_leftTop, rData.m_rightBottom,
834 rData.m_xPos, rData.m_yPos,
835 pCurve->getWidth(), pCurve->getHeight(),
837 rData.m_xKeepRatio, rData.m_yKeepRatio );
839 pLayout->addControl( pBackground, pos, rData.m_layer );
841 // Get the bitmaps of the cursor
842 GenericBitmap *pBmpUp = NULL;
843 GET_BMP( pBmpUp, rData.m_upId );
845 GenericBitmap *pBmpDown = pBmpUp;
846 GET_BMP( pBmpDown, rData.m_downId );
848 GenericBitmap *pBmpOver = pBmpUp;
849 GET_BMP( pBmpOver, rData.m_overId );
851 // Create the cursor control
852 CtrlSliderCursor *pCursor = new CtrlSliderCursor( getIntf(), *pBmpUp,
853 *pBmpOver, *pBmpDown, *pCurve, *pVar, pVisible,
854 UString( getIntf(), rData.m_tooltip.c_str() ),
855 UString( getIntf(), rData.m_help.c_str() ) );
856 m_pTheme->m_controls[rData.m_id] = CtrlGenericPtr( pCursor );
858 pLayout->addControl( pCursor, pos, rData.m_layer );
860 // Associate the cursor to the background
861 pBackground->associateCursor( *pCursor );
865 void Builder::addList( const BuilderData::List &rData )
867 // Get the background bitmap, if any
868 GenericBitmap *pBgBmp = NULL;
869 GET_BMP( pBgBmp, rData.m_bgImageId );
871 GenericLayout *pLayout = m_pTheme->getLayoutById( rData.m_layoutId );
872 if( pLayout == NULL )
874 msg_Err( getIntf(), "unknown layout id: %s", rData.m_layoutId.c_str() );
878 GenericFont *pFont = getFont( rData.m_fontId );
881 msg_Err( getIntf(), "unknown font id: %s", rData.m_fontId.c_str() );
885 // Get the list variable
886 Interpreter *pInterpreter = Interpreter::instance( getIntf() );
887 VarList *pVar = pInterpreter->getVarList( rData.m_var, m_pTheme );
890 msg_Err( getIntf(), "no such list variable: %s", rData.m_var.c_str() );
894 // Get the visibility variable
895 // XXX check when it is null
896 VarBool *pVisible = pInterpreter->getVarBool( rData.m_visible, m_pTheme );
898 // Get the color values
899 uint32_t fgColor = getColor( rData.m_fgColor );
900 uint32_t playColor = getColor( rData.m_playColor );
901 uint32_t bgColor1 = getColor( rData.m_bgColor1 );
902 uint32_t bgColor2 = getColor( rData.m_bgColor2 );
903 uint32_t selColor = getColor( rData.m_selColor );
905 // Create the list control
906 CtrlList *pList = new CtrlList( getIntf(), *pVar, *pFont, pBgBmp,
907 fgColor, playColor, bgColor1, bgColor2, selColor,
908 UString( getIntf(), rData.m_help.c_str() ), pVisible );
909 m_pTheme->m_controls[rData.m_id] = CtrlGenericPtr( pList );
911 // Compute the position of the control
912 const GenericRect *pRect;
913 GET_BOX( pRect, rData.m_panelId , pLayout);
914 const Position pos = makePosition( rData.m_leftTop, rData.m_rightBottom,
915 rData.m_xPos, rData.m_yPos,
916 rData.m_width, rData.m_height,
918 rData.m_xKeepRatio, rData.m_yKeepRatio );
920 pLayout->addControl( pList, pos, rData.m_layer );
923 void Builder::addTree( const BuilderData::Tree &rData )
925 // Get the bitmaps, if any
926 GenericBitmap *pBgBmp = NULL;
927 GenericBitmap *pItemBmp = NULL;
928 GenericBitmap *pOpenBmp = NULL;
929 GenericBitmap *pClosedBmp = NULL;
930 GET_BMP( pBgBmp, rData.m_bgImageId );
931 GET_BMP( pItemBmp, rData.m_itemImageId );
932 GET_BMP( pOpenBmp, rData.m_openImageId );
933 GET_BMP( pClosedBmp, rData.m_closedImageId );
935 GenericLayout *pLayout = m_pTheme->getLayoutById( rData.m_layoutId );
936 if( pLayout == NULL )
938 msg_Err( getIntf(), "unknown layout id: %s", rData.m_layoutId.c_str() );
942 GenericFont *pFont = getFont( rData.m_fontId );
945 msg_Err( getIntf(), "unknown font id: %s", rData.m_fontId.c_str() );
949 // Get the list variable
950 Interpreter *pInterpreter = Interpreter::instance( getIntf() );
951 VarTree *pVar = pInterpreter->getVarTree( rData.m_var, m_pTheme );
954 msg_Err( getIntf(), "no such list variable: %s", rData.m_var.c_str() );
958 // Get the visibility variable
959 // XXX check when it is null
960 VarBool *pVisible = pInterpreter->getVarBool( rData.m_visible, m_pTheme );
961 VarBool *pFlat = pInterpreter->getVarBool( rData.m_flat, m_pTheme );
963 // Get the color values
964 uint32_t fgColor = getColor( rData.m_fgColor );
965 uint32_t playColor = getColor( rData.m_playColor );
966 uint32_t bgColor1 = getColor( rData.m_bgColor1 );
967 uint32_t bgColor2 = getColor( rData.m_bgColor2 );
968 uint32_t selColor = getColor( rData.m_selColor );
970 // Create the list control
971 CtrlTree *pTree = new CtrlTree( getIntf(), *pVar, *pFont, pBgBmp,
972 pItemBmp, pOpenBmp, pClosedBmp,
973 fgColor, playColor, bgColor1, bgColor2, selColor,
974 UString( getIntf(), rData.m_help.c_str() ), pVisible, pFlat );
975 m_pTheme->m_controls[rData.m_id] = CtrlGenericPtr( pTree );
977 // Compute the position of the control
978 const GenericRect *pRect;
979 GET_BOX( pRect, rData.m_panelId , pLayout);
980 const Position pos = makePosition( rData.m_leftTop, rData.m_rightBottom,
981 rData.m_xPos, rData.m_yPos,
982 rData.m_width, rData.m_height,
984 rData.m_xKeepRatio, rData.m_yKeepRatio );
986 pLayout->addControl( pTree, pos, rData.m_layer );
989 void Builder::addVideo( const BuilderData::Video &rData )
991 GenericLayout *pLayout = m_pTheme->getLayoutById( rData.m_layoutId );
992 if( pLayout == NULL )
994 msg_Err( getIntf(), "unknown layout id: %s", rData.m_layoutId.c_str() );
998 // Get the visibility variable
999 // XXX check when it is null
1000 Interpreter *pInterpreter = Interpreter::instance( getIntf() );
1001 VarBool *pVisible = pInterpreter->getVarBool( rData.m_visible, m_pTheme );
1003 CtrlVideo *pVideo = new CtrlVideo( getIntf(), *pLayout,
1004 rData.m_autoResize, UString( getIntf(), rData.m_help.c_str() ),
1006 m_pTheme->m_controls[rData.m_id] = CtrlGenericPtr( pVideo );
1008 // Compute the position of the control
1009 const GenericRect *pRect;
1010 GET_BOX( pRect, rData.m_panelId , pLayout);
1011 const Position pos = makePosition( rData.m_leftTop, rData.m_rightBottom,
1012 rData.m_xPos, rData.m_yPos,
1013 rData.m_width, rData.m_height,
1015 rData.m_xKeepRatio, rData.m_yKeepRatio );
1017 pLayout->addControl( pVideo, pos, rData.m_layer );
1021 const Position Builder::makePosition( const string &rLeftTop,
1022 const string &rRightBottom,
1023 int xPos, int yPos, int width,
1024 int height, const GenericRect &rRect,
1025 bool xKeepRatio, bool yKeepRatio ) const
1027 int left = 0, top = 0, right = 0, bottom = 0;
1028 Position::Ref_t refLeftTop = Position::kLeftTop;
1029 Position::Ref_t refRightBottom = Position::kLeftTop;
1031 int boxWidth = rRect.getWidth();
1032 int boxHeight = rRect.getHeight();
1034 // Position of the left top corner
1035 if( rLeftTop == "lefttop" )
1039 refLeftTop = Position::kLeftTop;
1041 else if( rLeftTop == "righttop" )
1043 left = xPos - boxWidth + 1;
1045 refLeftTop = Position::kRightTop;
1047 else if( rLeftTop == "leftbottom" )
1050 top = yPos - boxHeight + 1;
1051 refLeftTop = Position::kLeftBottom;
1053 else if( rLeftTop == "rightbottom" )
1055 left = xPos - boxWidth + 1;
1056 top = yPos - boxHeight + 1;
1057 refLeftTop = Position::kRightBottom;
1060 // Position of the right bottom corner
1061 if( rRightBottom == "lefttop" )
1063 right = xPos + width - 1;
1064 bottom = yPos + height - 1;
1065 refRightBottom = Position::kLeftTop;
1067 else if( rRightBottom == "righttop" )
1069 right = xPos + width - boxWidth;
1070 bottom = yPos + height - 1;
1071 refRightBottom = Position::kRightTop;
1073 else if( rRightBottom == "leftbottom" )
1075 right = xPos + width - 1;
1076 bottom = yPos + height - boxHeight;
1077 refRightBottom = Position::kLeftBottom;
1079 else if( rRightBottom == "rightbottom" )
1081 right = xPos + width - boxWidth;
1082 bottom = yPos + height - boxHeight;
1083 refRightBottom = Position::kRightBottom;
1086 // In "keep ratio" mode, overwrite the previously computed values with the
1088 // XXX: this coupling between makePosition and the Position class should
1093 right = xPos + width;
1098 bottom = yPos + height;
1101 return Position( left, top, right, bottom, rRect, refLeftTop,
1102 refRightBottom, xKeepRatio, yKeepRatio );
1106 GenericFont *Builder::getFont( const string &fontId )
1108 GenericFont *pFont = m_pTheme->getFontById(fontId);
1109 if( !pFont && fontId == "defaultfont" )
1111 // Get the resource path and try to load the default font
1112 OSFactory *pOSFactory = OSFactory::instance( getIntf() );
1113 const list<string> &resPath = pOSFactory->getResourcePath();
1114 const string &sep = pOSFactory->getDirSeparator();
1116 list<string>::const_iterator it;
1117 for( it = resPath.begin(); it != resPath.end(); it++ )
1119 string path = (*it) + sep + "fonts" + sep + "FreeSans.ttf";
1120 pFont = new FT2Font( getIntf(), path, 12 );
1123 // Font loaded successfully
1124 m_pTheme->m_fonts["defaultfont"] = GenericFontPtr( pFont );
1135 msg_Err( getIntf(), "failed to open the default font" );
1142 string Builder::getFilePath( const string &rFileName ) const
1144 OSFactory *pFactory = OSFactory::instance( getIntf() );
1145 return m_path + pFactory->getDirSeparator() + sFromLocale( rFileName );
1150 Bezier *Builder::getPoints( const char *pTag ) const
1152 vector<float> xBez, yBez;
1156 if( sscanf( pTag, "(%d,%d)%n", &x, &y, &n ) < 1 )
1161 xBez.push_back( x );
1162 yBez.push_back( y );
1168 if( *(pTag++) != ',' )
1174 // Create the Bezier curve
1175 return new Bezier( getIntf(), xBez, yBez );
1179 uint32_t Builder::getColor( const string &rVal ) const
1181 // Check it the value is a registered constant
1182 Interpreter *pInterpreter = Interpreter::instance( getIntf() );
1183 string val = pInterpreter->getConstant( rVal );
1185 // Convert to an int value
1186 return SkinParser::convertColor( val.c_str() );