コード例 #1
0
void ColouredRenderedStringParser::appendRenderedText(CEGUI::RenderedString& rs, const CEGUI::String& text) const
{
	size_t cpos = 0;
	// split the given string into lines based upon the newline character
	while (text.length() > cpos) {
		// find next newline
		const size_t nlpos = text.find('\n', cpos);
		// calculate length of this substring
		const size_t len = ((nlpos != CEGUI::String::npos) ? nlpos : text.length()) - cpos;

		// construct new text component and append it.
		if (len > 0) {
			//If we're using colours different from those of the default colours we'll also use our own implementation which doesn't do modulation.
			if (d_initialColours.d_bottom_left != d_colours.d_bottom_left || d_initialColours.d_top_left != d_colours.d_top_left || d_initialColours.d_top_right != d_colours.d_top_right || d_initialColours.d_bottom_right != d_colours.d_bottom_right) {
				RenderedColourStringTextComponent rtc(text.substr(cpos, len), d_fontName);
				rtc.setPadding(d_padding);
				rtc.setColours(d_colours);
				rtc.setVerticalFormatting(d_vertAlignment);
				rtc.setAspectLock(d_aspectLock);
				rs.appendComponent(rtc);
			} else {
				CEGUI::RenderedStringTextComponent rtc(text.substr(cpos, len), d_fontName);
				rtc.setPadding(d_padding);
				rtc.setColours(d_colours);
				rtc.setVerticalFormatting(d_vertAlignment);
				rtc.setAspectLock(d_aspectLock);
				rs.appendComponent(rtc);
			}
		}

		// break line if needed
		if (nlpos != CEGUI::String::npos)
			rs.appendLineBreak();

		// advance current position.  +1 to skip the \n char
		cpos += len + 1;
	}
}
コード例 #2
0
//------------------------------------------------------------------------
bool WindowContext::AcceptsWindowAsChild() const
{
    // Validations
    wxASSERT_MSG(m_pWindow != NULL, wxT("Window member is NULL"));

    const CEGUI::String strWindowType = m_pWindow->getType();

    // These require different parent / child handling.
    // The current type must not be equal to the checks below
    // Because of the "find" instead of exact matches, it works for different
    // looknfeels, e.g. both "TaharezLook/Combobox" and "Windowslook/Combobox".
    return strWindowType.find("Combobox") == CEGUI::String::npos &&
        strWindowType.find("ComboDropList") == CEGUI::String::npos &&
        strWindowType.find("ListHeader") == CEGUI::String::npos &&
        strWindowType.find("Combobox") == CEGUI::String::npos &&
        strWindowType.find("ListBox") == CEGUI::String::npos &&
        strWindowType.find("MultiColumnList");
}
コード例 #3
0
CEGUI::String LinkButtonParser::Parse(const CEGUI::String &str)
{
    std::string szStr = CEGUIStringToAnsiChar( str );

    size_t parentWinPos,IDPos,TextPos,ColorPos,endPos;
    parentWinPos = IDPos = TextPos = ColorPos = endPos = CEGUI::String::npos;
    char ParentWinName[128] = "";
    char LinkID[32] = "";
    char LinkText[128] = "";
    char ColorVal[32] = "";
    parentWinPos = str.find("WIN:");
    IDPos        = str.find("ID:");
    TextPos      = str.find("TEXT:");
    ColorPos     = str.find("COLOR:");
    std::string  wndName("LinkBtn_"),temp;
    static DWORD LinkWndCounter = 0;
    wndName += CEGUI::PropertyHelper::intToString(LinkWndCounter++).c_str();

    CEGUI::Window *linkWnd = 0;
    if (CEGUI::WindowManager::getSingleton().isWindowPresent(wndName) == false)
    {
        linkWnd = CEGUI::WindowManager::getSingleton().createWindow("TaharezLook/Button",wndName);
        linkWnd->subscribeEvent(CEGUI::PushButton::EventClicked,CEGUI::Event::Subscriber(&LinkButtonParser::OnLinkBtnClicked,this));
        //解析父窗口
        if (parentWinPos != CEGUI::String::npos)
        {
            temp = szStr.substr(parentWinPos+5);
            endPos = temp.find("'");
            strcpy_s<128>(ParentWinName,temp.substr(0,endPos).c_str());
            CEGUI::Window *pParentWnd = CEGUI::WindowManager::getSingleton().getWindow(ParentWinName);
            pParentWnd->addChildWindow(linkWnd);
        }
        //解析ID
        if (IDPos != CEGUI::String::npos)
        {
            temp = szStr.substr(IDPos+3);
            endPos = temp.find(" ");
            strcpy_s<32>(LinkID,temp.substr(0,endPos).c_str());
            LinkMap[linkWnd] = LinkID;
        }
        //解析链接按钮文本
        if (TextPos !=  CEGUI::String::npos)
        {
            temp = szStr.substr(TextPos+6);
            endPos = temp.find("'");
            strcpy_s<128>(LinkText,temp.substr(0,endPos).c_str());
            float fWidth  = linkWnd->getFont()->getTextExtent(LinkText);
            float fheight = linkWnd->getFont()->getFontHeight();
            linkWnd->setSize(CEGUI::UVector2(cegui_absdim(fWidth),cegui_absdim(fheight)));
            //解析链接按钮文本的颜色
            if (ColorPos != CEGUI::String::npos)
            {
                temp = szStr.substr(ColorPos+6);
                endPos = temp.find(" ");
                strcpy_s(ColorVal,temp.substr(0,endPos).c_str());
                temp = "[COLOR ";
                temp += ColorVal;
                temp += "]";
                temp += CEGUI::String(LinkText).c_str();
                linkWnd->setText(ToCEGUIString(temp.c_str()));
            }
            else
                linkWnd->setText(ToCEGUIString(LinkText));
        }
    }
    return wndName;
}