From 8ea4736a46f1a468ee214528ba539e1f505b8273 Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Sun, 30 Sep 2012 10:56:35 +0200 Subject: Font coloring; fix for resize hack - added font coloring and changed default color to black - fixed resize hack incorrectly changing video config, but font resizing will not work for now --- src/graphics/engine/engine.cpp | 8 +++++--- src/graphics/engine/text.cpp | 32 ++++++++++++++++---------------- src/graphics/engine/text.h | 16 +++++++++------- 3 files changed, 30 insertions(+), 26 deletions(-) (limited to 'src/graphics/engine') diff --git a/src/graphics/engine/engine.cpp b/src/graphics/engine/engine.cpp index 7e00134..5bd9227 100644 --- a/src/graphics/engine/engine.cpp +++ b/src/graphics/engine/engine.cpp @@ -333,6 +333,8 @@ void CEngine::Destroy() void CEngine::ResetAfterDeviceChanged() { + m_text->FlushCache(); + // TODO reload textures, reset device state, etc. } @@ -3891,7 +3893,7 @@ void CEngine::DrawStats() std::string triangleText = str.str(); float height = m_text->GetAscent(FONT_COLOBOT, 12.0f); - float width = 0.15f; + float width = 0.2f; Math::Point pos(0.04f, 0.04f + height); @@ -3911,11 +3913,11 @@ void CEngine::DrawStats() SetState(ENG_RSTATE_TEXT); - m_text->DrawText(triangleText, FONT_COLOBOT, 12.0f, pos, 1.0f, TEXT_ALIGN_LEFT, 0); + m_text->DrawText(triangleText, FONT_COLOBOT, 12.0f, pos, 1.0f, TEXT_ALIGN_LEFT, 0, Color(1.0f, 1.0f, 1.0f, 1.0f)); pos.y -= height; - m_text->DrawText(m_fpsText, FONT_COLOBOT, 12.0f, pos, 1.0f, TEXT_ALIGN_LEFT, 0); + m_text->DrawText(m_fpsText, FONT_COLOBOT, 12.0f, pos, 1.0f, TEXT_ALIGN_LEFT, 0, Color(1.0f, 1.0f, 1.0f, 1.0f)); } diff --git a/src/graphics/engine/text.cpp b/src/graphics/engine/text.cpp index 9091905..6355aed 100644 --- a/src/graphics/engine/text.cpp +++ b/src/graphics/engine/text.cpp @@ -151,7 +151,7 @@ void CText::FlushCache() void CText::DrawText(const std::string &text, std::map &format, float size, Math::Point pos, float width, TextAlign align, - int eol) + int eol, Color color) { float sw = 0.0f; @@ -168,12 +168,12 @@ void CText::DrawText(const std::string &text, std::map &format, @@ -500,7 +500,7 @@ int CText::Detect(const std::string &text, FontType font, float size, float offs } void CText::DrawString(const std::string &text, std::map &format, - float size, Math::Point pos, float width, int eol) + float size, Math::Point pos, float width, int eol, Color color) { m_engine->SetState(ENG_RSTATE_TEXT); @@ -538,7 +538,7 @@ void CText::DrawString(const std::string &text, std::map & } void CText::DrawString(const std::string &text, FontType font, - float size, Math::Point pos, float width, int eol) + float size, Math::Point pos, float width, int eol, Color color) { assert(font != FONT_BUTTON); @@ -579,7 +579,7 @@ void CText::DrawString(const std::string &text, FontType font, StringToUTFCharList(text, chars); for (auto it = chars.begin(); it != chars.end(); ++it) { - DrawCharAndAdjustPos(*it, font, size, pos); + DrawCharAndAdjustPos(*it, font, size, pos, color); } } @@ -663,7 +663,7 @@ void CText::DrawHighlight(FontHighlight hl, Math::Point pos, Math::Point size) m_device->SetTextureEnabled(0, true); } -void CText::DrawCharAndAdjustPos(UTF8Char ch, FontType font, float size, Math::Point &pos) +void CText::DrawCharAndAdjustPos(UTF8Char ch, FontType font, float size, Math::Point &pos, Color color) { // TODO: if (font == FONT_BUTTON) if (font == FONT_BUTTON) return; @@ -674,14 +674,14 @@ void CText::DrawCharAndAdjustPos(UTF8Char ch, FontType font, float size, Math::P if (cf == nullptr) return; - + int width = 1; if (ch.c1 < 32) { // FIXME add support for chars with code 9 10 23 - ch.c1 = ' '; - ch.c2 = 0; - ch.c3 = 0; - if (ch.c1 == '\t') - width = 4; + ch.c1 = ' '; + ch.c2 = 0; + ch.c3 = 0; + if (ch.c1 == '\t') + width = 4; } auto it = cf->cache.find(ch); @@ -714,7 +714,7 @@ void CText::DrawCharAndAdjustPos(UTF8Char ch, FontType font, float size, Math::P }; m_device->SetTexture(0, tex.id); - m_device->DrawPrimitive(PRIMITIVE_TRIANGLE_STRIP, quad, 4); + m_device->DrawPrimitive(PRIMITIVE_TRIANGLE_STRIP, quad, 4, color); m_engine->AddStatisticTriangle(2); pos.x += tex.charSize.x * width; diff --git a/src/graphics/engine/text.h b/src/graphics/engine/text.h index 7fa8768..4575c37 100644 --- a/src/graphics/engine/text.h +++ b/src/graphics/engine/text.h @@ -23,6 +23,8 @@ #pragma once +#include "graphics/core/color.h" + #include "math/point.h" #include @@ -39,9 +41,9 @@ class CEngine; class CDevice; //! Standard small font size -const float FONT_SIZE_SMALL = 10.0f; +const float FONT_SIZE_SMALL = 12.0f; //! Standard big font size -const float FONT_SIZE_BIG = 15.0f; +const float FONT_SIZE_BIG = 18.0f; /** * \enum TextAlign @@ -244,11 +246,11 @@ public: //! Draws text (multi-format) void DrawText(const std::string &text, std::map &format, float size, Math::Point pos, float width, TextAlign align, - int eol); + int eol, Color color = Color(0.0f, 0.0f, 0.0f, 1.0f)); //! Draws text (one font) void DrawText(const std::string &text, FontType font, float size, Math::Point pos, float width, TextAlign align, - int eol); + int eol, Color color = Color(0.0f, 0.0f, 0.0f, 1.0f)); //! Calculates dimensions for text (multi-format) void SizeText(const std::string &text, std::map &format, @@ -291,11 +293,11 @@ protected: CharTexture CreateCharTexture(UTF8Char ch, CachedFont* font); void DrawString(const std::string &text, std::map &format, - float size, Math::Point pos, float width, int eol); + float size, Math::Point pos, float width, int eol, Color color); void DrawString(const std::string &text, FontType font, - float size, Math::Point pos, float width, int eol); + float size, Math::Point pos, float width, int eol, Color color); void DrawHighlight(FontHighlight hl, Math::Point pos, Math::Point size); - void DrawCharAndAdjustPos(UTF8Char ch, FontType font, float size, Math::Point &pos); + void DrawCharAndAdjustPos(UTF8Char ch, FontType font, float size, Math::Point &pos, Color color); void StringToUTFCharList(const std::string &text, std::vector &chars); protected: -- cgit v1.2.3-1-g7c22