guiScriptNotifyControl.cc 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  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/guiScriptNotifyControl.h"
  23. #include "console/consoleTypes.h"
  24. //------------------------------------------------------------------------------
  25. IMPLEMENT_CONOBJECT(GuiScriptNotifyCtrl);
  26. GuiScriptNotifyCtrl::GuiScriptNotifyCtrl()
  27. {
  28. mOnChildAdded = false;
  29. mOnChildRemoved = false;
  30. mOnResize = false;
  31. mOnChildResized = false;
  32. mOnParentResized = false;
  33. }
  34. GuiScriptNotifyCtrl::~GuiScriptNotifyCtrl()
  35. {
  36. }
  37. void GuiScriptNotifyCtrl::initPersistFields()
  38. {
  39. // Callbacks Group
  40. addGroup("Callbacks");
  41. addField("onChildAdded", TypeBool, Offset( mOnChildAdded, GuiScriptNotifyCtrl ) );
  42. addField("onChildRemoved", TypeBool, Offset( mOnChildRemoved, GuiScriptNotifyCtrl ) );
  43. addField("onChildResized", TypeBool, Offset( mOnChildResized, GuiScriptNotifyCtrl ) );
  44. addField("onParentResized", TypeBool, Offset( mOnParentResized, GuiScriptNotifyCtrl ) );
  45. addField("onResize", TypeBool, Offset( mOnResize, GuiScriptNotifyCtrl ) );
  46. addField("onLoseFirstResponder", TypeBool, Offset( mOnLoseFirstResponder, GuiScriptNotifyCtrl ) );
  47. addField("onGainFirstResponder", TypeBool, Offset( mOnGainFirstResponder, GuiScriptNotifyCtrl ) );
  48. endGroup("Callbacks");
  49. Parent::initPersistFields();
  50. }
  51. // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- //
  52. void GuiScriptNotifyCtrl::onChildAdded( GuiControl *child )
  53. {
  54. Parent::onChildAdded( child );
  55. // Call Script.
  56. if( mOnChildAdded && isMethod( "onChildAdded" ) )
  57. Con::executef(this, 3, "onChildAdded", child->getIdString() );
  58. }
  59. void GuiScriptNotifyCtrl::onChildRemoved( GuiControl *child )
  60. {
  61. Parent::onChildRemoved( child );
  62. // Call Script.
  63. if( mOnChildRemoved && isMethod( "onChildRemoved" ) )
  64. Con::executef(this, 3, "onChildRemoved", child->getIdString() );
  65. }
  66. //----------------------------------------------------------------
  67. void GuiScriptNotifyCtrl::resize(const Point2I &newPosition, const Point2I &newExtent)
  68. {
  69. Parent::resize( newPosition, newExtent );
  70. // Call Script.
  71. if( mOnResize && isMethod( "onResize" ) )
  72. Con::executef(this, 2, "onResize" );
  73. }
  74. void GuiScriptNotifyCtrl::childResized(GuiScriptNotifyCtrl *child)
  75. {
  76. Parent::childResized( child );
  77. // Call Script.
  78. if( mOnChildResized && isMethod( "onChildResized" ) )
  79. Con::executef(this, 3, "onChildResized", child->getIdString() );
  80. }
  81. void GuiScriptNotifyCtrl::parentResized(const Point2I &oldParentExtent, const Point2I &newParentExtent)
  82. {
  83. Parent::parentResized( oldParentExtent, newParentExtent );
  84. // Call Script.
  85. if( mOnParentResized && isMethod( "onParentResized" ) )
  86. Con::executef(this, 2, "onParentResized" );
  87. }
  88. void GuiScriptNotifyCtrl::onLoseFirstResponder()
  89. {
  90. Parent::onLoseFirstResponder();
  91. // Call Script.
  92. if( mOnLoseFirstResponder && isMethod( "onLoseFirstResponder" ) )
  93. Con::executef(this, 2, "onLoseFirstResponder" );
  94. }
  95. void GuiScriptNotifyCtrl::setFirstResponder( GuiControl* firstResponder )
  96. {
  97. Parent::setFirstResponder( firstResponder );
  98. // Call Script.
  99. if( mOnGainFirstResponder && isFirstResponder() && isMethod( "onGainFirstResponder" ) )
  100. Con::executef(this, 2, "onGainFirstResponder" );
  101. }
  102. void GuiScriptNotifyCtrl::setFirstResponder()
  103. {
  104. Parent::setFirstResponder();
  105. // Call Script.
  106. if( mOnGainFirstResponder && isFirstResponder() && isMethod( "onGainFirstResponder" ) )
  107. Con::executef(this, 2, "onGainFirstResponder" );
  108. }
  109. void GuiScriptNotifyCtrl::onMessage(GuiScriptNotifyCtrl *sender, S32 msg)
  110. {
  111. Parent::onMessage( sender, msg );
  112. }
  113. void GuiScriptNotifyCtrl::onDialogPush()
  114. {
  115. Parent::onDialogPush();
  116. }
  117. void GuiScriptNotifyCtrl::onDialogPop()
  118. {
  119. Parent::onDialogPop();
  120. }
  121. //void GuiScriptNotifyCtrl::onMouseUp(const GuiEvent &event)
  122. //{
  123. //}
  124. //
  125. //void GuiScriptNotifyCtrl::onMouseDown(const GuiEvent &event)
  126. //{
  127. //}
  128. //
  129. //void GuiScriptNotifyCtrl::onMouseMove(const GuiEvent &event)
  130. //{
  131. //}
  132. //
  133. //void GuiScriptNotifyCtrl::onMouseDragged(const GuiEvent &event)
  134. //{
  135. //}
  136. //
  137. //void GuiScriptNotifyCtrl::onMouseEnter(const GuiEvent &)
  138. //{
  139. //}
  140. //
  141. //void GuiScriptNotifyCtrl::onMouseLeave(const GuiEvent &)
  142. //{
  143. //}
  144. //
  145. //bool GuiScriptNotifyCtrl::onMouseWheelUp( const GuiEvent &event )
  146. //{
  147. //}
  148. //
  149. //bool GuiScriptNotifyCtrl::onMouseWheelDown( const GuiEvent &event )
  150. //{
  151. //}
  152. //
  153. //void GuiScriptNotifyCtrl::onRightMouseDown(const GuiEvent &)
  154. //{
  155. //}
  156. //
  157. //void GuiScriptNotifyCtrl::onRightMouseUp(const GuiEvent &)
  158. //{
  159. //}
  160. //
  161. //void GuiScriptNotifyCtrl::onRightMouseDragged(const GuiEvent &)
  162. //{
  163. //}
  164. //
  165. //void GuiScriptNotifyCtrl::onMiddleMouseDown(const GuiEvent &)
  166. //{
  167. //}
  168. //
  169. //void GuiScriptNotifyCtrl::onMiddleMouseUp(const GuiEvent &)
  170. //{
  171. //}
  172. //
  173. //void GuiScriptNotifyCtrl::onMiddleMouseDragged(const GuiEvent &)
  174. //{
  175. //}
  176. //void GuiScriptNotifyCtrl::onMouseDownEditor(const GuiEvent &event, Point2I offset)
  177. //{
  178. //}
  179. //void GuiScriptNotifyCtrl::onRightMouseDownEditor(const GuiEvent &event, Point2I offset)
  180. //{
  181. //}
  182. //bool GuiScriptNotifyCtrl::onKeyDown(const GuiEvent &event)
  183. //{
  184. // if ( Parent::onKeyDown( event ) )
  185. // return true;
  186. //}
  187. //
  188. //bool GuiScriptNotifyCtrl::onKeyRepeat(const GuiEvent &event)
  189. //{
  190. // // default to just another key down.
  191. // return onKeyDown(event);
  192. //}
  193. //
  194. //bool GuiScriptNotifyCtrl::onKeyUp(const GuiEvent &event)
  195. //{
  196. // if ( Parent::onKeyUp( event ) )
  197. // return true;
  198. //}