Skip to content

Commit

Permalink
Purge the last traces of PositionAtCharIndex and CharIndexAtPosition
Browse files Browse the repository at this point in the history
Also fix a bunch of other ugly things.
  • Loading branch information
LBPHacker committed Jul 19, 2019
1 parent 7c79302 commit 34b4665
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 39 deletions.
12 changes: 6 additions & 6 deletions src/gui/interface/Label.cpp
Expand Up @@ -68,7 +68,7 @@ void Label::updateTextWrapper()
);
if (autoHeight)
{
Size.Y = lines * 12 + 3;
Size.Y = lines * FONT_H + 3;
}
}

Expand Down Expand Up @@ -245,7 +245,7 @@ void Label::Draw(const Point& screenPos)
screenPos.X + textPosition.X + selectionXL,
screenPos.Y + textPosition.Y + selectionYL - 1,
selectionXH - selectionXL,
10,
FONT_H - 2,
255, 255, 255, 255
);
}
Expand All @@ -255,24 +255,24 @@ void Label::Draw(const Point& screenPos)
screenPos.X + textPosition.X + selectionXL,
screenPos.Y + textPosition.Y + selectionYL - 1,
textSize.X - selectionXL,
10,
FONT_H - 2,
255, 255, 255, 255
);
for (int i = 1; i < selectionLineH - selectionLineL; ++i)
{
g->fillrect(
screenPos.X + textPosition.X,
screenPos.Y + textPosition.Y + selectionYL - 1 + i * 12,
screenPos.Y + textPosition.Y + selectionYL - 1 + i * FONT_H,
textSize.X,
10,
FONT_H - 2,
255, 255, 255, 255
);
}
g->fillrect(
screenPos.X + textPosition.X,
screenPos.Y + textPosition.Y + selectionYH - 1,
selectionXH,
10,
FONT_H - 2,
255, 255, 255, 255
);
}
Expand Down
35 changes: 2 additions & 33 deletions src/gui/interface/RichLabel.cpp
Expand Up @@ -161,6 +161,7 @@ void RichLabel::updateRichText()
delete[] regionsStack;
}
TextPosition(displayText);
displayTextWrapper.Update(displayText, false, 0);
}

void RichLabel::SetText(String text)
Expand All @@ -186,41 +187,9 @@ void RichLabel::Draw(const Point& screenPos)
g->drawtext(screenPos.X+textPosition.X, screenPos.Y+textPosition.Y, displayText, textColour.Red, textColour.Green, textColour.Blue, 255);
}

// don't ever use this for anything ever again eww
int EndMySuffering(String const &displayText, int positionX, int positionY)
{
int x=0, y=-2,charIndex=0,cw;
auto s = displayText.begin();
for (; s != displayText.end(); ++s)
{
if(*s == '\n') {
x = 0;
y += FONT_H;
charIndex++;
continue;
} else if(*s == '\b') {
if((displayText.end() - s) < 2) break;
s++;
charIndex+=2;
continue;
} else if (*s == '\x0F') {
if((displayText.end() - s) < 4) 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;
}

void RichLabel::OnMouseClick(int x, int y, unsigned button)
{
int cursorPosition = EndMySuffering(displayText, x-textPosition.X, y-textPosition.Y);
int cursorPosition = displayTextWrapper.Point2Index(x - textPosition.X, y - textPosition.Y).raw_index;
for (auto const &region : regions)
{
if (region.start <= cursorPosition && region.finish >= cursorPosition)
Expand Down
3 changes: 3 additions & 0 deletions src/gui/interface/RichLabel.h
Expand Up @@ -2,6 +2,7 @@

#include "common/String.h"
#include "Component.h"
#include "TextWrapper.h"

namespace ui
{
Expand All @@ -16,6 +17,8 @@ namespace ui
String actionData;
};

TextWrapper displayTextWrapper;

RichLabel(Point position, Point size, String richText);

virtual ~RichLabel();
Expand Down
1 change: 1 addition & 0 deletions src/gui/interface/TextWrapper.h
Expand Up @@ -2,6 +2,7 @@

#include "common/String.h"
#include "Point.h"
#include "font.h"

#include <vector>

Expand Down

0 comments on commit 34b4665

Please sign in to comment.