Etterna 0.75.1
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 bool UsingCustomTexCoords() const { return m_bUsingCustomTexCoords; }
105 bool UsingCustomPosCoords() const { return m_bUsingCustomPosCoords; }
106 void EnableCustomTexCoords() { m_bUsingCustomTexCoords = true; }
107 void EnableCustomPosCoords() { m_bUsingCustomPosCoords = true; }
108
109 // Commands
110 void PushSelf(lua_State* L) override;
111
112 void SetAllStateDelays(float fDelay);
113
114 bool m_DecodeMovie;
115
116 bool m_use_effect_clock_for_texcoords;
117
118 protected:
119 void LoadFromTexture(const RageTextureID& ID);
120
121 private:
122 void LoadStatesFromTexture();
123
124 void DrawTexture(const TweenState* state);
125
126 RageTexture* m_pTexture;
127
128 std::vector<State> m_States;
129 int m_iCurState;
132 float m_fSecsIntoState;
133 float m_animation_length_seconds;
134
135 EffectMode m_EffectMode;
136 bool m_bUsingCustomTexCoords;
137 bool m_bUsingCustomPosCoords;
138 bool m_bSkipNextUpdate;
145 float m_CustomTexCoords[8];
155 float m_CustomPosCoords[8];
156
157 // Remembered clipped dimensions are applied on Load().
158 // -1 means no remembered dimensions;
159 float m_fRememberedClipWidth, m_fRememberedClipHeight;
160
161 float m_fTexCoordVelocityX;
162 float m_fTexCoordVelocityY;
163};
164
165#endif
Base class for all objects that appear on the screen.
Definition Actor.h:78
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