📄 builder.cpp
字号:
// XXX: test to be changed! XXX if( rData.m_actionId == "move" ) { CtrlMove *pMove = new CtrlMove( getIntf(), m_pTheme->getWindowManager(), *pImage, *pWindow, UString( getIntf(), rData.m_help.c_str() ), NULL); pLayout->addControl( pMove, pos, rData.m_layer ); } else if( rData.m_actionId == "resizeSE" ) { CtrlResize *pResize = new CtrlResize( getIntf(), *pImage, *pLayout, UString( getIntf(), rData.m_help.c_str() ), NULL ); pLayout->addControl( pResize, pos, rData.m_layer ); } else { pLayout->addControl( pImage, pos, rData.m_layer ); } m_pTheme->m_controls[rData.m_id] = CtrlGenericPtr( pImage );}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; } // Create a text variable VarText *pVar = new VarText( getIntf() ); UString msg( getIntf(), rData.m_text.c_str() ); pVar->set( msg ); 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 ); int height = pFont->getSize(); // Compute the position of the control const Position pos = makePosition( rData.m_leftTop, rData.m_rightBottom, rData.m_xPos, rData.m_yPos, rData.m_width, height, *pLayout ); pLayout->addControl( pText, pos, rData.m_layer ); m_pTheme->m_controls[rData.m_id] = CtrlGenericPtr( pText );}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 ); // XXX: resizing is not supported // Compute the position of the control const Position pos = makePosition( rData.m_leftTop, rData.m_rightBottom, rData.m_xPos, rData.m_yPos, pSeq->getWidth(), pSeq->getHeight() / rData.m_nbImages, *pLayout ); pLayout->addControl( pRadial, pos, rData.m_layer ); m_pTheme->m_controls[rData.m_id] = CtrlGenericPtr( pRadial );}void Builder::addSlider( const BuilderData::Slider &rData ){ // Get the bitmaps of the slider 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; } Bezier *pCurve = getPoints( rData.m_points.c_str() ); if( pCurve == NULL ) { msg_Err( getIntf(), "Invalid format in tag points=\"%s\"", rData.m_points.c_str() ); return; } m_pTheme->m_curves.push_back( BezierPtr( pCurve ) ); // Get the visibility variable // XXX check when it is null Interpreter *pInterpreter = Interpreter::instance( getIntf() ); VarBool *pVisible = pInterpreter->getVarBool( rData.m_visible, m_pTheme ); // Get the variable associated to the slider 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; } // Create the cursor and background controls CtrlSliderCursor *pCursor = new CtrlSliderCursor( getIntf(), *pBmpUp, *pBmpOver, *pBmpDown, *pCurve, *pVar, pVisible, UString( getIntf(), rData.m_tooltip.c_str() ), UString( getIntf(), rData.m_help.c_str() ) ); CtrlSliderBg *pBackground = new CtrlSliderBg( getIntf(), *pCursor, *pCurve, *pVar, rData.m_thickness, pVisible, UString( getIntf(), rData.m_help.c_str() ) ); // Compute the position of the control const Position pos = makePosition( rData.m_leftTop, rData.m_rightBottom, rData.m_xPos, rData.m_yPos, pCurve->getWidth(), pCurve->getHeight(), *pLayout ); pLayout->addControl( pBackground, pos, rData.m_layer ); pLayout->addControl( pCursor, pos, rData.m_layer ); m_pTheme->m_controls[rData.m_id] = CtrlGenericPtr( pCursor ); m_pTheme->m_controls[rData.m_id + "_bg"] = CtrlGenericPtr( pBackground );}void Builder::addList( const BuilderData::List &rData ){ // Get the background bitmap, if any GenericBitmap *pBgBmp = NULL; GET_BMP( pBgBmp, rData.m_bgImageId ); 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; } // Get the list variable Interpreter *pInterpreter = Interpreter::instance( getIntf() ); VarList *pVar = pInterpreter->getVarList( rData.m_var, m_pTheme ); if( pVar == NULL ) { msg_Err( getIntf(), "No such list variable: %s", rData.m_var.c_str() ); return; } // Get the visibility variable // XXX check when it is null VarBool *pVisible = pInterpreter->getVarBool( rData.m_visible, m_pTheme ); // Create the list control CtrlList *pList = new CtrlList( getIntf(), *pVar, *pFont, pBgBmp, rData.m_fgColor, rData.m_playColor, rData.m_bgColor1, rData.m_bgColor2, rData.m_selColor, UString( getIntf(), rData.m_help.c_str() ), pVisible ); // Compute the position of the control const Position pos = makePosition( rData.m_leftTop, rData.m_rightBottom, rData.m_xPos, rData.m_yPos, rData.m_width, rData.m_height, *pLayout ); pLayout->addControl( pList, pos, rData.m_layer ); m_pTheme->m_controls[rData.m_id] = CtrlGenericPtr( pList );}void Builder::addVideo( const BuilderData::Video &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; } // Get the visibility variable // XXX check when it is null Interpreter *pInterpreter = Interpreter::instance( getIntf() ); VarBool *pVisible = pInterpreter->getVarBool( rData.m_visible, m_pTheme ); CtrlVideo *pVideo = new CtrlVideo( getIntf(), UString( getIntf(), rData.m_help.c_str() ), pVisible ); // Compute the position of the control const Position pos = makePosition( rData.m_leftTop, rData.m_rightBottom, rData.m_xPos, rData.m_yPos, rData.m_width, rData.m_height, *pLayout ); pLayout->addControl( pVideo, pos, rData.m_layer ); m_pTheme->m_controls[rData.m_id] = CtrlGenericPtr( pVideo );}const Position Builder::makePosition( const string &rLeftTop, const string &rRightBottom, int xPos, int yPos, int width, int height, const Box &rBox ) const{ int left = 0, top = 0, right = 0, bottom = 0; Position::Ref_t refLeftTop = Position::kLeftTop; Position::Ref_t refRightBottom = Position::kLeftTop; int boxWidth = rBox.getWidth(); int boxHeight = rBox.getHeight(); // Position of the left top corner if( rLeftTop == "lefttop" ) { left = xPos; top = yPos; refLeftTop = Position::kLeftTop; } else if( rLeftTop == "righttop" ) { left = xPos - boxWidth + 1; top = yPos; refLeftTop = Position::kRightTop; } else if( rLeftTop == "leftbottom" ) { left = xPos; top = yPos - boxHeight + 1; refLeftTop = Position::kLeftBottom; } else if( rLeftTop == "rightbottom" ) { left = xPos - boxWidth + 1; top = yPos - boxHeight + 1; refLeftTop = Position::kRightBottom; } // Position of the right bottom corner if( rRightBottom == "lefttop" ) { right = xPos + width - 1; bottom = yPos + height - 1; refRightBottom = Position::kLeftTop; } else if( rRightBottom == "righttop" ) { right = xPos + width - boxWidth; bottom = yPos + height - 1; refRightBottom = Position::kRightTop; } else if( rRightBottom == "leftbottom" ) { right = xPos + width - 1; bottom = yPos + height - boxHeight; refRightBottom = Position::kLeftBottom; } else if( rRightBottom == "rightbottom" ) { right = xPos + width - boxWidth; bottom = yPos + height - boxHeight; refRightBottom = Position::kRightBottom; } return Position( left, top, right, bottom, rBox, refLeftTop, refRightBottom );}GenericFont *Builder::getFont( const string &fontId ){ GenericFont *pFont = m_pTheme->getFontById(fontId); if( !pFont && fontId == "defaultfont" ) { // Get the resource path and try to load the default font OSFactory *pOSFactory = OSFactory::instance( getIntf() ); const list<string> &resPath = pOSFactory->getResourcePath(); const string &sep = pOSFactory->getDirSeparator(); list<string>::const_iterator it; for( it = resPath.begin(); it != resPath.end(); it++ ) { string path = (*it) + sep + "fonts" + sep + "FreeSans.ttf"; pFont = new FT2Font( getIntf(), path, 12 ); if( pFont->init() ) { // Font loaded successfully m_pTheme->m_fonts["defaultfont"] = GenericFontPtr( pFont ); break; } else { delete pFont; pFont = NULL; } } if( !pFont ) { msg_Err( getIntf(), "Failed to open the default font" ); } } return pFont;}Bezier *Builder::getPoints( const char *pTag ) const{ vector<float> xBez, yBez; int x, y, n; while( 1 ) { if( sscanf( pTag, "(%d,%d)%n", &x, &y, &n ) < 1 ) { return NULL; }#if 0 if( x < 0 || y < 0 ) { msg_Err( getIntf(), "Slider points cannot have negative coordinates!" ); return NULL; }#endif xBez.push_back( x ); yBez.push_back( y ); pTag += n; if( *pTag == '\0' ) { break; } if( *(pTag++) != ',' ) { return NULL; } } // Create the Bezier curve return new Bezier( getIntf(), xBez, yBez );}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -