|
|
2fb9fd |
#ifndef CURVEAREA_H
|
|
|
2fb9fd |
#define CURVEAREA_H
|
|
|
2fb9fd |
|
|
|
2fb9fd |
|
|
|
2fb9fd |
#include <vector></vector>
|
|
|
2fb9fd |
|
|
|
2fb9fd |
#include "activearea.h"
|
|
|
2fb9fd |
|
|
|
2fb9fd |
|
|
|
2fb9fd |
class CurvesArea: public ActiveArea {
|
|
|
2fb9fd |
public:
|
|
|
2fb9fd |
class CurvePoint {
|
|
|
2fb9fd |
public:
|
|
|
2fb9fd |
ActivePoint::Handle p, t;
|
|
|
2fb9fd |
|
|
|
2fb9fd |
explicit CurvePoint(const Vector &p = Vector(), const Vector &t = Vector()):
|
|
|
2fb9fd |
p(new ActivePoint(p)),
|
|
|
2fb9fd |
t(new ActivePoint(p + t, Color::yellow()))
|
|
|
2fb9fd |
{ }
|
|
|
2fb9fd |
|
|
|
2fb9fd |
const Vector& get_p() const { return p->position; }
|
|
|
2fb9fd |
Vector get_t() const { return t->position - p->position; }
|
|
|
2fb9fd |
|
|
|
2fb9fd |
void add_to(CurvesArea &area) const { area.add_point(p); area.add_point(t); }
|
|
|
2fb9fd |
void remove_from(CurvesArea &area) const { area.remove_point(p); area.remove_point(t); }
|
|
|
2fb9fd |
};
|
|
|
2fb9fd |
|
|
|
2fb9fd |
class Curve: public std::vector<curvepoint> {</curvepoint>
|
|
|
2fb9fd |
public:
|
|
|
2fb9fd |
bool loop;
|
|
|
2fb9fd |
Curve(): loop() { }
|
|
|
2fb9fd |
Curve::const_iterator next(Curve::const_iterator i) const
|
|
|
2fb9fd |
{ return ++i != end() ? i : loop ? begin() : --i; }
|
|
|
2fb9fd |
Curve::const_iterator prev(Curve::const_iterator i) const
|
|
|
2fb9fd |
{ return --i != begin() ? i : loop ? end() : ++i; }
|
|
|
2fb9fd |
};
|
|
|
2fb9fd |
|
|
|
2fb9fd |
protected:
|
|
|
2fb9fd |
Curve curve;
|
|
|
6b4ca4 |
ActivePoint::Handle w;
|
|
|
6b4ca4 |
|
|
|
6b4ca4 |
Real get_width() const;
|
|
|
6b4ca4 |
void set_width(const Real &width);
|
|
|
2fb9fd |
|
|
|
2fb9fd |
void put_segment(const Context &context, const Segment &segment, const Real width = 0);
|
|
|
2fb9fd |
void put_curve(const Context &context, const Curve &curve, const Real width = 0);
|
|
|
6b4ca4 |
void draw_curve(const Context &context, const Curve &curve, const Real width);
|
|
|
6b4ca4 |
|
|
|
6b4ca4 |
void on_point_move(const ActivePoint::Handle &point, const Vector &oldposition, const Vector &newposition) override;
|
|
|
6b4ca4 |
void on_draw_content(const Context &context) override;
|
|
|
2fb9fd |
|
|
|
2fb9fd |
public:
|
|
|
2fb9fd |
CurvesArea();
|
|
|
2fb9fd |
};
|
|
|
2fb9fd |
|
|
|
2fb9fd |
|
|
|
2fb9fd |
#endif
|