gempyre  1.7.1
Gempyre::CanvasElement Class Reference

Graphics element. More...

#include <gempyre_graphics.h>

Inheritance diagram for Gempyre::CanvasElement:
[legend]
Collaboration diagram for Gempyre::CanvasElement:
[legend]

Public Types

enum class  DrawNotify { NoKick , Kick }
 set initial draw, More...
 
using Command = std::variant< std::string, double, int >
 Canvas draw command type.
 
using CommandList = std::vector< Command >
 List of Canvas draw commands.
 
using DrawCallback = std::function< void()>
 Function type for draw notifies. More...
 
- Public Types inherited from Gempyre::Element
using Attributes = std::unordered_map< std::string, std::string >
 Attribute key, value pairs.
 
using Values = std::unordered_map< std::string, std::string >
 Value key, value pairs.
 
using Elements = std::vector< Element >
 Vector of Elements.
 
using SubscribeFunction = std::function< void(const Event &)>
 Callback function for event subscriptions. More...
 
using Rect = Gempyre::Rect
 compatibility More...
 

Public Member Functions

 ~CanvasElement ()
 Destructor.
 
 CanvasElement (const CanvasElement &other)
 Copy constructor.
 
 CanvasElement (CanvasElement &&other)
 Move constructor.
 
 CanvasElement (Ui &ui, std::string_view id)
 Constructor of canvas id. More...
 
 CanvasElement (Ui &ui, std::string_view id, const Element &parent)
 Constructor to create a new CanvasElement. More...
 
 CanvasElement (Ui &ui, const Element &parent)
 Constructor to create a new CanvasElement. More...
 
CanvasElementoperator= (const CanvasElement &other)
 Copy operator.
 
CanvasElementoperator= (CanvasElement &&other)
 Move operator.
 
std::string add_image (std::string_view url, const std::function< void(std::string_view id)> &loaded=nullptr)
 Add an image into HTML DOM tree. More...
 
void paint_image (std::string_view imageId, int x, int y, const Element::Rect &clippingRect={0, 0, 0, 0}) const
 Draw image at position. More...
 
void paint_image (std::string_view imageId, const Element::Rect &targetRect, const Element::Rect &clippingRect={0, 0, 0, 0}) const
 Draw image in rectangle. More...
 
void draw (const CommandList &canvasCommands)
 Draw command list - please prefer. More...
 
void draw (const FrameComposer &frameComposer)
 Draw Frame Composer. More...
 
void draw (const Bitmap &bmp)
 Draw bitmap. More...
 
void draw (int x, int y, const Bitmap &bmp)
 Draw bitmap at position. More...
 
void draw_completed (const DrawCallback &drawCompletedCallback, DrawNotify kick=DrawNotify::NoKick)
 Set a callback to be called after the draw. More...
 
void erase (bool resized=false)
 erase bitmap More...
 
- Public Member Functions inherited from Gempyre::Element
 Element (const Element &other)=default
 Copy constructor.
 
 Element (Element &&other)=default
 Move constructor.
 
Elementoperator= (const Element &other)
 Copy operator.
 
Elementoperator= (Element &&other)
 Move operator.
 
 Element (Ui &ui, std::string_view id)
 Constructor for existing elements. More...
 
 Element (Ui &ui, std::string_view id, std::string_view htmlElement, const Element &parent)
 Constructor for exiting elements. More...
 
 Element (Ui &ui, std::string_view htmlElement, const Element &parent)
 Constructor for exiting elements. More...
 
virtual ~Element ()
 Destructor.
 
const Uiui () const
 Get Ui.
 
Uiui ()
 Get Ui.
 
std::string id () const
 Get id of element.
 
Elementsubscribe (std::string_view name, const SubscribeFunction &handler, const std::vector< std::string > &properties={}, const std::chrono::milliseconds &throttle=0ms)
 Subscribe UI event. More...
 
Elementset_html (std::string_view htmlText)
 Set HTML text value of the element. More...
 
HtmlStream html_stream ()
 get a stream that writes to html part of this element More...
 
Elementset_attribute (std::string_view attr, std::string_view value)
 Set HTML a attribute of this element. More...
 
Elementset_attribute (std::string_view attr)
 Set HTML a attribute of this element. More...
 
std::optional< Attributesattributes () const
 Get this element attributes.
 
Elementset_style (std::string_view style, std::string_view value)
 Set CSS style of this element. More...
 
Elementremove_attribute (std::string_view attr)
 Remove attribute. More...
 
std::optional< Valuesstyles (const std::vector< std::string > &keys) const
 Get element styles. More...
 
std::optional< Elementschildren () const
 Get element children.
 
