Skip to content

Commit

Permalink
Fix text wrapping (fixes #166)
Browse files Browse the repository at this point in the history
This breaks the syntax highlighting in ConsoleView.
I haven't yet thought of a way to fix that properly,
ideas anyone?
  • Loading branch information
LBPHacker committed Jul 19, 2019
1 parent c5c4d92 commit 4bb8557
Show file tree
Hide file tree
Showing 10 changed files with 506 additions and 394 deletions.
65 changes: 0 additions & 65 deletions src/graphics/Graphics.cpp
Expand Up @@ -644,71 +644,6 @@ int Graphics::textwidthx(String str, int w)
return n;
}

int Graphics::PositionAtCharIndex(String str, int charIndex, int & positionX, int & positionY)
{
int x = 0, y = 0, lines = 1;
String::value_type const *s = str.c_str();
for (; *s; s++)
{
if (!charIndex)
break;
if(*s == '\n') {
lines++;
x = 0;
y += FONT_H;
charIndex--;
continue;
} else if(*s =='\b') {
if(!s[1]) break;
s++;
charIndex-=2;
continue;
} else if(*s == '\x0F') {
if(!s[1] || !s[2] || !s[3]) break;
s+=3;
charIndex-=4;
continue;
}
x += FontReader(*s).GetWidth();
charIndex--;
}
positionX = x;
positionY = y;
return lines;
}

int Graphics::CharIndexAtPosition(String str, int positionX, int positionY)
{
int x=0, y=-2,charIndex=0,cw;
String::value_type const *s = str.c_str();
for (; *s; s++)
{
if(*s == '\n') {
x = 0;
y += FONT_H;
charIndex++;
continue;
} else if(*s == '\b') {
if(!s[1]) break;
s++;
charIndex+=2;
continue;
} else if (*s == '\x0F') {
if(!s[1] || !s[2] || !s[3]) break;
s+=3;
charIndex+=4;
continue;
}
cw = FontReader(*s).GetWidth();
if ((x+(cw/2) >= positionX && y+FONT_H >= positionY) || y > positionY)
break;
x += cw;
charIndex++;
}
return charIndex;
}


int Graphics::textwrapheight(String str, int width)
{
int x=0, height=FONT_H, cw;
Expand Down
2 changes: 0 additions & 2 deletions src/graphics/Graphics.h
Expand Up @@ -113,8 +113,6 @@ class Graphics
static pixel *render_packed_rgb(void *image, int width, int height, int cmp_size);

//Font/text metrics
static int CharIndexAtPosition(String s, int positionX, int positionY);
static int PositionAtCharIndex(String s, int charIndex, int & positionX, int & positionY);
static int CharWidth(String::value_type c);
static int textnwidth(String s, int n);
static void textnpos(String s, int n, int w, int *cx, int *cy);
Expand Down
6 changes: 3 additions & 3 deletions src/gui/console/ConsoleView.cpp
Expand Up @@ -26,7 +26,7 @@ ConsoleView::ConsoleView():
CommandHighlighter(ConsoleView * v_) { v = v_; }
void TextChangedCallback(ui::Textbox * sender) override
{
sender->SetDisplayText(v->c->FormatCommand(sender->GetText()));
// sender->SetDisplayText(v->c->FormatCommand(sender->GetText()));
}
};
commandField = new ui::Textbox(ui::Point(0, Size.Y-16), ui::Point(Size.X, 16), "");
Expand All @@ -52,7 +52,7 @@ void ConsoleView::DoKeyPress(int key, int scan, bool repeat, bool shift, bool ct
case SDLK_KP_ENTER:
c->EvaluateCommand(commandField->GetText());
commandField->SetText("");
commandField->SetDisplayText("");
// commandField->SetDisplayText("");
break;
case SDLK_DOWN:
c->NextCommand();
Expand Down Expand Up @@ -106,7 +106,7 @@ void ConsoleView::NotifyPreviousCommandsChanged(ConsoleModel * sender)
void ConsoleView::NotifyCurrentCommandChanged(ConsoleModel * sender)
{
commandField->SetText(sender->GetCurrentCommand().Command);
commandField->SetDisplayText(c->FormatCommand(commandField->GetText()));
// commandField->SetDisplayText(c->FormatCommand(commandField->GetText()));
}


Expand Down

0 comments on commit 4bb8557

Please sign in to comment.