The Battle for Wesnoth
1.21.0-dev
Loading...
Searching...
No Matches
font
cairo.hpp
Go to the documentation of this file.
1
/*
2
Copyright (C) 2025 - 2025
3
Part of the Battle for Wesnoth Project https://www.wesnoth.org/
4
5
This program is free software; you can redistribute it and/or modify
6
it under the terms of the GNU General Public License as published by
7
the Free Software Foundation; either version 2 of the License, or
8
(at your option) any later version.
9
This program is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY.
11
12
See the COPYING file for more details.
13
*/
14
15
#pragma once
16
17
#include "
sdl/point.hpp
"
18
19
#include <cairo.h>
20
#include <memory>
21
22
namespace
cairo
23
{
24
using
surface_ptr
= std::unique_ptr<cairo_surface_t, void(*)(cairo_surface_t*)>;
25
using
context_ptr
= std::unique_ptr<cairo_t, void(*)(cairo_t*)>;
26
27
/** Color format for cairo surfaces. Should be equivalent to the format used by SDL. */
28
constexpr
cairo_format_t
format
= CAIRO_FORMAT_ARGB32;
29
30
inline
surface_ptr
create_surface
(uint8_t* buffer,
const
point
& size)
31
{
32
const
auto
& [width, height] = size;
33
const
int
stride = cairo_format_stride_for_width(
format
, width);
34
35
return
{
36
cairo_image_surface_create_for_data(buffer,
format
, width, height, stride),
37
cairo_surface_destroy
38
};
39
}
40
41
inline
context_ptr
create_context
(
const
surface_ptr
&
surf
)
42
{
43
return
{
44
cairo_create(
surf
.
get
()),
45
cairo_destroy
46
};
47
}
48
49
}
// namespace cairo
surface::get
SDL_Surface * get() const
Definition
surface.hpp:60
cairo
Definition
cairo.hpp:23
cairo::surface_ptr
std::unique_ptr< cairo_surface_t, void(*)(cairo_surface_t *)> surface_ptr
Definition
cairo.hpp:24
cairo::create_context
context_ptr create_context(const surface_ptr &surf)
Definition
cairo.hpp:41
cairo::format
constexpr cairo_format_t format
Color format for cairo surfaces.
Definition
cairo.hpp:28
cairo::context_ptr
std::unique_ptr< cairo_t, void(*)(cairo_t *)> context_ptr
Definition
cairo.hpp:25
cairo::create_surface
surface_ptr create_surface(uint8_t *buffer, const point &size)
Definition
cairo.hpp:30
point.hpp
surf
surface surf
Image.
Definition
spritesheet_generator.cpp:64
point
Holds a 2D point.
Definition
point.hpp:25
Generated by
1.9.8