sprite_description.h

Go to the documentation of this file.
00001 /*
00002 **  ClanLib SDK
00003 **  Copyright (c) 1997-2011 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 */
00028 
00031 
00032 #pragma once
00033 
00034 #include "../api_display.h"
00035 #include "../../Core/Text/string_types.h"
00036 #include "../Render/graphic_context.h"
00037 #include "../Render/texture.h"
00038 #include "../Image/pixel_buffer.h"
00039 #include <vector>
00040 
00041 class CL_SpriteDescription_Impl;
00042 class CL_ResourceManager;
00043 
00047 class CL_SpriteDescriptionFrame
00048 {
00049 public:
00050         enum FrameType
00051         {
00052                 type_pixelbuffer,
00053                 type_texture
00054         };
00055 
00056 public:
00057 
00062         CL_SpriteDescriptionFrame(CL_PixelBuffer pixelbuffer, CL_Rect rect) : pixelbuffer(pixelbuffer), rect(rect), type(type_pixelbuffer), delay(1.0) { }
00063 
00068         CL_SpriteDescriptionFrame(CL_Texture texture, CL_Rect rect) : texture(texture), rect(rect), type(type_texture), delay(1.0) { }
00069 
00070         CL_PixelBuffer pixelbuffer;
00071         CL_Texture texture;
00072         CL_Rect rect;
00073         FrameType type;
00074         double delay;
00075 };
00076 
00085 class CL_API_DISPLAY CL_SpriteDescription
00086 {
00089 public:
00094         CL_SpriteDescription();
00095 
00101         CL_SpriteDescription(CL_GraphicContext &gc, const CL_StringRef &resource_id, CL_ResourceManager *resources, const CL_ImageImportDescription &import_desc = CL_ImageImportDescription ());
00102 
00106         CL_SpriteDescription(const CL_SpriteDescription &copy);
00107 
00108         ~CL_SpriteDescription();
00109 
00113 public:
00115         const std::vector<CL_SpriteDescriptionFrame> &get_frames() const;
00116 
00120 public:
00122         CL_SpriteDescription &operator =(const CL_SpriteDescription &copy);
00123 
00129         void add_frame(const CL_PixelBuffer &pixelbuffer);
00130 
00134         void add_frame(const CL_Texture &texture);
00135 
00139         void add_frame(const CL_StringRef &fullname, const CL_ImageImportDescription &import_desc = CL_ImageImportDescription ());
00140 
00145         void add_frame(CL_IODevice &file, const CL_String &image_type, const CL_ImageImportDescription &import_desc = CL_ImageImportDescription ());
00146 
00151         void add_frame(const CL_StringRef &filename, CL_VirtualDirectory &dir, const CL_ImageImportDescription &import_desc = CL_ImageImportDescription ());
00152 
00158         void add_frames(const CL_Texture &texture, CL_Rect *frames, int num_frames);
00159 
00161 
00169         void add_gridclipped_frames(
00170                 const CL_PixelBuffer &pixelbuffer,
00171                 int xpos, int ypos,
00172                 int width, int height,
00173                 int xarray = 1, int yarray = 1,
00174                 int array_skipframes = 0,
00175                 int xspacing = 0, int yspacing = 0);
00176 
00177         void add_gridclipped_frames(
00178                 const CL_Texture &texture,
00179                 int xpos, int ypos,
00180                 int width, int height,
00181                 int xarray = 1, int yarray = 1,
00182                 int array_skipframes = 0,
00183                 int xspacing = 0, int yspacing = 0);
00184 
00186 
00195         void add_alphaclipped_frames(
00196                 const CL_PixelBuffer &pixelbuffer,
00197                 int xpos = 0, int ypos = 0,
00198                 double trans_limit = 0.05f);
00199 
00200         void add_alphaclipped_frames(
00201                 const CL_Texture &texture,
00202                 int xpos = 0, int ypos = 0,
00203                 double trans_limit = 0.05f);
00204 
00206 
00214         void add_alphaclipped_frames_free(
00215                 const CL_PixelBuffer &pixelbuffer,
00216                 int xpos = 0, int ypos = 0,
00217                 double trans_limit = 0.05f);
00218 
00219         void add_alphaclipped_frames_free(
00220                 const CL_Texture &texture,
00221                 int xpos = 0, int ypos = 0,
00222                 double trans_limit = 0.05f);
00223 
00225         void set_frame_delay(int frame, double delay);
00226 
00230 private:
00232         CL_SharedPtr<CL_SpriteDescription_Impl> impl;
00234 };
00235