CYD-UI
A C++ library for building native graphic user interfaces
Loading...
Searching...
No Matches
circle.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 circle:
18 attrs_core<circle>,
19 attrs_fill<circle>,
20 attrs_stroke<circle>,
21 attr_cx<circle>,
22 attr_cy<circle>,
23 attr_r<circle> {
25 //TracyAllocN(this, sizeof(decltype(*this)), "fragment_elements");
26 }
27 ~circle() override {
28 //TracyFreeN(this, "fragment_elements");
29 }
30 void apply_to(pixelmap_editor_t &editor) const override {
31 editor->save();
32 apply_stroke(editor);
33 apply_fill(editor);
34
35 double odd_offset = 0.0;
36 if ((_stroke_width % 2) != 0) {
37 odd_offset = 0.5;
38 }
39 editor->begin_new_path();
40 editor->translate(origin_x + _cx + odd_offset, origin_y + _cy + odd_offset);
41 editor->arc(0.0, 0.0, _r, 0, 2 * std::numbers::pi);
42 set_source_to_fill(editor);
43 editor->fill_preserve();
44
46 editor->stroke();
47 editor->restore();
48 }
49
50 footprint get_footprint() const override {
51 return {_cx - _r, _cy - _r, 2 * _r, 2 * _r};
52 }
53 };
54}
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
void apply_to(pixelmap_editor_t &editor) const override
Definition circle.cppm:30
~circle() override
Definition circle.cppm:27
footprint get_footprint() const override
Definition circle.cppm:50