summaryrefslogtreecommitdiff
path: root/src/interface/Label.cpp
diff options
context:
space:
mode:
authorSimon Robertshaw <simon@hardwired.org.uk>2012-06-26 21:55:52 (GMT)
committer Simon Robertshaw <simon@hardwired.org.uk>2012-06-26 21:55:52 (GMT)
commit5a71068ba07f42cffbd50324176510d992ebbc5e (patch)
tree10fbbf3e466d10175faaacced7cafba449edbb69 /src/interface/Label.cpp
parent7c259c01238d91d41a778003e2529f5c06e09139 (diff)
downloadpowder-5a71068ba07f42cffbd50324176510d992ebbc5e.zip
powder-5a71068ba07f42cffbd50324176510d992ebbc5e.tar.gz
Textbox now inherits from Label - gets all the fancy text selection features
Diffstat (limited to 'src/interface/Label.cpp')
-rw-r--r--src/interface/Label.cpp46
1 files changed, 42 insertions, 4 deletions
diff --git a/src/interface/Label.cpp b/src/interface/Label.cpp
index a513878..35b2000 100644
--- a/src/interface/Label.cpp
+++ b/src/interface/Label.cpp
@@ -125,20 +125,58 @@ void Label::Tick(float dt)
{
if(!this->IsFocused() && (selecting || (selectionIndex0 != -1 && selectionIndex1 != -1)))
{
- selecting = false;
- selectionIndex0 = -1;
- selectionIndex1 = -1;
- updateSelection();
+ ClearSelection();
}
}
+int Label::getLowerSelectionBound()
+{
+ return (selectionIndex0 > selectionIndex1) ? selectionIndex1 : selectionIndex0;
+}
+
+int Label::getHigherSelectionBound()
+{
+ return (selectionIndex0 > selectionIndex1) ? selectionIndex0 : selectionIndex1;
+}
+
+bool Label::HasSelection()
+{
+ if(selectionIndex0 != -1 && selectionIndex1 != -1 && selectionIndex0 != selectionIndex1)
+ return true;
+ return false;
+}
+
+void Label::ClearSelection()
+{
+ selecting = false;
+ selectionIndex0 = -1;
+ selectionIndex1 = -1;
+ updateSelection();
+}
+
void Label::updateSelection()
{
std::string currentText;
+
+ if(selectionIndex0 < 0) selectionIndex0 = 0;
+ if(selectionIndex0 > text.length()) selectionIndex0 = text.length();
+ if(selectionIndex1 < 0) selectionIndex1 = 0;
+ if(selectionIndex1 > text.length()) selectionIndex1 = text.length();
+
+ if(selectionIndex0 == -1 || selectionIndex1 == -1)
+ {
+ selectionXH = -1;
+ selectionXL = -1;
+
+ textFragments = std::string(currentText);
+ return;
+ }
+
if(multiline)
currentText = textLines;
else
currentText = text;
+
if(selectionIndex1 > selectionIndex0) {
selectionLineH = Graphics::PositionAtCharIndex((char*)currentText.c_str(), selectionIndex1, selectionXH, selectionYH);
selectionLineL = Graphics::PositionAtCharIndex((char*)currentText.c_str(), selectionIndex0, selectionXL, selectionYL);