CYD-UI
A C++ library for building native graphic user interfaces
Loading...
Searching...
No Matches
pixelmap.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 pixelmap:
18 attrs_core<pixelmap>,
19 attr_x<pixelmap>,
20 attr_y<pixelmap>,
21 attr_rotate<pixelmap>,
22 attr_pivot_x<pixelmap>,
23 attr_pivot_y<pixelmap>,
24 attr_scale_x<pixelmap>,
25 attr_scale_y<pixelmap>,
26 attr_w<pixelmap>,
27 attr_h<pixelmap> {
29 explicit pixelmap(const pixelmap_t &pxm): _pxm(pxm) {
30 //TracyAllocN(this, sizeof(decltype(*this)), "fragment_elements");
31 }
32 ~pixelmap() override {
33 //TracyFreeN(this, "fragment_elements");
34 }
35
36 void apply_to(pixelmap_editor_t &editor) const override {
37 // TODO - cairo_format_stride_for_width() should be called before allocating the image buffer and thus use its
38 // output to determine the 'width' of the buffer.
39 Cairo::RefPtr<Cairo::Surface> surf = Cairo::ImageSurface::create(
40 (unsigned char*) this->_pxm.data,
41 Cairo::Surface::Format::ARGB32,
42 (int) this->_pxm.width(),
43 (int) this->_pxm.height(),
44 (int) this->_pxm.width() * 4
45 );
46 editor->save();
47 editor->translate(origin_x + _x + _pivot_x, origin_y + _y + _pivot_y);
48 editor->rotate(_rotate * std::numbers::pi / 180.0);
49 editor->scale(_scale_x, _scale_y);
50 editor->set_source(surf, -_pivot_x, -_pivot_y);
51 editor->paint_with_alpha(_opacity);
52 editor->restore();
53
54 surf->finish();
55 }
56
57 footprint get_footprint() const override {
58 return {};
59 }
60 };
61}
size_t width() const
Definition pixelmap.cppm:25
pivot_x - rotate pivot x-axis coordinate
pivot_y - rotate pivot y-axis coordinate
rotate - angle of rotation in degrees
rotate - angle of rotation in degrees
rotate - angle of rotation in degrees
x - x-axis coordinate
y - y-axis coordinate
pixelmap(const pixelmap_t &pxm)
Definition pixelmap.cppm:29
~pixelmap() override
Definition pixelmap.cppm:32
footprint get_footprint() const override
Definition pixelmap.cppm:57
const pixelmap_t & _pxm
Definition pixelmap.cppm:28
void apply_to(pixelmap_editor_t &editor) const override
Definition pixelmap.cppm:36