OLD | NEW |
---|---|
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2016 Google Inc. | 3 * Copyright 2016 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 #include "SampleCode.h" | 8 #include "SampleCode.h" |
9 #include "SkBlurMask.h" | 9 #include "SkBlurMask.h" |
10 #include "SkBlurMaskFilter.h" | 10 #include "SkBlurMaskFilter.h" |
(...skipping 23 matching lines...) Expand all Loading... | |
34 : fShowAmbient(true) | 34 : fShowAmbient(true) |
35 , fShowSpot(true) | 35 , fShowSpot(true) |
36 , fUseAlt(true) | 36 , fUseAlt(true) |
37 , fShowObject(true) {} | 37 , fShowObject(true) {} |
38 | 38 |
39 protected: | 39 protected: |
40 void onOnceBeforeDraw() override { | 40 void onOnceBeforeDraw() override { |
41 fCirclePath.addCircle(0, 0, 50); | 41 fCirclePath.addCircle(0, 0, 50); |
42 fRectPath.addRect(SkRect::MakeXYWH(-100, -50, 200, 100)); | 42 fRectPath.addRect(SkRect::MakeXYWH(-100, -50, 200, 100)); |
43 fRRPath.addRRect(SkRRect::MakeRectXY(SkRect::MakeXYWH(-100, -50, 200, 10 0), 4, 4)); | 43 fRRPath.addRRect(SkRRect::MakeRectXY(SkRect::MakeXYWH(-100, -50, 200, 10 0), 4, 4)); |
44 fLightPos = SkPoint3::Make(-2, -2, 6); | 44 fLightPos = SkPoint3::Make(-700, -700, 2800); |
45 } | 45 } |
46 | 46 |
47 // overrides from SkEventSink | 47 // overrides from SkEventSink |
48 bool onQuery(SkEvent* evt) override { | 48 bool onQuery(SkEvent* evt) override { |
49 if (SampleCode::TitleQ(*evt)) { | 49 if (SampleCode::TitleQ(*evt)) { |
50 SampleCode::TitleR(evt, "AndroidShadows"); | 50 SampleCode::TitleR(evt, "AndroidShadows"); |
51 return true; | 51 return true; |
52 } | 52 } |
53 | 53 |
54 SkUnichar uni; | 54 SkUnichar uni; |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
141 | 141 |
142 if (ambientAlpha <= 0) { | 142 if (ambientAlpha <= 0) { |
143 return; | 143 return; |
144 } | 144 } |
145 | 145 |
146 const SkScalar kHeightFactor = 1.f / 128.f; | 146 const SkScalar kHeightFactor = 1.f / 128.f; |
147 const SkScalar kGeomFactor = 64; | 147 const SkScalar kGeomFactor = 64; |
148 | 148 |
149 SkScalar umbraAlpha = 1 / (1 + SkMaxScalar(zValue*kHeightFactor, 0)); | 149 SkScalar umbraAlpha = 1 / (1 + SkMaxScalar(zValue*kHeightFactor, 0)); |
150 SkScalar radius = zValue*kHeightFactor*kGeomFactor; | 150 SkScalar radius = zValue*kHeightFactor*kGeomFactor; |
151 // distance to outer of edge of geometry from original shape edge | |
152 SkScalar offset = radius*umbraAlpha; | |
151 | 153 |
152 SkRect pathRect; | 154 SkRect pathRect; |
153 SkRRect pathRRect; | 155 SkRRect pathRRect; |
154 if (radius >= 64 || | 156 SkScalar scaleFactors[2]; |
157 if (!canvas->getTotalMatrix().getMinMaxScales(scaleFactors)) { | |
158 return; | |
159 } | |
160 if (scaleFactors[0] != scaleFactors[1] || radius*scaleFactors[0] >= 64 | | | |
155 !((path.isOval(&pathRect) && pathRect.width() == pathRect.height()) || | 161 !((path.isOval(&pathRect) && pathRect.width() == pathRect.height()) || |
156 (path.isRRect(&pathRRect) && pathRRect.allCornersCircular()) || | 162 (path.isRRect(&pathRRect) && pathRRect.allCornersCircular()) || |
157 path.isRect(&pathRect))) { | 163 path.isRect(&pathRect))) { |
158 this->drawAmbientShadow(canvas, path, zValue, ambientAlpha); | 164 this->drawAmbientShadow(canvas, path, zValue, ambientAlpha); |
159 return; | 165 return; |
160 } | 166 } |
161 | 167 |
162 // For all of these, we outset the rect by half the radius to get our st roke shape. | 168 // For all of these, we inset the offset rect by half the radius to get our stroke shape. |
163 SkScalar halfRadius = SK_ScalarHalf*radius; | 169 SkScalar strokeOutset = offset - SK_ScalarHalf*radius; |
170 // Make sure we'll have a radius of at least 0.5 after xform | |
171 if (strokeOutset*scaleFactors[0] < 0.5f) { | |
172 strokeOutset = 0.5f / scaleFactors[0]; | |
173 } | |
164 if (path.isOval(nullptr)) { | 174 if (path.isOval(nullptr)) { |
165 pathRect.outset(halfRadius, halfRadius); | 175 pathRect.outset(strokeOutset, strokeOutset); |
166 pathRRect = SkRRect::MakeOval(pathRect); | 176 pathRRect = SkRRect::MakeOval(pathRect); |
167 } else if (path.isRect(nullptr)) { | 177 } else if (path.isRect(nullptr)) { |
168 pathRect.outset(halfRadius, halfRadius); | 178 pathRect.outset(strokeOutset, strokeOutset); |
169 pathRRect = SkRRect::MakeRectXY(pathRect, halfRadius, halfRadius); | 179 pathRRect = SkRRect::MakeRectXY(pathRect, strokeOutset, strokeOutset ); |
170 } else { | 180 } else { |
171 pathRRect.outset(halfRadius, halfRadius); | 181 pathRRect.outset(strokeOutset, strokeOutset); |
172 } | 182 } |
173 | 183 |
174 SkPaint paint; | 184 SkPaint paint; |
175 paint.setAntiAlias(true); | 185 paint.setAntiAlias(true); |
176 paint.setStyle(SkPaint::kStroke_Style); | 186 paint.setStyle(SkPaint::kStroke_Style); |
177 // we outset the stroke a little to cover up AA on the interior edge | 187 // we outset the stroke a little to cover up AA on the interior edge |
178 paint.setStrokeWidth(radius + 1); | 188 SkScalar pad = 0.5f; |
179 // handle scale of radius due to CTM | 189 paint.setStrokeWidth(radius + 2*pad); |
180 SkScalar maxScale = canvas->getTotalMatrix().getMaxScale(); | 190 // handle scale of radius and pad due to CTM |
181 radius *= maxScale; | 191 radius *= scaleFactors[0]; |
182 unsigned char gray = (unsigned char)(ambientAlpha*umbraAlpha*255.999f); | 192 pad *= scaleFactors[0]; |
183 SkASSERT(radius < 64); | 193 SkASSERT(radius < 16384); |
184 // Convert radius to 6.2 fixed point and place in the G component. | 194 SkASSERT(pad < 64); |
herb_g
2016/09/07 18:22:00
how about:
uint16_t iRadius = (uint16_t)(radius *
jvanverth1
2016/09/08 18:12:35
Done.
| |
185 paint.setColor(SkColorSetARGB(1, gray, (unsigned char)(4.0f*radius), 0)) ; | 195 // Convert radius to 14.2 fixed point and place in the R & G components. |
196 // Convert pad to 6.2 fixed point and place in the B component. | |
197 unsigned int red = (unsigned int)(radius*0.015625f); | |
198 unsigned char alpha = (unsigned char)(ambientAlpha*255.999f); | |
199 paint.setColor(SkColorSetARGB(alpha, red, (unsigned char)(4.0f*(radius - red)), | |
200 (unsigned char)(4.0f*pad))); | |
186 | 201 |
187 sk_sp<SkShader> gaussShader = SkGaussianEdgeShader::Make(); | 202 sk_sp<SkShader> gaussShader = SkGaussianEdgeShader::Make(); |
188 paint.setShader(gaussShader); | 203 paint.setShader(gaussShader); |
189 canvas->drawRRect(pathRRect, paint); | 204 canvas->drawRRect(pathRRect, paint); |
190 } | 205 } |
191 | 206 |
192 void drawSpotShadow(SkCanvas* canvas, const SkPath& path, SkScalar zValue, | 207 void drawSpotShadow(SkCanvas* canvas, const SkPath& path, SkScalar zValue, |
193 SkPoint3 lightPos, SkScalar lightWidth, SkScalar spotAlp ha) { | 208 SkPoint3 lightPos, SkScalar lightWidth, SkScalar spotAlp ha) { |
194 if (spotAlpha <= 0) { | 209 if (spotAlpha <= 0) { |
195 return; | 210 return; |
196 } | 211 } |
197 | 212 |
198 SkScalar zRatio = zValue / (lightPos.fZ - zValue); | 213 SkScalar zRatio = zValue / (lightPos.fZ - zValue); |
199 if (zRatio < 0.0f) { | 214 if (zRatio < 0.0f) { |
200 zRatio = 0.0f; | 215 zRatio = 0.0f; |
201 } else if (zRatio > 0.95f) { | 216 } else if (zRatio > 0.95f) { |
202 zRatio = 0.95f; | 217 zRatio = 0.95f; |
203 } | 218 } |
204 SkScalar radius = lightWidth*zRatio; | 219 SkScalar blurRadius = lightWidth*zRatio; |
205 | 220 |
206 // compute the transformation params | 221 // compute the transformation params |
207 SkPoint center = SkPoint::Make(path.getBounds().centerX(), path.getBound s().centerY()); | 222 SkPoint center = SkPoint::Make(path.getBounds().centerX(), path.getBound s().centerY()); |
208 canvas->getTotalMatrix().mapPoints(¢er, 1); | 223 canvas->getTotalMatrix().mapPoints(¢er, 1); |
209 SkPoint offset = SkPoint::Make(-zRatio*(lightPos.fX - center.fX), | 224 SkPoint offset = SkPoint::Make(-zRatio*(lightPos.fX - center.fX), |
210 -zRatio*(lightPos.fY - center.fY)); | 225 -zRatio*(lightPos.fY - center.fY)); |
211 SkScalar scale = lightPos.fZ / (lightPos.fZ - zValue); | 226 SkScalar scale = lightPos.fZ / (lightPos.fZ - zValue); |
212 if (scale < 1.0f) { | |
213 scale = 1.0f; | |
214 } else if (scale > 1024.f) { | |
215 scale = 1024.f; | |
216 } | |
217 | 227 |
218 SkAutoCanvasRestore acr(canvas, true); | 228 SkAutoCanvasRestore acr(canvas, true); |
219 | 229 |
220 SkRect occlRect; | |
221 GetOcclRect(path, &occlRect); | |
222 // apply inverse transform | |
223 occlRect.offset(-offset); | |
224 #if 0 | |
225 // It looks like the scale may be invalid | |
226 SkScalar scale = lightPos.fZ / (lightPos.fZ - zValue); | |
227 if (scale < 1.0f) { | |
228 scale = 1.0f; | |
229 } else if (scale > 1024.f) { | |
230 scale = 1024.f; | |
231 } | |
232 occlRect.fLeft /= scale; | |
233 occlRect.fRight /= scale; | |
234 occlRect.fTop /= scale; | |
235 occlRect.fBottom /= scale; | |
236 #endif | |
237 sk_sp<SkMaskFilter> mf = SkBlurMaskFilter::Make(kNormal_SkBlurStyle, | 230 sk_sp<SkMaskFilter> mf = SkBlurMaskFilter::Make(kNormal_SkBlurStyle, |
238 SkBlurMask::ConvertRadiu sToSigma(radius), | 231 SkBlurMask::ConvertRadiu sToSigma(blurRadius), |
239 occlRect, | |
240 SkBlurMaskFilter::kNone_ BlurFlag); | 232 SkBlurMaskFilter::kNone_ BlurFlag); |
241 | 233 |
242 SkPaint paint; | 234 SkPaint paint; |
243 paint.setAntiAlias(true); | 235 paint.setAntiAlias(true); |
244 paint.setMaskFilter(std::move(mf)); | 236 paint.setMaskFilter(std::move(mf)); |
245 paint.setColor(SkColorSetARGB((unsigned char)(spotAlpha*255.999f), 0, 0, 0)); | 237 paint.setColor(SkColorSetARGB((unsigned char)(spotAlpha*255.999f), 0, 0, 0)); |
246 | 238 |
247 // apply transformation to shadow | 239 // apply transformation to shadow |
240 canvas->scale(scale, scale); | |
248 canvas->translate(offset.fX, offset.fY); | 241 canvas->translate(offset.fX, offset.fY); |
249 #if 0 | |
250 // It looks like the scale may be invalid | |
251 canvas->scale(scale, scale); | |
252 #endif | |
253 canvas->drawPath(path, paint); | 242 canvas->drawPath(path, paint); |
254 | |
255 // draw occlusion rect | |
256 #if DRAW_OCCL_RECT | |
257 SkPaint stroke; | |
258 stroke.setStyle(SkPaint::kStroke_Style); | |
259 stroke.setColor(SK_ColorRED); | |
260 canvas->drawRect(occlRect, stroke) | |
261 #endif | |
262 } | 243 } |
263 | 244 |
264 void drawSpotShadowAlt(SkCanvas* canvas, const SkPath& path, SkScalar zValue , | 245 void drawSpotShadowAlt(SkCanvas* canvas, const SkPath& path, SkScalar zValue , |
265 SkPoint3 lightPos, SkScalar lightWidth, SkScalar spotAlp ha) { | 246 SkPoint3 lightPos, SkScalar lightWidth, SkScalar spotAlp ha) { |
266 if (spotAlpha <= 0) { | 247 if (spotAlpha <= 0) { |
267 return; | 248 return; |
268 } | 249 } |
269 | 250 |
270 SkScalar zRatio = zValue / (lightPos.fZ - zValue); | 251 SkScalar zRatio = zValue / (lightPos.fZ - zValue); |
271 if (zRatio < 0.0f) { | 252 if (zRatio < 0.0f) { |
272 zRatio = 0.0f; | 253 zRatio = 0.0f; |
273 } else if (zRatio > 0.95f) { | 254 } else if (zRatio > 0.95f) { |
274 zRatio = 0.95f; | 255 zRatio = 0.95f; |
275 } | 256 } |
276 SkScalar radius = lightWidth*zRatio; | 257 SkScalar radius = 2.0f*lightWidth*zRatio; |
277 | 258 |
278 SkRect pathRect; | 259 SkRect pathRect; |
279 SkRRect pathRRect; | 260 SkRRect pathRRect; |
280 if (radius >= 64 || | 261 SkScalar scaleFactors[2]; |
262 if (!canvas->getTotalMatrix().getMinMaxScales(scaleFactors)) { | |
263 return; | |
264 } | |
265 if (scaleFactors[0] != scaleFactors[1] || radius*scaleFactors[0] >= 1638 4 || | |
281 !((path.isOval(&pathRect) && pathRect.width() == pathRect.height()) || | 266 !((path.isOval(&pathRect) && pathRect.width() == pathRect.height()) || |
282 (path.isRRect(&pathRRect) && pathRRect.allCornersCircular()) || | 267 (path.isRRect(&pathRRect) && pathRRect.allCornersCircular()) || |
283 path.isRect(&pathRect))) { | 268 path.isRect(&pathRect))) { |
284 this->drawSpotShadow(canvas, path, zValue, lightPos, lightWidth, spo tAlpha); | 269 this->drawSpotShadow(canvas, path, zValue, lightPos, lightWidth, spo tAlpha); |
285 return; | 270 return; |
286 } | 271 } |
287 | 272 |
288 // For all of these, we outset the rect by half the radius to get our st roke shape. | 273 // For all of these, we need to ensure we have a rrect with radius >= 0. 5f in device space |
289 SkScalar halfRadius = SK_ScalarHalf*radius; | 274 SkScalar minRadius = SK_ScalarHalf/scaleFactors[0]; |
290 if (path.isOval(nullptr)) { | 275 if (path.isOval(nullptr)) { |
291 pathRect.outset(halfRadius, halfRadius); | |
292 pathRRect = SkRRect::MakeOval(pathRect); | 276 pathRRect = SkRRect::MakeOval(pathRect); |
293 } else if (path.isRect(nullptr)) { | 277 } else if (path.isRect(nullptr)) { |
294 pathRect.outset(halfRadius, halfRadius); | 278 pathRRect = SkRRect::MakeRectXY(pathRect, minRadius, minRadius); |
295 pathRRect = SkRRect::MakeRectXY(pathRect, halfRadius, halfRadius); | |
296 } else { | 279 } else { |
297 pathRRect.outset(halfRadius, halfRadius); | 280 if (pathRRect.getSimpleRadii().fX < minRadius) { |
281 pathRRect.setRectXY(pathRRect.rect(), minRadius, minRadius); | |
282 } | |
298 } | 283 } |
299 | 284 |
300 // compute the transformation params | 285 // compute the scale and translation for the shadow |
301 SkPoint center = SkPoint::Make(path.getBounds().centerX(), path.getBound s().centerY()); | 286 SkScalar scale = lightPos.fZ / (lightPos.fZ - zValue); |
287 SkMatrix shadowXform; | |
288 shadowXform.setScale(scale, scale); | |
289 SkRRect shadowRRect; | |
290 pathRRect.transform(shadowXform, &shadowRRect); | |
herb_g
2016/09/07 18:22:00
....transform(SkMatrix::MakeScale(scale, scale), &
jvanverth1
2016/09/08 18:12:35
Done.
| |
291 SkPoint center = SkPoint::Make(shadowRRect.rect().centerX(), shadowRRect .rect().centerY()); | |
302 canvas->getTotalMatrix().mapPoints(¢er, 1); | 292 canvas->getTotalMatrix().mapPoints(¢er, 1); |
303 SkPoint offset = SkPoint::Make(-zRatio*(lightPos.fX - center.fX), | 293 SkPoint offset = SkPoint::Make(zRatio*(center.fX - lightPos.fX), |
304 -zRatio*(lightPos.fY - center.fY)); | 294 zRatio*(center.fY - lightPos.fY)); |
305 SkAutoCanvasRestore acr(canvas, true); | 295 SkAutoCanvasRestore acr(canvas, true); |
306 | 296 |
307 SkPaint paint; | 297 SkPaint paint; |
308 paint.setAntiAlias(true); | 298 paint.setAntiAlias(true); |
309 // We outset the stroke by the length of the translation so the shadow e xtends to | 299 // We outset the stroke by the length of the translation so the shadow e xtends to |
310 // the edge of the shape. We also add 1/2 to cover up AA on the interior edge. | 300 // the edge of the shape. We also add 1/2 to cover up AA on the interior edge. |
311 SkScalar pad = offset.length() + 0.5f; | 301 SkScalar pad = offset.length() + 0.5f; |
312 // compute area | 302 // compute area |
313 SkScalar strokeWidth = radius + 2.0f*pad; | 303 SkScalar strokeWidth = radius + 2.0f*pad/scaleFactors[0]; |
314 SkScalar strokedArea = 2.0f*strokeWidth*(pathRRect.width() + pathRRect.h eight()); | 304 SkScalar strokedArea = 2.0f*strokeWidth*(shadowRRect.width() + shadowRRe ct.height()); |
315 SkScalar filledArea = (pathRRect.height() + radius)*(pathRRect.width() + radius); | 305 SkScalar filledArea = (shadowRRect.height() + radius)*(shadowRRect.width () + radius); |
316 // If the area of the stroked geometry is larger than the fill geometry, or | 306 // If the area of the stroked geometry is larger than the fill geometry, or |
317 // if our pad is too big to convert to 6.2 fixed point, just fill it. | 307 // if our pad is too big to convert to 6.2 fixed point, just fill it. |
318 if (strokedArea > filledArea || pad >= 64) { | 308 if (strokedArea > filledArea || pad >= 64) { |
319 pad = 0; | 309 pad = 0; |
320 paint.setStyle(SkPaint::kStrokeAndFill_Style); | 310 paint.setStyle(SkPaint::kStrokeAndFill_Style); |
321 paint.setStrokeWidth(radius); | 311 paint.setStrokeWidth(radius); |
322 } else { | 312 } else { |
323 paint.setStyle(SkPaint::kStroke_Style); | 313 paint.setStyle(SkPaint::kStroke_Style); |
324 paint.setStrokeWidth(strokeWidth); | 314 paint.setStrokeWidth(strokeWidth); |
325 } | 315 } |
326 sk_sp<SkShader> gaussShader = SkGaussianEdgeShader::Make(); | 316 sk_sp<SkShader> gaussShader = SkGaussianEdgeShader::Make(); |
327 paint.setShader(gaussShader); | 317 paint.setShader(gaussShader); |
328 // handle scale of radius due to CTM | 318 // handle scale of radius due to CTM |
329 SkScalar maxScale = canvas->getTotalMatrix().getMaxScale(); | 319 radius *= scaleFactors[0]; |
330 radius *= maxScale; | 320 // don't need to scale pad as it was computed from the transformed offse t |
331 unsigned char gray = (unsigned char)(spotAlpha*255.999f); | 321 SkASSERT(radius < 16384); |
332 SkASSERT(radius < 64); | |
333 SkASSERT(pad < 64); | 322 SkASSERT(pad < 64); |
334 // Convert radius and pad to 6.2 fixed point and place in the G & B comp onents. | 323 // Convert radius to 14.2 fixed point and place in the R & G components. |
335 paint.setColor(SkColorSetARGB(1, gray, (unsigned char)(radius*4.0f), | 324 // Convert pad to 6.2 fixed point and place in the B component. |
336 (unsigned char)(pad*4.0f))); | 325 unsigned int red = (unsigned int)(radius*0.015625f); |
326 unsigned char alpha = (unsigned char)(spotAlpha*255.999f); | |
327 paint.setColor(SkColorSetARGB(alpha, red, (unsigned char)(4.0f*(radius - red)), | |
328 (unsigned char)(4.0f*pad))); | |
337 | 329 |
338 // apply transformation to shadow | 330 // apply transformation to shadow |
339 canvas->translate(offset.fX, offset.fY); | 331 canvas->translate(offset.fX, offset.fY); |
340 #if 0 | 332 canvas->drawRRect(shadowRRect, paint); |
341 // It looks like the scale may be invalid | |
342 SkScalar scale = lightPos.fZ / (lightPos.fZ - zValue); | |
343 if (scale < 1.0f) { | |
344 scale = 1.0f; | |
345 } else if (scale > 1024.f) { | |
346 scale = 1024.f; | |
347 } | |
348 canvas->scale(scale, scale); | |
349 #endif | |
350 canvas->drawRRect(pathRRect, paint); | |
351 } | 333 } |
352 | 334 |
353 void drawShadowedPath(SkCanvas* canvas, const SkPath& path, SkScalar zValue, | 335 void drawShadowedPath(SkCanvas* canvas, const SkPath& path, SkScalar zValue, |
354 const SkPaint& paint, SkScalar ambientAlpha, | 336 const SkPaint& paint, SkScalar ambientAlpha, |
355 const SkPoint3& lightPos, SkScalar lightWidth, SkScala r spotAlpha) { | 337 const SkPoint3& lightPos, SkScalar lightWidth, SkScala r spotAlpha) { |
356 if (fShowAmbient) { | 338 if (fShowAmbient) { |
357 if (fUseAlt) { | 339 if (fUseAlt) { |
358 this->drawAmbientShadowAlt(canvas, path, zValue, ambientAlpha); | 340 this->drawAmbientShadowAlt(canvas, path, zValue, ambientAlpha); |
359 } else { | 341 } else { |
360 this->drawAmbientShadow(canvas, path, zValue, ambientAlpha); | 342 this->drawAmbientShadow(canvas, path, zValue, ambientAlpha); |
361 } | 343 } |
362 } | 344 } |
363 if (fShowSpot) { | 345 if (fShowSpot) { |
364 if (fUseAlt) { | 346 if (fUseAlt) { |
365 this->drawSpotShadowAlt(canvas, path, zValue, lightPos, lightWid th, spotAlpha); | 347 this->drawSpotShadowAlt(canvas, path, zValue, lightPos, lightWid th, spotAlpha); |
366 } else { | 348 } else { |
367 this->drawSpotShadow(canvas, path, zValue, lightPos, lightWidth, spotAlpha); | 349 this->drawSpotShadow(canvas, path, zValue, lightPos, lightWidth, spotAlpha); |
368 } | 350 } |
369 } | 351 } |
370 if (fShowObject) { | 352 if (fShowObject) { |
371 canvas->drawPath(path, paint); | 353 canvas->drawPath(path, paint); |
372 } | 354 } |
373 } | 355 } |
374 | 356 |
375 void onDrawContent(SkCanvas* canvas) override { | 357 void onDrawContent(SkCanvas* canvas) override { |
376 this->drawBG(canvas); | 358 this->drawBG(canvas); |
377 const SkScalar kLightWidth = 3; | 359 const SkScalar kLightWidth = 2800; |
378 const SkScalar kAmbientAlpha = 0.25f; | 360 const SkScalar kAmbientAlpha = 0.25f; |
379 const SkScalar kSpotAlpha = 0.25f; | 361 const SkScalar kSpotAlpha = 0.25f; |
380 | 362 |
381 SkPaint paint; | 363 SkPaint paint; |
382 paint.setAntiAlias(true); | 364 paint.setAntiAlias(true); |
383 | 365 |
384 SkPoint3 lightPos = fLightPos; | 366 SkPoint3 lightPos = fLightPos; |
385 | 367 |
386 paint.setColor(SK_ColorWHITE); | 368 paint.setColor(SK_ColorWHITE); |
387 canvas->translate(200, 90); | 369 canvas->translate(200, 90); |
388 lightPos.fX += 200; | 370 lightPos.fX += 200; |
389 lightPos.fY += 90; | 371 lightPos.fY += 90; |
390 this->drawShadowedPath(canvas, fRectPath, 5, paint, kAmbientAlpha, | 372 this->drawShadowedPath(canvas, fRectPath, 2, paint, kAmbientAlpha, |
391 lightPos, kLightWidth, kSpotAlpha); | 373 lightPos, kLightWidth, kSpotAlpha); |
392 | 374 |
393 paint.setColor(SK_ColorRED); | 375 paint.setColor(SK_ColorRED); |
394 canvas->translate(250, 0); | 376 canvas->translate(250, 0); |
395 lightPos.fX += 250; | 377 lightPos.fX += 250; |
396 this->drawShadowedPath(canvas, fRRPath, 5, paint, kAmbientAlpha, | 378 this->drawShadowedPath(canvas, fRRPath, 4, paint, kAmbientAlpha, |
397 lightPos, kLightWidth, kSpotAlpha); | 379 lightPos, kLightWidth, kSpotAlpha); |
398 | 380 |
399 paint.setColor(SK_ColorBLUE); | 381 paint.setColor(SK_ColorBLUE); |
400 canvas->translate(-250, 110); | 382 canvas->translate(-250, 110); |
401 lightPos.fX -= 250; | 383 lightPos.fX -= 250; |
402 lightPos.fY += 110; | 384 lightPos.fY += 110; |
403 this->drawShadowedPath(canvas, fCirclePath, 5, paint, 0.0f, | 385 this->drawShadowedPath(canvas, fCirclePath, 8, paint, 0.0f, |
404 lightPos, kLightWidth, 0.5f); | 386 lightPos, kLightWidth, 0.5f); |
405 | 387 |
406 paint.setColor(SK_ColorGREEN); | 388 paint.setColor(SK_ColorGREEN); |
407 canvas->translate(250, 0); | 389 canvas->translate(250, 0); |
408 lightPos.fX += 250; | 390 lightPos.fX += 250; |
409 this->drawShadowedPath(canvas, fRRPath, 5, paint, kAmbientAlpha, | 391 this->drawShadowedPath(canvas, fRRPath, 16, paint, kAmbientAlpha, |
410 lightPos, kLightWidth, kSpotAlpha); | 392 lightPos, kLightWidth, kSpotAlpha); |
411 } | 393 } |
412 | 394 |
413 protected: | 395 protected: |
414 SkView::Click* onFindClickHandler(SkScalar x, SkScalar y, unsigned modi) ove rride { | 396 SkView::Click* onFindClickHandler(SkScalar x, SkScalar y, unsigned modi) ove rride { |
415 return new SkView::Click(this); | 397 return new SkView::Click(this); |
416 } | 398 } |
417 | 399 |
418 bool onClick(Click *click) override { | 400 bool onClick(Click *click) override { |
419 SkScalar x = click->fCurr.fX; | 401 SkScalar x = click->fCurr.fX; |
(...skipping 12 matching lines...) Expand all Loading... | |
432 } | 414 } |
433 | 415 |
434 private: | 416 private: |
435 typedef SkView INHERITED; | 417 typedef SkView INHERITED; |
436 }; | 418 }; |
437 | 419 |
438 ////////////////////////////////////////////////////////////////////////////// | 420 ////////////////////////////////////////////////////////////////////////////// |
439 | 421 |
440 static SkView* MyFactory() { return new ShadowsView; } | 422 static SkView* MyFactory() { return new ShadowsView; } |
441 static SkViewRegister reg(MyFactory); | 423 static SkViewRegister reg(MyFactory); |
OLD | NEW |