summaryrefslogtreecommitdiff
path: root/plugingui/lineedit.cc
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2014-10-14 17:21:06 +0200
committerBent Bisballe Nyeng <deva@aasimon.org>2014-10-14 17:21:06 +0200
commit5bcfa1aeab5def47b147c77f915028b76fdd4844 (patch)
treef556d3bdff38af7fb2fc1fc4f9150f17c072059c /plugingui/lineedit.cc
parentadc6d371af2cf356578fee6be0711d6db7f31288 (diff)
Remove errornously committed changes for plugingui branch.
Diffstat (limited to 'plugingui/lineedit.cc')
-rw-r--r--plugingui/lineedit.cc73
1 files changed, 64 insertions, 9 deletions
diff --git a/plugingui/lineedit.cc b/plugingui/lineedit.cc
index d6e717a..46354bb 100644
--- a/plugingui/lineedit.cc
+++ b/plugingui/lineedit.cc
@@ -30,6 +30,8 @@
#include "window.h"
+#include <assert.h>
+
#include <hugin.hpp>
#define BORDER 10
@@ -38,6 +40,7 @@ GUI::LineEdit::LineEdit(Widget *parent)
: GUI::Widget(parent)
{
pos = 0;
+ offsetpos = 0;
setReadOnly(false);
box.topLeft = new Image(":widget_tl.png");
@@ -72,7 +75,8 @@ bool GUI::LineEdit::readOnly()
void GUI::LineEdit::setText(std::string text)
{
_text = text;
- if(_text.size() < pos) pos = text.size();
+ pos = text.size();
+// if(_text.size() < pos) pos = text.size();
repaintEvent(NULL);
textChanged();
@@ -87,14 +91,16 @@ void GUI::LineEdit::buttonEvent(ButtonEvent *e)
{
if(readOnly()) return;
+
if(e->direction == 1) {
- for(int i = 0; i < (int)_text.length(); i++) {
- if(e->x < (int)(font.textWidth(_text.substr(0, i)) + BORDER)) {
- pos = i;
+ for(int i = 0; i < (int)_visibletext.length(); i++) {
+ if(e->x < (int)(font.textWidth(_visibletext.substr(0, i)) + BORDER)) {
+ printf("i, Offset: %d, %d\n", i, offsetpos);
+ pos = i + offsetpos;
break;
}
}
- if(e->x >= (int)(font.textWidth(_text) + BORDER)) pos = _text.length();
+// if(e->x >= (int)(font.textWidth(_visibletext) + BORDER)) pos = _visibletext.length();
repaintEvent(NULL);
}
}
@@ -111,7 +117,9 @@ void GUI::LineEdit::keyEvent(GUI::KeyEvent *e)
if(e->keycode == GUI::KeyEvent::KEY_LEFT) {
if(pos) pos--;
-
+ if(offsetpos >= pos) walkstate = WALK_LEFT;
+// else walkstate = NOOP;
+
} else if(e->keycode == GUI::KeyEvent::KEY_HOME) {
pos = 0;
@@ -120,7 +128,9 @@ void GUI::LineEdit::keyEvent(GUI::KeyEvent *e)
} else if(e->keycode == GUI::KeyEvent::KEY_RIGHT) {
if(pos < _text.length()) pos++;
-
+ if(offsetpos + _visibletext.length() <= pos) walkstate = WALK_RIGHT;
+// else walkstate = NOOP;
+
} else if(e->keycode == GUI::KeyEvent::KEY_DELETE) {
if(pos < _text.length()) {
std::string t = _text.substr(0, pos);
@@ -144,6 +154,7 @@ void GUI::LineEdit::keyEvent(GUI::KeyEvent *e)
_text = pre + e->text + post;
change = true;
pos++;
+
} else if(e->keycode == GUI::KeyEvent::KEY_ENTER) {
if(handler) handler(ptr);
}
@@ -165,12 +176,56 @@ void GUI::LineEdit::repaintEvent(GUI::RepaintEvent *e)
p.drawBox(0, 0, &box, w, h);
p.setColour(GUI::Colour(183.0/255.0, 219.0/255.0 , 255.0/255.0, 1));
- p.drawText(BORDER - 4 + 3, height()/2+5 + 1 + 1 + 1, font, _text);
+
+ if(walkstate == WALK_LEFT) {
+ _visibletext = _text.substr(pos, std::string::npos);
+ offsetpos = pos;
+ }
+ else if(walkstate == WALK_RIGHT) {
+ int d = (offsetpos < _text.length()) ? 1 : 0;
+ _visibletext = _text.substr(offsetpos + d);
+ offsetpos = offsetpos + d;
+ }
+ else {
+ _visibletext = _text;
+ offsetpos = 0;
+ }
+ while(true) {
+ int textwidth = font.textWidth(_visibletext);
+ if(textwidth > w - BORDER - 4 + 3) {
+ if(walkstate == WALK_LEFT) {
+ _visibletext = _visibletext.substr(0, _visibletext.length()-1);
+ }
+ else if(walkstate == WALK_RIGHT) {
+ _visibletext = _visibletext.substr(0, _visibletext.length()-1);
+ }
+ else {
+ if(offsetpos < pos) {
+ _visibletext = _visibletext.substr(1);
+ offsetpos++;
+ }
+ else {
+ _visibletext = _visibletext.substr(0, _visibletext.length() - 1);
+ }
+ }
+ }
+ else {
+ DEBUG(lienedit, "Full text: '%s'\n", _text.c_str());
+ DEBUG(lineedit, "Drawing text in lineedit '%s'\n", _visibletext.c_str());
+ DEBUG(lineedit, "Offset, pos: %d, %d\n", offsetpos, pos);
+ break;
+ }
+ }
+
+ walkstate = NOOP;
+
+ p.drawText(BORDER - 4 + 3, height()/2+5 + 1 + 1 + 1, font, _visibletext);
if(readOnly()) return;
if(hasKeyboardFocus()) {
- size_t px = font.textWidth(_text.substr(0, pos));
+// size_t px = font.textWidth(_text.substr(0, pos - offsetpos));
+ size_t px = font.textWidth(_visibletext.substr(0, pos - offsetpos));
//p.setColour(Colour(0.8));
p.drawLine(px + BORDER - 1 - 4 + 3, 6,
px + BORDER - 1 - 4 + 3, height() - 7);