ClanLib  2.3.7
sprite.h
Go to the documentation of this file.
1 /*
2 ** ClanLib SDK
3 ** Copyright (c) 1997-2011 The ClanLib Team
4 **
5 ** This software is provided 'as-is', without any express or implied
6 ** warranty. In no event will the authors be held liable for any damages
7 ** arising from the use of this software.
8 **
9 ** Permission is granted to anyone to use this software for any purpose,
10 ** including commercial applications, and to alter it and redistribute it
11 ** freely, subject to the following restrictions:
12 **
13 ** 1. The origin of this software must not be misrepresented; you must not
14 ** claim that you wrote the original software. If you use this software
15 ** in a product, an acknowledgment in the product documentation would be
16 ** appreciated but is not required.
17 ** 2. Altered source versions must be plainly marked as such, and must not be
18 ** misrepresented as being the original software.
19 ** 3. This notice may not be removed or altered from any source distribution.
20 **
21 ** Note: Some of the libraries ClanLib may link to may have additional
22 ** requirements or restrictions.
23 **
24 ** File Author(s):
25 **
26 ** Kenneth Gangstoe
27 ** Mark Page
28 */
29 
32 
33 #pragma once
34 
35 #include "../api_display.h"
36 #include "../../Core/Text/string_types.h"
37 #include "../../Core/System/sharedptr.h"
38 #include "../../Core/Math/origin.h"
39 #include "../../Core/Signals/signal_v0.h"
40 #include "../../Core/IOData/virtual_directory.h"
41 #include "../../Core/Resources/resource_data_session.h"
42 #include "../Render/graphic_context.h"
43 #include "../Render/blend_mode.h"
44 #include "../Image/image_import_description.h"
45 #include "../Collision/collision_outline.h"
46 #include "color.h"
47 
48 class CL_ResourceManager;
50 class CL_Sprite_Impl;
52 
57 {
60 public:
62  {
63  show_blank, show_last_frame, show_first_frame
64  };
66 
69 public:
71  CL_Sprite();
72 
78 
85 
91  CL_Sprite(CL_GraphicContext &gc, const CL_StringRef &resource_id, CL_ResourceManager *resources, const CL_ImageImportDescription &import_desc = CL_ImageImportDescription ());
92 
98  CL_Sprite(CL_GraphicContext &gc, CL_IODevice &file, const CL_String &image_type, const CL_ImageImportDescription &import_desc = CL_ImageImportDescription ());
99 
104  CL_Sprite(CL_GraphicContext &gc, const CL_SpriteDescription &description);
105 
106  virtual ~CL_Sprite();
108 
111 public:
113  bool is_null() const { return !impl; }
114 
116  void throw_if_null() const;
117 
119  CL_Angle get_angle() const;
120 
122  CL_Angle get_base_angle() const;
123 
125 
126  void get_scale(float &x, float &y) const;
127 
129 
130  float get_alpha() const;
131 
133 
134  CL_Colorf get_color() const;
135 
137  bool get_linear_filter() const;
138 
140  void get_alignment(CL_Origin &origin, int &x, int &y) const;
141 
143  void get_rotation_hotspot(CL_Origin &origin, int &x, int &y) const;
144 
146  int get_current_frame() const;
147 
149  int get_frame_count() const;
150 
155  int get_frame_delay(int frame) const;
156 
158  CL_Point get_frame_offset(int frame) const;
159 
161  CL_Size get_frame_size(int frame) const;
162 
164  int get_width() const;
165 
167  int get_height() const;
168 
170  CL_Size get_size() const;
171 
173  int get_id() const;
174 
176  bool is_play_loop() const;
177 
179  bool is_play_backward() const;
180 
182  bool is_play_pingpong() const;
183 
185 
186  ShowOnFinish get_show_on_finish() const;
187 
189 
191  bool is_finished() const;
192 
194  bool is_looping() const;
196 
199 public:
201  bool operator==(const CL_Sprite &other) const
202  {
203  return impl==other.impl;
204  }
205 
207  bool operator!=(const CL_Sprite &other) const
208  {
209  return impl!=other.impl;
210  }
211 
213  bool operator<(const CL_Sprite &other) const
214  {
215  return impl < other.impl;
216  }
218 
221 public:
223  CL_Sprite &operator =(const CL_Sprite &copy);
224 
226 
227  void set_image_data(const CL_Sprite &image_source);
228 
230 
231  void clone(const CL_Sprite &source);
232 
239  void draw(
240  CL_GraphicContext &gc,
241  float x,
242  float y);
243 
244  void draw(
245  CL_GraphicContext &gc,
246  int x,
247  int y);
248 
249  void draw(
250  CL_GraphicContext &gc,
251  const CL_Rectf &src,
252  const CL_Rectf &dest);
253 
254  void draw(
255  CL_GraphicContext &gc,
256  const CL_Rectf &dest);
257 
262  int update(int time_elapsed_ms = -1);
263 
265  void set_angle(CL_Angle angle);
266 
268  void set_angle_pitch(CL_Angle angle);
269 
271  void set_angle_yaw(CL_Angle angle);
272 
274  void rotate(CL_Angle angle);
275 
277  void rotate_pitch(CL_Angle angle);
278 
280  void rotate_yaw(CL_Angle angle);
281 
283  void set_base_angle(CL_Angle angle);
284 
286 
287  void set_scale(float x, float y);
288 
290 
291  void set_alpha(float alpha);
292 
294 
295  void set_color(const CL_Colorf &color);
296 
300  void set_color(const CL_Color& c) {CL_Colorf color; color.r = c.get_red() / 255.0f; color.g = c.get_green() / 255.0f; color.b = c.get_blue() / 255.0f; color.a = c.get_alpha() / 255.0f; set_color(color);}
301 
303  void set_linear_filter(bool linear_filter = true);
304 
306  void set_alignment(CL_Origin origin, int x = 0, int y = 0);
307 
309  void set_rotation_hotspot(CL_Origin origin, int x = 0, int y = 0);
310 
313  void set_frame(unsigned int frame);
314 
318  void set_delay(int delay_ms);
319 
324  void set_frame_delay(int frame, int delay_ms);
325 
327  void set_frame_offset(int frame, CL_Point offset);
328 
330  void set_id(int id);
331 
333 
335  void finish();
336 
338  void restart();
339 
341  void set_play_loop(bool loop = true);
342 
344  void set_play_pingpong(bool pingpong = true);
345 
347  void set_play_backward(bool backward = true);
348 
350  void set_show_on_finish(CL_Sprite::ShowOnFinish show_on_finish);
352 
355 public:
359  CL_Signal_v0 &sig_animation_finished();
361 
364 private:
365  CL_SharedPtr<CL_Sprite_Impl> impl;
367 };
368