std::optional< Valuesvalues () const
 Applies to form elements only - receive values bound to the element.
 
std::optional< std::string > html () const
 Get HTML value bound to this element (does not apply all elements)
 
void remove ()
 Remove this element from UI.
 
std::optional< std::string > type () const
 Get this element type, mostly a HTML tag.
 
std::optional< Rectrect () const
 Get this element UI rect. I.e area it occupies on screen (if applicable)
 
std::optional< Elementparent () const
 Parent of this element. If query fails, element is root or parent id is not set, nullopt is returned.
 

Friends

class Bitmap
 

Detailed Description

Graphics element.

Member Typedef Documentation

◆ DrawCallback

using Gempyre::CanvasElement::DrawCallback = std::function<void()>

Function type for draw notifies.

See also
CanvasElement::draw_completed and
DrawNotify.

Member Enumeration Documentation

◆ DrawNotify

Constructor & Destructor Documentation

◆ CanvasElement() [1/3]

Gempyre::CanvasElement::CanvasElement ( Ui ui,
std::string_view  id 
)

Constructor of canvas id.

Parameters
uiref.
idHTML id, should be canvas.

◆ CanvasElement() [2/3]

Gempyre::CanvasElement::CanvasElement ( Ui ui,
std::string_view  id,
const Element parent 
)

Constructor to create a new CanvasElement.

Parameters
uiref
idHTML id
parentparent element

◆ CanvasElement() [3/3]

Gempyre::CanvasElement::CanvasElement ( Ui ui,
const Element parent 
)

Constructor to create a new CanvasElement.

Parameters
uiref
parentparent element

Member Function Documentation

◆ add_image()

std::string Gempyre::CanvasElement::add_image ( std::string_view  url,
const std::function< void(std::string_view id)> &  loaded = nullptr 
)

Add an image into HTML DOM tree.

Parameters
urladdress of image, can be either a resource or any http url.
loadedcallback called when image is loaded.
Returns
image id.

◆ draw() [1/4]

void Gempyre::CanvasElement::draw ( const Bitmap bmp)
inline

Draw bitmap.

Parameters
bmp

◆ draw() [2/4]

void Gempyre::CanvasElement::draw ( const CommandList canvasCommands)

Draw command list - please prefer.

See also
draw(FrameComposer)
Parameters
canvasCommands

◆ draw() [3/4]

void Gempyre::CanvasElement::draw ( const FrameComposer frameComposer)

Draw Frame Composer.

Parameters
frameComposer

◆ draw() [4/4]

void Gempyre::CanvasElement::draw ( int  x,
int  y,
const Bitmap bmp 
)

Draw bitmap at position.

Parameters
x
y
bmp

◆ draw_completed()

void Gempyre::CanvasElement::draw_completed ( const DrawCallback drawCompletedCallback,
DrawNotify  kick = DrawNotify::NoKick 
)

Set a callback to be called after the draw.

Parameters
drawCompletedCallback- function called after draw.
kick- optional whether callback is called 1st time automatically.
  • When doing animation or frequent drawing, please do no call draw functions inside timer function. The preferred way is to to do animation in timer function, but use draw_completed to do the actual drawing. draw_completed do drawing in the optimal frequency (as fast the system can do it without consuming all CPU).
    Note
    canvas_element.draw_completed([this]() {draw_frame();}, Gempyre::CanvasElement::DrawNotify::Kick);
    ui.start_periodic(50ms, [this]() {animate();});
    const Ui & ui() const
    Get Ui.
    Definition: gempyre.h:127
    TimerId start_periodic(const std::chrono::milliseconds &ms, const std::function< void(TimerId id)> &timerFunc)
    Start a periodic timer.

◆ erase()

void Gempyre::CanvasElement::erase ( bool  resized = false)

erase bitmap

Parameters
resized- make an explicit query to ask canvas current size

◆ paint_image() [1/2]

void Gempyre::CanvasElement::paint_image ( std::string_view  imageId,
const Element::Rect targetRect,
const Element::Rect clippingRect = {0, 0, 0, 0} 
) const

Draw image in rectangle.

Parameters
imageIdimage id.
targetRectimage is resized in the rectangle.
clippingRectoptional image clipping rectangle.

paint image does not call draw_completed callback.

◆ paint_image() [2/2]

void Gempyre::CanvasElement::paint_image ( std::string_view  imageId,
int  x,
int  y,
const Element::Rect clippingRect = {0, 0, 0, 0} 
) const

Draw image at position.

Parameters
imageIdimage id.
ximage x coordinate.
yimage y coordinate.
clippingRectoptional image clipping rectangle.

paint image does not call draw_completed callback.


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