⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 theme.cpp

📁 这是一个mp3的源代码
💻 CPP
📖 第 1 页 / 共 3 页
字号:
          oAlign = oAttrMap["Align"]; 

       ((TextControl *)m_pCurrentControl)->SetStyle(pFont, oAlign,
               oColor, bBold, bItalic, bUnderline);
       
       return kError_NoErr;
    }

    if (oElement == string("ChangeWindow"))
    {
       if (m_pCurrentControl == NULL || m_eCurrentControl != eButtonControl)
       {
           m_oLastError = string("The <Style> tag must be inside of a "
                                 "<ButtonControl> tag");
           return kError_InvalidParam;
       }

       if (oAttrMap.find("Window") == oAttrMap.end())
       {
           m_oLastError = string("the <ChangeWindow> tag needs a Window attribute");
           return kError_ParseError;
       }        

       ((ButtonControl *)m_pCurrentControl)->SetTargetWindow(oAttrMap["Window"]);
       
       return kError_NoErr;
	}


    if (oElement == string("Position"))
    {
       Rect oRect;
       Pos  oPos;

       if (m_pCurrentControl == NULL)
       {
          m_oLastError = string("The <Position> tag must be inside of a "
                                "<XXXXControl> tag");
          return kError_InvalidParam;
       }

       if (oAttrMap.find("Rect") == oAttrMap.end() &&
           oAttrMap.find("Pos") == oAttrMap.end())
       {
           m_oLastError = string("the <Position> tag needs a Rect or a Pos attribute");
           return kError_ParseError;
       }        

       if (oAttrMap.find("Pos") != oAttrMap.end() &&
           m_eCurrentControl != eButtonControl &&
           m_eCurrentControl != eMultiStateControl)
       {
           m_oLastError = string("the Pos attribute in the <Position> tag can only be used "
                                 "for a MultiStateControl or a ButtonControl");
           return kError_ParseError;
       }        
       
       if (oAttrMap.find("Rect") != oAttrMap.end())
       {
           eRet = ParseRect(oAttrMap["Rect"], oRect);
           if (eRet != kError_NoErr)
           {
               m_oLastError = string("Improperly formatted Rect coordinates: ") +
                              oAttrMap["Rect"];
               return kError_InvalidParam;
           }
           m_pCurrentControl->SetRect(oRect);
       }    
       if (oAttrMap.find("Pos") != oAttrMap.end())
       {
           eRet = ParsePos(oAttrMap["Pos"], oPos);
           if (eRet != kError_NoErr)
           {
               m_oLastError = string("Improperly formatted Rect coordinates: ") +
                              oAttrMap["Rect"];
               return kError_InvalidParam;
           }
           m_pCurrentControl->SetPos(oPos);
       }    

       m_bPosDefined = true;

       return kError_NoErr;
    }

    if (oElement == string("ControlBitmap"))
    {
       Bitmap *pBitmap = NULL;
       Rect    oRect;
       bool    bHoriz = true;

       if (m_pCurrentControl == NULL)
       {
          m_oLastError = string("The <ControlBitmap> tag must be inside of a "
                                "<XXXXControl> tag");
          return kError_InvalidParam;
       }

       if (oAttrMap.find("Rect") == oAttrMap.end())
       {
           m_oLastError = string("the <ControlBitmap> tag needs a Rect attribute");
           return kError_ParseError;
       }        
       if (oAttrMap.find("Name") == oAttrMap.end())
       {
           m_oLastError = string("the <ControlBitmap> tag needs a Name attribute");
           return kError_ParseError;
       }        
       
       if (oAttrMap.find("Style") != oAttrMap.end())
       {
           if (oAttrMap["Style"] == string("Vert"))
               bHoriz = false;
       }        

       eRet = ParseRect(oAttrMap["Rect"], oRect);
       if (eRet != kError_NoErr)
       {
           m_oLastError = string("Improperly formatted Rect coordinates: ") +
                                 oAttrMap["Rect"];
           return kError_InvalidParam;
       }

       pBitmap = FindBitmap(oAttrMap["Name"]);
       if (pBitmap == NULL)
       {
           m_oLastError = string("Undefined bitmap ") +
                          oAttrMap["Name"] +
                          string(" in tag <BackgroundBitmap>");
           return kError_InvalidParam;
       }

       m_pCurrentControl->SetBitmap(pBitmap, oRect, bHoriz);
       
       m_bBitmapDefined = true;
       
       return kError_NoErr;
    }

    if (oElement == string("Info"))
    {
       if (m_pCurrentControl == NULL)
       {
          m_oLastError = string("The <Info> tag must be inside of a "
                                "<XXXXControl> tag");
          return kError_InvalidParam;
       }

	   if (oAttrMap.find("Desc") != oAttrMap.end())
           m_pCurrentControl->SetDesc(oAttrMap["Desc"]);
	   if (oAttrMap.find("Tip") != oAttrMap.end())
           m_pCurrentControl->SetTip(oAttrMap["Tip"]);
       
       m_bInfoDefined = true;
       
       return kError_NoErr;
    }

    if (oElement == string("ThemeInfo"))
    {
       if (m_pCurrentControl != NULL)
       {
          m_oLastError = string("The <ThemeInfo> tag must be top level tag");
          return kError_InvalidParam;
       }

	   if (oAttrMap.find("Name") != oAttrMap.end())
           m_oThemeName = oAttrMap["Name"];
	   if (oAttrMap.find("Author") != oAttrMap.end())
           m_oThemeAuthor = oAttrMap["Author"];
	   if (oAttrMap.find("EMail") != oAttrMap.end())
           m_oAuthorEMail = oAttrMap["EMail"];
	   if (oAttrMap.find("WebPage") != oAttrMap.end())
           m_oAuthorWebPage = oAttrMap["WebPage"];
       
       return kError_NoErr;
    }

    m_oLastError = string("Invalid tag: ") + oElement;

    return kError_InvalidParam;
}

