Syntax highlighting in SatCom
parent
1c0fc21e2b
commit
d6a946618e
2
data
2
data
|
@ -1 +1 @@
|
|||
Subproject commit 2ee08c5397658bbebe5d1593472fdd67a7b2778c
|
||||
Subproject commit 7099929783a41683b76204b98c0eae5a79abf143
|
|
@ -645,30 +645,33 @@ void CScript::UpdateList(Ui::CList* list)
|
|||
|
||||
// Colorize the text according to syntax.
|
||||
|
||||
void CScript::ColorizeScript(Ui::CEdit* edit)
|
||||
void CScript::ColorizeScript(Ui::CEdit* edit, int rangeStart, int rangeEnd)
|
||||
{
|
||||
CBotToken* bt;
|
||||
CBotString bs;
|
||||
const char* token;
|
||||
int error, type, cursor1, cursor2;
|
||||
Gfx::FontHighlight color;
|
||||
if (rangeEnd > edit->GetMaxChar())
|
||||
rangeEnd = edit->GetMaxChar();
|
||||
|
||||
edit->ClearFormat();
|
||||
edit->SetFormat(0, edit->GetMaxChar(), Gfx::FONT_HIGHLIGHT_COMMENT); // anything not processed is a comment
|
||||
edit->SetFormat(rangeStart, rangeEnd, Gfx::FONT_HIGHLIGHT_COMMENT); // anything not processed is a comment
|
||||
|
||||
bt = CBotToken::CompileTokens(edit->GetText(), error);
|
||||
std::string text = edit->GetText();
|
||||
text = text.substr(rangeStart, rangeEnd-rangeStart);
|
||||
|
||||
int error;
|
||||
CBotToken* bt = CBotToken::CompileTokens(text.c_str(), error);
|
||||
while ( bt != nullptr )
|
||||
{
|
||||
bs = bt->GetString();
|
||||
token = bs;
|
||||
type = bt->GetType();
|
||||
CBotString bs = bt->GetString();
|
||||
const char* token = bs;
|
||||
int type = bt->GetType();
|
||||
|
||||
cursor1 = bt->GetStart();
|
||||
cursor2 = bt->GetEnd();
|
||||
int cursor1 = bt->GetStart();
|
||||
int cursor2 = bt->GetEnd();
|
||||
|
||||
if (cursor1 < 0 || cursor2 < 0 || cursor1 == cursor2 || type == 0) { bt = bt->GetNext(); continue; } // seems to be a bug in CBot engine (how does it even still work? D:)
|
||||
|
||||
color = Gfx::FONT_HIGHLIGHT_NONE;
|
||||
cursor1 += rangeStart;
|
||||
cursor2 += rangeStart;
|
||||
|
||||
Gfx::FontHighlight color = Gfx::FONT_HIGHLIGHT_NONE;
|
||||
if ((type == TokenTypVar || (type >= TokenKeyWord && type < TokenKeyWord+100)) && IsType(token)) // types (basic types are TokenKeyWord, classes are TokenTypVar)
|
||||
{
|
||||
color = Gfx::FONT_HIGHLIGHT_TYPE;
|
||||
|
|
|
@ -78,7 +78,7 @@ public:
|
|||
bool IsContinue();
|
||||
bool GetCursor(int &cursor1, int &cursor2);
|
||||
void UpdateList(Ui::CList* list);
|
||||
void ColorizeScript(Ui::CEdit* edit);
|
||||
static void ColorizeScript(Ui::CEdit* edit, int rangeStart = 0, int rangeEnd = std::numeric_limits<int>::max());
|
||||
bool IntroduceVirus();
|
||||
|
||||
int GetError();
|
||||
|
|
|
@ -36,6 +36,8 @@
|
|||
|
||||
#include "level/parser/parser.h"
|
||||
|
||||
#include "script/script.h"
|
||||
|
||||
#include "ui/controls/scroll.h"
|
||||
|
||||
#include <clipboard/clipboard.h>
|
||||
|
@ -978,7 +980,7 @@ void CEdit::Draw()
|
|||
end.x = dim.x-MARGX*2.0f;
|
||||
start.y = ppos.y-(m_bMulti?0.0f:MARGY1);
|
||||
end.y = m_lineHeight;
|
||||
DrawHorizontalGradient(start, end, Gfx::Color(0.996f, 0.859f, 0.325f, 1.0f), Gfx::Color(0.996f, 0.953f, 0.792f, 1.0f)); // yellow background gradient
|
||||
DrawHorizontalGradient(start, end, Gfx::Color(0.847f, 0.847f, 0.847f, 1.0f), Gfx::Color(0.996f, 0.953f, 0.792f, 1.0f)); // yellow background gradient
|
||||
}
|
||||
|
||||
// Table \tab;?
|
||||
|
@ -1487,6 +1489,9 @@ bool CEdit::ReadText(std::string filename, int addSize)
|
|||
m_link.clear();
|
||||
i = j = 0;
|
||||
bBOL = true;
|
||||
int cbotStart = 0;
|
||||
bool cbotStarted = false;
|
||||
bool inCbot = false;
|
||||
while ( i < m_len )
|
||||
{
|
||||
if ( m_bAutoIndent )
|
||||
|
@ -1518,6 +1523,7 @@ bool CEdit::ReadText(std::string filename, int addSize)
|
|||
{
|
||||
font &= ~Gfx::FONT_MASK_FONT;
|
||||
font |= Gfx::FONT_COLOBOT;
|
||||
inCbot = false;
|
||||
}
|
||||
i += 3;
|
||||
}
|
||||
|
@ -1527,6 +1533,7 @@ bool CEdit::ReadText(std::string filename, int addSize)
|
|||
{
|
||||
font &= ~Gfx::FONT_MASK_FONT;
|
||||
font |= Gfx::FONT_COURIER;
|
||||
inCbot = true;
|
||||
}
|
||||
i += 3;
|
||||
}
|
||||
|
@ -1554,6 +1561,11 @@ bool CEdit::ReadText(std::string filename, int addSize)
|
|||
{
|
||||
font &= ~Gfx::FONT_MASK_TITLE;
|
||||
font |= Gfx::FONT_TITLE_LITTLE;
|
||||
if (inCbot && !cbotStarted)
|
||||
{
|
||||
cbotStart = j;
|
||||
cbotStarted = true;
|
||||
}
|
||||
}
|
||||
i += 3;
|
||||
}
|
||||
|
@ -1802,6 +1814,12 @@ bool CEdit::ReadText(std::string filename, int addSize)
|
|||
}
|
||||
else
|
||||
{
|
||||
if (buffer[i] == '\n' && cbotStarted)
|
||||
{
|
||||
CScript::ColorizeScript(this, cbotStart, j);
|
||||
cbotStarted = false;
|
||||
}
|
||||
|
||||
if ( m_bSoluce || !bInSoluce )
|
||||
{
|
||||
m_text[j] = buffer[i];
|
||||
|
|
Loading…
Reference in New Issue