Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(728)

Unified Diff: samplecode/SampleMegaStroke.cpp

Issue 1651573002: add new tests (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « gyp/SampleApp.gyp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: samplecode/SampleMegaStroke.cpp
diff --git a/samplecode/SampleMegaStroke.cpp b/samplecode/SampleMegaStroke.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..9222256c9efeb6b438c93b73c1211887415fc3dc
--- /dev/null
+++ b/samplecode/SampleMegaStroke.cpp
@@ -0,0 +1,99 @@
+/*
+ * 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 "SampleCode.h"
+#include "SkCanvas.h"
+#include "SkPath.h"
+#include "SkRandom.h"
+
+class MegaStrokeView : public SampleView {
+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:
+ // overrides from SkEventSink
+ bool onQuery(SkEvent* evt) override {
+ if (SampleCode::TitleQ(*evt)) {
+ SampleCode::TitleR(evt, "MegaStroke");
+ return true;
+ }
+
+ SkUnichar uni;
+ if (SampleCode::CharQ(*evt, &uni)) {
+ fClip.set(0, 0, 950, 600);
+ }
+ SkString str;
+ evt->getType(&str);
+ if (str == SkString("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 SkAnimTimer& ) override {
+ return true;
+ }
+
+private:
+ SkPath fMegaPath;
+ SkRect fClip;
+ int fAngle;
+ int fPlusMinus;
+ typedef SampleView INHERITED;
+};
+
+//////////////////////////////////////////////////////////////////////////////
+
+static SkView* MyFactory() { return new MegaStrokeView; }
+static SkViewRegister reg(MyFactory);
« no previous file with comments | « gyp/SampleApp.gyp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698