From 1a28393dabf4f4696bf433ddde52e7a25253c955 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Thu, 16 Oct 2008 16:34:15 +0000 Subject: various user interface related updates --- src/ui/ui.cc | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 61 insertions(+), 7 deletions(-) (limited to 'src/ui/ui.cc') diff --git a/src/ui/ui.cc b/src/ui/ui.cc index baedd38..1ecfbb1 100644 --- a/src/ui/ui.cc +++ b/src/ui/ui.cc @@ -7,13 +7,16 @@ #include #include +#include "audio/audio.h" #include "auxiliary/functions.h" #include "core/core.h" #include "filesystem/filesystem.h" +#include "render/gl.h" #include "sys/sys.h" #include "ui/button.h" #include "ui/label.h" #include "ui/menu.h" +#include "ui/paint.h" #include "ui/ui.h" #include "ui/widget.h" @@ -204,6 +207,9 @@ UI::UI() : Window(0) ui_mouse_focus = this; ui_input_focus = this; set_focus(); + + mouse_pointer_color = Palette::Pointer; + mouse_pointer_bitmap.assign("pointer"); } UI::~UI() @@ -386,7 +392,9 @@ void UI::show_menu(const char *label) ui_active_menu = menu; ui_active_menu->event_resize(); - ui_active_menu->show(); + ui_active_menu->show(); + + set_pointer("pointer"); } else { con_warn << "Unknown window '" << label << "'" << std::endl; } @@ -418,6 +426,9 @@ void UI::frame() } event_draw(); + + if (visible()) + draw_pointer(); } /* -- global event handlers ---------------------------------------- */ @@ -453,21 +464,18 @@ bool UI::input_key(const bool pressed, const int key, const unsigned int modifie return handled; } -/* -- event handlers ----------------------------------------------- */ -/* - These functions handle events for this widget only. They are - the fallback input handlers -*/ bool UI::on_keypress(const int key, const unsigned int modifier) { switch( key ) { case SDLK_ESCAPE: if (active()) { - previous_menu(); + hide_menu(); + audio::play("ui/menu"); } else { if (core::application()->connected()) { show_menu("game"); + audio::play("ui/menu"); } } return true; @@ -484,5 +492,51 @@ bool UI::on_keyrelease(const int key, const unsigned int modifier) return false; } +void UI::set_pointer(const char *pointerbitmap, const Palette::Color color, const bool animated) +{ + if (!pointerbitmap) { + mouse_pointer_bitmap.clear(); + } else { + mouse_pointer_bitmap.assign(pointerbitmap); + } + mouse_pointer_animated = animated; + mouse_pointer_color = color; +} + +void UI::draw_pointer() +{ + if (!mouse_pointer_bitmap.size()) + return; + + math::Color c(palette()->color(mouse_pointer_color)); + if (mouse_pointer_animated) { + c.a = 1; + } else { + c.a = 0.5f; + } + paint::color(c); + math::Vector2f pos(mouse_cursor.x - pointer_size * 0.5f, mouse_cursor.y - pointer_size * 0.5f); + math::Vector2f s(pointer_size, pointer_size); + + std::string texture("pointers/"); + texture.append(mouse_pointer_bitmap); + + if (mouse_pointer_animated) { + render::gl::push(); + render::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; + render::gl::rotate(angle, math::Vector3f(0, 0, 1.0f)); + render::gl::translate(-mouse_cursor.x, -mouse_cursor.y, 0); + } + + paint::bitmap(pos, s, texture); + + if (mouse_pointer_animated) { + render::gl::pop(); + } +} + } -- cgit v1.2.3