diff --git a/source/gui/CGUI.cpp b/source/gui/CGUI.cpp index 24a249e380..54d8c46fab 100755 --- a/source/gui/CGUI.cpp +++ b/source/gui/CGUI.cpp @@ -31,9 +31,6 @@ using namespace std; #include "input.h" -// JW: how about having each object export hit_test(x,y), -// instead of accessing the global mouse pos? -int gui_mouse_x, gui_mouse_y; // called from main loop when (input) events are received. // event is passed to other handlers if false is returned. @@ -49,7 +46,7 @@ bool gui_handler(const SDL_Event& ev) bool CGUI::HandleEvent(const SDL_Event& ev) { if(ev.type == SDL_MOUSEMOTION) - gui_mouse_x = ev.motion.x, gui_mouse_y = ev.motion.y; + mouse_x = ev.motion.x, mouse_y = ev.motion.y; // JW: (pre|post)process omitted; what're they for? why would we need any special button_released handling? diff --git a/source/gui/CGUI.h b/source/gui/CGUI.h index a81d547c2b..6e70c1f905 100755 --- a/source/gui/CGUI.h +++ b/source/gui/CGUI.h @@ -56,6 +56,10 @@ private: // Private typedefs typedef CGUIObject *(*ConstructObjectFunction)(); + // don't want to pass this around with the ChooseMouseOverAndClosest broadcast - + // we'd need to pack this and pNearest in a struct + u16 mouse_x, mouse_y; + public: CGUI(); ~CGUI(); @@ -158,7 +162,6 @@ private: void Xerces_ReadSprite(XERCES_CPP_NAMESPACE::DOMElement *); void Xerces_ReadImage(XERCES_CPP_NAMESPACE::DOMElement *, CGUISprite &parent); - private: // Variables diff --git a/source/gui/CGUIObject.cpp b/source/gui/CGUIObject.cpp index dfe84b1dbf..a6857cfb27 100755 --- a/source/gui/CGUIObject.cpp +++ b/source/gui/CGUIObject.cpp @@ -6,6 +6,7 @@ gee@pyro.nu //#include "stdafx." #include "GUI.h" +#include "cgui.h" ///#include "Parser/parser.h" #include @@ -166,24 +167,22 @@ void CGUIObject::SetupBaseSettingsInfo(map_Settings &SettingsInfo) } -extern int gui_mouse_x, gui_mouse_y; // declared in cgui.cpp -// JW: how about MouseOver(mouse_x, mouse_y) instead of accessing the global mouse pos? //------------------------------------------------------------------- // Checks if mouse is over and returns result -// Input: -// x, y Absolute mouse position +// mouse_x, mouse_y defined in CGUI //------------------------------------------------------------------- bool CGUIObject::MouseOver() { - if (!GetGUI()) + CGUI* gui = GetGUI(); + if(!gui) throw PS_NEEDS_PGUI; - return (gui_mouse_x >= m_BaseSettings.m_Size.left && - gui_mouse_x <= m_BaseSettings.m_Size.right && - gui_mouse_y >= m_BaseSettings.m_Size.bottom && - gui_mouse_y <= m_BaseSettings.m_Size.top); + return (gui->mouse_x >= m_BaseSettings.m_Size.left && + gui->mouse_x <= m_BaseSettings.m_Size.right && + gui->mouse_y >= m_BaseSettings.m_Size.bottom && + gui->mouse_y <= m_BaseSettings.m_Size.top); } //-------------------------------------------------------------------