path.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** Magnus Norddahl
27** Mark Page
28*/
29
30#pragma once
31
32#include <memory>
33#include "../../Core/Math/rect.h"
34#include "../../Core/Math/mat4.h"
35#include "../../Display/2D/color.h"
36
37namespace clan
38{
39 class Font;
40 class PathImpl;
41 class GlyphMetrics;
42 class Canvas;
43 class Pen;
44 class Brush;
45
46 enum class PathFillMode
47 {
50 };
51
52 class Path
53 {
54 public:
56
57 void set_fill_mode(PathFillMode fill_mode);
58
59 void move_to(const Pointf &point);
60 void move_to(float x, float y) { move_to(Pointf(x, y)); }
61 void line_to(const Pointf &point);
62 void line_to(float x, float y) { line_to(Pointf(x, y)); }
63 void bezier_to(const Pointf &control, const Pointf &point);
64 void bezier_to(const Pointf &control1, const Pointf &control2, const Pointf &point);
65 void close();
66
68 void stroke(Canvas &canvas, const Pen &pen);
69
71 void fill(Canvas &canvas, const Brush &brush);
72
74 void fill_and_stroke(Canvas &canvas, const Pen &pen, const Brush &brush);
75
76 // \brief Copy the entire description (not just the implementation)
77 Path clone() const;
78
79 static Path rect(const Rectf &box);
80 static Path rect(float x, float y, float width, float height) { return Path::rect(Rectf(x, y, Sizef(width, height))); }
81 static Path line(const Pointf &start, const Pointf &end);
82 static Path line(float x1, float y1, float x2, float y2) { return Path::line(Pointf(x1, y1), Pointf(x2, y2)); }
83
84 static Path rect(const Rectf &box, const clan::Sizef &corner);
85
86 static Path circle(float center_x, float center_y, float radius) { return Path::ellipse(Pointf(center_x, center_y), Sizef(radius, radius)); }
87 static Path ellipse(float center_x, float center_y, float radius_x, float radius_y) { return Path::ellipse(Pointf(center_x, center_y), Sizef(radius_x, radius_y)); }
88 static Path circle(const Pointf &center, float radius) { return Path::ellipse(center, Sizef(radius, radius)); }
89 static Path ellipse(const Pointf &center, const Sizef &radius);
90
91 // This function is to assist in debugging, it has not been decided if it will be removed. Don't use at the moment.
92 static Path glyph(Canvas &canvas, Font &font, unsigned int glyph, GlyphMetrics &out_metrics);
93
94 std::shared_ptr<PathImpl> get_impl() const { return impl; }
95
99 void operator += (const Path& path);
100
108 Path &transform_self(const Mat3f &transform);
109
110 private:
111 std::shared_ptr<PathImpl> impl;
112 friend class CanvasImpl;
113 };
115 Path operator + (const Path& v1, const Path& v2);
116}
Definition brush.h:71
2D Graphics Canvas
Definition canvas.h:72
Font class.
Definition font.h:60
Glyph metrics class.
Definition glyph_metrics.h:41
Definition path.h:53
Path clone() const
static Path line(const Pointf &start, const Pointf &end)
std::shared_ptr< PathImpl > get_impl() const
Definition path.h:94
friend class CanvasImpl
Definition path.h:112
void bezier_to(const Pointf &control, const Pointf &point)
static Path rect(float x, float y, float width, float height)
Definition path.h:80
static Path circle(const Pointf &center, float radius)
Definition path.h:88
void fill_and_stroke(Canvas &canvas, const Pen &pen, const Brush &brush)
First fills a path, then strokes on top.
static Path ellipse(const Pointf &center, const Sizef &radius)
static Path rect(const Rectf &box, const clan::Sizef &corner)
void bezier_to(const Pointf &control1, const Pointf &control2, const Pointf &point)
void fill(Canvas &canvas, const Brush &brush)
Fills a path.
static Path glyph(Canvas &canvas, Font &font, unsigned int glyph, GlyphMetrics &out_metrics)
void operator+=(const Path &path)
+= operator to concatenate a path onto this path.
void close()
Path & transform_self(const Mat3f &transform)
Transform this path.
void line_to(const Pointf &point)
static Path rect(const Rectf &box)
void set_fill_mode(PathFillMode fill_mode)
static Path ellipse(float center_x, float center_y, float radius_x, float radius_y)
Definition path.h:87
void move_to(float x, float y)
Definition path.h:60
static Path circle(float center_x, float center_y, float radius)
Definition path.h:86
static Path line(float x1, float y1, float x2, float y2)
Definition path.h:82
void move_to(const Pointf &point)
void stroke(Canvas &canvas, const Pen &pen)
Strokes a path.
void line_to(float x, float y)
Definition path.h:62
Definition pen.h:37
2D (x,y) point structure - Float
Definition point.h:72
2D (left,top,right,bottom) rectangle structure - Float
Definition rect.h:460
2D (width,height) size structure - Float
Definition size.h:189
Vec2< Type > operator+(const Vec2< Type > &v1, const Vec2< Type > &v2)
operator.
Definition vec2.h:270
Definition clanapp.h:36
PathFillMode
Definition path.h:47