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 DrawTextOnPath ( const std::string& aText,
69 const Path& aPath,
70 double aStartOffset,
71 const std::string& aFontFamily, double aFontSize,
72 int aFontWeight, int aFontStyle,
73 bool aReverse = false, bool aClosed = false ) final;
74 DLL void SetFillColor ( const ColorAttr& aColor ) final;
75 DLL const ColorAttr& GetFillColor() const final;
76 DLL void SetStrokeColor ( const ColorAttr& aColor ) final;
77 DLL const ColorAttr& GetStrokeColor() const final;
78 DLL void SetStrokeWidth ( double aWidth ) final;
79 DLL double GetStrokeWidth () const final;
80 DLL void SetStrokeOpacity ( double aWidth ) final;
81 DLL double GetStrokeOpacity () const final;
82 DLL void SetFillOpacity ( double aWidth ) final;
83 DLL double GetFillOpacity () const final;
84 DLL void SetOpacity ( double aWidth ) final;
85 DLL double GetOpacity () const final;
86 DLL void SetViewBox ( const ViewBox& aViewBox, const PreserveAspectRatio& aPreserveAspectRatio ) final;
87 DLL void SetTransform ( const Matrix2x3& aMatrix ) final;
88 DLL void Transform ( const Matrix2x3& aMatrix ) final;
89 DLL void Save() final;
90 DLL void Restore() final;
91 DLL void* GetNativeSurface() const final;
92 DLL void PushGroup() final;
93 DLL void PopGroup() final;
94 DLL void ApplyDropShadow ( double aDx, double aDy,
95 double aStdDeviationX, double aStdDeviationY,
96 const Color& aFloodColor, double aFloodOpacity ) final;
97 DLL uint8_t PickAtPoint ( double aX, double aY ) const final;
98 DLL void ResetPick() final;
99 DLL void SetClipRect ( double aX, double aY, double aWidth, double aHeight ) final;
100 DLL std::unique_ptr<Path> CreatePath() const final;
101 private:
102 void InitPickSurface ( uint32_t aWidth, uint32_t aHeight );
103 void DestroyPickSurface();
104 cairo_surface_t* mCairoSurface{};
105 cairo_t* mCairoContext{};
106 cairo_surface_t* mPickSurface{};
107 cairo_t* mPickContext{};
108 ColorAttr mFillColor{};
109 ColorAttr mStrokeColor{};
110 double mStrokeWidth{1};
111 double mStrokeOpacity{1};
112 double mFillOpacity{1};
113 double mOpacity{1};
114 };
115}
116#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:393
void SetStrokeColor(const ColorAttr &aColor) final
Set the stroke color.
Definition CairoCanvas.cpp:112
void SetViewBox(const ViewBox &aViewBox, const PreserveAspectRatio &aPreserveAspectRatio) final
Set the SVG viewBox and preserveAspectRatio.
Definition CairoCanvas.cpp:630
void DrawTextOnPath(const std::string &aText, const Path &aPath, double aStartOffset, const std::string &aFontFamily, double aFontSize, int aFontWeight, int aFontStyle, bool aReverse=false, bool aClosed=false) final
Definition CairoCanvas.cpp:489
void Save() final
Save the current graphics state (transform, clipping, etc.).
Definition CairoCanvas.cpp:713
const ColorAttr & GetStrokeColor() const final
Get the current stroke color.
Definition CairoCanvas.cpp:117
double GetStrokeOpacity() const final
Get the current stroke opacity.
Definition CairoCanvas.cpp:137
void SetOpacity(double aWidth) final
Set the global opacity.
Definition CairoCanvas.cpp:152
void SetStrokeOpacity(double aWidth) final
Set the stroke opacity.
Definition CairoCanvas.cpp:132
void Clear() final
Clear the canvas to transparent.
Definition CairoCanvas.cpp:82
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:162
void * GetNativeSurface() const final
Get the native rendering surface handle.
Definition CairoCanvas.cpp:729
void ResizeViewport(uint32_t aWidth, uint32_t aHeight) final
Resize the rendering viewport.
Definition CairoCanvas.cpp:41
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:262
void SetTransform(const Matrix2x3 &aMatrix) final
Replace the current transformation matrix.
Definition CairoCanvas.cpp:685
double GetOpacity() const final
Get the current global opacity.
Definition CairoCanvas.cpp:157
double GetFillOpacity() const final
Get the current fill opacity.
Definition CairoCanvas.cpp:147
uint8_t PickAtPoint(double aX, double aY) const final
Read the pick ID at the given viewport coordinates.
Definition CairoCanvas.cpp:947
size_t GetWidth() const final
Get the width of the canvas in pixels.
Definition CairoCanvas.cpp:70
size_t GetStride() const final
Get the stride (bytes per row) of the pixel buffer.
Definition CairoCanvas.cpp:78
std::unique_ptr< Path > CreatePath() const final
Create a new Path object suitable for this canvas backend.
Definition CairoCanvas.cpp:988
void SetFillColor(const ColorAttr &aColor) final
Set the fill color.
Definition CairoCanvas.cpp:102
const uint8_t * GetPixels() const final
Get a pointer to the raw pixel data.
Definition CairoCanvas.cpp:61
void Transform(const Matrix2x3 &aMatrix) final
Pre-multiply the current transformation matrix.
Definition CairoCanvas.cpp:699
double MeasureText(const std::string &aText, const std::string &aFontFamily, double aFontSize, int aFontWeight, int aFontStyle) const final
Definition CairoCanvas.cpp:460
size_t GetHeight() const final
Get the height of the canvas in pixels.
Definition CairoCanvas.cpp:74
void SetStrokeWidth(double aWidth) final
Set the stroke width.
Definition CairoCanvas.cpp:122
double GetStrokeWidth() const final
Get the current stroke width.
Definition CairoCanvas.cpp:127
void SetFillOpacity(double aWidth) final
Set the fill opacity.
Definition CairoCanvas.cpp:142
void PushGroup() final
Begin an offscreen group for filter/compositing.
Definition CairoCanvas.cpp:734
~CairoCanvas() final
Destructor. Releases Cairo resources.
Definition CairoCanvas.cpp:89
void ApplyDropShadow(double aDx, double aDy, double aStdDeviationX, double aStdDeviationY, const Color &aFloodColor, double aFloodOpacity) final
Apply a drop-shadow filter to the current group content.
Definition CairoCanvas.cpp:844
const ColorAttr & GetFillColor() const final
Get the current fill color.
Definition CairoCanvas.cpp:107
void ResetPick() final
Clear the pick buffer and reset for a new frame.
Definition CairoCanvas.cpp:934
void PopGroup() final
End an offscreen group and composite back.
Definition CairoCanvas.cpp:739
void SetClipRect(double aX, double aY, double aWidth, double aHeight) final
Set a device-space clip rectangle on both render and pick surfaces.
Definition CairoCanvas.cpp:967
void Restore() final
Restore the previously saved graphics state.
Definition CairoCanvas.cpp:721
Abstract 2D rendering surface.
Definition Canvas.hpp:40
2x3 affine transformation matrix.
Definition Matrix2x3.hpp:37
Abstract base class for renderable path data.
Definition Path.hpp:40
SVG preserveAspectRatio attribute.
Definition Attribute.hpp:44
SVG viewBox attribute value.
Definition Attribute.hpp:31
Pixel Color Union. The Color union allows access to each unsigned 8 bit RGBA color component individu...
Definition Color.hpp:185