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 );
435 pLayout->addControl( pButton, pos, rData.m_layer );
437 m_pTheme->m_controls[rData.m_id] = CtrlGenericPtr( pButton );
441 void Builder::addCheckbox( const BuilderData::Checkbox &rData )
443 // Get the bitmaps of the checkbox
444 GenericBitmap *pBmpUp1 = NULL;
445 GET_BMP( pBmpUp1, rData.m_up1Id );
447 GenericBitmap *pBmpDown1 = pBmpUp1;
448 GET_BMP( pBmpDown1, rData.m_down1Id );
450 GenericBitmap *pBmpOver1 = pBmpUp1;
451 GET_BMP( pBmpOver1, rData.m_over1Id );
453 GenericBitmap *pBmpUp2 = NULL;
454 GET_BMP( pBmpUp2, rData.m_up2Id );
456 GenericBitmap *pBmpDown2 = pBmpUp2;
457 GET_BMP( pBmpDown2, rData.m_down2Id );
459 GenericBitmap *pBmpOver2 = pBmpUp2;
460 GET_BMP( pBmpOver2, rData.m_over2Id );
462 GenericLayout *pLayout = m_pTheme->getLayoutById( rData.m_layoutId );
463 if( pLayout == NULL )
465 msg_Err( getIntf(), "unknown layout id: %s", rData.m_layoutId.c_str() );
469 CmdGeneric *pCommand1 = parseAction( rData.m_action1 );
470 if( pCommand1 == NULL )
472 msg_Err( getIntf(), "invalid action: %s", rData.m_action1.c_str() );
476 CmdGeneric *pCommand2 = parseAction( rData.m_action2 );
477 if( pCommand2 == NULL )
479 msg_Err( getIntf(), "invalid action: %s", rData.m_action2.c_str() );
483 // Get the state variable
484 Interpreter *pInterpreter = Interpreter::instance( getIntf() );
485 VarBool *pVar = pInterpreter->getVarBool( rData.m_state, m_pTheme );
488 // TODO: default state
492 // Get the visibility variable
493 // XXX check when it is null
494 VarBool *pVisible = pInterpreter->getVarBool( rData.m_visible, m_pTheme );
496 // Create the control
497 CtrlCheckbox *pCheckbox = new CtrlCheckbox( getIntf(), *pBmpUp1,
498 *pBmpOver1, *pBmpDown1, *pBmpUp2, *pBmpOver2, *pBmpDown2, *pCommand1,
499 *pCommand2, UString( getIntf(), rData.m_tooltip1.c_str() ),
500 UString( getIntf(), rData.m_tooltip2.c_str() ), *pVar,
501 UString( getIntf(), rData.m_help.c_str() ), pVisible );
503 // Compute the position of the control
504 // XXX (we suppose all the images have the same size...)
505 const Position pos = makePosition( rData.m_leftTop, rData.m_rightBottom,
506 rData.m_xPos, rData.m_yPos,
508 pBmpUp1->getHeight(), *pLayout );
510 pLayout->addControl( pCheckbox, pos, rData.m_layer );
512 m_pTheme->m_controls[rData.m_id] = CtrlGenericPtr( pCheckbox );
516 void Builder::addImage( const BuilderData::Image &rData )
518 GenericBitmap *pBmp = NULL;
519 GET_BMP( pBmp, rData.m_bmpId );
521 GenericLayout *pLayout = m_pTheme->getLayoutById( rData.m_layoutId );
522 if( pLayout == NULL )
524 msg_Err( getIntf(), "unknown layout id: %s", rData.m_layoutId.c_str() );
528 TopWindow *pWindow = m_pTheme->getWindowById( rData.m_windowId );
529 if( pWindow == NULL )
531 msg_Err( getIntf(), "unknown window id: %s", rData.m_windowId.c_str() );
535 CmdGeneric *pCommand = parseAction( rData.m_action2Id );
536 if( pCommand == NULL )
538 msg_Err( getIntf(), "invalid action: %s", rData.m_action2Id.c_str() );
542 // Get the visibility variable
543 // XXX check when it is null
544 Interpreter *pInterpreter = Interpreter::instance( getIntf() );
545 VarBool *pVisible = pInterpreter->getVarBool( rData.m_visible, m_pTheme );
547 CtrlImage::resize_t resizeMethod =
548 (rData.m_resize == "scale" ? CtrlImage::kScale : CtrlImage::kMosaic);
549 CtrlImage *pImage = new CtrlImage( getIntf(), *pBmp, *pCommand,
550 resizeMethod, UString( getIntf(), rData.m_help.c_str() ), pVisible );
552 // Compute the position of the control
553 const Position pos = makePosition( rData.m_leftTop, rData.m_rightBottom,
555 rData.m_yPos, pBmp->getWidth(),
556 pBmp->getHeight(), *pLayout );
558 // XXX: test to be changed! XXX
559 if( rData.m_actionId == "move" )
561 CtrlMove *pMove = new CtrlMove( getIntf(), m_pTheme->getWindowManager(),
562 *pImage, *pWindow, UString( getIntf(), rData.m_help.c_str() ),
564 pLayout->addControl( pMove, pos, rData.m_layer );
566 else if( rData.m_actionId == "resizeS" )
568 CtrlResize *pResize = new CtrlResize( getIntf(),
569 m_pTheme->getWindowManager(), *pImage, *pLayout,
570 UString( getIntf(), rData.m_help.c_str() ), pVisible,
571 WindowManager::kResizeS );
572 pLayout->addControl( pResize, pos, rData.m_layer );
574 else if( rData.m_actionId == "resizeE" )
576 CtrlResize *pResize = new CtrlResize( getIntf(),
577 m_pTheme->getWindowManager(), *pImage, *pLayout,
578 UString( getIntf(), rData.m_help.c_str() ), pVisible,
579 WindowManager::kResizeE );
580 pLayout->addControl( pResize, pos, rData.m_layer );
582 else if( rData.m_actionId == "resizeSE" )
584 CtrlResize *pResize = new CtrlResize( getIntf(),
585 m_pTheme->getWindowManager(), *pImage, *pLayout,
586 UString( getIntf(), rData.m_help.c_str() ), pVisible,
587 WindowManager::kResizeSE );
588 pLayout->addControl( pResize, pos, rData.m_layer );
592 pLayout->addControl( pImage, pos, rData.m_layer );
595 m_pTheme->m_controls[rData.m_id] = CtrlGenericPtr( pImage );
599 void Builder::addText( const BuilderData::Text &rData )
601 GenericLayout *pLayout = m_pTheme->getLayoutById( rData.m_layoutId );
602 if( pLayout == NULL )
604 msg_Err( getIntf(), "unknown layout id: %s", rData.m_layoutId.c_str() );
608 GenericFont *pFont = getFont( rData.m_fontId );
611 msg_Err( getIntf(), "unknown font id: %s", rData.m_fontId.c_str() );
615 // Convert the scrolling mode
616 CtrlText::Scrolling_t scrolling;
617 if( rData.m_scrolling == "auto" )
618 scrolling = CtrlText::kAutomatic;
619 else if( rData.m_scrolling == "manual" )
620 scrolling = CtrlText::kManual;
621 else if( rData.m_scrolling == "none" )
622 scrolling = CtrlText::kNone;
625 msg_Err( getIntf(), "invalid scrolling mode: %s",
626 rData.m_scrolling.c_str() );
630 // Convert the alignment
631 CtrlText::Align_t alignment;
632 if( rData.m_alignment == "left" )
633 alignment = CtrlText::kLeft;
634 else if( rData.m_alignment == "center" || rData.m_alignment == "centre" )
635 alignment = CtrlText::kCenter;
636 else if( rData.m_alignment == "right" )
637 alignment = CtrlText::kRight;
640 msg_Err( getIntf(), "invalid alignment: %s",
641 rData.m_alignment.c_str() );
645 // Create a text variable
646 VarText *pVar = new VarText( getIntf() );
647 m_pTheme->m_vars.push_back( VariablePtr( pVar ) );
649 // Get the visibility variable
650 // XXX check when it is null
651 Interpreter *pInterpreter = Interpreter::instance( getIntf() );
652 VarBool *pVisible = pInterpreter->getVarBool( rData.m_visible, m_pTheme );
654 CtrlText *pText = new CtrlText( getIntf(), *pVar, *pFont,
655 UString( getIntf(), rData.m_help.c_str() ), rData.m_color, pVisible,
656 scrolling, alignment );
658 int height = pFont->getSize();
660 // Compute the position of the control
661 const Position pos = makePosition( rData.m_leftTop, rData.m_rightBottom,
662 rData.m_xPos, rData.m_yPos,
663 rData.m_width, height,
666 pLayout->addControl( pText, pos, rData.m_layer );
668 // Set the text of the control
669 UString msg( getIntf(), rData.m_text.c_str() );
672 m_pTheme->m_controls[rData.m_id] = CtrlGenericPtr( pText );
676 void Builder::addRadialSlider( const BuilderData::RadialSlider &rData )
678 // Get the bitmaps of the slider
679 GenericBitmap *pSeq = NULL;
680 GET_BMP( pSeq, rData.m_sequence );
682 GenericLayout *pLayout = m_pTheme->getLayoutById( rData.m_layoutId );
683 if( pLayout == NULL )
685 msg_Err( getIntf(), "unknown layout id: %s", rData.m_layoutId.c_str() );
689 // Get the variable associated to the slider
690 Interpreter *pInterpreter = Interpreter::instance( getIntf() );
691 VarPercent *pVar = pInterpreter->getVarPercent( rData.m_value, m_pTheme );
694 msg_Err( getIntf(), "unknown slider value: %s", rData.m_value.c_str() );
698 // Get the visibility variable
699 // XXX check when it is null
700 VarBool *pVisible = pInterpreter->getVarBool( rData.m_visible, m_pTheme );
702 // Create the control
703 CtrlRadialSlider *pRadial =
704 new CtrlRadialSlider( getIntf(), *pSeq, rData.m_nbImages, *pVar,
705 rData.m_minAngle, rData.m_maxAngle,
706 UString( getIntf(), rData.m_help.c_str() ),
709 // XXX: resizing is not supported
710 // Compute the position of the control
712 makePosition( rData.m_leftTop, rData.m_rightBottom, rData.m_xPos,
713 rData.m_yPos, pSeq->getWidth(),
714 pSeq->getHeight() / rData.m_nbImages, *pLayout );
716 pLayout->addControl( pRadial, pos, rData.m_layer );
718 m_pTheme->m_controls[rData.m_id] = CtrlGenericPtr( pRadial );
722 void Builder::addSlider( const BuilderData::Slider &rData )
724 // Add the background first, so that we will still have something almost
725 // functional if the cursor cannot be created properly (this happens for
726 // some winamp2 skins, where the images of the cursor are not always
729 // Get the bitmaps of the background
730 GenericBitmap *pBgImage = NULL;
731 if( rData.m_imageId != "none" )
733 GET_BMP( pBgImage, rData.m_imageId );
736 GenericLayout *pLayout = m_pTheme->getLayoutById( rData.m_layoutId );
737 if( pLayout == NULL )
739 msg_Err( getIntf(), "unknown layout id: %s", rData.m_layoutId.c_str() );
743 Bezier *pCurve = getPoints( rData.m_points.c_str() );
746 msg_Err( getIntf(), "invalid format in tag points=\"%s\"",
747 rData.m_points.c_str() );
750 m_pTheme->m_curves.push_back( BezierPtr( pCurve ) );
752 // Get the visibility variable
753 // XXX check when it is null
754 Interpreter *pInterpreter = Interpreter::instance( getIntf() );
755 VarBool *pVisible = pInterpreter->getVarBool( rData.m_visible, m_pTheme );
757 // Get the variable associated to the slider
758 VarPercent *pVar = pInterpreter->getVarPercent( rData.m_value, m_pTheme );
761 msg_Err( getIntf(), "unknown slider value: %s", rData.m_value.c_str() );
765 // Create the background control
766 CtrlSliderBg *pBackground = new CtrlSliderBg( getIntf(),
767 *pCurve, *pVar, rData.m_thickness, pBgImage, rData.m_nbHoriz,
768 rData.m_nbVert, rData.m_padHoriz, rData.m_padVert,
769 pVisible, UString( getIntf(), rData.m_help.c_str() ) );
771 // Compute the position of the control
772 const Position pos = makePosition( rData.m_leftTop, rData.m_rightBottom,
773 rData.m_xPos, rData.m_yPos,
774 pCurve->getWidth(), pCurve->getHeight(),
777 pLayout->addControl( pBackground, pos, rData.m_layer );
779 m_pTheme->m_controls[rData.m_id + "_bg"] = CtrlGenericPtr( pBackground );
781 // Get the bitmaps of the cursor
782 GenericBitmap *pBmpUp = NULL;
783 GET_BMP( pBmpUp, rData.m_upId );
785 GenericBitmap *pBmpDown = pBmpUp;
786 GET_BMP( pBmpDown, rData.m_downId );
788 GenericBitmap *pBmpOver = pBmpUp;
789 GET_BMP( pBmpOver, rData.m_overId );
791 // Create the cursor control
792 CtrlSliderCursor *pCursor = new CtrlSliderCursor( getIntf(), *pBmpUp,
793 *pBmpOver, *pBmpDown, *pCurve, *pVar, pVisible,
794 UString( getIntf(), rData.m_tooltip.c_str() ),
795 UString( getIntf(), rData.m_help.c_str() ) );
797 pLayout->addControl( pCursor, pos, rData.m_layer );
799 m_pTheme->m_controls[rData.m_id] = CtrlGenericPtr( pCursor );
801 // Associate the cursor to the background
802 pBackground->associateCursor( *pCursor );
806 void Builder::addList( const BuilderData::List &rData )
808 // Get the background bitmap, if any
809 GenericBitmap *pBgBmp = NULL;
810 GET_BMP( pBgBmp, rData.m_bgImageId );
812 GenericLayout *pLayout = m_pTheme->getLayoutById( rData.m_layoutId );
813 if( pLayout == NULL )
815 msg_Err( getIntf(), "unknown layout id: %s", rData.m_layoutId.c_str() );
819 GenericFont *pFont = getFont( rData.m_fontId );
822 msg_Err( getIntf(), "unknown font id: %s", rData.m_fontId.c_str() );
826 // Get the list variable
827 Interpreter *pInterpreter = Interpreter::instance( getIntf() );
828 VarList *pVar = pInterpreter->getVarList( rData.m_var, m_pTheme );
831 msg_Err( getIntf(), "no such list variable: %s", rData.m_var.c_str() );
835 // Get the visibility variable
836 // XXX check when it is null
837 VarBool *pVisible = pInterpreter->getVarBool( rData.m_visible, m_pTheme );
839 // Get the color values
840 uint32_t fgColor = getColor( rData.m_fgColor );
841 uint32_t playColor = getColor( rData.m_playColor );
842 uint32_t bgColor1 = getColor( rData.m_bgColor1 );
843 uint32_t bgColor2 = getColor( rData.m_bgColor2 );
844 uint32_t selColor = getColor( rData.m_selColor );
846 // Create the list control
847 CtrlList *pList = new CtrlList( getIntf(), *pVar, *pFont, pBgBmp,
848 fgColor, playColor, bgColor1, bgColor2, selColor,
849 UString( getIntf(), rData.m_help.c_str() ), pVisible );
851 // Compute the position of the control
852 const Position pos = makePosition( rData.m_leftTop, rData.m_rightBottom,
853 rData.m_xPos, rData.m_yPos,
854 rData.m_width, rData.m_height,
857 pLayout->addControl( pList, pos, rData.m_layer );
859 m_pTheme->m_controls[rData.m_id] = CtrlGenericPtr( pList );
862 void Builder::addTree( const BuilderData::Tree &rData )
864 // Get the bitmaps, if any
865 GenericBitmap *pBgBmp = NULL;
866 GenericBitmap *pItemBmp = NULL;
867 GenericBitmap *pOpenBmp = NULL;
868 GenericBitmap *pClosedBmp = NULL;
869 GET_BMP( pBgBmp, rData.m_bgImageId );
870 GET_BMP( pItemBmp, rData.m_itemImageId );
871 GET_BMP( pOpenBmp, rData.m_openImageId );
872 GET_BMP( pClosedBmp, rData.m_closedImageId );
874 GenericLayout *pLayout = m_pTheme->getLayoutById( rData.m_layoutId );
875 if( pLayout == NULL )
877 msg_Err( getIntf(), "unknown layout id: %s", rData.m_layoutId.c_str() );
881 GenericFont *pFont = getFont( rData.m_fontId );
884 msg_Err( getIntf(), "unknown font id: %s", rData.m_fontId.c_str() );
888 // Get the list variable
889 Interpreter *pInterpreter = Interpreter::instance( getIntf() );
890 VarTree *pVar = pInterpreter->getVarTree( rData.m_var, m_pTheme );
893 msg_Err( getIntf(), "no such list variable: %s", rData.m_var.c_str() );
897 // Get the visibility variable
898 // XXX check when it is null
899 VarBool *pVisible = pInterpreter->getVarBool( rData.m_visible, m_pTheme );
900 VarBool *pFlat = pInterpreter->getVarBool( rData.m_flat, m_pTheme );
902 // Get the color values
903 uint32_t fgColor = getColor( rData.m_fgColor );
904 uint32_t playColor = getColor( rData.m_playColor );
905 uint32_t bgColor1 = getColor( rData.m_bgColor1 );
906 uint32_t bgColor2 = getColor( rData.m_bgColor2 );
907 uint32_t selColor = getColor( rData.m_selColor );
909 // Create the list control
910 CtrlTree *pTree = new CtrlTree( getIntf(), *pVar, *pFont, pBgBmp,
911 pItemBmp, pOpenBmp, pClosedBmp,
912 fgColor, playColor, bgColor1, bgColor2, selColor,
913 UString( getIntf(), rData.m_help.c_str() ), pVisible, pFlat );
915 // Compute the position of the control
916 const Position pos = makePosition( rData.m_leftTop, rData.m_rightBottom,
917 rData.m_xPos, rData.m_yPos,
918 rData.m_width, rData.m_height,
921 pLayout->addControl( pTree, pos, rData.m_layer );
923 m_pTheme->m_controls[rData.m_id] = CtrlGenericPtr( pTree );
926 void Builder::addVideo( const BuilderData::Video &rData )
928 GenericLayout *pLayout = m_pTheme->getLayoutById( rData.m_layoutId );
929 if( pLayout == NULL )
931 msg_Err( getIntf(), "unknown layout id: %s", rData.m_layoutId.c_str() );
935 // Get the visibility variable
936 // XXX check when it is null
937 Interpreter *pInterpreter = Interpreter::instance( getIntf() );
938 VarBool *pVisible = pInterpreter->getVarBool( rData.m_visible, m_pTheme );
940 CtrlVideo *pVideo = new CtrlVideo( getIntf(), *pLayout,
941 rData.m_autoResize, UString( getIntf(), rData.m_help.c_str() ),
944 // Compute the position of the control
945 const Position pos = makePosition( rData.m_leftTop, rData.m_rightBottom,
946 rData.m_xPos, rData.m_yPos,
947 rData.m_width, rData.m_height,
950 pLayout->addControl( pVideo, pos, rData.m_layer );
952 m_pTheme->m_controls[rData.m_id] = CtrlGenericPtr( pVideo );
956 const Position Builder::makePosition( const string &rLeftTop,
957 const string &rRightBottom,
958 int xPos, int yPos, int width,
959 int height, const Box &rBox ) const
961 int left = 0, top = 0, right = 0, bottom = 0;
962 Position::Ref_t refLeftTop = Position::kLeftTop;
963 Position::Ref_t refRightBottom = Position::kLeftTop;
965 int boxWidth = rBox.getWidth();
966 int boxHeight = rBox.getHeight();
968 // Position of the left top corner
969 if( rLeftTop == "lefttop" )
973 refLeftTop = Position::kLeftTop;
975 else if( rLeftTop == "righttop" )
977 left = xPos - boxWidth + 1;
979 refLeftTop = Position::kRightTop;
981 else if( rLeftTop == "leftbottom" )
984 top = yPos - boxHeight + 1;
985 refLeftTop = Position::kLeftBottom;
987 else if( rLeftTop == "rightbottom" )
989 left = xPos - boxWidth + 1;
990 top = yPos - boxHeight + 1;
991 refLeftTop = Position::kRightBottom;
994 // Position of the right bottom corner
995 if( rRightBottom == "lefttop" )
997 right = xPos + width - 1;
998 bottom = yPos + height - 1;
999 refRightBottom = Position::kLeftTop;
1001 else if( rRightBottom == "righttop" )
1003 right = xPos + width - boxWidth;
1004 bottom = yPos + height - 1;
1005 refRightBottom = Position::kRightTop;
1007 else if( rRightBottom == "leftbottom" )
1009 right = xPos + width - 1;
1010 bottom = yPos + height - boxHeight;
1011 refRightBottom = Position::kLeftBottom;
1013 else if( rRightBottom == "rightbottom" )
1015 right = xPos + width - boxWidth;
1016 bottom = yPos + height - boxHeight;
1017 refRightBottom = Position::kRightBottom;
1020 return Position( left, top, right, bottom, rBox, refLeftTop,
1025 GenericFont *Builder::getFont( const string &fontId )
1027 GenericFont *pFont = m_pTheme->getFontById(fontId);
1028 if( !pFont && fontId == "defaultfont" )
1030 // Get the resource path and try to load the default font
1031 OSFactory *pOSFactory = OSFactory::instance( getIntf() );
1032 const list<string> &resPath = pOSFactory->getResourcePath();
1033 const string &sep = pOSFactory->getDirSeparator();
1035 list<string>::const_iterator it;
1036 for( it = resPath.begin(); it != resPath.end(); it++ )
1038 string path = (*it) + sep + "fonts" + sep + "FreeSans.ttf";
1039 pFont = new FT2Font( getIntf(), path, 12 );
1042 // Font loaded successfully
1043 m_pTheme->m_fonts["defaultfont"] = GenericFontPtr( pFont );
1054 msg_Err( getIntf(), "failed to open the default font" );
1061 string Builder::getFilePath( const string &rFileName ) const
1063 OSFactory *pFactory = OSFactory::instance( getIntf() );
1064 return m_path + pFactory->getDirSeparator() + sFromLocale( rFileName );
1069 Bezier *Builder::getPoints( const char *pTag ) const
1071 vector<float> xBez, yBez;
1075 if( sscanf( pTag, "(%d,%d)%n", &x, &y, &n ) < 1 )
1080 if( x < 0 || y < 0 )
1083 "Slider points cannot have negative coordinates!" );
1087 xBez.push_back( x );
1088 yBez.push_back( y );
1094 if( *(pTag++) != ',' )
1100 // Create the Bezier curve
1101 return new Bezier( getIntf(), xBez, yBez );
1105 uint32_t Builder::getColor( const string &rVal ) const
1107 // Check it the value is a registered constant
1108 Interpreter *pInterpreter = Interpreter::instance( getIntf() );
1109 string val = pInterpreter->getConstant( rVal );
1111 // Convert to an int value
1112 return SkinParser::convertColor( val.c_str() );