2016-01-30 18:11:21 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2016 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/SkCanvas.h"
|
|
|
|
#include "include/core/SkPath.h"
|
|
|
|
#include "include/utils/SkRandom.h"
|
|
|
|
#include "samplecode/Sample.h"
|
2016-01-30 18:11:21 +00:00
|
|
|
|
2018-08-08 15:36:17 +00:00
|
|
|
class MegaStrokeView : public Sample {
|
2016-01-30 18:11:21 +00:00
|
|
|
public:
|
|
|
|
MegaStrokeView() {
|
2019-08-24 23:39:13 +00:00
|
|
|
fClip.setLTRB(0, 0, 950, 600);
|
2016-01-30 18:11:21 +00:00
|
|
|
fAngle = 0;
|
|
|
|
fPlusMinus = 0;
|
|
|
|
SkRandom rand;
|
|
|
|
fMegaPath.reset();
|
|
|
|
for (int index = 0; index < 921; ++index) {
|
|
|
|
for (int segs = 0; segs < 40; ++segs) {
|
|
|
|
fMegaPath.lineTo(SkIntToScalar(index), SkIntToScalar(rand.nextRangeU(500, 600)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2019-07-03 14:55:44 +00:00
|
|
|
SkString name() override { return SkString("MegaStroke"); }
|
2016-01-30 18:11:21 +00:00
|
|
|
|
2019-07-03 19:53:04 +00:00
|
|
|
bool onChar(SkUnichar uni) override {
|
2019-08-24 23:39:13 +00:00
|
|
|
fClip.setLTRB(0, 0, 950, 600);
|
2019-07-03 19:53:04 +00:00
|
|
|
return true;
|
2016-01-30 18:11:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void onDrawBackground(SkCanvas* canvas) override {
|
|
|
|
}
|
|
|
|
|
|
|
|
void onDrawContent(SkCanvas* canvas) override {
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setAntiAlias(true);
|
|
|
|
paint.setARGB(255,255,153,0);
|
|
|
|
paint.setStyle(SkPaint::kStroke_Style);
|
|
|
|
paint.setStrokeWidth(1);
|
|
|
|
|
|
|
|
canvas->save();
|
|
|
|
canvas->clipRect(fClip);
|
|
|
|
canvas->clear(SK_ColorWHITE);
|
|
|
|
canvas->drawPath(fMegaPath, paint);
|
|
|
|
canvas->restore();
|
|
|
|
|
|
|
|
SkPaint divSimPaint;
|
|
|
|
divSimPaint.setColor(SK_ColorBLUE);
|
|
|
|
SkScalar x = SkScalarSin(fAngle * SK_ScalarPI / 180) * 200 + 250;
|
|
|
|
SkScalar y = SkScalarCos(fAngle * SK_ScalarPI / 180) * 200 + 250;
|
|
|
|
|
|
|
|
if ((fPlusMinus ^= 1)) {
|
|
|
|
fAngle += 5;
|
|
|
|
} else {
|
|
|
|
fAngle -= 5;
|
|
|
|
}
|
|
|
|
SkRect divSim = SkRect::MakeXYWH(x, y, 100, 100);
|
|
|
|
divSim.outset(30, 30);
|
|
|
|
canvas->drawRect(divSim, divSimPaint);
|
|
|
|
fClip = divSim;
|
|
|
|
}
|
|
|
|
|
|
|
|
void onSizeChange() override {
|
2019-08-24 23:39:13 +00:00
|
|
|
fClip.setWH(950, 600);
|
2016-01-30 18:11:21 +00:00
|
|
|
}
|
|
|
|
|
2019-07-11 20:32:53 +00:00
|
|
|
bool onAnimate(double /*nanos*/) override { return true; }
|
2016-01-30 18:11:21 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
SkPath fMegaPath;
|
|
|
|
SkRect fClip;
|
|
|
|
int fAngle;
|
|
|
|
int fPlusMinus;
|
2020-09-03 02:42:33 +00:00
|
|
|
using INHERITED = Sample;
|
2016-01-30 18:11:21 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2018-08-08 15:36:17 +00:00
|
|
|
DEF_SAMPLE( return new MegaStrokeView(); )
|