Esempio n. 1
0
MyGUI::IntSize CalcTextWidth( MyGUI::UString text,string font ){
	MyGUI::FontManager* pfm = MyGUI::FontManager::getInstancePtr();
	MyGUI::IFont* pf = pfm->getByName(font);
	MyGUI::IntSize size;
	size.height = pf->getDefaultHeight();
	if( pf ){
		for( MyGUI::UString::iterator i=text.begin();i!=text.end();++i ){
			MyGUI::GlyphInfo* pg = pf->getGlyphInfo(*i);
			if( pg ){
				size.width += (int)pg->width;
			}
		}
	}
	return size;
}
Esempio n. 2
0
		//--------------------------------------------------------------------------------
		void	Chat::_Log(const MyGUI::UString& str, const MyGUI::UString& color)
		{
			while(mList->getItemCount() > 200)
				mList->removeItemAt(0);

			std::wstring tmp;

			std::vector<std::wstring> lines;
			lines.clear();

			MyGUI::IFont* font = MyGUI::FontManager::getInstance().getByName(MyGUI::FontManager::getInstance().getDefaultFont());

			int ctr = 0;

			for(size_t i = 0; i < str.size(); i++)
			{
				if(ctr + font->getGlyphInfo((int)str[i])->width > mList->getWidth() - 35)
				{
					ctr = 0;

					if(str[i] != L' ')
						tmp.push_back(L'-');
					else
						while(str[i] == L' ' && i < str.size()){i++;}

						lines.push_back(tmp);
						tmp.clear();
				}

				tmp.push_back(str[i]);

				ctr += font->getGlyphInfo((int)str[i])->width;

				if (i >= str.size() - 1)
				{
					ctr = 0;
					lines.push_back(tmp);
					tmp.clear();
				}
			}

			for (unsigned int i = 0 ; i < lines.size() ; i++)
			{
				if (i == 0)
				{
					std::wstring toAdd;
					toAdd += lines[i].substr(0, lines[i].find(L":") + 1);
					toAdd += color;
					toAdd += lines[i].substr(lines[i].find(L":") + 1, lines[i].size());

					mList->addItem(toAdd);
				}
				else
				{
					std::wstring toAdd = color;
					toAdd += lines[i];
					mList->addItem(toAdd);
				}
			}

			mList->beginToItemLast();
		}