sprite.h

Go to the documentation of this file.
00001 /*
00002 **  ClanLib SDK
00003 **  Copyright (c) 1997-2009 The ClanLib Team
00004 **
00005 **  This software is provided 'as-is', without any express or implied
00006 **  warranty.  In no event will the authors be held liable for any damages
00007 **  arising from the use of this software.
00008 **
00009 **  Permission is granted to anyone to use this software for any purpose,
00010 **  including commercial applications, and to alter it and redistribute it
00011 **  freely, subject to the following restrictions:
00012 **
00013 **  1. The origin of this software must not be misrepresented; you must not
00014 **     claim that you wrote the original software. If you use this software
00015 **     in a product, an acknowledgment in the product documentation would be
00016 **     appreciated but is not required.
00017 **  2. Altered source versions must be plainly marked as such, and must not be
00018 **     misrepresented as being the original software.
00019 **  3. This notice may not be removed or altered from any source distribution.
00020 **
00021 **  Note: Some of the libraries ClanLib may link to may have additional
00022 **  requirements or restrictions.
00023 **
00024 **  File Author(s):
00025 **
00026 **    Kenneth Gangstoe
00027 **    Mark Page
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 
00045 #include "color.h"
00046 
00047 class CL_ResourceManager;
00048 class CL_SpriteDescription;
00049 class CL_Sprite_Impl;
00050 
00054 class CL_API_DISPLAY CL_Sprite
00055 {
00058 public:
00059         enum ShowOnFinish
00060         {
00061                 show_blank, show_last_frame, show_first_frame
00062         };
00064 
00067 public:
00074         CL_Sprite();
00075 
00079         CL_Sprite(CL_GraphicContext &gc);
00080 
00085         CL_Sprite(CL_GraphicContext &gc, const CL_StringRef &fullname);
00086 
00092         CL_Sprite(CL_GraphicContext &gc, const CL_StringRef &filename, CL_VirtualDirectory &dir);
00093 
00099         CL_Sprite(CL_GraphicContext &gc, const CL_StringRef &resource_id, CL_ResourceManager *resources);
00100 
00106         CL_Sprite(CL_GraphicContext &gc, CL_IODevice &file, const CL_String &image_type);
00107 
00112         CL_Sprite(CL_GraphicContext &gc, const CL_SpriteDescription &description);
00113 
00117         CL_Sprite(const CL_Sprite &copy);
00118         virtual ~CL_Sprite();
00120 
00123 public:
00125         bool is_null() const;
00126 
00128         CL_Angle get_angle() const;
00129 
00131         CL_Angle get_base_angle() const;
00132 
00134 
00135         void get_scale(float &x, float &y) const;
00136 
00138 
00139         float get_alpha() const;
00140 
00142 
00143         CL_Colorf get_color() const;
00144 
00146         bool get_linear_filter() const;
00147 
00149         void get_alignment(CL_Origin &origin, int &x, int &y) const;
00150 
00152         void get_rotation_hotspot(CL_Origin &origin, int &x, int &y) const;
00153 
00155         int get_current_frame() const;
00156 
00158         int get_frame_count() const;
00159 
00164         int get_frame_delay(int frame) const;
00165 
00167         CL_Point get_frame_offset(int frame) const;
00168 
00170         CL_Size get_frame_size(int frame) const;
00171 
00173         int get_width() const;
00174 
00176         int get_height() const;
00177 
00179         CL_Size get_size() const;
00180 
00182         int get_id() const;
00183 
00185         bool is_play_loop() const;
00186 
00188         bool is_play_backward() const;
00189 
00191         bool is_play_pingpong() const;
00192 
00194 
00195         ShowOnFinish get_show_on_finish() const;
00196 
00198 
00200         bool is_finished() const;
00201 
00203         bool is_looping() const;
00204 
00206 
00209 public:
00211         bool operator==(const CL_Sprite &other) const
00212         {
00213                 return impl==other.impl;
00214         }
00215 
00217         bool operator!=(const CL_Sprite &other) const
00218         {
00219                 return impl!=other.impl;
00220         }
00221 
00223         bool operator<(const CL_Sprite &other) const
00224         {
00225                 return impl < other.impl;
00226         }
00228         
00231 public:
00233         CL_Sprite &operator =(const CL_Sprite &copy);
00234 
00236 
00237         void set_image_data(const CL_Sprite &image_source);
00238 
00240 
00241         void clone(const CL_Sprite &source);
00242 
00249         void draw(
00250                 CL_GraphicContext &gc,
00251                 float x,
00252                 float y);
00253 
00254         void draw(
00255                 CL_GraphicContext &gc,
00256                 int x,
00257                 int y);
00258 
00259         void draw(
00260                 CL_GraphicContext &gc,
00261                 const CL_Rectf &src,
00262                 const CL_Rectf &dest);
00263 
00264         void draw(
00265                 CL_GraphicContext &gc,
00266                 const CL_Rectf &dest);
00267 
00272         int update(int time_elapsed_ms = -1);
00273 
00275         void set_angle(CL_Angle angle);
00276 
00278         void set_angle_pitch(CL_Angle angle);
00279 
00281         void set_angle_yaw(CL_Angle angle);
00282 
00284         void rotate(CL_Angle angle);
00285 
00287         void rotate_pitch(CL_Angle angle);
00288 
00290         void rotate_yaw(CL_Angle angle);
00291 
00293         void set_base_angle(CL_Angle angle);
00294 
00296 
00297         void set_scale(float x, float y);
00298 
00300 
00301         void set_alpha(float alpha);
00302 
00304 
00305         void set_color(const CL_Colorf &color);
00306 
00310         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);}
00311 
00313         void set_linear_filter(bool linear_filter = true);
00314 
00316         void set_alignment(CL_Origin origin, int x = 0, int y = 0);
00317 
00319         void set_rotation_hotspot(CL_Origin origin, int x = 0, int y = 0);
00320 
00323         void set_frame(unsigned int frame);
00324 
00328         void set_delay(int delay_ms);
00329 
00334         void set_frame_delay(int frame, int delay_ms);
00335 
00337         void set_frame_offset(int frame, CL_Point offset);
00338 
00340         void set_id(int id);
00341 
00343 
00345         void finish();
00346 
00348         void restart();
00349 
00351         void set_play_loop(bool loop = true);
00352 
00354         void set_play_pingpong(bool pingpong = true);
00355 
00357         void set_play_backward(bool backward = true);
00358 
00360         void set_show_on_finish(CL_Sprite::ShowOnFinish show_on_finish);
00362 
00365 public:
00366 
00370         CL_Signal_v0 &sig_animation_finished();
00372 
00375 private:
00376         CL_SharedPtr<CL_Sprite_Impl> impl;
00377         CL_ResourceDataSession resource_data_session;
00379 };
00380 

Generated on Thu Dec 3 02:39:32 2009 for ClanLib by  doxygen 1.4.6