AeonGUI
A portable video game graphic user interface library.
Loading...
Searching...
No Matches
AeonGUI::Canvas Class Referenceabstract

Abstract 2D rendering surface. More...

#include </d/a/AeonGUI/AeonGUI/include/aeongui/Canvas.hpp>

Inheritance diagram for AeonGUI::Canvas:
[legend]
Collaboration diagram for AeonGUI::Canvas:
[legend]

Classes

struct  PickBounds
 Device-space bounding box for a pick-tracked element. More...

Public Member Functions

virtual void ResizeViewport (uint32_t aWidth, uint32_t aHeight)=0
 Resize the rendering viewport.
virtual const uint8_t * GetPixels () const =0
 Get a pointer to the raw pixel data.
virtual size_t GetWidth () const =0
 Get the width of the canvas in pixels.
virtual size_t GetHeight () const =0
 Get the height of the canvas in pixels.
virtual size_t GetStride () const =0
 Get the stride (bytes per row) of the pixel buffer.
virtual void Clear ()=0
 Clear the canvas to transparent.
virtual void SetFillColor (const ColorAttr &aColor)=0
 Set the fill color.
virtual const ColorAttr & GetFillColor () const =0
 Get the current fill color.
virtual void SetStrokeColor (const ColorAttr &aColor)=0
 Set the stroke color.
virtual const ColorAttr & GetStrokeColor () const =0
 Get the current stroke color.
virtual void SetStrokeWidth (double aWidth)=0
 Set the stroke width.
virtual double GetStrokeWidth () const =0
 Get the current stroke width.
virtual void SetStrokeOpacity (double aWidth)=0
 Set the stroke opacity.
virtual double GetStrokeOpacity () const =0
 Get the current stroke opacity.
virtual void SetFillOpacity (double aWidth)=0
 Set the fill opacity.
virtual double GetFillOpacity () const =0
 Get the current fill opacity.
virtual void SetOpacity (double aWidth)=0
 Set the global opacity.
virtual double GetOpacity () const =0
 Get the current global opacity.
virtual void Draw (const Path &aPath)=0
 Draw a path using the current fill and stroke settings.
virtual 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)=0
 Draw a raster image.
virtual void DrawText (const std::string &aText, double aX, double aY, const std::string &aFontFamily, double aFontSize, int aFontWeight, int aFontStyle)=0
virtual double MeasureText (const std::string &aText, const std::string &aFontFamily, double aFontSize, int aFontWeight, int aFontStyle) const =0
virtual 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)=0
virtual void SetViewBox (const ViewBox &aViewBox, const PreserveAspectRatio &aPreserveAspectRatio)=0
 Set the SVG viewBox and preserveAspectRatio.
virtual void SetTransform (const Matrix2x3 &aMatrix)=0
 Replace the current transformation matrix.
virtual void Transform (const Matrix2x3 &aMatrix)=0
 Pre-multiply the current transformation matrix.
virtual void Save ()=0
 Save the current graphics state (transform, clipping, etc.).
virtual void Restore ()=0
 Restore the previously saved graphics state.
virtual void * GetNativeSurface () const =0
 Get the native rendering surface handle.
virtual void PushGroup ()=0
 Begin an offscreen group for filter/compositing.
virtual void PopGroup ()=0
 End an offscreen group and composite back.
virtual void ApplyDropShadow (double aDx, double aDy, double aStdDeviationX, double aStdDeviationY, const Color &aFloodColor, double aFloodOpacity)=0
 Apply a drop-shadow filter to the current group content.
void SetHitTesting (bool aHitTesting)
 Enable or disable hit-testing mode.
bool IsHitTesting () const
 Query whether the canvas is in hit-testing mode.
void SetPickId (uint8_t aPickId)
 Set the current pick ID for subsequent Draw calls.
virtual uint8_t PickAtPoint (double aX, double aY) const =0
 Read the pick ID at the given viewport coordinates.
virtual void ResetPick ()=0
 Clear the pick buffer and reset for a new frame.
