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-12 17:51:55 +0000
committerStijn Buys <ingar@osirion.org>2008-10-12 17:51:55 +0000
commit97fca172fd51270cebd5b722f861a6c753bd4d2a (patch)
tree0740e43d1d360d536a4709384b49b1667f6bfae6
parent574bf11742c40203a4433c0b69264014b10b5a96 (diff)
inputbox respects text width
-rw-r--r--src/ui/input.cc26
1 files changed, 18 insertions, 8 deletions
diff --git a/src/ui/input.cc b/src/ui/input.cc
index 0c4ea32..5e000d2 100644
--- a/src/ui/input.cc
+++ b/src/ui/input.cc
@@ -52,11 +52,11 @@ void Input::draw()
draw_background();
draw_border();
- using namespace render;
size_t text_width = (size_t) width() / font()->width();
math::Vector2f v(global_location());
paint::color(palette()->foreground());
+ // draw the part before the cursor
std::string firstpart(input_text.substr(0, input_pos));
size_t draw_width = 0;
const char *c = firstpart.c_str();
@@ -74,14 +74,13 @@ void Input::draw()
while (*c && draw_width > text_width - 2) {
if (aux::is_color_code(c)) {
c++;
- Text::setcolor(*c);
+ render::Text::setcolor(*c);
} else {
draw_width--;
}
c++;
}
- // draw the part before the cursor
if (*c) {
paint::text(v, size(), font(), std::string(c), AlignLeft | AlignVCenter);
}
@@ -89,15 +88,26 @@ void Input::draw()
// draw the part behind the cursor
v.x += draw_width * font()->width();
if (input_pos < input_text.size()) {
- // FIXME limit to width
if (input_pos > 1 && aux::is_color_code(input_text.c_str() + input_pos -1)) {
- Text::setcolor(input_text[input_pos]);
+ render::Text::setcolor(input_text[input_pos]);
}
- c = input_text.c_str() + input_pos;
- paint::text(v, size(), font(), std::string(c), AlignLeft | AlignVCenter);
+ // limit to width
+ std::string secondpart;
+ c = &input_text.c_str()[input_pos];
+ while (*c && (draw_width <= (text_width - 2))) {
+ if (aux::is_color_code(c)) {
+ c++;
+ } else {
+ draw_width++;
+ secondpart += *c;
+ }
+ c++;
+ }
+
+ paint::text(v, size(), font(), secondpart, AlignLeft | AlignVCenter);
}
- // draw cursor
+ // draw the cursor
if (has_input_focus() && (core::application()->time() - ::floorf(core::application()->time())) < 0.5f) {
std::string cursor("^B");
cursor += (char) 11;