forked from EasyRPG/Player
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsprite.h
303 lines (244 loc) · 6.07 KB
/
sprite.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
/*
* This file is part of EasyRPG Player.
*
* EasyRPG Player is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* EasyRPG Player is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with EasyRPG Player. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef EP_SPRITE_H
#define EP_SPRITE_H
// Headers
#include "color.h"
#include "drawable.h"
#include "memory_management.h"
#include "rect.h"
#include "tone.h"
/**
* Sprite class.
*/
class Sprite : public Drawable {
public:
explicit Sprite(Drawable::Flags flags = Drawable::Flags::Default);
void Draw(Bitmap& dst) override;
virtual int GetWidth() const;
virtual int GetHeight() const;
BitmapRef& GetBitmap();
BitmapRef const& GetBitmap() const;
void SetBitmap(BitmapRef const& bitmap);
Rect const& GetSrcRect() const;
void SetSrcRect(Rect const& src_rect);
void SetSpriteRect(Rect const& sprite_rect);
int GetX() const;
void SetX(int x);
int GetY() const;
void SetY(int y);
int GetOx() const;
void SetOx(int ox);
int GetOy() const;
void SetOy(int oy);
double GetZoomX() const;
void SetZoomX(double zoom_x);
double GetZoomY() const;
void SetZoomY(double zoom_y);
/** @return rotation angle in radians */
double GetAngle() const;
/**
* Set rotation angle.
*
* @param angle the angle in radians
*/
void SetAngle(double angle);
bool GetFlipX() const;
void SetFlipX(bool flipx);
bool GetFlipY() const;
void SetFlipY(bool flipy);
int GetBushDepth() const;
void SetBushDepth(int bush_depth);
int GetOpacity(int which = 0) const;
void SetOpacity(int top_opacity, int bottom_opacity = -1);
int GetBlendType() const;
void SetBlendType(int blend_type);
Color GetBlendColor() const;
void SetBlendColor(Color color);
Tone GetTone() const;
void SetTone(Tone tone);
/** @return wave depth in pixels */
int GetWaverDepth() const;
/** Set wave effect depth
*
* @param depth in pixels
*/
void SetWaverDepth(int depth);
/** @return waver phase in radians */
double GetWaverPhase() const;
/**
* Set wave effect phase.
*
* @param angle the phase in radians
*/
void SetWaverPhase(double phase);
/**
* Set the flash effect color
*/
void SetFlashEffect(const Color &color);
private:
BitmapRef bitmap;
Rect src_rect;
int x = 0;
int y = 0;
int ox = 0;
int oy = 0;
Rect src_rect_effect;
int opacity_top_effect = 255;
int opacity_bottom_effect = 128;
int bush_effect = 0;
Tone tone_effect;
double zoom_x_effect = 1.0;
double zoom_y_effect = 1.0;
double angle_effect = 0.0;
int blend_type_effect = 0;
Color blend_color_effect;
int waver_effect_depth = 0;
double waver_effect_phase = 0.0;
Color flash_effect;
BitmapRef bitmap_effects;
Rect bitmap_effects_src_rect;
Tone current_tone;
Color current_flash;
bool flipx_effect = false;
bool flipy_effect = false;
bool current_flip_x = false;
bool current_flip_y = false;
bool bitmap_changed = true;
void BlitScreen(Bitmap& dst);
void BlitScreenIntern(Bitmap& dst, Bitmap const& draw_bitmap,
Rect const& src_rect) const;
BitmapRef Refresh(Rect& rect);
};
inline int Sprite::GetWidth() const {
return src_rect.width;
}
inline int Sprite::GetHeight() const {
return src_rect.height;
}
inline BitmapRef& Sprite::GetBitmap() {
return bitmap;
}
inline BitmapRef const& Sprite::GetBitmap() const {
return bitmap;
}
inline Rect const& Sprite::GetSrcRect() const {
return src_rect;
}
inline void Sprite::SetSrcRect(Rect const& nsrc_rect) {
src_rect = nsrc_rect;
}
inline int Sprite::GetX() const {
return x;
}
inline void Sprite::SetX(int nx) {
x = nx;
}
inline int Sprite::GetY() const {
return y;
}
inline void Sprite::SetY(int ny) {
y = ny;
}
inline int Sprite::GetOx() const {
return ox;
}
inline void Sprite::SetOx(int nox) {
ox = nox;
}
inline int Sprite::GetOy() const {
return oy;
}
inline void Sprite::SetOy(int noy) {
oy = noy;
}
inline double Sprite::GetZoomX() const {
return zoom_x_effect;
}
inline double Sprite::GetZoomY() const {
return zoom_y_effect;
}
inline void Sprite::SetZoomX(double zoom_x) {
zoom_x_effect = zoom_x;
}
inline void Sprite::SetZoomY(double zoom_y) {
zoom_y_effect = zoom_y;
}
inline double Sprite::GetAngle() const {
return angle_effect;
}
inline void Sprite::SetAngle(double angle) {
angle_effect = angle;
}
inline bool Sprite::GetFlipX() const {
return flipx_effect;
}
inline bool Sprite::GetFlipY() const {
return flipy_effect;
}
inline int Sprite::GetBushDepth() const {
return bush_effect;
}
inline int Sprite::GetOpacity(int which) const {
return which > 0 ? opacity_bottom_effect : opacity_top_effect;
}
inline int Sprite::GetBlendType() const {
return blend_type_effect;
}
inline void Sprite::SetBlendType(int blend_type) {
blend_type_effect = blend_type;
}
inline Color Sprite::GetBlendColor() const {
return blend_color_effect;
}
inline void Sprite::SetBlendColor(Color blend_color) {
blend_color_effect = blend_color;
}
inline Tone Sprite::GetTone() const {
return tone_effect;
}
inline void Sprite::SetTone(Tone tone) {
tone_effect = tone;
}
inline int Sprite::GetWaverDepth() const {
return waver_effect_depth;
}
inline double Sprite::GetWaverPhase() const {
return waver_effect_phase;
}
inline void Sprite::SetWaverDepth(int depth) {
waver_effect_depth = depth;
}
inline void Sprite::SetWaverPhase(double phase) {
waver_effect_phase = phase;
}
inline void Sprite::SetSpriteRect(Rect const& nsprite_rect) {
src_rect_effect = nsprite_rect;
}
inline void Sprite::SetFlipX(bool flipx) {
flipx_effect = flipx;
}
inline void Sprite::SetFlipY(bool flipy) {
flipy_effect = flipy;
}
inline void Sprite::SetBushDepth(int bush_depth) {
bush_effect = bush_depth;
}
inline void Sprite::SetFlashEffect(const Color &color) {
flash_effect = color;
}
#endif