skia2/samplecode/SampleMegaStroke.cpp
Mike Klein c0bd9f9fe5 rewrite includes to not need so much -Ifoo
Current strategy: everything from the top

Things to look at first are the manual changes:

   - added tools/rewrite_includes.py
   - removed -Idirectives from BUILD.gn
   - various compile.sh simplifications
   - tweak tools/embed_resources.py
   - update gn/find_headers.py to write paths from the top
   - update gn/gn_to_bp.py SkUserConfig.h layout
     so that #include "include/config/SkUserConfig.h" always
     gets the header we want.

No-Presubmit: true
Change-Id: I73a4b181654e0e38d229bc456c0d0854bae3363e
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/209706
Commit-Queue: Mike Klein <mtklein@google.com>
Reviewed-by: Hal Canary <halcanary@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
Reviewed-by: Florin Malita <fmalita@chromium.org>
2019-04-24 16:27:11 +00:00

94 lines
2.5 KiB
C++

/*
* Copyright 2016 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "include/core/SkCanvas.h"
#include "include/core/SkPath.h"
#include "include/utils/SkRandom.h"
#include "samplecode/Sample.h"
class MegaStrokeView : public Sample {
public:
MegaStrokeView() {
fClip.set(0, 0, 950, 600);
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:
bool onQuery(Sample::Event* evt) override {
if (Sample::TitleQ(*evt)) {
Sample::TitleR(evt, "MegaStroke");
return true;
}
SkUnichar uni;
if (Sample::CharQ(*evt, &uni)) {
fClip.set(0, 0, 950, 600);
}
if (evt->isType("SampleCode_Key_Event")) {
fClip.set(0, 0, 950, 600);
}
return this->INHERITED::onQuery(evt);
}
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 {
fClip.set(0, 0, 950, 600);
}
bool onAnimate(const AnimTimer&) override { return true; }
private:
SkPath fMegaPath;
SkRect fClip;
int fAngle;
int fPlusMinus;
typedef Sample INHERITED;
};
//////////////////////////////////////////////////////////////////////////////
DEF_SAMPLE( return new MegaStrokeView(); )