guiControl_ScriptBinding.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  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. ConsoleMethodGroupBeginWithDocs(GuiControl, SimGroup)
  23. /*! Sets whether this control can serialize itself to the hard disk
  24. @param Flag setting
  25. @return No Return Value
  26. */
  27. ConsoleMethodWithDocs( GuiControl, setCanSave, ConsoleVoid, 3,3, (bool canSave))
  28. {
  29. object->setCanSave( dAtob( argv[2] ) );
  30. }
  31. /*! Check if point id in the control
  32. @param x Point x coordinate in parent coords
  33. @param y Point y coordinate in parent coords
  34. @return Returns true if the point is in the control, false otherwise
  35. */
  36. ConsoleMethodWithDocs(GuiControl, pointInControl, ConsoleBool, 4,4, (int x, int y))
  37. {
  38. Point2I kPoint(dAtoi(argv[2]), dAtoi(argv[3]));
  39. return object->pointInControl(kPoint);
  40. }
  41. // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- //
  42. /*! Adds the gui control
  43. @param controlId integer ID of the control to add
  44. @return No Return value
  45. */
  46. ConsoleMethodWithDocs( GuiControl, addGuiControl, ConsoleVoid, 3, 3, (int controlId))
  47. {
  48. GuiControl *ctrl = dynamic_cast<GuiControl *>(Sim::findObject(argv[2]));
  49. if(ctrl)
  50. {
  51. object->addObject(ctrl);
  52. }
  53. }
  54. //-----------------------------------------------------------------------------
  55. // Make Sure Child 1 is Ordered Just Under Child 2.
  56. //-----------------------------------------------------------------------------
  57. /*! uses simset reorder to push child 1 after child 2 - both must already be child controls of this control
  58. */
  59. ConsoleMethodWithDocs(GuiControl, reorderChild, ConsoleVoid, 4,4, (child1, child2))
  60. {
  61. GuiControl* pControl = dynamic_cast<GuiControl*>(Sim::findObject(dAtoi(argv[2])));
  62. GuiControl* pTarget = dynamic_cast<GuiControl*>(Sim::findObject(dAtoi(argv[3])));
  63. if(pControl && pTarget)
  64. {
  65. object->reOrder(pControl,pTarget);
  66. }
  67. }
  68. /*! @return Returns the Id of the parent control
  69. */
  70. ConsoleMethodWithDocs( GuiControl, getParent, ConsoleInt, 2, 2, ())
  71. {
  72. GuiControl* pParent = object->getParent();
  73. if(pParent)
  74. {
  75. return pParent->getId();
  76. }
  77. return 0;
  78. }
  79. /*! Use the setValue method to set the control specific value to value. Purpose and type varies by control type.
  80. @param value Some control specific value.
  81. @return No return value
  82. */
  83. ConsoleMethodWithDocs( GuiControl, setValue, ConsoleVoid, 3, 3, ( value ))
  84. {
  85. object->setScriptValue(argv[2]);
  86. }
  87. /*! Use the getValue method to get the control-specific 'value' for this control.
  88. @return Returns a control-specific specific value. Varies by control
  89. */
  90. ConsoleMethodWithDocs( GuiControl, getValue, ConsoleString, 2, 2, ())
  91. {
  92. return object->getScriptValue();
  93. }
  94. /*! Use the setActive method to (de)activate this control. Once active, a control can accept inputs. Controls automatically re-shade/skin themselves to reflect their active/inactive state.
  95. @param isActive A boolean value. f isActive is true, this control is activated, else it is set to inactive.
  96. @return No return value
  97. */
  98. ConsoleMethodWithDocs( GuiControl, setActive, ConsoleVoid, 3, 3, ( isActive ))
  99. {
  100. object->setActive(dAtob(argv[2]));
  101. }
  102. /*! Use the isActive method to determine if this control is active.
  103. An inactive control may visible, but will not accept inputs. It will also normally re-shade or re-skin itself to reflect its inactive state
  104. @return Returns true if this control is active.
  105. */
  106. ConsoleMethodWithDocs( GuiControl, isActive, ConsoleBool, 2, 2, ())
  107. {
  108. return object->isActive();
  109. }
  110. /*! Use the setVisible method to (un)hide this control.
  111. @param isVisible A boolean value. If true, the control will be made visible, otherwise the control will be hidden.
  112. @return No return value
  113. */
  114. ConsoleMethodWithDocs( GuiControl, setVisible, ConsoleVoid, 3, 3, ( isVisible ))
  115. {
  116. object->setVisible(dAtob(argv[2]));
  117. }
  118. /*! Use the makeFirstResponder method to force this control to become the first responder.
  119. @param isFirst A boolean value. If true, then this control become first reponder and at captures inputs before all other controls, excluding dialogs above this control.
  120. @return No return value
  121. */
  122. ConsoleMethodWithDocs( GuiControl, makeFirstResponder, ConsoleVoid, 3, 3, ( isFirst ))
  123. {
  124. object->makeFirstResponder(dAtob(argv[2]));
  125. }
  126. /*! Use the isVisible method to determine if this control is visible.
  127. This can return true, even if the entire control covered by another. This merely means that the control will render if not covered
  128. @return Returns true if the control is visible.
  129. */
  130. ConsoleMethodWithDocs( GuiControl, isVisible, ConsoleBool, 2, 2, ())
  131. {
  132. return object->isVisible();
  133. }
  134. /*! Use the isAwake method to determine if this control is awake.
  135. @return Returns true if this control is awake and ready to display
  136. */
  137. ConsoleMethodWithDocs( GuiControl, isAwake, ConsoleBool, 2, 2, ())
  138. {
  139. return object->isAwake();
  140. }
  141. /*! Sets the currently used from for the GuiControl
  142. @param p The profile you wish to set the control to use
  143. @return No return value
  144. */
  145. ConsoleMethodWithDocs( GuiControl, setProfile, ConsoleVoid, 3, 3, (GuiControlProfile p))
  146. {
  147. GuiControlProfile * profile;
  148. if(Sim::findObject(argv[2], profile))
  149. object->setControlProfile(profile);
  150. }
  151. /*! Resizes the control to the given dimensions
  152. */
  153. ConsoleMethodWithDocs( GuiControl, resize, ConsoleVoid, 6, 6, (int x, int y, int w, int h))
  154. {
  155. Point2I newPos(dAtoi(argv[2]), dAtoi(argv[3]));
  156. Point2I newExt(dAtoi(argv[4]), dAtoi(argv[5]));
  157. object->resize(newPos, newExt);
  158. }
  159. /*! @return A string set up as \<pos.x> <pos.y>\
  160. */
  161. ConsoleMethodWithDocs( GuiControl, getPosition, ConsoleString, 2, 2, ())
  162. {
  163. char *retBuffer = Con::getReturnBuffer(64);
  164. const Point2I &pos = object->getPosition();
  165. dSprintf(retBuffer, 64, "%d %d", pos.x, pos.y);
  166. return retBuffer;
  167. }
  168. /*! @return Returns center of control, as space seperated ints
  169. */
  170. ConsoleMethodWithDocs( GuiControl, getCenter, ConsoleString, 2, 2, ())
  171. {
  172. char *retBuffer = Con::getReturnBuffer(64);
  173. const Point2I pos = object->getPosition();
  174. const Point2I ext = object->getExtent();
  175. Point2I center(pos.x + ext.x/2, pos.y + ext.y/2);
  176. dSprintf(retBuffer, 64, "%d %d", center.x, center.y);
  177. return retBuffer;
  178. }
  179. /*! Sets control position, by center - coords are local not global
  180. @return No Return value.
  181. */
  182. ConsoleMethodWithDocs( GuiControl, setCenter, ConsoleVoid, 4, 4, (int x, int y))
  183. {
  184. const Point2I ext = object->getExtent();
  185. Point2I newpos(dAtoi(argv[2])-ext.x/2, dAtoi(argv[3])-ext.y/2);
  186. object->setPosition(newpos);
  187. }
  188. /*! @return Returns center of control, as space seperated ints
  189. */
  190. ConsoleMethodWithDocs( GuiControl, getGlobalCenter, ConsoleString, 2, 2, ())
  191. {
  192. char *retBuffer = Con::getReturnBuffer(64);
  193. const Point2I tl(0,0);
  194. Point2I pos = object->localToGlobalCoord(tl);
  195. const Point2I ext = object->getExtent();
  196. Point2I center(pos.x + ext.x/2, pos.y + ext.y/2);
  197. dSprintf(retBuffer, 64, "%d %d", center.x, center.y);
  198. return retBuffer;
  199. }
  200. /*! @return Returns the control's position converted to global coordinates (position as space-separted integers)
  201. */
  202. ConsoleMethodWithDocs( GuiControl, getGlobalPosition, ConsoleString, 2, 2, ())
  203. {
  204. char *retBuffer = Con::getReturnBuffer(64);
  205. const Point2I pos(0,0);
  206. Point2I gPos = object->localToGlobalCoord(pos);
  207. dSprintf(retBuffer, 64, "%d %d", gPos.x, gPos.y);
  208. return retBuffer;
  209. }
  210. /*! Sets the control's position in global space
  211. @return No return value
  212. */
  213. ConsoleMethodWithDocs( GuiControl, setPositionGlobal, ConsoleVoid, 4, 4, (int x, int y))
  214. {
  215. //see if we can turn the x/y into ints directly,
  216. Point2I gPos(dAtoi(argv[2]), dAtoi(argv[3]));
  217. Point2I lPosOffset = object->globalToLocalCoord(gPos);
  218. lPosOffset.x += object->mBounds.point.x;
  219. lPosOffset.y += object->mBounds.point.y;
  220. object->mBounds.set(lPosOffset,object->mBounds.extent);
  221. }
  222. /*! Sets the current control position in local space
  223. @return No Return Value.
  224. */
  225. ConsoleMethodWithDocs( GuiControl, setPosition, ConsoleVoid, 4, 4, (int x, int y))
  226. {
  227. //see if we can turn the x/y into ints directly,
  228. Point2I lPos(dAtoi(argv[2]), dAtoi(argv[3]));
  229. object->mBounds.set(lPos,object->mBounds.extent);
  230. }
  231. /*! Get the width and height of the control.
  232. @return The height and width as a string with space-separated integers
  233. */
  234. ConsoleMethodWithDocs( GuiControl, getExtent, ConsoleString, 2, 2, (...))
  235. {
  236. char *retBuffer = Con::getReturnBuffer(64);
  237. const Point2I &ext = object->getExtent();
  238. dSprintf(retBuffer, 64, "%d %d", ext.x, ext.y);
  239. return retBuffer;
  240. }
  241. /*! Sets the width & height of the control.
  242. @return No Return Value.
  243. */
  244. ConsoleMethodWithDocs( GuiControl, setExtent, ConsoleVoid, 4, 4, (int width, int height))
  245. {
  246. Point2I kExt(dAtoi(argv[2]), dAtoi(argv[3]));
  247. object->setExtent(kExt);
  248. }
  249. /*! Get the minimum allowed size of the control.
  250. @return Returns the minimum extent as a string with space separated point values <width> <height>
  251. */
  252. ConsoleMethodWithDocs( GuiControl, getMinExtent, ConsoleString, 2, 2, ())
  253. {
  254. char *retBuffer = Con::getReturnBuffer(64);
  255. const Point2I &minExt = object->getMinExtent();
  256. dSprintf(retBuffer, 64, "%d %d", minExt.x, minExt.y);
  257. return retBuffer;
  258. }
  259. /*! Searches for the control at the given point
  260. @return Returns the Id of the control at the point
  261. */
  262. ConsoleMethodWithDocs( GuiControl, findHitControl, ConsoleInt, 4, 4, (int x, int y))
  263. {
  264. Point2I pos(dAtoi(argv[2]), dAtoi(argv[3]));
  265. GuiControl *hit = object->findHitControl(pos);
  266. return hit ? hit->getId() : 0;
  267. }
  268. /*! Sets this control as the first responder
  269. */
  270. ConsoleMethodWithDocs(GuiControl, setFirstResponder, ConsoleVoid, 2, 2, ())
  271. {
  272. object->setFirstResponder();
  273. }
  274. ConsoleMethodGroupEndWithDocs(GuiControl)