📄 builder.cpp
字号:
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 background control CtrlSliderBg *pBackground = new CtrlSliderBg( getIntf(), *pCurve, *pVar, rData.m_thickness, pBgImage, rData.m_nbHoriz, rData.m_nbVert, rData.m_padHoriz, rData.m_padVert, pVisible, UString( getIntf(), rData.m_help.c_str() ) ); m_pTheme->m_controls[rData.m_id + "_bg"] = CtrlGenericPtr( pBackground ); // 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, pCurve->getWidth(), pCurve->getHeight(), *pRect, rData.m_xKeepRatio, rData.m_yKeepRatio ); pLayout->addControl( pBackground, pos, rData.m_layer ); // Get the bitmaps of the cursor 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 ); // Create the cursor control 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() ) ); m_pTheme->m_controls[rData.m_id] = CtrlGenericPtr( pCursor ); pLayout->addControl( pCursor, pos, rData.m_layer ); // Associate the cursor to the background pBackground->associateCursor( *pCursor );}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 ); // Get the color values uint32_t fgColor = getColor( rData.m_fgColor ); uint32_t playColor = getColor( rData.m_playColor ); uint32_t bgColor1 = getColor( rData.m_bgColor1 ); uint32_t bgColor2 = getColor( rData.m_bgColor2 ); uint32_t selColor = getColor( rData.m_selColor ); // Create the list control CtrlList *pList = new CtrlList( getIntf(), *pVar, *pFont, pBgBmp, fgColor, playColor, bgColor1, bgColor2, selColor, UString( getIntf(), rData.m_help.c_str() ), pVisible ); m_pTheme->m_controls[rData.m_id] = CtrlGenericPtr( pList ); // 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, rData.m_height, *pRect, rData.m_xKeepRatio, rData.m_yKeepRatio ); pLayout->addControl( pList, pos, rData.m_layer );}void Builder::addTree( const BuilderData::Tree &rData ){ // Get the bitmaps, if any GenericBitmap *pBgBmp = NULL; GenericBitmap *pItemBmp = NULL; GenericBitmap *pOpenBmp = NULL; GenericBitmap *pClosedBmp = NULL; GET_BMP( pBgBmp, rData.m_bgImageId ); GET_BMP( pItemBmp, rData.m_itemImageId ); GET_BMP( pOpenBmp, rData.m_openImageId ); GET_BMP( pClosedBmp, rData.m_closedImageId ); 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() ); VarTree *pVar = pInterpreter->getVarTree( 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 ); VarBool *pFlat = pInterpreter->getVarBool( rData.m_flat, m_pTheme ); // Get the color values uint32_t fgColor = getColor( rData.m_fgColor ); uint32_t playColor = getColor( rData.m_playColor ); uint32_t bgColor1 = getColor( rData.m_bgColor1 ); uint32_t bgColor2 = getColor( rData.m_bgColor2 ); uint32_t selColor = getColor( rData.m_selColor ); // Create the list control CtrlTree *pTree = new CtrlTree( getIntf(), *pVar, *pFont, pBgBmp, pItemBmp, pOpenBmp, pClosedBmp, fgColor, playColor, bgColor1, bgColor2, selColor, UString( getIntf(), rData.m_help.c_str() ), pVisible, pFlat ); m_pTheme->m_controls[rData.m_id] = CtrlGenericPtr( pTree ); // 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, rData.m_height, *pRect, rData.m_xKeepRatio, rData.m_yKeepRatio ); pLayout->addControl( pTree, pos, rData.m_layer );}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(), *pLayout, rData.m_autoResize, UString( getIntf(), rData.m_help.c_str() ), pVisible ); m_pTheme->m_controls[rData.m_id] = CtrlGenericPtr( pVideo ); // 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, rData.m_height, *pRect, rData.m_xKeepRatio, rData.m_yKeepRatio ); pLayout->addControl( pVideo, pos, rData.m_layer );}const Position Builder::makePosition( const string &rLeftTop, const string &rRightBottom, int xPos, int yPos, int width, int height, const GenericRect &rRect, bool xKeepRatio, bool yKeepRatio ) const{ int left = 0, top = 0, right = 0, bottom = 0; Position::Ref_t refLeftTop = Position::kLeftTop; Position::Ref_t refRightBottom = Position::kLeftTop; int boxWidth = rRect.getWidth(); int boxHeight = rRect.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; } // In "keep ratio" mode, overwrite the previously computed values with the // actual ones // XXX: this coupling between makePosition and the Position class should // be reduced... if( xKeepRatio ) { left = xPos; right = xPos + width; } if( yKeepRatio ) { top = yPos; bottom = yPos + height; } return Position( left, top, right, bottom, rRect, refLeftTop, refRightBottom, xKeepRatio, yKeepRatio );}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;}string Builder::getFilePath( const string &rFileName ) const{ OSFactory *pFactory = OSFactory::instance( getIntf() ); return m_path + pFactory->getDirSeparator() + sFromLocale( rFileName );}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; } 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 );}uint32_t Builder::getColor( const string &rVal ) const{ // Check it the value is a registered constant Interpreter *pInterpreter = Interpreter::instance( getIntf() ); string val = pInterpreter->getConstant( rVal ); // Convert to an int value return SkinParser::convertColor( val.c_str() );}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -