canvas.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 ** Magnus Norddahl
27 ** Mark Page
28 */
29 
30 #pragma once
31 
32 #include "../../Core/Math/mat4.h"
33 #include "../../Core/Math/mat3.h"
34 #include "../../Core/Math/point.h"
35 #include "../../Core/Math/size.h"
36 #include "../../Core/Math/rect.h"
37 #include "../../Core/Math/color.h"
38 
39 namespace uicore
40 {
42  typedef std::shared_ptr<DisplayWindow> DisplayWindowPtr;
43  class GraphicContext;
44  typedef std::shared_ptr<GraphicContext> GraphicContextPtr;
45  class BlendState;
46  typedef std::shared_ptr<BlendState> BlendStatePtr;
47  class Path;
48  class Pen;
49  class Brush;
50 
52  class Canvas
53  {
54  public:
56  static std::shared_ptr<Canvas> create(const DisplayWindowPtr &window);
57 
59  virtual const GraphicContextPtr &gc() const = 0;
60 
62  virtual const Mat4f &transform() const = 0;
63 
65  virtual const Mat4f &inverse_transform() const = 0;
66 
68  virtual const Mat4f &projection() const = 0;
69 
71  virtual float width() const = 0;
72 
74  virtual float height() const = 0;
75 
77  virtual Sizef size() const = 0;
78 
80  virtual Rectf clip() const = 0;
81 
84  virtual float pixel_ratio() const = 0;
85 
87  virtual void set_clip(const Rectf &rect) = 0;
88 
94  virtual void push_clip(const Rectf &rect) = 0;
95  virtual void push_clip() = 0;
96 
98  virtual void pop_clip() = 0;
99 
101  virtual void reset_clip() = 0;
102 
104  virtual void clear(const Colorf &color = Colorf::black) = 0;
105 
107  virtual void set_transform(const Mat4f &matrix) = 0;
108 
110  void mult_transform(const Mat4f &matrix) { set_transform(transform() * matrix); }
111 
115  virtual void begin() = 0;
116 
120  virtual void end() = 0;
121 
123  virtual Pointf grid_fit(const Pointf &pos) = 0;
124  };
125 
126  typedef std::shared_ptr<Canvas> CanvasPtr;
127 }
static std::shared_ptr< Canvas > create(const DisplayWindowPtr &window)
Constructs a canvas.
virtual const Mat4f & inverse_transform() const =0
Returns the inverse of the transform matrix.
Top-level window class.
Definition: display_window.h:101
virtual float height() const =0
Returns the current height of the context.
virtual Pointf grid_fit(const Pointf &pos)=0
Snaps the point to the nearest pixel corner.
2D (x,y) point structure - Float
Definition: point.h:68
virtual void begin()=0
Marks the start of a canvas rendering pass.
virtual void set_transform(const Mat4f &matrix)=0
Sets the transform matrix to a new matrix.
virtual const GraphicContextPtr & gc() const =0
Returns the graphic context associated with this canvas.
std::shared_ptr< BlendState > BlendStatePtr
Definition: canvas.h:45
Floating point color description class (for float).
Definition: color.h:630
Definition: pen.h:36
virtual void set_clip(const Rectf &rect)=0
Set the current clipping rectangle.
std::shared_ptr< DisplayWindow > DisplayWindowPtr
Definition: canvas.h:41
static Colorf black
Definition: color.h:799
virtual const Mat4f & projection() const =0
Returns the current effective projection matrix.
2D Graphics Canvas
Definition: canvas.h:52
virtual Sizef size() const =0
Returns the current size of the context.
virtual float pixel_ratio() const =0
2D (width,height) size structure - Float
Definition: size.h:180
virtual void pop_clip()=0
Pop current clipping rectangle from the stack.
virtual void clear(const Colorf &color=Colorf::black)=0
Clears the whole context using the specified color.
virtual Rectf clip() const =0
Returns the current clipping rectangle.
2D (left,top,right,bottom) rectangle structure - Float
Definition: rect.h:505
virtual void push_clip()=0
virtual void reset_clip()=0
Removes any active clipping rectangle and empties the clip stack.
Definition: brush.h:70
void mult_transform(const Mat4f &matrix)
Multiplies the passed matrix onto the transform matrix.
Definition: canvas.h:110
virtual const Mat4f & transform() const =0
Returns the transform matrix.
virtual void end()=0
Marks the end of a canvas rendering pass.
std::shared_ptr< GraphicContext > GraphicContextPtr
Definition: d3d_target.h:49
Interface to drawing graphics.
Definition: graphic_context.h:269
std::shared_ptr< Canvas > CanvasPtr
Definition: canvas.h:126
Definition: path.h:54
virtual float width() const =0
Returns the current width of the context.
Definition: Application/application.h:35
4D matrix
Definition: mat2.h:47
Definition: graphic_context.h:262