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

Primary top-level interface for drawing to screens, off-screen buffers, or other devices. More...

#include <roo_display.h>

Public Member Functions

template<typename Display >
 DrawingContext (Display &display)
 Constructs a drawing context covering the entire display.
 
template<typename Display >
 DrawingContext (Display &display, Box bounds)
 Constructs a drawing context covering the specified bounds, relative to the display's extents. If bounds exceed the display's extents, they will be clipped accordingly, but the requested bounds will still be used for alignment purposes. For example, drawing a centered object will center it relative to the bounds(), even if they exceed the display's extents.
 
template<typename Display >
 DrawingContext (Display &display, int16_t x_offset, int16_t y_offset)
 Constructs a drawing context covering the entire display, with device coordinates offset by the specified amounts.
 
template<typename Display >
 DrawingContext (Display &display, int16_t x_offset, int16_t y_offset, Box bounds)
 Constructs a drawing context covering the specified bounds, with device coordinates offset by the specified amounts. The bounds are expressed post-translation. That is, bounds corresponding to the entire display surface would be equal to display.extents().translate(-x_offset, -y_offset). If bounds exceed the display's extents, they will be clipped accordingly, but the requested bounds will still be used for alignment purposes. For example, drawing a centered object will center it relative to the requested bounds, even if they exceed the display's extents.
 
 ~DrawingContext ()
 
const Boxbounds () const
 Returns the bounds used for alignment.
 
const uint16_t width () const
 Returns the width of the drawing context. Equivalent to bounds().width().
 
const uint16_t height () const
 Returns the height of the drawing context. Equivalent to bounds().height().
 
void setBackground (const Rasterizable *bg)
 
const RasterizablegetBackground () const
 
Color getBackgroundColor () const
 
void setBackgroundColor (Color bgcolor)
 
FillMode fillMode () const
 
void setFillMode (FillMode fill_mode)
 
BlendingMode blendingMode () const
 
void setBlendingMode (BlendingMode blending_mode)
 
void clear ()
 Clears the display, respecting the clip box, and background settings.
 
void fill (Color color)
 Fills the display with the specified color, respecting the clip box.
 
void setClipBox (const Box &clip_box)
 Sets the clip box, intersected with the maximum allowed clip box. Expressed in device coordinates.
 
void setClipBox (int16_t x0, int16_t y0, int16_t x1, int16_t y1)
 Sets the clip box, intersected with the maximum allowed clip box. Expressed in device coordinates.
 
void setClipMask (const ClipMask *clip_mask)
 
const BoxgetClipBox () const
 Returns the current clip box, in device coordinates.
 
void setTransformation (Transformation t)
 Sets a transformation to be applied to all drawn objects when converting the drawing coordinates to device coordinates.
 
const Transformationtransformation () const
 Returns the current transformation. (The identity transformation by default).
 
void setWriteOnce ()
 
bool isWriteOnce () const
 
void drawPixels (const std::function< void(ClippingBufferedPixelWriter &)> &fn, BlendingMode blending_mode=BlendingMode::kSourceOver)
 Allows to efficiently draw pixels to the context, using a buffered pixel writer (avoiding virtual calls per pixel, and allowing for batch writes). The provided function fn will be called with a ClippingBufferedPixelWriter that respects the current clip box and uses the specified blending mode.
 
void draw (const Drawable &object)
 Draws the object using its inherent coordinates. The point (0, 0) in the object's coordinates maps to (0, 0) in the context's coordinates (subject to the optional transformation).
 
void draw (const Drawable &object, int16_t dx, int16_t dy)
 Draws the object using the specified absolute offset. The point (0, 0) in the object's coordinates maps to (dx, dy) in the context's coordinates (subject to the optional transformation).
 
void draw (const Drawable &object, Alignment alignment)
 Draws the object applying the specified alignment, relative to the bounds(). For example, for with kMiddle | kCenter, the object will be centered relative to the bounds().
 
void erase (const Drawable &object)
 Analogous to draw(object), but instead of drawing, replaces all the output pixels with the background color.
 
void erase (const Drawable &object, int16_t dx, int16_t dy)
 Analogous to draw(object, dx, dy), but instead of drawing, replaces all the output pixels with the background color.
 
void erase (const Drawable &object, Alignment alignment)
 Analogous to draw(object, alignment), but instead of drawing, replaces all the output pixels with the background color.
 

Detailed Description

