mirror of
https://github.com/The-Powder-Toy/The-Powder-Toy.git
synced 2025-08-07 00:46:33 +02:00
Purge the last traces of PositionAtCharIndex and CharIndexAtPosition
Also fix a bunch of other ugly things.
This commit is contained in:
@@ -68,7 +68,7 @@ void Label::updateTextWrapper()
|
|||||||
);
|
);
|
||||||
if (autoHeight)
|
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.X + textPosition.X + selectionXL,
|
||||||
screenPos.Y + textPosition.Y + selectionYL - 1,
|
screenPos.Y + textPosition.Y + selectionYL - 1,
|
||||||
selectionXH - selectionXL,
|
selectionXH - selectionXL,
|
||||||
10,
|
FONT_H - 2,
|
||||||
255, 255, 255, 255
|
255, 255, 255, 255
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -255,16 +255,16 @@ void Label::Draw(const Point& screenPos)
|
|||||||
screenPos.X + textPosition.X + selectionXL,
|
screenPos.X + textPosition.X + selectionXL,
|
||||||
screenPos.Y + textPosition.Y + selectionYL - 1,
|
screenPos.Y + textPosition.Y + selectionYL - 1,
|
||||||
textSize.X - selectionXL,
|
textSize.X - selectionXL,
|
||||||
10,
|
FONT_H - 2,
|
||||||
255, 255, 255, 255
|
255, 255, 255, 255
|
||||||
);
|
);
|
||||||
for (int i = 1; i < selectionLineH - selectionLineL; ++i)
|
for (int i = 1; i < selectionLineH - selectionLineL; ++i)
|
||||||
{
|
{
|
||||||
g->fillrect(
|
g->fillrect(
|
||||||
screenPos.X + textPosition.X,
|
screenPos.X + textPosition.X,
|
||||||
screenPos.Y + textPosition.Y + selectionYL - 1 + i * 12,
|
screenPos.Y + textPosition.Y + selectionYL - 1 + i * FONT_H,
|
||||||
textSize.X,
|
textSize.X,
|
||||||
10,
|
FONT_H - 2,
|
||||||
255, 255, 255, 255
|
255, 255, 255, 255
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -272,7 +272,7 @@ void Label::Draw(const Point& screenPos)
|
|||||||
screenPos.X + textPosition.X,
|
screenPos.X + textPosition.X,
|
||||||
screenPos.Y + textPosition.Y + selectionYH - 1,
|
screenPos.Y + textPosition.Y + selectionYH - 1,
|
||||||
selectionXH,
|
selectionXH,
|
||||||
10,
|
FONT_H - 2,
|
||||||
255, 255, 255, 255
|
255, 255, 255, 255
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@@ -161,6 +161,7 @@ void RichLabel::updateRichText()
|
|||||||
delete[] regionsStack;
|
delete[] regionsStack;
|
||||||
}
|
}
|
||||||
TextPosition(displayText);
|
TextPosition(displayText);
|
||||||
|
displayTextWrapper.Update(displayText, false, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RichLabel::SetText(String text)
|
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);
|
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)
|
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)
|
for (auto const ®ion : regions)
|
||||||
{
|
{
|
||||||
if (region.start <= cursorPosition && region.finish >= cursorPosition)
|
if (region.start <= cursorPosition && region.finish >= cursorPosition)
|
||||||
|
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
#include "common/String.h"
|
#include "common/String.h"
|
||||||
#include "Component.h"
|
#include "Component.h"
|
||||||
|
#include "TextWrapper.h"
|
||||||
|
|
||||||
namespace ui
|
namespace ui
|
||||||
{
|
{
|
||||||
@@ -16,6 +17,8 @@ namespace ui
|
|||||||
String actionData;
|
String actionData;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
TextWrapper displayTextWrapper;
|
||||||
|
|
||||||
RichLabel(Point position, Point size, String richText);
|
RichLabel(Point position, Point size, String richText);
|
||||||
|
|
||||||
virtual ~RichLabel();
|
virtual ~RichLabel();
|
||||||
|
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
#include "common/String.h"
|
#include "common/String.h"
|
||||||
#include "Point.h"
|
#include "Point.h"
|
||||||
|
#include "font.h"
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user