2015-02-18 18:56:00 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2012 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkBlendMode.h"
|
|
|
|
#include "include/core/SkCanvas.h"
|
|
|
|
#include "include/core/SkColor.h"
|
|
|
|
#include "include/core/SkFont.h"
|
|
|
|
#include "include/core/SkImageInfo.h"
|
|
|
|
#include "include/core/SkMatrix.h"
|
|
|
|
#include "include/core/SkPaint.h"
|
|
|
|
#include "include/core/SkPath.h"
|
|
|
|
#include "include/core/SkPathMeasure.h"
|
|
|
|
#include "include/core/SkPoint.h"
|
|
|
|
#include "include/core/SkRRect.h"
|
|
|
|
#include "include/core/SkRect.h"
|
|
|
|
#include "include/core/SkRefCnt.h"
|
|
|
|
#include "include/core/SkScalar.h"
|
|
|
|
#include "include/core/SkShader.h"
|
|
|
|
#include "include/core/SkString.h"
|
|
|
|
#include "include/core/SkSurface.h"
|
|
|
|
#include "include/core/SkTypes.h"
|
|
|
|
#include "include/private/SkTArray.h"
|
|
|
|
#include "include/private/SkTemplates.h"
|
|
|
|
#include "include/utils/SkTextUtils.h"
|
|
|
|
#include "samplecode/Sample.h"
|
|
|
|
#include "src/core/SkGeometry.h"
|
2020-05-05 21:06:30 +00:00
|
|
|
#include "src/core/SkPathPriv.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "src/core/SkPointPriv.h"
|
|
|
|
#include "src/core/SkStroke.h"
|
|
|
|
#include "tools/ToolUtils.h"
|
2018-03-14 19:07:43 +00:00
|
|
|
|
|
|
|
#include <cfloat>
|
|
|
|
|
|
|
|
class SkEvent;
|
2015-02-18 18:56:00 +00:00
|
|
|
|
|
|
|
static bool hittest(const SkPoint& target, SkScalar x, SkScalar y) {
|
|
|
|
const SkScalar TOL = 7;
|
|
|
|
return SkPoint::Distance(target, SkPoint::Make(x, y)) <= TOL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int getOnCurvePoints(const SkPath& path, SkPoint storage[]) {
|
|
|
|
int count = 0;
|
2020-05-05 21:06:30 +00:00
|
|
|
for (auto [verb, pts, w] : SkPathPriv::Iterate(path)) {
|
2015-02-18 18:56:00 +00:00
|
|
|
switch (verb) {
|
2020-05-05 21:06:30 +00:00
|
|
|
case SkPathVerb::kMove:
|
|
|
|
case SkPathVerb::kLine:
|
|
|
|
case SkPathVerb::kQuad:
|
|
|
|
case SkPathVerb::kConic:
|
|
|
|
case SkPathVerb::kCubic:
|
2015-02-18 18:56:00 +00:00
|
|
|
storage[count++] = pts[0];
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void getContourCounts(const SkPath& path, SkTArray<int>* contourCounts) {
|
|
|
|
int count = 0;
|
2020-05-05 21:06:30 +00:00
|
|
|
for (auto [verb, pts, w] : SkPathPriv::Iterate(path)) {
|
2015-02-18 18:56:00 +00:00
|
|
|
switch (verb) {
|
2020-05-05 21:06:30 +00:00
|
|
|
case SkPathVerb::kMove:
|
|
|
|
case SkPathVerb::kLine:
|
2015-02-18 18:56:00 +00:00
|
|
|
count += 1;
|
|
|
|
break;
|
2020-05-05 21:06:30 +00:00
|
|
|
case SkPathVerb::kQuad:
|
|
|
|
case SkPathVerb::kConic:
|
2015-02-18 18:56:00 +00:00
|
|
|
count += 2;
|
|
|
|
break;
|
2020-05-05 21:06:30 +00:00
|
|
|
case SkPathVerb::kCubic:
|
2015-02-18 18:56:00 +00:00
|
|
|
count += 3;
|
|
|
|
break;
|
2020-05-05 21:06:30 +00:00
|
|
|
case SkPathVerb::kClose:
|
2015-02-18 18:56:00 +00:00
|
|
|
contourCounts->push_back(count);
|
|
|
|
count = 0;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (count > 0) {
|
|
|
|
contourCounts->push_back(count);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-24 01:59:25 +00:00
|
|
|
static void erase(const sk_sp<SkSurface>& surface) {
|
2016-01-20 19:55:11 +00:00
|
|
|
SkCanvas* canvas = surface->getCanvas();
|
|
|
|
if (canvas) {
|
|
|
|
canvas->clear(SK_ColorTRANSPARENT);
|
|
|
|
}
|
2015-02-18 18:56:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
struct StrokeTypeButton {
|
|
|
|
SkRect fBounds;
|
|
|
|
char fLabel;
|
|
|
|
bool fEnabled;
|
|
|
|
};
|
|
|
|
|
2015-02-20 14:33:57 +00:00
|
|
|
struct CircleTypeButton : public StrokeTypeButton {
|
|
|
|
bool fFill;
|
|
|
|
};
|
|
|
|
|
2018-08-08 15:36:17 +00:00
|
|
|
class QuadStrokerView : public Sample {
|
2015-02-18 18:56:00 +00:00
|
|
|
enum {
|
|
|
|
SKELETON_COLOR = 0xFF0000FF,
|
|
|
|
WIREFRAME_COLOR = 0x80FF0000
|
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
2016-01-20 19:55:11 +00:00
|
|
|
kCount = 18
|
2015-02-18 18:56:00 +00:00
|
|
|
};
|
|
|
|
SkPoint fPts[kCount];
|
2015-02-20 14:33:57 +00:00
|
|
|
SkRect fWeightControl;
|
2016-01-20 19:55:11 +00:00
|
|
|
SkRect fRadiusControl;
|
2015-02-18 18:56:00 +00:00
|
|
|
SkRect fErrorControl;
|
|
|
|
SkRect fWidthControl;
|
|
|
|
SkRect fBounds;
|
|
|
|
SkMatrix fMatrix, fInverse;
|
2016-03-09 02:50:00 +00:00
|
|
|
sk_sp<SkShader> fShader;
|
2016-03-24 01:59:25 +00:00
|
|
|
sk_sp<SkSurface> fMinSurface;
|
|
|
|
sk_sp<SkSurface> fMaxSurface;
|
2015-02-18 18:56:00 +00:00
|
|
|
StrokeTypeButton fCubicButton;
|
2015-02-20 14:33:57 +00:00
|
|
|
StrokeTypeButton fConicButton;
|
2015-02-18 18:56:00 +00:00
|
|
|
StrokeTypeButton fQuadButton;
|
2016-01-20 19:55:11 +00:00
|
|
|
StrokeTypeButton fArcButton;
|
2015-02-18 18:56:00 +00:00
|
|
|
StrokeTypeButton fRRectButton;
|
2015-02-20 14:33:57 +00:00
|
|
|
CircleTypeButton fCircleButton;
|
2015-02-18 18:56:00 +00:00
|
|
|
StrokeTypeButton fTextButton;
|
|
|
|
SkString fText;
|
|
|
|
SkScalar fTextSize;
|
2015-02-20 14:33:57 +00:00
|
|
|
SkScalar fWeight;
|
2016-01-20 19:55:11 +00:00
|
|
|
SkScalar fRadius;
|
2015-02-18 18:56:00 +00:00
|
|
|
SkScalar fWidth, fDWidth;
|
|
|
|
SkScalar fWidthScale;
|
|
|
|
int fW, fH, fZoom;
|
|
|
|
bool fAnimate;
|
|
|
|
bool fDrawRibs;
|
|
|
|
bool fDrawTangents;
|
2016-01-19 16:07:49 +00:00
|
|
|
bool fDrawTDivs;
|
2015-05-22 13:26:52 +00:00
|
|
|
#ifdef SK_DEBUG
|
2015-02-18 18:56:00 +00:00
|
|
|
#define kStrokerErrorMin 0.001f
|
|
|
|
#define kStrokerErrorMax 5
|
|
|
|
#endif
|
|
|
|
#define kWidthMin 1
|
|
|
|
#define kWidthMax 100
|
|
|
|
public:
|
|
|
|
QuadStrokerView() {
|
|
|
|
this->setBGColor(SK_ColorLTGRAY);
|
|
|
|
|
2015-02-20 14:33:57 +00:00
|
|
|
fPts[0].set(50, 200); // cubic
|
2015-02-18 18:56:00 +00:00
|
|
|
fPts[1].set(50, 100);
|
|
|
|
fPts[2].set(150, 50);
|
|
|
|
fPts[3].set(300, 50);
|
|
|
|
|
2015-02-20 14:33:57 +00:00
|
|
|
fPts[4].set(350, 200); // conic
|
2015-02-18 18:56:00 +00:00
|
|
|
fPts[5].set(350, 100);
|
|
|
|
fPts[6].set(450, 50);
|
|
|
|
|
2015-02-20 14:33:57 +00:00
|
|
|
fPts[7].set(150, 300); // quad
|
|
|
|
fPts[8].set(150, 200);
|
|
|
|
fPts[9].set(250, 150);
|
|
|
|
|
2016-01-20 19:55:11 +00:00
|
|
|
fPts[10].set(250, 200); // arc
|
|
|
|
fPts[11].set(250, 300);
|
|
|
|
fPts[12].set(150, 350);
|
|
|
|
|
|
|
|
fPts[13].set(200, 200); // rrect
|
|
|
|
fPts[14].set(400, 400);
|
2015-02-20 14:33:57 +00:00
|
|
|
|
2016-01-20 19:55:11 +00:00
|
|
|
fPts[15].set(250, 250); // oval
|
|
|
|
fPts[16].set(450, 450);
|
2015-02-18 18:56:00 +00:00
|
|
|
|
|
|
|
fText = "a";
|
|
|
|
fTextSize = 12;
|
|
|
|
fWidth = 50;
|
|
|
|
fDWidth = 0.25f;
|
2015-02-20 14:33:57 +00:00
|
|
|
fWeight = 1;
|
2016-01-20 19:55:11 +00:00
|
|
|
fRadius = 150;
|
2015-02-18 18:56:00 +00:00
|
|
|
|
|
|
|
fCubicButton.fLabel = 'C';
|
|
|
|
fCubicButton.fEnabled = false;
|
2015-02-20 14:33:57 +00:00
|
|
|
fConicButton.fLabel = 'K';
|
2016-01-20 19:55:11 +00:00
|
|
|
fConicButton.fEnabled = false;
|
2015-02-18 18:56:00 +00:00
|
|
|
fQuadButton.fLabel = 'Q';
|
|
|
|
fQuadButton.fEnabled = false;
|
2016-01-20 19:55:11 +00:00
|
|
|
fArcButton.fLabel = 'A';
|
|
|
|
fArcButton.fEnabled = true;
|
2015-02-18 18:56:00 +00:00
|
|
|
fRRectButton.fLabel = 'R';
|
|
|
|
fRRectButton.fEnabled = false;
|
2015-02-20 14:33:57 +00:00
|
|
|
fCircleButton.fLabel = 'O';
|
2016-01-20 19:55:11 +00:00
|
|
|
fCircleButton.fEnabled = true;
|
|
|
|
fCircleButton.fFill = true;
|
2015-02-18 18:56:00 +00:00
|
|
|
fTextButton.fLabel = 'T';
|
2015-02-20 14:33:57 +00:00
|
|
|
fTextButton.fEnabled = false;
|
2016-01-20 19:55:11 +00:00
|
|
|
fAnimate = false;
|
2015-02-18 18:56:00 +00:00
|
|
|
setAsNeeded();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2019-07-03 14:55:44 +00:00
|
|
|
SkString name() override { return SkString("QuadStroker"); }
|
|
|
|
|
2019-07-03 19:53:04 +00:00
|
|
|
bool onChar(SkUnichar uni) override {
|
|
|
|
if (fTextButton.fEnabled) {
|
2015-02-18 18:56:00 +00:00
|
|
|
switch (uni) {
|
|
|
|
case ' ':
|
|
|
|
fText = "";
|
|
|
|
break;
|
|
|
|
case '-':
|
2020-02-07 15:36:46 +00:00
|
|
|
fTextSize = std::max(1.0f, fTextSize - 1);
|
2015-02-18 18:56:00 +00:00
|
|
|
break;
|
|
|
|
case '+':
|
|
|
|
case '=':
|
|
|
|
fTextSize += 1;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
fText.appendUnichar(uni);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2019-07-03 19:53:04 +00:00
|
|
|
return false;
|
2015-02-18 18:56:00 +00:00
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
void onSizeChange() override {
|
2016-01-20 19:55:11 +00:00
|
|
|
fRadiusControl.setXYWH(this->width() - 200, 30, 30, 400);
|
2015-02-20 14:33:57 +00:00
|
|
|
fWeightControl.setXYWH(this->width() - 150, 30, 30, 400);
|
2015-02-18 18:56:00 +00:00
|
|
|
fErrorControl.setXYWH(this->width() - 100, 30, 30, 400);
|
|
|
|
fWidthControl.setXYWH(this->width() - 50, 30, 30, 400);
|
2015-02-20 14:33:57 +00:00
|
|
|
int buttonOffset = 450;
|
|
|
|
fCubicButton.fBounds.setXYWH(this->width() - 50, SkIntToScalar(buttonOffset), 30, 30);
|
|
|
|
buttonOffset += 50;
|
|
|
|
fConicButton.fBounds.setXYWH(this->width() - 50, SkIntToScalar(buttonOffset), 30, 30);
|
|
|
|
buttonOffset += 50;
|
|
|
|
fQuadButton.fBounds.setXYWH(this->width() - 50, SkIntToScalar(buttonOffset), 30, 30);
|
|
|
|
buttonOffset += 50;
|
2016-01-20 19:55:11 +00:00
|
|
|
fArcButton.fBounds.setXYWH(this->width() - 50, SkIntToScalar(buttonOffset), 30, 30);
|
|
|
|
buttonOffset += 50;
|
2015-02-20 14:33:57 +00:00
|
|
|
fRRectButton.fBounds.setXYWH(this->width() - 50, SkIntToScalar(buttonOffset), 30, 30);
|
|
|
|
buttonOffset += 50;
|
|
|
|
fCircleButton.fBounds.setXYWH(this->width() - 50, SkIntToScalar(buttonOffset), 30, 30);
|
|
|
|
buttonOffset += 50;
|
|
|
|
fTextButton.fBounds.setXYWH(this->width() - 50, SkIntToScalar(buttonOffset), 30, 30);
|
2015-02-18 18:56:00 +00:00
|
|
|
this->INHERITED::onSizeChange();
|
|
|
|
}
|
|
|
|
|
|
|
|
void copyMinToMax() {
|
|
|
|
erase(fMaxSurface);
|
|
|
|
SkCanvas* canvas = fMaxSurface->getCanvas();
|
|
|
|
canvas->save();
|
|
|
|
canvas->concat(fMatrix);
|
2015-08-27 14:41:13 +00:00
|
|
|
fMinSurface->draw(canvas, 0, 0, nullptr);
|
2015-02-18 18:56:00 +00:00
|
|
|
canvas->restore();
|
|
|
|
|
|
|
|
SkPaint paint;
|
2016-10-06 00:33:02 +00:00
|
|
|
paint.setBlendMode(SkBlendMode::kClear);
|
2015-02-18 18:56:00 +00:00
|
|
|
for (int iy = 1; iy < fH; ++iy) {
|
|
|
|
SkScalar y = SkIntToScalar(iy * fZoom);
|
|
|
|
canvas->drawLine(0, y - SK_ScalarHalf, 999, y - SK_ScalarHalf, paint);
|
|
|
|
}
|
|
|
|
for (int ix = 1; ix < fW; ++ix) {
|
|
|
|
SkScalar x = SkIntToScalar(ix * fZoom);
|
|
|
|
canvas->drawLine(x - SK_ScalarHalf, 0, x - SK_ScalarHalf, 999, paint);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void setWHZ(int width, int height, int zoom) {
|
|
|
|
fZoom = zoom;
|
2019-08-24 23:39:13 +00:00
|
|
|
fBounds.setIWH(width * zoom, height * zoom);
|
2015-02-18 18:56:00 +00:00
|
|
|
fMatrix.setScale(SkIntToScalar(zoom), SkIntToScalar(zoom));
|
|
|
|
fInverse.setScale(SK_Scalar1 / zoom, SK_Scalar1 / zoom);
|
2019-03-20 16:12:10 +00:00
|
|
|
fShader = ToolUtils::create_checkerboard_shader(0xFFCCCCCC, 0xFFFFFFFF, zoom);
|
2015-02-18 18:56:00 +00:00
|
|
|
|
|
|
|
SkImageInfo info = SkImageInfo::MakeN32Premul(width, height);
|
2016-03-24 01:59:25 +00:00
|
|
|
fMinSurface = SkSurface::MakeRaster(info);
|
2015-02-18 18:56:00 +00:00
|
|
|
info = info.makeWH(width * zoom, height * zoom);
|
2016-03-24 01:59:25 +00:00
|
|
|
fMaxSurface = SkSurface::MakeRaster(info);
|
2015-02-18 18:56:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void draw_points(SkCanvas* canvas, const SkPath& path, SkColor color,
|
|
|
|
bool show_lines) {
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setColor(color);
|
|
|
|
paint.setAlpha(0x80);
|
|
|
|
paint.setAntiAlias(true);
|
|
|
|
int n = path.countPoints();
|
|
|
|
SkAutoSTArray<32, SkPoint> pts(n);
|
|
|
|
if (show_lines && fDrawTangents) {
|
|
|
|
SkTArray<int> contourCounts;
|
|
|
|
getContourCounts(path, &contourCounts);
|
|
|
|
SkPoint* ptPtr = pts.get();
|
|
|
|
for (int i = 0; i < contourCounts.count(); ++i) {
|
|
|
|
int count = contourCounts[i];
|
|
|
|
path.getPoints(ptPtr, count);
|
|
|
|
canvas->drawPoints(SkCanvas::kPolygon_PointMode, count, ptPtr, paint);
|
|
|
|
ptPtr += count;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
n = getOnCurvePoints(path, pts.get());
|
|
|
|
}
|
|
|
|
paint.setStrokeWidth(5);
|
|
|
|
canvas->drawPoints(SkCanvas::kPoints_PointMode, n, pts.get(), paint);
|
|
|
|
}
|
|
|
|
|
|
|
|
void draw_ribs(SkCanvas* canvas, const SkPath& path, SkScalar width,
|
|
|
|
SkColor color) {
|
|
|
|
const SkScalar radius = width / 2;
|
|
|
|
|
|
|
|
SkPathMeasure meas(path, false);
|
|
|
|
SkScalar total = meas.getLength();
|
|
|
|
|
|
|
|
SkScalar delta = 8;
|
2016-01-19 16:07:49 +00:00
|
|
|
SkPaint paint, labelP;
|
2015-02-18 18:56:00 +00:00
|
|
|
paint.setColor(color);
|
2016-01-19 16:07:49 +00:00
|
|
|
labelP.setColor(color & 0xff5f9f5f);
|
2019-01-08 19:00:08 +00:00
|
|
|
SkFont font;
|
2015-02-18 18:56:00 +00:00
|
|
|
SkPoint pos, tan;
|
2016-01-19 16:07:49 +00:00
|
|
|
int index = 0;
|
2015-02-18 18:56:00 +00:00
|
|
|
for (SkScalar dist = 0; dist <= total; dist += delta) {
|
|
|
|
if (meas.getPosTan(dist, &pos, &tan)) {
|
|
|
|
tan.scale(radius);
|
2017-11-08 16:44:31 +00:00
|
|
|
SkPointPriv::RotateCCW(&tan);
|
2015-02-18 18:56:00 +00:00
|
|
|
canvas->drawLine(pos.x() + tan.x(), pos.y() + tan.y(),
|
|
|
|
pos.x() - tan.x(), pos.y() - tan.y(), paint);
|
2016-01-19 16:07:49 +00:00
|
|
|
if (0 == index % 10) {
|
|
|
|
SkString label;
|
|
|
|
label.appendS32(index);
|
|
|
|
SkRect dot = SkRect::MakeXYWH(pos.x() - 2, pos.y() - 2, 4, 4);
|
|
|
|
canvas->drawRect(dot, labelP);
|
2017-04-28 19:35:12 +00:00
|
|
|
canvas->drawString(label,
|
2019-01-08 19:00:08 +00:00
|
|
|
pos.x() - tan.x() * 1.25f, pos.y() - tan.y() * 1.25f, font, labelP);
|
2016-01-19 16:07:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
++index;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void draw_t_divs(SkCanvas* canvas, const SkPath& path, SkScalar width, SkColor color) {
|
|
|
|
const SkScalar radius = width / 2;
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setColor(color);
|
|
|
|
SkPathMeasure meas(path, false);
|
|
|
|
SkScalar total = meas.getLength();
|
|
|
|
SkScalar delta = 8;
|
|
|
|
int ribs = 0;
|
|
|
|
for (SkScalar dist = 0; dist <= total; dist += delta) {
|
|
|
|
++ribs;
|
|
|
|
}
|
2020-05-05 21:06:30 +00:00
|
|
|
const uint8_t* verbs = SkPathPriv::VerbData(path);
|
|
|
|
if (path.countVerbs() < 2 || SkPath::kMove_Verb != verbs[0]) {
|
2016-01-19 16:07:49 +00:00
|
|
|
SkASSERT(0);
|
|
|
|
return;
|
|
|
|
}
|
2020-05-05 21:06:30 +00:00
|
|
|
auto verb = static_cast<SkPath::Verb>(verbs[1]);
|
2016-01-19 16:07:49 +00:00
|
|
|
SkASSERT(SkPath::kLine_Verb <= verb && verb <= SkPath::kCubic_Verb);
|
2020-05-05 21:06:30 +00:00
|
|
|
const SkPoint* pts = SkPathPriv::PointData(path);
|
2016-01-19 16:07:49 +00:00
|
|
|
SkPoint pos, tan;
|
|
|
|
for (int index = 0; index < ribs; ++index) {
|
|
|
|
SkScalar t = (SkScalar) index / ribs;
|
|
|
|
switch (verb) {
|
|
|
|
case SkPath::kLine_Verb:
|
|
|
|
tan = pts[1] - pts[0];
|
|
|
|
pos = pts[0];
|
|
|
|
pos.fX += tan.fX * t;
|
|
|
|
pos.fY += tan.fY * t;
|
|
|
|
break;
|
|
|
|
case SkPath::kQuad_Verb:
|
|
|
|
pos = SkEvalQuadAt(pts, t);
|
|
|
|
tan = SkEvalQuadTangentAt(pts, t);
|
|
|
|
break;
|
|
|
|
case SkPath::kConic_Verb: {
|
2020-05-05 21:06:30 +00:00
|
|
|
SkConic conic(pts, SkPathPriv::ConicWeightData(path)[0]);
|
2016-01-19 16:07:49 +00:00
|
|
|
pos = conic.evalAt(t);
|
|
|
|
tan = conic.evalTangentAt(t);
|
|
|
|
} break;
|
|
|
|
case SkPath::kCubic_Verb:
|
|
|
|
SkEvalCubicAt(pts, t, &pos, &tan, nullptr);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
SkASSERT(0);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
tan.setLength(radius);
|
2017-11-08 16:44:31 +00:00
|
|
|
SkPointPriv::RotateCCW(&tan);
|
2016-01-19 16:07:49 +00:00
|
|
|
canvas->drawLine(pos.x() + tan.x(), pos.y() + tan.y(),
|
|
|
|
pos.x() - tan.x(), pos.y() - tan.y(), paint);
|
|
|
|
if (0 == index % 10) {
|
|
|
|
SkString label;
|
|
|
|
label.appendS32(index);
|
2017-04-28 19:35:12 +00:00
|
|
|
canvas->drawString(label,
|
2019-01-08 19:00:08 +00:00
|
|
|
pos.x() + tan.x() * 1.25f, pos.y() + tan.y() * 1.25f, SkFont(), paint);
|
2015-02-18 18:56:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-20 14:33:57 +00:00
|
|
|
void draw_stroke(SkCanvas* canvas, const SkPath& path, SkScalar width, SkScalar scale,
|
|
|
|
bool drawText) {
|
2015-05-19 18:05:37 +00:00
|
|
|
if (path.isEmpty()) {
|
2015-02-18 18:56:00 +00:00
|
|
|
return;
|
|
|
|
}
|
2015-05-19 18:05:37 +00:00
|
|
|
SkRect bounds = path.getBounds();
|
2016-03-29 16:03:52 +00:00
|
|
|
this->setWHZ(SkScalarCeilToInt(bounds.right()), drawText
|
2015-02-20 14:33:57 +00:00
|
|
|
? SkScalarRoundToInt(scale * 3 / 2) : SkScalarRoundToInt(scale),
|
|
|
|
SkScalarRoundToInt(950.0f / scale));
|
2015-02-18 18:56:00 +00:00
|
|
|
erase(fMinSurface);
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setColor(0x1f1f0f0f);
|
|
|
|
paint.setStyle(SkPaint::kStroke_Style);
|
2015-02-20 14:33:57 +00:00
|
|
|
paint.setStrokeWidth(width * scale * scale);
|
2015-02-18 18:56:00 +00:00
|
|
|
paint.setColor(0x3f0f1f3f);
|
2015-02-20 14:33:57 +00:00
|
|
|
if (drawText) {
|
|
|
|
fMinSurface->getCanvas()->drawPath(path, paint);
|
|
|
|
this->copyMinToMax();
|
2015-08-27 14:41:13 +00:00
|
|
|
fMaxSurface->draw(canvas, 0, 0, nullptr);
|
2015-02-20 14:33:57 +00:00
|
|
|
}
|
2015-02-18 18:56:00 +00:00
|
|
|
paint.setAntiAlias(true);
|
|
|
|
paint.setStyle(SkPaint::kStroke_Style);
|
|
|
|
paint.setStrokeWidth(1);
|
|
|
|
|
|
|
|
paint.setColor(SKELETON_COLOR);
|
|
|
|
SkPath scaled;
|
|
|
|
SkMatrix matrix;
|
|
|
|
matrix.reset();
|
2015-02-20 14:33:57 +00:00
|
|
|
matrix.setScale(950 / scale, 950 / scale);
|
2015-02-18 18:56:00 +00:00
|
|
|
if (drawText) {
|
|
|
|
path.transform(matrix, &scaled);
|
|
|
|
} else {
|
|
|
|
scaled = path;
|
|
|
|
}
|
|
|
|
canvas->drawPath(scaled, paint);
|
|
|
|
draw_points(canvas, scaled, SKELETON_COLOR, true);
|
|
|
|
|
|
|
|
if (fDrawRibs) {
|
|
|
|
draw_ribs(canvas, scaled, width, 0xFF00FF00);
|
|
|
|
}
|
|
|
|
|
2016-01-19 16:07:49 +00:00
|
|
|
if (fDrawTDivs) {
|
|
|
|
draw_t_divs(canvas, scaled, width, 0xFF3F3F00);
|
|
|
|
}
|
|
|
|
|
2015-02-18 18:56:00 +00:00
|
|
|
SkPath fill;
|
|
|
|
|
|
|
|
SkPaint p;
|
|
|
|
p.setStyle(SkPaint::kStroke_Style);
|
2015-02-20 14:33:57 +00:00
|
|
|
if (drawText) {
|
|
|
|
p.setStrokeWidth(width * scale * scale);
|
|
|
|
} else {
|
|
|
|
p.setStrokeWidth(width);
|
|
|
|
}
|
2015-02-18 18:56:00 +00:00
|
|
|
p.getFillPath(path, &fill);
|
|
|
|
SkPath scaledFill;
|
|
|
|
if (drawText) {
|
|
|
|
fill.transform(matrix, &scaledFill);
|
|
|
|
} else {
|
|
|
|
scaledFill = fill;
|
|
|
|
}
|
|
|
|
paint.setColor(WIREFRAME_COLOR);
|
|
|
|
canvas->drawPath(scaledFill, paint);
|
|
|
|
draw_points(canvas, scaledFill, WIREFRAME_COLOR, false);
|
|
|
|
}
|
|
|
|
|
2015-02-20 14:33:57 +00:00
|
|
|
void draw_fill(SkCanvas* canvas, const SkRect& rect, SkScalar width) {
|
|
|
|
if (rect.isEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setColor(0x1f1f0f0f);
|
|
|
|
paint.setStyle(SkPaint::kStroke_Style);
|
|
|
|
paint.setStrokeWidth(width);
|
|
|
|
SkPath path;
|
2020-02-07 15:36:46 +00:00
|
|
|
SkScalar maxSide = std::max(rect.width(), rect.height()) / 2;
|
2015-02-20 14:33:57 +00:00
|
|
|
SkPoint center = { rect.fLeft + maxSide, rect.fTop + maxSide };
|
|
|
|
path.addCircle(center.fX, center.fY, maxSide);
|
|
|
|
canvas->drawPath(path, paint);
|
|
|
|
paint.setStyle(SkPaint::kFill_Style);
|
|
|
|
path.reset();
|
|
|
|
path.addCircle(center.fX, center.fY, maxSide - width / 2);
|
|
|
|
paint.setColor(0x3f0f1f3f);
|
|
|
|
canvas->drawPath(path, paint);
|
|
|
|
path.reset();
|
2019-11-26 17:17:17 +00:00
|
|
|
path.setFillType(SkPathFillType::kEvenOdd);
|
2015-02-20 14:33:57 +00:00
|
|
|
path.addCircle(center.fX, center.fY, maxSide + width / 2);
|
2016-03-29 16:03:52 +00:00
|
|
|
SkRect outside = SkRect::MakeXYWH(center.fX - maxSide - width, center.fY - maxSide - width,
|
2015-02-20 14:33:57 +00:00
|
|
|
(maxSide + width) * 2, (maxSide + width) * 2);
|
|
|
|
path.addRect(outside);
|
|
|
|
canvas->drawPath(path, paint);
|
|
|
|
}
|
|
|
|
|
2015-02-18 18:56:00 +00:00
|
|
|
void draw_button(SkCanvas* canvas, const StrokeTypeButton& button) {
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setAntiAlias(true);
|
|
|
|
paint.setStyle(SkPaint::kStroke_Style);
|
|
|
|
paint.setColor(button.fEnabled ? 0xFF3F0000 : 0x6F3F0000);
|
|
|
|
canvas->drawRect(button.fBounds, paint);
|
|
|
|
paint.setColor(button.fEnabled ? 0xFF3F0000 : 0x6F3F0000);
|
|
|
|
paint.setStyle(SkPaint::kFill_Style);
|
2019-01-03 20:45:53 +00:00
|
|
|
SkFont font;
|
|
|
|
font.setSize(25.0f);
|
2019-05-07 19:38:46 +00:00
|
|
|
SkTextUtils::Draw(canvas, &button.fLabel, 1, SkTextEncoding::kUTF8,
|
2019-01-03 20:45:53 +00:00
|
|
|
button.fBounds.centerX(), button.fBounds.fBottom - 5,
|
|
|
|
font, paint, SkTextUtils::kCenter_Align);
|
2015-02-18 18:56:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void draw_control(SkCanvas* canvas, const SkRect& bounds, SkScalar value,
|
|
|
|
SkScalar min, SkScalar max, const char* name) {
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setAntiAlias(true);
|
|
|
|
paint.setStyle(SkPaint::kStroke_Style);
|
|
|
|
canvas->drawRect(bounds, paint);
|
|
|
|
SkScalar scale = max - min;
|
|
|
|
SkScalar yPos = bounds.fTop + (value - min) * bounds.height() / scale;
|
|
|
|
paint.setColor(0xFFFF0000);
|
|
|
|
canvas->drawLine(bounds.fLeft - 5, yPos, bounds.fRight + 5, yPos, paint);
|
|
|
|
SkString label;
|
|
|
|
label.printf("%0.3g", value);
|
|
|
|
paint.setColor(0xFF000000);
|
|
|
|
paint.setStyle(SkPaint::kFill_Style);
|
2019-01-08 19:00:08 +00:00
|
|
|
SkFont font(nullptr, 11.0f);
|
|
|
|
canvas->drawString(label, bounds.fLeft + 5, yPos - 5, font, paint);
|
|
|
|
font.setSize(13.0f);
|
|
|
|
canvas->drawString(name, bounds.fLeft, bounds.bottom() + 11, font, paint);
|
2015-02-18 18:56:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void setForGeometry() {
|
|
|
|
fDrawRibs = true;
|
|
|
|
fDrawTangents = true;
|
2016-01-19 16:07:49 +00:00
|
|
|
fDrawTDivs = false;
|
2015-02-18 18:56:00 +00:00
|
|
|
fWidthScale = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setForText() {
|
2016-01-19 16:07:49 +00:00
|
|
|
fDrawRibs = fDrawTangents = fDrawTDivs = false;
|
2015-02-18 18:56:00 +00:00
|
|
|
fWidthScale = 0.002f;
|
|
|
|
}
|
|
|
|
|
2016-01-19 16:07:49 +00:00
|
|
|
void setForSingles() {
|
|
|
|
setForGeometry();
|
|
|
|
fDrawTDivs = true;
|
|
|
|
}
|
|
|
|
|
2015-02-18 18:56:00 +00:00
|
|
|
void setAsNeeded() {
|
2016-01-19 16:07:49 +00:00
|
|
|
if (fConicButton.fEnabled || fCubicButton.fEnabled || fQuadButton.fEnabled) {
|
|
|
|
setForSingles();
|
2016-01-20 19:55:11 +00:00
|
|
|
} else if (fRRectButton.fEnabled || fCircleButton.fEnabled || fArcButton.fEnabled) {
|
2015-02-18 18:56:00 +00:00
|
|
|
setForGeometry();
|
|
|
|
} else {
|
|
|
|
setForText();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-20 19:55:11 +00:00
|
|
|
bool arcCenter(SkPoint* center) {
|
|
|
|
SkPath path;
|
|
|
|
path.moveTo(fPts[10]);
|
|
|
|
path.arcTo(fPts[11], fPts[12], fRadius);
|
|
|
|
SkPath::Iter iter(path, false);
|
|
|
|
SkPoint pts[4];
|
|
|
|
iter.next(pts);
|
|
|
|
if (SkPath::kLine_Verb == iter.next(pts)) {
|
|
|
|
iter.next(pts);
|
|
|
|
}
|
|
|
|
SkVector before = pts[0] - pts[1];
|
|
|
|
SkVector after = pts[1] - pts[2];
|
|
|
|
before.setLength(fRadius);
|
|
|
|
after.setLength(fRadius);
|
|
|
|
SkVector beforeCCW, afterCCW;
|
2017-11-08 16:44:31 +00:00
|
|
|
SkPointPriv::RotateCCW(before, &beforeCCW);
|
|
|
|
SkPointPriv::RotateCCW(after, &afterCCW);
|
2016-01-20 19:55:11 +00:00
|
|
|
beforeCCW += pts[0];
|
|
|
|
afterCCW += pts[2];
|
|
|
|
*center = beforeCCW;
|
|
|
|
if (SkScalarNearlyEqual(beforeCCW.fX, afterCCW.fX)
|
|
|
|
&& SkScalarNearlyEqual(beforeCCW.fY, afterCCW.fY)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
SkVector beforeCW, afterCW;
|
2017-11-08 16:44:31 +00:00
|
|
|
SkPointPriv::RotateCW(before, &beforeCW);
|
|
|
|
SkPointPriv::RotateCW(after, &afterCW);
|
2016-01-20 19:55:11 +00:00
|
|
|
beforeCW += pts[0];
|
|
|
|
afterCW += pts[2];
|
|
|
|
*center = beforeCW;
|
|
|
|
return SkScalarNearlyEqual(beforeCW.fX, afterCW.fX)
|
|
|
|
&& SkScalarNearlyEqual(beforeCCW.fY, afterCW.fY);
|
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
void onDrawContent(SkCanvas* canvas) override {
|
2015-02-18 18:56:00 +00:00
|
|
|
SkPath path;
|
|
|
|
SkScalar width = fWidth;
|
|
|
|
|
|
|
|
if (fCubicButton.fEnabled) {
|
|
|
|
path.moveTo(fPts[0]);
|
|
|
|
path.cubicTo(fPts[1], fPts[2], fPts[3]);
|
2016-01-19 16:07:49 +00:00
|
|
|
setForSingles();
|
2015-02-20 14:33:57 +00:00
|
|
|
draw_stroke(canvas, path, width, 950, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fConicButton.fEnabled) {
|
2016-01-19 16:07:49 +00:00
|
|
|
path.reset();
|
2015-02-20 14:33:57 +00:00
|
|
|
path.moveTo(fPts[4]);
|
|
|
|
path.conicTo(fPts[5], fPts[6], fWeight);
|
2016-01-19 16:07:49 +00:00
|
|
|
setForSingles();
|
2015-02-20 14:33:57 +00:00
|
|
|
draw_stroke(canvas, path, width, 950, false);
|
2015-02-18 18:56:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (fQuadButton.fEnabled) {
|
|
|
|
path.reset();
|
2015-02-20 14:33:57 +00:00
|
|
|
path.moveTo(fPts[7]);
|
|
|
|
path.quadTo(fPts[8], fPts[9]);
|
2016-01-19 16:07:49 +00:00
|
|
|
setForSingles();
|
2015-02-20 14:33:57 +00:00
|
|
|
draw_stroke(canvas, path, width, 950, false);
|
2015-02-18 18:56:00 +00:00
|
|
|
}
|
|
|
|
|
2016-01-20 19:55:11 +00:00
|
|
|
if (fArcButton.fEnabled) {
|
|
|
|
path.reset();
|
|
|
|
path.moveTo(fPts[10]);
|
|
|
|
path.arcTo(fPts[11], fPts[12], fRadius);
|
|
|
|
setForGeometry();
|
|
|
|
draw_stroke(canvas, path, width, 950, false);
|
|
|
|
SkPath pathPts;
|
|
|
|
pathPts.moveTo(fPts[10]);
|
|
|
|
pathPts.lineTo(fPts[11]);
|
|
|
|
pathPts.lineTo(fPts[12]);
|
|
|
|
draw_points(canvas, pathPts, SK_ColorDKGRAY, true);
|
|
|
|
}
|
|
|
|
|
2015-02-18 18:56:00 +00:00
|
|
|
if (fRRectButton.fEnabled) {
|
|
|
|
SkScalar rad = 32;
|
|
|
|
SkRect r;
|
2019-08-24 23:39:13 +00:00
|
|
|
r.setBounds(&fPts[13], 2);
|
2015-02-18 18:56:00 +00:00
|
|
|
path.reset();
|
|
|
|
SkRRect rr;
|
|
|
|
rr.setRectXY(r, rad, rad);
|
|
|
|
path.addRRect(rr);
|
|
|
|
setForGeometry();
|
2015-02-20 14:33:57 +00:00
|
|
|
draw_stroke(canvas, path, width, 950, false);
|
2015-02-18 18:56:00 +00:00
|
|
|
|
|
|
|
path.reset();
|
|
|
|
SkRRect rr2;
|
|
|
|
rr.inset(width/2, width/2, &rr2);
|
2019-11-22 18:34:02 +00:00
|
|
|
path.addRRect(rr2, SkPathDirection::kCCW);
|
2015-02-18 18:56:00 +00:00
|
|
|
rr.inset(-width/2, -width/2, &rr2);
|
2019-11-22 18:34:02 +00:00
|
|
|
path.addRRect(rr2, SkPathDirection::kCW);
|
2015-02-18 18:56:00 +00:00
|
|
|
SkPaint paint;
|
|
|
|
paint.setAntiAlias(true);
|
|
|
|
paint.setColor(0x40FF8844);
|
|
|
|
canvas->drawPath(path, paint);
|
|
|
|
}
|
|
|
|
|
2015-02-20 14:33:57 +00:00
|
|
|
if (fCircleButton.fEnabled) {
|
|
|
|
path.reset();
|
|
|
|
SkRect r;
|
2019-08-24 23:39:13 +00:00
|
|
|
r.setBounds(&fPts[15], 2);
|
2015-02-20 14:33:57 +00:00
|
|
|
path.addOval(r);
|
|
|
|
setForGeometry();
|
|
|
|
if (fCircleButton.fFill) {
|
2016-01-20 19:55:11 +00:00
|
|
|
if (fArcButton.fEnabled) {
|
|
|
|
SkPoint center;
|
|
|
|
if (arcCenter(¢er)) {
|
2019-08-24 23:39:13 +00:00
|
|
|
r.setLTRB(center.fX - fRadius, center.fY - fRadius,
|
|
|
|
center.fX + fRadius, center.fY + fRadius);
|
2016-01-20 19:55:11 +00:00
|
|
|
}
|
|
|
|
}
|
2015-02-20 14:33:57 +00:00
|
|
|
draw_fill(canvas, r, width);
|
|
|
|
} else {
|
|
|
|
draw_stroke(canvas, path, width, 950, false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-18 18:56:00 +00:00
|
|
|
if (fTextButton.fEnabled) {
|
|
|
|
path.reset();
|
2018-12-26 03:06:17 +00:00
|
|
|
SkFont font;
|
|
|
|
font.setSize(fTextSize);
|
2019-05-07 19:38:46 +00:00
|
|
|
SkTextUtils::GetPath(fText.c_str(), fText.size(), SkTextEncoding::kUTF8,
|
2018-12-26 03:06:17 +00:00
|
|
|
0, fTextSize, font, &path);
|
2015-02-18 18:56:00 +00:00
|
|
|
setForText();
|
2015-02-20 14:33:57 +00:00
|
|
|
draw_stroke(canvas, path, width * fWidthScale / fTextSize, fTextSize, true);
|
2015-02-18 18:56:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (fAnimate) {
|
|
|
|
fWidth += fDWidth;
|
|
|
|
if (fDWidth > 0 && fWidth > kWidthMax) {
|
|
|
|
fDWidth = -fDWidth;
|
|
|
|
} else if (fDWidth < 0 && fWidth < kWidthMin) {
|
|
|
|
fDWidth = -fDWidth;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
setAsNeeded();
|
2015-02-20 14:33:57 +00:00
|
|
|
if (fConicButton.fEnabled) {
|
|
|
|
draw_control(canvas, fWeightControl, fWeight, 0, 5, "weight");
|
|
|
|
}
|
2016-01-20 19:55:11 +00:00
|
|
|
if (fArcButton.fEnabled) {
|
|
|
|
draw_control(canvas, fRadiusControl, fRadius, 0, 500, "radius");
|
|
|
|
}
|
2015-05-22 13:26:52 +00:00
|
|
|
#ifdef SK_DEBUG
|
2015-02-18 18:56:00 +00:00
|
|
|
draw_control(canvas, fErrorControl, gDebugStrokerError, kStrokerErrorMin, kStrokerErrorMax,
|
|
|
|
"error");
|
|
|
|
#endif
|
|
|
|
draw_control(canvas, fWidthControl, fWidth * fWidthScale, kWidthMin * fWidthScale,
|
|
|
|
kWidthMax * fWidthScale, "width");
|
|
|
|
draw_button(canvas, fQuadButton);
|
|
|
|
draw_button(canvas, fCubicButton);
|
2015-02-20 14:33:57 +00:00
|
|
|
draw_button(canvas, fConicButton);
|
2016-01-20 19:55:11 +00:00
|
|
|
draw_button(canvas, fArcButton);
|
2015-02-18 18:56:00 +00:00
|
|
|
draw_button(canvas, fRRectButton);
|
2015-02-20 14:33:57 +00:00
|
|
|
draw_button(canvas, fCircleButton);
|
2015-02-18 18:56:00 +00:00
|
|
|
draw_button(canvas, fTextButton);
|
|
|
|
}
|
|
|
|
|
|
|
|
class MyClick : public Click {
|
|
|
|
public:
|
|
|
|
int fIndex;
|
2019-07-12 15:32:43 +00:00
|
|
|
MyClick(int index) : fIndex(index) {}
|
2015-02-18 18:56:00 +00:00
|
|
|
};
|
|
|
|
|
2020-08-14 02:58:04 +00:00
|
|
|
Sample::Click* onFindClickHandler(SkScalar x, SkScalar y, skui::ModifierKey modi) override {
|
2015-02-18 18:56:00 +00:00
|
|
|
for (size_t i = 0; i < SK_ARRAY_COUNT(fPts); ++i) {
|
|
|
|
if (hittest(fPts[i], x, y)) {
|
2019-07-12 15:32:43 +00:00
|
|
|
return new MyClick((int)i);
|
2015-02-18 18:56:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
const SkRect& rectPt = SkRect::MakeXYWH(x, y, 1, 1);
|
2015-02-20 14:33:57 +00:00
|
|
|
if (fWeightControl.contains(rectPt)) {
|
2019-07-12 15:32:43 +00:00
|
|
|
return new MyClick((int) SK_ARRAY_COUNT(fPts) + 1);
|
2015-02-20 14:33:57 +00:00
|
|
|
}
|
2016-01-20 19:55:11 +00:00
|
|
|
if (fRadiusControl.contains(rectPt)) {
|
2019-07-12 15:32:43 +00:00
|
|
|
return new MyClick((int) SK_ARRAY_COUNT(fPts) + 2);
|
2016-01-20 19:55:11 +00:00
|
|
|
}
|
2015-05-22 13:26:52 +00:00
|
|
|
#ifdef SK_DEBUG
|
2015-02-18 18:56:00 +00:00
|
|
|
if (fErrorControl.contains(rectPt)) {
|
2019-07-12 15:32:43 +00:00
|
|
|
return new MyClick((int) SK_ARRAY_COUNT(fPts) + 3);
|
2015-02-18 18:56:00 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
if (fWidthControl.contains(rectPt)) {
|
2019-07-12 15:32:43 +00:00
|
|
|
return new MyClick((int) SK_ARRAY_COUNT(fPts) + 4);
|
2015-02-18 18:56:00 +00:00
|
|
|
}
|
|
|
|
if (fCubicButton.fBounds.contains(rectPt)) {
|
|
|
|
fCubicButton.fEnabled ^= true;
|
2019-07-12 15:32:43 +00:00
|
|
|
return new MyClick((int) SK_ARRAY_COUNT(fPts) + 5);
|
2015-02-18 18:56:00 +00:00
|
|
|
}
|
2015-02-20 14:33:57 +00:00
|
|
|
if (fConicButton.fBounds.contains(rectPt)) {
|
|
|
|
fConicButton.fEnabled ^= true;
|
2019-07-12 15:32:43 +00:00
|
|
|
return new MyClick((int) SK_ARRAY_COUNT(fPts) + 6);
|
2015-02-20 14:33:57 +00:00
|
|
|
}
|
2015-02-18 18:56:00 +00:00
|
|
|
if (fQuadButton.fBounds.contains(rectPt)) {
|
|
|
|
fQuadButton.fEnabled ^= true;
|
2019-07-12 15:32:43 +00:00
|
|
|
return new MyClick((int) SK_ARRAY_COUNT(fPts) + 7);
|
2016-01-20 19:55:11 +00:00
|
|
|
}
|
|
|
|
if (fArcButton.fBounds.contains(rectPt)) {
|
|
|
|
fArcButton.fEnabled ^= true;
|
2019-07-12 15:32:43 +00:00
|
|
|
return new MyClick((int) SK_ARRAY_COUNT(fPts) + 8);
|
2015-02-18 18:56:00 +00:00
|
|
|
}
|
|
|
|
if (fRRectButton.fBounds.contains(rectPt)) {
|
|
|
|
fRRectButton.fEnabled ^= true;
|
2019-07-12 15:32:43 +00:00
|
|
|
return new MyClick((int) SK_ARRAY_COUNT(fPts) + 9);
|
2015-02-20 14:33:57 +00:00
|
|
|
}
|
|
|
|
if (fCircleButton.fBounds.contains(rectPt)) {
|
|
|
|
bool wasEnabled = fCircleButton.fEnabled;
|
|
|
|
fCircleButton.fEnabled = !fCircleButton.fFill;
|
|
|
|
fCircleButton.fFill = wasEnabled && !fCircleButton.fFill;
|
2019-07-12 15:32:43 +00:00
|
|
|
return new MyClick((int) SK_ARRAY_COUNT(fPts) + 10);
|
2015-02-18 18:56:00 +00:00
|
|
|
}
|
|
|
|
if (fTextButton.fBounds.contains(rectPt)) {
|
|
|
|
fTextButton.fEnabled ^= true;
|
2019-07-12 15:32:43 +00:00
|
|
|
return new MyClick((int) SK_ARRAY_COUNT(fPts) + 11);
|
2015-02-18 18:56:00 +00:00
|
|
|
}
|
2019-07-12 15:32:43 +00:00
|
|
|
return nullptr;
|
2015-02-18 18:56:00 +00:00
|
|
|
}
|
|
|
|
|
2019-07-12 15:32:43 +00:00
|
|
|
static SkScalar MapScreenYtoValue(SkScalar y, const SkRect& control, SkScalar min,
|
2015-02-18 18:56:00 +00:00
|
|
|
SkScalar max) {
|
2019-07-12 15:32:43 +00:00
|
|
|
return (y - control.fTop) / control.height() * (max - min) + min;
|
2015-02-18 18:56:00 +00:00
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
bool onClick(Click* click) override {
|
2015-02-18 18:56:00 +00:00
|
|
|
int index = ((MyClick*)click)->fIndex;
|
|
|
|
if (index < (int) SK_ARRAY_COUNT(fPts)) {
|
2019-07-12 15:32:43 +00:00
|
|
|
fPts[index].offset(click->fCurr.fX - click->fPrev.fX,
|
|
|
|
click->fCurr.fY - click->fPrev.fY);
|
2015-02-20 14:33:57 +00:00
|
|
|
} else if (index == (int) SK_ARRAY_COUNT(fPts) + 1) {
|
2019-07-12 15:32:43 +00:00
|
|
|
fWeight = MapScreenYtoValue(click->fCurr.fY, fWeightControl, 0, 5);
|
2016-01-20 19:55:11 +00:00
|
|
|
} else if (index == (int) SK_ARRAY_COUNT(fPts) + 2) {
|
2019-07-12 15:32:43 +00:00
|
|
|
fRadius = MapScreenYtoValue(click->fCurr.fY, fRadiusControl, 0, 500);
|
2015-02-18 18:56:00 +00:00
|
|
|
}
|
2015-05-22 13:26:52 +00:00
|
|
|
#ifdef SK_DEBUG
|
2016-01-20 19:55:11 +00:00
|
|
|
else if (index == (int) SK_ARRAY_COUNT(fPts) + 3) {
|
2020-02-07 15:36:46 +00:00
|
|
|
gDebugStrokerError = std::max(FLT_EPSILON, MapScreenYtoValue(click->fCurr.fY,
|
2015-02-18 18:56:00 +00:00
|
|
|
fErrorControl, kStrokerErrorMin, kStrokerErrorMax));
|
|
|
|
gDebugStrokerErrorSet = true;
|
|
|
|
}
|
|
|
|
#endif
|
2016-01-20 19:55:11 +00:00
|
|
|
else if (index == (int) SK_ARRAY_COUNT(fPts) + 4) {
|
2020-02-07 15:36:46 +00:00
|
|
|
fWidth = std::max(FLT_EPSILON, MapScreenYtoValue(click->fCurr.fY, fWidthControl,
|
2015-02-18 18:56:00 +00:00
|
|
|
kWidthMin, kWidthMax));
|
|
|
|
fAnimate = fWidth <= kWidthMin;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2020-09-03 02:42:33 +00:00
|
|
|
using INHERITED = Sample;
|
2015-02-18 18:56:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2018-08-08 15:36:17 +00:00
|
|
|
DEF_SAMPLE( return new QuadStrokerView(); )
|