diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/menu/software_mouse_pointer.cpp | 55 | ||||
-rw-r--r-- | src/menu/software_mouse_pointer.hpp | 14 |
2 files changed, 65 insertions, 4 deletions
diff --git a/src/menu/software_mouse_pointer.cpp b/src/menu/software_mouse_pointer.cpp index 99aed07a..d5be92d1 100644 --- a/src/menu/software_mouse_pointer.cpp +++ b/src/menu/software_mouse_pointer.cpp @@ -30,7 +30,7 @@ namespace usdx { SoftwareMousePointer::SoftwareMousePointer(Container* parent, EventManager* event_manager) - : DrawableControl(parent), color(255,255,255,100) + : DrawableControl(parent), color(255,255,255,100), down(false) { fade_inactive = new Timer(this, 2000, true); @@ -51,11 +51,17 @@ namespace usdx mouse_move_connection = event_manager->mouse_move.connect( boost::bind(&SoftwareMousePointer::on_mouse_move, this, _1, _2)); + mouse_down_connection = event_manager->mouse_down.connect( + boost::bind(&SoftwareMousePointer::on_mouse_down, this, _1, _2, _3)); + mouse_up_connection = event_manager->mouse_up.connect( + boost::bind(&SoftwareMousePointer::on_mouse_up, this, _1, _2, _3)); } SoftwareMousePointer::~SoftwareMousePointer() { mouse_move_connection.disconnect(); + mouse_down_connection.disconnect(); + mouse_up_connection.disconnect(); if (texture_normal != NULL) { delete texture_normal; @@ -68,6 +74,16 @@ namespace usdx } } + Texture* SoftwareMousePointer::get_current_texture() const + { + if (is_down()) { + return texture_pressed->get(); + } + else { + return texture_normal->get(); + } + } + void SoftwareMousePointer::draw(void) { if (fade_inactive->is_ready()) { @@ -75,7 +91,7 @@ namespace usdx return; } - Activator<Texture> a(texture_normal->get()); + Activator<Texture> a(get_current_texture()); glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_TEXTURE_COORD_ARRAY); @@ -97,14 +113,45 @@ namespace usdx glDisableClientState(GL_COLOR_ARRAY); } - void SoftwareMousePointer::on_mouse_move(uint16_t x, uint16_t y) + void SoftwareMousePointer::update(void) { - set_position(x, y); fade_inactive->update(); if (!is_visible()) { set_visible(true); } } + + void SoftwareMousePointer::on_mouse_move(uint16_t x, uint16_t y) + { + set_position(x, y); + update(); + } + + void SoftwareMousePointer::on_mouse_down(uint8_t button, uint16_t x, uint16_t y) + { + if (button == 1) { + boost::unique_lock<boost::shared_mutex> lock(down_mutex); + down = true; + } + + update(); + } + + void SoftwareMousePointer::on_mouse_up(uint8_t button, uint16_t x, uint16_t y) + { + if (button == 1) { + boost::unique_lock<boost::shared_mutex> lock(down_mutex); + down = false; + } + + update(); + } + + bool SoftwareMousePointer::is_down(void) const + { + boost::shared_lock<boost::shared_mutex> lock(down_mutex); + return down; + } }; diff --git a/src/menu/software_mouse_pointer.hpp b/src/menu/software_mouse_pointer.hpp index 0e3d2ff8..797236ff 100644 --- a/src/menu/software_mouse_pointer.hpp +++ b/src/menu/software_mouse_pointer.hpp @@ -34,6 +34,7 @@ #include "utils/disposer.hpp" #include <boost/signals2.hpp> +#include <boost/thread/shared_mutex.hpp> #include <GL/gl.h> namespace usdx @@ -44,12 +45,21 @@ namespace usdx GLfloat vertices[8]; RgbaColor color; + bool down; + Disposer<Texture>* texture_normal; Disposer<Texture>* texture_pressed; Timer* fade_inactive; boost::signals2::connection mouse_move_connection; + boost::signals2::connection mouse_down_connection; + boost::signals2::connection mouse_up_connection; + + mutable boost::shared_mutex down_mutex; + + Texture* get_current_texture() const; + void update(void); protected: void draw(void); @@ -59,6 +69,10 @@ namespace usdx virtual ~SoftwareMousePointer(); void on_mouse_move(uint16_t x, uint16_t y); + void on_mouse_down(uint8_t button, uint16_t x, uint16_t y); + void on_mouse_up(uint8_t button, uint16_t x, uint16_t y); + + bool is_down(void) const; }; }; |