virtual void SetClipRect (double aX, double aY, double aWidth, double aHeight)=0
 Set a device-space clip rectangle on both render and pick surfaces.
virtual std::unique_ptr< PathCreatePath () const =0
 Create a new Path object suitable for this canvas backend.
virtual ~Canvas ()=0
 Virtual destructor.
const PickBoundsGetPickBounds (uint8_t aId) const
 Get the cached device-space bounds for a pick ID.

Protected Attributes

bool mHitTesting {false}
 True when in hit-testing mode.
uint8_t mPickId {0}
 Current pick ID for Draw calls.
std::array< PickBounds, 256 > mPickBounds {}
 Cached device-space bounds per pick ID.

Detailed Description

Abstract 2D rendering surface.

Provides a pure virtual interface for drawing paths, images, and text onto a pixel buffer. Concrete implementations (e.g. CairoCanvas) supply the actual rendering back-end.

Member Function Documentation

◆ ApplyDropShadow()

virtual void AeonGUI::Canvas::ApplyDropShadow ( double aDx,
double aDy,
double aStdDeviationX,
double aStdDeviationY,
const Color & aFloodColor,
double aFloodOpacity )
pure virtual

Apply a drop-shadow filter to the current group content.

Must be called between PushGroup() and PopGroup(). The implementation captures the group, creates a blurred shadow, offsets it, and composites it under the original content.

Parameters
aDxHorizontal offset of the shadow.
aDyVertical offset of the shadow.
aStdDeviationXHorizontal Gaussian blur standard deviation.
aStdDeviationYVertical Gaussian blur standard deviation.
aFloodColorShadow color.
aFloodOpacityShadow opacity [0.0, 1.0].

Implemented in AeonGUI::CairoCanvas, and AeonGUI::SkiaCanvas.

◆ Clear()

virtual void AeonGUI::Canvas::Clear ( )
pure virtual

Clear the canvas to transparent.

Implemented in AeonGUI::CairoCanvas, and AeonGUI::SkiaCanvas.

◆ CreatePath()

virtual std::unique_ptr< Path > AeonGUI::Canvas::CreatePath ( ) const
pure virtual

Create a new Path object suitable for this canvas backend.

Returns
A new empty Path instance.

Implemented in AeonGUI::CairoCanvas, and AeonGUI::SkiaCanvas.

◆ Draw()

virtual void AeonGUI::Canvas::Draw ( const Path & aPath)
pure virtual

Draw a path using the current fill and stroke settings.

Parameters
aPathThe path to draw.

Implemented in AeonGUI::CairoCanvas, and AeonGUI::SkiaCanvas.

◆ DrawImage()

virtual void AeonGUI::Canvas::DrawImage ( const uint8_t * aPixels,
size_t aImageWidth,
size_t aImageHeight,
size_t aImageStride,
double aX,
double aY,
double aWidth,
double aHeight,
double aOpacity )
pure virtual

Draw a raster image.

Parameters
aPixelsPointer to source BGRA pixel data.
aImageWidthWidth of the source image in pixels.
aImageHeightHeight of the source image in pixels.
aImageStrideStride of the source image in bytes.
aXDestination X coordinate.
aYDestination Y coordinate.
aWidthDestination width in user units.
aHeightDestination height in user units.
aOpacityOpacity for the image [0.0, 1.0].

Implemented in AeonGUI::CairoCanvas, and AeonGUI::SkiaCanvas.

◆ DrawText()

virtual void AeonGUI::Canvas::DrawText ( const std::string & aText,
double aX,
double aY,
const std::string & aFontFamily,
double aFontSize,
int aFontWeight,
int aFontStyle )
pure virtual

Draw text at the given position using the specified font description and size.

Parameters
aTextThe UTF-8 text string to render.
aXThe x coordinate for the text start position.
aYThe y coordinate for the text baseline.
aFontFamilyFont family name (e.g. "sans-serif").
aFontSizeFont size in CSS pixels.
aFontWeightCSS font weight (400 = normal, 700 = bold).
aFontStyle0 = normal, 1 = italic, 2 = oblique.

