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

Side by Side Diff: samplecode/PerlinPatch.cpp

Issue 2269673002: 'g' key toggles showgrid for PerlinPatch (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 3 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2015 Google Inc. 2 * Copyright 2015 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SampleCode.h" 8 #include "SampleCode.h"
9 #include "SkAnimTimer.h" 9 #include "SkAnimTimer.h"
10 #include "SkCanvas.h" 10 #include "SkCanvas.h"
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 sk_sp<SkShader> fShader1; 64 sk_sp<SkShader> fShader1;
65 sk_sp<SkShader> fShaderCompose; 65 sk_sp<SkShader> fShaderCompose;
66 SkScalar fXFreq; 66 SkScalar fXFreq;
67 SkScalar fYFreq; 67 SkScalar fYFreq;
68 SkScalar fSeed; 68 SkScalar fSeed;
69 SkPoint fPts[SkPatchUtils::kNumCtrlPts]; 69 SkPoint fPts[SkPatchUtils::kNumCtrlPts];
70 SkScalar fTexX; 70 SkScalar fTexX;
71 SkScalar fTexY; 71 SkScalar fTexY;
72 SkScalar fTexScale; 72 SkScalar fTexScale;
73 SkMatrix fInvMatrix; 73 SkMatrix fInvMatrix;
74 bool fShowGrid = false;
75
74 public: 76 public:
75 PerlinPatchView() : fXFreq(0.025f), fYFreq(0.025f), fSeed(0.0f), 77 PerlinPatchView() : fXFreq(0.025f), fYFreq(0.025f), fSeed(0.0f),
76 fTexX(100.0), fTexY(50.0), fTexScale(1.0f) { 78 fTexX(100.0), fTexY(50.0), fTexScale(1.0f) {
77 const SkScalar s = 2; 79 const SkScalar s = 2;
78 // The order of the colors and points is clockwise starting at upper-lef t corner. 80 // The order of the colors and points is clockwise starting at upper-lef t corner.
79 //top points 81 //top points
80 fPts[0].set(100 * s, 100 * s); 82 fPts[0].set(100 * s, 100 * s);
81 fPts[1].set(150 * s, 50 * s); 83 fPts[1].set(150 * s, 50 * s);
82 fPts[2].set(250 * s, 150 * s); 84 fPts[2].set(250 * s, 150 * s);
83 fPts[3].set(300 * s, 100 * s); 85 fPts[3].set(300 * s, 100 * s);
(...skipping 23 matching lines...) Expand all
107 NULL); 109 NULL);
108 } 110 }
109 111
110 protected: 112 protected:
111 // overrides from SkEventSink 113 // overrides from SkEventSink
112 bool onQuery(SkEvent* evt) override { 114 bool onQuery(SkEvent* evt) override {
113 if (SampleCode::TitleQ(*evt)) { 115 if (SampleCode::TitleQ(*evt)) {
114 SampleCode::TitleR(evt, "PerlinPatch"); 116 SampleCode::TitleR(evt, "PerlinPatch");
115 return true; 117 return true;
116 } 118 }
119 SkUnichar uni;
120 if (SampleCode::CharQ(*evt, &uni)) {
121 switch (uni) {
122 case 'g': fShowGrid = !fShowGrid; this->inval(nullptr); return t rue;
123 default: break;
124 }
125 }
117 return this->INHERITED::onQuery(evt); 126 return this->INHERITED::onQuery(evt);
118 } 127 }
119 128
120 bool onAnimate(const SkAnimTimer& timer) override { 129 bool onAnimate(const SkAnimTimer& timer) override {
121 fSeed += 0.005f; 130 fSeed += 0.005f;
122 return true; 131 return true;
123 } 132 }
124 133
125 134
126 void onDrawContent(SkCanvas* canvas) override { 135 void onDrawContent(SkCanvas* canvas) override {
(...skipping 13 matching lines...) Expand all
140 ; 149 ;
141 150
142 sk_sp<SkXfermode> xfer(SkXfermode::Make(SkXfermode::kSrc_Mode)); 151 sk_sp<SkXfermode> xfer(SkXfermode::Make(SkXfermode::kSrc_Mode));
143 152
144 SkScalar scaleFreq = 2.0; 153 SkScalar scaleFreq = 2.0;
145 fShader1 = SkPerlinNoiseShader2::MakeImprovedNoise(fXFreq/scaleFreq, fYF req/scaleFreq, 4, 154 fShader1 = SkPerlinNoiseShader2::MakeImprovedNoise(fXFreq/scaleFreq, fYF req/scaleFreq, 4,
146 fSeed); 155 fSeed);
147 fShaderCompose = SkShader::MakeComposeShader(fShader0, fShader1, nullptr ); 156 fShaderCompose = SkShader::MakeComposeShader(fShader0, fShader1, nullptr );
148 157
149 paint.setShader(fShaderCompose); 158 paint.setShader(fShaderCompose);
150 canvas->drawPatch(fPts, nullptr, texCoords, xfer, paint); 159
160 const SkPoint* tex = texCoords;
161 if (fShowGrid) {
162 tex = nullptr;
163 }
164 canvas->drawPatch(fPts, nullptr, tex, xfer, paint);
151 165
152 draw_control_points(canvas, fPts); 166 draw_control_points(canvas, fPts);
153 } 167 }
154 168
155 class PtClick : public Click { 169 class PtClick : public Click {
156 public: 170 public:
157 int fIndex; 171 int fIndex;
158 PtClick(SkView* view, int index) : Click(view), fIndex(index) {} 172 PtClick(SkView* view, int index) : Click(view), fIndex(index) {}
159 }; 173 };
160 174
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 } 211 }
198 this->inval(nullptr); 212 this->inval(nullptr);
199 return true; 213 return true;
200 } 214 }
201 215
202 private: 216 private:
203 typedef SampleView INHERITED; 217 typedef SampleView INHERITED;
204 }; 218 };
205 219
206 DEF_SAMPLE( return new PerlinPatchView(); ) 220 DEF_SAMPLE( return new PerlinPatchView(); )
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698