CYD-UI
A C++ library for building native graphic user interfaces
Loading...
Searching...
No Matches
arc.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 arc:
18 attrs_core<arc>,
19 attrs_fill<arc>,
20 attrs_stroke<arc>,
21 attr_cx<arc>,
22 attr_cy<arc>,
23 attr_r<arc>,
24 attr_a1<arc>,
25 attr_a2<arc> {
26 arc() {
27 //TracyAllocN(this, sizeof(decltype(*this)), "fragment_elements");
28 }
29 ~arc() override {
30 //TracyFreeN(this, "fragment_elements");
31 }
32 void apply_to(pixelmap_editor_t &editor) const override {
33 editor->save();
34 apply_stroke(editor);
35 apply_fill(editor);
36
37 double odd_offset = 0.0;
38 if ((_stroke_width % 2) != 0) {
39 odd_offset = 0.5;
40 }
41 editor->translate(origin_x + _cx + odd_offset, origin_y + _cy + odd_offset);
42 //editor->scale(_rx, _ry);
43 editor->arc(0.0, 0.0, _r, _a1 * 2 * std::numbers::pi / 360.0, _a2 * 2 * std::numbers::pi / 360.0);
44
45 set_source_to_fill(editor);
46 editor->fill_preserve();
47
49 editor->stroke();
50
51 editor->restore();
52 }
53
54 footprint get_footprint() const override {
55 return {_cx - _r, _cy - _r, 2 * _r, 2 * _r};
56 }
57 };
58}
footprint get_footprint() const override
Definition arc.cppm:54
~arc() override
Definition arc.cppm:29
void apply_to(pixelmap_editor_t &editor) const override
Definition arc.cppm:32
arc()
Definition arc.cppm:26
a1 - 1st angle in arcs in degrees
a1 - 2st angle in arcs in degrees
cx - center x-axis coordinate
cy - center y-axis coordinate
r - radius
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