diff --git a/include/pyro/graphics.h b/include/pyro/graphics.h index ed633db..e4e83dd 100644 --- a/include/pyro/graphics.h +++ b/include/pyro/graphics.h @@ -90,8 +90,10 @@ namespace Pyro // Transformation virtual void translate(float x, float y); + virtual void translate(Vector v); virtual void rotate(float a); virtual void scale(float sx, float sy); + virtual void scale(Vector v); virtual void pushmatrix(); virtual void popmatrix(); void pushstyle(); @@ -136,18 +138,26 @@ namespace Pyro { this->_shape.endcontour(); }; - void vertex(Vector v) + void vertex(Vector p) { - this->_shape.vertex(v.x, v.y); + this->_shape.vertex(p); }; void vertex(float x, float y) { this->_shape.vertex(x, y); }; + void curvevertex(Vector p) + { + this->_shape.curvevertex(p); + }; void curvevertex(float x, float y) { this->_shape.curvevertex(x, y); }; + void beziervertex(Vector p2, Vector p3, Vector p4) + { + this->_shape.beziervertex(p2, p3, p4); + } void beziervertex(float x2, float y2, float x3, float y3, float x4, float y4) { this->_shape.beziervertex(x2, y2, x3, y3, x4, y4); @@ -160,8 +170,12 @@ namespace Pyro // Primitive shapes void point(float x, float y); + void point(Vector p); + virtual void line(Vector /*p0*/, Vector /*p1*/){}; virtual void line(float /*x0*/, float /*y0*/, float /*x1*/, float /*y1*/) {}; + void curve(Vector p0, Vector p1, Vector p2, Vector p3); void curve(float x0, float y0, float x1, float y1, float x2, float y2, float x3, float y3); + void bezier(Vector p0, Vector p1, Vector p2, Vector p3); void bezier(float x0, float y0, float x1, float y1, float x2, float y2, float x3, float y3); void triangle(Vector a, Vector b, Vector c); @@ -172,10 +186,12 @@ namespace Pyro this->style.rectmode(mode); }; void rect(float a, float b, float c, float d); + void rect(Vector p0, Vector p1); void quad(Vector a, Vector b, Vector c, Vector d); void quad(float x0, float y0, float x1, float y1, float x2, float y2, float x3, float y3); + void arc(Vector p0, Vector p1, float start, float end, int mode = OPEN); void arc(float a, float b, float c, float d, float start, float end, int mode = OPEN); void ellipsemode(int mode) @@ -187,6 +203,11 @@ namespace Pyro { this->ellipse(x, y, r, r); }; + void ellipse(Vector p0, float w, float h); + void ellipse(Vector p0, float r) + { + this->ellipse(p0, r, r); + }; // Typography diff --git a/include/pyro/pyro.h b/include/pyro/pyro.h index 98b349d..fcbf500 100644 --- a/include/pyro/pyro.h +++ b/include/pyro/pyro.h @@ -85,22 +85,35 @@ namespace Pyro inline void endshape() { pg->endshape(); }; inline void endshape(int close) { pg->endshape(close); }; inline void vertex(float x, float y) { pg->vertex(x, y); }; + inline void vertex(Vector p) { pg->vertex(p); }; inline void curvevertex(float x, float y) { pg->curvevertex(x, y); }; + inline void curvevertex(Vector p) { pg->curvevertex(p); }; inline void beziervertex(float x2, float y2, float x3, float y3, float x4, float y4) { pg->beziervertex(x2, y2, x3, y3, x4, y4); }; + inline void beziervertex(Vector p2, Vector p3, Vector p4) { pg->beziervertex(p2, p3, p4); }; inline void point(float x, float y) { pg->point(x, y); }; + inline void point(Vector p) { pg->point(p); }; inline void line(float x0, float y0, float x1, float y1) { pg->line(x0, y0, x1, y1); }; + inline void line(Vector p0, Vector p1) { pg->line(p0, p1); }; inline void triangle(float x0, float y0, float x1, float y1, float x2, float y2) { pg->triangle(x0, y0, x1, y1, x2, y2); }; + inline void triangle(Vector p0, Vector p1, Vector p2) { pg->triangle(p0, p1, p2); }; inline void rect(float a, float b, float c, float d) { pg->rect(a, b, c, d); }; + inline void rect(Vector p0, Vector p1) { pg->rect(p0, p1); }; inline void quad(float x0, float y0, float x1, float y1, float x2, float y2, float x3, float y3) { pg->quad(x0, y0, x1, y1, x2, y2, x3, y3); }; + inline void quad(Vector p0, Vector p1, Vector p2, Vector p3) { pg->quad(p0, p1, p2, p3); }; inline void arc(float a, float b, float c, float d, float start, float end, int mode = OPEN) { pg->arc(a, b, c, d, start, end, mode); }; + inline void arc(Vector p0, Vector p1, float start, float end, int mode = OPEN) { pg->arc(p0, p1, start, end, mode); }; inline void ellipse(float x, float y, float w, float h) { pg->ellipse(x, y, w, h); }; + inline void ellipse(Vector p0, float w, float h) { pg->ellipse(p0, w, h); }; inline void circle(float x, float y, float r) { ellipse(x, y, r, r); }; + inline void circle(Vector p0, float r) { ellipse(p0, r, r); }; inline void translate(float x, float y) { pg->translate(x, y); }; + inline void translate(Vector v) { pg->translate(v); }; inline void scale(float sx, float sy) { pg->scale(sx, sy); }; + inline void scale(Vector v) { pg->scale(v); }; inline void rotate(float a) { pg->rotate(a); }; inline void pushmatrix() { pg->pushmatrix(); }; inline void popmatrix() { pg->popmatrix(); }; diff --git a/include/pyro/shape.h b/include/pyro/shape.h index 2068fa5..d05df4c 100644 --- a/include/pyro/shape.h +++ b/include/pyro/shape.h @@ -52,10 +52,12 @@ namespace Pyro void end(int close); void begincontour(); void endcontour(); - void vertex(Vector v) { this->vertex(v.x, v.y); }; - void vertex(float x, float y); - void curvevertex(float x, float y); - void beziervertex(float x2, float y2, float x3, float y3, float x4, float y4); + void vertex(Vector p); + void vertex(float x, float y) { this->vertex(Vector(x, y)); }; + void curvevertex(Vector p); + void curvevertex(float x, float y) { this->curvevertex(Vector(x, y)); }; + void beziervertex(Vector p2, Vector p3, Vector p4); + void beziervertex(float x2, float y2, float x3, float y3, float x4, float y4) { this->beziervertex(Vector(x2, y2), Vector(x3, y3), Vector(x4, y4)); }; std::vector> getpoints() { return this->outpoints; }; }; }; diff --git a/include/pyro/transformer.h b/include/pyro/transformer.h index 55a26c3..1db967c 100644 --- a/include/pyro/transformer.h +++ b/include/pyro/transformer.h @@ -15,8 +15,10 @@ namespace Pyro public: Transformer2D(); + void translate(Vector v); void translate(float x, float y); void rotate(float a); + void scale(Vector v); void scale(float sx, float sy); void pushmatrix(); diff --git a/src/graphics.cpp b/src/graphics.cpp index 5c08db3..e6b86e5 100644 --- a/src/graphics.cpp +++ b/src/graphics.cpp @@ -76,11 +76,20 @@ namespace Pyro this->transformer.translate(x, y); } + void Graphics::translate(Vector v) + { + this->transformer.translate(v); + } + void Graphics::rotate(float a) { this->transformer.rotate(a); } + void Graphics::scale(Vector v) + { + this->transformer.scale(v); + } void Graphics::scale(float sx, float sy) { this->transformer.scale(sx, sy); @@ -192,6 +201,18 @@ namespace Pyro this->shape(s, 0, 0); } + void Graphics::rect(Vector p0, Vector p1) + { + Shape s{Shape()}; + s.begin(); + s.vertex(p0); + s.vertex(p1.x, p0.y); + s.vertex(p1); + s.vertex(p0.x, p1.y); + s.end(CLOSE); + this->shape(s, 0, 0); + } + void Graphics::curve(float x0, float y0, float x1, float y1, float x2, float y2, float x3, float y3) { Shape s{Shape()}; diff --git a/src/shape.cpp b/src/shape.cpp index aed298c..fd05f5b 100644 --- a/src/shape.cpp +++ b/src/shape.cpp @@ -159,22 +159,22 @@ namespace Pyro { } - void Shape::vertex(float x, float y) + void Shape::vertex(Vector p) { - this->points.push_back({Pyro::Vector(x, y), PointType::VERTEX}); + this->points.push_back({p, PointType::VERTEX}); } - void Shape::curvevertex(float x, float y) + void Shape::curvevertex(Vector p) { - this->points.push_back({Pyro::Vector(x, y), PointType::CURVEVERTEX}); + this->points.push_back({p, PointType::CURVEVERTEX}); } - void Shape::beziervertex(float x2, float y2, float x3, float y3, float x4, float y4) + void Shape::beziervertex(Vector p2, Vector p3, Vector p4) { assert(this->points.size() > 0); - this->points.push_back({Pyro::Vector(x2, y2), PointType::BEZIERVERTEX}); - this->points.push_back({Pyro::Vector(x3, y3), PointType::BEZIERVERTEX}); - this->points.push_back({Pyro::Vector(x4, y4), PointType::BEZIERVERTEX}); + this->points.push_back({p2, PointType::BEZIERVERTEX}); + this->points.push_back({p3, PointType::BEZIERVERTEX}); + this->points.push_back({p4, PointType::BEZIERVERTEX}); } } diff --git a/src/transformer.cpp b/src/transformer.cpp index 913d46b..87308e1 100644 --- a/src/transformer.cpp +++ b/src/transformer.cpp @@ -9,6 +9,11 @@ namespace Pyro this->current = Eigen::Affine2d::Identity(); this->stack = std::vector(); } + void Transformer2D::translate(Vector v) + { + Eigen::Vector2d t = Eigen::Vector2d(v.x, v.y); + this->current *= Eigen::Translation2d(t); + } void Transformer2D::translate(float x, float y) { @@ -27,6 +32,11 @@ namespace Pyro this->current *= Eigen::Scaling(sx, sy); } + void Transformer2D::scale(Vector v) + { + this->current *= Eigen::Scaling(v.x, v.y); + } + void Transformer2D::pushmatrix() { this->stack.push_back(Eigen::Affine2d(this->current));