/* * Copyright (c) 2015 Tricoire Sebastien 3dsman@free.fr * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages * arising from the use of this software. * * Permission is granted to anyone to use this software for any purpose, * including commercial applications, and to alter it and redistribute it * freely, subject to the following restrictions: * * 1. The origin of this software must not be misrepresented; you must not * claim that you wrote the original software. If you use this software * in a product, an acknowledgment in the product documentation would be * appreciated but is not required. * 2. Altered source versions must be plainly marked as such, and must not be * misrepresented as being the original software. * 3. This notice may not be removed or altered from any source distribution. * */ #include "curves/OE_pointcurve.h" #include "OE_utils.h" #include #include #include #include #include #include #include unsigned char OE_pointcurve::controlLineColor[] = {100,60,92,255}; unsigned char OE_pointcurve::controlPointColor[] = {100,60,92,255}; unsigned char OE_pointcurve::controlEndPointColor[] = {100,60,92,255}; OE_pointcurve::OE_pointcurve(){} OE_pointcurve::OE_pointcurve(std::vector points, bool closed) { pts = points; this->closed = closed; // Flag indicating if shapes should be treated as closed. } OE_pointcurve::~OE_pointcurve() { } bool OE_pointcurve::getPoint(uint16_t nb, float* x, float* y) { if ((pts.size())&&(nb<=pts.size())) { *x = pts.at(nb-1).x; *y = pts.at(nb-1).y; return true; } return false; } bool OE_pointcurve::getPoint(uint16_t nb, vector_2d& pt) { if ((pts.size())&&(nb<=pts.size())) { pt.x = pts.at(nb-1).x; pt.y = pts.at(nb-1).y; return true; } return false; } bool OE_pointcurve::setPoint(uint16_t nb, float x, float y) { if (nb<=pts.size()) { pts[(nb-1)] = vector_2d(x,y); setNeedRefresh(); return true; } return false; } bool OE_pointcurve::setPoint(uint16_t nb, vector_2d coord) { if (nb<=pts.size()) { pts[(nb-1)] = coord; setNeedRefresh(); return true; } return false; } bool OE_pointcurve::addPoint( float x, float y) { pts.push_back(vector_2d(x,y)); setNeedRefresh(); return true; } bool OE_pointcurve::addPoint( vector_2d pt) { pts.push_back(pt); setNeedRefresh(); return true; } void OE_pointcurve::lineTo(float x, float y) { float px,py, dx,dy; if (pts.size() > 0) { getPoint(pts.size(), &px, &py); dx = x - px; dy = y - py; addPoint(px + dx/3.0f, py + dy/3.0f); addPoint(x - dx/3.0f, y - dy/3.0f); addPoint(x, y); } } void OE_pointcurve::lineTo(vector_2d pt) { vector_2d p,d; if (pts.size() > 0) { getPoint(pts.size(), p); d = pt-p; addPoint(p + d/3.0f); addPoint(pt - d/3.0f); addPoint(pt); } } void OE_pointcurve::cubicBezTo(float cpx1, float cpy1, float cpx2, float cpy2, float x, float y) { addPoint(cpx1, cpy1); addPoint(cpx2, cpy2); addPoint(x, y); } void OE_pointcurve::refresh(float dpi) { OE_curve::refresh(dpi); } void OE_pointcurve::move(vector_2d offset) { for (unsigned i = 0; i < pts.size(); i++) { pts[i] = pts[i] + offset; } setNeedRefresh(); }