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

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 {
48 alternate,
49 winding
50 };
51
52 class Path
53 {
54 public:
55 Path();
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}
clan::Brush
Definition brush.h:71
clan::Canvas
2D Graphics Canvas
Definition canvas.h:72
clan::Font
Font class.
Definition font.h:60
clan::GlyphMetrics
Glyph metrics class.
Definition glyph_metrics.h:41
clan::Mat3< float >
clan::Path
Definition path.h:53
clan::Path::clone
Path clone() const
clan::Path::line
static Path line(const Pointf &start, const Pointf &end)
clan::Path::get_impl
std::shared_ptr< PathImpl > get_impl() const
Definition path.h:94
clan::Path::CanvasImpl
friend class CanvasImpl
Definition path.h:112
clan::Path::bezier_to
void bezier_to(const Pointf &control, const Pointf &point)
clan::Path::rect
static Path rect(float x, float y, float width, float height)
Definition path.h:80
clan::Path::circle
static Path circle(const Pointf &center, float radius)
Definition path.h:88
clan::Path::fill_and_stroke
void fill_and_stroke(Canvas &canvas, const Pen &pen, const Brush &brush)
First fills a path, then strokes on top.
clan::Path::ellipse
static Path ellipse(const Pointf &center, const Sizef &radius)
clan::Path::Path
Path()
clan::Path::rect
static Path rect(const Rectf &box, const clan::Sizef &corner)
clan::Path::bezier_to
void bezier_to(const Pointf &control1, const Pointf &control2, const Pointf &point)
clan::Path::fill
void fill(Canvas &canvas, const Brush &brush)
Fills a path.
clan::Path::glyph
static Path glyph(Canvas &canvas, Font &font, unsigned int glyph, GlyphMetrics &out_metrics)
clan::Path::operator+=
void operator+=(const Path &path)
+= operator to concatenate a path onto this path.
clan::Path::close
void close()
clan::Path::transform_self
Path & transform_self(const Mat3f &transform)
Transform this path.
clan::Path::line_to
void line_to(const Pointf &point)
clan::Path::rect
static Path rect(const Rectf &box)
clan::Path::set_fill_mode
void set_fill_mode(PathFillMode fill_mode)
clan::Path::ellipse
static Path ellipse(float center_x, float center_y, float radius_x, float radius_y)
Definition path.h:87
clan::Path::move_to
void move_to(float x, float y)
Definition path.h:60
clan::Path::circle
static Path circle(float center_x, float center_y, float radius)
Definition path.h:86
clan::Path::line
static Path line(float x1, float y1, float x2, float y2)
Definition path.h:82
clan::Path::move_to
void move_to(const Pointf &point)
clan::Path::stroke
void stroke(Canvas &canvas, const Pen &pen)
Strokes a path.
clan::Path::line_to
void line_to(float x, float y)
Definition path.h:62
clan::Pen
Definition pen.h:37
clan::Pointf
2D (x,y) point structure - Float
Definition point.h:72
clan::Rectf
2D (left,top,right,bottom) rectangle structure - Float
Definition rect.h:503
clan::Sizef
2D (width,height) size structure - Float
Definition size.h:184
clan::operator+
Vec2< Type > operator+(const Vec2< Type > &v1, const Vec2< Type > &v2)
operator.
Definition vec2.h:266
clan::Origin::center
@ center
clan::FillMode::point
@ point
clan::StandardProgram::path
@ path
clan
Definition clanapp.h:36
clan::Key::y
@ y
clan::Key::end
@ end
clan::Key::x
@ x
clan::PathFillMode
PathFillMode
Definition path.h:47
clan::PathFillMode::alternate
@ alternate
clan::PathFillMode::winding
@ winding