void FontTextureController::updateTexture(const std::string& _value)
	{
		MyGUI::IResource* resource = MyGUI::ResourceManager::getInstance().findByName(_value);
		MyGUI::ResourceTrueTypeFont* font = resource != nullptr ? resource->castType<MyGUI::ResourceTrueTypeFont>(false) : nullptr;
		
		MyGUI::ITexture* texture = font != nullptr ? font->getTextureFont() : nullptr;
		std::string value = texture != nullptr ? texture->getName() : "";

		mControl->setTextureValue(value);
		mControl->resetTextureRegion();
	}
Пример #2
0
 void CopySubSkin::_setUVSet(const MyGUI::FloatRect &_rect) {
     MyGUI::FloatRect r;
     if (!mRenderItem) return;
     MyGUI::ITexture* tex = getTexture();
     if (tex) {
         int left = mCoord.left;
         int top = mCoord.top;
         r.set(float(left)/tex->getWidth(),
               float(top)/tex->getHeight(),
               float(left+mCoord.width)/tex->getWidth(),
               float(top+mCoord.height)/tex->getHeight());
         Base::_setUVSet(r);
     }
 }
	void FontTextureController::updateResultPropery(DataPtr _data)
	{
		MyGUI::IResource* resource = MyGUI::ResourceManager::getInstance().findByName(_data->getPropertyValue("FontName"));
		MyGUI::ResourceTrueTypeFont* font = resource != nullptr ? resource->castType<MyGUI::ResourceTrueTypeFont>(false) : nullptr;
		MyGUI::ITexture* texture = font != nullptr ? font->getTextureFont() : nullptr;

		if (texture != nullptr)
			_data->setPropertyValue("TextureSizeResult", MyGUI::utility::toString(texture->getWidth(), " ", texture->getHeight()));
		else
			_data->setPropertyValue("TextureSizeResult", "0 0");

		if (font != nullptr)
			_data->setPropertyValue("FontHeightPix", font->getDefaultHeight());
		else
			_data->setPropertyValue("FontHeightPix", "0");
	}
Пример #4
0
	void FontPanel::notifyMouseButtonClick(MyGUI::Widget* _widget)
	{
		// шрифто?нету
		if (mComboFont->getOnlyText().empty()) return;
		if (mEditSaveFileName->getOnlyText().empty() && _widget == mButtonSave) return;

		MyGUI::xml::Document document;
		document.createDeclaration();
		MyGUI::xml::ElementPtr root = document.createRoot("MyGUI");
		generateFontTTFXml(root);

		if (_widget == mButtonSave)
		{
			if (!document.save(mEditSaveFileName->getOnlyText() + ".xml"))
			{
				/*MyGUI::Message* message =*/ MyGUI::Message::createMessageBox("Message", "error", document.getLastError(), MyGUI::MessageBoxStyle::Ok | MyGUI::MessageBoxStyle::IconError);
			}
			else
			{
				/*MyGUI::Message* message =*/ MyGUI::Message::createMessageBox("Message", "success", mEditSaveFileName->getOnlyText() + ".xml", MyGUI::MessageBoxStyle::Ok | MyGUI::MessageBoxStyle::IconInfo);
			}

			MyGUI::IFont* font = MyGUI::FontManager::getInstance().getByName(mFontName);
			MyGUI::ITexture* texture = font->getTextureFont();
			texture->saveToFile(mEditSaveFileName->getOnlyText() + ".png");
		}
		else if (_widget == mButtonGenerate)
		{
			MyGUI::ResourceManager& manager = MyGUI::ResourceManager::getInstance();
			if (manager.isExist(mFontName))
			{
				manager.removeByName(mFontName);
			}

			MyGUI::ResourceManager::getInstance().loadFromXmlNode(root, "", MyGUI::Version());
			MyGUI::IResource* resource = manager.getByName(mFontName, false);
			MYGUI_ASSERT(resource != nullptr, "Could not find font '" << mFontName << "'");
			MyGUI::IFont* font = resource->castType<MyGUI::IFont>();

			// выво?реальног?размер?шрифта
			mFontHeight = font->getDefaultHeight();
			mTextPix->setCaption(MyGUI::utility::toString("Height of a font is ", mFontHeight, " pixels"));

			mFontView->setFontName(mFontName);
			mTextureView->setFontName(mFontName);
		}
	}