Primary top-level interface for drawing to screens, off-screen buffers, or other devices.

Supports rectangular clip regions, as well as arbitrary clip masks.

Able to render objects implementing the Drawable interface.

Definition at line 225 of file roo_display.h.

Constructor & Destructor Documentation

◆ DrawingContext() [1/4]

template<typename Display >
roo_display::DrawingContext::DrawingContext ( Display display)
inline

Constructs a drawing context covering the entire display.

Definition at line 229 of file roo_display.h.

◆ DrawingContext() [2/4]

template<typename Display >
roo_display::DrawingContext::DrawingContext ( Display display,
Box  bounds 
)
inline

Constructs a drawing context covering the specified bounds, relative to the display's extents. If bounds exceed the display's extents, they will be clipped accordingly, but the requested bounds will still be used for alignment purposes. For example, drawing a centered object will center it relative to the bounds(), even if they exceed the display's extents.

Definition at line 238 of file roo_display.h.

◆ DrawingContext() [3/4]

template<typename Display >
roo_display::DrawingContext::DrawingContext ( Display display,
int16_t  x_offset,
int16_t  y_offset 
)
inline

Constructs a drawing context covering the entire display, with device coordinates offset by the specified amounts.

Definition at line 244 of file roo_display.h.

◆ DrawingContext() [4/4]

template<typename Display >
roo_display::DrawingContext::DrawingContext ( Display display,
int16_t  x_offset,
int16_t  y_offset,
Box  bounds 
)
inline

Constructs a drawing context covering the specified bounds, with device coordinates offset by the specified amounts. The bounds are expressed post-translation. That is, bounds corresponding to the entire display surface would be equal to display.extents().translate(-x_offset, -y_offset). If bounds exceed the display's extents, they will be clipped accordingly, but the requested bounds will still be used for alignment purposes. For example, drawing a centered object will center it relative to the requested bounds, even if they exceed the display's extents.

Definition at line 257 of file roo_display.h.

◆ ~DrawingContext()

roo_display::DrawingContext::~DrawingContext ( )

Definition at line 160 of file roo_display.cpp.

Member Function Documentation

◆ blendingMode()

BlendingMode roo_display::DrawingContext::blendingMode ( ) const
inline

Definition at line 299 of file roo_display.h.

◆ bounds()

const Box & roo_display::DrawingContext::bounds ( ) const
inline

Returns the bounds used for alignment.

Definition at line 281 of file roo_display.h.

Referenced by draw().

◆ clear()

void roo_display::DrawingContext::clear ( )

Clears the display, respecting the clip box, and background settings.

Definition at line 105 of file roo_display.cpp.

Referenced by roo_display::Display::clear().

◆ draw() [1/3]

void roo_display::DrawingContext::draw ( const Drawable object)
inline

Draws the object using its inherent coordinates. The point (0, 0) in the object's coordinates maps to (0, 0) in the context's coordinates (subject to the optional transformation).

Definition at line 357 of file roo_display.h.

◆ draw() [2/3]

void roo_display::DrawingContext::draw ( const Drawable object,
Alignment  alignment 
)
inline

Draws the object applying the specified alignment, relative to the bounds(). For example, for with kMiddle | kCenter, the object will be centered relative to the bounds().

Definition at line 371 of file roo_display.h.

References bounds(), roo_display::Offset::dx, roo_display::Offset::dy, roo_display::Alignment::resolveOffset(), and roo_display::Transformation::transformBox().

◆ draw() [3/3]

void roo_display::DrawingContext::draw ( const Drawable object,
int16_t  dx,
int16_t  dy 
)
inline

Draws the object using the specified absolute offset. The point (0, 0) in the object's coordinates maps to (dx, dy) in the context's coordinates (subject to the optional transformation).

Definition at line 364 of file roo_display.h.

◆ drawPixels()

void roo_display::DrawingContext::drawPixels ( const std::function< void(ClippingBufferedPixelWriter &)> &  fn,
BlendingMode  blending_mode = BlendingMode::kSourceOver 
)

Allows to efficiently draw pixels to the context, using a buffered pixel writer (avoiding virtual calls per pixel, and allowing for batch writes). The provided function fn will be called with a ClippingBufferedPixelWriter that respects the current clip box and uses the specified blending mode.

Definition at line 169 of file roo_display.cpp.

References blending_mode.

◆ erase() [1/3]

void roo_display::DrawingContext::erase ( const Drawable object)

