roo_display
API Documentation for roo_display
Loading...
Searching...
No Matches
roo_display::Surface Class Reference

Low-level handle used to draw to an underlying device. More...

#include <drawable.h>

Public Member Functions

 Surface (DisplayOutput &out, int16_t dx, int16_t dy, Box clip, bool is_write_once, Color bg=color::Transparent, FillMode fill_mode=FillMode::kVisible, BlendingMode blending_mode=BlendingMode::kSourceOver)
 Create a surface targeting a device output.
 
 Surface (DisplayOutput *out, Box clip, bool is_write_once, Color bg=color::Transparent, FillMode fill_mode=FillMode::kVisible, BlendingMode blending_mode=BlendingMode::kSourceOver)
 Create a surface targeting a device output with no offset.
 
 Surface (Surface &&other)=default
 
 Surface (const Surface &other)=default
 
DisplayOutputout () const
 Return the device output.
 
void set_out (DisplayOutput *out)
 Replace the output device pointer.
 
int16_t dx () const
 Return the x offset to apply to drawn objects.
 
int16_t dy () const
 Return the y offset to apply to drawn objects.
 
bool is_write_once () const
 Return whether this surface is write-once.
 
const Boxclip_box () const
 Return the clip box in device coordinates (independent of offsets).
 
void set_clip_box (const Box &clip_box)
 Set the clip box in device coordinates.
 
Color bgcolor () const
 Return the background color used for blending.
 
void set_bgcolor (Color bgcolor)
 Set the background color used for blending.
 
FillMode fill_mode () const
 Return the fill mode the drawable should observe. FillMode::kVisible If FillMode::kExtents, the drawable must fill its entire (clipped) extents even if some pixels are completely transparent. If FillMode::kVisible, the drawable may omit fully transparent pixels. This assumes the appropriate background has been pre-applied.
 
void set_fill_mode (FillMode fill_mode)
 Set the fill mode for drawables.
 
BlendingMode blending_mode () const
 Return the default blending mode for drawing.
 
void set_blending_mode (BlendingMode blending_mode)
 Set the default blending mode.
 
void set_dx (int16_t dx)
 Set the x offset applied to drawables.
 
void set_dy (int16_t dy)
 Set the y offset applied to drawables.
 
void drawObject (const Drawable &object) const
 Draw a drawable object to this surface.
 
void drawObject (const Drawable &object, int16_t dx, int16_t dy) const
 Draw a drawable object with an additional offset.
 
Box::ClipResult clipToExtents (Box extents)
 Clip the given extents to the surface clip box.
 

Friends

class DrawingContext
 

Detailed Description

Low-level handle used to draw to an underlying device.

This is passed by the library to Drawable::drawTo(); do not create it directly.

The device uses absolute coordinates starting at (0, 0). To translate an object's extents into device coordinates, apply the surface offsets:

extents.translate(s.dx(), s.dy())

Constrain to clip_box() when drawing:

Box::Intersect(s.clip_box(), extents.translate(s.dx(), s.dy()))

To quickly reject objects outside the clip box:

Box bounds = Box::Intersect(s.clip_box(), extents.translate(s.dx(), s.dy())); if (bounds.empty()) return;

To compute clipped bounds in object coordinates:

Box clipped = Box::Intersect(s.clip_box().translate(-s.dx(), -s.dy()), extents);

Definition at line 60 of file drawable.h.

Constructor & Destructor Documentation

◆ Surface() [1/4]

roo_display::Surface::Surface ( DisplayOutput out,
int16_t  dx,
int16_t  dy,
Box  clip,
bool  is_write_once,
Color  bg = color::Transparent,
FillMode  fill_mode = FillMode::kVisible,
BlendingMode  blending_mode = BlendingMode::kSourceOver 
)
inline

Create a surface targeting a device output.

Parameters
outOutput device.
dxX offset to apply to drawn objects.
dyY offset to apply to drawn objects.
clipClip box in device coordinates.
is_write_onceWhether this surface is write-once.
bgBackground color used for blending.
fill_modeFill behavior for transparent pixels.
blending_modeDefaFillMode::kVisiblee.

Definition at line 72 of file drawable.h.

References blending_mode(), and roo_display::kSource.

◆ Surface() [2/4]

roo_display::Surface::Surface ( DisplayOutput out,
Box  clip,
bool  is_write_once,
Color  bg = color::Transparent,
FillMode  fill_mode = FillMode::kVisible,
BlendingMode  blending_mode = BlendingMode::kSourceOver 
)
inline

Create a surface targeting a device output with no offset.

Parameters
outOutput device.
clipClip box in device coordinates.
is_write_onceWhether this surface is write-once.
bgBackground color used for blending.
fill_modeFill behavior for transparent pixels.FillMode::kVisible
blending_modeDefault blending mode.

Definition at line 97 of file drawable.h.

