Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
path: root/src/ui
diff options
context:
space:
mode:
Diffstat (limited to 'src/ui')
-rw-r--r--src/ui/container.cc4
-rw-r--r--src/ui/input.cc8
-rw-r--r--src/ui/paint.cc4
-rw-r--r--src/ui/paint.h10
-rw-r--r--src/ui/ui.cc37
-rw-r--r--src/ui/ui.h2
-rw-r--r--src/ui/widget.cc14
-rw-r--r--src/ui/window.cc9
-rw-r--r--src/ui/window.h5
9 files changed, 66 insertions, 27 deletions
diff --git a/src/ui/container.cc b/src/ui/container.cc
index d544244..5a12e8e 100644
--- a/src/ui/container.cc
+++ b/src/ui/container.cc
@@ -30,12 +30,12 @@ Container::~Container()
void Container::resize()
{
float w = container_childsize.width() * 1.5f;
- float h = children().size() * container_childsize.height() + (children().size()+1) * container_margin;
+ float h = children().size() * (container_childsize.height() + margin()) + container_childsize.height();
set_size(w, h);
const float x = container_childsize.width() * 0.25f;
- float y = container_margin;
+ float y = container_childsize.height() * 0.5f;
// reposition all children within the container
for (Children::iterator it = children().begin(); it != children().end(); it++) {
diff --git a/src/ui/input.cc b/src/ui/input.cc
index 5e000d2..8113354 100644
--- a/src/ui/input.cc
+++ b/src/ui/input.cc
@@ -8,7 +8,6 @@
#include "ui/paint.h"
#include "auxiliary/functions.h"
#include "core/core.h"
-#include "render/render.h"
namespace ui
{
@@ -52,7 +51,7 @@ void Input::draw()
draw_background();
draw_border();
- size_t text_width = (size_t) width() / font()->width();
+ size_t text_width = (size_t) floorf(width() / font()->width());
math::Vector2f v(global_location());
paint::color(palette()->foreground());
@@ -74,7 +73,7 @@ void Input::draw()
while (*c && draw_width > text_width - 2) {
if (aux::is_color_code(c)) {
c++;
- render::Text::setcolor(*c);
+ paint::color_code(*c);
} else {
draw_width--;
}
@@ -89,7 +88,7 @@ void Input::draw()
v.x += 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)) {
- render::Text::setcolor(input_text[input_pos]);
+ paint::color_code(input_text[input_pos]);
}
// limit to width
std::string secondpart;
@@ -119,6 +118,7 @@ bool Input::on_keypress(const int key, const unsigned int modifier)
{
switch (key) {
case SDLK_TAB:
+ // FIXME should not be here
core::CommandBuffer::complete(input_text, input_pos);
return true;
break;
diff --git a/src/ui/paint.cc b/src/ui/paint.cc
index 33ee54f..d50e3b5 100644
--- a/src/ui/paint.cc
+++ b/src/ui/paint.cc
@@ -27,9 +27,9 @@ void color(math::Color const & color)
render::gl::color(color);
}
-void color_code(const char *c)
+void color_code(const char c)
{
- render::Text::setcolor(*c);
+ render::Text::setcolor(c);
}
void border(math::Vector2f const &location, math::Vector2f const &size)
diff --git a/src/ui/paint.h b/src/ui/paint.h
index 367b001..c90f1b5 100644
--- a/src/ui/paint.h
+++ b/src/ui/paint.h
@@ -22,7 +22,7 @@ void color(float r=0.0f, float g=0.0f, float b=0.0f, float a=1.0f);
void color(math::Color const & color);
/// set paint color
-void color_code(const char *c);
+void color_code(const char c);
/// draw a border
void border(math::Vector2f const &location, math::Vector2f const &size);
@@ -33,12 +33,12 @@ void rectangle(math::Vector2f const &location, math::Vector2f const &size);
/// draw a rectangular bitmap
void bitmap(math::Vector2f const &location, math::Vector2f const &size, std::string const &texture);
-/// draw text
+/// draw one line of text from a string
void text(math::Vector2f const &location, math::Vector2f const &size, Font const *font,
std::string const &text, unsigned int align = AlignCenter);
-
-/// draw textstream
-void text(math::Vector2f const &location, Font const *font, std::stringstream & textstream);
+
+/// draw unaligned text from a stringstream
+void text(math::Vector2f const &location, Font const *font, std::stringstream & textstream);
}
diff --git a/src/ui/ui.cc b/src/ui/ui.cc
index 2cadd8b..baedd38 100644
--- a/src/ui/ui.cc
+++ b/src/ui/ui.cc
@@ -381,13 +381,12 @@ void UI::show_menu(const char *label)
} else {
menu->clear_previous();
}
- ui_active_menu = menu;
- ui_active_menu->event_resize();
- ui_active_menu->raise();
- ui_active_menu->show();
- ui_active_menu->set_focus();
ui_mouse_focus = this;
ui_input_focus = this;
+
+ ui_active_menu = menu;
+ ui_active_menu->event_resize();
+ ui_active_menu->show();
} else {
con_warn << "Unknown window '" << label << "'" << std::endl;
}
@@ -436,20 +435,22 @@ void UI::input_mouse(const float x, const float y)
ui_mouse_focus = f;
}
-void UI::input_key(const bool pressed, const int key, const unsigned int modifier)
+bool UI::input_key(const bool pressed, const int key, const unsigned int modifier)
{
+ bool handled = false;
if (key < 512) {
// keyboard keys
Widget *f = find_input_focus();
if (f) {
- f->event_key(pressed, key, modifier);
+ handled = f->event_key(pressed, key, modifier);
}
ui_input_focus = f;
} else {
// mosue buttons
if (ui_mouse_focus)
- ui_mouse_focus->event_key(pressed, key, modifier);
+ handled = ui_mouse_focus->event_key(pressed, key, modifier);
}
+ return handled;
}
/* -- event handlers ----------------------------------------------- */
@@ -459,12 +460,28 @@ void UI::input_key(const bool pressed, const int key, const unsigned int modifie
*/
bool UI::on_keypress(const int key, const unsigned int modifier)
{
- return true;
+ switch( key ) {
+
+ case SDLK_ESCAPE:
+ if (active()) {
+ previous_menu();
+ } else {
+ if (core::application()->connected()) {
+ show_menu("game");
+ }
+ }
+ return true;
+ break;
+ default:
+ break;
+ }
+
+ return false;
}
bool UI::on_keyrelease(const int key, const unsigned int modifier)
{
- return true;
+ return false;
}
}
diff --git a/src/ui/ui.h b/src/ui/ui.h
index 583f76c..8fa32c2 100644
--- a/src/ui/ui.h
+++ b/src/ui/ui.h
@@ -61,7 +61,7 @@ public:
void input_mouse(const float x, const float y);
/// receive global key input
- void input_key(const bool pressed, const int key, const unsigned int modifier);
+ bool input_key(const bool pressed, const int key, const unsigned int modifier);
/// run a user interface frame
void frame();
diff --git a/src/ui/widget.cc b/src/ui/widget.cc
index 1ecfcc8..24dfe5c 100644
--- a/src/ui/widget.cc
+++ b/src/ui/widget.cc
@@ -128,6 +128,20 @@ void Widget::show()
void Widget::hide()
{
widget_visible = false;
+ if (parent() && focus()) {
+ Widget::Children::reverse_iterator it = parent()->children().rbegin();
+
+ while (it != parent()->children().rend()) {
+ Widget *w = (*it);
+ if (w != this && w->visible()) {
+ widget_focus = false;
+ w->widget_focus = true;
+ it = parent()->children().rend();
+ } else {
+ it++;
+ }
+ }
+ }
}
diff --git a/src/ui/window.cc b/src/ui/window.cc
index e79262f..3015a10 100644
--- a/src/ui/window.cc
+++ b/src/ui/window.cc
@@ -23,11 +23,16 @@ Window::~Window()
{
}
-void Window::show() {
+void Window::show()
+{
resize();
Widget::show();
raise();
- set_focus();
+ Widget *w = this;
+ while (w && w->visible()) {
+ w->set_focus();
+ w = w->parent();
+ }
}
void Window::set_previous(Window *previous)
diff --git a/src/ui/window.h b/src/ui/window.h
index 2c0e2a5..412d1f1 100644
--- a/src/ui/window.h
+++ b/src/ui/window.h
@@ -12,6 +12,7 @@
namespace ui
{
+/// a user interface window
class Window : public Widget
{
@@ -27,7 +28,9 @@ public:
/// clear the label of the previous window
void clear_previous();
- /// showing a window sets focus
+ /// show the window
+ /**show() sets focus on the window and all of its parents
+ */
virtual void show();
inline const std::string &previous() const {