aboutsummaryrefslogtreecommitdiff
path: root/gui/EditTextWidget.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'gui/EditTextWidget.cpp')
-rw-r--r--gui/EditTextWidget.cpp52
1 files changed, 23 insertions, 29 deletions
diff --git a/gui/EditTextWidget.cpp b/gui/EditTextWidget.cpp
index 25326eb868..5ae561b756 100644
--- a/gui/EditTextWidget.cpp
+++ b/gui/EditTextWidget.cpp
@@ -24,8 +24,7 @@
#include "newgui.h"
EditTextWidget::EditTextWidget(Dialog *boss, int x, int y, int w, int h, const String &text)
- : StaticTextWidget(boss, x, y-1, w, h+2, text, kTextAlignLeft), _backupString(text)
-{
+ : StaticTextWidget(boss, x, y-1, w, h+2, text, kTextAlignLeft), _backupString(text) {
_flags = WIDGET_ENABLED | WIDGET_CLEARBG | WIDGET_RETAIN_FOCUS | WIDGET_WANT_TICKLE;
_type = kEditTextWidget;
@@ -35,8 +34,7 @@ EditTextWidget::EditTextWidget(Dialog *boss, int x, int y, int w, int h, const S
_pos = _label.size();
}
-void EditTextWidget::handleTickle()
-{
+void EditTextWidget::handleTickle() {
uint32 time = _boss->getGui()->get_time();
if (_caretTime < time) {
_caretTime = time + kCaretBlinkTime;
@@ -48,14 +46,12 @@ void EditTextWidget::handleTickle()
}
}
-void EditTextWidget::handleMouseDown(int x, int y, int button, int clickCount)
-{
+void EditTextWidget::handleMouseDown(int x, int y, int button, int clickCount) {
// TODO - once we support "real editing" (i.e. caret can be at any spot),
// a mouse click should place the caret.
}
-bool EditTextWidget::handleKeyDown(uint16 ascii, int keycode, int modifiers)
-{
+bool EditTextWidget::handleKeyDown(uint16 ascii, int keycode, int modifiers) {
bool handled = true;
bool dirty = false;
@@ -84,19 +80,19 @@ bool EditTextWidget::handleKeyDown(uint16 ascii, int keycode, int modifiers)
_label.deleteChar(_pos);
dirty = true;
break;
- case 256+20: // left arrow
+ case 256 + 20: // left arrow
if (_pos > 0)
_pos--;
break;
- case 256+19: // right arrow
+ case 256 + 19: // right arrow
if (_pos < _label.size())
_pos++;
break;
break;
- case 256+22: // home
+ case 256 + 22: // home
_pos = 0;
break;
- case 256+23: // end
+ case 256 + 23: // end
_pos = _label.size();
break;
default:
@@ -111,33 +107,31 @@ bool EditTextWidget::handleKeyDown(uint16 ascii, int keycode, int modifiers)
if (dirty)
draw();
-
+
return handled;
}
-void EditTextWidget::drawWidget(bool hilite)
-{
- NewGui *gui = _boss->getGui();
+void EditTextWidget::drawWidget(bool hilite) {
+ NewGui *gui = _boss->getGui();
// Draw a thin frame around us.
- gui->hline(_x, _y, _x+_w-1, gui->_color);
- gui->hline(_x, _y+_h-1, _x+_w-1, gui->_shadowcolor);
- gui->vline(_x, _y, _y+_h-1, gui->_color);
- gui->vline(_x+_w-1, _y, _y+_h-1, gui->_shadowcolor);
+ gui->hline(_x, _y, _x + _w - 1, gui->_color);
+ gui->hline(_x, _y + _h - 1, _x +_w - 1, gui->_shadowcolor);
+ gui->vline(_x, _y, _y + _h - 1, gui->_color);
+ gui->vline(_x + _w - 1, _y, _y + _h - 1, gui->_shadowcolor);
// Draw the text
- _align = (gui->getStringWidth(_label) > _w-6) ? kTextAlignRight : kTextAlignLeft;
- gui->drawString(_label, _x+2, _y+3, _w-6, gui->_textcolor, _align);
+ _align = (gui->getStringWidth(_label) > _w - 6) ? kTextAlignRight : kTextAlignLeft;
+ gui->drawString(_label, _x + 2, _y + 3, _w - 6, gui->_textcolor, _align);
}
-void EditTextWidget::drawCaret(bool erase)
-{
+void EditTextWidget::drawCaret(bool erase) {
// Only draw if item is visible
if (!isVisible() || !_boss->isVisible())
return;
NewGui *gui = _boss->getGui();
-
+
int16 color = erase ? gui->_bgcolor : gui->_textcolorhi;
int x = _x + _boss->getX() + 2;
int y = _y + _boss->getY() + 1;
@@ -146,12 +140,12 @@ void EditTextWidget::drawCaret(bool erase)
for (int i = 0; i < _pos; i++)
width += gui->getCharWidth(_label[i]);
- if (width > _w-6)
- width = _w-6;
+ if (width > _w - 6)
+ width = _w - 6;
x += width;
- gui->vline(x, y, y+kLineHeight, color);
+ gui->vline(x, y, y + kLineHeight, color);
gui->addDirtyRect(x, y, 2, kLineHeight);
-
+
_caretVisible = !erase;
}