1 /*****************************************************************************
3 *****************************************************************************
4 * Copyright (C) 2003 the VideoLAN team
7 * Authors: Cyril Deguet <asmax@via.ecp.fr>
8 * Olivier Teulière <ipkiss@via.ecp.fr>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
23 *****************************************************************************/
26 #include "builder.hpp"
27 #include "builder_data.hpp"
28 #include "interpreter.hpp"
29 #include "../src/file_bitmap.hpp"
30 #include "../src/os_factory.hpp"
31 #include "../src/generic_bitmap.hpp"
32 #include "../src/top_window.hpp"
33 #include "../src/anchor.hpp"
34 #include "../src/bitmap_font.hpp"
35 #include "../src/ft2_font.hpp"
36 #include "../src/generic_layout.hpp"
37 #include "../src/popup.hpp"
38 #include "../src/theme.hpp"
39 #include "../commands/cmd_generic.hpp"
40 #include "../controls/ctrl_button.hpp"
41 #include "../controls/ctrl_checkbox.hpp"
42 #include "../controls/ctrl_image.hpp"
43 #include "../controls/ctrl_list.hpp"
44 #include "../controls/ctrl_move.hpp"
45 #include "../controls/ctrl_resize.hpp"
46 #include "../controls/ctrl_slider.hpp"
47 #include "../controls/ctrl_radialslider.hpp"
48 #include "../controls/ctrl_text.hpp"
49 #include "../controls/ctrl_tree.hpp"
50 #include "../controls/ctrl_video.hpp"
51 #include "../utils/bezier.hpp"
52 #include "../utils/position.hpp"
53 #include "../utils/var_bool.hpp"
54 #include "../utils/var_text.hpp"
56 #include "vlc_image.h"
59 Builder::Builder( intf_thread_t *pIntf, const BuilderData &rData,
60 const string &rPath ):
61 SkinObject( pIntf ), m_rData( rData ), m_path( rPath ), m_pTheme( NULL )
63 m_pImageHandler = image_HandlerCreate( pIntf );
68 if( m_pImageHandler ) image_HandlerDelete( m_pImageHandler );
71 CmdGeneric *Builder::parseAction( const string &rAction )
73 return Interpreter::instance( getIntf() )->parseAction( rAction, m_pTheme );
78 #define ADD_OBJECTS( type ) \
79 list<BuilderData::type>::const_iterator it##type; \
80 for( it##type = m_rData.m_list##type.begin(); \
81 it##type != m_rData.m_list##type.end(); it##type++ ) \
83 add##type( *it##type ); \
87 Theme *Builder::build()
89 m_pTheme = new Theme( getIntf() );
90 if( m_pTheme == NULL )
95 // Create everything from the data in the XML
97 ADD_OBJECTS( Bitmap );
98 ADD_OBJECTS( SubBitmap );
99 ADD_OBJECTS( BitmapFont );
101 ADD_OBJECTS( Window );
102 // XXX: PopupMenus are created after the windows, so that the Win32Factory
103 // (at least) can give a valid window handle to the OSPopup objects
104 ADD_OBJECTS( PopupMenu );
105 ADD_OBJECTS( Layout );
106 ADD_OBJECTS( Anchor );
107 ADD_OBJECTS( Button );
108 ADD_OBJECTS( Checkbox );
109 ADD_OBJECTS( Image );
111 ADD_OBJECTS( RadialSlider );
112 ADD_OBJECTS( Slider );
115 ADD_OBJECTS( Video );
116 // MenuItems must be created after all the rest, so that the IDs of the
117 // other elements exist and can be parsed in the actions
118 ADD_OBJECTS( MenuItem );
119 ADD_OBJECTS( MenuSeparator );
125 // Macro to get a bitmap by its ID in the builder
126 #define GET_BMP( pBmp, id ) \
129 pBmp = m_pTheme->getBitmapById(id); \
132 msg_Err( getIntf(), "unknown bitmap id: %s", id.c_str() ); \
137 void Builder::addTheme( const BuilderData::Theme &rData )
139 WindowManager &rManager = m_pTheme->getWindowManager();
140 rManager.setMagnetValue( rData.m_magnet );
141 rManager.setAlphaValue( rData.m_alpha );
142 rManager.setMoveAlphaValue( rData.m_moveAlpha );
143 GenericFont *pFont = getFont( rData.m_tooltipfont );
146 rManager.createTooltip( *pFont );
150 msg_Warn( getIntf(), "Invalid tooltip font: %s",
151 rData.m_tooltipfont.c_str() );
156 void Builder::addBitmap( const BuilderData::Bitmap &rData )
158 GenericBitmap *pBmp =
159 new FileBitmap( getIntf(), m_pImageHandler,
160 getFilePath( rData.m_fileName ), rData.m_alphaColor,
161 rData.m_nbFrames, rData.m_fps );
162 if( !pBmp->getData() )
168 m_pTheme->m_bitmaps[rData.m_id] = GenericBitmapPtr( pBmp );
172 void Builder::addSubBitmap( const BuilderData::SubBitmap &rData )
174 if( m_pTheme->m_bitmaps.find( rData.m_id ) != m_pTheme->m_bitmaps.end() )
176 msg_Dbg( getIntf(), "Bitmap %s already exists", rData.m_id.c_str() );
180 // Get the parent bitmap
181 GenericBitmap *pParentBmp = NULL;
182 GET_BMP( pParentBmp, rData.m_parent );
184 // Copy a region of the parent bitmap to the new one
186 new BitmapImpl( getIntf(), rData.m_width, rData.m_height,
187 rData.m_nbFrames, rData.m_fps );
188 bool res = pBmp->drawBitmap( *pParentBmp, rData.m_x, rData.m_y, 0, 0,
189 rData.m_width, rData.m_height );
192 // Invalid sub-bitmap
194 msg_Warn( getIntf(), "SubBitmap %s ignored", rData.m_id.c_str() );
197 m_pTheme->m_bitmaps[rData.m_id] = GenericBitmapPtr( pBmp );
201 void Builder::addBitmapFont( const BuilderData::BitmapFont &rData )
203 if( m_pTheme->m_fonts.find( rData.m_id ) != m_pTheme->m_fonts.end() )
205 msg_Dbg( getIntf(), "Font %s already exists", rData.m_id.c_str() );
209 GenericBitmap *pBmp =
210 new FileBitmap( getIntf(), m_pImageHandler,
211 getFilePath( rData.m_file ), 0 );
212 if( !pBmp->getData() )
219 m_pTheme->m_bitmaps[rData.m_id] = GenericBitmapPtr( pBmp );
221 GenericFont *pFont = new BitmapFont( getIntf(), *pBmp, rData.m_type );
224 m_pTheme->m_fonts[rData.m_id] = GenericFontPtr( pFont );
233 void Builder::addFont( const BuilderData::Font &rData )
235 // Try to load the font from the theme directory
236 GenericFont *pFont = new FT2Font( getIntf(),
237 getFilePath( rData.m_fontFile ),
241 m_pTheme->m_fonts[rData.m_id] = GenericFontPtr( pFont );
247 // Font not found; try in the resource path
248 OSFactory *pOSFactory = OSFactory::instance( getIntf() );
249 const list<string> &resPath = pOSFactory->getResourcePath();
250 const string &sep = pOSFactory->getDirSeparator();
252 list<string>::const_iterator it;
253 for( it = resPath.begin(); it != resPath.end(); it++ )
255 string path = (*it) + sep + "fonts" + sep + rData.m_fontFile;
256 pFont = new FT2Font( getIntf(), path, rData.m_size );
259 // Font loaded successfully
260 m_pTheme->m_fonts[rData.m_id] = GenericFontPtr( pFont );
272 void Builder::addPopupMenu( const BuilderData::PopupMenu &rData )
274 Popup *pPopup = new Popup( getIntf(), m_pTheme->getWindowManager() );
276 m_pTheme->m_popups[rData.m_id] = PopupPtr( pPopup );
280 void Builder::addMenuItem( const BuilderData::MenuItem &rData )
282 Popup *pPopup = m_pTheme->getPopupById( rData.m_popupId );
285 msg_Err( getIntf(), "Unknown popup id: %s", rData.m_popupId.c_str() );
289 CmdGeneric *pCommand = parseAction( rData.m_action );
290 if( pCommand == NULL )
292 msg_Err( getIntf(), "Invalid action: %s", rData.m_action.c_str() );
296 pPopup->addItem( rData.m_label, *pCommand, rData.m_pos );
300 void Builder::addMenuSeparator( const BuilderData::MenuSeparator &rData )
302 Popup *pPopup = m_pTheme->getPopupById( rData.m_popupId );
305 msg_Err( getIntf(), "Unknown popup id: %s", rData.m_popupId.c_str() );
309 pPopup->addSeparator( rData.m_pos );
313 void Builder::addWindow( const BuilderData::Window &rData )
316 new TopWindow( getIntf(), rData.m_xPos, rData.m_yPos,
317 m_pTheme->getWindowManager(),
318 rData.m_dragDrop, rData.m_playOnDrop,
321 m_pTheme->m_windows[rData.m_id] = TopWindowPtr( pWin );
325 void Builder::addLayout( const BuilderData::Layout &rData )
327 TopWindow *pWin = m_pTheme->getWindowById( rData.m_windowId );
330 msg_Err( getIntf(), "unknown window id: %s", rData.m_windowId.c_str() );
334 int minWidth = rData.m_minWidth != -1 ? rData.m_minWidth : rData.m_width;
335 int maxWidth = rData.m_maxWidth != -1 ? rData.m_maxWidth : rData.m_width;
336 int minHeight = rData.m_minHeight != -1 ? rData.m_minHeight :
338 int maxHeight = rData.m_maxHeight != -1 ? rData.m_maxHeight :
340 GenericLayout *pLayout = new GenericLayout( getIntf(), rData.m_width,
342 minWidth, maxWidth, minHeight,
344 m_pTheme->m_layouts[rData.m_id] = GenericLayoutPtr( pLayout );
346 // Attach the layout to its window
347 m_pTheme->getWindowManager().addLayout( *pWin, *pLayout );
351 void Builder::addAnchor( const BuilderData::Anchor &rData )
353 GenericLayout *pLayout = m_pTheme->getLayoutById( rData.m_layoutId );
354 if( pLayout == NULL )
356 msg_Err( getIntf(), "unknown layout id: %s", rData.m_layoutId.c_str() );
360 Bezier *pCurve = getPoints( rData.m_points.c_str() );
363 msg_Err( getIntf(), "Invalid format in tag points=\"%s\"",
364 rData.m_points.c_str() );
367 m_pTheme->m_curves.push_back( BezierPtr( pCurve ) );
369 Anchor *pAnc = new Anchor( getIntf(), rData.m_xPos, rData.m_yPos,
370 rData.m_range, rData.m_priority,
372 pLayout->addAnchor( pAnc );
376 void Builder::addButton( const BuilderData::Button &rData )
378 // Get the bitmaps of the button
379 GenericBitmap *pBmpUp = NULL;
380 GET_BMP( pBmpUp, rData.m_upId );
382 GenericBitmap *pBmpDown = pBmpUp;
383 GET_BMP( pBmpDown, rData.m_downId );
385 GenericBitmap *pBmpOver = pBmpUp;
386 GET_BMP( pBmpOver, rData.m_overId );
388 GenericLayout *pLayout = m_pTheme->getLayoutById( rData.m_layoutId );
389 if( pLayout == NULL )
391 msg_Err( getIntf(), "unknown layout id: %s", rData.m_layoutId.c_str() );
395 CmdGeneric *pCommand = parseAction( rData.m_actionId );
396 if( pCommand == NULL )
398 msg_Err( getIntf(), "Invalid action: %s", rData.m_actionId.c_str() );
402 // Get the visibility variable
403 // XXX check when it is null
404 Interpreter *pInterpreter = Interpreter::instance( getIntf() );
405 VarBool *pVisible = pInterpreter->getVarBool( rData.m_visible, m_pTheme );
407 CtrlButton *pButton = new CtrlButton( getIntf(), *pBmpUp, *pBmpOver,
408 *pBmpDown, *pCommand, UString( getIntf(), rData.m_tooltip.c_str() ),
409 UString( getIntf(), rData.m_help.c_str() ), pVisible );
411 // Compute the position of the control
412 // XXX (we suppose all the images have the same size...)
413 const Position pos = makePosition( rData.m_leftTop, rData.m_rightBottom,
414 rData.m_xPos, rData.m_yPos,
416 pBmpUp->getHeight(), *pLayout );
418 pLayout->addControl( pButton, pos, rData.m_layer );
420 m_pTheme->m_controls[rData.m_id] = CtrlGenericPtr( pButton );
424 void Builder::addCheckbox( const BuilderData::Checkbox &rData )
426 // Get the bitmaps of the checkbox
427 GenericBitmap *pBmpUp1 = NULL;
428 GET_BMP( pBmpUp1, rData.m_up1Id );
430 GenericBitmap *pBmpDown1 = pBmpUp1;
431 GET_BMP( pBmpDown1, rData.m_down1Id );
433 GenericBitmap *pBmpOver1 = pBmpUp1;
434 GET_BMP( pBmpOver1, rData.m_over1Id );
436 GenericBitmap *pBmpUp2 = NULL;
437 GET_BMP( pBmpUp2, rData.m_up2Id );
439 GenericBitmap *pBmpDown2 = pBmpUp2;
440 GET_BMP( pBmpDown2, rData.m_down2Id );
442 GenericBitmap *pBmpOver2 = pBmpUp2;
443 GET_BMP( pBmpOver2, rData.m_over2Id );
445 GenericLayout *pLayout = m_pTheme->getLayoutById( rData.m_layoutId );
446 if( pLayout == NULL )
448 msg_Err( getIntf(), "unknown layout id: %s", rData.m_layoutId.c_str() );
452 CmdGeneric *pCommand1 = parseAction( rData.m_action1 );
453 if( pCommand1 == NULL )
455 msg_Err( getIntf(), "Invalid action: %s", rData.m_action1.c_str() );
459 CmdGeneric *pCommand2 = parseAction( rData.m_action2 );
460 if( pCommand2 == NULL )
462 msg_Err( getIntf(), "Invalid action: %s", rData.m_action2.c_str() );
466 // Get the state variable
467 Interpreter *pInterpreter = Interpreter::instance( getIntf() );
468 VarBool *pVar = pInterpreter->getVarBool( rData.m_state, m_pTheme );
471 // TODO: default state
475 // Get the visibility variable
476 // XXX check when it is null
477 VarBool *pVisible = pInterpreter->getVarBool( rData.m_visible, m_pTheme );
479 // Create the control
480 CtrlCheckbox *pCheckbox = new CtrlCheckbox( getIntf(), *pBmpUp1,
481 *pBmpOver1, *pBmpDown1, *pBmpUp2, *pBmpOver2, *pBmpDown2, *pCommand1,
482 *pCommand2, UString( getIntf(), rData.m_tooltip1.c_str() ),
483 UString( getIntf(), rData.m_tooltip2.c_str() ), *pVar,
484 UString( getIntf(), rData.m_help.c_str() ), pVisible );
486 // Compute the position of the control
487 // XXX (we suppose all the images have the same size...)
488 const Position pos = makePosition( rData.m_leftTop, rData.m_rightBottom,
489 rData.m_xPos, rData.m_yPos,
491 pBmpUp1->getHeight(), *pLayout );
493 pLayout->addControl( pCheckbox, pos, rData.m_layer );
495 m_pTheme->m_controls[rData.m_id] = CtrlGenericPtr( pCheckbox );
499 void Builder::addImage( const BuilderData::Image &rData )
501 GenericBitmap *pBmp = NULL;
502 GET_BMP( pBmp, rData.m_bmpId );
504 GenericLayout *pLayout = m_pTheme->getLayoutById( rData.m_layoutId );
505 if( pLayout == NULL )
507 msg_Err( getIntf(), "unknown layout id: %s", rData.m_layoutId.c_str() );
511 TopWindow *pWindow = m_pTheme->getWindowById( rData.m_windowId );
512 if( pWindow == NULL )
514 msg_Err( getIntf(), "unknown window id: %s", rData.m_windowId.c_str() );
518 CmdGeneric *pCommand = parseAction( rData.m_action2Id );
519 if( pCommand == NULL )
521 msg_Err( getIntf(), "Invalid action: %s", rData.m_action2Id.c_str() );
525 // Get the visibility variable
526 // XXX check when it is null
527 Interpreter *pInterpreter = Interpreter::instance( getIntf() );
528 VarBool *pVisible = pInterpreter->getVarBool( rData.m_visible, m_pTheme );
530 CtrlImage::resize_t resizeMethod =
531 (rData.m_resize == "scale" ? CtrlImage::kScale : CtrlImage::kMosaic);
532 CtrlImage *pImage = new CtrlImage( getIntf(), *pBmp, *pCommand,
533 resizeMethod, UString( getIntf(), rData.m_help.c_str() ), pVisible );
535 // Compute the position of the control
536 const Position pos = makePosition( rData.m_leftTop, rData.m_rightBottom,
538 rData.m_yPos, pBmp->getWidth(),
539 pBmp->getHeight(), *pLayout );
541 // XXX: test to be changed! XXX
542 if( rData.m_actionId == "move" )
544 CtrlMove *pMove = new CtrlMove( getIntf(), m_pTheme->getWindowManager(),
545 *pImage, *pWindow, UString( getIntf(), rData.m_help.c_str() ),
547 pLayout->addControl( pMove, pos, rData.m_layer );
549 else if( rData.m_actionId == "resizeS" )
551 CtrlResize *pResize = new CtrlResize( getIntf(), *pImage, *pLayout,
552 UString( getIntf(), rData.m_help.c_str() ), NULL,
553 CtrlResize::kResizeS );
554 pLayout->addControl( pResize, pos, rData.m_layer );
556 else if( rData.m_actionId == "resizeE" )
558 CtrlResize *pResize = new CtrlResize( getIntf(), *pImage, *pLayout,
559 UString( getIntf(), rData.m_help.c_str() ), NULL,
560 CtrlResize::kResizeE );
561 pLayout->addControl( pResize, pos, rData.m_layer );
563 else if( rData.m_actionId == "resizeSE" )
565 CtrlResize *pResize = new CtrlResize( getIntf(), *pImage, *pLayout,
566 UString( getIntf(), rData.m_help.c_str() ), NULL,
567 CtrlResize::kResizeSE );
568 pLayout->addControl( pResize, pos, rData.m_layer );
572 pLayout->addControl( pImage, pos, rData.m_layer );
575 m_pTheme->m_controls[rData.m_id] = CtrlGenericPtr( pImage );
579 void Builder::addText( const BuilderData::Text &rData )
581 GenericLayout *pLayout = m_pTheme->getLayoutById( rData.m_layoutId );
582 if( pLayout == NULL )
584 msg_Err( getIntf(), "unknown layout id: %s", rData.m_layoutId.c_str() );
588 GenericFont *pFont = getFont( rData.m_fontId );
591 msg_Err( getIntf(), "Unknown font id: %s", rData.m_fontId.c_str() );
595 // Convert the scrolling mode
596 CtrlText::Scrolling_t scrolling;
597 if( rData.m_scrolling == "auto" )
598 scrolling = CtrlText::kAutomatic;
599 else if( rData.m_scrolling == "manual" )
600 scrolling = CtrlText::kManual;
601 else if( rData.m_scrolling == "none" )
602 scrolling = CtrlText::kNone;
605 msg_Err( getIntf(), "Invalid scrolling mode: %s",
606 rData.m_scrolling.c_str() );
610 // Convert the alignment
611 CtrlText::Align_t alignment;
612 if( rData.m_alignment == "left" )
613 alignment = CtrlText::kLeft;
614 else if( rData.m_alignment == "center" || rData.m_alignment == "centre" )
615 alignment = CtrlText::kCenter;
616 else if( rData.m_alignment == "right" )
617 alignment = CtrlText::kRight;
620 msg_Err( getIntf(), "Invalid alignment: %s",
621 rData.m_alignment.c_str() );
625 // Create a text variable
626 VarText *pVar = new VarText( getIntf() );
627 m_pTheme->m_vars.push_back( VariablePtr( pVar ) );
629 // Get the visibility variable
630 // XXX check when it is null
631 Interpreter *pInterpreter = Interpreter::instance( getIntf() );
632 VarBool *pVisible = pInterpreter->getVarBool( rData.m_visible, m_pTheme );
634 CtrlText *pText = new CtrlText( getIntf(), *pVar, *pFont,
635 UString( getIntf(), rData.m_help.c_str() ), rData.m_color, pVisible,
636 scrolling, alignment );
638 int height = pFont->getSize();
640 // Compute the position of the control
641 const Position pos = makePosition( rData.m_leftTop, rData.m_rightBottom,
642 rData.m_xPos, rData.m_yPos,
643 rData.m_width, height,
646 pLayout->addControl( pText, pos, rData.m_layer );
648 // Set the text of the control
649 UString msg( getIntf(), rData.m_text.c_str() );
652 m_pTheme->m_controls[rData.m_id] = CtrlGenericPtr( pText );
656 void Builder::addRadialSlider( const BuilderData::RadialSlider &rData )
658 // Get the bitmaps of the slider
659 GenericBitmap *pSeq = NULL;
660 GET_BMP( pSeq, rData.m_sequence );
662 GenericLayout *pLayout = m_pTheme->getLayoutById( rData.m_layoutId );
663 if( pLayout == NULL )
665 msg_Err( getIntf(), "unknown layout id: %s", rData.m_layoutId.c_str() );
669 // Get the variable associated to the slider
670 Interpreter *pInterpreter = Interpreter::instance( getIntf() );
671 VarPercent *pVar = pInterpreter->getVarPercent( rData.m_value, m_pTheme );
674 msg_Err( getIntf(), "Unknown slider value: %s", rData.m_value.c_str() );
678 // Get the visibility variable
679 // XXX check when it is null
680 VarBool *pVisible = pInterpreter->getVarBool( rData.m_visible, m_pTheme );
682 // Create the control
683 CtrlRadialSlider *pRadial =
684 new CtrlRadialSlider( getIntf(), *pSeq, rData.m_nbImages, *pVar,
685 rData.m_minAngle, rData.m_maxAngle,
686 UString( getIntf(), rData.m_help.c_str() ),
689 // XXX: resizing is not supported
690 // Compute the position of the control
692 makePosition( rData.m_leftTop, rData.m_rightBottom, rData.m_xPos,
693 rData.m_yPos, pSeq->getWidth(),
694 pSeq->getHeight() / rData.m_nbImages, *pLayout );
696 pLayout->addControl( pRadial, pos, rData.m_layer );
698 m_pTheme->m_controls[rData.m_id] = CtrlGenericPtr( pRadial );
702 void Builder::addSlider( const BuilderData::Slider &rData )
704 // Add the background first, so that we will still have something almost
705 // functional if the cursor cannot be created properly (this happens for
706 // some winamp2 skins, where the images of the cursor are not always
709 // Get the bitmaps of the background
710 GenericBitmap *pBgImage = NULL;
711 if( rData.m_imageId != "none" )
713 GET_BMP( pBgImage, rData.m_imageId );
716 GenericLayout *pLayout = m_pTheme->getLayoutById( rData.m_layoutId );
717 if( pLayout == NULL )
719 msg_Err( getIntf(), "unknown layout id: %s", rData.m_layoutId.c_str() );
723 Bezier *pCurve = getPoints( rData.m_points.c_str() );
726 msg_Err( getIntf(), "Invalid format in tag points=\"%s\"",
727 rData.m_points.c_str() );
730 m_pTheme->m_curves.push_back( BezierPtr( pCurve ) );
732 // Get the visibility variable
733 // XXX check when it is null
734 Interpreter *pInterpreter = Interpreter::instance( getIntf() );
735 VarBool *pVisible = pInterpreter->getVarBool( rData.m_visible, m_pTheme );
737 // Get the variable associated to the slider
738 VarPercent *pVar = pInterpreter->getVarPercent( rData.m_value, m_pTheme );
741 msg_Err( getIntf(), "Unknown slider value: %s", rData.m_value.c_str() );
745 // Create the background control
746 CtrlSliderBg *pBackground = new CtrlSliderBg( getIntf(),
747 *pCurve, *pVar, rData.m_thickness, pBgImage, rData.m_nbHoriz,
748 rData.m_nbVert, rData.m_padHoriz, rData.m_padVert,
749 pVisible, UString( getIntf(), rData.m_help.c_str() ) );
751 // Compute the position of the control
752 const Position pos = makePosition( rData.m_leftTop, rData.m_rightBottom,
753 rData.m_xPos, rData.m_yPos,
754 pCurve->getWidth(), pCurve->getHeight(),
757 pLayout->addControl( pBackground, pos, rData.m_layer );
759 m_pTheme->m_controls[rData.m_id + "_bg"] = CtrlGenericPtr( pBackground );
761 // Get the bitmaps of the cursor
762 GenericBitmap *pBmpUp = NULL;
763 GET_BMP( pBmpUp, rData.m_upId );
765 GenericBitmap *pBmpDown = pBmpUp;
766 GET_BMP( pBmpDown, rData.m_downId );
768 GenericBitmap *pBmpOver = pBmpUp;
769 GET_BMP( pBmpOver, rData.m_overId );
771 // Create the cursor control
772 CtrlSliderCursor *pCursor = new CtrlSliderCursor( getIntf(), *pBmpUp,
773 *pBmpOver, *pBmpDown, *pCurve, *pVar, pVisible,
774 UString( getIntf(), rData.m_tooltip.c_str() ),
775 UString( getIntf(), rData.m_help.c_str() ) );
777 pLayout->addControl( pCursor, pos, rData.m_layer );
779 m_pTheme->m_controls[rData.m_id] = CtrlGenericPtr( pCursor );
781 // Associate the cursor to the background
782 pBackground->associateCursor( *pCursor );
786 void Builder::addList( const BuilderData::List &rData )
788 // Get the background bitmap, if any
789 GenericBitmap *pBgBmp = NULL;
790 GET_BMP( pBgBmp, rData.m_bgImageId );
792 GenericLayout *pLayout = m_pTheme->getLayoutById( rData.m_layoutId );
793 if( pLayout == NULL )
795 msg_Err( getIntf(), "unknown layout id: %s", rData.m_layoutId.c_str() );
799 GenericFont *pFont = getFont( rData.m_fontId );
802 msg_Err( getIntf(), "Unknown font id: %s", rData.m_fontId.c_str() );
806 // Get the list variable
807 Interpreter *pInterpreter = Interpreter::instance( getIntf() );
808 VarList *pVar = pInterpreter->getVarList( rData.m_var, m_pTheme );
811 msg_Err( getIntf(), "No such list variable: %s", rData.m_var.c_str() );
815 // Get the visibility variable
816 // XXX check when it is null
817 VarBool *pVisible = pInterpreter->getVarBool( rData.m_visible, m_pTheme );
819 // Create the list control
820 CtrlList *pList = new CtrlList( getIntf(), *pVar, *pFont, pBgBmp,
821 rData.m_fgColor, rData.m_playColor, rData.m_bgColor1,
822 rData.m_bgColor2, rData.m_selColor,
823 UString( getIntf(), rData.m_help.c_str() ), pVisible );
825 // Compute the position of the control
826 const Position pos = makePosition( rData.m_leftTop, rData.m_rightBottom,
827 rData.m_xPos, rData.m_yPos,
828 rData.m_width, rData.m_height,
831 pLayout->addControl( pList, pos, rData.m_layer );
833 m_pTheme->m_controls[rData.m_id] = CtrlGenericPtr( pList );
836 void Builder::addTree( const BuilderData::Tree &rData )
838 // Get the bitmaps, if any
839 GenericBitmap *pBgBmp = NULL;
840 GenericBitmap *pItemBmp = NULL;
841 GenericBitmap *pOpenBmp = NULL;
842 GenericBitmap *pClosedBmp = NULL;
843 GET_BMP( pBgBmp, rData.m_bgImageId );
844 GET_BMP( pItemBmp, rData.m_itemImageId );
845 GET_BMP( pOpenBmp, rData.m_openImageId );
846 GET_BMP( pClosedBmp, rData.m_closedImageId );
848 GenericLayout *pLayout = m_pTheme->getLayoutById( rData.m_layoutId );
849 if( pLayout == NULL )
851 msg_Err( getIntf(), "unknown layout id: %s", rData.m_layoutId.c_str() );
855 GenericFont *pFont = getFont( rData.m_fontId );
858 msg_Err( getIntf(), "Unknown font id: %s", rData.m_fontId.c_str() );
862 // Get the list variable
863 Interpreter *pInterpreter = Interpreter::instance( getIntf() );
864 VarTree *pVar = pInterpreter->getVarTree( rData.m_var, m_pTheme );
867 msg_Err( getIntf(), "No such list variable: %s", rData.m_var.c_str() );
871 // Get the visibility variable
872 // XXX check when it is null
873 VarBool *pVisible = pInterpreter->getVarBool( rData.m_visible, m_pTheme );
875 // Create the list control
876 CtrlTree *pTree = new CtrlTree( getIntf(), *pVar, *pFont, pBgBmp,
877 pItemBmp, pOpenBmp, pClosedBmp,
878 rData.m_fgColor, rData.m_playColor, rData.m_bgColor1,
879 rData.m_bgColor2, rData.m_selColor,
880 UString( getIntf(), rData.m_help.c_str() ), pVisible );
882 // Compute the position of the control
883 const Position pos = makePosition( rData.m_leftTop, rData.m_rightBottom,
884 rData.m_xPos, rData.m_yPos,
885 rData.m_width, rData.m_height,
888 pLayout->addControl( pTree, pos, rData.m_layer );
890 m_pTheme->m_controls[rData.m_id] = CtrlGenericPtr( pTree );
893 void Builder::addVideo( const BuilderData::Video &rData )
895 GenericLayout *pLayout = m_pTheme->getLayoutById( rData.m_layoutId );
896 if( pLayout == NULL )
898 msg_Err( getIntf(), "unknown layout id: %s", rData.m_layoutId.c_str() );
902 // Get the visibility variable
903 // XXX check when it is null
904 Interpreter *pInterpreter = Interpreter::instance( getIntf() );
905 VarBool *pVisible = pInterpreter->getVarBool( rData.m_visible, m_pTheme );
907 CtrlVideo *pVideo = new CtrlVideo( getIntf(), *pLayout,
908 rData.m_autoResize, UString( getIntf(), rData.m_help.c_str() ),
911 // Compute the position of the control
912 const Position pos = makePosition( rData.m_leftTop, rData.m_rightBottom,
913 rData.m_xPos, rData.m_yPos,
914 rData.m_width, rData.m_height,
917 pLayout->addControl( pVideo, pos, rData.m_layer );
919 m_pTheme->m_controls[rData.m_id] = CtrlGenericPtr( pVideo );
923 const Position Builder::makePosition( const string &rLeftTop,
924 const string &rRightBottom,
925 int xPos, int yPos, int width,
926 int height, const Box &rBox ) const
928 int left = 0, top = 0, right = 0, bottom = 0;
929 Position::Ref_t refLeftTop = Position::kLeftTop;
930 Position::Ref_t refRightBottom = Position::kLeftTop;
932 int boxWidth = rBox.getWidth();
933 int boxHeight = rBox.getHeight();
935 // Position of the left top corner
936 if( rLeftTop == "lefttop" )
940 refLeftTop = Position::kLeftTop;
942 else if( rLeftTop == "righttop" )
944 left = xPos - boxWidth + 1;
946 refLeftTop = Position::kRightTop;
948 else if( rLeftTop == "leftbottom" )
951 top = yPos - boxHeight + 1;
952 refLeftTop = Position::kLeftBottom;
954 else if( rLeftTop == "rightbottom" )
956 left = xPos - boxWidth + 1;
957 top = yPos - boxHeight + 1;
958 refLeftTop = Position::kRightBottom;
961 // Position of the right bottom corner
962 if( rRightBottom == "lefttop" )
964 right = xPos + width - 1;
965 bottom = yPos + height - 1;
966 refRightBottom = Position::kLeftTop;
968 else if( rRightBottom == "righttop" )
970 right = xPos + width - boxWidth;
971 bottom = yPos + height - 1;
972 refRightBottom = Position::kRightTop;
974 else if( rRightBottom == "leftbottom" )
976 right = xPos + width - 1;
977 bottom = yPos + height - boxHeight;
978 refRightBottom = Position::kLeftBottom;
980 else if( rRightBottom == "rightbottom" )
982 right = xPos + width - boxWidth;
983 bottom = yPos + height - boxHeight;
984 refRightBottom = Position::kRightBottom;
987 return Position( left, top, right, bottom, rBox, refLeftTop,
992 GenericFont *Builder::getFont( const string &fontId )
994 GenericFont *pFont = m_pTheme->getFontById(fontId);
995 if( !pFont && fontId == "defaultfont" )
997 // Get the resource path and try to load the default font
998 OSFactory *pOSFactory = OSFactory::instance( getIntf() );
999 const list<string> &resPath = pOSFactory->getResourcePath();
1000 const string &sep = pOSFactory->getDirSeparator();
1002 list<string>::const_iterator it;
1003 for( it = resPath.begin(); it != resPath.end(); it++ )
1005 string path = (*it) + sep + "fonts" + sep + "FreeSans.ttf";
1006 pFont = new FT2Font( getIntf(), path, 12 );
1009 // Font loaded successfully
1010 m_pTheme->m_fonts["defaultfont"] = GenericFontPtr( pFont );
1021 msg_Err( getIntf(), "Failed to open the default font" );
1028 string Builder::getFilePath( const string &rFileName ) const
1030 OSFactory *pFactory = OSFactory::instance( getIntf() );
1031 return m_path + pFactory->getDirSeparator() + rFileName;
1036 Bezier *Builder::getPoints( const char *pTag ) const
1038 vector<float> xBez, yBez;
1042 if( sscanf( pTag, "(%d,%d)%n", &x, &y, &n ) < 1 )
1047 if( x < 0 || y < 0 )
1050 "Slider points cannot have negative coordinates!" );
1054 xBez.push_back( x );
1055 yBez.push_back( y );
1061 if( *(pTag++) != ',' )
1067 // Create the Bezier curve
1068 return new Bezier( getIntf(), xBez, yBez );