Etterna 0.74.4
Loading...
Searching...
No Matches
Sprite.h
1#ifndef SPRITE_H
2#define SPRITE_H
3
4#include "Actor.h"
5#include "RageUtil/Graphics/RageTextureID.h"
6
7void
8TexCoordArrayFromRect(float fImageCoords[8], const RectF& rect);
9
10class RageTexture;
12class Sprite : public Actor
13{
14 public:
16 struct State
17 {
18 RectF rect;
20 float fDelay;
21 };
22
23 Sprite();
24 Sprite(const Sprite& cpy);
25 ~Sprite() override;
26
27 // See explanation in source.
28 static auto NewBlankSprite() -> Sprite*;
29
30 void InitState() override;
31
32 void LoadFromNode(const XNode* pNode) override;
33 [[nodiscard]] auto Copy() const -> Sprite* override;
34
35 [[nodiscard]] auto EarlyAbortDraw() const -> bool override;
36 void DrawPrimitives() override;
37 void Update(float fDeltaTime) override;
38
39 void
40 UpdateAnimationState(); // take m_fSecondsIntoState, and move to a new state
41
42 // Adjust texture properties for song backgrounds.
43 static auto SongBGTexture(RageTextureID ID) -> RageTextureID;
44
45 // Adjust texture properties for song banners.
46 static auto SongBannerTexture(RageTextureID ID) -> RageTextureID;
47
48 virtual void Load(const RageTextureID& ID);
49 void SetTexture(RageTexture* pTexture);
50
51 void UnloadTexture();
52 [[nodiscard]] auto GetTexture() const -> RageTexture*
53 {
54 return m_pTexture;
55 };
56
57 void EnableAnimation(bool bEnable) override;
58
59 [[nodiscard]] auto GetNumStates() const -> int override;
60 void SetState(int iNewState) override;
61 [[nodiscard]] auto GetState() const -> int { return m_iCurState; }
62
63 [[nodiscard]] auto GetAnimationLengthSeconds() const -> float override
64 {
65 return m_animation_length_seconds;
66 }
67 virtual void RecalcAnimationLengthSeconds();
68 void SetSecondsIntoAnimation(float fSeconds) override;
69 void SetStateProperties(const std::vector<State>& new_states)
70 {
71 m_States = new_states;
72 RecalcAnimationLengthSeconds();
73 SetState(0);
74 }
75
76 [[nodiscard]] auto GetTexturePath() const -> std::string;
77
78 void SetCustomTextureRect(const RectF& new_texcoord_frect);
79 void SetCustomTextureCoords(float fTexCoords[8]);
80 void SetCustomImageRect(RectF rectImageCoords); // in image pixel space
81 void SetCustomImageCoords(float fImageCoords[8]);
82 void SetCustomPosCoords(float fPosCoords[8]);
83 [[nodiscard]] auto GetCurrentTextureCoordRect() const -> const RectF*;
84 [[nodiscard]] auto GetTextureCoordRectForState(int iState) const
85 -> const RectF*;
86 void StopUsingCustomCoords();
87 void StopUsingCustomPosCoords();
88 void GetActiveTextureCoords(float fTexCoordsOut[8]) const;
89 void StretchTexCoords(float fX, float fY);
90 void AddImageCoords(float fX, float fY); // in image pixel space
91 void SetEffectMode(EffectMode em) { m_EffectMode = em; }
92
93 void LoadFromCached(const std::string& sDir, const std::string& sPath);
94 void SetTexCoordVelocity(float fVelX, float fVelY);
101 void ScaleToClipped(float fWidth, float fHeight);
102 void CropTo(float fWidth, float fHeight);
103
104 // Commands
105 void PushSelf(lua_State* L) override;
106
107 void SetAllStateDelays(float fDelay);
108
109 bool m_DecodeMovie;
110
111 bool m_use_effect_clock_for_texcoords;
112
113 protected:
114 void LoadFromTexture(const RageTextureID& ID);
115
116 private:
117 void LoadStatesFromTexture();
118
119 void DrawTexture(const TweenState* state);
120
121 RageTexture* m_pTexture;
122
123 std::vector<State> m_States;
124 int m_iCurState;
127 float m_fSecsIntoState;
128 float m_animation_length_seconds;
129
130 EffectMode m_EffectMode;
131 bool m_bUsingCustomTexCoords;
132 bool m_bUsingCustomPosCoords;
133 bool m_bSkipNextUpdate;
140 float m_CustomTexCoords[8];
150 float m_CustomPosCoords[8];
151
152 // Remembered clipped dimensions are applied on Load().
153 // -1 means no remembered dimensions;
154 float m_fRememberedClipWidth, m_fRememberedClipHeight;
155
156 float m_fTexCoordVelocityX;
157 float m_fTexCoordVelocityY;
158};
159
160#endif
Base class for all objects that appear on the screen.
Definition Actor.h:77
Definition RageTexture.h:14
A bitmap Actor that animates and moves around.
Definition Sprite.h:13
void ScaleToClipped(float fWidth, float fHeight)
Scale the Sprite while maintaining the aspect ratio.
Definition Sprite.cpp:1096
void DrawPrimitives() override
Draw the primitives of the Actor.
Definition Sprite.cpp:692
auto EarlyAbortDraw() const -> bool override
Allow the Actor to be aborted early.
Definition Sprite.cpp:686
Definition XmlFile.h:95
Definition RageTextureID.h:12
The Sprite's present state.
Definition Sprite.h:17
float fDelay
The number of "seconds to show".
Definition Sprite.h:20