Better text selection colour invert, fixes #107
This commit is contained in:
parent
3fcfede08f
commit
bd7dd20742
@ -33,6 +33,13 @@ int PIXELMETHODS_CLASS::drawtext(int x, int y, const char *s, int r, int g, int
|
||||
g = oG;
|
||||
b = oB;
|
||||
}
|
||||
else if (*s == '\x01')
|
||||
{
|
||||
invert = !invert;
|
||||
r = 255-r;
|
||||
g = 255-g;
|
||||
b = 255-b;
|
||||
}
|
||||
else if (*s == '\b')
|
||||
{
|
||||
if(!s[1]) break;
|
||||
@ -67,6 +74,12 @@ int PIXELMETHODS_CLASS::drawtext(int x, int y, const char *s, int r, int g, int
|
||||
r = 32;
|
||||
break;
|
||||
}
|
||||
if(invert)
|
||||
{
|
||||
r = 255-r;
|
||||
g = 255-g;
|
||||
b = 255-b;
|
||||
}
|
||||
s++;
|
||||
}
|
||||
else
|
||||
|
@ -6,6 +6,7 @@ int PIXELMETHODS_CLASS::drawtext(int x, int y, const char *s, int r, int g, int
|
||||
return 0;
|
||||
int width, height;
|
||||
|
||||
int invert = 0;
|
||||
int oR = r, oG = g, oB = b;
|
||||
int characterX = x, characterY = y;
|
||||
int startX = characterX;
|
||||
@ -33,6 +34,13 @@ int PIXELMETHODS_CLASS::drawtext(int x, int y, const char *s, int r, int g, int
|
||||
g = oG;
|
||||
b = oB;
|
||||
}
|
||||
else if (*s == '\x01')
|
||||
{
|
||||
invert = !invert;
|
||||
r = 255-r;
|
||||
g = 255-g;
|
||||
b = 255-b;
|
||||
}
|
||||
else if (*s == '\b')
|
||||
{
|
||||
if(!s[1]) break;
|
||||
@ -67,6 +75,12 @@ int PIXELMETHODS_CLASS::drawtext(int x, int y, const char *s, int r, int g, int
|
||||
r = 32;
|
||||
break;
|
||||
}
|
||||
if(invert)
|
||||
{
|
||||
r = 255-r;
|
||||
g = 255-g;
|
||||
b = 255-b;
|
||||
}
|
||||
s++;
|
||||
}
|
||||
else
|
||||
|
@ -250,26 +250,49 @@ void Label::updateSelection()
|
||||
selectionLineL = Graphics::PositionAtCharIndex((char*)currentText.c_str(), selectionIndex0, selectionXL, selectionYL);
|
||||
|
||||
textFragments = std::string(currentText);
|
||||
textFragments.insert(selectionIndex1, "\x0E");
|
||||
textFragments.insert(selectionIndex0, "\x0F\x01\x01\x01");
|
||||
//textFragments.insert(selectionIndex1, "\x0E");
|
||||
//textFragments.insert(selectionIndex0, "\x0F\x01\x01\x01");
|
||||
textFragments.insert(selectionIndex1, "\x01");
|
||||
textFragments.insert(selectionIndex0, "\x01");
|
||||
} else if(selectionIndex0 > selectionIndex1) {
|
||||
selectionLineH = Graphics::PositionAtCharIndex((char*)currentText.c_str(), selectionIndex0, selectionXH, selectionYH);
|
||||
selectionLineL = Graphics::PositionAtCharIndex((char*)currentText.c_str(), selectionIndex1, selectionXL, selectionYL);
|
||||
|
||||
textFragments = std::string(currentText);
|
||||
textFragments.insert(selectionIndex0, "\x0E");
|
||||
textFragments.insert(selectionIndex1, "\x0F\x01\x01\x01");
|
||||
//textFragments.insert(selectionIndex0, "\x0E");
|
||||
//textFragments.insert(selectionIndex1, "\x0F\x01\x01\x01");
|
||||
textFragments.insert(selectionIndex0, "\x01");
|
||||
textFragments.insert(selectionIndex1, "\x01");
|
||||
} else {
|
||||
selectionXH = -1;
|
||||
selectionXL = -1;
|
||||
|
||||
textFragments = std::string(currentText);
|
||||
}
|
||||
|
||||
if(displayText.length())
|
||||
{
|
||||
displayText = tDisplayText;
|
||||
if(selectionIndex1 > selectionIndex0) {
|
||||
int tSelectionIndex1 = Graphics::CharIndexAtPosition((char*)displayText.c_str(), selectionXH, selectionYH);
|
||||
int tSelectionIndex0 = Graphics::CharIndexAtPosition((char*)displayText.c_str(), selectionXL, selectionYL);
|
||||
|
||||
displayText.insert(tSelectionIndex1, "\x01");
|
||||
displayText.insert(tSelectionIndex0, "\x01");
|
||||
} else if(selectionIndex0 > selectionIndex1) {
|
||||
int tSelectionIndex0 = Graphics::CharIndexAtPosition((char*)displayText.c_str(), selectionXH, selectionYH);
|
||||
int tSelectionIndex1 = Graphics::CharIndexAtPosition((char*)displayText.c_str(), selectionXL, selectionYL);
|
||||
|
||||
displayText.insert(tSelectionIndex0, "\x01");
|
||||
displayText.insert(tSelectionIndex1, "\x01");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Label::SetDisplayText(std::string newText)
|
||||
{
|
||||
displayText = newText;
|
||||
tDisplayText = displayText;
|
||||
}
|
||||
|
||||
void Label::Draw(const Point& screenPos)
|
||||
|
@ -15,6 +15,7 @@ namespace ui
|
||||
std::string textFragments;
|
||||
std::string textLines;
|
||||
std::string displayText;
|
||||
std::string tDisplayText;
|
||||
|
||||
std::string text;
|
||||
Colour textColour;
|
||||
|
Loading…
Reference in New Issue
Block a user