CYD-UI
A C++ library for building native graphic user interfaces
Loading...
Searching...
No Matches
polyline.cppm
Go to the documentation of this file.
1// Copyright (c) 2024, Víctor Castillo Agüero.
2// SPDX-License-Identifier: GPL-3.0-or-later
3
4module;
5#include <cairomm-1.16/cairomm/cairomm.h>
6#include <tracy/Tracy.hpp>
7
9
10import std;
11
12export import cydui.dimensions;
14
15export namespace vg {
16 struct polyline:
18 attrs_core<polyline>,
19 attrs_fill<polyline>,
20 attrs_stroke<polyline>,
21 attr_points<polyline> {
23 //TracyAllocN(this, sizeof(decltype(*this)), "fragment_elements");
24 }
25 ~polyline() override {
26 //TracyFreeN(this, "fragment_elements");
27 }
28 void apply_to(pixelmap_editor_t &editor) const override {
29 apply_stroke(editor);
30 apply_fill(editor);
31
32 bool first = true;
33 double odd_offset = 0.0;
34 if ((_stroke_width % 2) != 0) {
35 odd_offset = 0.5;
36 }
37 for (const auto &p: _points) {
38 if (first) {
39 editor->move_to(origin_x + p[0] + odd_offset, origin_y + p[1] + odd_offset);
40 first = false;
41 } else {
42 editor->line_to(origin_x + p[0] + odd_offset, origin_y + p[1] + odd_offset);
43 }
44 }
45
46 set_source_to_fill(editor);
47 editor->fill_preserve();
48
50 editor->stroke();
51 }
52
53 footprint get_footprint() const override {
54 if (_points.empty()) {
55 return {0, 0, 0, 0};
56 }
57
58 int min_x = _points[0][0];
59 int min_y = _points[0][1];
60 int max_x = _points[0][0];
61 int max_y = _points[0][1];
62 int x, y;
63 for (std::size_t i = 1; i < _points.size(); ++i) {
64 x = _points[i][0];
65 y = _points[i][1];
66 if (x < min_x) min_x = x;
67 if (x > max_x) max_x = x;
68 if (y < min_y) min_y = y;
69 if (y > max_y) max_y = y;
70 }
71 return {
72 min_x,
73 min_y,
74 max_x - min_x,
75 max_y - min_y,
76 };
77 }
78 };
79}
void apply_fill(pixelmap_editor_t &editor) const
void set_source_to_fill(pixelmap_editor_t &editor) const
void set_source_to_stroke(pixelmap_editor_t &editor) const
void apply_stroke(pixelmap_editor_t &editor) const
footprint get_footprint() const override
Definition polyline.cppm:53
~polyline() override
Definition polyline.cppm:25
void apply_to(pixelmap_editor_t &editor) const override
Definition polyline.cppm:28