Implemented in AeonGUI::CairoCanvas, and AeonGUI::SkiaCanvas.

◆ DrawTextOnPath()

virtual void AeonGUI::Canvas::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 )
pure virtual

Draw text along a path. Each glyph is positioned and rotated to follow the path.

Parameters
aTextThe UTF-8 text string to render.
aPathThe path to follow.
aStartOffsetStarting distance along the path in user units.
aFontFamilyFont family name.
aFontSizeFont size in CSS pixels.
aFontWeightCSS font weight (400 = normal, 700 = bold).
aFontStyle0 = normal, 1 = italic, 2 = oblique.
aReverseIf true, render glyph order against the path direction.
aClosedIf true, treat the path as closed for offset wrapping.

Implemented in AeonGUI::CairoCanvas, and AeonGUI::SkiaCanvas.

◆ GetFillColor()

virtual const ColorAttr & AeonGUI::Canvas::GetFillColor ( ) const
pure virtual

Get the current fill color.

Returns
Reference to the current fill color.

Implemented in AeonGUI::CairoCanvas, and AeonGUI::SkiaCanvas.

◆ GetFillOpacity()

virtual double AeonGUI::Canvas::GetFillOpacity ( ) const
pure virtual

Get the current fill opacity.

Returns
Opacity in [0.0, 1.0].

Implemented in AeonGUI::CairoCanvas, and AeonGUI::SkiaCanvas.

◆ GetHeight()

virtual size_t AeonGUI::Canvas::GetHeight ( ) const
pure virtual

Get the height of the canvas in pixels.

Returns
Height in pixels.

Implemented in AeonGUI::CairoCanvas, and AeonGUI::SkiaCanvas.

◆ GetNativeSurface()

virtual void * AeonGUI::Canvas::GetNativeSurface ( ) const
pure virtual

Get the native rendering surface handle.

Returns
Pointer to the underlying surface (e.g. cairo_surface_t).

Implemented in AeonGUI::CairoCanvas, and AeonGUI::SkiaCanvas.

◆ GetOpacity()

virtual double AeonGUI::Canvas::GetOpacity ( ) const
pure virtual

Get the current global opacity.

Returns
Opacity in [0.0, 1.0].

Implemented in AeonGUI::CairoCanvas, and AeonGUI::SkiaCanvas.

◆ GetPickBounds()

const PickBounds & AeonGUI::Canvas::GetPickBounds ( uint8_t aId) const
inline

Get the cached device-space bounds for a pick ID.

Parameters
aIdPick ID (1-255).
Returns
Reference to the cached bounds.

◆ GetPixels()

virtual const uint8_t * AeonGUI::Canvas::GetPixels ( ) const
pure virtual

Get a pointer to the raw pixel data.

Returns
Pointer to BGRA pixel data, or nullptr if empty.

Implemented in AeonGUI::CairoCanvas, and AeonGUI::SkiaCanvas.

◆ GetStride()

virtual size_t AeonGUI::Canvas::GetStride ( ) const
pure virtual

Get the stride (bytes per row) of the pixel buffer.

Returns
Stride in bytes.

Implemented in AeonGUI::CairoCanvas, and AeonGUI::SkiaCanvas.

◆ GetStrokeColor()

virtual const ColorAttr & AeonGUI::Canvas::GetStrokeColor ( ) const
pure virtual

Get the current stroke color.

Returns
Reference to the current stroke color.

Implemented in AeonGUI::CairoCanvas, and AeonGUI::SkiaCanvas.

◆ GetStrokeOpacity()

virtual double AeonGUI::Canvas::GetStrokeOpacity ( ) const
pure virtual

Get the current stroke opacity.

Returns
Opacity in [0.0, 1.0].

Implemented in AeonGUI::CairoCanvas, and AeonGUI::SkiaCanvas.

◆ GetStrokeWidth()

virtual double AeonGUI::Canvas::GetStrokeWidth ( ) const
pure virtual

