CYD-UI
A C++ library for building native graphic user interfaces
Loading...
Searching...
No Matches
pixelmap_editor.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
8
9export import cydui.graphics.types;
10
11// CAIRO_HAS_PDF_SURFACE
12
13export {
15public:
17 pixel_t *img = nullptr;
18
19 Cairo::RefPtr<Cairo::Surface> surface;
20 Cairo::RefPtr<Cairo::Context> ctx;
21public:
23 // TODO - cairo_format_stride_for_width() should be called before allocating the image buffer and thus use its
24 // output to determine the 'width' of the buffer.
25 // Cairo::PdfSurface::create("",1,1);
26 surface = Cairo::ImageSurface::create(
27 (unsigned char*) this->img,
28 Cairo::Surface::Format::ARGB32,
30 width * 4
31 //cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, (int) this->img.width())
32 );
33 ctx = Cairo::Context::create(surface);
34 // ctx->set_antialias(Cairo::Antialias::ANTIALIAS_SUBPIXEL);
35 }
36
39
40 explicit pixelmap_editor_t(int width_, int height_, pixel_t* img_, int stride): width(std::max(0, width_)), height(std::max(0, height_)), img(img_) {
41 // TODO - cairo_format_stride_for_width() should be called before allocating the image buffer and thus use its
42 // output to determine the 'width' of the buffer.
43 // Cairo::PdfSurface::create("",1,1);
44 surface = Cairo::ImageSurface::create(
45 (unsigned char*) img,
46 Cairo::Surface::Format::ARGB32,
48 stride
49 //cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, (int) this->img.width())
50 );
51 ctx = Cairo::Context::create(surface);
52 // ctx->set_antialias(Cairo::Antialias::ANTIALIAS_SUBPIXEL);
53 }
54
55public:
56 Cairo::RefPtr<Cairo::Context> operator->() {
57 return ctx;
58 }
59
60 void clear() {
61 memset(img, 0, width * height * sizeof(pixel_t));
62 }
63};
64
65}
Cairo::RefPtr< Cairo::Context > ctx
Cairo::RefPtr< Cairo::Context > operator->()
pixelmap_editor_t(int width_, int height_, pixel_t *img_, int stride)
Cairo::RefPtr< Cairo::Surface > surface
pixelmap_editor_t(pixelmap_t *img)
pixelmap_editor_t(pixelmap_t &img)