Sprite.h 4.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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 _SPRITE_H_
  23. #define _SPRITE_H_
  24. #ifndef _SPRITE_BASE_H_
  25. #include "2d/core/SpriteBase.h"
  26. #endif
  27. #ifndef _FADETOCOLOR_H_
  28. #include "graphics/FadeToColor.h"
  29. #endif
  30. //------------------------------------------------------------------------------
  31. class Sprite : public SpriteBase
  32. {
  33. typedef SpriteBase Parent;
  34. private:
  35. /// Render flipping.
  36. bool mFlipX;
  37. bool mFlipY;
  38. FadeToColor mFadeToColorTL;
  39. FadeToColor mFadeToColorTR;
  40. FadeToColor mFadeToColorBL;
  41. FadeToColor mFadeToColorBR;
  42. public:
  43. Sprite();
  44. virtual ~Sprite();
  45. static void initPersistFields();
  46. virtual void copyTo(SimObject* object);
  47. /// Render flipping.
  48. void setFlip( const bool flipX, const bool flipY ) { mFlipX = flipX; mFlipY = flipY; }
  49. void setFlipX( const bool flipX ) { setFlip( flipX, mFlipY ); }
  50. void setFlipY( const bool flipY ) { setFlip( mFlipX, flipY ); }
  51. inline bool getFlipX( void ) const { return mFlipX; }
  52. inline bool getFlipY( void ) const { return mFlipY; }
  53. virtual void sceneRender( const SceneRenderState* pSceneRenderState, const SceneRenderRequest* pSceneRenderRequest, BatchRender* pBatchRenderer );
  54. // Complex Colors (Using 4 blend colors, one for each corner)
  55. inline void setUseComplexColor(const bool complexColor) { mUseComplexColor = complexColor; }
  56. inline bool getUseComplexColor(void) const { return mUseComplexColor; }
  57. inline void setComplexColor(const ColorF& blendColor0, const ColorF& blendColor1, const ColorF& blendColor2, const ColorF& blendColor3) { mComplexColor0 = blendColor0; mComplexColor1 = blendColor1; mComplexColor2 = blendColor2; mComplexColor3 = blendColor3; }
  58. const ColorF& getComplexColor(const S8 cornerID);
  59. static Corner getCornerEnum(const char* label);
  60. // FadeTo for Complex Colors
  61. bool fadeToComplex(const S8 cornerID, const ColorF& targetColor, const F32 deltaRed, const F32 deltaGreen, const F32 deltaBlue, const F32 deltaAlpha);
  62. void updateBlendColor(const F32 elapsedTime);
  63. void checkFadeComplete();
  64. /// Declare Console Object.
  65. DECLARE_CONOBJECT( Sprite );
  66. protected:
  67. static bool writeFlipX( void* obj, StringTableEntry pFieldName ) { return static_cast<Sprite*>(obj)->getFlipX() == true; }
  68. static bool writeFlipY( void* obj, StringTableEntry pFieldName ) { return static_cast<Sprite*>(obj)->getFlipY() == true; }
  69. static bool writeUseComplexColor( void* obj, StringTableEntry pFieldName ) {return static_cast<Sprite*>(obj)->getUseComplexColor() == true; }
  70. bool mUseComplexColor;
  71. ColorF mComplexColor0;
  72. ColorF mComplexColor1;
  73. ColorF mComplexColor2;
  74. ColorF mComplexColor3;
  75. };
  76. #endif // _SPRITE_H_