Get the current stroke width.

Returns
Stroke width in user units.

Implemented in AeonGUI::CairoCanvas, and AeonGUI::SkiaCanvas.

◆ GetWidth()

virtual size_t AeonGUI::Canvas::GetWidth ( ) const
pure virtual

Get the width of the canvas in pixels.

Returns
Width in pixels.

Implemented in AeonGUI::CairoCanvas, and AeonGUI::SkiaCanvas.

◆ IsHitTesting()

bool AeonGUI::Canvas::IsHitTesting ( ) const
inline

Query whether the canvas is in hit-testing mode.

Returns
True if hit-testing is active.

◆ MeasureText()

virtual double AeonGUI::Canvas::MeasureText ( const std::string & aText,
const std::string & aFontFamily,
double aFontSize,
int aFontWeight,
int aFontStyle ) const
pure virtual

Measure the width of text with the given font parameters.

Parameters
aTextThe UTF-8 text string to measure.
aFontFamilyFont family name.
aFontSizeFont size in CSS pixels.
aFontWeightCSS font weight.
aFontStyleFont style (0=normal, 1=italic, 2=oblique).
Returns
The logical width in CSS pixels.

Implemented in AeonGUI::CairoCanvas, and AeonGUI::SkiaCanvas.

◆ PickAtPoint()

virtual uint8_t AeonGUI::Canvas::PickAtPoint ( double aX,
double aY ) const
pure virtual

Read the pick ID at the given viewport coordinates.

Parameters
aXX coordinate in viewport pixels.
aYY coordinate in viewport pixels.
Returns
Pick ID at that pixel, or 0 if empty / out of bounds.

Implemented in AeonGUI::CairoCanvas, and AeonGUI::SkiaCanvas.

◆ PopGroup()

virtual void AeonGUI::Canvas::PopGroup ( )
pure virtual

End an offscreen group and composite back.

Pops the group pushed by PushGroup() and paints it back to the underlying surface.

Implemented in AeonGUI::CairoCanvas, and AeonGUI::SkiaCanvas.

◆ PushGroup()

virtual void AeonGUI::Canvas::PushGroup ( )
pure virtual

Begin an offscreen group for filter/compositing.

All subsequent drawing is redirected to a temporary surface. Call PopGroup() to retrieve and composite the result.

Implemented in AeonGUI::CairoCanvas, and AeonGUI::SkiaCanvas.

◆ ResetPick()

virtual void AeonGUI::Canvas::ResetPick ( )
pure virtual

Clear the pick buffer and reset for a new frame.

Implemented in AeonGUI::CairoCanvas, and AeonGUI::SkiaCanvas.

◆ ResizeViewport()

virtual void AeonGUI::Canvas::ResizeViewport ( uint32_t aWidth,
uint32_t aHeight )
pure virtual

Resize the rendering viewport.

Parameters
aWidthNew width in pixels.
aHeightNew height in pixels.

Implemented in AeonGUI::CairoCanvas, and AeonGUI::SkiaCanvas.

◆ Restore()

virtual void AeonGUI::Canvas::Restore ( )
pure virtual

Restore the previously saved graphics state.

Implemented in AeonGUI::CairoCanvas, and AeonGUI::SkiaCanvas.

◆ Save()

virtual void AeonGUI::Canvas::Save ( )
pure virtual

Save the current graphics state (transform, clipping, etc.).

Implemented in AeonGUI::CairoCanvas, and AeonGUI::SkiaCanvas.

◆ SetClipRect()

virtual void AeonGUI::Canvas::SetClipRect ( double aX,
double aY,
double aWidth,
double aHeight )
pure virtual

Set a device-space clip rectangle on both render and pick surfaces.

Must be called between Save() and Restore().

Parameters
aXX of clip rect (device pixels).
aYY of clip rect (device pixels).
aWidthWidth (device pixels).
aHeightHeight (device pixels).

Implemented in AeonGUI::CairoCanvas, and AeonGUI::SkiaCanvas.

