2016-08-12 17:40:38 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright 2016 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
2018-08-08 15:36:17 +00:00
|
|
|
#include "Sample.h"
|
2017-03-10 19:34:51 +00:00
|
|
|
#include "SkAnimTimer.h"
|
2016-08-12 17:40:38 +00:00
|
|
|
#include "SkBlurMask.h"
|
|
|
|
#include "SkBlurMaskFilter.h"
|
2017-02-06 19:36:01 +00:00
|
|
|
#include "SkColorFilter.h"
|
2017-03-10 19:34:51 +00:00
|
|
|
#include "SkCamera.h"
|
2016-08-12 17:40:38 +00:00
|
|
|
#include "SkCanvas.h"
|
|
|
|
#include "SkPath.h"
|
2017-03-10 19:34:51 +00:00
|
|
|
#include "SkPathOps.h"
|
2016-08-12 17:40:38 +00:00
|
|
|
#include "SkPoint3.h"
|
2017-01-13 19:37:37 +00:00
|
|
|
#include "SkShadowUtils.h"
|
2018-08-21 15:45:46 +00:00
|
|
|
#include "SkUTF.h"
|
2016-08-12 17:40:38 +00:00
|
|
|
#include "sk_tool_utils.h"
|
|
|
|
|
2016-08-17 14:59:41 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2018-08-08 15:36:17 +00:00
|
|
|
class ShadowsView : public Sample {
|
2016-08-12 17:40:38 +00:00
|
|
|
SkPath fRectPath;
|
|
|
|
SkPath fRRPath;
|
|
|
|
SkPath fCirclePath;
|
2017-01-25 14:39:46 +00:00
|
|
|
SkPath fFunkyRRPath;
|
|
|
|
SkPath fCubicPath;
|
2018-04-10 15:24:11 +00:00
|
|
|
SkPath fStarPath;
|
2017-03-10 19:34:51 +00:00
|
|
|
SkPath fSquareRRectPath;
|
|
|
|
SkPath fWideRectPath;
|
|
|
|
SkPath fWideOvalPath;
|
2018-04-10 15:24:11 +00:00
|
|
|
SkPath fNotchPath;
|
|
|
|
SkPath fTabPath;
|
|
|
|
|
2016-08-12 17:40:38 +00:00
|
|
|
SkPoint3 fLightPos;
|
2017-02-06 19:36:01 +00:00
|
|
|
SkScalar fZDelta;
|
2017-03-10 19:34:51 +00:00
|
|
|
SkScalar fAnimTranslate;
|
2017-04-11 19:29:14 +00:00
|
|
|
SkScalar fAnimAngle;
|
2017-12-19 18:02:38 +00:00
|
|
|
SkScalar fAnimAlpha;
|
2016-08-12 17:40:38 +00:00
|
|
|
|
|
|
|
bool fShowAmbient;
|
|
|
|
bool fShowSpot;
|
2016-08-17 17:06:18 +00:00
|
|
|
bool fUseAlt;
|
2016-08-12 17:40:38 +00:00
|
|
|
bool fShowObject;
|
2016-10-07 18:44:07 +00:00
|
|
|
bool fIgnoreShadowAlpha;
|
2017-12-19 18:02:38 +00:00
|
|
|
bool fDoAlphaAnimation;
|
2016-08-12 17:40:38 +00:00
|
|
|
|
|
|
|
public:
|
2017-02-06 19:36:01 +00:00
|
|
|
ShadowsView()
|
2017-03-10 19:34:51 +00:00
|
|
|
: fZDelta(0)
|
|
|
|
, fAnimTranslate(0)
|
2017-04-11 19:29:14 +00:00
|
|
|
, fAnimAngle(0)
|
2017-12-19 18:02:38 +00:00
|
|
|
, fAnimAlpha(1)
|
2017-02-06 19:36:01 +00:00
|
|
|
, fShowAmbient(true)
|
2016-08-12 17:40:38 +00:00
|
|
|
, fShowSpot(true)
|
2017-04-28 15:00:35 +00:00
|
|
|
, fUseAlt(false)
|
2016-10-07 18:44:07 +00:00
|
|
|
, fShowObject(true)
|
2017-12-19 18:02:38 +00:00
|
|
|
, fIgnoreShadowAlpha(false)
|
|
|
|
, fDoAlphaAnimation(false) {}
|
2016-08-12 17:40:38 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
void onOnceBeforeDraw() override {
|
|
|
|
fCirclePath.addCircle(0, 0, 50);
|
|
|
|
fRectPath.addRect(SkRect::MakeXYWH(-100, -50, 200, 100));
|
|
|
|
fRRPath.addRRect(SkRRect::MakeRectXY(SkRect::MakeXYWH(-100, -50, 200, 100), 4, 4));
|
2017-01-25 14:39:46 +00:00
|
|
|
fFunkyRRPath.addRoundRect(SkRect::MakeXYWH(-50, -50, SK_Scalar1 * 100, SK_Scalar1 * 100),
|
|
|
|
40 * SK_Scalar1, 20 * SK_Scalar1,
|
|
|
|
SkPath::kCW_Direction);
|
|
|
|
fCubicPath.cubicTo(100 * SK_Scalar1, 50 * SK_Scalar1,
|
|
|
|
20 * SK_Scalar1, 100 * SK_Scalar1,
|
|
|
|
0 * SK_Scalar1, 0 * SK_Scalar1);
|
2018-04-10 15:24:11 +00:00
|
|
|
fStarPath.moveTo(0.0f, -50.0f);
|
|
|
|
fStarPath.lineTo(14.43f, -25.0f);
|
|
|
|
fStarPath.lineTo(43.30f, -25.0f);
|
|
|
|
fStarPath.lineTo(28.86f, 0.0f);
|
|
|
|
fStarPath.lineTo(43.30f, 25.0f);
|
|
|
|
fStarPath.lineTo(14.43f, 25.0f);
|
|
|
|
fStarPath.lineTo(0.0f, 50.0f);
|
|
|
|
fStarPath.lineTo(-14.43f, 25.0f);
|
|
|
|
fStarPath.lineTo(-43.30f, 25.0f);
|
|
|
|
fStarPath.lineTo(-28.86f, 0.0f);
|
|
|
|
fStarPath.lineTo(-43.30f, -25.0f);
|
|
|
|
fStarPath.lineTo(-14.43f, -25.0f);
|
2017-03-10 19:34:51 +00:00
|
|
|
fSquareRRectPath.addRRect(SkRRect::MakeRectXY(SkRect::MakeXYWH(-50, -50, 100, 100),
|
|
|
|
10, 10));
|
|
|
|
fWideRectPath.addRect(SkRect::MakeXYWH(0, 0, 630, 70));
|
|
|
|
fWideOvalPath.addOval(SkRect::MakeXYWH(0, 0, 630, 70));
|
2017-01-25 14:39:46 +00:00
|
|
|
|
2018-04-10 15:24:11 +00:00
|
|
|
fNotchPath.moveTo(0, 80);
|
|
|
|
fNotchPath.arcTo(SkRect::MakeLTRB(-20, 80, 20, 120), -90, -90, false);
|
|
|
|
fNotchPath.lineTo(-75, 100);
|
|
|
|
fNotchPath.lineTo(-75, -100);
|
|
|
|
fNotchPath.lineTo(75, -100);
|
|
|
|
fNotchPath.lineTo(75, 100);
|
|
|
|
fNotchPath.arcTo(SkRect::MakeLTRB(-20, 80, 20, 120), 0, -90, false);
|
|
|
|
|
|
|
|
fTabPath.moveTo(-75, -100);
|
|
|
|
fTabPath.lineTo(75, -100);
|
|
|
|
fTabPath.lineTo(75, 100);
|
|
|
|
fTabPath.arcTo(SkRect::MakeLTRB(-20, 80, 20, 120), 0, 90, false);
|
|
|
|
fTabPath.arcTo(SkRect::MakeLTRB(-20, 80, 20, 120), 90, 90, false);
|
|
|
|
fTabPath.lineTo(-75, 100);
|
|
|
|
|
2017-04-28 15:00:35 +00:00
|
|
|
fLightPos = SkPoint3::Make(350, 0, 600);
|
2016-08-12 17:40:38 +00:00
|
|
|
}
|
|
|
|
|
2018-08-08 15:36:17 +00:00
|
|
|
bool onQuery(Sample::Event* evt) override {
|
|
|
|
if (Sample::TitleQ(*evt)) {
|
|
|
|
Sample::TitleR(evt, "AndroidShadows");
|
2016-08-12 17:40:38 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
SkUnichar uni;
|
2018-08-08 15:36:17 +00:00
|
|
|
if (Sample::CharQ(*evt, &uni)) {
|
2017-02-14 20:16:46 +00:00
|
|
|
bool handled = false;
|
2016-08-12 17:40:38 +00:00
|
|
|
switch (uni) {
|
2017-02-06 19:36:01 +00:00
|
|
|
case 'W':
|
2016-08-12 17:40:38 +00:00
|
|
|
fShowAmbient = !fShowAmbient;
|
2017-02-14 20:16:46 +00:00
|
|
|
handled = true;
|
2016-08-12 17:40:38 +00:00
|
|
|
break;
|
|
|
|
case 'S':
|
|
|
|
fShowSpot = !fShowSpot;
|
2017-02-14 20:16:46 +00:00
|
|
|
handled = true;
|
2016-08-12 17:40:38 +00:00
|
|
|
break;
|
2016-08-17 17:06:18 +00:00
|
|
|
case 'T':
|
|
|
|
fUseAlt = !fUseAlt;
|
2017-02-14 20:16:46 +00:00
|
|
|
handled = true;
|
2016-08-17 17:06:18 +00:00
|
|
|
break;
|
2016-08-12 17:40:38 +00:00
|
|
|
case 'O':
|
|
|
|
fShowObject = !fShowObject;
|
2017-02-14 20:16:46 +00:00
|
|
|
handled = true;
|
2016-08-12 17:40:38 +00:00
|
|
|
break;
|
2017-12-19 18:02:38 +00:00
|
|
|
case 'N':
|
|
|
|
fDoAlphaAnimation = !fDoAlphaAnimation;
|
|
|
|
if (!fDoAlphaAnimation) {
|
|
|
|
fAnimAlpha = 1;
|
|
|
|
}
|
|
|
|
handled = true;
|
|
|
|
break;
|
2016-08-12 17:40:38 +00:00
|
|
|
case '>':
|
2017-02-06 19:36:01 +00:00
|
|
|
fZDelta += 0.5f;
|
2017-02-14 20:16:46 +00:00
|
|
|
handled = true;
|
2016-08-12 17:40:38 +00:00
|
|
|
break;
|
|
|
|
case '<':
|
2017-02-06 19:36:01 +00:00
|
|
|
fZDelta -= 0.5f;
|
2017-02-14 20:16:46 +00:00
|
|
|
handled = true;
|
2016-08-12 17:40:38 +00:00
|
|
|
break;
|
2016-10-07 18:44:07 +00:00
|
|
|
case '?':
|
|
|
|
fIgnoreShadowAlpha = !fIgnoreShadowAlpha;
|
2017-02-14 20:16:46 +00:00
|
|
|
handled = true;
|
2016-10-07 18:44:07 +00:00
|
|
|
break;
|
2016-08-12 17:40:38 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2017-02-14 20:16:46 +00:00
|
|
|
if (handled) {
|
|
|
|
return true;
|
|
|
|
}
|
2016-08-12 17:40:38 +00:00
|
|
|
}
|
|
|
|
return this->INHERITED::onQuery(evt);
|
|
|
|
}
|
|
|
|
|
|
|
|
void drawBG(SkCanvas* canvas) {
|
|
|
|
canvas->drawColor(0xFFDDDDDD);
|
|
|
|
}
|
|
|
|
|
2017-04-11 19:29:14 +00:00
|
|
|
void drawShadowedPath(SkCanvas* canvas, const SkPath& path,
|
2017-05-08 18:19:30 +00:00
|
|
|
const SkPoint3& zPlaneParams,
|
2016-08-17 17:06:18 +00:00
|
|
|
const SkPaint& paint, SkScalar ambientAlpha,
|
|
|
|
const SkPoint3& lightPos, SkScalar lightWidth, SkScalar spotAlpha) {
|
2017-05-04 18:00:59 +00:00
|
|
|
if (fIgnoreShadowAlpha) {
|
2018-04-10 15:24:11 +00:00
|
|
|
ambientAlpha = 1;
|
|
|
|
spotAlpha = 1;
|
2017-05-04 18:00:59 +00:00
|
|
|
}
|
2017-05-04 13:58:17 +00:00
|
|
|
if (!fShowAmbient) {
|
|
|
|
ambientAlpha = 0;
|
2016-10-31 20:06:51 +00:00
|
|
|
}
|
2017-05-04 13:58:17 +00:00
|
|
|
if (!fShowSpot) {
|
|
|
|
spotAlpha = 0;
|
2016-08-12 17:40:38 +00:00
|
|
|
}
|
2017-05-04 13:58:17 +00:00
|
|
|
uint32_t flags = 0;
|
|
|
|
if (fUseAlt) {
|
|
|
|
flags |= SkShadowFlags::kGeometricOnly_ShadowFlag;
|
2016-08-12 17:40:38 +00:00
|
|
|
}
|
2017-06-09 15:09:03 +00:00
|
|
|
|
2018-02-22 15:58:34 +00:00
|
|
|
SkColor ambientColor = SkColorSetARGB(ambientAlpha * 255, 0, 0, 0);
|
|
|
|
SkColor spotColor = SkColorSetARGB(spotAlpha * 255, 0, 0, 0);
|
|
|
|
SkShadowUtils::DrawShadow(canvas, path, zPlaneParams, lightPos, lightWidth,
|
|
|
|
ambientColor, spotColor, flags);
|
2016-10-31 20:06:51 +00:00
|
|
|
|
2016-08-12 17:40:38 +00:00
|
|
|
if (fShowObject) {
|
|
|
|
canvas->drawPath(path, paint);
|
2016-10-07 18:44:07 +00:00
|
|
|
} else {
|
|
|
|
SkPaint strokePaint;
|
|
|
|
|
|
|
|
strokePaint.setColor(paint.getColor());
|
|
|
|
strokePaint.setStyle(SkPaint::kStroke_Style);
|
|
|
|
|
|
|
|
canvas->drawPath(path, strokePaint);
|
2016-08-12 17:40:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void onDrawContent(SkCanvas* canvas) override {
|
|
|
|
this->drawBG(canvas);
|
2017-04-28 15:00:35 +00:00
|
|
|
const SkScalar kLightWidth = 800;
|
2018-04-23 21:14:48 +00:00
|
|
|
const SkScalar kAmbientAlpha = 0.039f;
|
|
|
|
const SkScalar kSpotAlpha = 0.19f;
|
2016-08-12 17:40:38 +00:00
|
|
|
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setAntiAlias(true);
|
|
|
|
|
2016-08-17 17:06:18 +00:00
|
|
|
SkPoint3 lightPos = fLightPos;
|
2017-05-08 18:19:30 +00:00
|
|
|
SkPoint3 zPlaneParams = SkPoint3::Make(0, 0, 0);
|
2016-08-17 17:06:18 +00:00
|
|
|
|
2016-08-12 17:40:38 +00:00
|
|
|
paint.setColor(SK_ColorWHITE);
|
|
|
|
canvas->translate(200, 90);
|
2017-05-08 18:19:30 +00:00
|
|
|
zPlaneParams.fZ = SkTMax(1.0f, 2 + fZDelta);
|
2017-12-19 18:02:38 +00:00
|
|
|
this->drawShadowedPath(canvas, fRRPath, zPlaneParams, paint, fAnimAlpha*kAmbientAlpha,
|
|
|
|
lightPos, kLightWidth, fAnimAlpha*kSpotAlpha);
|
2016-08-12 17:40:38 +00:00
|
|
|
|
|
|
|
paint.setColor(SK_ColorRED);
|
|
|
|
canvas->translate(250, 0);
|
2017-05-08 18:19:30 +00:00
|
|
|
zPlaneParams.fZ = SkTMax(1.0f, 8 + fZDelta);
|
2017-12-19 18:02:38 +00:00
|
|
|
this->drawShadowedPath(canvas, fRectPath, zPlaneParams, paint, fAnimAlpha*kAmbientAlpha,
|
|
|
|
lightPos, kLightWidth, fAnimAlpha*kSpotAlpha);
|
2016-08-12 17:40:38 +00:00
|
|
|
|
|
|
|
paint.setColor(SK_ColorBLUE);
|
|
|
|
canvas->translate(-250, 110);
|
2017-05-08 18:19:30 +00:00
|
|
|
zPlaneParams.fZ = SkTMax(1.0f, 12 + fZDelta);
|
2017-12-19 18:02:38 +00:00
|
|
|
this->drawShadowedPath(canvas, fCirclePath, zPlaneParams, paint, fAnimAlpha*kAmbientAlpha,
|
|
|
|
lightPos, kLightWidth, fAnimAlpha*0.5f);
|
2016-08-17 14:59:41 +00:00
|
|
|
|
|
|
|
paint.setColor(SK_ColorGREEN);
|
|
|
|
canvas->translate(250, 0);
|
2017-05-08 18:19:30 +00:00
|
|
|
zPlaneParams.fZ = SkTMax(1.0f, 64 + fZDelta);
|
2017-12-19 18:02:38 +00:00
|
|
|
this->drawShadowedPath(canvas, fRRPath, zPlaneParams, paint, fAnimAlpha*kAmbientAlpha,
|
|
|
|
lightPos, kLightWidth, fAnimAlpha*kSpotAlpha);
|
2017-01-25 14:39:46 +00:00
|
|
|
|
|
|
|
paint.setColor(SK_ColorYELLOW);
|
|
|
|
canvas->translate(-250, 110);
|
2017-05-08 18:19:30 +00:00
|
|
|
zPlaneParams.fZ = SkTMax(1.0f, 8 + fZDelta);
|
2017-12-19 18:02:38 +00:00
|
|
|
this->drawShadowedPath(canvas, fFunkyRRPath, zPlaneParams, paint, fAnimAlpha*kAmbientAlpha,
|
|
|
|
lightPos, kLightWidth, fAnimAlpha*kSpotAlpha);
|
2017-01-25 14:39:46 +00:00
|
|
|
|
|
|
|
paint.setColor(SK_ColorCYAN);
|
|
|
|
canvas->translate(250, 0);
|
2017-05-08 18:19:30 +00:00
|
|
|
zPlaneParams.fZ = SkTMax(1.0f, 16 + fZDelta);
|
2017-12-19 18:02:38 +00:00
|
|
|
this->drawShadowedPath(canvas, fCubicPath, zPlaneParams, paint, fAnimAlpha*kAmbientAlpha,
|
|
|
|
lightPos, kLightWidth, fAnimAlpha*kSpotAlpha);
|
2017-03-10 19:34:51 +00:00
|
|
|
|
2018-04-10 15:24:11 +00:00
|
|
|
paint.setColor(SK_ColorWHITE);
|
|
|
|
canvas->translate(250, -180);
|
|
|
|
zPlaneParams.fZ = SkTMax(1.0f, 8 + fZDelta);
|
|
|
|
this->drawShadowedPath(canvas, fStarPath, zPlaneParams, paint,
|
|
|
|
kAmbientAlpha, lightPos, kLightWidth, kSpotAlpha);
|
|
|
|
|
|
|
|
paint.setColor(SK_ColorWHITE);
|
|
|
|
canvas->translate(150, 0);
|
|
|
|
zPlaneParams.fZ = SkTMax(1.0f, 2 + fZDelta);
|
|
|
|
this->drawShadowedPath(canvas, fNotchPath, zPlaneParams, paint,
|
|
|
|
kAmbientAlpha, lightPos, kLightWidth, kSpotAlpha);
|
|
|
|
|
|
|
|
paint.setColor(SK_ColorWHITE);
|
|
|
|
canvas->translate(200, 0);
|
|
|
|
zPlaneParams.fZ = SkTMax(1.0f, 16 + fZDelta);
|
|
|
|
this->drawShadowedPath(canvas, fTabPath, zPlaneParams, paint,
|
|
|
|
kAmbientAlpha, lightPos, kLightWidth, kSpotAlpha);
|
|
|
|
|
2017-03-10 19:34:51 +00:00
|
|
|
// circular reveal
|
|
|
|
SkPath tmpPath;
|
|
|
|
SkPath tmpClipPath;
|
|
|
|
tmpClipPath.addCircle(fAnimTranslate, 0, 60);
|
|
|
|
Op(fSquareRRectPath, tmpClipPath, kIntersect_SkPathOp, &tmpPath);
|
|
|
|
|
|
|
|
paint.setColor(SK_ColorMAGENTA);
|
2018-04-10 15:24:11 +00:00
|
|
|
canvas->translate(-725, 240);
|
2017-05-08 18:19:30 +00:00
|
|
|
zPlaneParams.fZ = SkTMax(1.0f, 32 + fZDelta);
|
|
|
|
this->drawShadowedPath(canvas, tmpPath, zPlaneParams, paint, .1f,
|
2017-03-10 19:34:51 +00:00
|
|
|
lightPos, kLightWidth, .5f);
|
|
|
|
|
2018-05-11 14:48:20 +00:00
|
|
|
// path ops bug
|
|
|
|
SkPath tmpClipPathBug;
|
|
|
|
tmpClipPathBug.addCircle(88.0344925f, 0, 60);
|
|
|
|
Op(fSquareRRectPath, tmpClipPathBug, kIntersect_SkPathOp, &tmpPath);
|
|
|
|
|
|
|
|
canvas->translate(250, 0);
|
|
|
|
zPlaneParams.fZ = SkTMax(1.0f, 32 + fZDelta);
|
|
|
|
this->drawShadowedPath(canvas, tmpPath, zPlaneParams, paint, .1f,
|
|
|
|
lightPos, kLightWidth, .5f);
|
|
|
|
|
2017-03-10 19:34:51 +00:00
|
|
|
// perspective paths
|
|
|
|
SkPoint pivot = SkPoint::Make(fWideRectPath.getBounds().width()/2,
|
|
|
|
fWideRectPath.getBounds().height()/2);
|
2017-04-11 19:29:14 +00:00
|
|
|
SkPoint translate = SkPoint::Make(100, 450);
|
2017-03-10 19:34:51 +00:00
|
|
|
paint.setColor(SK_ColorWHITE);
|
|
|
|
Sk3DView view;
|
|
|
|
view.save();
|
2017-04-11 19:29:14 +00:00
|
|
|
view.rotateX(fAnimAngle);
|
2017-03-10 19:34:51 +00:00
|
|
|
SkMatrix persp;
|
|
|
|
view.getMatrix(&persp);
|
|
|
|
persp.preTranslate(-pivot.fX, -pivot.fY);
|
|
|
|
persp.postTranslate(pivot.fX + translate.fX, pivot.fY + translate.fY);
|
|
|
|
canvas->setMatrix(persp);
|
2017-04-11 19:29:14 +00:00
|
|
|
SkScalar radians = SkDegreesToRadians(fAnimAngle);
|
2017-05-08 18:19:30 +00:00
|
|
|
zPlaneParams = SkPoint3::Make(0,
|
2018-08-31 16:36:52 +00:00
|
|
|
SkScalarSin(radians),
|
|
|
|
SkTMax(1.0f, 16 + fZDelta) - SkScalarSin(radians)*pivot.fY);
|
2017-05-08 18:19:30 +00:00
|
|
|
this->drawShadowedPath(canvas, fWideRectPath, zPlaneParams, paint, .1f,
|
2017-03-10 19:34:51 +00:00
|
|
|
lightPos, kLightWidth, .5f);
|
|
|
|
|
|
|
|
pivot = SkPoint::Make(fWideOvalPath.getBounds().width() / 2,
|
|
|
|
fWideOvalPath.getBounds().height() / 2);
|
2017-04-11 19:29:14 +00:00
|
|
|
translate = SkPoint::Make(100, 600);
|
2017-03-10 19:34:51 +00:00
|
|
|
view.restore();
|
2018-06-14 18:43:00 +00:00
|
|
|
view.save();
|
2017-04-11 19:29:14 +00:00
|
|
|
view.rotateY(fAnimAngle);
|
2017-03-10 19:34:51 +00:00
|
|
|
view.getMatrix(&persp);
|
|
|
|
persp.preTranslate(-pivot.fX, -pivot.fY);
|
|
|
|
persp.postTranslate(pivot.fX + translate.fX, pivot.fY + translate.fY);
|
|
|
|
canvas->setMatrix(persp);
|
2017-05-08 18:19:30 +00:00
|
|
|
zPlaneParams = SkPoint3::Make(-SkScalarSin(radians),
|
|
|
|
0,
|
|
|
|
SkTMax(1.0f, 32 + fZDelta) + SkScalarSin(radians)*pivot.fX);
|
|
|
|
this->drawShadowedPath(canvas, fWideOvalPath, zPlaneParams, paint, .1f,
|
2017-03-10 19:34:51 +00:00
|
|
|
lightPos, kLightWidth, .5f);
|
2018-06-14 18:43:00 +00:00
|
|
|
|
|
|
|
pivot = SkPoint::Make(fStarPath.getBounds().width() / 2,
|
|
|
|
fStarPath.getBounds().height() / 2);
|
|
|
|
translate = SkPoint::Make(700, 250);
|
|
|
|
view.restore();
|
|
|
|
view.rotateY(fAnimAngle);
|
|
|
|
view.getMatrix(&persp);
|
|
|
|
persp.preTranslate(-pivot.fX, -pivot.fY);
|
|
|
|
persp.postTranslate(pivot.fX + translate.fX, pivot.fY + translate.fY);
|
|
|
|
canvas->setMatrix(persp);
|
|
|
|
zPlaneParams = SkPoint3::Make(-SkScalarSin(radians),
|
|
|
|
0,
|
|
|
|
SkTMax(1.0f, 8 + fZDelta) + SkScalarSin(radians)*pivot.fX);
|
|
|
|
this->drawShadowedPath(canvas, fStarPath, zPlaneParams, paint, .1f,
|
|
|
|
lightPos, kLightWidth, .5f);
|
2017-03-10 19:34:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool onAnimate(const SkAnimTimer& timer) override {
|
2018-05-11 14:48:20 +00:00
|
|
|
fAnimTranslate = timer.pingPong(30, 0, 125, -125);
|
2017-04-11 19:29:14 +00:00
|
|
|
fAnimAngle = timer.pingPong(15, 0, 0, 20);
|
2017-12-19 18:02:38 +00:00
|
|
|
if (fDoAlphaAnimation) {
|
|
|
|
fAnimAlpha = timer.pingPong(5, 0, 1, 0);
|
|
|
|
}
|
2017-03-10 19:34:51 +00:00
|
|
|
return true;
|
2016-08-12 17:40:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2018-08-08 15:36:17 +00:00
|
|
|
typedef Sample INHERITED;
|
2016-08-12 17:40:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2018-08-08 15:36:17 +00:00
|
|
|
DEF_SAMPLE( return new ShadowsView(); )
|