guiScriptNotifyControl.cpp 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  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. mOnLoseFirstResponder = true;
  53. mOnGainFirstResponder = true;
  54. }
  55. GuiScriptNotifyCtrl::~GuiScriptNotifyCtrl()
  56. {
  57. }
  58. void GuiScriptNotifyCtrl::initPersistFields()
  59. {
  60. // Callbacks Group
  61. addGroup("Callbacks");
  62. addField("notifyOnChildAdded", TypeBool, Offset( mOnChildAdded, GuiScriptNotifyCtrl ), "Enables/disables onChildAdded callback" );
  63. addField("notifyOnChildRemoved", TypeBool, Offset( mOnChildRemoved, GuiScriptNotifyCtrl ), "Enables/disables onChildRemoved callback" );
  64. addField("notifyOnChildResized", TypeBool, Offset( mOnChildResized, GuiScriptNotifyCtrl ), "Enables/disables onChildResized callback" );
  65. addField("notifyOnParentResized", TypeBool, Offset( mOnParentResized, GuiScriptNotifyCtrl ), "Enables/disables onParentResized callback" );
  66. addField("notifyOnResize", TypeBool, Offset( mOnResize, GuiScriptNotifyCtrl ), "Enables/disables onResize callback" );
  67. addField("notifyOnLoseFirstResponder", TypeBool, Offset( mOnLoseFirstResponder, GuiScriptNotifyCtrl ), "Enables/disables onLoseFirstResponder callback" );
  68. addField("notifyOnGainFirstResponder", TypeBool, Offset( mOnGainFirstResponder, GuiScriptNotifyCtrl ), "Enables/disables onGainFirstResponder callback" );
  69. endGroup("Callbacks");
  70. Parent::initPersistFields();
  71. }
  72. IMPLEMENT_CALLBACK( GuiScriptNotifyCtrl, onResize, void, ( SimObjectId ID ), ( ID ),
  73. "Called when this GUI is resized.\n\n"
  74. "@param ID Unique object ID assigned when created (%this in script).\n"
  75. );
  76. IMPLEMENT_CALLBACK( GuiScriptNotifyCtrl, onChildAdded, void, ( SimObjectId ID, SimObjectId childID ), ( ID, childID ),
  77. "Called when a child is added to this GUI.\n\n"
  78. "@param ID Unique object ID assigned when created (%this in script).\n"
  79. "@param childID Unique object ID of child being added.\n"
  80. );
  81. IMPLEMENT_CALLBACK( GuiScriptNotifyCtrl, onChildRemoved, void, ( SimObjectId ID, SimObjectId childID ), ( ID, childID ),
  82. "Called when a child is removed from this GUI.\n\n"
  83. "@param ID Unique object ID assigned when created (%this in script).\n"
  84. "@param childID Unique object ID of child being removed.\n"
  85. );
  86. IMPLEMENT_CALLBACK( GuiScriptNotifyCtrl, onChildResized, void, ( SimObjectId ID, SimObjectId childID ), ( ID, childID ),
  87. "Called when a child is of this GUI is being resized.\n\n"
  88. "@param ID Unique object ID assigned when created (%this in script).\n"
  89. "@param childID Unique object ID of child being resized.\n"
  90. );
  91. IMPLEMENT_CALLBACK( GuiScriptNotifyCtrl, onParentResized, void, ( SimObjectId ID ), ( ID ),
  92. "Called when this GUI's parent is resized.\n\n"
  93. "@param ID Unique object ID assigned when created (%this in script).\n"
  94. );
  95. IMPLEMENT_CALLBACK( GuiScriptNotifyCtrl, onLoseFirstResponder, void, ( SimObjectId ID ), ( ID ),
  96. "Called when this GUI loses focus.\n\n"
  97. "@param ID Unique object ID assigned when created (%this in script).\n"
  98. );
  99. IMPLEMENT_CALLBACK( GuiScriptNotifyCtrl, onGainFirstResponder, void, ( SimObjectId ID ), ( ID ),
  100. "Called when this GUI gains focus.\n\n"
  101. "@param ID Unique object ID assigned when created (%this in script).\n"
  102. );
  103. // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- //
  104. void GuiScriptNotifyCtrl::onChildAdded( GuiControl *child )
  105. {
  106. Parent::onChildAdded( child );
  107. // Call Script.
  108. if( mOnChildAdded )
  109. onChildAdded_callback(getId(), child->getId());
  110. }
  111. void GuiScriptNotifyCtrl::onChildRemoved( GuiControl *child )
  112. {
  113. Parent::onChildRemoved( child );
  114. // Call Script.
  115. if( mOnChildRemoved )
  116. onChildRemoved_callback(getId(), child->getId());
  117. }
  118. //----------------------------------------------------------------
  119. bool GuiScriptNotifyCtrl::resize(const Point2I &newPosition, const Point2I &newExtent)
  120. {
  121. if( !Parent::resize( newPosition, newExtent ) )
  122. return false;
  123. // Call Script.
  124. if( mOnResize )
  125. onResize_callback(getId());
  126. return true;
  127. }
  128. void GuiScriptNotifyCtrl::childResized(GuiScriptNotifyCtrl *child)
  129. {
  130. Parent::childResized( child );
  131. // Call Script.
  132. if( mOnChildResized )
  133. onChildResized_callback(getId(), child->getId());
  134. }
  135. void GuiScriptNotifyCtrl::parentResized(const RectI &oldParentRect, const RectI &newParentRect)
  136. {
  137. Parent::parentResized( oldParentRect, newParentRect );
  138. // Call Script.
  139. if( mOnParentResized )
  140. onParentResized_callback(getId());
  141. }
  142. void GuiScriptNotifyCtrl::onLoseFirstResponder()
  143. {
  144. Parent::onLoseFirstResponder();
  145. // Call Script.
  146. if( mOnLoseFirstResponder )
  147. onLoseFirstResponder_callback(getId());
  148. }
  149. void GuiScriptNotifyCtrl::setFirstResponder( GuiControl* firstResponder )
  150. {
  151. Parent::setFirstResponder( firstResponder );
  152. // Call Script.
  153. if( mOnGainFirstResponder && isFirstResponder() )
  154. onGainFirstResponder_callback(getId());
  155. }
  156. void GuiScriptNotifyCtrl::setFirstResponder()
  157. {
  158. Parent::setFirstResponder();
  159. // Call Script.
  160. if( mOnGainFirstResponder && isFirstResponder() )
  161. onGainFirstResponder_callback(getId());
  162. }
  163. void GuiScriptNotifyCtrl::onMessage(GuiScriptNotifyCtrl *sender, S32 msg)
  164. {
  165. Parent::onMessage( sender, msg );
  166. }
  167. void GuiScriptNotifyCtrl::onDialogPush()
  168. {
  169. Parent::onDialogPush();
  170. }
  171. void GuiScriptNotifyCtrl::onDialogPop()
  172. {
  173. Parent::onDialogPop();
  174. }
  175. //void GuiScriptNotifyCtrl::onMouseUp(const GuiEvent &event)
  176. //{
  177. //}
  178. //
  179. //void GuiScriptNotifyCtrl::onMouseDown(const GuiEvent &event)
  180. //{
  181. //}
  182. //
  183. //void GuiScriptNotifyCtrl::onMouseMove(const GuiEvent &event)
  184. //{
  185. //}
  186. //
  187. //void GuiScriptNotifyCtrl::onMouseDragged(const GuiEvent &event)
  188. //{
  189. //}
  190. //
  191. //void GuiScriptNotifyCtrl::onMouseEnter(const GuiEvent &)
  192. //{
  193. //}
  194. //
  195. //void GuiScriptNotifyCtrl::onMouseLeave(const GuiEvent &)
  196. //{
  197. //}
  198. //
  199. //bool GuiScriptNotifyCtrl::onMouseWheelUp( const GuiEvent &event )
  200. //{
  201. //}
  202. //
  203. //bool GuiScriptNotifyCtrl::onMouseWheelDown( const GuiEvent &event )
  204. //{
  205. //}
  206. //
  207. //void GuiScriptNotifyCtrl::onRightMouseDown(const GuiEvent &)
  208. //{
  209. //}
  210. //
  211. //void GuiScriptNotifyCtrl::onRightMouseUp(const GuiEvent &)
  212. //{
  213. //}
  214. //
  215. //void GuiScriptNotifyCtrl::onRightMouseDragged(const GuiEvent &)
  216. //{
  217. //}
  218. //
  219. //void GuiScriptNotifyCtrl::onMiddleMouseDown(const GuiEvent &)
  220. //{
  221. //}
  222. //
  223. //void GuiScriptNotifyCtrl::onMiddleMouseUp(const GuiEvent &)
  224. //{
  225. //}
  226. //
  227. //void GuiScriptNotifyCtrl::onMiddleMouseDragged(const GuiEvent &)
  228. //{
  229. //}
  230. //void GuiScriptNotifyCtrl::onMouseDownEditor(const GuiEvent &event, Point2I offset)
  231. //{
  232. //}
  233. //void GuiScriptNotifyCtrl::onRightMouseDownEditor(const GuiEvent &event, Point2I offset)
  234. //{
  235. //}
  236. //bool GuiScriptNotifyCtrl::onKeyDown(const GuiEvent &event)
  237. //{
  238. // if ( Parent::onKeyDown( event ) )
  239. // return true;
  240. //}
  241. //
  242. //bool GuiScriptNotifyCtrl::onKeyRepeat(const GuiEvent &event)
  243. //{
  244. // // default to just another key down.
  245. // return onKeyDown(event);
  246. //}
  247. //
  248. //bool GuiScriptNotifyCtrl::onKeyUp(const GuiEvent &event)
  249. //{
  250. // if ( Parent::onKeyUp( event ) )
  251. // return true;
  252. //}