Error Theme::EndElement(string &oElement)
{
    if (oElement == string("Bitmap") ||
        oElement == string("BackgroundBitmap") ||
        oElement == string("Font") ||
        oElement == string("ChangeWindow") ||
        oElement == string("ThemeInfo") ||
        oElement == string("MaskBitmap"))
       return kError_NoErr;

    if (oElement == string("Controls"))
    {
       if (m_pCurrentWindow == NULL)
       {
           m_oLastError = string("The <Controls> tag must be inside a "
                                 "<Window> tag");
           return kError_InvalidParam;
       }
       return kError_NoErr;
    }

    if (oElement == string("Action") ||
        oElement == string("Position") ||
        oElement == string("Style") ||
        oElement == string("Info") ||
        oElement == string("ControlBitmap"))
    {
       if (m_pCurrentControl == NULL)
       {
           m_oLastError = string("The <") + 
                          oElement.c_str()+ 
                          string("> tag must be inside a <XXXXControl>");
           return kError_InvalidParam;
       }
       return kError_NoErr;
    }

    if (oElement == string("ButtonControl") ||
        oElement == string("DialControl") ||
        oElement == string("SliderControl") ||
        oElement == string("VSliderControl") ||
        oElement == string("MultiStateControl") ||
        oElement == string("TextControl")) 
    {
       if (!m_bPosDefined)
       {
           m_oLastError = string("The Control is missing the <Position> tag");
           return kError_InvalidParam;
       }
       if (!m_bBitmapDefined && m_eCurrentControl != eTextControl)
       {
           m_oLastError = string("The Control is missing the <ControlBitmap> tag");
           return kError_InvalidParam;
       }
       if (!m_bInfoDefined && m_eCurrentControl != eTextControl)
       {
           m_oLastError = string("The Control is missing the <Info> tag");
           return kError_InvalidParam;
       }
       if (m_eCurrentControl == eTextControl)
       {
       	   if (!((TextControl *)m_pCurrentControl)->StyleHasBeenSet())
           {
               m_oLastError = "A <TextControl> needs to define a <Style> tag";
               return kError_InvalidParam;
           }    
       }

       m_pCurrentWindow->AddControl(m_pCurrentControl);
       m_pCurrentControl = NULL;
       m_eCurrentControl = eUndefinedControl;

       return kError_NoErr;
    }

    if (oElement == string("Window"))
    {
       if (!m_pParsedWindows)
           m_pParsedWindows = new vector<Window *>;

       m_pParsedWindows->push_back(m_pCurrentWindow);
           
       m_pCurrentWindow = NULL;

       return kError_NoErr;
    }

    m_oLastError = string("Invalid close tag: ") + oElement;

    return kError_InvalidParam;
}    

