Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/ui/inputbox.cc')
-rw-r--r--src/ui/inputbox.cc36
1 files changed, 18 insertions, 18 deletions
diff --git a/src/ui/inputbox.cc b/src/ui/inputbox.cc
index 07a0a7e..6f493e2 100644
--- a/src/ui/inputbox.cc
+++ b/src/ui/inputbox.cc
@@ -18,7 +18,7 @@ InputBox::InputBox(Widget *parent) : Widget(parent)
input_text.clear();
input_pos = 0;
input_max = 512;
-
+
set_label("input");
set_background(false);
set_border(false);
@@ -72,7 +72,7 @@ void InputBox::draw()
size_t prompt_width = aux::text_length(input_prompt);
math::Vector2f v(global_location());
paint::color(palette()->text());
-
+
// draw the prompt
if (prompt_width) {
paint::text(v, size(), font(), input_prompt);
@@ -84,7 +84,7 @@ void InputBox::draw()
std::string firstpart(input_text.substr(0, input_pos));
size_t draw_width = 0;
const char *c = firstpart.c_str();
-
+
while (*c) {
if (aux::is_color_code(c)) {
c++;
@@ -93,7 +93,7 @@ void InputBox::draw()
}
c++;
}
-
+
c = firstpart.c_str();
while (*c && draw_width > text_width - prompt_width - 1) {
if (aux::is_color_code(c)) {
@@ -104,15 +104,15 @@ void InputBox::draw()
}
c++;
}
-
+
if (*c) {
paint::text(v, size(), font(), std::string(c));
}
-
+
// draw the part behind the cursor
v[0] += draw_width * font()->width();
if (input_pos < input_text.size()) {
- if (input_pos > 1 && aux::is_color_code(input_text.c_str() + input_pos -1)) {
+ if (input_pos > 1 && aux::is_color_code(input_text.c_str() + input_pos - 1)) {
paint::color_code(input_text[input_pos]);
}
// limit to width
@@ -130,7 +130,7 @@ void InputBox::draw()
paint::text(v, size(), font(), secondpart);
}
-
+
// draw the cursor
if (has_input_focus() && (core::application()->time() - ::floorf(core::application()->time())) < 0.5f) {
std::string cursor("^B");
@@ -150,46 +150,46 @@ bool InputBox::on_keypress(const int key, const unsigned int modifier)
core::CommandBuffer::complete(input_text, input_pos);
return true;
break;
-
+
case SDLK_HOME:
input_pos = 0;
return true;
break;
-
+
case SDLK_END:
input_pos = input_text.size();
return true;
break;
-
+
case SDLK_LEFT:
if (input_pos > 0)
input_pos--;
return true;
break;
-
+
case SDLK_RIGHT:
if (input_pos < input_text.size())
input_pos++;
return true;
break;
-
+
case SDLK_DELETE:
if (input_text.size() && input_pos < input_text.size()) {
input_text.erase(input_pos, 1);
}
return true;
break;
-
+
case SDLK_BACKSPACE:
if (input_text.size() && input_pos) {
- input_text.erase(input_pos-1, 1);
+ input_text.erase(input_pos - 1, 1);
input_pos--;
}
return true;
break;
-
+
default:
- if ((key >= 32) && (key <175)) {
+ if ((key >= 32) && (key < 175)) {
if (input_text.size() < input_max) {
// TODO bell sound
if (input_pos == input_text.size())
@@ -202,7 +202,7 @@ bool InputBox::on_keypress(const int key, const unsigned int modifier)
}
break;
}
-
+
return false;
}
bool InputBox::on_keyrelease(const int key, const unsigned int modifier)