CYD-UI
A C++ library for building native graphic user interfaces
Loading...
Searching...
No Matches
line.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 line:
18 attrs_core<line>,
19 attrs_stroke<line>,
20 attr_x1<line>,
21 attr_y1<line>,
22 attr_x2<line>,
23 attr_y2<line> {
24 line() {
25 // per element Defaults
26 this->stroke_width(1);
27 //TracyAllocN(this, sizeof(decltype(*this)), "fragment_elements");
28 }
29 ~line() override {
30 //TracyFreeN(this, "fragment_elements");
31 }
32
33 void apply_to(pixelmap_editor_t &editor) const override {
34 apply_stroke(editor);
35
37
38 if ((_stroke_width % 2) != 0) {
39 editor->move_to(origin_x + _x1 + 0.5, origin_y + _y1 + 0.5);
40 editor->line_to(origin_x + _x2 + 0.5, origin_y + _y2 + 0.5);
41 } else {
42 editor->move_to(origin_x + _x1, origin_y + _y1);
43 editor->line_to(origin_x + _x2, origin_y + _y2);
44 }
45
46 editor->stroke();
47 }
48
49 footprint get_footprint() const override {
50 return {
51 std::min(_x1, _x2),
52 std::min(_y1, _y2),
53 std::abs(_x2 - _x1),
54 std::abs(_y2 - _y1),
55 };
56 }
57 };
58}
line & stroke_width(const quantify::quantity_t< UNIT, T > &_stroke_width_)
x1 - 1st point x-axis coordinate
x2 - 2nd point x-axis coordinate
y1 - 1st point y-axis coordinate
y2 - 2nd point y-axis coordinate
void set_source_to_stroke(pixelmap_editor_t &editor) const
void apply_stroke(pixelmap_editor_t &editor) const
footprint get_footprint() const override
Definition line.cppm:49
~line() override
Definition line.cppm:29
void apply_to(pixelmap_editor_t &editor) const override
Definition line.cppm:33