CanvasAction.hpp

Define a base class for all actions that can be done to widgets, plus simple actions.

CanvasAction objects modify the appearance of a canvas and can be tracked to reconstruct the state of the canvas from scratch.

Other, more specific actions defined here are: CanvasStrokeColor CanvasRotate CanvasFont

See also CanvasShape.h for more actions.

class CanvasAction
#include <CanvasAction.hpp>

Base class to maintain canvas actions.

Subclassed by CanvasFont, CanvasImage, CanvasRotate, CanvasShape, CanvasStrokeColor

Public Functions

inline CanvasAction()
inline CanvasAction(const CanvasAction&)
inline virtual ~CanvasAction()
virtual void Apply() = 0

Apply current action to emp_i.ctx.

virtual CanvasAction *Clone() const = 0

Make a copy of the current action.

Protected Functions

inline void Fill(const std::string &style = "")

Helper function to set the fill status.

inline void Stroke(const std::string &style = "")

Helper function to set the stroke status.

inline void LineWidth(double line_width = 1.0)

Helper function to set the stroke status.

class CanvasStrokeColor : public CanvasAction
#include <CanvasAction.hpp>

Set the line color on subsequent draw-related actions.

Public Functions

inline CanvasStrokeColor(const std::string &c)
inline virtual void Apply()

Apply current action to emp_i.ctx.

inline virtual CanvasAction *Clone() const

Make a copy of the current action.

Protected Attributes

std::string color

Color to use.

class CanvasRotate : public CanvasAction
#include <CanvasAction.hpp>

Rotate the entire canvas for subsequent drawings.

Public Functions

inline CanvasRotate(double a)
inline virtual void Apply()

Apply current action to emp_i.ctx.

inline virtual CanvasAction *Clone() const

Make a copy of the current action.

Protected Attributes

double angle
class CanvasFont : public CanvasAction
#include <CanvasAction.hpp>

Change the default font to be used.

Public Functions

inline CanvasFont(const std::string &f)
inline virtual void Apply()

Apply current action to emp_i.ctx.

inline virtual CanvasAction *Clone() const

Make a copy of the current action.

Protected Attributes

std::string font
class CanvasImage : public CanvasAction
#include <CanvasAction.hpp>

Change the default font to be used.

Public Functions

inline CanvasImage(const RawImage &raw_image, double _x = 0.0, double _y = 0.0, double _w = 0.0, double _h = 0.0)
inline CanvasImage(const RawImage &raw_image, Point _p, double _w = 0.0, double _h = 0.0)
inline CanvasImage(const std::string &url, double _x = 0.0, double _y = 0.0, double _w = 0.0, double _h = 0.0)
inline CanvasImage(const std::string &url, Point _p, double _w = 0.0, double _h = 0.0)
inline virtual void Apply()

Apply current action to emp_i.ctx.

inline virtual CanvasAction *Clone() const

Make a copy of the current action.

Protected Attributes

RawImage image
Point position
double width
double height