summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/graphics/engine/text.cpp35
-rw-r--r--src/graphics/engine/text.h8
-rw-r--r--src/ui/edit.cpp12
3 files changed, 38 insertions, 17 deletions
diff --git a/src/graphics/engine/text.cpp b/src/graphics/engine/text.cpp
index 424b99b..9dea129 100644
--- a/src/graphics/engine/text.cpp
+++ b/src/graphics/engine/text.cpp
@@ -149,6 +149,7 @@ void CText::FlushCache()
}
void CText::DrawText(const std::string &text, std::vector<FontMetaChar>::iterator format,
+ std::vector<FontMetaChar>::iterator end,
float size, Math::Point pos, float width, TextAlign align,
int eol, Color color)
{
@@ -156,18 +157,18 @@ void CText::DrawText(const std::string &text, std::vector<FontMetaChar>::iterato
if (align == TEXT_ALIGN_CENTER)
{
- sw = GetStringWidth(text, format, size);
+ sw = GetStringWidth(text, format, end, size);
if (sw > width) sw = width;
pos.x -= sw / 2.0f;
}
else if (align == TEXT_ALIGN_RIGHT)
{
- sw = GetStringWidth(text, format, size);
+ sw = GetStringWidth(text, format, end, size);
if (sw > width) sw = width;
pos.x -= sw;
}
- DrawString(text, format, size, pos, width, eol, color);
+ DrawString(text, format, end, size, pos, width, eol, color);
}
void CText::DrawText(const std::string &text, FontType font,
@@ -193,12 +194,13 @@ void CText::DrawText(const std::string &text, FontType font,
}
void CText::SizeText(const std::string &text, std::vector<FontMetaChar>::iterator format,
+ std::vector<FontMetaChar>::iterator endFormat,
float size, Math::Point pos, TextAlign align,
Math::Point &start, Math::Point &end)
{
start = end = pos;
- float sw = GetStringWidth(text, format, size);
+ float sw = GetStringWidth(text, format, endFormat, size);
end.x += sw;
if (align == TEXT_ALIGN_CENTER)
{
@@ -276,7 +278,8 @@ float CText::GetHeight(FontType font, float size)
float CText::GetStringWidth(const std::string &text,
- std::vector<FontMetaChar>::iterator format, float size)
+ std::vector<FontMetaChar>::iterator format,
+ std::vector<FontMetaChar>::iterator end, float size)
{
float width = 0.0f;
unsigned int index = 0;
@@ -284,8 +287,8 @@ float CText::GetStringWidth(const std::string &text,
while (index < text.length())
{
FontType font = FONT_COLOBOT;
- //if (format.size() > fmtIndex)
- font = static_cast<FontType>(format[fmtIndex] & FONT_MASK_FONT);
+ if (format + fmtIndex != end)
+ font = static_cast<FontType>(*(format + fmtIndex) & FONT_MASK_FONT);
UTF8Char ch;
@@ -343,6 +346,7 @@ float CText::GetCharWidth(UTF8Char ch, FontType font, float size, float offset)
int CText::Justify(const std::string &text, std::vector<FontMetaChar>::iterator format,
+ std::vector<FontMetaChar>::iterator end,
float size, float width)
{
float pos = 0.0f;
@@ -352,8 +356,8 @@ int CText::Justify(const std::string &text, std::vector<FontMetaChar>::iterator
while (index < text.length())
{
FontType font = FONT_COLOBOT;
- //if (format.size() > fmtIndex)
- font = static_cast<FontType>(format[fmtIndex] & FONT_MASK_FONT);
+ if (format + fmtIndex != end)
+ font = static_cast<FontType>(*(format + fmtIndex) & FONT_MASK_FONT);
UTF8Char ch;
@@ -427,6 +431,7 @@ int CText::Justify(const std::string &text, FontType font, float size, float wid
}
int CText::Detect(const std::string &text, std::vector<FontMetaChar>::iterator format,
+ std::vector<FontMetaChar>::iterator end,
float size, float offset)
{
float pos = 0.0f;
@@ -435,11 +440,12 @@ int CText::Detect(const std::string &text, std::vector<FontMetaChar>::iterator f
while (index < text.length())
{
FontType font = FONT_COLOBOT;
- //if (format.size() > fmtIndex)
- font = static_cast<FontType>(format[fmtIndex] & FONT_MASK_FONT);
+
+ if (format + fmtIndex != end)
+ font = static_cast<FontType>(*(format + fmtIndex) & FONT_MASK_FONT);
// TODO: if (font == FONT_BUTTON)
- if (font == FONT_BUTTON) continue;
+ //if (font == FONT_BUTTON) continue;
UTF8Char ch;
@@ -500,6 +506,7 @@ int CText::Detect(const std::string &text, FontType font, float size, float offs
}
void CText::DrawString(const std::string &text, std::vector<FontMetaChar>::iterator format,
+ std::vector<FontMetaChar>::iterator end,
float size, Math::Point pos, float width, int eol, Color color)
{
m_engine->SetState(ENG_RSTATE_TEXT);
@@ -513,8 +520,8 @@ void CText::DrawString(const std::string &text, std::vector<FontMetaChar>::itera
for (auto it = chars.begin(); it != chars.end(); ++it)
{
FontType font = FONT_COLOBOT;
- //if (format.size() > fmtIndex)
- font = static_cast<FontType>(format[fmtIndex] & FONT_MASK_FONT);
+ if (format + fmtIndex != end)
+ font = static_cast<FontType>(*(format + fmtIndex) & FONT_MASK_FONT);
// TODO: if (font == FONT_BUTTON)
if (font == FONT_BUTTON) continue;
diff --git a/src/graphics/engine/text.h b/src/graphics/engine/text.h
index d8e2aff..6bcc59b 100644
--- a/src/graphics/engine/text.h
+++ b/src/graphics/engine/text.h
@@ -242,6 +242,7 @@ public:
//! Draws text (multi-format)
void DrawText(const std::string &text, std::vector<FontMetaChar>::iterator format,
+ std::vector<FontMetaChar>::iterator end,
float size, Math::Point pos, float width, TextAlign align,
int eol, Color color = Color(0.0f, 0.0f, 0.0f, 1.0f));
//! Draws text (one font)
@@ -251,6 +252,7 @@ public:
//! Calculates dimensions for text (multi-format)
void SizeText(const std::string &text, std::vector<FontMetaChar>::iterator format,
+ std::vector<FontMetaChar>::iterator endFormat,
float size, Math::Point pos, TextAlign align,
Math::Point &start, Math::Point &end);
//! Calculates dimensions for text (one font)
@@ -267,7 +269,8 @@ public:
//! Returns width of string (multi-format)
TEST_VIRTUAL float GetStringWidth(const std::string &text,
- std::vector<FontMetaChar>::iterator format, float size);
+ std::vector<FontMetaChar>::iterator format,
+ std::vector<FontMetaChar>::iterator end, float size);
//! Returns width of string (single font)
TEST_VIRTUAL float GetStringWidth(const std::string &text, FontType font, float size);
//! Returns width of single character
@@ -275,12 +278,14 @@ public:
//! Justifies a line of text (multi-format)
int Justify(const std::string &text, std::vector<FontMetaChar>::iterator format,
+ std::vector<FontMetaChar>::iterator end,
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, std::vector<FontMetaChar>::iterator format,
+ std::vector<FontMetaChar>::iterator end,
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);
@@ -290,6 +295,7 @@ protected:
CharTexture CreateCharTexture(UTF8Char ch, CachedFont* font);
void DrawString(const std::string &text, std::vector<FontMetaChar>::iterator format,
+ std::vector<FontMetaChar>::iterator end,
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, Color color);
diff --git a/src/ui/edit.cpp b/src/ui/edit.cpp
index 64004bb..c0b6446 100644
--- a/src/ui/edit.cpp
+++ b/src/ui/edit.cpp
@@ -261,7 +261,7 @@ bool CEdit::EventProcess(const Event &event)
if ( event.type == EVENT_MOUSE_MOVE )
{
- if ( Detect(event.mousePos) &&
+ if ( Detect(event.mousePos) &&
event.mousePos.x < m_pos.x+m_dim.x-(m_bMulti?MARGX+SCROLL_WIDTH:0.0f) )
{
if ( m_bEdit )
@@ -560,7 +560,7 @@ bool CEdit::IsLinkPos(Math::Point pos)
if ( i == -1 ) return false;
if ( i >= m_len ) return false;
- if ( (m_format[i]& Gfx::FONT_MASK_HIGHLIGHT) == Gfx::FONT_HIGHLIGHT_LINK) return true; // TODO
+ if ( m_format.size() > i && ((m_format[i] & Gfx::FONT_MASK_HIGHLIGHT) == Gfx::FONT_HIGHLIGHT_LINK)) return true; // TODO
return false;
}
@@ -736,6 +736,7 @@ int CEdit::MouseDetect(Math::Point mouse)
// m_fontStretch);
c = m_engine->GetText()->Detect(std::string(m_text+m_lineOffset[i]).substr(0, len),
m_format.begin() + m_lineOffset[i],
+ m_format.end(),
size,
offset); // TODO check if good
}
@@ -1035,9 +1036,11 @@ void CEdit::Draw()
{
start.x = ppos.x+m_engine->GetText()->GetStringWidth(std::string(m_text+beg).substr(0, o1-beg),
m_format.begin() + beg,
+ m_format.end(),
size);
end.x = m_engine->GetText()->GetStringWidth(std::string(m_text+o1).substr(0, o2-o1),
m_format.begin() + o1,
+ m_format.end(),
size);
}
@@ -1066,6 +1069,7 @@ void CEdit::Draw()
{
m_engine->GetText()->DrawText(std::string(m_text+beg).substr(0, len),
m_format.begin() + beg,
+ m_format.end(),
size,
ppos,
m_dim.x,
@@ -1108,6 +1112,7 @@ void CEdit::Draw()
{
m_engine->GetText()->SizeText(std::string(m_text+m_lineOffset[i]).substr(0, len),
m_format.begin() + m_lineOffset[i],
+ m_format.end(),
size, pos, Gfx::TEXT_ALIGN_LEFT,
start, end);
}
@@ -2464,6 +2469,7 @@ void CEdit::MoveLine(int move, bool bWord, bool bSelect)
{
c = m_engine->GetText()->Detect(std::string(m_text+m_lineOffset[line]),
m_format.begin() + m_lineOffset[line],
+ m_format.end(),
m_fontSize,
m_lineOffset[line+1]-m_lineOffset[line]);
}
@@ -2495,6 +2501,7 @@ void CEdit::ColumnFix()
m_column = m_engine->GetText()->GetStringWidth(
std::string(m_text+m_lineOffset[line]),
m_format.begin() + m_lineOffset[line],
+ m_format.end(),
m_fontSize
);
}
@@ -3115,6 +3122,7 @@ void CEdit::Justif()
// TODO check if good
i += m_engine->GetText()->Justify(std::string(m_text+i),
m_format.begin() + i,
+ m_format.end(),
size,
width);
}