1#ifndef GEMPYRE_GRAPHICS_H
2#define GEMPYRE_GRAPHICS_H
4#include <initializer_list>
26 #define GGEMPYRE_EX __declspec( dllexport )
38using CanvasDataPtr = std::shared_ptr<CanvasData>;
44 using Command = std::variant<std::string, double, int>;
88 std::string
add_image(std::string_view url,
const std::function<
void (std::string_view
id)>& loaded =
nullptr);
141 void paint(
const CanvasDataPtr& canvas,
int x,
int y,
bool as_draw);
143 CanvasDataPtr m_tile{};
177 return push({
"arc", x, y, r, sAngle, eAngle});}
179 FrameComposer ellipse(
double x,
double y,
double radiusX,
double radiusY,
double rotation,
double startAngle,
double endAngle) {
180 return push({
"ellipse", x, y, radiusX, radiusY, rotation, startAngle, endAngle});}
191 return push({
"bezierCurveTo", cp1x, cp1y, cp2x, cp2y, x, y});}
194 return push({
"quadraticCurveTo", cpx, cpy, x, y});}
197 return push({
"arcTo", x1, y1, x2, y2, radius});}
231 FrameComposer draw_image(std::string_view
id,
double x,
double y,
double w,
double h) {
return push({
"drawImageRect", std::string{
id}, x, y, w, h});}
233 FrameComposer draw_image(std::string_view
id,
const Gempyre::Element::Rect& clip,
const Gempyre::Element::Rect&
rect) {
return push({
"drawImageClip", std::string{
id}, clip.
x, clip.
y, clip.
width, clip.
height,
rect.x,
rect.y,
rect.width,
rect.height});}
235 FrameComposer draw_image(std::string_view
id,
double cx,
double cy,
double cw,
double ch,
double x,
double y,
double w,
double h) {
return push({
"drawImageClip", std::string{
id}, cx, cy, cw, ch, x, y, w, h});}
241 FrameComposer push(
const std::initializer_list<Gempyre::CanvasElement::Command>& list) {m_composition.insert(m_composition.end(), list);
return *
this;}
Bitmap for Gempyre Graphics.
Definition gempyre_bitmap.h:242
Graphics element.
Definition gempyre_graphics.h:41
CanvasElement(Ui &ui, std::string_view id, const Element &parent)
Constructor to create a new CanvasElement.
CanvasElement(const CanvasElement &other)
Copy constructor.
std::variant< std::string, double, int > Command
Canvas draw command type.
Definition gempyre_graphics.h:44
void draw(int x, int y, const Bitmap &bmp)
Draw bitmap at position.
CanvasElement(Ui &ui, const Element &parent)
Constructor to create a new CanvasElement.
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.
void draw(const FrameComposer &frameComposer)
Draw Frame Composer.
CanvasElement(Ui &ui, std::string_view id)
Constructor of canvas id.
void paint_image(std::string_view imageId, int x, int y, const Element::Rect &clippingRect={0, 0, 0, 0}) const
Draw image at position.
void draw(const Bitmap &bmp)
Draw bitmap.
Definition gempyre_graphics.h:115
std::function< void()> DrawCallback
Function type for draw notifies.
Definition gempyre_graphics.h:48
CanvasElement & operator=(const CanvasElement &other)
Copy operator.
void erase(bool resized=false)
erase bitmap
void draw_completed(const DrawCallback &drawCompletedCallback, DrawNotify kick=DrawNotify::NoKick)
Set a callback to be called after the draw.
DrawNotify
set initial draw,
Definition gempyre_graphics.h:51
~CanvasElement()
Destructor.
CanvasElement & operator=(CanvasElement &&other)
Move operator.
void paint_image(std::string_view imageId, const Element::Rect &targetRect, const Element::Rect &clippingRect={0, 0, 0, 0}) const
Draw image in rectangle.
void draw(const CommandList &canvasCommands)
Draw command list - please prefer.
CanvasElement(CanvasElement &&other)
Move constructor.
std::vector< Command > CommandList
List of Canvas draw commands.
Definition gempyre_graphics.h:46
Represents all HTML elements on UI.
Definition gempyre.h:84
wrap up Javascript draw commands.
Definition gempyre_graphics.h:149
FrameComposer restore()
Visit the Mozilla documentation
Definition gempyre_graphics.h:219
FrameComposer fill_rect(double x, double y, double w, double h)
Visit the Mozilla documentation
Definition gempyre_graphics.h:170
FrameComposer stroke_rect(double x, double y, double w, double h)
Visit the Mozilla documentation
Definition gempyre_graphics.h:162
FrameComposer clear_rect(const Gempyre::Element::Rect &r)
Visit the Mozilla documentation
Definition gempyre_graphics.h:164
FrameComposer translate(double x, double y)
Visit the Mozilla documentation
Definition gempyre_graphics.h:223
FrameComposer arc_to(double x1, double y1, double x2, double y2, double radius)
Visit the Mozilla documentation
Definition gempyre_graphics.h:196
FrameComposer fill_rect(const Gempyre::Element::Rect &r)
Visit the Mozilla documentation
Definition gempyre_graphics.h:168
FrameComposer scale(const double x, double y)
Visit the Mozilla documentation
Definition gempyre_graphics.h:225
FrameComposer begin_path()
Visit the Mozilla documentation
Definition gempyre_graphics.h:182
FrameComposer fill_style(std::string_view color)
Visit the Mozilla documentation
Definition gempyre_graphics.h:207
FrameComposer save()
Visit the Mozilla documentation
Definition gempyre_graphics.h:217
FrameComposer draw_image(std::string_view id, double x, double y, double w, double h)
Visit the Mozilla documentation
Definition gempyre_graphics.h:231
FrameComposer line_to(double x, double y)
Visit the Mozilla documentation
Definition gempyre_graphics.h:186
FrameComposer font(std::string_view style)
Visit the Mozilla documentation
Definition gempyre_graphics.h:213
FrameComposer bezier_curve_to(double cp1x, double cp1y, double cp2x, double cp2y, double x, double y)
Visit the Mozilla documentation
Definition gempyre_graphics.h:190
FrameComposer text_align(std::string_view align)
Visit the Mozilla documentation
Definition gempyre_graphics.h:215
FrameComposer arc(double x, double y, double r, double sAngle, double eAngle)
Visit the Mozilla documentation
Definition gempyre_graphics.h:176
FrameComposer stroke_style(std::string_view color)
Visit the Mozilla documentation
Definition gempyre_graphics.h:209
FrameComposer quadratic_curve_to(double cpx, double cpy, double x, double y)
Visit the Mozilla documentation
Definition gempyre_graphics.h:193
FrameComposer stroke()
Visit the Mozilla documentation
Definition gempyre_graphics.h:203
FrameComposer line_width(double width)
Visit the Mozilla documentation
Definition gempyre_graphics.h:211
FrameComposer(const FrameComposer &other)=default
Copy constructor.
FrameComposer draw_image(std::string_view id, double x, double y)
Visit the Mozilla documentation
Definition gempyre_graphics.h:227
FrameComposer fill()
Visit the Mozilla documentation
Definition gempyre_graphics.h:205
FrameComposer fill_text(std::string_view text, double x, double y)
Visit the Mozilla documentation
Definition gempyre_graphics.h:172
FrameComposer clear_rect(double x, double y, double w, double h)
Visit the Mozilla documentation
Definition gempyre_graphics.h:166
FrameComposer ellipse(double x, double y, double radiusX, double radiusY, double rotation, double startAngle, double endAngle)
Visit the Mozilla documentation
Definition gempyre_graphics.h:179
FrameComposer draw_image(std::string_view id, double cx, double cy, double cw, double ch, double x, double y, double w, double h)
Visit the Mozilla documentation
Definition gempyre_graphics.h:235
FrameComposer move_to(double x, double y)
Visit the Mozilla documentation
Definition gempyre_graphics.h:188
FrameComposer rect(const Gempyre::Element::Rect &r)
Visit the Mozilla documentation
Definition gempyre_graphics.h:199
FrameComposer close_path()
Visit the Mozilla documentation
Definition gempyre_graphics.h:184
FrameComposer draw_image(std::string_view id, const Gempyre::Element::Rect &clip, const Gempyre::Element::Rect &rect)
Visit the Mozilla documentation
Definition gempyre_graphics.h:233
FrameComposer stroke_text(std::string_view text, double x, double y)
Visit the Mozilla documentation
Definition gempyre_graphics.h:174
const Gempyre::CanvasElement::CommandList & composed() const
Get command list composed.
Definition gempyre_graphics.h:239
FrameComposer rotate(double angle)
Visit the Mozilla documentation
Definition gempyre_graphics.h:221
FrameComposer(Gempyre::CanvasElement::CommandList &lst)
Construct from CommandList.
Definition gempyre_graphics.h:154
FrameComposer()
Constructor.
Definition gempyre_graphics.h:152
FrameComposer draw_image(std::string_view id, const Gempyre::Element::Rect &rect)
Visit the Mozilla documentation
Definition gempyre_graphics.h:229
FrameComposer text_baseline(std::string_view textBaseline)
Visit the Mozilla documentation
Definition gempyre_graphics.h:237
FrameComposer(FrameComposer &&other)=default
Move constructor.
FrameComposer stroke_rect(const Gempyre::Element::Rect &r)
Visit the Mozilla documentation
Definition gempyre_graphics.h:160
FrameComposer rect(double x, double y, double w, double h)
Visit the Mozilla documentation
Definition gempyre_graphics.h:201
The application UI.
Definition gempyre.h:260
Rect.
Definition gempyre_types.h:24
int width
rectangle width.
Definition gempyre_types.h:30
int x
rectangle x coordinate.
Definition gempyre_types.h:26
int y
rectangle y coordinate.
Definition gempyre_types.h:28
int height
rectangle height.
Definition gempyre_types.h:32