Error Theme::PCData(string &oData)
{
    m_oLastError = string("Invalid character data: ") + oData;
    
    return kError_InvalidParam;
}

Bitmap *Theme::FindBitmap(string &oName)
{
    vector<Bitmap *>::iterator i;
    string                     oTemp;

	if (!m_pParsedBitmaps)
		return NULL;
        
    for(i = m_pParsedBitmaps->begin(); i != m_pParsedBitmaps->end(); i++)
    {
       (*i)->GetName(oTemp);
       if (oTemp == oName)
          return *i;
    }

    return NULL;
}

Font *Theme::FindFont(string &oName)
{
    vector<Font *>::iterator i;
    string                   oTemp;

	if (!m_pParsedFonts)
		return NULL;
        
    for(i = m_pParsedFonts->begin(); i != m_pParsedFonts->end(); i++)
    {
       (*i)->GetName(oTemp);
       if (oTemp == oName)
          return *i;
    }

    return NULL;
}

Error Theme::ParseRect(string &oRectstring, Rect &oRect)
{
    int iRet;

    iRet = sscanf(oRectstring.c_str(), " %d , %d , %d , %d",
             &oRect.x1, &oRect.y1, &oRect.x2, &oRect.y2);

    return (iRet == 4) ? kError_NoErr : kError_InvalidParam;
}

Error Theme::ParseColor(string &oColorstring, Color &oColor)
{
    int iRet;
    int iRed, iGreen, iBlue;

    iRet = sscanf(oColorstring.c_str(), "#%02X%02X%02X",
                  &iRed, &iGreen, &iBlue);

    if (iRet == 3)
    {
    	oColor.red = iRed;
        oColor.green = iGreen;
        oColor.blue = iBlue;
        return kError_NoErr;
    }     

    return kError_InvalidParam;
}

Error Theme::ParsePos(string &oPosstring, Pos &oPos)
{
    int iRet;

    iRet = sscanf(oPosstring.c_str(), " %d , %d",
    		&oPos.x, &oPos.y);

    return (iRet == 2) ? kError_NoErr : kError_InvalidParam;
}

void Theme::SetDefaultFont(const string &oFont)
{ 
	m_oDefaultFont = oFont;
}

void Theme::PostWindowCreate(void)
{
}

void Theme::ShowThemeCredits(void)
{
    string oText;

    if (m_bCreditsShown)
    {
       m_bCreditsShown = false;
       m_pWindow->ControlStringValue("Title", true, m_oSavedText);
       return;
    }
    
    m_pWindow->ControlStringValue("Title", false, m_oSavedText);
    if (m_oThemeName.size() > 0)
    {
        oText = m_oThemeName;
       
        if (m_oThemeAuthor.size() > 0)
           oText += string(" written by ") + m_oThemeAuthor;     

        if (m_oAuthorEMail.size() > 0)
           oText += string(", ") + m_oAuthorEMail;     

        if (m_oAuthorWebPage.size() > 0)
           oText += string(" (") + m_oAuthorWebPage + string(")");     
    }   
    else
       oText = "<No theme credit info available>";
       
    m_pWindow->ControlStringValue("Title", true, oText);
    m_bCreditsShown = true;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -