Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStijn Buys <ingar@osirion.org>2008-10-19 13:45:07 +0000
committerStijn Buys <ingar@osirion.org>2008-10-19 13:45:07 +0000
commit56cdfd3822d2800abdd2f912ab7f76a5764793a7 (patch)
tree2656c7ef694117e0554ae4a47bb09629c78ed8af /src/ui/inputbox.cc
parente6f1fad441a7737549f463ebac1c9de062b5173d (diff)
scrollpane widget, updated chatbox
Diffstat (limited to 'src/ui/inputbox.cc')
-rw-r--r--src/ui/inputbox.cc55
1 files changed, 41 insertions, 14 deletions
diff --git a/src/ui/inputbox.cc b/src/ui/inputbox.cc
index 30cae3b..39f8393 100644
--- a/src/ui/inputbox.cc
+++ b/src/ui/inputbox.cc
@@ -16,6 +16,7 @@ InputBox::InputBox(Widget *parent) : Widget(parent)
{
input_text.clear();
input_pos = 0;
+ input_max = 512;
set_label("input");
set_background(false);
@@ -46,15 +47,38 @@ void InputBox::set_text(const char *text)
input_pos = input_text.size();
}
+void InputBox::set_prompt(const std::string &prompt)
+{
+ input_prompt.assign(prompt);
+}
+
+void InputBox::set_prompt(const char *prompt)
+{
+ if (!prompt)
+ input_prompt.clear();
+ else
+ input_prompt.assign(prompt);
+}
+
+void InputBox::set_max(const size_t max)
+{
+ input_max = max;
+}
+
void InputBox::draw()
{
- draw_background();
- draw_border();
-
size_t text_width = (size_t) floorf(width() / font()->width());
+ size_t prompt_width = aux::text_length(input_prompt);
math::Vector2f v(global_location());
- paint::color(palette()->foreground());
+ paint::color(palette()->text());
+ // draw the prompt
+ if (prompt_width) {
+ paint::text(v, size(), font(), input_prompt);
+ v.x += prompt_width * font()->width();
+ }
+ paint::color(palette()->text());
+
// draw the part before the cursor
std::string firstpart(input_text.substr(0, input_pos));
size_t draw_width = 0;
@@ -70,7 +94,7 @@ void InputBox::draw()
}
c = firstpart.c_str();
- while (*c && draw_width > text_width - 2) {
+ while (*c && draw_width > text_width - prompt_width - 1) {
if (aux::is_color_code(c)) {
c++;
paint::color_code(*c);
@@ -81,7 +105,7 @@ void InputBox::draw()
}
if (*c) {
- paint::text(v, size(), font(), std::string(c), AlignLeft | AlignVCenter);
+ paint::text(v, size(), font(), std::string(c));
}
// draw the part behind the cursor
@@ -93,7 +117,7 @@ void InputBox::draw()
// limit to width
std::string secondpart;
c = &input_text.c_str()[input_pos];
- while (*c && (draw_width <= (text_width - 2))) {
+ while (*c && (draw_width <= (text_width - prompt_width - 1))) {
if (aux::is_color_code(c)) {
c++;
} else {
@@ -103,14 +127,14 @@ void InputBox::draw()
c++;
}
- paint::text(v, size(), font(), secondpart, AlignLeft | AlignVCenter);
+ 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");
cursor += (char) 11;
- paint::text(v, size(), font(), cursor, AlignLeft | AlignVCenter);
+ paint::text(v, size(), font(), cursor);
}
}
@@ -162,11 +186,14 @@ bool InputBox::on_keypress(const int key, const unsigned int modifier)
default:
if ((key >= 32) && (key <175)) {
- if (input_pos == input_text.size())
- input_text += (char)key;
- else
- input_text.insert(input_pos, 1, (char)key);
- input_pos++;
+ if (input_text.size() < input_max) {
+ // TODO bell sound
+ if (input_pos == input_text.size())
+ input_text += (char)key;
+ else
+ input_text.insert(input_pos, 1, (char)key);
+ input_pos++;
+ }
return true;
}
break;