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
4
module
;
5
#include <cairomm-1.16/cairomm/cairomm.h>
6
7
export
module
cydui.graphics.pixelmap_editor
;
8
9
export
import
cydui.graphics.types
;
10
11
// CAIRO_HAS_PDF_SURFACE
12
13
export
{
14
class
pixelmap_editor_t
{
15
public
:
16
int
width
,
height
;
17
pixel_t *
img
=
nullptr
;
18
19
Cairo::RefPtr<Cairo::Surface>
surface
;
20
Cairo::RefPtr<Cairo::Context>
ctx
;
21
public
:
22
explicit
pixelmap_editor_t
(
pixelmap_t
&
img
):
width
(
img
.
width
()),
height
(
img
.
height
()),
img
(
img
.data) {
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,
29
width
,
height
,
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
37
explicit
pixelmap_editor_t
(
pixelmap_t
*
img
):
pixelmap_editor_t
(*
img
) {
38
}
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,
47
width
,
height
,
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
55
public
:
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
}
pixelmap_editor_t::img
pixel_t * img
Definition
pixelmap_editor.cppm:17
pixelmap_editor_t::ctx
Cairo::RefPtr< Cairo::Context > ctx
Definition
pixelmap_editor.cppm:20
pixelmap_editor_t::operator->
Cairo::RefPtr< Cairo::Context > operator->()
Definition
pixelmap_editor.cppm:56
pixelmap_editor_t::pixelmap_editor_t
pixelmap_editor_t(int width_, int height_, pixel_t *img_, int stride)
Definition
pixelmap_editor.cppm:40
pixelmap_editor_t::width
int width
Definition
pixelmap_editor.cppm:16
pixelmap_editor_t::surface
Cairo::RefPtr< Cairo::Surface > surface
Definition
pixelmap_editor.cppm:19
pixelmap_editor_t::clear
void clear()
Definition
pixelmap_editor.cppm:60
pixelmap_editor_t::height
int height
Definition
pixelmap_editor.cppm:16
pixelmap_editor_t::pixelmap_editor_t
pixelmap_editor_t(pixelmap_t *img)
Definition
pixelmap_editor.cppm:37
pixelmap_editor_t::pixelmap_editor_t
pixelmap_editor_t(pixelmap_t &img)
Definition
pixelmap_editor.cppm:22
cydui.graphics.pixelmap_editor
cydui.graphics.types
pixelmap_t
Definition
pixelmap.cppm:19
include
cyd_ui
graphics
pixelmap_editor.cppm
Generated by
1.13.2