123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368 |
- //-----------------------------------------------------------------------------
- // Copyright (c) 2012 GarageGames, LLC
- //
- // Permission is hereby granted, free of charge, to any person obtaining a copy
- // of this software and associated documentation files (the "Software"), to
- // deal in the Software without restriction, including without limitation the
- // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
- // sell copies of the Software, and to permit persons to whom the Software is
- // furnished to do so, subject to the following conditions:
- //
- // The above copyright notice and this permission notice shall be included in
- // all copies or substantial portions of the Software.
- //
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
- // IN THE SOFTWARE.
- //-----------------------------------------------------------------------------
- #include "gui/utility/guiMouseEventCtrl.h"
- #include "console/consoleTypes.h"
- #include "console/engineAPI.h"
- IMPLEMENT_CONOBJECT(GuiMouseEventCtrl);
- ConsoleDocClass( GuiMouseEventCtrl,
- "@brief Used to overlaps a 'hot region' where you want to catch inputs with and have specific events occur based on individual callbacks.\n\n"
- "Mouse event callbacks supported by this control are: onMouseUp, onMouseDown, onMouseMove, onMouseDragged, onMouseEnter, onMouseLeave,\n"
- "onRightMouseDown, onRightMouseUp and onRightMouseDragged.\n\n"
- "@tsexample\n"
- "new GuiMouseEventCtrl()\n"
- "{\n"
- " lockMouse = \"0\";\n"
- " //Properties not specific to this control have been omitted from this example.\n"
- "};\n"
- "@endtsexample\n\n"
- "@see GuiControl\n\n"
- "@ingroup GuiCore\n"
- );
- IMPLEMENT_CALLBACK( GuiMouseEventCtrl, onMouseDown, void, ( S32 modifier, Point2I mousePoint, S32 mouseClickCount ),
- ( modifier, mousePoint, mouseClickCount ),
- "@brief Callback that occurs whenever the mouse is pressed down while in this control.\n\n"
- "@param modifier Key that was pressed during this callback. Values are:\n\n"
- "$EventModifier::RSHIFT\n\n"
- "$EventModifier::SHIFT\n\n"
- "$EventModifier::LCTRL\n\n"
- "$EventModifier::RCTRL\n\n"
- "$EventModifier::CTRL\n\n"
- "$EventModifier::CTRL\n\n"
- "$EventModifier::RALT\n\n"
- "$EventModifier::ALT\n\n"
- "@param mousePoint X/Y location of the mouse point\n"
- "@param mouseClickCount How many mouse clicks have occured for this event\n\n"
- "@tsexample\n"
- "// Mouse was pressed down in this control, causing the callback\n"
- "GuiMouseEventCtrl::onMouseDown(%this,%modifier,%mousePoint,%mouseClickCount)\n"
- "{\n"
- " // Code to call when a mouse event occurs.\n"
- "}\n"
- "@endtsexample\n\n"
- "@see GuiControl\n\n"
- );
- IMPLEMENT_CALLBACK( GuiMouseEventCtrl, onMouseUp, void, ( S32 modifier, Point2I mousePoint, S32 mouseClickCount ),
- ( modifier, mousePoint, mouseClickCount ),
- "@brief Callback that occurs whenever the mouse is released while in this control.\n\n"
- "@param modifier Key that was pressed during this callback. Values are:\n\n"
- "$EventModifier::RSHIFT\n\n"
- "$EventModifier::SHIFT\n\n"
- "$EventModifier::LCTRL\n\n"
- "$EventModifier::RCTRL\n\n"
- "$EventModifier::CTRL\n\n"
- "$EventModifier::CTRL\n\n"
- "$EventModifier::RALT\n\n"
- "$EventModifier::ALT\n\n"
- "@param mousePoint X/Y location of the mouse point\n"
- "@param mouseClickCount How many mouse clicks have occured for this event\n\n"
- "@tsexample\n"
- "// Mouse was released in this control, causing the callback\n"
- "GuiMouseEventCtrl::onMouseUp(%this,%modifier,%mousePoint,%mouseClickCount)\n"
- "{\n"
- " // Code to call when a mouse event occurs.\n"
- "}\n"
- "@endtsexample\n\n"
- "@see GuiControl\n\n"
- );
- IMPLEMENT_CALLBACK( GuiMouseEventCtrl, onMouseMove, void, ( S32 modifier, Point2I mousePoint, S32 mouseClickCount ),
- ( modifier, mousePoint, mouseClickCount ),
- "@brief Callback that occurs whenever the mouse is moved (without dragging) while in this control.\n\n"
- "@param modifier Key that was pressed during this callback. Values are:\n\n"
- "$EventModifier::RSHIFT\n\n"
- "$EventModifier::SHIFT\n\n"
- "$EventModifier::LCTRL\n\n"
- "$EventModifier::RCTRL\n\n"
- "$EventModifier::CTRL\n\n"
- "$EventModifier::CTRL\n\n"
- "$EventModifier::RALT\n\n"
- "$EventModifier::ALT\n\n"
- "@param mousePoint X/Y location of the mouse point\n"
- "@param mouseClickCount How many mouse clicks have occured for this event\n\n"
- "@tsexample\n"
- "// Mouse was moved in this control, causing the callback\n"
- "GuiMouseEventCtrl::onMouseMove(%this,%modifier,%mousePoint,%mouseClickCount)\n"
- "{\n"
- " // Code to call when a mouse event occurs.\n"
- "}\n"
- "@endtsexample\n\n"
- "@see GuiControl\n\n"
- );
- IMPLEMENT_CALLBACK( GuiMouseEventCtrl, onMouseDragged, void, ( S32 modifier, Point2I mousePoint, S32 mouseClickCount ),
- ( modifier, mousePoint, mouseClickCount ),
- "@brief Callback that occurs whenever the mouse is dragged while in this control.\n\n"
- "@param modifier Key that was pressed during this callback. Values are:\n\n"
- "$EventModifier::RSHIFT\n\n"
- "$EventModifier::SHIFT\n\n"
- "$EventModifier::LCTRL\n\n"
- "$EventModifier::RCTRL\n\n"
- "$EventModifier::CTRL\n\n"
- "$EventModifier::CTRL\n\n"
- "$EventModifier::RALT\n\n"
- "$EventModifier::ALT\n\n"
- "@param mousePoint X/Y location of the mouse point\n"
- "@param mouseClickCount How many mouse clicks have occured for this event\n\n"
- "@tsexample\n"
- "// Mouse was dragged in this control, causing the callback\n"
- "GuiMouseEventCtrl::onMouseDragged(%this,%modifier,%mousePoint,%mouseClickCount)\n"
- "{\n"
- " // Code to call when a mouse event occurs.\n"
- "}\n"
- "@endtsexample\n\n"
- "@see GuiControl\n\n"
- );
- IMPLEMENT_CALLBACK( GuiMouseEventCtrl, onMouseEnter, void, ( S32 modifier, Point2I mousePoint, S32 mouseClickCount ),
- ( modifier, mousePoint, mouseClickCount ),
- "@brief Callback that occurs whenever the mouse enters this control.\n\n"
- "@param modifier Key that was pressed during this callback. Values are:\n\n"
- "$EventModifier::RSHIFT\n\n"
- "$EventModifier::SHIFT\n\n"
- "$EventModifier::LCTRL\n\n"
- "$EventModifier::RCTRL\n\n"
- "$EventModifier::CTRL\n\n"
- "$EventModifier::CTRL\n\n"
- "$EventModifier::RALT\n\n"
- "$EventModifier::ALT\n\n"
- "@param mousePoint X/Y location of the mouse point\n"
- "@param mouseClickCount How many mouse clicks have occured for this event\n\n"
- "@tsexample\n"
- "// Mouse entered this control, causing the callback\n"
- "GuiMouseEventCtrl::onMouseEnter(%this,%modifier,%mousePoint,%mouseClickCount)\n"
- "{\n"
- " // Code to call when a mouse event occurs.\n"
- "}\n"
- "@endtsexample\n\n"
- "@see GuiControl\n\n"
- );
- IMPLEMENT_CALLBACK( GuiMouseEventCtrl, onMouseLeave, void, ( S32 modifier, Point2I mousePoint, S32 mouseClickCount ),
- ( modifier, mousePoint, mouseClickCount ),
- "@brief Callback that occurs whenever the mouse leaves this control.\n\n"
- "@param modifier Key that was pressed during this callback. Values are:\n\n"
- "$EventModifier::RSHIFT\n\n"
- "$EventModifier::SHIFT\n\n"
- "$EventModifier::LCTRL\n\n"
- "$EventModifier::RCTRL\n\n"
- "$EventModifier::CTRL\n\n"
- "$EventModifier::CTRL\n\n"
- "$EventModifier::RALT\n\n"
- "$EventModifier::ALT\n\n"
- "@param mousePoint X/Y location of the mouse point\n"
- "@param mouseClickCount How many mouse clicks have occured for this event\n\n"
- "@tsexample\n"
- "// Mouse left this control, causing the callback\n"
- "GuiMouseEventCtrl::onMouseLeave(%this,%modifier,%mousePoint,%mouseClickCount)\n"
- "{\n"
- " // Code to call when a mouse event occurs.\n"
- "}\n"
- "@endtsexample\n\n"
- "@see GuiControl\n\n"
- );
- IMPLEMENT_CALLBACK( GuiMouseEventCtrl, onRightMouseDown, void, ( S32 modifier, Point2I mousePoint, S32 mouseClickCount ),
- ( modifier, mousePoint, mouseClickCount ),
- "@brief Callback that occurs whenever the right mouse button is pressed while in this control.\n\n"
- "@param modifier Key that was pressed during this callback. Values are:\n\n"
- "$EventModifier::RSHIFT\n\n"
- "$EventModifier::SHIFT\n\n"
- "$EventModifier::LCTRL\n\n"
- "$EventModifier::RCTRL\n\n"
- "$EventModifier::CTRL\n\n"
- "$EventModifier::CTRL\n\n"
- "$EventModifier::RALT\n\n"
- "$EventModifier::ALT\n\n"
- "@param mousePoint X/Y location of the mouse point\n"
- "@param mouseClickCount How many mouse clicks have occured for this event\n\n"
- "@tsexample\n"
- "// Right mouse button was pressed in this control, causing the callback\n"
- "GuiMouseEventCtrl::onRightMouseDown(%this,%modifier,%mousePoint,%mouseClickCount)\n"
- "{\n"
- " // Code to call when a mouse event occurs.\n"
- "}\n"
- "@endtsexample\n\n"
- "@see GuiControl\n\n"
- );
- IMPLEMENT_CALLBACK( GuiMouseEventCtrl, onRightMouseUp, void, ( S32 modifier, Point2I mousePoint, S32 mouseClickCount ),
- ( modifier, mousePoint, mouseClickCount ),
- "@brief Callback that occurs whenever the right mouse button is released while in this control.\n\n"
- "@param modifier Key that was pressed during this callback. Values are:\n\n"
- "$EventModifier::RSHIFT\n\n"
- "$EventModifier::SHIFT\n\n"
- "$EventModifier::LCTRL\n\n"
- "$EventModifier::RCTRL\n\n"
- "$EventModifier::CTRL\n\n"
- "$EventModifier::CTRL\n\n"
- "$EventModifier::RALT\n\n"
- "$EventModifier::ALT\n\n"
- "@param mousePoint X/Y location of the mouse point\n"
- "@param mouseClickCount How many mouse clicks have occured for this event\n\n"
- "@tsexample\n"
- "// Right mouse button was released in this control, causing the callback\n"
- "GuiMouseEventCtrl::onRightMouseUp(%this,%modifier,%mousePoint,%mouseClickCount)\n"
- "{\n"
- " // Code to call when a mouse event occurs.\n"
- "}\n"
- "@endtsexample\n\n"
- "@see GuiControl\n\n"
- );
- IMPLEMENT_CALLBACK( GuiMouseEventCtrl, onRightMouseDragged, void, ( S32 modifier, Point2I mousePoint, S32 mouseClickCount ),
- ( modifier, mousePoint, mouseClickCount ),
- "@brief Callback that occurs whenever the mouse is dragged in this control while the right mouse button is pressed.\n\n"
- "@param modifier Key that was pressed during this callback. Values are:\n\n"
- "$EventModifier::RSHIFT\n\n"
- "$EventModifier::SHIFT\n\n"
- "$EventModifier::LCTRL\n\n"
- "$EventModifier::RCTRL\n\n"
- "$EventModifier::CTRL\n\n"
- "$EventModifier::CTRL\n\n"
- "$EventModifier::RALT\n\n"
- "$EventModifier::ALT\n\n"
- "@param mousePoint X/Y location of the mouse point\n"
- "@param mouseClickCount How many mouse clicks have occured for this event\n\n"
- "@tsexample\n"
- "// Right mouse button was dragged in this control, causing the callback\n"
- "GuiMouseEventCtrl::onRightMouseDragged(%this,%modifier,%mousePoint,%mouseClickCount)\n"
- "{\n"
- " // Code to call when a mouse event occurs.\n"
- "}\n"
- "@endtsexample\n\n"
- "@see GuiControl\n\n"
- );
- GuiMouseEventCtrl::GuiMouseEventCtrl()
- {
- mLockMouse = false;
- }
- //------------------------------------------------------------------------------
- void GuiMouseEventCtrl::sendMouseEvent(const char * name, const GuiEvent & event)
- {
- if(dStricmp(name,"onMouseDown") == 0)
- onMouseDown_callback(event.modifier, event.mousePoint, event.mouseClickCount);
- else if(dStricmp(name,"onMouseUp") == 0)
- onMouseUp_callback(event.modifier, event.mousePoint, event.mouseClickCount);
- else if(dStricmp(name,"onMouseMove") == 0)
- onMouseMove_callback(event.modifier, event.mousePoint, event.mouseClickCount);
- else if(dStricmp(name,"onMouseDragged") == 0)
- onMouseDragged_callback(event.modifier, event.mousePoint, event.mouseClickCount);
- else if(dStricmp(name,"onMouseEnter") == 0)
- onMouseEnter_callback(event.modifier, event.mousePoint, event.mouseClickCount);
- else if(dStricmp(name,"onMouseLeave") == 0)
- onMouseLeave_callback(event.modifier, event.mousePoint, event.mouseClickCount);
- else if(dStricmp(name,"onRightMouseDown") == 0)
- onRightMouseDown_callback(event.modifier, event.mousePoint, event.mouseClickCount);
- else if(dStricmp(name,"onRightMouseUp") == 0)
- onRightMouseUp_callback(event.modifier, event.mousePoint, event.mouseClickCount);
- else if(dStricmp(name,"onRightMouseDragged") == 0)
- onRightMouseDragged_callback(event.modifier, event.mousePoint, event.mouseClickCount);
- }
- //------------------------------------------------------------------------------
- void GuiMouseEventCtrl::initPersistFields()
- {
- addGroup( "Input" );
-
- addField("lockMouse", TypeBool, Offset(mLockMouse, GuiMouseEventCtrl),
- "Whether the control should lock the mouse between up and down button events." );
-
- endGroup( "Input" );
- Parent::initPersistFields();
- Con::setIntVariable("$EventModifier::LSHIFT", SI_LSHIFT);
- Con::setIntVariable("$EventModifier::RSHIFT", SI_RSHIFT);
- Con::setIntVariable("$EventModifier::SHIFT", SI_SHIFT);
- Con::setIntVariable("$EventModifier::LCTRL", SI_LCTRL);
- Con::setIntVariable("$EventModifier::RCTRL", SI_RCTRL);
- Con::setIntVariable("$EventModifier::CTRL", SI_CTRL);
- Con::setIntVariable("$EventModifier::LALT", SI_LALT);
- Con::setIntVariable("$EventModifier::RALT", SI_RALT);
- Con::setIntVariable("$EventModifier::ALT", SI_ALT);
- }
- //------------------------------------------------------------------------------
- void GuiMouseEventCtrl::onMouseDown(const GuiEvent & event)
- {
- if(mLockMouse)
- mouseLock();
- sendMouseEvent("onMouseDown", event);
- }
- void GuiMouseEventCtrl::onMouseUp(const GuiEvent & event)
- {
- if(mLockMouse)
- mouseUnlock();
- sendMouseEvent("onMouseUp", event);
- }
- void GuiMouseEventCtrl::onMouseMove(const GuiEvent & event)
- {
- sendMouseEvent("onMouseMove", event);
- }
- void GuiMouseEventCtrl::onMouseDragged(const GuiEvent & event)
- {
- sendMouseEvent("onMouseDragged", event);
- }
- void GuiMouseEventCtrl::onMouseEnter(const GuiEvent & event)
- {
- sendMouseEvent("onMouseEnter", event);
- }
- void GuiMouseEventCtrl::onMouseLeave(const GuiEvent & event)
- {
- sendMouseEvent("onMouseLeave", event);
- }
- void GuiMouseEventCtrl::onRightMouseDown(const GuiEvent & event)
- {
- if(mLockMouse)
- mouseLock();
- sendMouseEvent("onRightMouseDown", event);
- }
- void GuiMouseEventCtrl::onRightMouseUp(const GuiEvent & event)
- {
- if(mLockMouse)
- mouseUnlock();
- sendMouseEvent("onRightMouseUp", event);
- }
- void GuiMouseEventCtrl::onRightMouseDragged(const GuiEvent & event)
- {
- sendMouseEvent("onRightMouseDragged", event);
- }
|