Analogous to draw(object), but instead of drawing, replaces all the output pixels with the background color.

Definition at line 247 of file roo_display.cpp.

◆ erase() [2/3]

void roo_display::DrawingContext::erase ( const Drawable object,
Alignment  alignment 
)

Analogous to draw(object, alignment), but instead of drawing, replaces all the output pixels with the background color.

Definition at line 255 of file roo_display.cpp.

◆ erase() [3/3]

void roo_display::DrawingContext::erase ( const Drawable object,
int16_t  dx,
int16_t  dy 
)

Analogous to draw(object, dx, dy), but instead of drawing, replaces all the output pixels with the background color.

Definition at line 251 of file roo_display.cpp.

◆ fill()

void roo_display::DrawingContext::fill ( Color  color)

Fills the display with the specified color, respecting the clip box.

Definition at line 95 of file roo_display.cpp.

References color.

◆ fillMode()

FillMode roo_display::DrawingContext::fillMode ( ) const
inline

Definition at line 296 of file roo_display.h.

◆ getBackground()

const Rasterizable * roo_display::DrawingContext::getBackground ( ) const
inline

Definition at line 291 of file roo_display.h.

◆ getBackgroundColor()

Color roo_display::DrawingContext::getBackgroundColor ( ) const
inline

Definition at line 293 of file roo_display.h.

◆ getClipBox()

const Box & roo_display::DrawingContext::getClipBox ( ) const
inline

Returns the current clip box, in device coordinates.

Definition at line 325 of file roo_display.h.

◆ height()

const uint16_t roo_display::DrawingContext::height ( ) const
inline

Returns the height of the drawing context. Equivalent to bounds().height().

Definition at line 288 of file roo_display.h.

References roo_display::Box::height().

◆ isWriteOnce()

bool roo_display::DrawingContext::isWriteOnce ( ) const
inline

Definition at line 344 of file roo_display.h.

◆ setBackground()

void roo_display::DrawingContext::setBackground ( const Rasterizable bg)
inline

Definition at line 290 of file roo_display.h.

◆ setBackgroundColor()

void roo_display::DrawingContext::setBackgroundColor ( Color  bgcolor)
inline

Definition at line 294 of file roo_display.h.

References bgcolor.

◆ setBlendingMode()

void roo_display::DrawingContext::setBlendingMode ( BlendingMode  blending_mode)
inline

Definition at line 300 of file roo_display.h.

References blending_mode.

◆ setClipBox() [1/2]

void roo_display::DrawingContext::setClipBox ( const Box clip_box)
inline

Sets the clip box, intersected with the maximum allowed clip box. Expressed in device coordinates.

Definition at line 312 of file roo_display.h.

References roo_display::Box::Intersect().

Referenced by setClipBox().

◆ setClipBox() [2/2]

void roo_display::DrawingContext::setClipBox ( int16_t  x0,
int16_t  y0,
int16_t  x1,
int16_t  y1 
)
inline

Sets the clip box, intersected with the maximum allowed clip box. Expressed in device coordinates.

Definition at line 318 of file roo_display.h.

References setClipBox().

◆ setClipMask()

void roo_display::DrawingContext::setClipMask ( const ClipMask clip_mask)
inline

Definition at line 322 of file roo_display.h.

◆ setFillMode()

void roo_display::DrawingContext::setFillMode ( FillMode  fill_mode)
inline

Definition at line 297 of file roo_display.h.

References fill_mode.

◆ setTransformation()

void roo_display::DrawingContext::setTransformation ( Transformation  t)
inline

Sets a transformation to be applied to all drawn objects when converting the drawing coordinates to device coordinates.

Definition at line 333 of file roo_display.h.

References roo_display::Transformation::is_rescaled(), roo_display::Transformation::is_translated(), and roo_display::Transformation::xy_swap().

◆ setWriteOnce()

void roo_display::DrawingContext::setWriteOnce ( )

Definition at line 162 of file roo_display.cpp.

◆ transformation()

const Transformation & roo_display::DrawingContext::transformation ( ) const
inline

Returns the current transformation. (The identity transformation by default).

Definition at line 340 of file roo_display.h.

◆ width()

const uint16_t roo_display::DrawingContext::width ( ) const
inline

Returns the width of the drawing context. Equivalent to bounds().width().

Definition at line 284 of file roo_display.h.

References roo_display::Box::width().


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