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 "../src/window_manager.hpp"
42 #include "../commands/cmd_generic.hpp"
43 #include "../controls/ctrl_button.hpp"
44 #include "../controls/ctrl_checkbox.hpp"
45 #include "../controls/ctrl_image.hpp"
46 #include "../controls/ctrl_list.hpp"
47 #include "../controls/ctrl_move.hpp"
48 #include "../controls/ctrl_resize.hpp"
49 #include "../controls/ctrl_slider.hpp"
50 #include "../controls/ctrl_radialslider.hpp"
51 #include "../controls/ctrl_text.hpp"
52 #include "../controls/ctrl_tree.hpp"
53 #include "../controls/ctrl_video.hpp"
54 #include "../utils/bezier.hpp"
55 #include "../utils/position.hpp"
56 #include "../utils/var_bool.hpp"
57 #include "../utils/var_text.hpp"
59 #include "vlc_image.h"
62 Builder::Builder( intf_thread_t *pIntf, const BuilderData &rData,
63 const string &rPath ):
64 SkinObject( pIntf ), m_rData( rData ), m_path( rPath ), m_pTheme( NULL )
66 m_pImageHandler = image_HandlerCreate( pIntf );
71 if( m_pImageHandler ) image_HandlerDelete( m_pImageHandler );
74 CmdGeneric *Builder::parseAction( const string &rAction )
76 return Interpreter::instance( getIntf() )->parseAction( rAction, m_pTheme );
81 #define ADD_OBJECTS( type ) \
82 list<BuilderData::type>::const_iterator it##type; \
83 for( it##type = m_rData.m_list##type.begin(); \
84 it##type != m_rData.m_list##type.end(); it##type++ ) \
86 add##type( *it##type ); \
90 Theme *Builder::build()
92 m_pTheme = new Theme( getIntf() );
93 if( m_pTheme == NULL )
98 // Create everything from the data in the XML
100 ADD_OBJECTS( IniFile );
101 ADD_OBJECTS( Bitmap );
102 ADD_OBJECTS( SubBitmap );
103 ADD_OBJECTS( BitmapFont );
105 ADD_OBJECTS( Window );
106 // XXX: PopupMenus are created after the windows, so that the Win32Factory
107 // (at least) can give a valid window handle to the OSPopup objects
108 ADD_OBJECTS( PopupMenu );
109 ADD_OBJECTS( Layout );
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() ); \
141 void Builder::addTheme( const BuilderData::Theme &rData )
143 WindowManager &rManager = m_pTheme->getWindowManager();
144 rManager.setMagnetValue( rData.m_magnet );
145 rManager.setAlphaValue( rData.m_alpha );
146 rManager.setMoveAlphaValue( rData.m_moveAlpha );
147 GenericFont *pFont = getFont( rData.m_tooltipfont );
150 rManager.createTooltip( *pFont );
154 msg_Warn( getIntf(), "invalid tooltip font: %s",
155 rData.m_tooltipfont.c_str() );
160 void Builder::addIniFile( const BuilderData::IniFile &rData )
162 // Parse the INI file
163 IniFile iniFile( getIntf(), rData.m_id, getFilePath( rData.m_file ) );
168 void Builder::addBitmap( const BuilderData::Bitmap &rData )
170 GenericBitmap *pBmp =
171 new FileBitmap( getIntf(), m_pImageHandler,
172 getFilePath( rData.m_fileName ), rData.m_alphaColor,
173 rData.m_nbFrames, rData.m_fps );
174 if( !pBmp->getData() )
180 m_pTheme->m_bitmaps[rData.m_id] = GenericBitmapPtr( pBmp );
184 void Builder::addSubBitmap( const BuilderData::SubBitmap &rData )
186 if( m_pTheme->m_bitmaps.find( rData.m_id ) != m_pTheme->m_bitmaps.end() )
188 msg_Dbg( getIntf(), "bitmap %s already exists", rData.m_id.c_str() );
192 // Get the parent bitmap
193 GenericBitmap *pParentBmp = NULL;
194 GET_BMP( pParentBmp, rData.m_parent );
196 // Copy a region of the parent bitmap to the new one
198 new BitmapImpl( getIntf(), rData.m_width, rData.m_height,
199 rData.m_nbFrames, rData.m_fps );
200 bool res = pBmp->drawBitmap( *pParentBmp, rData.m_x, rData.m_y, 0, 0,
201 rData.m_width, rData.m_height );
204 // Invalid sub-bitmap
206 msg_Warn( getIntf(), "sub-bitmap %s ignored", rData.m_id.c_str() );
209 m_pTheme->m_bitmaps[rData.m_id] = GenericBitmapPtr( pBmp );
213 void Builder::addBitmapFont( const BuilderData::BitmapFont &rData )
215 if( m_pTheme->m_fonts.find( rData.m_id ) != m_pTheme->m_fonts.end() )
217 msg_Dbg( getIntf(), "font %s already exists", rData.m_id.c_str() );
221 GenericBitmap *pBmp =
222 new FileBitmap( getIntf(), m_pImageHandler,
223 getFilePath( rData.m_file ), 0 );
224 if( !pBmp->getData() )
231 m_pTheme->m_bitmaps[rData.m_id] = GenericBitmapPtr( pBmp );
233 GenericFont *pFont = new BitmapFont( getIntf(), *pBmp, rData.m_type );
236 m_pTheme->m_fonts[rData.m_id] = GenericFontPtr( pFont );
245 void Builder::addFont( const BuilderData::Font &rData )
247 // Try to load the font from the theme directory
248 GenericFont *pFont = new FT2Font( getIntf(),
249 getFilePath( rData.m_fontFile ),
253 m_pTheme->m_fonts[rData.m_id] = GenericFontPtr( pFont );
259 // Font not found; try in the resource path
260 OSFactory *pOSFactory = OSFactory::instance( getIntf() );
261 const list<string> &resPath = pOSFactory->getResourcePath();
262 const string &sep = pOSFactory->getDirSeparator();
264 list<string>::const_iterator it;
265 for( it = resPath.begin(); it != resPath.end(); it++ )
267 string path = (*it) + sep + "fonts" + sep + rData.m_fontFile;
268 pFont = new FT2Font( getIntf(), path, rData.m_size );
271 // Font loaded successfully
272 m_pTheme->m_fonts[rData.m_id] = GenericFontPtr( pFont );
284 void Builder::addPopupMenu( const BuilderData::PopupMenu &rData )
286 Popup *pPopup = new Popup( getIntf(), m_pTheme->getWindowManager() );
288 m_pTheme->m_popups[rData.m_id] = PopupPtr( pPopup );
292 void Builder::addMenuItem( const BuilderData::MenuItem &rData )
294 Popup *pPopup = m_pTheme->getPopupById( rData.m_popupId );
297 msg_Err( getIntf(), "unknown popup id: %s", rData.m_popupId.c_str() );
301 CmdGeneric *pCommand = parseAction( rData.m_action );
302 if( pCommand == NULL )
304 msg_Err( getIntf(), "invalid action: %s", rData.m_action.c_str() );
308 pPopup->addItem( rData.m_label, *pCommand, rData.m_pos );
312 void Builder::addMenuSeparator( const BuilderData::MenuSeparator &rData )
314 Popup *pPopup = m_pTheme->getPopupById( rData.m_popupId );
317 msg_Err( getIntf(), "unknown popup id: %s", rData.m_popupId.c_str() );
321 pPopup->addSeparator( rData.m_pos );
325 void Builder::addWindow( const BuilderData::Window &rData )
328 new TopWindow( getIntf(), rData.m_xPos, rData.m_yPos,
329 m_pTheme->getWindowManager(),
330 rData.m_dragDrop, rData.m_playOnDrop,
333 m_pTheme->m_windows[rData.m_id] = TopWindowPtr( pWin );
337 void Builder::addLayout( const BuilderData::Layout &rData )
339 TopWindow *pWin = m_pTheme->getWindowById( rData.m_windowId );
342 msg_Err( getIntf(), "unknown window id: %s", rData.m_windowId.c_str() );
346 int minWidth = rData.m_minWidth != -1 ? rData.m_minWidth : rData.m_width;
347 int maxWidth = rData.m_maxWidth != -1 ? rData.m_maxWidth : rData.m_width;
348 int minHeight = rData.m_minHeight != -1 ? rData.m_minHeight :
350 int maxHeight = rData.m_maxHeight != -1 ? rData.m_maxHeight :
352 GenericLayout *pLayout = new GenericLayout( getIntf(), rData.m_width,
354 minWidth, maxWidth, minHeight,
356 m_pTheme->m_layouts[rData.m_id] = GenericLayoutPtr( pLayout );
358 // Attach the layout to its window
359 m_pTheme->getWindowManager().addLayout( *pWin, *pLayout );
363 void Builder::addAnchor( const BuilderData::Anchor &rData )
365 GenericLayout *pLayout = m_pTheme->getLayoutById( rData.m_layoutId );
366 if( pLayout == NULL )
368 msg_Err( getIntf(), "unknown layout id: %s", rData.m_layoutId.c_str() );
372 Bezier *pCurve = getPoints( rData.m_points.c_str() );
375 msg_Err( getIntf(), "invalid format in tag points=\"%s\"",
376 rData.m_points.c_str() );
379 m_pTheme->m_curves.push_back( BezierPtr( pCurve ) );
381 // Compute the position of the anchor
382 const Position pos = makePosition( rData.m_leftTop, rData.m_leftTop,
383 rData.m_xPos, rData.m_yPos,
385 pCurve->getHeight(), *pLayout );
387 Anchor *pAnc = new Anchor( getIntf(), pos, rData.m_range, rData.m_priority,
389 pLayout->addAnchor( pAnc );
393 void Builder::addButton( const BuilderData::Button &rData )
395 // Get the bitmaps of the button
396 GenericBitmap *pBmpUp = NULL;
397 GET_BMP( pBmpUp, rData.m_upId );
399 GenericBitmap *pBmpDown = pBmpUp;
400 GET_BMP( pBmpDown, rData.m_downId );
402 GenericBitmap *pBmpOver = pBmpUp;
403 GET_BMP( pBmpOver, rData.m_overId );
405 GenericLayout *pLayout = m_pTheme->getLayoutById( rData.m_layoutId );
406 if( pLayout == NULL )
408 msg_Err( getIntf(), "unknown layout id: %s", rData.m_layoutId.c_str() );
412 CmdGeneric *pCommand = parseAction( rData.m_actionId );
413 if( pCommand == NULL )
415 msg_Err( getIntf(), "invalid action: %s", rData.m_actionId.c_str() );
419 // Get the visibility variable
420 // XXX check when it is null
421 Interpreter *pInterpreter = Interpreter::instance( getIntf() );
422 VarBool *pVisible = pInterpreter->getVarBool( rData.m_visible, m_pTheme );
424 CtrlButton *pButton = new CtrlButton( getIntf(), *pBmpUp, *pBmpOver,
425 *pBmpDown, *pCommand, UString( getIntf(), rData.m_tooltip.c_str() ),
426 UString( getIntf(), rData.m_help.c_str() ), pVisible );
428 // Compute the position of the control
429 // XXX (we suppose all the images have the same size...)
430 const Position pos = makePosition( rData.m_leftTop, rData.m_rightBottom,
431 rData.m_xPos, rData.m_yPos,
433 pBmpUp->getHeight(), *pLayout,
434 rData.m_xKeepRatio, rData.m_yKeepRatio );
436 pLayout->addControl( pButton, pos, rData.m_layer );
438 m_pTheme->m_controls[rData.m_id] = CtrlGenericPtr( pButton );
442 void Builder::addCheckbox( const BuilderData::Checkbox &rData )
444 // Get the bitmaps of the checkbox
445 GenericBitmap *pBmpUp1 = NULL;
446 GET_BMP( pBmpUp1, rData.m_up1Id );
448 GenericBitmap *pBmpDown1 = pBmpUp1;
449 GET_BMP( pBmpDown1, rData.m_down1Id );
451 GenericBitmap *pBmpOver1 = pBmpUp1;
452 GET_BMP( pBmpOver1, rData.m_over1Id );
454 GenericBitmap *pBmpUp2 = NULL;
455 GET_BMP( pBmpUp2, rData.m_up2Id );
457 GenericBitmap *pBmpDown2 = pBmpUp2;
458 GET_BMP( pBmpDown2, rData.m_down2Id );
460 GenericBitmap *pBmpOver2 = pBmpUp2;
461 GET_BMP( pBmpOver2, rData.m_over2Id );
463 GenericLayout *pLayout = m_pTheme->getLayoutById( rData.m_layoutId );
464 if( pLayout == NULL )
466 msg_Err( getIntf(), "unknown layout id: %s", rData.m_layoutId.c_str() );
470 CmdGeneric *pCommand1 = parseAction( rData.m_action1 );
471 if( pCommand1 == NULL )
473 msg_Err( getIntf(), "invalid action: %s", rData.m_action1.c_str() );
477 CmdGeneric *pCommand2 = parseAction( rData.m_action2 );
478 if( pCommand2 == NULL )
480 msg_Err( getIntf(), "invalid action: %s", rData.m_action2.c_str() );
484 // Get the state variable
485 Interpreter *pInterpreter = Interpreter::instance( getIntf() );
486 VarBool *pVar = pInterpreter->getVarBool( rData.m_state, m_pTheme );
489 // TODO: default state
493 // Get the visibility variable
494 // XXX check when it is null
495 VarBool *pVisible = pInterpreter->getVarBool( rData.m_visible, m_pTheme );
497 // Create the control
498 CtrlCheckbox *pCheckbox = new CtrlCheckbox( getIntf(), *pBmpUp1,
499 *pBmpOver1, *pBmpDown1, *pBmpUp2, *pBmpOver2, *pBmpDown2, *pCommand1,
500 *pCommand2, UString( getIntf(), rData.m_tooltip1.c_str() ),
501 UString( getIntf(), rData.m_tooltip2.c_str() ), *pVar,
502 UString( getIntf(), rData.m_help.c_str() ), pVisible );
504 // Compute the position of the control
505 // XXX (we suppose all the images have the same size...)
506 const Position pos = makePosition( rData.m_leftTop, rData.m_rightBottom,
507 rData.m_xPos, rData.m_yPos,
509 pBmpUp1->getHeight(), *pLayout,
510 rData.m_xKeepRatio, rData.m_yKeepRatio );
512 pLayout->addControl( pCheckbox, pos, rData.m_layer );
514 m_pTheme->m_controls[rData.m_id] = CtrlGenericPtr( pCheckbox );
518 void Builder::addImage( const BuilderData::Image &rData )
520 GenericBitmap *pBmp = NULL;
521 GET_BMP( pBmp, rData.m_bmpId );
523 GenericLayout *pLayout = m_pTheme->getLayoutById( rData.m_layoutId );
524 if( pLayout == NULL )
526 msg_Err( getIntf(), "unknown layout id: %s", rData.m_layoutId.c_str() );
530 TopWindow *pWindow = m_pTheme->getWindowById( rData.m_windowId );
531 if( pWindow == NULL )
533 msg_Err( getIntf(), "unknown window id: %s", rData.m_windowId.c_str() );
537 CmdGeneric *pCommand = parseAction( rData.m_action2Id );
538 if( pCommand == NULL )
540 msg_Err( getIntf(), "invalid action: %s", rData.m_action2Id.c_str() );
544 // Get the visibility variable
545 // XXX check when it is null
546 Interpreter *pInterpreter = Interpreter::instance( getIntf() );
547 VarBool *pVisible = pInterpreter->getVarBool( rData.m_visible, m_pTheme );
549 CtrlImage::resize_t resizeMethod =
550 (rData.m_resize == "scale" ? CtrlImage::kScale : CtrlImage::kMosaic);
551 CtrlImage *pImage = new CtrlImage( getIntf(), *pBmp, *pCommand,
552 resizeMethod, UString( getIntf(), rData.m_help.c_str() ), pVisible );
554 // Compute the position of the control
555 const Position pos = makePosition( rData.m_leftTop, rData.m_rightBottom,
556 rData.m_xPos, rData.m_yPos,
557 pBmp->getWidth(), pBmp->getHeight(),
558 *pLayout, rData.m_xKeepRatio,
559 rData.m_yKeepRatio );
561 // XXX: test to be changed! XXX
562 if( rData.m_actionId == "move" )
564 CtrlMove *pMove = new CtrlMove( getIntf(), m_pTheme->getWindowManager(),
565 *pImage, *pWindow, UString( getIntf(), rData.m_help.c_str() ),
567 pLayout->addControl( pMove, pos, rData.m_layer );
569 else if( rData.m_actionId == "resizeS" )
571 CtrlResize *pResize = new CtrlResize( getIntf(),
572 m_pTheme->getWindowManager(), *pImage, *pLayout,
573 UString( getIntf(), rData.m_help.c_str() ), pVisible,
574 WindowManager::kResizeS );
575 pLayout->addControl( pResize, pos, rData.m_layer );
577 else if( rData.m_actionId == "resizeE" )
579 CtrlResize *pResize = new CtrlResize( getIntf(),
580 m_pTheme->getWindowManager(), *pImage, *pLayout,
581 UString( getIntf(), rData.m_help.c_str() ), pVisible,
582 WindowManager::kResizeE );
583 pLayout->addControl( pResize, pos, rData.m_layer );
585 else if( rData.m_actionId == "resizeSE" )
587 CtrlResize *pResize = new CtrlResize( getIntf(),
588 m_pTheme->getWindowManager(), *pImage, *pLayout,
589 UString( getIntf(), rData.m_help.c_str() ), pVisible,
590 WindowManager::kResizeSE );
591 pLayout->addControl( pResize, pos, rData.m_layer );
595 pLayout->addControl( pImage, pos, rData.m_layer );
598 m_pTheme->m_controls[rData.m_id] = CtrlGenericPtr( pImage );
602 void Builder::addText( const BuilderData::Text &rData )
604 GenericLayout *pLayout = m_pTheme->getLayoutById( rData.m_layoutId );
605 if( pLayout == NULL )
607 msg_Err( getIntf(), "unknown layout id: %s", rData.m_layoutId.c_str() );
611 GenericFont *pFont = getFont( rData.m_fontId );
614 msg_Err( getIntf(), "unknown font id: %s", rData.m_fontId.c_str() );
618 // Convert the scrolling mode
619 CtrlText::Scrolling_t scrolling;
620 if( rData.m_scrolling == "auto" )
621 scrolling = CtrlText::kAutomatic;
622 else if( rData.m_scrolling == "manual" )
623 scrolling = CtrlText::kManual;
624 else if( rData.m_scrolling == "none" )
625 scrolling = CtrlText::kNone;
628 msg_Err( getIntf(), "invalid scrolling mode: %s",
629 rData.m_scrolling.c_str() );
633 // Convert the alignment
634 CtrlText::Align_t alignment;
635 if( rData.m_alignment == "left" )
636 alignment = CtrlText::kLeft;
637 else if( rData.m_alignment == "center" || rData.m_alignment == "centre" )
638 alignment = CtrlText::kCenter;
639 else if( rData.m_alignment == "right" )
640 alignment = CtrlText::kRight;
643 msg_Err( getIntf(), "invalid alignment: %s",
644 rData.m_alignment.c_str() );
648 // Create a text variable
649 VarText *pVar = new VarText( getIntf() );
650 m_pTheme->m_vars.push_back( VariablePtr( pVar ) );
652 // Get the visibility variable
653 // XXX check when it is null
654 Interpreter *pInterpreter = Interpreter::instance( getIntf() );
655 VarBool *pVisible = pInterpreter->getVarBool( rData.m_visible, m_pTheme );
657 CtrlText *pText = new CtrlText( getIntf(), *pVar, *pFont,
658 UString( getIntf(), rData.m_help.c_str() ), rData.m_color, pVisible,
659 scrolling, alignment );
661 int height = pFont->getSize();
663 // Compute the position of the control
664 const Position pos = makePosition( rData.m_leftTop, rData.m_rightBottom,
665 rData.m_xPos, rData.m_yPos,
666 rData.m_width, height, *pLayout,
667 rData.m_xKeepRatio, rData.m_yKeepRatio );
669 pLayout->addControl( pText, pos, rData.m_layer );
671 // Set the text of the control
672 UString msg( getIntf(), rData.m_text.c_str() );
675 m_pTheme->m_controls[rData.m_id] = CtrlGenericPtr( pText );
679 void Builder::addRadialSlider( const BuilderData::RadialSlider &rData )
681 // Get the bitmaps of the slider
682 GenericBitmap *pSeq = NULL;
683 GET_BMP( pSeq, rData.m_sequence );
685 GenericLayout *pLayout = m_pTheme->getLayoutById( rData.m_layoutId );
686 if( pLayout == NULL )
688 msg_Err( getIntf(), "unknown layout id: %s", rData.m_layoutId.c_str() );
692 // Get the variable associated to the slider
693 Interpreter *pInterpreter = Interpreter::instance( getIntf() );
694 VarPercent *pVar = pInterpreter->getVarPercent( rData.m_value, m_pTheme );
697 msg_Err( getIntf(), "unknown slider value: %s", rData.m_value.c_str() );
701 // Get the visibility variable
702 // XXX check when it is null
703 VarBool *pVisible = pInterpreter->getVarBool( rData.m_visible, m_pTheme );
705 // Create the control
706 CtrlRadialSlider *pRadial =
707 new CtrlRadialSlider( getIntf(), *pSeq, rData.m_nbImages, *pVar,
708 rData.m_minAngle, rData.m_maxAngle,
709 UString( getIntf(), rData.m_help.c_str() ),
712 // XXX: resizing is not supported
713 // Compute the position of the control
714 const Position pos = makePosition( rData.m_leftTop, rData.m_rightBottom,
715 rData.m_xPos, rData.m_yPos,
717 pSeq->getHeight() / rData.m_nbImages,
719 rData.m_xKeepRatio, rData.m_yKeepRatio );
721 pLayout->addControl( pRadial, pos, rData.m_layer );
723 m_pTheme->m_controls[rData.m_id] = CtrlGenericPtr( pRadial );
727 void Builder::addSlider( const BuilderData::Slider &rData )
729 // Add the background first, so that we will still have something almost
730 // functional if the cursor cannot be created properly (this happens for
731 // some winamp2 skins, where the images of the cursor are not always
734 // Get the bitmaps of the background
735 GenericBitmap *pBgImage = NULL;
736 if( rData.m_imageId != "none" )
738 GET_BMP( pBgImage, rData.m_imageId );
741 GenericLayout *pLayout = m_pTheme->getLayoutById( rData.m_layoutId );
742 if( pLayout == NULL )
744 msg_Err( getIntf(), "unknown layout id: %s", rData.m_layoutId.c_str() );
748 Bezier *pCurve = getPoints( rData.m_points.c_str() );
751 msg_Err( getIntf(), "invalid format in tag points=\"%s\"",
752 rData.m_points.c_str() );
755 m_pTheme->m_curves.push_back( BezierPtr( pCurve ) );
757 // Get the visibility variable
758 // XXX check when it is null
759 Interpreter *pInterpreter = Interpreter::instance( getIntf() );
760 VarBool *pVisible = pInterpreter->getVarBool( rData.m_visible, m_pTheme );
762 // Get the variable associated to the slider
763 VarPercent *pVar = pInterpreter->getVarPercent( rData.m_value, m_pTheme );
766 msg_Err( getIntf(), "unknown slider value: %s", rData.m_value.c_str() );
770 // Create the background control
771 CtrlSliderBg *pBackground = new CtrlSliderBg( getIntf(),
772 *pCurve, *pVar, rData.m_thickness, pBgImage, rData.m_nbHoriz,
773 rData.m_nbVert, rData.m_padHoriz, rData.m_padVert,
774 pVisible, UString( getIntf(), rData.m_help.c_str() ) );
776 // Compute the position of the control
777 const Position pos = makePosition( rData.m_leftTop, rData.m_rightBottom,
778 rData.m_xPos, rData.m_yPos,
779 pCurve->getWidth(), pCurve->getHeight(),
781 rData.m_xKeepRatio, rData.m_yKeepRatio );
783 pLayout->addControl( pBackground, pos, rData.m_layer );
785 m_pTheme->m_controls[rData.m_id + "_bg"] = CtrlGenericPtr( pBackground );
787 // Get the bitmaps of the cursor
788 GenericBitmap *pBmpUp = NULL;
789 GET_BMP( pBmpUp, rData.m_upId );
791 GenericBitmap *pBmpDown = pBmpUp;
792 GET_BMP( pBmpDown, rData.m_downId );
794 GenericBitmap *pBmpOver = pBmpUp;
795 GET_BMP( pBmpOver, rData.m_overId );
797 // Create the cursor control
798 CtrlSliderCursor *pCursor = new CtrlSliderCursor( getIntf(), *pBmpUp,
799 *pBmpOver, *pBmpDown, *pCurve, *pVar, pVisible,
800 UString( getIntf(), rData.m_tooltip.c_str() ),
801 UString( getIntf(), rData.m_help.c_str() ) );
803 pLayout->addControl( pCursor, pos, rData.m_layer );
805 m_pTheme->m_controls[rData.m_id] = CtrlGenericPtr( pCursor );
807 // Associate the cursor to the background
808 pBackground->associateCursor( *pCursor );
812 void Builder::addList( const BuilderData::List &rData )
814 // Get the background bitmap, if any
815 GenericBitmap *pBgBmp = NULL;
816 GET_BMP( pBgBmp, rData.m_bgImageId );
818 GenericLayout *pLayout = m_pTheme->getLayoutById( rData.m_layoutId );
819 if( pLayout == NULL )
821 msg_Err( getIntf(), "unknown layout id: %s", rData.m_layoutId.c_str() );
825 GenericFont *pFont = getFont( rData.m_fontId );
828 msg_Err( getIntf(), "unknown font id: %s", rData.m_fontId.c_str() );
832 // Get the list variable
833 Interpreter *pInterpreter = Interpreter::instance( getIntf() );
834 VarList *pVar = pInterpreter->getVarList( rData.m_var, m_pTheme );
837 msg_Err( getIntf(), "no such list variable: %s", rData.m_var.c_str() );
841 // Get the visibility variable
842 // XXX check when it is null
843 VarBool *pVisible = pInterpreter->getVarBool( rData.m_visible, m_pTheme );
845 // Get the color values
846 uint32_t fgColor = getColor( rData.m_fgColor );
847 uint32_t playColor = getColor( rData.m_playColor );
848 uint32_t bgColor1 = getColor( rData.m_bgColor1 );
849 uint32_t bgColor2 = getColor( rData.m_bgColor2 );
850 uint32_t selColor = getColor( rData.m_selColor );
852 // Create the list control
853 CtrlList *pList = new CtrlList( getIntf(), *pVar, *pFont, pBgBmp,
854 fgColor, playColor, bgColor1, bgColor2, selColor,
855 UString( getIntf(), rData.m_help.c_str() ), pVisible );
857 // Compute the position of the control
858 const Position pos = makePosition( rData.m_leftTop, rData.m_rightBottom,
859 rData.m_xPos, rData.m_yPos,
860 rData.m_width, rData.m_height,
862 rData.m_xKeepRatio, rData.m_yKeepRatio );
864 pLayout->addControl( pList, pos, rData.m_layer );
866 m_pTheme->m_controls[rData.m_id] = CtrlGenericPtr( pList );
869 void Builder::addTree( const BuilderData::Tree &rData )
871 // Get the bitmaps, if any
872 GenericBitmap *pBgBmp = NULL;
873 GenericBitmap *pItemBmp = NULL;
874 GenericBitmap *pOpenBmp = NULL;
875 GenericBitmap *pClosedBmp = NULL;
876 GET_BMP( pBgBmp, rData.m_bgImageId );
877 GET_BMP( pItemBmp, rData.m_itemImageId );
878 GET_BMP( pOpenBmp, rData.m_openImageId );
879 GET_BMP( pClosedBmp, rData.m_closedImageId );
881 GenericLayout *pLayout = m_pTheme->getLayoutById( rData.m_layoutId );
882 if( pLayout == NULL )
884 msg_Err( getIntf(), "unknown layout id: %s", rData.m_layoutId.c_str() );
888 GenericFont *pFont = getFont( rData.m_fontId );
891 msg_Err( getIntf(), "unknown font id: %s", rData.m_fontId.c_str() );
895 // Get the list variable
896 Interpreter *pInterpreter = Interpreter::instance( getIntf() );
897 VarTree *pVar = pInterpreter->getVarTree( rData.m_var, m_pTheme );
900 msg_Err( getIntf(), "no such list variable: %s", rData.m_var.c_str() );
904 // Get the visibility variable
905 // XXX check when it is null
906 VarBool *pVisible = pInterpreter->getVarBool( rData.m_visible, m_pTheme );
907 VarBool *pFlat = pInterpreter->getVarBool( rData.m_flat, m_pTheme );
909 // Get the color values
910 uint32_t fgColor = getColor( rData.m_fgColor );
911 uint32_t playColor = getColor( rData.m_playColor );
912 uint32_t bgColor1 = getColor( rData.m_bgColor1 );
913 uint32_t bgColor2 = getColor( rData.m_bgColor2 );
914 uint32_t selColor = getColor( rData.m_selColor );
916 // Create the list control
917 CtrlTree *pTree = new CtrlTree( getIntf(), *pVar, *pFont, pBgBmp,
918 pItemBmp, pOpenBmp, pClosedBmp,
919 fgColor, playColor, bgColor1, bgColor2, selColor,
920 UString( getIntf(), rData.m_help.c_str() ), pVisible, pFlat );
922 // Compute the position of the control
923 const Position pos = makePosition( rData.m_leftTop, rData.m_rightBottom,
924 rData.m_xPos, rData.m_yPos,
925 rData.m_width, rData.m_height,
927 rData.m_xKeepRatio, rData.m_yKeepRatio );
929 pLayout->addControl( pTree, pos, rData.m_layer );
931 m_pTheme->m_controls[rData.m_id] = CtrlGenericPtr( pTree );
934 void Builder::addVideo( const BuilderData::Video &rData )
936 GenericLayout *pLayout = m_pTheme->getLayoutById( rData.m_layoutId );
937 if( pLayout == NULL )
939 msg_Err( getIntf(), "unknown layout id: %s", rData.m_layoutId.c_str() );
943 // Get the visibility variable
944 // XXX check when it is null
945 Interpreter *pInterpreter = Interpreter::instance( getIntf() );
946 VarBool *pVisible = pInterpreter->getVarBool( rData.m_visible, m_pTheme );
948 CtrlVideo *pVideo = new CtrlVideo( getIntf(), *pLayout,
949 rData.m_autoResize, UString( getIntf(), rData.m_help.c_str() ),
952 // Compute the position of the control
953 const Position pos = makePosition( rData.m_leftTop, rData.m_rightBottom,
954 rData.m_xPos, rData.m_yPos,
955 rData.m_width, rData.m_height,
957 rData.m_xKeepRatio, rData.m_yKeepRatio );
959 pLayout->addControl( pVideo, pos, rData.m_layer );
961 m_pTheme->m_controls[rData.m_id] = CtrlGenericPtr( pVideo );
965 const Position Builder::makePosition( const string &rLeftTop,
966 const string &rRightBottom,
967 int xPos, int yPos, int width,
968 int height, const Box &rBox,
969 bool xKeepRatio, bool yKeepRatio ) const
971 int left = 0, top = 0, right = 0, bottom = 0;
972 Position::Ref_t refLeftTop = Position::kLeftTop;
973 Position::Ref_t refRightBottom = Position::kLeftTop;
975 int boxWidth = rBox.getWidth();
976 int boxHeight = rBox.getHeight();
978 // Position of the left top corner
979 if( rLeftTop == "lefttop" )
983 refLeftTop = Position::kLeftTop;
985 else if( rLeftTop == "righttop" )
987 left = xPos - boxWidth + 1;
989 refLeftTop = Position::kRightTop;
991 else if( rLeftTop == "leftbottom" )
994 top = yPos - boxHeight + 1;
995 refLeftTop = Position::kLeftBottom;
997 else if( rLeftTop == "rightbottom" )
999 left = xPos - boxWidth + 1;
1000 top = yPos - boxHeight + 1;
1001 refLeftTop = Position::kRightBottom;
1004 // Position of the right bottom corner
1005 if( rRightBottom == "lefttop" )
1007 right = xPos + width - 1;
1008 bottom = yPos + height - 1;
1009 refRightBottom = Position::kLeftTop;
1011 else if( rRightBottom == "righttop" )
1013 right = xPos + width - boxWidth;
1014 bottom = yPos + height - 1;
1015 refRightBottom = Position::kRightTop;
1017 else if( rRightBottom == "leftbottom" )
1019 right = xPos + width - 1;
1020 bottom = yPos + height - boxHeight;
1021 refRightBottom = Position::kLeftBottom;
1023 else if( rRightBottom == "rightbottom" )
1025 right = xPos + width - boxWidth;
1026 bottom = yPos + height - boxHeight;
1027 refRightBottom = Position::kRightBottom;
1030 return Position( left, top, right, bottom, rBox, refLeftTop,
1031 refRightBottom, xKeepRatio, yKeepRatio );
1035 GenericFont *Builder::getFont( const string &fontId )
1037 GenericFont *pFont = m_pTheme->getFontById(fontId);
1038 if( !pFont && fontId == "defaultfont" )
1040 // Get the resource path and try to load the default font
1041 OSFactory *pOSFactory = OSFactory::instance( getIntf() );
1042 const list<string> &resPath = pOSFactory->getResourcePath();
1043 const string &sep = pOSFactory->getDirSeparator();
1045 list<string>::const_iterator it;
1046 for( it = resPath.begin(); it != resPath.end(); it++ )
1048 string path = (*it) + sep + "fonts" + sep + "FreeSans.ttf";
1049 pFont = new FT2Font( getIntf(), path, 12 );
1052 // Font loaded successfully
1053 m_pTheme->m_fonts["defaultfont"] = GenericFontPtr( pFont );
1064 msg_Err( getIntf(), "failed to open the default font" );
1071 string Builder::getFilePath( const string &rFileName ) const
1073 OSFactory *pFactory = OSFactory::instance( getIntf() );
1074 return m_path + pFactory->getDirSeparator() + sFromLocale( rFileName );
1079 Bezier *Builder::getPoints( const char *pTag ) const
1081 vector<float> xBez, yBez;
1085 if( sscanf( pTag, "(%d,%d)%n", &x, &y, &n ) < 1 )
1090 if( x < 0 || y < 0 )
1093 "Slider points cannot have negative coordinates!" );
1097 xBez.push_back( x );
1098 yBez.push_back( y );
1104 if( *(pTag++) != ',' )
1110 // Create the Bezier curve
1111 return new Bezier( getIntf(), xBez, yBez );
1115 uint32_t Builder::getColor( const string &rVal ) const
1117 // Check it the value is a registered constant
1118 Interpreter *pInterpreter = Interpreter::instance( getIntf() );
1119 string val = pInterpreter->getConstant( rVal );
1121 // Convert to an int value
1122 return SkinParser::convertColor( val.c_str() );