image.h
1 /*
2 ** UICore
3 ** Copyright (c) 1997-2015 The UICore 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 UICore 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/Math/color.h"
34 #include "../Image/image_import_description.h"
35 #include "UICore/Display/Render/texture.h"
36 
37 namespace uicore
38 {
39  class Rect;
40  class Size;
41  class Rectf;
42  class Texture2D;
43  typedef std::shared_ptr<Texture2D> Texture2DPtr;
44  class TextureGroupImage;
45  class PixelBuffer;
46  class Canvas;
47  typedef std::shared_ptr<Canvas> CanvasPtr;
48  class Quadf;
49 
51  class Image
52  {
53  public:
55  static std::shared_ptr<Image> create(Texture2DPtr texture, const Rect &rect, float pixel_ratio = 1.0f);
56  static std::shared_ptr<Image> create(TextureGroupImage &sub_texture, float pixel_ratio = 1.0f);
57  static std::shared_ptr<Image> create(const CanvasPtr &canvas, const PixelBufferPtr &pixelbuffer, const Rect &rect, float pixel_ratio = 1.0f);
58  static std::shared_ptr<Image> create(const CanvasPtr &canvas, const std::string &filename, const ImageImportDescription &import_desc = ImageImportDescription(), float pixel_ratio = 1.0f);
59 
61  virtual float scale_x() const = 0;
62 
64  virtual float scale_y() const = 0;
65 
67  virtual Colorf color() const = 0;
68 
70  virtual void alignment(Origin &origin, float &x, float &y) const = 0;
71 
73  virtual TextureGroupImage texture() const = 0;
74 
76  virtual Sizef size() const = 0;
77 
79  virtual float width() const = 0;
80 
82  virtual float height() const = 0;
83 
85  virtual std::shared_ptr<Image> clone() const = 0;
86 
93  virtual void draw(const CanvasPtr &canvas, float x, float y) const = 0;
94  virtual void draw(const CanvasPtr &canvas, const Rectf &src, const Rectf &dest) const = 0;
95  virtual void draw(const CanvasPtr &canvas, const Rectf &dest) const = 0;
96  virtual void draw(const CanvasPtr &canvas, const Rectf &src, const Quadf &dest) const = 0;
97  virtual void draw(const CanvasPtr &canvas, const Quadf &dest) const = 0;
98 
100  virtual void set_scale(float x, float y) = 0;
101 
103  virtual void set_color(const Colorf &color) = 0;
104  void set_color(const Color& c) { Colorf color; color.x = c.get_red() / 255.0f; color.y = c.get_green() / 255.0f; color.z = c.get_blue() / 255.0f; color.w = c.get_alpha() / 255.0f; set_color(color); }
105 
107  virtual void set_alignment(Origin origin, float x = 0, float y = 0) = 0;
108 
110  virtual void set_wrap_mode(TextureWrapMode wrap_s, TextureWrapMode wrap_t) = 0;
111 
113  virtual void set_linear_filter(bool linear_filter = true) = 0;
114  };
115 
116  typedef std::shared_ptr<Image> ImagePtr;
117 }
virtual Sizef size() const =0
Return the size of the image.
virtual void set_scale(float x, float y)=0
Set scale factors.
std::shared_ptr< Texture2D > Texture2DPtr
Definition: image.h:42
virtual Colorf color() const =0
Returns current color.
unsigned char get_green() const
Returns the green color component, in the range 0-255.
Definition: color.h:77
Image class.
Definition: image.h:51
virtual void set_wrap_mode(TextureWrapMode wrap_s, TextureWrapMode wrap_t)=0
Sets the wrapping mode to use.
Type x
Definition: vec4.h:74
Floating point color description class (for float).
Definition: color.h:630
Pixel data container.
Definition: pixel_buffer.h:52
Image Import Description Class.
Definition: image_import_description.h:45
unsigned char get_red() const
Returns the red color component, in the range 0-255.
Definition: color.h:74
Color description class.
Definition: color.h:42
virtual float width() const =0
Return the width of the image.
virtual void draw(const CanvasPtr &canvas, float x, float y) const =0
Draw image on graphic context.
unsigned char get_alpha() const
Returns the alpha color component, in the range 0-255.
Definition: color.h:71
2D Graphics Canvas
Definition: canvas.h:52
virtual void alignment(Origin &origin, float &x, float &y) const =0
Returns translation hot-spot.
2D (width,height) size structure - Float
Definition: size.h:180
2D (left,top,right,bottom) rectangle structure - Float
Definition: rect.h:505
2D quad structure - Float
Definition: quad.h:213
Type y
Definition: vec4.h:75
virtual void set_color(const Colorf &color)=0
Sets the color.
Type w
Definition: vec4.h:77
2D (left,top,right,bottom) rectangle structure - Integer
Definition: rect.h:491
std::shared_ptr< Image > ImagePtr
Definition: image.h:116
virtual float scale_x() const =0
Returns x scale.
virtual void set_linear_filter(bool linear_filter=true)=0
Set to true if a linear filter should be used for scaling up and down, false if a nearest-point filte...
void set_color(const Color &c)
Definition: image.h:104
unsigned char get_blue() const
Returns the blue color component, in the range 0-255.
Definition: color.h:80
std::shared_ptr< PixelBuffer > PixelBufferPtr
Definition: d3d_target.h:39
Type z
Definition: vec4.h:76
Origin
Alignment origins.
Definition: origin.h:35
TextureWrapMode
Texture coordinate wrapping modes.
Definition: texture.h:56
std::shared_ptr< Canvas > CanvasPtr
Definition: canvas.h:126
static std::shared_ptr< Image > create(Texture2DPtr texture, const Rect &rect, float pixel_ratio=1.0f)
Constructs an image.
virtual void set_alignment(Origin origin, float x=0, float y=0)=0
Sets translation hotspot.
Definition: Application/application.h:35
virtual std::shared_ptr< Image > clone() const =0
Copies all information from this image to another, excluding the graphics that remain shared...
virtual float scale_y() const =0
Returns y scale.
virtual float height() const =0
Return the height of the image.
Image position in a TextureGroup.
Definition: texture_group.h:44
2D texture object class.
Definition: texture_2d.h:39
virtual TextureGroupImage texture() const =0
Return the texture of the image.