Main Page | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members

Sprite.h

Go to the documentation of this file.
00001 /* Sprite - A bitmap Actor that animates and moves around. */ 00002 00003 #ifndef SPRITE_H 00004 #define SPRITE_H 00005 00006 #include "Actor.h" 00007 #include "RageTextureID.h" 00008 00009 class RageTexture; 00010 00011 00012 #define LUA_Sprite_METHODS( T ) \ 00013 LUA_Actor_METHODS( T ) \ 00014 /* Commands that go in the tweening queue: 00015 * Commands that take effect immediately (ignoring the tweening queue): */ \ 00016 static int customtexturerect( T* p, lua_State *L ) { p->SetCustomTextureRect( RectF(FArg(1),FArg(2),FArg(3),FArg(4)) ); return 0; } \ 00017 static int texcoordvelocity( T* p, lua_State *L ) { p->SetTexCoordVelocity( FArg(1),FArg(2) ); return 0; } \ 00018 static int scaletoclipped( T* p, lua_State *L ) { p->ScaleToClipped( FArg(1),FArg(2) ); return 0; } \ 00019 static int stretchtexcoords( T* p, lua_State *L ) { p->StretchTexCoords( FArg(1),FArg(2) ); return 0; } \ 00020 /* Texture commands; these could be moved to RageTexture* (even though that's 00021 * not an Actor) if these are needed for other things that use textures. 00022 * We'd need to break the command helpers into a separate function; RageTexture 00023 * shouldn't depend on Actor. */ \ 00024 static int position( T* p, lua_State *L ) { p->SetPosition(FArg(1)); return 0; } \ 00025 static int loop( T* p, lua_State *L ) { p->SetLooping(BArg(1)); return 0; } \ 00026 static int rate( T* p, lua_State *L ) { p->SetPlaybackRate(FArg(1)); return 0; } \ 00027 00028 #define LUA_Sprite_METHODS_MAP( T ) \ 00029 LUA_Actor_METHODS_MAP( T ) \ 00030 LUA_METHOD_MAP( T, customtexturerect ) \ 00031 LUA_METHOD_MAP( T, texcoordvelocity ) \ 00032 LUA_METHOD_MAP( T, scaletoclipped ) \ 00033 LUA_METHOD_MAP( T, stretchtexcoords ) \ 00034 LUA_METHOD_MAP( T, position ) \ 00035 LUA_METHOD_MAP( T, loop ) \ 00036 LUA_METHOD_MAP( T, rate ) \ 00037 00038 00039 class Sprite: public Actor 00040 { 00041 public: 00042 Sprite(); 00043 virtual ~Sprite(); 00044 00045 virtual bool EarlyAbortDraw(); 00046 virtual void DrawPrimitives(); 00047 virtual void Update( float fDeltaTime ); 00048 00049 virtual void GainFocus( float fRate, bool bRewindMovie, bool bLoop ); 00050 virtual void LoseFocus(); 00051 00052 void UpdateAnimationState(); // take m_fSecondsIntoState, and move to a new state 00053 00054 /* Adjust texture properties for song backgrounds. */ 00055 static RageTextureID SongBGTexture( RageTextureID ID ); 00056 00057 /* Adjust texture properties for song banners. */ 00058 static RageTextureID SongBannerTexture( RageTextureID ID ); 00059 00060 /* Just a convenience function; load an image that'll be used in the 00061 * background. */ 00062 virtual bool LoadBG( RageTextureID ID ); 00063 virtual bool Load( RageTextureID ID ); 00064 00065 void UnloadTexture(); 00066 RageTexture* GetTexture() { return m_pTexture; }; 00067 00068 virtual void EnableAnimation( bool bEnable ); 00069 00070 virtual int GetNumStates() const; 00071 virtual void SetState( int iNewState ); 00072 virtual float GetAnimationLengthSeconds() const; 00073 virtual void SetSecondsIntoAnimation( float fSeconds ); 00074 00075 CString GetTexturePath() const; 00076 00077 void SetCustomTextureRect( const RectF &new_texcoord_frect ); 00078 void SetCustomTextureCoords( float fTexCoords[8] ); 00079 void SetCustomSourceRect( const RectF &rectSourceCoords ); // in source pixel space 00080 void SetCustomImageRect( RectF rectImageCoords ); // in image pixel space 00081 void SetCustomImageCoords( float fImageCoords[8] ); 00082 const RectF *GetCurrentTextureCoordRect() const; 00083 void StopUsingCustomCoords(); 00084 void GetActiveTextureCoords(float fTexCoordsOut[8]) const; 00085 void StretchTexCoords( float fX, float fY ); 00086 void SetPosition( float f ); 00087 void SetLooping( bool b ); 00088 void SetPlaybackRate( float f ); 00089 00090 00091 void SetTexCoordVelocity(float fVelX, float fVelY) { m_fTexCoordVelocityX = fVelX; m_fTexCoordVelocityY = fVelY; } 00092 // Scale the Sprite maintaining the aspect ratio so that it fits 00093 // within (fWidth,fHeight) and is clipped to (fWidth,fHeight). 00094 void ScaleToClipped( float fWidth, float fHeight ); 00095 static bool IsDiagonalBanner( int iWidth, int iHeight ); 00096 00097 // 00098 // Commands 00099 // 00100 virtual void PushSelf( lua_State *L ); 00101 00102 protected: 00103 virtual bool LoadFromTexture( RageTextureID ID ); 00104 virtual bool LoadFromSpriteFile( RageTextureID ID ); 00105 00106 void DrawTexture( const TweenState *state ); 00107 00108 CString m_sSpritePath; 00109 RageTexture* m_pTexture; 00110 bool m_bDrawIfTextureNull; 00111 00112 struct State 00113 { 00114 int iFrameIndex; 00115 float fDelay; // "seconds to show" 00116 }; 00117 vector<State> m_States; 00118 int m_iCurState; 00119 float m_fSecsIntoState; // number of seconds that have elapsed since we switched to this frame 00120 00121 bool m_bUsingCustomTexCoords; 00122 bool m_bSkipNextUpdate; 00123 float m_CustomTexCoords[8]; // (x,y) * 4: top left, bottom left, bottom right, top right 00124 00125 // Remembered clipped dimensions are applied on Load(). 00126 // -1 means no remembered dimensions; 00127 float m_fRememberedClipWidth, m_fRememberedClipHeight; 00128 00129 float m_fTexCoordVelocityX; 00130 float m_fTexCoordVelocityY; 00131 }; 00132 00133 00134 #endif 00135 00136 /* 00137 * (c) 2001-2004 Chris Danford 00138 * All rights reserved. 00139 * 00140 * Permission is hereby granted, free of charge, to any person obtaining a 00141 * copy of this software and associated documentation files (the 00142 * "Software"), to deal in the Software without restriction, including 00143 * without limitation the rights to use, copy, modify, merge, publish, 00144 * distribute, and/or sell copies of the Software, and to permit persons to 00145 * whom the Software is furnished to do so, provided that the above 00146 * copyright notice(s) and this permission notice appear in all copies of 00147 * the Software and that both the above copyright notice(s) and this 00148 * permission notice appear in supporting documentation. 00149 * 00150 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 00151 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 00152 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF 00153 * THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS 00154 * INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT 00155 * OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS 00156 * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR 00157 * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 00158 * PERFORMANCE OF THIS SOFTWARE. 00159 */

Generated on Thu Jan 27 20:57:33 2005 for StepMania by doxygen 1.3.7