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