2
0

guiMouseEventCtrl.cc 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2013 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #include "gui/guiMouseEventCtrl.h"
  23. #include "console/consoleTypes.h"
  24. IMPLEMENT_CONOBJECT(GuiMouseEventCtrl);
  25. GuiMouseEventCtrl::GuiMouseEventCtrl()
  26. {
  27. mLockMouse = false;
  28. }
  29. //------------------------------------------------------------------------------
  30. void GuiMouseEventCtrl::sendMouseEvent(const char * name, const GuiEvent & event)
  31. {
  32. char buf[3][32];
  33. dSprintf(buf[0], 32, "%d", event.modifier);
  34. dSprintf(buf[1], 32, "%d %d", event.mousePoint.x, event.mousePoint.y);
  35. dSprintf(buf[2], 32, "%d", event.mouseClickCount);
  36. Con::executef(this, 4, name, buf[0], buf[1], buf[2]);
  37. }
  38. //------------------------------------------------------------------------------
  39. void GuiMouseEventCtrl::initPersistFields()
  40. {
  41. Parent::initPersistFields();
  42. addField("lockMouse", TypeBool, Offset(mLockMouse, GuiMouseEventCtrl));
  43. Con::setIntVariable("$EventModifier::LSHIFT", SI_LSHIFT);
  44. Con::setIntVariable("$EventModifier::RSHIFT", SI_RSHIFT);
  45. Con::setIntVariable("$EventModifier::SHIFT", SI_SHIFT);
  46. Con::setIntVariable("$EventModifier::LCTRL", SI_LCTRL);
  47. Con::setIntVariable("$EventModifier::RCTRL", SI_RCTRL);
  48. Con::setIntVariable("$EventModifier::CTRL", SI_CTRL);
  49. Con::setIntVariable("$EventModifier::LALT", SI_LALT);
  50. Con::setIntVariable("$EventModifier::RALT", SI_RALT);
  51. Con::setIntVariable("$EventModifier::ALT", SI_ALT);
  52. }
  53. //------------------------------------------------------------------------------
  54. void GuiMouseEventCtrl::onMouseDown(const GuiEvent & event)
  55. {
  56. if(mLockMouse)
  57. mouseLock();
  58. sendMouseEvent("onMouseDown", event);
  59. }
  60. void GuiMouseEventCtrl::onMouseUp(const GuiEvent & event)
  61. {
  62. if(mLockMouse)
  63. mouseUnlock();
  64. sendMouseEvent("onMouseUp", event);
  65. }
  66. void GuiMouseEventCtrl::onMouseMove(const GuiEvent & event)
  67. {
  68. sendMouseEvent("onMouseMove", event);
  69. }
  70. void GuiMouseEventCtrl::onMouseDragged(const GuiEvent & event)
  71. {
  72. sendMouseEvent("onMouseDragged", event);
  73. }
  74. void GuiMouseEventCtrl::onMouseEnter(const GuiEvent & event)
  75. {
  76. sendMouseEvent("onMouseEnter", event);
  77. }
  78. void GuiMouseEventCtrl::onMouseLeave(const GuiEvent & event)
  79. {
  80. sendMouseEvent("onMouseLeave", event);
  81. }
  82. void GuiMouseEventCtrl::onRightMouseDown(const GuiEvent & event)
  83. {
  84. if(mLockMouse)
  85. mouseLock();
  86. sendMouseEvent("onRightMouseDown", event);
  87. }
  88. void GuiMouseEventCtrl::onRightMouseUp(const GuiEvent & event)
  89. {
  90. if(mLockMouse)
  91. mouseUnlock();
  92. sendMouseEvent("onRightMouseUp", event);
  93. }
  94. void GuiMouseEventCtrl::onRightMouseDragged(const GuiEvent & event)
  95. {
  96. sendMouseEvent("onRightMouseDragged", event);
  97. }