guiSpriteCtrl_ScriptBindings.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. ConsoleMethod( GuiSpriteCtrl, isStaticFrameProvider, bool, 2, 2, "() - Gets whether the control is in static or dynamic (animated)mode.\n"
  23. "@return Returns whether the control is in static or dynamic (animated)mode.")
  24. {
  25. return object->isStaticFrameProvider();
  26. }
  27. //-----------------------------------------------------------------------------
  28. ConsoleMethod( GuiSpriteCtrl, setImage, void, 3, 3, "(imageAssetId) Sets the image asset Id to use as the image.\n"
  29. "@param imageAssetId The image asset Id to use as the image.\n"
  30. "@return No return value.")
  31. {
  32. object->setImage( argv[2] );
  33. }
  34. //------------------------------------------------------------------------------
  35. ConsoleMethod( GuiSpriteCtrl, getImage, const char*, 2, 2, "() - Gets current image asset Id.\n"
  36. "@return (string imageAssetId) The image being displayed.")
  37. {
  38. // Are we in static mode?
  39. if ( !object->isStaticFrameProvider() )
  40. {
  41. // No, so warn.
  42. Con::warnf( "GuiSpriteCtrl::getImage() - Method invalid, not in static mode." );
  43. return StringTable->EmptyString;
  44. }
  45. // Get image.
  46. return DYNAMIC_VOID_CAST_TO(GuiSpriteCtrl, ImageFrameProvider, object)->getImage();
  47. }
  48. //-----------------------------------------------------------------------------
  49. ConsoleMethod( GuiSpriteCtrl, setImageFrame, void, 3, 3, "(int imageFrame) Sets the image frame to use as the image.\n"
  50. "@param imageFrame The image frame to use as the image.\n"
  51. "@return No return value.")
  52. {
  53. object->setImageFrame( dAtoi(argv[2]) );
  54. }
  55. //------------------------------------------------------------------------------
  56. ConsoleMethod( GuiSpriteCtrl, getImageFrame, S32, 2, 2, "() - Gets current image Frame.\n"
  57. "@return (int frame) The frame currently being displayed.")
  58. {
  59. // Are we in static mode?
  60. if ( !object->isStaticFrameProvider() )
  61. {
  62. // No, so warn.
  63. Con::warnf( "GuiSpriteCtrl::getFrame() - Method invalid, not in static mode." );
  64. return -1;
  65. }
  66. // Get image frame.
  67. return object->getImageFrame();
  68. }
  69. //------------------------------------------------------------------------------
  70. ConsoleMethod( GuiSpriteCtrl, setAnimation, void, 3, 3, "(string animationAssetId) - Sets the animation asset Id to display.\n"
  71. "@param animationAssetId The animation asset Id to play\n"
  72. "@return No return value.")
  73. {
  74. // Set animation.
  75. object->setAnimation( argv[2] );
  76. }
  77. //------------------------------------------------------------------------------
  78. ConsoleMethod( GuiSpriteCtrl, getAnimation, const char*, 2, 2, "() - Gets the current animation asset Id.\n"
  79. "@return (string ianimationAssetId) The animation being displayed.")
  80. {
  81. // Are we in static mode?
  82. if ( object->isStaticFrameProvider() )
  83. {
  84. // Yes, so warn.
  85. Con::warnf( "GuiSpriteCtrl::getAnimation() - Method invalid, in static mode." );
  86. return StringTable->EmptyString;
  87. }
  88. // Get animation.
  89. return DYNAMIC_VOID_CAST_TO(GuiSpriteCtrl, ImageFrameProvider, object)->getAnimation();
  90. }