changeset 416:a8bb57884723

* Added a getX/getY command to the cursor
author helios2000@33b003aa-7bff-0310-803a-e67f0ece8222
date Wed, 03 Feb 2010 18:59:34 +0000
parents 16ea97290dbc
children 14e8087cde2c
files engine/core/video/cursor.cpp engine/core/video/cursor.h engine/core/video/video.i
diffstat 3 files changed, 17 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/engine/core/video/cursor.cpp	Wed Feb 03 01:50:37 2010 +0000
+++ b/engine/core/video/cursor.cpp	Wed Feb 03 18:59:34 2010 +0000
@@ -87,6 +87,8 @@
 		m_drag_animtime(0),
 		m_drag_offset_x(0),
 		m_drag_offset_y(0),
+		m_mx(0),
+		m_my(0),
 		m_timemanager(TimeManager::instance()) {
 		assert(m_timemanager);
 		set(m_cursor_type, m_cursor_id);
@@ -128,12 +130,10 @@
 	}
 	
 	void Cursor::draw() {
-		int mx = 0;
-		int my = 0;
+		SDL_GetMouseState(&m_mx, &m_my);
 		if ((m_cursor_type == CURSOR_NATIVE) && (m_drag_type == CURSOR_NONE)) {
 			return;
 		}
-		SDL_GetMouseState(&mx, &my);
 		
 		// render possible drag image
 		Image* img = NULL;
@@ -145,7 +145,7 @@
  			img = anim.getFrameByTimestamp(animtime);
 		}
 		if (img) {
-			Rect area(mx + m_drag_offset_x + img->getXShift(), my + m_drag_offset_y + img->getYShift(), img->getWidth(), img->getHeight());
+			Rect area(m_mx + m_drag_offset_x + img->getXShift(), m_my + m_drag_offset_y + img->getYShift(), img->getWidth(), img->getHeight());
 			m_renderbackend->pushClipArea(area, false);
 			img->render(area);
 			m_renderbackend->popClipArea();
@@ -161,7 +161,7 @@
 			img = anim.getFrameByTimestamp(animtime);
 		}
 		if (img) {
-			Rect area(mx + img->getXShift(), my + img->getYShift(), img->getWidth(), img->getHeight());
+			Rect area(m_mx + img->getXShift(), m_my + img->getYShift(), img->getWidth(), img->getHeight());
 			m_renderbackend->pushClipArea(area, false);
 			img->render(area);
 			m_renderbackend->popClipArea();
--- a/engine/core/video/cursor.h	Wed Feb 03 01:50:37 2010 +0000
+++ b/engine/core/video/cursor.h	Wed Feb 03 18:59:34 2010 +0000
@@ -124,6 +124,14 @@
 		 */
 		unsigned int getDragId() const { return m_drag_id; }
 
+		/** Gets the current mouse x position
+		 */
+		unsigned int getX() const {return m_mx;}
+
+		/** Gets the current mouse y position
+		 */
+		unsigned int getY() const {return m_my;}
+
 	protected:
 		/** Sets the cursor to a native type.
 		  * @param cursor_id Resource id to native cursor, or one of the values in NativeCursor
@@ -156,6 +164,8 @@
 		
 		int m_drag_offset_x;
 		int m_drag_offset_y;
+		int m_mx;
+		int m_my;
 		TimeManager* m_timemanager;
 	};
 
--- a/engine/core/video/video.i	Wed Feb 03 01:50:37 2010 +0000
+++ b/engine/core/video/video.i	Wed Feb 03 18:59:34 2010 +0000
@@ -201,6 +201,8 @@
 		unsigned int getId() const;
 		MouseCursorType getDragType() const;
 		unsigned int getDragId() const;
+		unsigned int getX() const;
+		unsigned int getY() const;
 	
 	private:
 		Cursor(ImagePool* imgpool, AnimationPool* animpool);