EditorToyTool.cc 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. #include "console/consoleInternal.h"
  2. #include "console/console.h"
  3. #include "graphics/dgl.h"
  4. #include "2d/editorToy/EditorToyTool.h"
  5. //-----------------------------------------------------------------------
  6. IMPLEMENT_CONOBJECT(EditorToyTool);
  7. //-----------------------------------------------------------------------
  8. EditorToyTool::EditorToyTool()
  9. {
  10. mEditorToy = NULL;
  11. mUseMouseDown = true;
  12. mUseMouseUp = true;
  13. mUseMouseMove = true;
  14. mUseRightMouseDown = false;
  15. mUseRightMouseUp = false;
  16. mUseRightMouseMove = false;
  17. mUseMiddleMouseDown = true;
  18. mUseMiddleMouseUp = true;
  19. mUseMiddleMouseMove = true;
  20. mUseKeyInput = true;
  21. }
  22. EditorToyTool::~EditorToyTool()
  23. {
  24. }
  25. bool EditorToyTool::onAdd()
  26. {
  27. return Parent::onAdd();
  28. }
  29. void EditorToyTool::onRemove()
  30. {
  31. Parent::onRemove();
  32. }
  33. void EditorToyTool::onActivate(EditorToySceneWindow* sceneWin)
  34. {
  35. mEditorToy = sceneWin;
  36. Con::executef(this, 1, "onActivate");
  37. }
  38. void EditorToyTool::onDeactivate()
  39. {
  40. mEditorToy = NULL;
  41. Con::executef(this, 1, "onDeactivate");
  42. }
  43. void EditorToyTool::onRelinquishObj(SceneObject * obj)
  44. {
  45. }
  46. bool EditorToyTool::onTouchMove(const GuiEvent &e)
  47. {
  48. if (mUseMouseDown && isMethod("onTouchMove"))
  49. {
  50. char* point = Con::getArgBuffer(32);
  51. dSprintf(point, 32, "%d %d", e.mousePoint.x, e.mousePoint.y);
  52. Con::executef(this, 2, "onTouchMove", point);
  53. return true;
  54. }
  55. return false;
  56. }
  57. bool EditorToyTool::onTouchDown(const GuiEvent &e)
  58. {
  59. if (mUseMouseDown && isMethod("onTouchDown"))
  60. {
  61. char* point = Con::getArgBuffer(32);
  62. dSprintf(point, 32, "%d %d", e.mousePoint.x, e.mousePoint.y);
  63. Con::executef(this, 2, "onTouchDown", point);
  64. return true;
  65. }
  66. return false;
  67. }
  68. bool EditorToyTool::onTouchDragged(const GuiEvent &e)
  69. {
  70. if (isMethod("onTouchDragged"))
  71. {
  72. char* point = Con::getArgBuffer(32);
  73. dSprintf(point, 32, "%d %d", e.mousePoint.x, e.mousePoint.y);
  74. Con::executef(this, 2, "onTouchDragged", point);
  75. return true;
  76. }
  77. return false;
  78. }
  79. bool EditorToyTool::onTouchUp(const GuiEvent &e)
  80. {
  81. if (mUseMouseDown && isMethod("onTouchUp"))
  82. {
  83. char* point = Con::getArgBuffer(32);
  84. dSprintf(point, 32, "%d %d", e.mousePoint.x, e.mousePoint.y);
  85. Con::executef(this, 2, "onTouchUp", point);
  86. return true;
  87. }
  88. return false;
  89. }
  90. bool EditorToyTool::onRightMouseDown(const GuiEvent &e)
  91. {
  92. if (mUseRightMouseDown && isMethod("onRightMouseDown"))
  93. {
  94. char* point = Con::getArgBuffer(32);
  95. dSprintf(point, 32, "%d %d", e.mousePoint.x, e.mousePoint.y);
  96. Con::executef(this, 2, "onRightMouseDown", point);
  97. return true;
  98. }
  99. return false;
  100. }
  101. bool EditorToyTool::onRightMouseDragged(const GuiEvent &e)
  102. {
  103. if (isMethod("onRightMouseDragged"))
  104. {
  105. char* point = Con::getArgBuffer(32);
  106. dSprintf(point, 32, "%d %d", e.mousePoint.x, e.mousePoint.y);
  107. Con::executef(this, 2, "onRightMouseDragged", point);
  108. return true;
  109. }
  110. return false;
  111. }
  112. bool EditorToyTool::onRightMouseUp(const GuiEvent &e)
  113. {
  114. if (mUseRightMouseDown && isMethod("onRightMouseUp"))
  115. {
  116. char* point = Con::getArgBuffer(32);
  117. dSprintf(point, 32, "%d %d", e.mousePoint.x, e.mousePoint.y);
  118. Con::executef(this, 2, "onRightMouseUp", point);
  119. return true;
  120. }
  121. return false;
  122. }
  123. bool EditorToyTool::onMiddleMouseDown(const GuiEvent &e)
  124. {
  125. if (mUseMiddleMouseDown && isMethod("onMiddleMouseDown"))
  126. {
  127. char* point = Con::getArgBuffer(32);
  128. dSprintf(point, 32, "%d %d", e.mousePoint.x, e.mousePoint.y);
  129. Con::executef(this, 2, "onMiddleMouseDown", point);
  130. return true;
  131. }
  132. return false;
  133. }
  134. bool EditorToyTool::onMiddleMouseDragged(const GuiEvent &e)
  135. {
  136. if (isMethod("onMiddleMouseDragged"))
  137. {
  138. char* point = Con::getArgBuffer(32);
  139. dSprintf(point, 32, "%d %d", e.mousePoint.x, e.mousePoint.y);
  140. Con::executef(this, 2, "onMiddleMouseDragged", point);
  141. return true;
  142. }
  143. return false;
  144. }
  145. bool EditorToyTool::onMiddleMouseUp(const GuiEvent &e)
  146. {
  147. if (mUseMiddleMouseDown && isMethod("onMiddleMouseUp"))
  148. {
  149. char* point = Con::getArgBuffer(32);
  150. dSprintf(point, 32, "%d %d", e.mousePoint.x, e.mousePoint.y);
  151. Con::executef(this, 2, "onMiddleMouseUp", point);
  152. return true;
  153. }
  154. return false;
  155. }
  156. bool EditorToyTool::onInputEvent(const GuiEvent &e)
  157. {
  158. if (!mUseKeyInput)
  159. return false;
  160. Con::executef(this,3, "onKeyPress", e.ascii, e.modifier);
  161. return true;
  162. }