1
0
forked from 0ad/0ad

Fix right clicks passing through GUI objects and triggering unit commands.

Fix cursor displaying unit commands when over a GUI object.

This was SVN commit r8020.
This commit is contained in:
Ykkrosh 2010-08-21 23:58:08 +00:00
parent 674f516f83
commit a9b11b780e
5 changed files with 43 additions and 14 deletions

View File

@ -26,6 +26,7 @@ var placementEntity;
var mouseX = 0;
var mouseY = 0;
var mouseIsOverObject = false;
var specialKeyStates = {};
specialKeyStates[SDLK_RSHIFT] = 0;
specialKeyStates[SDLK_LSHIFT] = 0;
@ -34,7 +35,7 @@ specialKeyStates[SDLK_LSHIFT] = 0;
function updateCursor()
{
if (inputState == INPUT_NORMAL)
if (!mouseIsOverObject && inputState == INPUT_NORMAL)
{
var action = determineAction(mouseX, mouseY);
if (action)
@ -226,7 +227,7 @@ function getPreferredEntities(ents)
return preferredEnts;
}
function handleInputBeforeGui(ev)
function handleInputBeforeGui(ev, hoveredObject)
{
// Capture mouse position so we can use it for displaying cursors,
// and key states
@ -248,6 +249,9 @@ function handleInputBeforeGui(ev)
break;
}
// Remember whether the mouse is over a GUI object or not
mouseIsOverObject = (hoveredObject != null);
// State-machine processing:
//
// (This is for states which should override the normal GUI processing - events will

View File

@ -128,9 +128,7 @@ InReaction CGUI::HandleEvent(const SDL_Event_* ev)
// these two recursive function are quite overhead heavy.
// pNearest will after this point at the hovered object, possibly NULL
GUI<IGUIObject*>::RecurseObject(GUIRR_HIDDEN | GUIRR_GHOST, m_BaseObject,
&IGUIObject::ChooseMouseOverAndClosest,
pNearest);
pNearest = FindObjectUnderMouse();
// Is placed in the UpdateMouseOver function
//if (ev->ev.type == SDL_MOUSEMOTION && pNearest)
@ -162,6 +160,16 @@ InReaction CGUI::HandleEvent(const SDL_Event_* ev)
}
break;
case SDL_BUTTON_RIGHT:
if (pNearest)
{
pNearest->HandleMessage(SGUIMessage(GUIM_MOUSE_PRESS_RIGHT));
pNearest->ScriptEvent("mouserightpress");
ret = IN_HANDLED;
}
break;
case SDL_BUTTON_WHEELDOWN: // wheel down
if (pNearest)
{
@ -303,14 +311,7 @@ void CGUI::TickObjects()
&IGUIObject::ScriptEvent, action);
// Also update tooltips:
// TODO: Efficiency
IGUIObject* pNearest = NULL;
GUI<IGUIObject*>::RecurseObject(GUIRR_HIDDEN | GUIRR_GHOST, m_BaseObject,
&IGUIObject::ChooseMouseOverAndClosest,
pNearest);
m_Tooltip.Update(pNearest, m_MousePos, this);
m_Tooltip.Update(FindObjectUnderMouse(), m_MousePos, this);
}
void CGUI::SendEventToAll(const CStr& EventName)
@ -523,6 +524,15 @@ IGUIObject* CGUI::FindObjectByName(const CStr& Name) const
return it->second;
}
IGUIObject* CGUI::FindObjectUnderMouse() const
{
IGUIObject* pNearest = NULL;
GUI<IGUIObject*>::RecurseObject(GUIRR_HIDDEN | GUIRR_GHOST, m_BaseObject,
&IGUIObject::ChooseMouseOverAndClosest,
pNearest);
return pNearest;
}
void CGUI::SetFocusedObject(IGUIObject* pObject)
{
if (pObject == m_FocusedObject)

View File

@ -202,6 +202,11 @@ public:
*/
IGUIObject* FindObjectByName(const CStr& Name) const;
/**
* Returns the GUI object under the mouse, or NULL if none.
*/
IGUIObject* FindObjectUnderMouse() const;
/**
* The GUI needs to have all object types inputted and
* their constructors. Also it needs to associate a type

View File

@ -207,9 +207,10 @@ InReaction CGUIManager::HandleEvent(const SDL_Event_* ev)
// So we call two separate handler functions:
bool handled;
{
PROFILE("handleInputBeforeGui");
if (m_ScriptInterface.CallFunction(OBJECT_TO_JSVAL(top()->GetScriptObject()), "handleInputBeforeGui", *ev, handled))
if (m_ScriptInterface.CallFunction(OBJECT_TO_JSVAL(top()->GetScriptObject()), "handleInputBeforeGui", *ev, top()->FindObjectUnderMouse(), handled))
if (handled)
return IN_HANDLED;
}

View File

@ -19,6 +19,7 @@
#include "scriptinterface/ScriptInterface.h"
#include "gui/IGUIObject.h"
#include "lib/external_libraries/sdl.h"
#include "ps/Hotkey.h"
@ -130,3 +131,11 @@ template<> jsval ScriptInterface::ToJSVal<SDL_Event_>(JSContext* cx, SDL_Event_
return OBJECT_TO_JSVAL(obj);
}
template<> jsval ScriptInterface::ToJSVal<IGUIObject*>(JSContext* UNUSED(cx), IGUIObject* const& val)
{
if (val == NULL)
return JSVAL_NULL;
return OBJECT_TO_JSVAL(val->GetJSObject());
}