summaryrefslogtreecommitdiffstats
path: root/src/graphics
diff options
context:
space:
mode:
authoradiblol <adiblol@chommik.eu>2012-09-27 23:55:13 +0200
committeradiblol <adiblol@chommik.eu>2012-09-27 23:55:13 +0200
commit77952a85e63ca13dd9cfc93c7b6a271d7c91e59a (patch)
treeacec920fff5f86b2776bab9e1e4ea9921115ecaa /src/graphics
parent6d0ed0d26aebead7c79e4fb97c6962e06e7dcb41 (diff)
parent9f4c1454dc75d697b43a634927ebcfd6186a4e93 (diff)
downloadcolobot-77952a85e63ca13dd9cfc93c7b6a271d7c91e59a.tar.gz
colobot-77952a85e63ca13dd9cfc93c7b6a271d7c91e59a.tar.bz2
colobot-77952a85e63ca13dd9cfc93c7b6a271d7c91e59a.zip
Merge remote-tracking branch 'origin/dev' into dev-graphics
Diffstat (limited to 'src/graphics')
-rw-r--r--src/graphics/engine/text.cpp57
-rw-r--r--src/graphics/engine/text.h12
2 files changed, 47 insertions, 22 deletions
diff --git a/src/graphics/engine/text.cpp b/src/graphics/engine/text.cpp
index 00b6617..a77a6fd 100644
--- a/src/graphics/engine/text.cpp
+++ b/src/graphics/engine/text.cpp
@@ -149,7 +149,7 @@ void CText::FlushCache()
}
}
-void CText::DrawText(const std::string &text, const std::vector<FontMetaChar> &format,
+void CText::DrawText(const std::string &text, std::map<unsigned int, FontMetaChar> &format,
float size, Math::Point pos, float width, TextAlign align,
int eol)
{
@@ -193,7 +193,7 @@ void CText::DrawText(const std::string &text, FontType font,
DrawString(text, font, size, pos, width, eol);
}
-void CText::SizeText(const std::string &text, const std::vector<FontMetaChar> &format,
+void CText::SizeText(const std::string &text, std::map<unsigned int, FontMetaChar> &format,
float size, Math::Point pos, TextAlign align,
Math::Point &start, Math::Point &end)
{
@@ -277,16 +277,20 @@ float CText::GetHeight(FontType font, float size)
float CText::GetStringWidth(const std::string &text,
- const std::vector<FontMetaChar> &format, float size)
+ std::map<unsigned int, FontMetaChar> &format, float size)
{
- assert(StrUtils::Utf8StringLength(text) == format.size());
+ // TODO assert was commented as new code uses map not vector and if's size doesn't have to match text length
+ // this has to be tested if it's correct
+ //assert(StrUtils::Utf8StringLength(text) == format.size());
float width = 0.0f;
unsigned int index = 0;
unsigned int fmtIndex = 0;
while (index < text.length())
{
- FontType font = static_cast<FontType>(format[fmtIndex] & FONT_MASK_FONT);
+ FontType font = FONT_COLOBOT;
+ if (format.count(fmtIndex))
+ font = static_cast<FontType>(format[fmtIndex] & FONT_MASK_FONT);
UTF8Char ch;
@@ -343,10 +347,12 @@ float CText::GetCharWidth(UTF8Char ch, FontType font, float size, float offset)
}
-int CText::Justify(const std::string &text, const std::vector<FontMetaChar> &format,
+int CText::Justify(const std::string &text, std::map<unsigned int, FontMetaChar> &format,
float size, float width)
{
- assert(StrUtils::Utf8StringLength(text) == format.size());
+ // TODO assert was commented as new code uses map not vector and if's size doesn't have to match text length
+ // this has to be tested if it's correct
+ //assert(StrUtils::Utf8StringLength(text) == format.size());
float pos = 0.0f;
int cut = 0;
@@ -354,7 +360,9 @@ int CText::Justify(const std::string &text, const std::vector<FontMetaChar> &for
unsigned int fmtIndex = 0;
while (index < text.length())
{
- FontType font = static_cast<FontType>(format[fmtIndex] & FONT_MASK_FONT);
+ FontType font = FONT_COLOBOT;
+ if (format.count(fmtIndex))
+ font = static_cast<FontType>(format[fmtIndex] & FONT_MASK_FONT);
UTF8Char ch;
@@ -426,17 +434,21 @@ int CText::Justify(const std::string &text, FontType font, float size, float wid
return index;
}
-int CText::Detect(const std::string &text, const std::vector<FontMetaChar> &format,
+int CText::Detect(const std::string &text, std::map<unsigned int, FontMetaChar> &format,
float size, float offset)
{
- assert(StrUtils::Utf8StringLength(text) == format.size());
+ // TODO assert was commented as new code uses map not vector and if's size doesn't have to match text length
+ // this has to be tested if it's correct
+ //assert(StrUtils::Utf8StringLength(text) == format.size());
float pos = 0.0f;
unsigned int index = 0;
unsigned int fmtIndex = 0;
while (index < text.length())
{
- FontType font = static_cast<FontType>(format[fmtIndex] & FONT_MASK_FONT);
+ FontType font = FONT_COLOBOT;
+ if (format.count(fmtIndex))
+ font = static_cast<FontType>(format[fmtIndex] & FONT_MASK_FONT);
// TODO: if (font == FONT_BUTTON)
if (font == FONT_BUTTON) continue;
@@ -499,10 +511,12 @@ int CText::Detect(const std::string &text, FontType font, float size, float offs
return index;
}
-void CText::DrawString(const std::string &text, const std::vector<FontMetaChar> &format,
+void CText::DrawString(const std::string &text, std::map<unsigned int, FontMetaChar> &format,
float size, Math::Point pos, float width, int eol)
{
- assert(StrUtils::Utf8StringLength(text) == format.size());
+ // TODO assert was commented as new code uses map not vector and if's size doesn't have to match text length
+ // this has to be tested if it's correct
+ //assert(StrUtils::Utf8StringLength(text) == format.size());
m_engine->SetState(ENG_RSTATE_TEXT);
@@ -515,7 +529,9 @@ void CText::DrawString(const std::string &text, const std::vector<FontMetaChar>
StringToUTFCharList(text, chars);
for (auto it = chars.begin(); it != chars.end(); ++it)
{
- font = static_cast<FontType>(format[fmtIndex] & FONT_MASK_FONT);
+ FontType font = FONT_COLOBOT;
+ if (format.count(fmtIndex))
+ font = static_cast<FontType>(format[fmtIndex] & FONT_MASK_FONT);
// TODO: if (font == FONT_BUTTON)
if (font == FONT_BUTTON) continue;
@@ -674,6 +690,15 @@ 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;
+ }
auto it = cf->cache.find(ch);
CharTexture tex;
@@ -692,7 +717,7 @@ void CText::DrawCharAndAdjustPos(UTF8Char ch, FontType font, float size, Math::P
}
Math::Point p1(pos.x, pos.y + tex.charSize.y - tex.texSize.y);
- Math::Point p2(pos.x + tex.texSize.x, pos.y + tex.charSize.y);
+ Math::Point p2(pos.x + tex.texSize.x * width, pos.y + tex.charSize.y);
Math::Vector n(0.0f, 0.0f, -1.0f); // normal
@@ -708,7 +733,7 @@ void CText::DrawCharAndAdjustPos(UTF8Char ch, FontType font, float size, Math::P
m_device->DrawPrimitive(PRIMITIVE_TRIANGLE_STRIP, quad, 4);
m_engine->AddStatisticTriangle(2);
- pos.x += tex.charSize.x;
+ pos.x += tex.charSize.x * width;
}
CachedFont* CText::GetOrOpenFont(FontType font, float size)
diff --git a/src/graphics/engine/text.h b/src/graphics/engine/text.h
index bb9a32d..cc18f55 100644
--- a/src/graphics/engine/text.h
+++ b/src/graphics/engine/text.h
@@ -239,7 +239,7 @@ public:
void FlushCache();
//! Draws text (multi-format)
- void DrawText(const std::string &text, const std::vector<FontMetaChar> &format,
+ void DrawText(const std::string &text, std::map<unsigned int, FontMetaChar> &format,
float size, Math::Point pos, float width, TextAlign align,
int eol);
//! Draws text (one font)
@@ -248,7 +248,7 @@ public:
int eol);
//! Calculates dimensions for text (multi-format)
- void SizeText(const std::string &text, const std::vector<FontMetaChar> &format,
+ void SizeText(const std::string &text, std::map<unsigned int, FontMetaChar> &format,
float size, Math::Point pos, TextAlign align,
Math::Point &start, Math::Point &end);
//! Calculates dimensions for text (one font)
@@ -265,20 +265,20 @@ public:
//! Returns width of string (multi-format)
float GetStringWidth(const std::string &text,
- const std::vector<FontMetaChar> &format, float size);
+ std::map<unsigned int, FontMetaChar> &format, float size);
//! Returns width of string (single font)
float GetStringWidth(const std::string &text, FontType font, float size);
//! Returns width of single character
float GetCharWidth(UTF8Char ch, FontType font, float size, float offset);
//! Justifies a line of text (multi-format)
- int Justify(const std::string &text, const std::vector<FontMetaChar> &format,
+ int Justify(const std::string &text, std::map<unsigned int, FontMetaChar> &format,
float size, float width);
//! Justifies a line of text (one font)
int Justify(const std::string &text, FontType font, float size, float width);
//! Returns the most suitable position to a given offset (multi-format)
- int Detect(const std::string &text, const std::vector<FontMetaChar> &format,
+ int Detect(const std::string &text, std::map<unsigned int, FontMetaChar> &format,
float size, float offset);
//! Returns the most suitable position to a given offset (one font)
int Detect(const std::string &text, FontType font, float size, float offset);
@@ -287,7 +287,7 @@ protected:
CachedFont* GetOrOpenFont(FontType type, float size);
CharTexture CreateCharTexture(UTF8Char ch, CachedFont* font);
- void DrawString(const std::string &text, const std::vector<FontMetaChar> &format,
+ void DrawString(const std::string &text, std::map<unsigned int, FontMetaChar> &format,
float size, Math::Point pos, float width, int eol);
void DrawString(const std::string &text, FontType font,
float size, Math::Point pos, float width, int eol);