OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 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 "SkPictureRecorder.h" | 9 #include "SkPictureRecorder.h" |
10 #include "SkShadowPaintFilterCanvas.h" | 10 #include "SkShadowPaintFilterCanvas.h" |
11 #include "SkShadowShader.h" | 11 #include "SkShadowShader.h" |
12 #include "SkSurface.h" | 12 #include "SkSurface.h" |
13 | 13 |
14 #ifdef SK_EXPERIMENTAL_SHADOWING | 14 #ifdef SK_EXPERIMENTAL_SHADOWING |
15 | 15 |
16 class ShadowingView : public SampleView { | 16 class ShadowingView : public SampleView { |
17 public: | 17 public: |
18 ShadowingView() | 18 ShadowingView() |
19 : fSceneChanged(true) | 19 : fSceneChanged(true) |
20 , fLightsChanged(true) | 20 , fLightsChanged(true) |
21 , fMoveLight(false) | 21 , fMoveLight(false) |
22 , fClearShadowMaps(false) | 22 , fClearShadowMaps(false) |
23 , fSelectedRectID(-1) | 23 , fSelectedRectID(-1) |
24 , fSelectedSliderID(-1) | 24 , fSelectedSliderID(-1) |
25 , fLightDepth(300.0f) { | 25 , fLightDepth(300.0f) { |
26 this->setBGColor(0xFFCCCCCC); | 26 this->setBGColor(0xFFCCCCCC); |
27 | 27 |
robertphillips
2016/08/26 19:16:02
In the prior CL you were calling updateLights. Why
vjiaoblack
2016/08/26 19:25:17
Done.
| |
28 this->updateLights(200, 200); | 28 SkLights::Builder builder; |
29 builder.add(SkLights::Light::MakeDirectional(SkColor3f::Make(0.2f, 0.3f, 0.4f), | |
30 SkVector3::Make(0.2f, 0.05f , 1.0f))); | |
31 builder.add(SkLights::Light::MakeDirectional(SkColor3f::Make(0.4f, 0.3f, 0.2f), | |
32 SkVector3::Make(0.05f, 0.2f , 1.0f))); | |
33 builder.setAmbientLightColor(SkColor3f::Make(0.4f, 0.4f, 0.4f)); | |
34 fLights = builder.finish(); | |
29 | 35 |
30 fTestRects[0].fColor = 0xFFEE8888; | 36 fTestRects[0].fColor = 0xFFEE8888; |
31 fTestRects[0].fDepth = 80; | 37 fTestRects[0].fDepth = 80; |
32 fTestRects[0].fGeometry = SkRect::MakeLTRB(200,150,350,300); | 38 fTestRects[0].fGeometry = SkRect::MakeLTRB(200,150,350,300); |
33 | 39 |
34 fTestRects[1].fColor = 0xFF88EE88; | 40 fTestRects[1].fColor = 0xFF88EE88; |
35 fTestRects[1].fDepth = 160; | 41 fTestRects[1].fDepth = 160; |
36 fTestRects[1].fGeometry = SkRect::MakeLTRB(150,200,300,350); | 42 fTestRects[1].fGeometry = SkRect::MakeLTRB(150,200,300,350); |
37 | 43 |
38 fTestRects[2].fColor = 0xFF8888EE; | 44 fTestRects[2].fColor = 0xFF8888EE; |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
153 paint.setColor(SK_ColorBLACK); | 159 paint.setColor(SK_ColorBLACK); |
154 canvas->drawRect(fSliders[i].fGeometry, paint); | 160 canvas->drawRect(fSliders[i].fGeometry, paint); |
155 } | 161 } |
156 } | 162 } |
157 | 163 |
158 SkView::Click* onFindClickHandler(SkScalar x, SkScalar y, unsigned modi) ove rride { | 164 SkView::Click* onFindClickHandler(SkScalar x, SkScalar y, unsigned modi) ove rride { |
159 return new SkView::Click(this); | 165 return new SkView::Click(this); |
160 } | 166 } |
161 | 167 |
162 void updateLights(int x, int y) { | 168 void updateLights(int x, int y) { |
169 float recipX = 1.0f / kWidth; | |
170 float recipY = 1.0f / kHeight; | |
171 | |
163 SkLights::Builder builder; | 172 SkLights::Builder builder; |
164 builder.add(SkLights::Light::MakePoint(SkColor3f::Make(0.2f, 0.4f, 0.6f) , | 173 builder.add(SkLights::Light::MakeDirectional( |
165 SkVector3::Make(x - 50, | 174 SkColor3f::Make(0.2f, 0.3f, 0.4f), |
166 350 - y, | 175 SkVector3::Make(0.2f + (200.0f - x) * recipX, |
167 fLightDepth), | 176 0.05f + (200.0f - y) * recipY, |
168 1024)); | 177 1.0f))); |
169 builder.add(SkLights::Light::MakePoint(SkColor3f::Make(0.6f, 0.4f, 0.2f) , | 178 builder.add(SkLights::Light::MakeDirectional( |
170 SkVector3::Make(x + 50, | 179 SkColor3f::Make(0.4f, 0.3f, 0.2f), |
171 450 - y, | 180 SkVector3::Make(0.05f + (200.0f - x) * recipX, |
172 fLightDepth), | 181 0.2f + (200.0f - y) * recipY, |
173 1024)); | 182 1.0f))); |
174 builder.add(SkLights::Light::MakeDirectional(SkColor3f::Make(0.2f, 0.2f, 0.2f), | 183 builder.setAmbientLightColor(SkColor3f::Make(0.4f, 0.4f, 0.4f)); |
175 SkVector3::Make(0.2f, 0.2f, 1.0f))); | |
176 fLights = builder.finish(); | 184 fLights = builder.finish(); |
177 } | 185 } |
178 | 186 |
179 void updateFromSelectedSlider() { | 187 void updateFromSelectedSlider() { |
180 SkScalar newValue = fSliders[fSelectedSliderID].fGeometry.fLeft * | 188 SkScalar newValue = fSliders[fSelectedSliderID].fGeometry.fLeft * |
181 fSliders[fSelectedSliderID].fScale + | 189 fSliders[fSelectedSliderID].fScale + |
182 fSliders[fSelectedSliderID].fOffset; | 190 fSliders[fSelectedSliderID].fOffset; |
183 | 191 |
184 switch (fSelectedSliderID) { | 192 switch (fSelectedSliderID) { |
185 case 0: | 193 case 0: |
(...skipping 11 matching lines...) Expand all Loading... | |
197 } | 205 } |
198 | 206 |
199 bool onClick(Click *click) override { | 207 bool onClick(Click *click) override { |
200 SkScalar x = click->fCurr.fX; | 208 SkScalar x = click->fCurr.fX; |
201 SkScalar y = click->fCurr.fY; | 209 SkScalar y = click->fCurr.fY; |
202 | 210 |
203 SkScalar dx = x - click->fPrev.fX; | 211 SkScalar dx = x - click->fPrev.fX; |
204 SkScalar dy = y - click->fPrev.fY; | 212 SkScalar dy = y - click->fPrev.fY; |
205 | 213 |
206 if (fMoveLight) { | 214 if (fMoveLight) { |
207 if (dx != 0 || dy != 0) { | 215 if (dx != 0 || dy != 0) { |
robertphillips
2016/08/26 19:16:02
this-> - from prior CL
| |
208 this->updateLights(x, y); | 216 updateLights(x, y); |
209 fLightsChanged = true; | 217 fLightsChanged = true; |
210 this->inval(nullptr); | 218 this->inval(nullptr); |
211 } | 219 } |
212 return true; | 220 return true; |
213 } | 221 } |
214 | 222 |
215 if (click->fState == Click::State::kUp_State) { | 223 if (click->fState == Click::State::kUp_State) { |
216 fSelectedRectID = -1; | 224 fSelectedRectID = -1; |
217 fSelectedSliderID = -1; | 225 fSelectedSliderID = -1; |
218 return true; | 226 return true; |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
298 sk_sp<SkLights> fLights; | 306 sk_sp<SkLights> fLights; |
299 | 307 |
300 typedef SampleView INHERITED; | 308 typedef SampleView INHERITED; |
301 }; | 309 }; |
302 | 310 |
303 ////////////////////////////////////////////////////////////////////////////// | 311 ////////////////////////////////////////////////////////////////////////////// |
304 static SkView* MyFactory() { return new ShadowingView; } | 312 static SkView* MyFactory() { return new ShadowingView; } |
305 static SkViewRegister reg(MyFactory); | 313 static SkViewRegister reg(MyFactory); |
306 | 314 |
307 #endif | 315 #endif |
OLD | NEW |