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/ui.cc')
-rw-r--r--src/ui/ui.cc69
1 files changed, 58 insertions, 11 deletions
diff --git a/src/ui/ui.cc b/src/ui/ui.cc
index 0877519..95b18e2 100644
--- a/src/ui/ui.cc
+++ b/src/ui/ui.cc
@@ -4,13 +4,11 @@
the terms of the GNU General Public License version 2
*/
-#include <string>
-#include <sstream>
-
#include "audio/audio.h"
#include "auxiliary/functions.h"
#include "core/core.h"
#include "core/application.h"
+#include "core/cvar.h"
#include "filesystem/filesystem.h"
#include "render/gl.h"
#include "sys/sys.h"
@@ -20,6 +18,10 @@
#include "ui/ui.h"
#include "ui/widget.h"
+#include <string>
+#include <sstream>
+#include <cassert>
+
namespace ui
{
@@ -32,8 +34,12 @@ math::Vector2f UI::elementsize(256, 32);
float UI::padding = 24.0f;
float UI::margin = 16.0f;
+float UI::icon_small = 24.0f;
+
float UI::pointer_size = 48.0f;
+core::Cvar *ui_tooltiptimeout = nullptr;
+
UI *global_ui = 0;
UI *root()
@@ -44,6 +50,9 @@ UI *root()
void init()
{
con_print << "^BInitializing user interface..." << std::endl;
+
+ ui_tooltiptimeout = core::Cvar::get("ui_tooltiptimeout", "250", core::Cvar::Archive);
+ ui_tooltiptimeout->set_info("[int] time in milliseconds before a tooltip is shown");
if (!global_ui) {
global_ui = new UI();
@@ -94,6 +103,7 @@ UI::UI() : Window(0)
mouse_pointer_bitmap.assign("pointer");
mouse_buttonleft_pressed = false;
+ ui_tooltip_timestamp = core::application()->timestamp();
}
UI::~UI()
@@ -266,7 +276,7 @@ void UI::frame()
Widget *f = 0;
if (!mouse_buttonleft_pressed) {
- f = find_mouse_focus(mouse_cursor);
+ f = find_widget_in_location(mouse_cursor);
} else {
f = find_visible_child(ui_mouse_focus);
}
@@ -275,15 +285,38 @@ void UI::frame()
}
ui_mouse_focus = f;
+ // show tooltip if the timeout has expired
+ if (ui_mouse_focus && ui_mouse_focus->tooltip() && ui_mouse_focus->tooltip()->text().size() && ui_mouse_focus->tooltip()->hidden())
+ {
+ assert(ui_tooltiptimeout != nullptr);
+ unsigned long timeout = (unsigned long) ui_tooltiptimeout->value();
+
+ if (ui_tooltip_timestamp + timeout < core::application()->timestamp()) {
+ // move the tooltip below the mouse cursor
+ math::Vector2f p(
+ ui_mouse_focus->tooltip()->parent() ?
+ ui_mouse_focus->tooltip()->parent()->to_local_coords(mouse_cursor) :
+ mouse_cursor);
+
+ ui_mouse_focus->tooltip()->set_location(p.x() - ui_mouse_focus->tooltip()->width() * 0.5f, p.y() + pointer_size);
+ ui_mouse_focus->tooltip()->resize();
+ ui_mouse_focus->tooltip()->show();
+ }
+ }
+
// reset mouse pointer
ui::root()->set_pointer("pointer");
// draw the widget stack
event_draw();
-
- // draw the mouse pointer
- if (visible())
+
+ if (visible()) {
+ // draw tooltip
+ Tooltip::event_draw_global();
+
+ // draw the mouse pointer
draw_pointer();
+ }
}
/* -- global event handlers ---------------------------------------- */
@@ -293,6 +326,13 @@ void UI::frame()
*/
void UI::input_mouse(const float x, const float y)
{
+ // hide tooltip if the mouse has been moved
+ if (Tooltip::global() && Tooltip::global()->visible())
+ {
+ Tooltip::global()->hide();
+ }
+ ui_tooltip_timestamp = core::application()->timestamp();
+
mouse_cursor.assign(x, y);
}
@@ -300,13 +340,20 @@ bool UI::input_mouse_button(const bool pressed, unsigned int button)
{
bool handled = false;
+ // hide tooltip if a mouse button has been clicked
+ if (Tooltip::global() && Tooltip::global()->visible())
+ {
+ Tooltip::global()->hide();
+ }
+ ui_tooltip_timestamp = core::application()->timestamp();
+
if (button == SDL_BUTTON_LEFT)
{
mouse_buttonleft_pressed = pressed;
}
// set mouse focus
- Widget *f = find_mouse_focus(mouse_cursor);
+ Widget *f = find_widget_in_location(mouse_cursor);
if (f)
{
f->event_mouse(mouse_cursor);
@@ -326,7 +373,7 @@ bool UI::input_mouse_wheel(const math::Vector2f & direction)
bool handled = false;
// set mouse focus
- Widget *f = find_mouse_focus(mouse_cursor);
+ Widget *f = find_widget_in_location(mouse_cursor);
if (f)
{
f->event_mouse(mouse_cursor);
@@ -399,8 +446,8 @@ void UI::draw_pointer()
gl::push();
gl::translate(mouse_cursor.x(), mouse_cursor.y(), 0);
- float angle = core::application()->time() * 0.75f - floorf(core::application()->time() * 0.75f);
- angle *= 360.0f;
+ const float t = core::application()->time() * 0.75f;
+ const float angle = (t - floorf(t)) * 360.0f;
gl::rotate(angle, math::Vector3f(0, 0, 1.0f));
gl::translate(-mouse_cursor.x(), -mouse_cursor.y(), 0);
}