CanvasShape.hpp

Define simple shapes to draw on a canvas.

Canvas shapes can be defined in detail, describing how they modify a canvas.

Other, more specific actions defined here are: CanvasCircle CanvasRect

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

Define an arbitrary shape to draw on a canvas (base class)

Subclassed by CanvasCircle, CanvasClearRect, CanvasLine, CanvasMultiLine, CanvasPolygon, CanvasRect, CanvasText

Public Functions

inline CanvasShape(double _x, double _y, const std::string &fc = "", const std::string &lc = "", double lw = 1.0)
inline CanvasShape(Point _p, const std::string &fc = "", const std::string &lc = "", double lw = 1.0)
inline virtual ~CanvasShape()
inline void MoveTo(Point _p)

Shift the position of this shape to a point.

inline void MoveTo(double _x, double _y)

Shift the position of this shape to coordinates.

inline void SetLineWidth(double lw = 1.0)

Setup details needed before drawing lines.

inline void SetFillColor(const std::string &color)

Change the fill color of this shape.

inline void SetLineColor(const std::string &color)

Change the stroke color of this shape.

inline void ApplyColor()

Actually change the color on screen.

Protected Attributes

Point p

Anchor point for this shape.

std::string fill_color

Internal color to fill shape with.

std::string line_color

Border color for shape.

double line_width

How wide should lines be?

class CanvasCircle : public CanvasShape
#include <CanvasShape.hpp>

Track a circle shape to be drawn on a canvas.

Public Functions

inline CanvasCircle(double _x, double _y, double _r, const std::string &fc = "", const std::string &lc = "", double lw = 1.0)
inline CanvasCircle(Point _p, double _r, const std::string &fc = "", const std::string &lc = "", double lw = 1.0)
inline CanvasCircle(Circle circle, const std::string &fc = "", const std::string &lc = "", double lw = 1.0)
inline virtual void Apply()

Apply current action to emp_i.ctx.

inline virtual CanvasAction *Clone() const

Make a copy of the current action.

Private Members

double radius

Circle radius.

class CanvasRect : public CanvasShape
#include <CanvasShape.hpp>

Track a rectangle shape to be drawn on a canvas.

Public Functions

inline CanvasRect(Point _p, double _w, double _h, const std::string &fc = "", const std::string &lc = "")
inline CanvasRect(double _x, double _y, double _w, double _h, const std::string &fc = "", const std::string &lc = "")
inline virtual void Apply()

Apply current action to emp_i.ctx.

inline virtual CanvasAction *Clone() const

Make a copy of the current action.

Private Members

double w

Rectangle width.

double h

Rectangle height.

class CanvasClearRect : public CanvasShape
#include <CanvasShape.hpp>

Clear a rectangular area in a canvas.

Public Functions

inline CanvasClearRect(Point _p, double _w, double _h)
inline virtual void Apply()

Apply current action to emp_i.ctx.

inline virtual CanvasAction *Clone() const

Make a copy of the current action.

Private Members

double w

Rectangle width.

double h

Rectangle height.

class CanvasPolygon : public CanvasShape
#include <CanvasShape.hpp>

An arbitrary-sized polygon to be drawn on a canvas.

Public Functions

inline CanvasPolygon(const std::string &fc = "", const std::string &lc = "")
inline CanvasPolygon(const vector<Point> &p, const std::string &fc = "", const std::string &lc = "")
inline CanvasPolygon(Point _p, const std::string &fc = "", const std::string &lc = "")
inline CanvasPolygon(double _x, double _y, const std::string &fc = "", const std::string &lc = "")
inline CanvasPolygon &AddPoint(double x, double y)
inline CanvasPolygon &AddPoint(Point p)
inline virtual void Apply()

Apply current action to emp_i.ctx.

inline virtual CanvasAction *Clone() const

Make a copy of the current action.

Private Members

vector<Point> points

Series of points defining the perimeter of the Polygon.

class CanvasLine : public CanvasShape
#include <CanvasShape.hpp>

A line segment on the canvas.

Public Functions

inline CanvasLine(double _x1, double _y1, double _x2, double _y2, const std::string &lc = "", double lw = 1.0)

Y-position for second point of line segment.

inline CanvasLine(Point p1, Point p2, const std::string &lc = "", double lw = 1.0)
inline virtual void Apply()

Apply current action to emp_i.ctx.

inline virtual CanvasAction *Clone() const

Make a copy of the current action.

Private Members

double x2
double y2

X-position for second point of line segment.

class CanvasMultiLine : public CanvasShape
#include <CanvasShape.hpp>

A whole series of line segments on the canvas. Currently not working…

Public Functions

inline CanvasMultiLine(double _x1, double _y1, const vector<Point> &_points, const std::string &lc = "", double lw = 1.0)
inline CanvasMultiLine(Point p1, const vector<Point> &_points, const std::string &lc = "", double lw = 1.0)
inline virtual void Apply()

Apply current action to emp_i.ctx.

inline virtual CanvasAction *Clone() const

Make a copy of the current action.

Private Members

vector<Point> points
class CanvasText : public CanvasShape
#include <CanvasShape.hpp>

Text to be written on a canvas.

Public Functions

inline CanvasText(Point p, const std::string &_text, const std::string &fc = "", const std::string &lc = "")
inline virtual void Apply()

Apply current action to emp_i.ctx.

inline void Center(bool c = true)

Center this text.

inline bool GetCenter() const

Identify if text is centered.

inline virtual CanvasAction *Clone() const

Make a copy of the current action.

Protected Attributes

std::string text

Specific text to be written.

bool center

Should this text be centered (or is anchor on left side)?