guiImageButtonCtrl.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. #ifndef _GUIIMAGEBUTTON_H_
  23. #define _GUIIMAGEBUTTON_H_
  24. #ifndef _GUIBUTTONCTRL_H_
  25. #include "gui/buttons/guiButtonCtrl.h"
  26. #endif
  27. #ifndef _TEXTURE_MANAGER_H_
  28. #include "graphics/TextureManager.h"
  29. #endif
  30. #ifndef _IMAGE_ASSET_H_
  31. #include "2d/assets/ImageAsset.h"
  32. #endif
  33. #ifndef _ASSET_PTR_H_
  34. #include "assets/assetPtr.h"
  35. #endif
  36. //-----------------------------------------------------------------------------
  37. class GuiImageButtonCtrl : public GuiButtonCtrl
  38. {
  39. private:
  40. typedef GuiButtonCtrl Parent;
  41. protected:
  42. StringTableEntry mNormalAssetId;
  43. StringTableEntry mHoverAssetId;
  44. StringTableEntry mDownAssetId;
  45. StringTableEntry mInactiveAssetId;
  46. AssetPtr<ImageAsset> mImageNormalAsset;
  47. AssetPtr<ImageAsset> mImageHoverAsset;
  48. AssetPtr<ImageAsset> mImageDownAsset;
  49. AssetPtr<ImageAsset> mImageInactiveAsset;
  50. void renderButton( ImageAsset* pImageAsset, const U32 frame, Point2I &offset, const RectI& updateRect);
  51. protected:
  52. enum ButtonState
  53. {
  54. NORMAL,
  55. HOVER,
  56. DOWN,
  57. INACTIVE
  58. };
  59. public:
  60. GuiImageButtonCtrl();
  61. bool onWake();
  62. void onSleep();
  63. void onRender(Point2I offset, const RectI &updateRect);
  64. static void initPersistFields();
  65. void setNormalImage( const char* pImageAssetId );
  66. inline StringTableEntry getNormalImage( void ) const { return mNormalAssetId; }
  67. void setHoverImage( const char* pImageAssetId );
  68. inline StringTableEntry getHoverImage( void ) const { return mHoverAssetId; }
  69. void setDownImage( const char* pImageAssetId );
  70. inline StringTableEntry getDownImage( void ) const { return mDownAssetId; }
  71. void setInactiveImage( const char* pImageAssetId );
  72. inline StringTableEntry getInactiveImage( void ) const { return mInactiveAssetId; }
  73. // Declare type.
  74. DECLARE_CONOBJECT(GuiImageButtonCtrl);
  75. protected:
  76. static bool setNormalImage(void* obj, const char* data) { static_cast<GuiImageButtonCtrl*>(obj)->setNormalImage( data ); return false; }
  77. static const char* getNormalImage(void* obj, const char* data) { return static_cast<GuiImageButtonCtrl*>(obj)->getNormalImage(); }
  78. static bool setHoverImage(void* obj, const char* data) { static_cast<GuiImageButtonCtrl*>(obj)->setHoverImage( data ); return false; }
  79. static const char* getHoverImage(void* obj, const char* data) { return static_cast<GuiImageButtonCtrl*>(obj)->getHoverImage(); }
  80. static bool setDownImage(void* obj, const char* data) { static_cast<GuiImageButtonCtrl*>(obj)->setDownImage( data ); return false; }
  81. static const char* getDownImage(void* obj, const char* data) { return static_cast<GuiImageButtonCtrl*>(obj)->getDownImage(); }
  82. static bool setInactiveImage(void* obj, const char* data) { static_cast<GuiImageButtonCtrl*>(obj)->setInactiveImage( data ); return false; }
  83. static const char* getInactiveImage(void* obj, const char* data) { return static_cast<GuiImageButtonCtrl*>(obj)->getInactiveImage(); }
  84. };
  85. #endif //_GUIIMAGEBUTTON_H_