12 #ifndef EMP_WEB_CANVAS_H 13 #define EMP_WEB_CANVAS_H 17 #include "../base/vector.h" 18 #include "../geometry/Circle2D.h" 45 std::string
TypeName()
const override {
return "CanvasInfo"; }
49 virtual void GetHTML(std::stringstream & HTML)
override {
51 HTML <<
"<canvas id=\"" <<
id 52 <<
"\" width=\"" << width
53 <<
"\" height=\"" << height <<
"\">";
61 var cname = Pointer_stringify($0);
62 var canvas = document.getElementById(cname);
63 emp_i.ctx = canvas.getContext(
'2d');
71 for (
auto & a : actions) a->Apply();
84 for (
auto * a : actions)
delete a;
90 virtual std::string
GetType()
override {
return "web::CanvasInfo"; }
103 Canvas(
double w,
double h,
const std::string & in_id=
"")
130 template <
typename... Ts>
136 template <
typename... Ts>
144 template <
typename... Ts>
150 template <
typename... Ts>
151 Canvas &
Rect(
double x,
double y,
double w,
double h, Ts &&... vals) {
157 template <
typename... Ts>
163 template <
typename... Ts>
171 template <
typename... Ts>
172 Canvas &
Line(
double x1,
double y1,
double x2,
double y2, Ts &&... vals) {
177 template <
typename... Ts>
184 template <
typename... Ts>
192 template <
typename... Ts>
198 template <
typename... Ts>
206 template <
typename... Ts>
208 auto * ctext =
new CanvasText(p, std::forward<Ts>(vals)...);
214 template <
typename... Ts>
216 auto * ctext =
new CanvasText({x, y}, std::forward<Ts>(vals)...);
230 const std::string & fc=
"",
const std::string & lc=
"") {
Canvas & Text(double x, double y, Ts &&...vals)
Definition: Canvas.h:199
Define an arbitrary shape to draw on a canvas (base clase)
Definition: CanvasShape.h:31
void SetHeight(double h)
Set a new height for this Canvas.
Definition: Canvas.h:123
CanvasInfo(const std::string &in_id="")
Definition: Canvas.h:40
virtual bool IsCanvasInfo() const override
Definition: Canvas.h:47
Canvas & Rect(double x, double y, double w, double h, Ts &&...vals)
Definition: Canvas.h:151
Canvas & Clear()
Clear everything off of this canvas.
Definition: Canvas.h:254
Rotate the entire canvas for subsequent drawings.
Definition: CanvasAction.h:90
Canvas & Circle(double _x, double _y, double _r, Ts &&...vals)
Definition: Canvas.h:137
A line segment on the canvas.
Definition: CanvasShape.h:170
Canvas & Line(emp::Point p1, emp::Point p2, Ts &&...vals)
Definition: Canvas.h:178
const CanvasInfo * Info() const
Definition: Canvas.h:97
Clear a rectangular area in a canvas.
Definition: CanvasShape.h:117
Definition: CanvasShape.h:197
Canvas & Circle(Point center, double _r, Ts &&...vals)
Definition: Canvas.h:131
virtual void Apply()=0
Apply current action to emp_i.ctx.
Define a base class for all actions that can be done to widgets, plus simple actions.
void AddAction(CanvasAction *new_action)
Definition: Canvas.h:75
virtual void GetHTML(std::stringstream &HTML) override
Definition: Canvas.h:49
void push_back(PB_Ts &&...args)
Definition: vector.h:189
Canvas & Font(const std::string font)
Update the default font for text.
Definition: Canvas.h:223
Canvas & CenterText(double x, double y, Ts &&...vals)
Definition: Canvas.h:215
Canvas & Line(double x1, double y1, double x2, double y2, Ts &&...vals)
Add a Line from x1,y1 to x2,y2. Optional face color and line color.
Definition: Canvas.h:172
Change the default font to be used.
Definition: CanvasAction.h:106
Canvas & Image(const emp::RawImage &image, Point corner, Ts &&...vals)
Add an Image to this canvas at x,y with width w and heigh h.
Definition: Canvas.h:158
virtual ~CanvasInfo()
Definition: Canvas.h:43
Canvas(const Widget &in)
Definition: Canvas.h:113
CanvasInfo * Info()
Definition: Canvas.h:96
Canvas()
Definition: Canvas.h:114
double height
pixel height of the canvas.
Definition: Canvas.h:36
Canvas & MultiLine(emp::Point p1, const emp::vector< emp::Point > &points, Ts &&...vals)
Add a Line from x1,y1 to x2,y2. Optional face color and line color.
Definition: Canvas.h:185
Manage an HTML Canvas object.
Definition: Canvas.h:27
Canvas(double w, double h, const std::string &in_id="")
Create a new canvas with the specified size and optional HTML identifier.
Definition: Canvas.h:103
Base class to maintain canvas actions.
Definition: CanvasAction.h:33
void TargetCanvas()
Definition: Canvas.h:59
Canvas(CanvasInfo *in_info)
Definition: Canvas.h:99
If we are in emscripten, make sure to include the header.
Definition: array.h:37
Change the default font to be used.
Definition: CanvasAction.h:121
Build a debug wrapper emp::vector around std::vector.
Definition: vector.h:42
Canvas & Clear(const std::string &bg_color)
Clear to a specific background color.
Definition: Canvas.h:261
double width
pixel width of the canvas.
Definition: Canvas.h:35
Canvas & Text(emp::Point p, Ts &&...vals)
Definition: Canvas.h:193
Canvas & StrokeColor(std::string c)
Change the default stroke color.
Definition: Canvas.h:242
#define emp_assert(...)
Definition: assert.h:199
double GetWidth() const
Get the pixel width of this Canvas.
Definition: Canvas.h:119
virtual CanvasAction * Clone() const =0
Make a copy of the current action.
Canvas & Draw(const CanvasShape &shape)
Draw an arbitrary shape onto this canvas.
Definition: Canvas.h:236
void SetWidth(double w)
Set a new width for this Canvas.
Definition: Canvas.h:122
Text to be written on a canvas.
Definition: CanvasShape.h:227
Define simple shapes to draw on a canvas.
virtual std::string GetType() override
Definition: Canvas.h:90
void SetSize(double w, double h)
Set Canvas size.
Definition: Canvas.h:126
emp::vector< CanvasAction * > actions
Definition: Canvas.h:38
Canvas(const Canvas &in)
Link to an existing canvas.
Definition: Canvas.h:112
Set the line color on subsequent draw-related actions.
Definition: CanvasAction.h:74
Fundamental information about a single image.
Definition: RawImage.h:124
void TriggerJS() override
Definition: Canvas.h:68
std::string TypeName() const override
Debugging helpers...
Definition: Canvas.h:45
double GetHeight() const
Get the pixel height of this Canvas.
Definition: Canvas.h:120
Canvas & Image(const emp::RawImage &image, double x, double y, Ts &&...vals)
Definition: Canvas.h:164
Canvas & Draw(const emp::Circle &circle, const std::string &fc="", const std::string &lc="")
Draw a circle onto this canvas.
Definition: Canvas.h:229
CanvasInfo & operator=(const CanvasInfo &)=delete
Track a circle shape to be drawn on a canvas.
Definition: CanvasShape.h:69
Canvas & CenterText(emp::Point p, Ts &&...vals)
Definition: Canvas.h:207
void ClearActions()
Definition: Canvas.h:83
Canvas & Rotate(double angle)
Rotate the entire canvas.
Definition: Canvas.h:248
Canvas & Rect(Point corner, double w, double h, Ts &&...vals)
Definition: Canvas.h:145
virtual ~Canvas()
Definition: Canvas.h:115
Track a rectangle shape to be drawn on a canvas.
Definition: CanvasShape.h:94