Fixed links in CBot listings in SatCom

master
krzys-h 2016-06-17 21:13:16 +02:00
parent b56cd11c98
commit 9017e5a25b
3 changed files with 58 additions and 60 deletions

View File

@ -720,43 +720,42 @@ void CText::DrawString(const std::string &text, std::vector<FontMetaChar>::itera
Color c = color; Color c = color;
FontHighlight hl = static_cast<FontHighlight>(format[fmtIndex] & FONT_MASK_HIGHLIGHT); FontHighlight hl = static_cast<FontHighlight>(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
{ }
c = Color(0.490f, 0.380f, 0.165f, 1.0f); // #7D612A else if (hl == FONT_HIGHLIGHT_TYPE)
} {
else if (hl == FONT_HIGHLIGHT_TYPE) c = Color(0.31f, 0.443f, 0.196f, 1.0f); // #4F7132
{ }
c = Color(0.31f, 0.443f, 0.196f, 1.0f); // #4F7132 else if (hl == FONT_HIGHLIGHT_CONST)
} {
else if (hl == FONT_HIGHLIGHT_CONST) c = Color(0.882f, 0.176f, 0.176f, 1.0f); // #E12D2D
{ }
c = Color(0.882f, 0.176f, 0.176f, 1.0f); // #E12D2D else if (hl == FONT_HIGHLIGHT_THIS)
} {
else if (hl == FONT_HIGHLIGHT_THIS) c = Color(0.545f, 0.329f, 0.608f, 1.0f); // #8B549B
{ }
c = Color(0.545f, 0.329f, 0.608f, 1.0f); // #8B549B else if (hl == FONT_HIGHLIGHT_COMMENT)
} {
else if (hl == FONT_HIGHLIGHT_COMMENT) c = Color(0.251f, 0.271f, 0.306f, 1.0f); // #40454E
{ }
c = Color(0.251f, 0.271f, 0.306f, 1.0f); // #40454E else if (hl == FONT_HIGHLIGHT_KEYWORD)
} {
else if (hl == FONT_HIGHLIGHT_KEYWORD) c = Color(0.239f, 0.431f, 0.588f, 1.0f); // #3D6E96
{ }
c = Color(0.239f, 0.431f, 0.588f, 1.0f); // #3D6E96 else if (hl == FONT_HIGHLIGHT_STRING)
} {
else if (hl == FONT_HIGHLIGHT_STRING) c = Color(0.239f, 0.384f, 0.341f, 1.0f); // #3D6257
{ }
c = Color(0.239f, 0.384f, 0.341f, 1.0f); // #3D6257
} // draw highlight background or link underline
else if (font != FONT_BUTTON)
{ {
Math::IntPoint charSize; Math::IntPoint charSize;
charSize.x = GetCharWidthInt(ch, font, size, offset); charSize.x = GetCharWidthInt(ch, font, size, offset);
charSize.y = GetHeightInt(font, size); charSize.y = GetHeightInt(font, size);
DrawHighlight(hl, pos, charSize); DrawHighlight(format[fmtIndex], pos, charSize);
}
} }
DrawCharAndAdjustPos(ch, font, size, pos, c); 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 // Gradient colors
Color grad[4]; Color grad[4];
// TODO: switch to alpha factors // 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);
grad[0] = grad[1] = grad[2] = grad[3] = Color(0.0f, 0.0f, 1.0f, 0.5f); }
break; else if ((hl & FONT_MASK_HIGHLIGHT) == FONT_HIGHLIGHT_KEY)
{
case FONT_HIGHLIGHT_KEY: grad[0] = grad[1] = grad[2] = grad[3] =
grad[0] = grad[1] = grad[2] = grad[3] = Color(192.0f / 256.0f, 192.0f / 256.0f, 192.0f / 256.0f, 0.5f);
Color(192.0f / 256.0f, 192.0f / 256.0f, 192.0f / 256.0f, 0.5f); }
break; else
{
default: return;
return;
} }
Math::IntPoint vsize = m_engine->GetWindowSize(); 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.x = pos.x + size.x;
p2.y = pos.y; p2.y = pos.y;
if (hl == FONT_HIGHLIGHT_LINK) if ((hl & FONT_MASK_LINK) != 0)
{ {
p1.y = pos.y - h; // just emphasized p1.y = pos.y - h; // just emphasized
} }

View File

