diff options
Diffstat (limited to 'src/menu')
-rw-r--r-- | src/menu/drawable_control.cpp | 39 | ||||
-rw-r--r-- | src/menu/drawable_control.hpp | 12 | ||||
-rw-r--r-- | src/menu/software_mouse_pointer.cpp | 40 | ||||
-rw-r--r-- | src/menu/software_mouse_pointer.hpp | 5 |
4 files changed, 64 insertions, 32 deletions
diff --git a/src/menu/drawable_control.cpp b/src/menu/drawable_control.cpp index cf44aa73..6ee5100c 100644 --- a/src/menu/drawable_control.cpp +++ b/src/menu/drawable_control.cpp @@ -35,14 +35,14 @@ namespace usdx log4cpp::Category::getInstance("usdx.menu.drawable_control"); DrawableControl::DrawableControl(Container* parent) - : Control(parent), parent(parent) + : Control(parent), position(0, 0), parent(parent) { ContainerHelper(this).add(parent); } DrawableControl::DrawableControl(Container* parent, const ContainerHelper& helper) - : Control(parent), parent(parent) + : Control(parent), position(0, 0), parent(parent) { helper.add(parent); } @@ -59,9 +59,44 @@ namespace usdx { glLoadIdentity(); + { + // position + boost::mutex::scoped_lock lock(position_mutex); + glTranslatef(position.get_x(), position.get_y(), 0.0f); + } + Drawable::repaint(); } + void DrawableControl::set_position(const Point<int>& position) + { + boost::mutex::scoped_lock lock(position_mutex); + this->position = position; + } + + void DrawableControl::set_position(int left, int top) + { + boost::mutex::scoped_lock lock(position_mutex); + this->position = Point<int>(left, top); + } + + + const Point<int>& DrawableControl::get_position(void) const + { + return position; + } + + int DrawableControl::get_left(void) const + { + return position.get_x(); + } + + int DrawableControl::get_top(void) const + { + return position.get_y(); + } + + DrawableControl::ContainerHelper::ContainerHelper(DrawableControl* self) : self(self) { diff --git a/src/menu/drawable_control.hpp b/src/menu/drawable_control.hpp index de3881c5..e954f291 100644 --- a/src/menu/drawable_control.hpp +++ b/src/menu/drawable_control.hpp @@ -28,10 +28,12 @@ #define DRAWABLE_CONTROL_HPP #include <SDL/SDL.h> +#include <boost/thread/mutex.hpp> #include <log4cpp/Category.hh> #include "drawable.hpp" #include "control.hpp" +#include "utils/point.hpp" namespace usdx { @@ -42,6 +44,9 @@ namespace usdx private: static log4cpp::Category& log; + Point<int> position; + + boost::mutex position_mutex; protected: Container* parent; @@ -61,6 +66,13 @@ namespace usdx virtual ~DrawableControl(); void repaint(void); + + void set_position(const Point<int>& position); + void set_position(int left, int top); + + const Point<int>& get_position(void) const; + int get_left(void) const; + int get_top(void) const; }; }; diff --git a/src/menu/software_mouse_pointer.cpp b/src/menu/software_mouse_pointer.cpp index 32609e13..dfe67475 100644 --- a/src/menu/software_mouse_pointer.cpp +++ b/src/menu/software_mouse_pointer.cpp @@ -31,7 +31,7 @@ namespace usdx { SoftwareMousePointer::SoftwareMousePointer(Container* parent, EventManager* event_manager) - : DrawableControl(parent), x(-1), y(-1) + : DrawableControl(parent) { this->vertices[0] = 0.0f; this->vertices[1] = 40.0f; @@ -68,6 +68,8 @@ namespace usdx this->texture[6] = 0.0f; this->texture[7] = 0.0f; + set_position(0, 0); + texture_normal = new Texture("game/themes/Deluxe/interface/cursor.png"); texture_pressed = new Texture("game/themes/Deluxe/interface/cursor_pressed.png"); @@ -92,38 +94,26 @@ namespace usdx void SoftwareMousePointer::draw(void) { - glLoadIdentity(); - - boost::mutex::scoped_lock lock(mutex); - - if (x >= 0 && y >= 0) { - glTranslatef(x, y, 0.0f); - lock.unlock(); + glBindTexture(GL_TEXTURE_2D, texture_normal->get_texture()); - glBindTexture(GL_TEXTURE_2D, texture_normal->get_texture()); + glEnableClientState(GL_VERTEX_ARRAY); + glEnableClientState(GL_TEXTURE_COORD_ARRAY); + glEnableClientState(GL_COLOR_ARRAY); - glEnableClientState(GL_VERTEX_ARRAY); - glEnableClientState(GL_TEXTURE_COORD_ARRAY); - glEnableClientState(GL_COLOR_ARRAY); + glVertexPointer(2, GL_FLOAT, 0, vertices); + glColorPointer(4, GL_UNSIGNED_BYTE, 0, color); + glTexCoordPointer(2, GL_FLOAT, 0, texture); - glVertexPointer(2, GL_FLOAT, 0, vertices); - glColorPointer(4, GL_UNSIGNED_BYTE, 0, color); - glTexCoordPointer(2, GL_FLOAT, 0, texture); + glDrawArrays(GL_QUADS, 0, 4); - glDrawArrays(GL_QUADS, 0, 4); - - glDisableClientState(GL_VERTEX_ARRAY); - glDisableClientState(GL_TEXTURE_COORD_ARRAY); - glDisableClientState(GL_COLOR_ARRAY); - } + glDisableClientState(GL_VERTEX_ARRAY); + glDisableClientState(GL_TEXTURE_COORD_ARRAY); + glDisableClientState(GL_COLOR_ARRAY); } void SoftwareMousePointer::on_mouse_move(int x, int y) { - boost::mutex::scoped_lock lock(mutex); - - this->x = x; - this->y = y; + set_position(x, y); } }; diff --git a/src/menu/software_mouse_pointer.hpp b/src/menu/software_mouse_pointer.hpp index d2f8abb0..15e855db 100644 --- a/src/menu/software_mouse_pointer.hpp +++ b/src/menu/software_mouse_pointer.hpp @@ -41,9 +41,6 @@ namespace usdx class SoftwareMousePointer : public DrawableControl { private: - int x; - int y; - GLfloat vertices[8]; GLubyte color[16]; GLfloat texture[8]; @@ -53,8 +50,6 @@ namespace usdx boost::signals2::connection mouse_move_connection; - boost::mutex mutex; - protected: void draw(void); |