Пример #5
0
	void addCode(MyGUI::xml::Element* _node, MyGUI::Char _code, MyGUI::ResourceTrueTypeFont* _font, bool _isSubstitute)
	{
		MyGUI::xml::Element* codeNode = _node->createChild("Code");

		if (!_isSubstitute)
		{
			switch (_code)
			{
			case MyGUI::FontCodeType::Selected:
				codeNode->addAttribute("index", "selected");
				break;

			case MyGUI::FontCodeType::SelectedBack:
				codeNode->addAttribute("index", "selected_back");
				break;

			case MyGUI::FontCodeType::Cursor:
				codeNode->addAttribute("index", "cursor");
				break;

			default:
				codeNode->addAttribute("index", _code);
				break;
			}
		}
		else
		{
			codeNode->addAttribute("index", "substitute");
		}

		MyGUI::GlyphInfo* info = _font->getGlyphInfo(_code);
		MyGUI::ITexture* texture = _font->getTextureFont();
		MyGUI::FloatCoord coord(info->uvRect.left * (float)texture->getWidth(), info->uvRect.top * (float)texture->getHeight(), info->width, info->height);

		if (!coord.empty())
			codeNode->addAttribute("coord", coord);

		if (info->bearingX != 0.0f || info->bearingY != 0.0f)
			codeNode->addAttribute("bearing", MyGUI::FloatPoint(info->bearingX, info->bearingY));

		if (info->advance != info->width)
			codeNode->addAttribute("advance", info->advance);
	}
Пример #6
0
	void FontExportSerializer::generateFontManualXml(MyGUI::xml::ElementPtr _root, const MyGUI::UString& _folderName, DataPtr _data)
	{
		MyGUI::IFont* resource = MyGUI::FontManager::getInstance().getByName(_data->getPropertyValue("FontName"));
		MyGUI::ResourceTrueTypeFont* font = resource != nullptr ? resource->castType<MyGUI::ResourceTrueTypeFont>(false) : nullptr;

		if (font != nullptr)
		{
			std::string textureName = _data->getPropertyValue("Name") + ".png";
			MyGUI::ITexture* texture = font->getTextureFont();
			if (texture == nullptr)
				return;
			texture->saveToFile(MyGUI::UString(common::concatenatePath(_folderName, MyGUI::UString(textureName))).asUTF8());

			MyGUI::xml::ElementPtr node = _root->createChild("Resource");
			node->addAttribute("type", "ResourceManualFont");
			node->addAttribute("name", _data->getPropertyValue("Name"));

			addProperty(node, "Source", textureName);
			addProperty(node, "SourceSize", MyGUI::IntSize(texture->getWidth(), texture->getHeight()));
			addProperty(node, "DefaultHeight", font->getDefaultHeight());

			MyGUI::xml::Element* codes = node->createChild("Codes");

			std::vector<std::pair<MyGUI::Char, MyGUI::Char> > codePointRanges = font->getCodePointRanges();
			MyGUI::Char substituteCodePoint = font->getSubstituteCodePoint();
			bool isCustomSubstituteCodePoint = substituteCodePoint != MyGUI::FontCodeType::NotDefined;

			// Add all of the code points. Skip over the substitute code point -- unless it's been customized, in which case it
			// needs to be added here as a regular code point and then at the end as a substitute code point.
			for (std::vector<std::pair<MyGUI::Char, MyGUI::Char> >::const_iterator iter = codePointRanges.begin() ; iter != codePointRanges.end(); ++iter)
				for (MyGUI::Char code = iter->first; code <= iter->second && code >= iter->first; ++code)
					if (code != substituteCodePoint || isCustomSubstituteCodePoint)
						addCode(codes, code, font, false);

			// Always add the substitute code point last, even if it isn't the last one in the range.
			addCode(codes, substituteCodePoint, font, true);
		}
	}
Пример #7
0
	void FontPanel::saveTexture(const std::string& _fontName, const std::string& _fileName)
	{
		MyGUI::IFont* font = MyGUI::FontManager::getInstance().getByName(_fontName);
		MyGUI::ITexture* texture = font->getTextureFont();
		texture->saveToFile(_fileName);
	}