diff --git a/src/gui/interface/Label.cpp b/src/gui/interface/Label.cpp index 6c0aab346..0b952d645 100644 --- a/src/gui/interface/Label.cpp +++ b/src/gui/interface/Label.cpp @@ -68,7 +68,7 @@ void Label::updateTextWrapper() ); if (autoHeight) { - Size.Y = lines * 12 + 3; + Size.Y = lines * FONT_H + 3; } } @@ -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 ); } @@ -255,16 +255,16 @@ 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 ); } @@ -272,7 +272,7 @@ void Label::Draw(const Point& screenPos) screenPos.X + textPosition.X, screenPos.Y + textPosition.Y + selectionYH - 1, selectionXH, - 10, + FONT_H - 2, 255, 255, 255, 255 ); } diff --git a/src/gui/interface/RichLabel.cpp b/src/gui/interface/RichLabel.cpp index 613d76240..f41d25337 100644 --- a/src/gui/interface/RichLabel.cpp +++ b/src/gui/interface/RichLabel.cpp @@ -161,6 +161,7 @@ void RichLabel::updateRichText() delete[] regionsStack; } TextPosition(displayText); + displayTextWrapper.Update(displayText, false, 0); } void RichLabel::SetText(String text) @@ -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 ®ion : regions) { if (region.start <= cursorPosition && region.finish >= cursorPosition) diff --git a/src/gui/interface/RichLabel.h b/src/gui/interface/RichLabel.h index ca586a893..1f7326924 100644 --- a/src/gui/interface/RichLabel.h +++ b/src/gui/interface/RichLabel.h @@ -2,6 +2,7 @@ #include "common/String.h" #include "Component.h" +#include "TextWrapper.h" namespace ui { @@ -16,6 +17,8 @@ namespace ui String actionData; }; + TextWrapper displayTextWrapper; + RichLabel(Point position, Point size, String richText); virtual ~RichLabel(); diff --git a/src/gui/interface/TextWrapper.h b/src/gui/interface/TextWrapper.h index c2640f63b..430f34dd3 100644 --- a/src/gui/interface/TextWrapper.h +++ b/src/gui/interface/TextWrapper.h @@ -2,6 +2,7 @@ #include "common/String.h" #include "Point.h" +#include "font.h" #include