image.h Source File - ClanLib SDK
Description: image.h Source File

image.h
1/*
2** ClanLib SDK
3** Copyright (c) 1997-2020 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*/
28
29#pragma once
30
31#include <memory>
32#include "../../Core/Math/origin.h"
33#include "../../Core/Resources/resource.h"
34#include "color.h"
35#include "../Image/image_import_description.h"
36#include "../Render/texture.h"
37
38namespace clan
39{
42
43 class GraphicContext;
44 class FileSystem;
45 class Rect;
46 class Size;
47 class Rectf;
48 class Image_Impl;
49 class Texture2D;
50 class Subtexture;
51 class PixelBuffer;
52 class ResourceManager;
53 class XMLResourceDocument;
54 class Canvas;
55 class Quadf;
56
58 class Image
59 {
60 public:
62 Image();
63
68 Image(Texture2D texture, const Rect &rect);
69
73 Image(Subtexture &sub_texture);
74
80 Image(Canvas &canvas, const PixelBuffer &pixelbuffer, const Rect &rect);
81
87 Image(Canvas &canvas, const std::string &filename, const ImageImportDescription &import_desc = ImageImportDescription());
88
95 Image(Canvas &canvas, const std::string &filename, const FileSystem &fs, const ImageImportDescription &import_desc = ImageImportDescription());
96
97 virtual ~Image();
98
104 static Resource<Image> resource(Canvas &canvas, const std::string &id, const ResourceManager &resources);
105
107 static Image load(Canvas &canvas, const std::string &id, const XMLResourceDocument &doc);
108
110 bool is_null() const { return !impl; }
111 explicit operator bool() const { return bool(impl); }
112
114 void throw_if_null() const;
115
117
118 float get_scale_x() const;
119
121
122 float get_scale_y() const;
123
125
126 float get_alpha() const;
127
129
130 Colorf get_color() const;
131
133 void get_alignment(Origin &origin, float &x, float &y) const;
134
136 Subtexture get_texture() const;
137
139 Sizef get_size() const;
140
142 float get_width() const;
143
145 float get_height() const;
146
148 bool operator==(const Image &other) const
149 {
150 return impl == other.impl;
151 }
152
154 bool operator!=(const Image &other) const
155 {
156 return impl != other.impl;
157 }
158
160 bool operator<(const Image &other) const
161 {
162 return impl < other.impl;
163 }
164
166 Image clone() const;
167
172 void draw(
173 Canvas &canvas,
174 float x,
175 float y) const;
176
182 void draw(
183 Canvas &canvas,
184 const Rectf &src,
185 const Rectf &dest) const;
186
191 void draw(
192 Canvas &canvas,
193 const Rectf &dest) const;
194
200 void draw(
201 Canvas &canvas,
202 const Rectf &src,
203 const Quadf &dest) const;
204
209 void draw(
210 Canvas &canvas,
211 const Quadf &dest) const;
212
214
215 void set_scale(float x, float y);
216
218
219 void set_alpha(float alpha);
220
222
223 void set_color(const Colorf &color);
224
228 void set_color(const Color& c) { 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); }
229
231 void set_alignment(Origin origin, float x = 0, float y = 0);
232
233 void set_wrap_mode(
234 TextureWrapMode wrap_s,
235 TextureWrapMode wrap_t);
236
238 void set_linear_filter(bool linear_filter = true);
239
249 void set_subimage(
250 Canvas &canvas,
251 int x,
252 int y,
253 const PixelBuffer &image,
254 const Rect &src_rect,
255 int level = 0);
256
257 private:
258 std::shared_ptr<Image_Impl> impl;
259 };
260
262}
clan::Canvas
2D Graphics Canvas
Definition canvas.h:72
clan::Color
Color description class.
Definition color.h:46
clan::Colorf
Floating point color description class (for float).
Definition color.h:799
clan::FileSystem
Virtual File System (VFS).
Definition file_system.h:47
clan::ImageImportDescription
Image Import Description Class.
Definition image_import_description.h:48
clan::Image
Image class.
Definition image.h:59
clan::Image::Image
Image(Canvas &canvas, const std::string &filename, const ImageImportDescription &import_desc=ImageImportDescription())
Constructs a Image.
clan::Image::get_alignment
void get_alignment(Origin &origin, float &x, float &y) const
Returns translation hot-spot.
clan::Image::get_scale_y
float get_scale_y() const
Returns y scale.
clan::Image::get_color
Colorf get_color() const
Returns current color.
clan::Image::get_height
float get_height() const
Return the height of the image.
clan::Image::load
static Image load(Canvas &canvas, const std::string &id, const XMLResourceDocument &doc)
Loads a Sprite from a XML resource definition.
clan::Image::draw
void draw(Canvas &canvas, const Rectf &src, const Quadf &dest) const
Draw image on graphic context.
clan::Image::get_alpha
float get_alpha() const
Returns current alpha.
clan::Image::set_linear_filter
void set_linear_filter(bool linear_filter=true)
Set to true if a linear filter should be used for scaling up and down, false if a nearest-point filte...
clan::Image::Image
Image()
Constructs a null instance.
clan::Image::is_null
bool is_null() const
Returns true if this object is invalid.
Definition image.h:110
clan::Image::set_scale
void set_scale(float x, float y)
Set scale for x and y directions individually.
clan::Image::draw
void draw(Canvas &canvas, const Rectf &dest) const
Draw image on graphic context.
clan::Image::set_subimage
void set_subimage(Canvas &canvas, int x, int y, const PixelBuffer &image, const Rect &src_rect, int level=0)
clan::Image::Image
Image(Subtexture &sub_texture)
Constructs an image from a subtexture.
clan::Image::operator!=
bool operator!=(const Image &other) const
Inequality operator.
Definition image.h:154
clan::Image::resource
static Resource< Image > resource(Canvas &canvas, const std::string &id, const ResourceManager &resources)
Retrieves a Sprite resource from the resource manager.
clan::Image::Image
Image(Canvas &canvas, const PixelBuffer &pixelbuffer, const Rect &rect)
Constructs a Image from a pixelbuffer.
clan::Image::get_width
float get_width() const
Return the width of the image.
clan::Image::get_texture
Subtexture get_texture() const
Return the texture of the image.
clan::Image::operator<
bool operator<(const Image &other) const
Less than operator.
Definition image.h:160
clan::Image::clone
Image clone() const
Copies all information from this image to another, excluding the graphics that remain shared.
clan::Image::draw
void draw(Canvas &canvas, const Quadf &dest) const
Draw image on graphic context.
clan::Image::set_wrap_mode
void set_wrap_mode(TextureWrapMode wrap_s, TextureWrapMode wrap_t)
clan::Image::Image
Image(Canvas &canvas, const std::string &filename, const FileSystem &fs, const ImageImportDescription &import_desc=ImageImportDescription())
Constructs a Image.
clan::Image::set_color
void set_color(const Color &c)
Set color.
Definition image.h:228
clan::Image::operator==
bool operator==(const Image &other) const
Equality operator.
Definition image.h:148
clan::Image::Image
Image(Texture2D texture, const Rect &rect)
Constructs an image from a texture.
clan::Image::draw
void draw(Canvas &canvas, float x, float y) const
Draw image on graphic context.
clan::Image::get_scale_x
float get_scale_x() const
Returns x scale.
clan::Image::set_alpha
void set_alpha(float alpha)
Sets transparency.
clan::Image::~Image
virtual ~Image()
clan::Image::draw
void draw(Canvas &canvas, const Rectf &src, const Rectf &dest) const
Draw image on graphic context.
clan::Image::set_alignment
void set_alignment(Origin origin, float x=0, float y=0)
Sets translation hotspot.
clan::Image::set_color
void set_color(const Colorf &color)
Sets the color.
clan::Image::throw_if_null
void throw_if_null() const
Throw an exception if this object is invalid.
clan::Image::get_size
Sizef get_size() const
Return the size of the image.
clan::PixelBuffer
Pixel data container.
Definition pixel_buffer.h:68
clan::Quadf
2D quad structure - Float
Definition quad.h:217
clan::Rect
2D (left,top,right,bottom) rectangle structure - Integer
Definition rect.h:489
clan::Rectf
2D (left,top,right,bottom) rectangle structure - Float
Definition rect.h:503
clan::ResourceManager
Resource manager.
Definition resource_manager.h:44
clan::Resource
Resource proxy of a specific type.
Definition resource.h:58
clan::Sizef
2D (width,height) size structure - Float
Definition size.h:184
clan::Subtexture
Sub-texture description.
Definition subtexture.h:45
clan::Texture2D
2D texture object class.
Definition texture_2d.h:41
clan::Vec4::r
Type r
Definition vec4.h:79
clan::XMLResourceDocument
XML Resource Document.
Definition xml_resource_document.h:48
clan::Origin
Origin
Alignment origins.
Definition origin.h:39
clan::TextureWrapMode
TextureWrapMode
Texture coordinate wrapping modes.
Definition texture.h:65
clan
Definition clanapp.h:36
clan::StyleValueType::color
@ color
value is an url
clan::BrushType::image
@ image
clan::Key::y
@ y
clan::Key::c
@ c
clan::Key::x
@ x