@ -118,7 +118,6 @@ enum FontTitle
enum FontHighlight enum FontHighlight
{ {
FONT_HIGHLIGHT_NONE = 0x00 << 6, FONT_HIGHLIGHT_NONE = 0x00 << 6,
FONT_HIGHLIGHT_LINK = 0x01 << 6, //!< link underline
FONT_HIGHLIGHT_TABLE = 0x02 << 6, //!< code background in SatCom FONT_HIGHLIGHT_TABLE = 0x02 << 6, //!< code background in SatCom
FONT_HIGHLIGHT_KEY = 0x03 << 6, //!< background for keys in documentation in SatCom FONT_HIGHLIGHT_KEY = 0x03 << 6, //!< background for keys in documentation in SatCom
FONT_HIGHLIGHT_TOKEN = 0x04 << 6, //!< keywords in CBot scripts FONT_HIGHLIGHT_TOKEN = 0x04 << 6, //!< keywords in CBot scripts
@ -142,8 +141,10 @@ enum FontMask
FONT_MASK_TITLE = 0x030, FONT_MASK_TITLE = 0x030,
//! Mask for FontHighlight //! Mask for FontHighlight
FONT_MASK_HIGHLIGHT = 0x3c0, FONT_MASK_HIGHLIGHT = 0x3c0,
//! Mask for links
FONT_MASK_LINK = 0x400,
//! Mask for image bit (TODO: not used?) //! 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); float size, Math::IntPoint pos, int width, int eol, Color color);
void DrawString(const std::string &text, FontType font, void DrawString(const std::string &text, FontType font,
float size, Math::IntPoint pos, int width, int eol, Color color); 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 DrawCharAndAdjustPos(UTF8Char ch, FontType font, float size, Math::IntPoint &pos, Color color);
void StringToUTFCharList(const std::string &text, std::vector<UTF8Char> &chars); void StringToUTFCharList(const std::string &text, std::vector<UTF8Char> &chars);
void StringToUTFCharList(const std::string &text, std::vector<UTF8Char> &chars, std::vector<FontMetaChar>::iterator format, std::vector<FontMetaChar>::iterator end); void StringToUTFCharList(const std::string &text, std::vector<UTF8Char> &chars, std::vector<FontMetaChar>::iterator format, std::vector<FontMetaChar>::iterator end);

View File

@ -564,7 +564,7 @@ bool CEdit::IsLinkPos(Math::Point pos)
if ( i == -1 ) return false; if ( i == -1 ) return false;
if ( i >= m_len ) return false; if ( i >= m_len ) return false;
if ( m_format.size() > static_cast<unsigned int>(i) && ((m_format[i] & Gfx::FONT_MASK_HIGHLIGHT) == Gfx::FONT_HIGHLIGHT_LINK)) return true; // TODO if ( m_format.size() > static_cast<unsigned int>(i) && ((m_format[i] & Gfx::FONT_MASK_LINK) != 0)) return true; // TODO
return false; return false;
} }
@ -637,13 +637,13 @@ void CEdit::MouseRelease(Math::Point mouse)
if ( !m_bEdit ) if ( !m_bEdit )
{ {
if ( m_format.size() > 0 && i < m_len && m_cursor1 == m_cursor2 && 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; int rank = -1;
for ( int j=0 ; j<=i ; j++ ) 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 if ( (j == 0 || (m_format[j-1]&Gfx::FONT_MASK_LINK) == 0) && // TODO check if good
(m_format[j+0]&Gfx::FONT_MASK_HIGHLIGHT) == Gfx::FONT_HIGHLIGHT_LINK) // TODO (m_format[j+0]&Gfx::FONT_MASK_LINK) != 0) // TODO
{ {
rank ++; rank ++;
} }
@ -1581,8 +1581,7 @@ bool CEdit::ReadText(std::string filename, int addSize)
{ {
if ( m_bSoluce || !bInSoluce ) if ( m_bSoluce || !bInSoluce )
{ {
font &= ~Gfx::FONT_MASK_HIGHLIGHT; font |= Gfx::FONT_MASK_LINK;
font |= Gfx::FONT_HIGHLIGHT_LINK;
} }
i += 3; i += 3;
} }
@ -1602,7 +1601,7 @@ bool CEdit::ReadText(std::string filename, int addSize)
link.name = GetNameParam(buffer.data()+i+3, 0); link.name = GetNameParam(buffer.data()+i+3, 0);
link.marker = GetNameParam(buffer.data()+i+3, 1); link.marker = GetNameParam(buffer.data()+i+3, 1);
m_link.push_back(link); m_link.push_back(link);
font &= ~Gfx::FONT_MASK_HIGHLIGHT; font &= ~Gfx::FONT_MASK_LINK;
} }
i += strchr(buffer.data()+i, ';')-(buffer.data()+i)+1; i += strchr(buffer.data()+i, ';')-(buffer.data()+i)+1;
} }