Changed GUI mouse event handling so that button events use the mouse position at the time of the button state change. Fixed minimap message handling to respect out-of-order events. Fixes #669

This was SVN commit r8610.
This commit is contained in:
historic_bruno 2010-11-14 22:47:39 +00:00
parent 6b444ea23b
commit 293e5e33ec
3 changed files with 28 additions and 9 deletions

View File

@ -116,6 +116,13 @@ InReaction CGUI::HandleEvent(const SDL_Event_* ev)
}
}
// Update m_MousePos (for delayed mouse button events)
CPos oldMousePos = m_MousePos;
if (ev->ev.type == SDL_MOUSEBUTTONDOWN || ev->ev.type == SDL_MOUSEBUTTONUP)
{
m_MousePos = CPos((float)ev->ev.button.x, (float)ev->ev.button.y);
}
// Only one object can be hovered
IGUIObject *pNearest = NULL;
@ -284,6 +291,12 @@ InReaction CGUI::HandleEvent(const SDL_Event_* ev)
}
}
// Restore m_MousePos (for delayed mouse button events)
if (ev->ev.type == SDL_MOUSEBUTTONDOWN || ev->ev.type == SDL_MOUSEBUTTONUP)
{
m_MousePos = oldMousePos;
}
// Handle keys for input boxes
if (GetFocusedObject())
{

View File

@ -60,6 +60,7 @@ CMiniMap::CMiniMap()
AddSetting(GUIST_CStr, "tooltip");
AddSetting(GUIST_CStr, "tooltip_style");
m_Clicking = false;
m_Hovering = false;
m_LOSScale = 2;
}
@ -75,33 +76,37 @@ void CMiniMap::HandleMessage(const SGUIMessage &Message)
{
case GUIM_MOUSE_PRESS_LEFT:
{
SetCameraPos();
m_Clicking = true;
if (m_Hovering)
{
SetCameraPos();
m_Clicking = true;
}
break;
}
case GUIM_MOUSE_RELEASE_LEFT:
{
if(m_Clicking)
if(m_Hovering && m_Clicking)
{
SetCameraPos();
}
m_Clicking = false;
break;
}
case GUIM_MOUSE_DBLCLICK_LEFT:
{
if(m_Clicking)
if(m_Hovering && m_Clicking)
SetCameraPos();
m_Clicking = false;
break;
}
case GUIM_MOUSE_ENTER:
{
// g_Selection.m_mouseOverMM = true;
m_Hovering = true;
break;
}
case GUIM_MOUSE_LEAVE:
{
// g_Selection.m_mouseOverMM = false;
m_Clicking = false;
m_Hovering = false;
break;
}
case GUIM_MOUSE_RELEASE_RIGHT:
@ -116,7 +121,7 @@ void CMiniMap::HandleMessage(const SGUIMessage &Message)
}
case GUIM_MOUSE_MOTION:
{
if (m_Clicking)
if (m_Hovering && m_Clicking)
SetCameraPos();
break;
}

View File

@ -56,7 +56,8 @@ protected:
const CCamera* m_Camera;
//Whether or not the mouse is currently down
bool m_Clicking;
bool m_Clicking;
bool m_Hovering;
// minimap texture handles
GLuint m_TerrainTexture;