2013-09-19 15:32:22 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2013 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
2015-08-05 20:57:49 +00:00
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkCanvas.h"
|
|
|
|
#include "include/core/SkPath.h"
|
|
|
|
#include "samplecode/Sample.h"
|
2013-09-19 15:32:22 +00:00
|
|
|
|
|
|
|
// Reproduces https://code.google.com/p/chromium/issues/detail?id=279014
|
|
|
|
|
|
|
|
// Renders a string art shape.
|
|
|
|
// The particular shape rendered can be controlled by clicking horizontally, thereby
|
|
|
|
// generating an angle from 0 to 1.
|
|
|
|
|
2018-08-08 15:36:17 +00:00
|
|
|
class StringArtView : public Sample {
|
2013-09-19 15:32:22 +00:00
|
|
|
public:
|
|
|
|
StringArtView() : fAngle(0.305f) {}
|
|
|
|
|
|
|
|
protected:
|
2019-07-03 14:55:44 +00:00
|
|
|
SkString name() override { return SkString("StringArt"); }
|
2013-09-19 15:32:22 +00:00
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
void onDrawContent(SkCanvas* canvas) override {
|
2013-09-19 15:32:22 +00:00
|
|
|
SkScalar angle = fAngle*SK_ScalarPI + SkScalarHalf(SK_ScalarPI);
|
|
|
|
|
|
|
|
SkPoint center = SkPoint::Make(SkScalarHalf(this->width()), SkScalarHalf(this->height()));
|
|
|
|
SkScalar length = 5;
|
|
|
|
SkScalar step = angle;
|
|
|
|
|
|
|
|
SkPath path;
|
|
|
|
path.moveTo(center);
|
|
|
|
|
2020-02-05 18:34:09 +00:00
|
|
|
while (length < (SkScalarHalf(std::min(this->width(), this->height())) - 10.f))
|
2013-09-19 15:32:22 +00:00
|
|
|
{
|
|
|
|
SkPoint rp = SkPoint::Make(length*SkScalarCos(step) + center.fX,
|
|
|
|
length*SkScalarSin(step) + center.fY);
|
|
|
|
path.lineTo(rp);
|
2015-05-12 17:37:34 +00:00
|
|
|
length += angle / SkScalarHalf(SK_ScalarPI);
|
2013-09-19 15:32:22 +00:00
|
|
|
step += angle;
|
|
|
|
}
|
|
|
|
path.close();
|
|
|
|
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setAntiAlias(true);
|
|
|
|
paint.setStyle(SkPaint::kStroke_Style);
|
|
|
|
paint.setColor(0xFF007700);
|
|
|
|
|
|
|
|
canvas->drawPath(path, paint);
|
|
|
|
}
|
|
|
|
|
2019-08-29 14:39:22 +00:00
|
|
|
Sample::Click* onFindClickHandler(SkScalar x, SkScalar y, skui::ModifierKey) override {
|
2013-09-19 15:32:22 +00:00
|
|
|
fAngle = x/width();
|
2015-08-27 14:41:13 +00:00
|
|
|
return nullptr;
|
2013-09-19 15:32:22 +00:00
|
|
|
}
|
|
|
|
private:
|
|
|
|
|
|
|
|
SkScalar fAngle;
|
2018-08-08 15:36:17 +00:00
|
|
|
typedef Sample INHERITED;
|
2013-09-19 15:32:22 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2018-08-08 15:36:17 +00:00
|
|
|
DEF_SAMPLE( return new StringArtView(); )
|