guiScriptNotifyControl.cpp 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 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/core/guiScriptNotifyControl.h"
  23. #include "console/consoleTypes.h"
  24. #include "console/engineAPI.h"
  25. //------------------------------------------------------------------------------
  26. IMPLEMENT_CONOBJECT(GuiScriptNotifyCtrl);
  27. ConsoleDocClass( GuiScriptNotifyCtrl,
  28. "@brief A control which adds several reactions to other GUIs via callbacks.\n\n"
  29. "GuiScriptNotifyCtrl does not exist to render anything. When parented or made a child of "
  30. "other controls, you can toggle flags on or off to make use of its specialized callbacks. "
  31. "Normally these callbacks are used as utility functions by the GUI Editor, or other container "
  32. "classes. However, for very fancy GUI work where controls interact with each other "
  33. "constantly, this is a handy utility to make use of.\n\n "
  34. "@tsexample\n"
  35. "// Common member fields left out for sake of example\n"
  36. "new GuiScriptNotifyCtrl()\n"
  37. "{\n"
  38. " onChildAdded = \"0\";\n"
  39. " onChildRemoved = \"0\";\n"
  40. " onChildResized = \"0\";\n"
  41. " onParentResized = \"0\";\n"
  42. "};\n"
  43. "@endtsexample\n\n"
  44. "@ingroup GuiUtil\n");
  45. GuiScriptNotifyCtrl::GuiScriptNotifyCtrl()
  46. {
  47. mOnChildAdded = false;
  48. mOnChildRemoved = false;
  49. mOnResize = false;
  50. mOnChildResized = false;
  51. mOnParentResized = false;
  52. }
  53. GuiScriptNotifyCtrl::~GuiScriptNotifyCtrl()
  54. {
  55. }
  56. void GuiScriptNotifyCtrl::initPersistFields()
  57. {
  58. // Callbacks Group
  59. addGroup("Callbacks");
  60. addField("onChildAdded", TypeBool, Offset( mOnChildAdded, GuiScriptNotifyCtrl ), "Enables/disables onChildAdded callback" );
  61. addField("onChildRemoved", TypeBool, Offset( mOnChildRemoved, GuiScriptNotifyCtrl ), "Enables/disables onChildRemoved callback" );
  62. addField("onChildResized", TypeBool, Offset( mOnChildResized, GuiScriptNotifyCtrl ), "Enables/disables onChildResized callback" );
  63. addField("onParentResized", TypeBool, Offset( mOnParentResized, GuiScriptNotifyCtrl ), "Enables/disables onParentResized callback" );
  64. addField("onResize", TypeBool, Offset( mOnResize, GuiScriptNotifyCtrl ), "Enables/disables onResize callback" );
  65. addField("onLoseFirstResponder", TypeBool, Offset( mOnLoseFirstResponder, GuiScriptNotifyCtrl ), "Enables/disables onLoseFirstResponder callback" );
  66. addField("onGainFirstResponder", TypeBool, Offset( mOnGainFirstResponder, GuiScriptNotifyCtrl ), "Enables/disables onGainFirstResponder callback" );
  67. endGroup("Callbacks");
  68. Parent::initPersistFields();
  69. }
  70. IMPLEMENT_CALLBACK( GuiScriptNotifyCtrl, onResize, void, ( SimObjectId ID ), ( ID ),
  71. "Called when this GUI is resized.\n\n"
  72. "@param ID Unique object ID assigned when created (%this in script).\n"
  73. );
  74. IMPLEMENT_CALLBACK( GuiScriptNotifyCtrl, onChildAdded, void, ( SimObjectId ID, SimObjectId childID ), ( ID, childID ),
  75. "Called when a child is added to this GUI.\n\n"
  76. "@param ID Unique object ID assigned when created (%this in script).\n"
  77. "@param childID Unique object ID of child being added.\n"
  78. );
  79. IMPLEMENT_CALLBACK( GuiScriptNotifyCtrl, onChildRemoved, void, ( SimObjectId ID, SimObjectId childID ), ( ID, childID ),
  80. "Called when a child is removed from this GUI.\n\n"
  81. "@param ID Unique object ID assigned when created (%this in script).\n"
  82. "@param childID Unique object ID of child being removed.\n"
  83. );
  84. IMPLEMENT_CALLBACK( GuiScriptNotifyCtrl, onChildResized, void, ( SimObjectId ID, SimObjectId childID ), ( ID, childID ),
  85. "Called when a child is of this GUI is being resized.\n\n"
  86. "@param ID Unique object ID assigned when created (%this in script).\n"
  87. "@param childID Unique object ID of child being resized.\n"
  88. );
  89. IMPLEMENT_CALLBACK( GuiScriptNotifyCtrl, onParentResized, void, ( SimObjectId ID ), ( ID ),
  90. "Called when this GUI's parent is resized.\n\n"
  91. "@param ID Unique object ID assigned when created (%this in script).\n"
  92. );
  93. IMPLEMENT_CALLBACK( GuiScriptNotifyCtrl, onLoseFirstResponder, void, ( SimObjectId ID ), ( ID ),
  94. "Called when this GUI loses focus.\n\n"
  95. "@param ID Unique object ID assigned when created (%this in script).\n"
  96. );
  97. IMPLEMENT_CALLBACK( GuiScriptNotifyCtrl, onGainFirstResponder, void, ( SimObjectId ID ), ( ID ),
  98. "Called when this GUI gains focus.\n\n"
  99. "@param ID Unique object ID assigned when created (%this in script).\n"
  100. );
  101. // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- //
  102. void GuiScriptNotifyCtrl::onChildAdded( GuiControl *child )
  103. {
  104. Parent::onChildAdded( child );
  105. // Call Script.
  106. if( mOnChildAdded )
  107. onChildAdded_callback(getId(), child->getId());
  108. }
  109. void GuiScriptNotifyCtrl::onChildRemoved( GuiControl *child )
  110. {
  111. Parent::onChildRemoved( child );
  112. // Call Script.
  113. if( mOnChildRemoved )
  114. onChildRemoved_callback(getId(), child->getId());
  115. }
  116. //----------------------------------------------------------------
  117. bool GuiScriptNotifyCtrl::resize(const Point2I &newPosition, const Point2I &newExtent)
  118. {
  119. if( !Parent::resize( newPosition, newExtent ) )
  120. return false;
  121. // Call Script.
  122. if( mOnResize )
  123. onResize_callback(getId());
  124. return true;
  125. }
  126. void GuiScriptNotifyCtrl::childResized(GuiScriptNotifyCtrl *child)
  127. {
  128. Parent::childResized( child );
  129. // Call Script.
  130. if( mOnChildResized )
  131. onChildResized_callback(getId(), child->getId());
  132. }
  133. void GuiScriptNotifyCtrl::parentResized(const RectI &oldParentRect, const RectI &newParentRect)
  134. {
  135. Parent::parentResized( oldParentRect, newParentRect );
  136. // Call Script.
  137. if( mOnParentResized )
  138. onParentResized_callback(getId());
  139. }
  140. void GuiScriptNotifyCtrl::onLoseFirstResponder()
  141. {
  142. Parent::onLoseFirstResponder();
  143. // Call Script.
  144. if( mOnLoseFirstResponder )
  145. onLoseFirstResponder_callback(getId());
  146. }
  147. void GuiScriptNotifyCtrl::setFirstResponder( GuiControl* firstResponder )
  148. {
  149. Parent::setFirstResponder( firstResponder );
  150. // Call Script.
  151. if( mOnGainFirstResponder && isFirstResponder() )
  152. onGainFirstResponder_callback(getId());
  153. }
  154. void GuiScriptNotifyCtrl::setFirstResponder()
  155. {
  156. Parent::setFirstResponder();
  157. // Call Script.
  158. if( mOnGainFirstResponder && isFirstResponder() )
  159. onGainFirstResponder_callback(getId());
  160. }
  161. void GuiScriptNotifyCtrl::onMessage(GuiScriptNotifyCtrl *sender, S32 msg)
  162. {
  163. Parent::onMessage( sender, msg );
  164. }
  165. void GuiScriptNotifyCtrl::onDialogPush()
  166. {
  167. Parent::onDialogPush();
  168. }
  169. void GuiScriptNotifyCtrl::onDialogPop()
  170. {
  171. Parent::onDialogPop();
  172. }
  173. //void GuiScriptNotifyCtrl::onMouseUp(const GuiEvent &event)
  174. //{
  175. //}
  176. //
  177. //void GuiScriptNotifyCtrl::onMouseDown(const GuiEvent &event)
  178. //{
  179. //}
  180. //
  181. //void GuiScriptNotifyCtrl::onMouseMove(const GuiEvent &event)
  182. //{
  183. //}
  184. //
  185. //void GuiScriptNotifyCtrl::onMouseDragged(const GuiEvent &event)
  186. //{
  187. //}
  188. //
  189. //void GuiScriptNotifyCtrl::onMouseEnter(const GuiEvent &)
  190. //{
  191. //}
  192. //
  193. //void GuiScriptNotifyCtrl::onMouseLeave(const GuiEvent &)
  194. //{
  195. //}
  196. //
  197. //bool GuiScriptNotifyCtrl::onMouseWheelUp( const GuiEvent &event )
  198. //{
  199. //}
  200. //
  201. //bool GuiScriptNotifyCtrl::onMouseWheelDown( const GuiEvent &event )
  202. //{
  203. //}
  204. //
  205. //void GuiScriptNotifyCtrl::onRightMouseDown(const GuiEvent &)
  206. //{
  207. //}
  208. //
  209. //void GuiScriptNotifyCtrl::onRightMouseUp(const GuiEvent &)
  210. //{
  211. //}
  212. //
  213. //void GuiScriptNotifyCtrl::onRightMouseDragged(const GuiEvent &)
  214. //{
  215. //}
  216. //
  217. //void GuiScriptNotifyCtrl::onMiddleMouseDown(const GuiEvent &)
  218. //{
  219. //}
  220. //
  221. //void GuiScriptNotifyCtrl::onMiddleMouseUp(const GuiEvent &)
  222. //{
  223. //}
  224. //
  225. //void GuiScriptNotifyCtrl::onMiddleMouseDragged(const GuiEvent &)
  226. //{
  227. //}
  228. //void GuiScriptNotifyCtrl::onMouseDownEditor(const GuiEvent &event, Point2I offset)
  229. //{
  230. //}
  231. //void GuiScriptNotifyCtrl::onRightMouseDownEditor(const GuiEvent &event, Point2I offset)
  232. //{
  233. //}
  234. //bool GuiScriptNotifyCtrl::onKeyDown(const GuiEvent &event)
  235. //{
  236. // if ( Parent::onKeyDown( event ) )
  237. // return true;
  238. //}
  239. //
  240. //bool GuiScriptNotifyCtrl::onKeyRepeat(const GuiEvent &event)
  241. //{
  242. // // default to just another key down.
  243. // return onKeyDown(event);
  244. //}
  245. //
  246. //bool GuiScriptNotifyCtrl::onKeyUp(const GuiEvent &event)
  247. //{
  248. // if ( Parent::onKeyUp( event ) )
  249. // return true;
  250. //}