📄 builder.cpp
字号:
m_pTheme->m_curves.push_back( BezierPtr( pCurve ) ); // Compute the position of the anchor const Position pos = makePosition( rData.m_leftTop, rData.m_leftTop, rData.m_xPos, rData.m_yPos, pCurve->getWidth(), pCurve->getHeight(), pLayout->getRect() ); Anchor *pAnc = new Anchor( getIntf(), pos, rData.m_range, rData.m_priority, *pCurve, *pLayout ); pLayout->addAnchor( pAnc );}void Builder::addButton( const BuilderData::Button &rData ){ // Get the bitmaps of the button GenericBitmap *pBmpUp = NULL; GET_BMP( pBmpUp, rData.m_upId ); GenericBitmap *pBmpDown = pBmpUp; GET_BMP( pBmpDown, rData.m_downId ); GenericBitmap *pBmpOver = pBmpUp; GET_BMP( pBmpOver, rData.m_overId ); GenericLayout *pLayout = m_pTheme->getLayoutById( rData.m_layoutId ); if( pLayout == NULL ) { msg_Err( getIntf(), "unknown layout id: %s", rData.m_layoutId.c_str() ); return; } CmdGeneric *pCommand = parseAction( rData.m_actionId ); if( pCommand == NULL ) { msg_Err( getIntf(), "invalid action: %s", rData.m_actionId.c_str() ); return; } // Get the visibility variable // XXX check when it is null Interpreter *pInterpreter = Interpreter::instance( getIntf() ); VarBool *pVisible = pInterpreter->getVarBool( rData.m_visible, m_pTheme ); CtrlButton *pButton = new CtrlButton( getIntf(), *pBmpUp, *pBmpOver, *pBmpDown, *pCommand, UString( getIntf(), rData.m_tooltip.c_str() ), UString( getIntf(), rData.m_help.c_str() ), pVisible ); m_pTheme->m_controls[rData.m_id] = CtrlGenericPtr( pButton ); // Compute the position of the control // XXX (we suppose all the images have the same size...) const GenericRect *pRect; GET_BOX( pRect, rData.m_panelId , pLayout); const Position pos = makePosition( rData.m_leftTop, rData.m_rightBottom, rData.m_xPos, rData.m_yPos, pBmpUp->getWidth(), pBmpUp->getHeight(), *pRect, rData.m_xKeepRatio, rData.m_yKeepRatio ); pLayout->addControl( pButton, pos, rData.m_layer );}void Builder::addCheckbox( const BuilderData::Checkbox &rData ){ // Get the bitmaps of the checkbox GenericBitmap *pBmpUp1 = NULL; GET_BMP( pBmpUp1, rData.m_up1Id ); GenericBitmap *pBmpDown1 = pBmpUp1; GET_BMP( pBmpDown1, rData.m_down1Id ); GenericBitmap *pBmpOver1 = pBmpUp1; GET_BMP( pBmpOver1, rData.m_over1Id ); GenericBitmap *pBmpUp2 = NULL; GET_BMP( pBmpUp2, rData.m_up2Id ); GenericBitmap *pBmpDown2 = pBmpUp2; GET_BMP( pBmpDown2, rData.m_down2Id ); GenericBitmap *pBmpOver2 = pBmpUp2; GET_BMP( pBmpOver2, rData.m_over2Id ); GenericLayout *pLayout = m_pTheme->getLayoutById( rData.m_layoutId ); if( pLayout == NULL ) { msg_Err( getIntf(), "unknown layout id: %s", rData.m_layoutId.c_str() ); return; } CmdGeneric *pCommand1 = parseAction( rData.m_action1 ); if( pCommand1 == NULL ) { msg_Err( getIntf(), "invalid action: %s", rData.m_action1.c_str() ); return; } CmdGeneric *pCommand2 = parseAction( rData.m_action2 ); if( pCommand2 == NULL ) { msg_Err( getIntf(), "invalid action: %s", rData.m_action2.c_str() ); return; } // Get the state variable Interpreter *pInterpreter = Interpreter::instance( getIntf() ); VarBool *pVar = pInterpreter->getVarBool( rData.m_state, m_pTheme ); if( pVar == NULL ) { // TODO: default state return; } // Get the visibility variable // XXX check when it is null VarBool *pVisible = pInterpreter->getVarBool( rData.m_visible, m_pTheme ); // Create the control CtrlCheckbox *pCheckbox = new CtrlCheckbox( getIntf(), *pBmpUp1, *pBmpOver1, *pBmpDown1, *pBmpUp2, *pBmpOver2, *pBmpDown2, *pCommand1, *pCommand2, UString( getIntf(), rData.m_tooltip1.c_str() ), UString( getIntf(), rData.m_tooltip2.c_str() ), *pVar, UString( getIntf(), rData.m_help.c_str() ), pVisible ); m_pTheme->m_controls[rData.m_id] = CtrlGenericPtr( pCheckbox ); // Compute the position of the control // XXX (we suppose all the images have the same size...) const GenericRect *pRect; GET_BOX( pRect, rData.m_panelId , pLayout); const Position pos = makePosition( rData.m_leftTop, rData.m_rightBottom, rData.m_xPos, rData.m_yPos, pBmpUp1->getWidth(), pBmpUp1->getHeight(), *pRect, rData.m_xKeepRatio, rData.m_yKeepRatio ); pLayout->addControl( pCheckbox, pos, rData.m_layer );}void Builder::addImage( const BuilderData::Image &rData ){ GenericBitmap *pBmp = NULL; GET_BMP( pBmp, rData.m_bmpId ); GenericLayout *pLayout = m_pTheme->getLayoutById( rData.m_layoutId ); if( pLayout == NULL ) { msg_Err( getIntf(), "unknown layout id: %s", rData.m_layoutId.c_str() ); return; } TopWindow *pWindow = m_pTheme->getWindowById( rData.m_windowId ); if( pWindow == NULL ) { msg_Err( getIntf(), "unknown window id: %s", rData.m_windowId.c_str() ); return; } CmdGeneric *pCommand = parseAction( rData.m_action2Id ); if( pCommand == NULL ) { msg_Err( getIntf(), "invalid action: %s", rData.m_action2Id.c_str() ); return; } // Get the visibility variable // XXX check when it is null Interpreter *pInterpreter = Interpreter::instance( getIntf() ); VarBool *pVisible = pInterpreter->getVarBool( rData.m_visible, m_pTheme ); CtrlImage::resize_t resizeMethod = (rData.m_resize == "scale" ? CtrlImage::kScale : CtrlImage::kMosaic); CtrlImage *pImage = new CtrlImage( getIntf(), *pBmp, *pCommand, resizeMethod, UString( getIntf(), rData.m_help.c_str() ), pVisible ); m_pTheme->m_controls[rData.m_id] = CtrlGenericPtr( pImage ); // Compute the position of the control const GenericRect *pRect; GET_BOX( pRect, rData.m_panelId , pLayout); const Position pos = makePosition( rData.m_leftTop, rData.m_rightBottom, rData.m_xPos, rData.m_yPos, pBmp->getWidth(), pBmp->getHeight(), *pRect, rData.m_xKeepRatio, rData.m_yKeepRatio ); if( rData.m_actionId == "move" ) { CtrlMove *pMove = new CtrlMove( getIntf(), m_pTheme->getWindowManager(), *pImage, *pWindow, UString( getIntf(), rData.m_help.c_str() ), pVisible ); m_pTheme->m_controls[rData.m_id + "_move"] = CtrlGenericPtr( pMove ); pLayout->addControl( pMove, pos, rData.m_layer ); } else if( rData.m_actionId == "resizeS" ) { CtrlResize *pResize = new CtrlResize( getIntf(), m_pTheme->getWindowManager(), *pImage, *pLayout, UString( getIntf(), rData.m_help.c_str() ), pVisible, WindowManager::kResizeS ); m_pTheme->m_controls[rData.m_id + "_rsz"] = CtrlGenericPtr( pResize ); pLayout->addControl( pResize, pos, rData.m_layer ); } else if( rData.m_actionId == "resizeE" ) { CtrlResize *pResize = new CtrlResize( getIntf(), m_pTheme->getWindowManager(), *pImage, *pLayout, UString( getIntf(), rData.m_help.c_str() ), pVisible, WindowManager::kResizeE ); m_pTheme->m_controls[rData.m_id + "_rsz"] = CtrlGenericPtr( pResize ); pLayout->addControl( pResize, pos, rData.m_layer ); } else if( rData.m_actionId == "resizeSE" ) { CtrlResize *pResize = new CtrlResize( getIntf(), m_pTheme->getWindowManager(), *pImage, *pLayout, UString( getIntf(), rData.m_help.c_str() ), pVisible, WindowManager::kResizeSE ); m_pTheme->m_controls[rData.m_id + "_rsz"] = CtrlGenericPtr( pResize ); pLayout->addControl( pResize, pos, rData.m_layer ); } else { pLayout->addControl( pImage, pos, rData.m_layer ); }}void Builder::addPanel( const BuilderData::Panel &rData ){ // This method makes the assumption that the Panels are created in the // order of the XML, because each child Panel expects its parent Panel // in order to be fully created GenericLayout *pLayout = m_pTheme->getLayoutById( rData.m_layoutId ); if( pLayout == NULL ) { msg_Err( getIntf(), "unknown layout id: %s", rData.m_layoutId.c_str() ); return; } const GenericRect *pRect; GET_BOX( pRect, rData.m_panelId , pLayout); Position *pPos = new Position( makePosition( rData.m_leftTop, rData.m_rightBottom, rData.m_xPos, rData.m_yPos, rData.m_width, rData.m_height, *pRect, rData.m_xKeepRatio, rData.m_yKeepRatio ) ); m_pTheme->m_positions[rData.m_id] = PositionPtr( pPos );}void Builder::addText( const BuilderData::Text &rData ){ GenericLayout *pLayout = m_pTheme->getLayoutById( rData.m_layoutId ); if( pLayout == NULL ) { msg_Err( getIntf(), "unknown layout id: %s", rData.m_layoutId.c_str() ); return; } GenericFont *pFont = getFont( rData.m_fontId ); if( pFont == NULL ) { msg_Err( getIntf(), "unknown font id: %s", rData.m_fontId.c_str() ); return; } // Convert the scrolling mode CtrlText::Scrolling_t scrolling; if( rData.m_scrolling == "auto" ) scrolling = CtrlText::kAutomatic; else if( rData.m_scrolling == "manual" ) scrolling = CtrlText::kManual; else if( rData.m_scrolling == "none" ) scrolling = CtrlText::kNone; else { msg_Err( getIntf(), "invalid scrolling mode: %s", rData.m_scrolling.c_str() ); return; } // Convert the alignment CtrlText::Align_t alignment; if( rData.m_alignment == "left" ) alignment = CtrlText::kLeft; else if( rData.m_alignment == "center" || rData.m_alignment == "centre" ) alignment = CtrlText::kCenter; else if( rData.m_alignment == "right" ) alignment = CtrlText::kRight; else { msg_Err( getIntf(), "invalid alignment: %s", rData.m_alignment.c_str() ); return; } // Create a text variable VarText *pVar = new VarText( getIntf() ); m_pTheme->m_vars.push_back( VariablePtr( pVar ) ); // Get the visibility variable // XXX check when it is null Interpreter *pInterpreter = Interpreter::instance( getIntf() ); VarBool *pVisible = pInterpreter->getVarBool( rData.m_visible, m_pTheme ); CtrlText *pText = new CtrlText( getIntf(), *pVar, *pFont, UString( getIntf(), rData.m_help.c_str() ), rData.m_color, pVisible, scrolling, alignment ); m_pTheme->m_controls[rData.m_id] = CtrlGenericPtr( pText ); int height = pFont->getSize(); // Compute the position of the control const GenericRect *pRect; GET_BOX( pRect, rData.m_panelId , pLayout); const Position pos = makePosition( rData.m_leftTop, rData.m_rightBottom, rData.m_xPos, rData.m_yPos, rData.m_width, height, *pRect, rData.m_xKeepRatio, rData.m_yKeepRatio ); pLayout->addControl( pText, pos, rData.m_layer ); // Set the text of the control UString msg( getIntf(), rData.m_text.c_str() ); pVar->set( msg );}void Builder::addRadialSlider( const BuilderData::RadialSlider &rData ){ // Get the bitmaps of the slider GenericBitmap *pSeq = NULL; GET_BMP( pSeq, rData.m_sequence ); GenericLayout *pLayout = m_pTheme->getLayoutById( rData.m_layoutId ); if( pLayout == NULL ) { msg_Err( getIntf(), "unknown layout id: %s", rData.m_layoutId.c_str() ); return; } // Get the variable associated to the slider Interpreter *pInterpreter = Interpreter::instance( getIntf() ); VarPercent *pVar = pInterpreter->getVarPercent( rData.m_value, m_pTheme ); if( pVar == NULL ) { msg_Err( getIntf(), "unknown slider value: %s", rData.m_value.c_str() ); return; } // Get the visibility variable // XXX check when it is null VarBool *pVisible = pInterpreter->getVarBool( rData.m_visible, m_pTheme ); // Create the control CtrlRadialSlider *pRadial = new CtrlRadialSlider( getIntf(), *pSeq, rData.m_nbImages, *pVar, rData.m_minAngle, rData.m_maxAngle, UString( getIntf(), rData.m_help.c_str() ), pVisible ); m_pTheme->m_controls[rData.m_id] = CtrlGenericPtr( pRadial ); // XXX: resizing is not supported // Compute the position of the control const GenericRect *pRect; GET_BOX( pRect, rData.m_panelId , pLayout); const Position pos = makePosition( rData.m_leftTop, rData.m_rightBottom, rData.m_xPos, rData.m_yPos, pSeq->getWidth(), pSeq->getHeight() / rData.m_nbImages, *pRect, rData.m_xKeepRatio, rData.m_yKeepRatio ); pLayout->addControl( pRadial, pos, rData.m_layer );}void Builder::addSlider( const BuilderData::Slider &rData ){ // Add the background first, so that we will still have something almost // functional if the cursor cannot be created properly (this happens for // some winamp2 skins, where the images of the cursor are not always // present) // Get the bitmaps of the background GenericBitmap *pBgImage = NULL; if( rData.m_imageId != "none" ) { GET_BMP( pBgImage, rData.m_imageId ); } GenericLayout *pLayout = m_pTheme->getLayoutById( rData.m_layoutId );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -