AeonGUI
A portable video game graphic user interface library.
Loading...
Searching...
No Matches
CairoCanvas.hpp
1/*
2Copyright (C) 2019,2020,2024,2025,2026 Rodrigo Jose Hernandez Cordoba
3
4Licensed under the Apache License, Version 2.0 (the "License");
5you may not use this file except in compliance with the License.
6You may obtain a copy of the License at
7
8http://www.apache.org/licenses/LICENSE-2.0
9
10Unless required by applicable law or agreed to in writing, software
11distributed under the License is distributed on an "AS IS" BASIS,
12WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13See the License for the specific language governing permissions and
14limitations under the License.
15*/
16#ifndef AEONGUI_CAIROCANVAS_H
17#define AEONGUI_CAIROCANVAS_H
18#include <cstdint>
19#include <string>
20#include "aeongui/Canvas.hpp"
21
22struct _cairo_surface;
23typedef struct _cairo_surface cairo_surface_t;
24struct _cairo;
25typedef struct _cairo cairo_t;
26
27namespace AeonGUI
28{
34 class CairoCanvas : public Canvas
35 {
36 public:
43 DLL CairoCanvas ( uint32_t aWidth, uint32_t aHeight );
45 DLL ~CairoCanvas() final;
46 DLL void ResizeViewport ( uint32_t aWidth, uint32_t aHeight ) final;
47 DLL const uint8_t* GetPixels() const final;
48 DLL size_t GetWidth() const final;
49 DLL size_t GetHeight() const final;
50 DLL size_t GetStride() const final;
51 DLL void Clear() final;
52 DLL void Draw ( const Path& aPath ) final;
53 DLL void DrawImage ( const uint8_t* aPixels,
54 size_t aImageWidth,
55 size_t aImageHeight,
56 size_t aImageStride,
57 double aX,
58 double aY,
59 double aWidth,
60 double aHeight,
61 double aOpacity ) final;
62 DLL void DrawText ( const std::string& aText, double aX, double aY,
63 const std::string& aFontFamily, double aFontSize,
64 int aFontWeight, int aFontStyle ) final;
65 DLL double MeasureText ( const std::string& aText,
66 const std::string& aFontFamily, double aFontSize,
67 int aFontWeight, int aFontStyle ) const final;
68 DLL void SetFillColor ( const ColorAttr& aColor ) final;
69 DLL const ColorAttr& GetFillColor() const final;
70 DLL void SetStrokeColor ( const ColorAttr& aColor ) final;
71 DLL const ColorAttr& GetStrokeColor() const final;
72 DLL void SetStrokeWidth ( double aWidth ) final;
73 DLL double GetStrokeWidth () const final;
74 DLL void SetStrokeOpacity ( double aWidth ) final;
75 DLL double GetStrokeOpacity () const final;
76 DLL void SetFillOpacity ( double aWidth ) final;
77 DLL double GetFillOpacity () const final;
78 DLL void SetOpacity ( double aWidth ) final;
79 DLL double GetOpacity () const final;
80 DLL void SetViewBox ( const ViewBox& aViewBox, const PreserveAspectRatio& aPreserveAspectRatio ) final;
81 DLL void SetTransform ( const Matrix2x3& aMatrix ) final;
82 DLL void Transform ( const Matrix2x3& aMatrix ) final;
83 DLL void* GetNativeSurface() const final;
84 private:
85 cairo_surface_t* mCairoSurface{};
86 cairo_t* mCairoContext{};
87 ColorAttr mFillColor{};
88 ColorAttr mStrokeColor{};
89 double mStrokeWidth{1};
90 double mStrokeOpacity{1};
91 double mFillOpacity{1};
92 double mOpacity{1};
93 };
94}
95#endif
void DrawText(const std::string &aText, double aX, double aY, const std::string &aFontFamily, double aFontSize, int aFontWeight, int aFontStyle) final
Definition CairoCanvas.cpp:316
void SetStrokeColor(const ColorAttr &aColor) final
Set the stroke color.
Definition CairoCanvas.cpp:106
void SetViewBox(const ViewBox &aViewBox, const PreserveAspectRatio &aPreserveAspectRatio) final
Set the SVG viewBox and preserveAspectRatio.
Definition CairoCanvas.cpp:412
const ColorAttr & GetStrokeColor() const final
Get the current stroke color.
Definition CairoCanvas.cpp:111
double GetStrokeOpacity() const final
Get the current stroke opacity.
Definition CairoCanvas.cpp:131
void SetOpacity(double aWidth) final
Set the global opacity.
Definition CairoCanvas.cpp:146
void SetStrokeOpacity(double aWidth) final
Set the stroke opacity.
Definition CairoCanvas.cpp:126
void Clear() final
Clear the canvas to transparent.
Definition CairoCanvas.cpp:77
CairoCanvas()
Default constructor. Creates an empty canvas.
void Draw(const Path &aPath) final
Draw a path using the current fill and stroke settings.
Definition CairoCanvas.cpp:156
void * GetNativeSurface() const final
Get the native rendering surface handle.
Definition CairoCanvas.cpp:483
void ResizeViewport(uint32_t aWidth, uint32_t aHeight) final
Resize the rendering viewport.
Definition CairoCanvas.cpp:38
void DrawImage(const uint8_t *aPixels, size_t aImageWidth, size_t aImageHeight, size_t aImageStride, double aX, double aY, double aWidth, double aHeight, double aOpacity) final
Draw a raster image.
Definition CairoCanvas.cpp:185
void SetTransform(const Matrix2x3 &aMatrix) final
Replace the current transformation matrix.
Definition CairoCanvas.cpp:463
double GetOpacity() const final
Get the current global opacity.
Definition CairoCanvas.cpp:151
double GetFillOpacity() const final
Get the current fill opacity.
Definition CairoCanvas.cpp:141
size_t GetWidth() const final
Get the width of the canvas in pixels.
Definition CairoCanvas.cpp:65
size_t GetStride() const final
Get the stride (bytes per row) of the pixel buffer.
Definition CairoCanvas.cpp:73
void SetFillColor(const ColorAttr &aColor) final
Set the fill color.
Definition CairoCanvas.cpp:96
const uint8_t * GetPixels() const final
Get a pointer to the raw pixel data.
Definition CairoCanvas.cpp:56
void Transform(const Matrix2x3 &aMatrix) final
Pre-multiply the current transformation matrix.
Definition CairoCanvas.cpp:473
double MeasureText(const std::string &aText, const std::string &aFontFamily, double aFontSize, int aFontWeight, int aFontStyle) const final
Definition CairoCanvas.cpp:383
size_t GetHeight() const final
Get the height of the canvas in pixels.
Definition CairoCanvas.cpp:69
void SetStrokeWidth(double aWidth) final
Set the stroke width.
Definition CairoCanvas.cpp:116
double GetStrokeWidth() const final
Get the current stroke width.
Definition CairoCanvas.cpp:121
void SetFillOpacity(double aWidth) final
Set the fill opacity.
Definition CairoCanvas.cpp:136
~CairoCanvas() final
Destructor. Releases Cairo resources.
Definition CairoCanvas.cpp:84
const ColorAttr & GetFillColor() const final
Get the current fill color.
Definition CairoCanvas.cpp:101
Abstract 2D rendering surface.
Definition Canvas.hpp:39
2x3 affine transformation matrix.
Definition Matrix2x3.hpp:37
Abstract base class for renderable path data.
Definition Path.hpp:32
SVG preserveAspectRatio attribute.
Definition Attribute.hpp:44
SVG viewBox attribute value.
Definition Attribute.hpp:31