References blending_mode(), roo_display::kSource, roo_display::kSourceOver, and roo_display::kSourceOverOpaque.

◆ Surface() [3/4]

roo_display::Surface::Surface ( Surface &&  other)
default

◆ Surface() [4/4]

roo_display::Surface::Surface ( const Surface other)
default

Member Function Documentation

◆ bgcolor()

Color roo_display::Surface::bgcolor ( ) const
inline

Return the background color used for blending.

Definition at line 140 of file drawable.h.

Referenced by set_bgcolor().

◆ blending_mode()

BlendingMode roo_display::Surface::blending_mode ( ) const
inline

Return the default blending mode for drawing.

If the mode is BlendingMode::kSourceOver, a drawable may replace it with BlendingMode::kSource when all pixels it writes are fully opaque. If an opaque background is specified, BlendingMode::kSourceOver is automatically replaced with BlendingMode::kSource.

Definition at line 162 of file drawable.h.

Referenced by set_blending_mode(), Surface(), and Surface().

◆ clip_box()

const Box & roo_display::Surface::clip_box ( ) const
inline

Return the clip box in device coordinates (independent of offsets).

Definition at line 134 of file drawable.h.

Referenced by roo_display::png_draw(), and set_clip_box().

◆ clipToExtents()

Box::ClipResult roo_display::Surface::clipToExtents ( Box  extents)
inline

Clip the given extents to the surface clip box.

Definition at line 194 of file drawable.h.

References roo_display::Box::clip(), and roo_display::Box::translate().

◆ drawObject() [1/2]

void roo_display::Surface::drawObject ( const Drawable object) const
inline

Draw a drawable object to this surface.

Intended for custom Drawable implementations to draw child objects.

Definition at line 278 of file drawable.h.

References roo_display::Box::kEmpty.

Referenced by drawObject(), and roo_display::png_draw().

◆ drawObject() [2/2]

void roo_display::Surface::drawObject ( const Drawable object,
int16_t  dx,
int16_t  dy 
) const
inline

Draw a drawable object with an additional offset.

Convenience wrapper around drawObject().

Definition at line 182 of file drawable.h.

References drawObject(), dx(), and dy().

◆ dx()

int16_t roo_display::Surface::dx ( ) const
inline

Return the x offset to apply to drawn objects.

Definition at line 125 of file drawable.h.

Referenced by drawObject(), and set_dx().

◆ dy()

int16_t roo_display::Surface::dy ( ) const
inline

Return the y offset to apply to drawn objects.

Definition at line 128 of file drawable.h.

Referenced by drawObject(), roo_display::png_draw(), and set_dy().

◆ fill_mode()

FillMode roo_display::Surface::fill_mode ( ) const
inline

Return the fill mode the drawable should observe. FillMode::kVisible If FillMode::kExtents, the drawable must fill its entire (clipped) extents even if some pixels are completely transparent. If FillMode::kVisible, the drawable may omit fully transparent pixels. This assumes the appropriate background has been pre-applied.

Definition at line 151 of file drawable.h.

Referenced by set_fill_mode().

◆ is_write_once()

bool roo_display::Surface::is_write_once ( ) const
inline

Return whether this surface is write-once.

Definition at line 131 of file drawable.h.

◆ out()

DisplayOutput & roo_display::Surface::out ( ) const
inline

Return the device output.

Definition at line 119 of file drawable.h.

Referenced by roo_display::png_draw(), and set_out().

◆ set_bgcolor()

void roo_display::Surface::set_bgcolor ( Color  bgcolor)
inline

Set the background color used for blending.

Definition at line 143 of file drawable.h.

References bgcolor().

◆ set_blending_mode()

void roo_display::Surface::set_blending_mode ( BlendingMode  blending_mode)
inline

Set the default blending mode.

Definition at line 165 of file drawable.h.

References blending_mode().

◆ set_clip_box()

void roo_display::Surface::set_clip_box ( const Box clip_box)
inline

Set the clip box in device coordinates.

Definition at line 137 of file drawable.h.

References clip_box().

◆ set_dx()

void roo_display::Surface::set_dx ( int16_t  dx)
inline

Set the x offset applied to drawables.

Definition at line 170 of file drawable.h.

References dx().

◆ set_dy()

void roo_display::Surface::set_dy ( int16_t  dy)
inline

Set the y offset applied to drawables.

Definition at line 172 of file drawable.h.

References dy().

◆ set_fill_mode()

void roo_display::Surface::set_fill_mode ( FillMode  fill_mode)
inline

Set the fill mode for drawables.

Definition at line 154 of file drawable.h.

References fill_mode().

◆ set_out()

void roo_display::Surface::set_out ( DisplayOutput out)
inline

Replace the output device pointer.

Definition at line 122 of file drawable.h.

References out().

Friends And Related Symbol Documentation

◆ DrawingContext

Definition at line 199 of file drawable.h.


The documentation for this class was generated from the following file: