diff options
Diffstat (limited to 'src/ui/ui.cc')
-rw-r--r-- | src/ui/ui.cc | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/ui/ui.cc b/src/ui/ui.cc index 700099e..fc52bbf 100644 --- a/src/ui/ui.cc +++ b/src/ui/ui.cc @@ -11,6 +11,7 @@ #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" @@ -34,6 +35,8 @@ float UI::margin = 16.0f; float UI::pointer_size = 48.0f; +core::Cvar *ui_tooltiptimeout = nullptr; + UI *global_ui = 0; UI *root() @@ -44,6 +47,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 +100,7 @@ UI::UI() : Window(0) mouse_pointer_bitmap.assign("pointer"); mouse_buttonleft_pressed = false; + ui_tooltip_timestamp = core::application()->timestamp(); } UI::~UI() @@ -275,6 +282,17 @@ 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()->hidden()) + { + assert(ui_tooltiptimeout != nullptr); + unsigned long timeout = (unsigned long) ui_tooltiptimeout->value(); + + if (ui_tooltip_timestamp + timeout < core::application()->timestamp()) { + ui_mouse_focus->tooltip()->show(); + } + } + // reset mouse pointer ui::root()->set_pointer("pointer"); @@ -293,6 +311,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,6 +325,13 @@ 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; |