diff --git a/src/graphics/engine/text.cpp b/src/graphics/engine/text.cpp index 4fcf4acc..aece13e9 100644 --- a/src/graphics/engine/text.cpp +++ b/src/graphics/engine/text.cpp @@ -720,43 +720,42 @@ void CText::DrawString(const std::string &text, std::vector::itera Color c = color; FontHighlight hl = static_cast(format[fmtIndex] & FONT_MASK_HIGHLIGHT); - if (hl != FONT_HIGHLIGHT_NONE) + if (hl == FONT_HIGHLIGHT_TOKEN) { - if (hl == FONT_HIGHLIGHT_TOKEN) - { - c = Color(0.490f, 0.380f, 0.165f, 1.0f); // #7D612A - } - else if (hl == FONT_HIGHLIGHT_TYPE) - { - c = Color(0.31f, 0.443f, 0.196f, 1.0f); // #4F7132 - } - else if (hl == FONT_HIGHLIGHT_CONST) - { - c = Color(0.882f, 0.176f, 0.176f, 1.0f); // #E12D2D - } - else if (hl == FONT_HIGHLIGHT_THIS) - { - c = Color(0.545f, 0.329f, 0.608f, 1.0f); // #8B549B - } - else if (hl == FONT_HIGHLIGHT_COMMENT) - { - c = Color(0.251f, 0.271f, 0.306f, 1.0f); // #40454E - } - else if (hl == FONT_HIGHLIGHT_KEYWORD) - { - c = Color(0.239f, 0.431f, 0.588f, 1.0f); // #3D6E96 - } - else if (hl == FONT_HIGHLIGHT_STRING) - { - c = Color(0.239f, 0.384f, 0.341f, 1.0f); // #3D6257 - } - else - { - Math::IntPoint charSize; - charSize.x = GetCharWidthInt(ch, font, size, offset); - charSize.y = GetHeightInt(font, size); - DrawHighlight(hl, pos, charSize); - } + c = Color(0.490f, 0.380f, 0.165f, 1.0f); // #7D612A + } + else if (hl == FONT_HIGHLIGHT_TYPE) + { + c = Color(0.31f, 0.443f, 0.196f, 1.0f); // #4F7132 + } + else if (hl == FONT_HIGHLIGHT_CONST) + { + c = Color(0.882f, 0.176f, 0.176f, 1.0f); // #E12D2D + } + else if (hl == FONT_HIGHLIGHT_THIS) + { + c = Color(0.545f, 0.329f, 0.608f, 1.0f); // #8B549B + } + else if (hl == FONT_HIGHLIGHT_COMMENT) + { + c = Color(0.251f, 0.271f, 0.306f, 1.0f); // #40454E + } + else if (hl == FONT_HIGHLIGHT_KEYWORD) + { + c = Color(0.239f, 0.431f, 0.588f, 1.0f); // #3D6E96 + } + else if (hl == FONT_HIGHLIGHT_STRING) + { + c = Color(0.239f, 0.384f, 0.341f, 1.0f); // #3D6257 + } + + // draw highlight background or link underline + if (font != FONT_BUTTON) + { + Math::IntPoint charSize; + charSize.x = GetCharWidthInt(ch, font, size, offset); + charSize.y = GetHeightInt(font, size); + DrawHighlight(format[fmtIndex], pos, charSize); } DrawCharAndAdjustPos(ch, font, size, pos, c); @@ -854,26 +853,25 @@ void CText::DrawString(const std::string &text, FontType font, } } -void CText::DrawHighlight(FontHighlight hl, Math::IntPoint pos, Math::IntPoint size) +void CText::DrawHighlight(FontMetaChar hl, Math::IntPoint pos, Math::IntPoint size) { // Gradient colors Color grad[4]; // TODO: switch to alpha factors - switch (hl) + if ((hl & FONT_MASK_LINK) != 0) { - case FONT_HIGHLIGHT_LINK: - grad[0] = grad[1] = grad[2] = grad[3] = Color(0.0f, 0.0f, 1.0f, 0.5f); - break; - - case FONT_HIGHLIGHT_KEY: - grad[0] = grad[1] = grad[2] = grad[3] = - Color(192.0f / 256.0f, 192.0f / 256.0f, 192.0f / 256.0f, 0.5f); - break; - - default: - return; + grad[0] = grad[1] = grad[2] = grad[3] = Color(0.0f, 0.0f, 1.0f, 0.5f); + } + else if ((hl & FONT_MASK_HIGHLIGHT) == FONT_HIGHLIGHT_KEY) + { + grad[0] = grad[1] = grad[2] = grad[3] = + Color(192.0f / 256.0f, 192.0f / 256.0f, 192.0f / 256.0f, 0.5f); + } + else + { + return; } Math::IntPoint vsize = m_engine->GetWindowSize(); @@ -889,7 +887,7 @@ void CText::DrawHighlight(FontHighlight hl, Math::IntPoint pos, Math::IntPoint s p2.x = pos.x + size.x; p2.y = pos.y; - if (hl == FONT_HIGHLIGHT_LINK) + if ((hl & FONT_MASK_LINK) != 0) { p1.y = pos.y - h; // just emphasized } diff --git a/src/graphics/engine/text.h b/src/graphics/engine/text.h index 909dada5..f6414c00 100644 --- a/src/graphics/engine/text.h +++ b/src/graphics/engine/text.h @@ -118,7 +118,6 @@ enum FontTitle enum FontHighlight { FONT_HIGHLIGHT_NONE = 0x00 << 6, - FONT_HIGHLIGHT_LINK = 0x01 << 6, //!< link underline FONT_HIGHLIGHT_TABLE = 0x02 << 6, //!< code background in SatCom FONT_HIGHLIGHT_KEY = 0x03 << 6, //!< background for keys in documentation in SatCom FONT_HIGHLIGHT_TOKEN = 0x04 << 6, //!< keywords in CBot scripts @@ -142,8 +141,10 @@ enum FontMask FONT_MASK_TITLE = 0x030, //! Mask for FontHighlight FONT_MASK_HIGHLIGHT = 0x3c0, + //! Mask for links + FONT_MASK_LINK = 0x400, //! Mask for image bit (TODO: not used?) - FONT_MASK_IMAGE = 0x400 + FONT_MASK_IMAGE = 0x800 }; @@ -324,7 +325,7 @@ protected: float size, Math::IntPoint pos, int width, int eol, Color color); void DrawString(const std::string &text, FontType font, float size, Math::IntPoint pos, int width, int eol, Color color); - void DrawHighlight(FontHighlight hl, Math::IntPoint pos, Math::IntPoint size); + void DrawHighlight(FontMetaChar hl, Math::IntPoint pos, Math::IntPoint size); void DrawCharAndAdjustPos(UTF8Char ch, FontType font, float size, Math::IntPoint &pos, Color color); void StringToUTFCharList(const std::string &text, std::vector &chars); void StringToUTFCharList(const std::string &text, std::vector &chars, std::vector::iterator format, std::vector::iterator end); diff --git a/src/ui/controls/edit.cpp b/src/ui/controls/edit.cpp index c46d5b0b..c50f9796 100644 --- a/src/ui/controls/edit.cpp +++ b/src/ui/controls/edit.cpp @@ -564,7 +564,7 @@ bool CEdit::IsLinkPos(Math::Point pos) if ( i == -1 ) return false; if ( i >= m_len ) return false; - if ( m_format.size() > static_cast(i) && ((m_format[i] & Gfx::FONT_MASK_HIGHLIGHT) == Gfx::FONT_HIGHLIGHT_LINK)) return true; // TODO + if ( m_format.size() > static_cast(i) && ((m_format[i] & Gfx::FONT_MASK_LINK) != 0)) return true; // TODO return false; } @@ -637,13 +637,13 @@ void CEdit::MouseRelease(Math::Point mouse) if ( !m_bEdit ) { if ( m_format.size() > 0 && i < m_len && m_cursor1 == m_cursor2 && - (m_format[i]&Gfx::FONT_MASK_HIGHLIGHT) == Gfx::FONT_HIGHLIGHT_LINK) //TODO + (m_format[i]&Gfx::FONT_MASK_LINK) != 0) //TODO { int rank = -1; for ( int j=0 ; j<=i ; j++ ) { - if ( (j == 0 || (m_format[j-1]&Gfx::FONT_MASK_HIGHLIGHT) != Gfx::FONT_HIGHLIGHT_LINK) && // TODO check if good - (m_format[j+0]&Gfx::FONT_MASK_HIGHLIGHT) == Gfx::FONT_HIGHLIGHT_LINK) // TODO + if ( (j == 0 || (m_format[j-1]&Gfx::FONT_MASK_LINK) == 0) && // TODO check if good + (m_format[j+0]&Gfx::FONT_MASK_LINK) != 0) // TODO { rank ++; } @@ -1581,8 +1581,7 @@ bool CEdit::ReadText(std::string filename, int addSize) { if ( m_bSoluce || !bInSoluce ) { - font &= ~Gfx::FONT_MASK_HIGHLIGHT; - font |= Gfx::FONT_HIGHLIGHT_LINK; + font |= Gfx::FONT_MASK_LINK; } i += 3; } @@ -1602,7 +1601,7 @@ bool CEdit::ReadText(std::string filename, int addSize) link.name = GetNameParam(buffer.data()+i+3, 0); link.marker = GetNameParam(buffer.data()+i+3, 1); m_link.push_back(link); - font &= ~Gfx::FONT_MASK_HIGHLIGHT; + font &= ~Gfx::FONT_MASK_LINK; } i += strchr(buffer.data()+i, ';')-(buffer.data()+i)+1; }