Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00032
00033 #pragma once
00034
00035 #include "../api_display.h"
00036 #include "../../Core/Text/string_types.h"
00037 #include "../../Core/System/sharedptr.h"
00038 #include "../../Core/Math/origin.h"
00039 #include "../../Core/Signals/signal_v0.h"
00040 #include "../../Core/IOData/virtual_directory.h"
00041 #include "../../Core/Resources/resource_data_session.h"
00042 #include "../Render/graphic_context.h"
00043 #include "../Render/blend_mode.h"
00044 #include "../Image/image_import_description.h"
00045 #include "../Collision/collision_outline.h"
00046 #include "color.h"
00047
00048 class CL_ResourceManager;
00049 class CL_SpriteDescription;
00050 class CL_Sprite_Impl;
00051 class CL_CollisionOutline;
00052
00056 class CL_API_DISPLAY CL_Sprite
00057 {
00060 public:
00061 enum ShowOnFinish
00062 {
00063 show_blank, show_last_frame, show_first_frame
00064 };
00066
00069 public:
00071 CL_Sprite();
00072
00077 CL_Sprite(CL_GraphicContext &gc, const CL_StringRef &fullname, const CL_ImageImportDescription &import_desc = CL_ImageImportDescription ());
00078
00084 CL_Sprite(CL_GraphicContext &gc, const CL_StringRef &filename, CL_VirtualDirectory &dir, const CL_ImageImportDescription &import_desc = CL_ImageImportDescription ());
00085
00091 CL_Sprite(CL_GraphicContext &gc, const CL_StringRef &resource_id, CL_ResourceManager *resources, const CL_ImageImportDescription &import_desc = CL_ImageImportDescription ());
00092
00098 CL_Sprite(CL_GraphicContext &gc, CL_IODevice &file, const CL_String &image_type, const CL_ImageImportDescription &import_desc = CL_ImageImportDescription ());
00099
00104 CL_Sprite(CL_GraphicContext &gc, const CL_SpriteDescription &description);
00105
00106 virtual ~CL_Sprite();
00108
00111 public:
00113 bool is_null() const { return !impl; }
00114
00116 void throw_if_null() const;
00117
00119 CL_Angle get_angle() const;
00120
00122 CL_Angle get_base_angle() const;
00123
00125
00126 void get_scale(float &x, float &y) const;
00127
00129
00130 float get_alpha() const;
00131
00133
00134 CL_Colorf get_color() const;
00135
00137 bool get_linear_filter() const;
00138
00140 void get_alignment(CL_Origin &origin, int &x, int &y) const;
00141
00143 void get_rotation_hotspot(CL_Origin &origin, int &x, int &y) const;
00144
00146 int get_current_frame() const;
00147
00149 int get_frame_count() const;
00150
00155 int get_frame_delay(int frame) const;
00156
00158 CL_Point get_frame_offset(int frame) const;
00159
00161 CL_Size get_frame_size(int frame) const;
00162
00164 int get_width() const;
00165
00167 int get_height() const;
00168
00170 CL_Size get_size() const;
00171
00173 int get_id() const;
00174
00176 bool is_play_loop() const;
00177
00179 bool is_play_backward() const;
00180
00182 bool is_play_pingpong() const;
00183
00185
00186 ShowOnFinish get_show_on_finish() const;
00187
00189
00191 bool is_finished() const;
00192
00194 bool is_looping() const;
00196
00199 public:
00201 bool operator==(const CL_Sprite &other) const
00202 {
00203 return impl==other.impl;
00204 }
00205
00207 bool operator!=(const CL_Sprite &other) const
00208 {
00209 return impl!=other.impl;
00210 }
00211
00213 bool operator<(const CL_Sprite &other) const
00214 {
00215 return impl < other.impl;
00216 }
00218
00221 public:
00223 CL_Sprite &operator =(const CL_Sprite ©);
00224
00226
00227 void set_image_data(const CL_Sprite &image_source);
00228
00230
00231 void clone(const CL_Sprite &source);
00232
00239 void draw(
00240 CL_GraphicContext &gc,
00241 float x,
00242 float y);
00243
00244 void draw(
00245 CL_GraphicContext &gc,
00246 int x,
00247 int y);
00248
00249 void draw(
00250 CL_GraphicContext &gc,
00251 const CL_Rectf &src,
00252 const CL_Rectf &dest);
00253
00254 void draw(
00255 CL_GraphicContext &gc,
00256 const CL_Rectf &dest);
00257
00262 int update(int time_elapsed_ms = -1);
00263
00265 void set_angle(CL_Angle angle);
00266
00268 void set_angle_pitch(CL_Angle angle);
00269
00271 void set_angle_yaw(CL_Angle angle);
00272
00274 void rotate(CL_Angle angle);
00275
00277 void rotate_pitch(CL_Angle angle);
00278
00280 void rotate_yaw(CL_Angle angle);
00281
00283 void set_base_angle(CL_Angle angle);
00284
00286
00287 void set_scale(float x, float y);
00288
00290
00291 void set_alpha(float alpha);
00292
00294
00295 void set_color(const CL_Colorf &color);
00296
00300 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);}
00301
00303 void set_linear_filter(bool linear_filter = true);
00304
00306 void set_alignment(CL_Origin origin, int x = 0, int y = 0);
00307
00309 void set_rotation_hotspot(CL_Origin origin, int x = 0, int y = 0);
00310
00313 void set_frame(unsigned int frame);
00314
00318 void set_delay(int delay_ms);
00319
00324 void set_frame_delay(int frame, int delay_ms);
00325
00327 void set_frame_offset(int frame, CL_Point offset);
00328
00330 void set_id(int id);
00331
00333
00335 void finish();
00336
00338 void restart();
00339
00341 void set_play_loop(bool loop = true);
00342
00344 void set_play_pingpong(bool pingpong = true);
00345
00347 void set_play_backward(bool backward = true);
00348
00350 void set_show_on_finish(CL_Sprite::ShowOnFinish show_on_finish);
00352
00355 public:
00359 CL_Signal_v0 &sig_animation_finished();
00361
00364 private:
00365 CL_SharedPtr<CL_Sprite_Impl> impl;
00367 };
00368