guiScriptNotifyControl.cpp 9.2 KB

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