CYD-UI
A C++ library for building native graphic user interfaces
Loading...
Searching...
No Matches
rectangle.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 rectangle:
18 attrs_core<rectangle>,
19 attrs_fill<rectangle>,
20 attrs_stroke<rectangle>,
21 attr_x<rectangle>,
22 attr_y<rectangle>,
23 attr_w<rectangle>,
24 attr_h<rectangle>,
25 attr_r<rectangle> {
27 //TracyAllocN(this, sizeof(decltype(*this)), "fragment_elements");
28 }
29 ~rectangle() override {
30 //TracyFreeN(this, "fragment_elements");
31 }
32 void apply_to(pixelmap_editor_t &editor) const override {
33 apply_stroke(editor);
34 apply_fill(editor);
35
36 double odd_offset = 0.0;
37 if ((_stroke_width % 2) != 0) {
38 odd_offset = 0.5;
39 }
40 auto x = origin_x + _x + odd_offset;
41 auto y = origin_y + _y + odd_offset;
42
43 if (_r == 0) {
44 editor->rectangle(x, y, _w, _h);
45 } else {
46 auto r = _r;
47 r = std::min(_w / 2, r);
48 r = std::min(_h / 2, r);
49 editor->move_to(x + r, y);
50 editor->arc(x + _w - r, y + r, r, 3 * M_PI / 2, 0);
51 editor->arc(x + _w - r, y + _h - r, r, 0, M_PI / 2);
52 editor->arc(x + r, y + _h - r, r, M_PI / 2, M_PI);
53 editor->arc(x + r, y + r, r, M_PI, 3 * M_PI / 2);
54 }
55
56 set_source_to_fill(editor);
57 editor->fill_preserve();
58
60 editor->stroke();
61 }
62
63 footprint get_footprint() const override {
64 return {_x, _y, _w, _h};
65 }
66 };
67}
r - radius
rectangle & r(const quantify::quantity_t< UNIT, T > &_r_)
x - x-axis coordinate
rectangle & x(const quantify::quantity_t< UNIT, T > &_x_)
y - y-axis coordinate
rectangle & y(const quantify::quantity_t< UNIT, T > &_y_)
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
void apply_to(pixelmap_editor_t &editor) const override
~rectangle() override