| |
| |
| #ifdef _DEBUG |
| #define _STLP_DEBUG 1 |
| #endif |
| #include "ext/CornerDeformation.h" |
| #include "ext/StrokeDeformation.h" |
| #include "ext/SquarePotential.h" |
| |
| |
| #include "ext/ContextStatus.h" |
| #include "ext/Designer.h" |
| |
| #include "ext/ExtUtil.h" |
| |
| #include "DeformationSelector.h" |
| |
| |
| |
| |
| #include <algorithm> |
| #include <iterator> |
| #include <vector> |
| |
| |
| #include "tmathutil.h" |
| |
| using namespace ToonzExt; |
| |
| REGISTER(CornerDeformation, 2); |
| |
| |
| |
| CornerDeformation::CornerDeformation() { |
| this->setPotential(new SquarePotential); |
| shortcutKey_ = ContextStatus::SHIFT; |
| } |
| |
| |
| |
| CornerDeformation::~CornerDeformation() {} |
| |
| |
| |
| void CornerDeformation::draw(Designer *designer) { |
| StrokeDeformationImpl::draw(0); |
| designer->draw(this); |
| } |
| |
| |
| |
| bool CornerDeformation::findExtremes_(const ContextStatus *status, |
| Interval &ret) { |
| return ToonzExt::findNearestSpireCorners(status->stroke2change_, status->w_, |
| ret, status->cornerSize_, |
| &this->getSpiresList()); |
| } |
| |
| |
| |
| bool CornerDeformation::check_(const ContextStatus *status) { |
| assert(status && "Not status available"); |
| |
| TStroke *s = status->stroke2change_; |
| double w = status->w_; |
| |
| if (isASpireCorner(s, w, status->cornerSize_, &this->getSpiresList())) |
| return true; |
| |
| #ifdef USE_TOLERANCE_IN_SELECTION |
| |
| |
| |
| const TPointD pressed = status->stroke2change_->getPoint(status->w_); |
| |
| double pixelTolerance2 = sq(5 * status->pixelSize_); |
| |
| |
| std::vector<double> corners; |
| |
| |
| if (cornersDetector(status->stroke2change_, status->cornerSize_, corners)) { |
| while (!corners.empty()) { |
| TPointD actual = status->stroke2change_->getPoint(corners.back()); |
| if (tdistance2(actual, pressed) < pixelTolerance2) { |
| |
| |
| |
| this->w_ = corners.back(); |
| return true; |
| } |
| corners.pop_back(); |
| } |
| } |
| #endif |
| |
| return false; |
| } |
| |
| |
| |
| double CornerDeformation::findActionLength() { |
| |
| |
| |
| |
| return stroke2manipulate_->getLength(); |
| } |
| |
| |
| |
| CornerDeformation *CornerDeformation::instance() { |
| static CornerDeformation singleton; |
| return &singleton; |
| } |
| |
| |
| |
| |
| |