◆ SetFillColor()

virtual void AeonGUI::Canvas::SetFillColor ( const ColorAttr & aColor)
pure virtual

Set the fill color.

Parameters
aColorThe fill color to set.

Implemented in AeonGUI::CairoCanvas, and AeonGUI::SkiaCanvas.

◆ SetFillOpacity()

virtual void AeonGUI::Canvas::SetFillOpacity ( double aWidth)
pure virtual

Set the fill opacity.

Parameters
aWidthOpacity value in the range [0.0, 1.0].

Implemented in AeonGUI::CairoCanvas, and AeonGUI::SkiaCanvas.

◆ SetHitTesting()

void AeonGUI::Canvas::SetHitTesting ( bool aHitTesting)
inline

Enable or disable hit-testing mode.

When true, filter effects (PushGroup/PopGroup/ApplyDropShadow) are skipped to avoid expensive pixel processing during elementFromPoint traversals.

Parameters
aHitTestingTrue to enable hit-testing mode, false to disable.

◆ SetOpacity()

virtual void AeonGUI::Canvas::SetOpacity ( double aWidth)
pure virtual

Set the global opacity.

Parameters
aWidthOpacity value in the range [0.0, 1.0].

Implemented in AeonGUI::CairoCanvas, and AeonGUI::SkiaCanvas.

◆ SetPickId()

void AeonGUI::Canvas::SetPickId ( uint8_t aPickId)
inline

Set the current pick ID for subsequent Draw calls.

When non-zero, Draw(path) also fills the path on the internal pick buffer using this value. Set to 0 to disable pick rendering for non-geometry nodes.

Parameters
aPickIdThe pick ID to assign (0 disables pick rendering).

◆ SetStrokeColor()

virtual void AeonGUI::Canvas::SetStrokeColor ( const ColorAttr & aColor)
pure virtual

Set the stroke color.

Parameters
aColorThe stroke color to set.

Implemented in AeonGUI::CairoCanvas, and AeonGUI::SkiaCanvas.

◆ SetStrokeOpacity()

virtual void AeonGUI::Canvas::SetStrokeOpacity ( double aWidth)
pure virtual

Set the stroke opacity.

Parameters
aWidthOpacity value in the range [0.0, 1.0].

Implemented in AeonGUI::CairoCanvas, and AeonGUI::SkiaCanvas.

◆ SetStrokeWidth()

virtual void AeonGUI::Canvas::SetStrokeWidth ( double aWidth)
pure virtual

Set the stroke width.

Parameters
aWidthThe stroke width in user units.

Implemented in AeonGUI::CairoCanvas, and AeonGUI::SkiaCanvas.

◆ SetTransform()

virtual void AeonGUI::Canvas::SetTransform ( const Matrix2x3 & aMatrix)
pure virtual

Replace the current transformation matrix.

Parameters
aMatrixThe new 2x3 transformation matrix.

Implemented in AeonGUI::CairoCanvas, and AeonGUI::SkiaCanvas.

◆ SetViewBox()

virtual void AeonGUI::Canvas::SetViewBox ( const ViewBox & aViewBox,
const PreserveAspectRatio & aPreserveAspectRatio )
pure virtual

Set the SVG viewBox and preserveAspectRatio.

Parameters
aViewBoxThe viewBox rectangle.
aPreserveAspectRatioHow to align and scale.

Implemented in AeonGUI::CairoCanvas, and AeonGUI::SkiaCanvas.

◆ Transform()

virtual void AeonGUI::Canvas::Transform ( const Matrix2x3 & aMatrix)
pure virtual

Pre-multiply the current transformation matrix.

Parameters
aMatrixThe matrix to concatenate.

Implemented in AeonGUI::CairoCanvas, and AeonGUI::SkiaCanvas.


The documentation for this class was generated from the following files:
  • /d/a/AeonGUI/AeonGUI/include/aeongui/Canvas.hpp
  • /d/a/AeonGUI/AeonGUI/core/Canvas.cpp