jvanverth | e1a3bc6 | 2016-08-12 10:40:38 -0700 | [diff] [blame] | 1 | |
| 2 | /* |
| 3 | * Copyright 2016 Google Inc. |
| 4 | * |
| 5 | * Use of this source code is governed by a BSD-style license that can be |
| 6 | * found in the LICENSE file. |
| 7 | */ |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #include "include/core/SkCanvas.h" |
| 9 | #include "include/core/SkColorFilter.h" |
| 10 | #include "include/core/SkPath.h" |
| 11 | #include "include/core/SkPoint3.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 12 | #include "include/pathops/SkPathOps.h" |
| 13 | #include "include/utils/SkCamera.h" |
| 14 | #include "include/utils/SkShadowUtils.h" |
| 15 | #include "samplecode/Sample.h" |
| 16 | #include "src/core/SkBlurMask.h" |
| 17 | #include "src/utils/SkUTF.h" |
| 18 | #include "tools/ToolUtils.h" |
Hal Canary | 4124807 | 2019-07-11 16:32:53 -0400 | [diff] [blame] | 19 | #include "tools/timer/TimeUtils.h" |
jvanverth | e1a3bc6 | 2016-08-12 10:40:38 -0700 | [diff] [blame] | 20 | |
jvanverth | 6c177a1 | 2016-08-17 07:59:41 -0700 | [diff] [blame] | 21 | //////////////////////////////////////////////////////////////////////////// |
| 22 | |
Ben Wagner | b2c4ea6 | 2018-08-08 11:36:17 -0400 | [diff] [blame] | 23 | class ShadowsView : public Sample { |
jvanverth | e1a3bc6 | 2016-08-12 10:40:38 -0700 | [diff] [blame] | 24 | SkPath fRectPath; |
| 25 | SkPath fRRPath; |
| 26 | SkPath fCirclePath; |
Jim Van Verth | bce7496 | 2017-01-25 09:39:46 -0500 | [diff] [blame] | 27 | SkPath fFunkyRRPath; |
| 28 | SkPath fCubicPath; |
Jim Van Verth | 872da6b | 2018-04-10 11:24:11 -0400 | [diff] [blame] | 29 | SkPath fStarPath; |
Jim Van Verth | 2c1cd6d | 2017-03-10 14:34:51 -0500 | [diff] [blame] | 30 | SkPath fSquareRRectPath; |
| 31 | SkPath fWideRectPath; |
| 32 | SkPath fWideOvalPath; |
Jim Van Verth | 872da6b | 2018-04-10 11:24:11 -0400 | [diff] [blame] | 33 | SkPath fNotchPath; |
| 34 | SkPath fTabPath; |
| 35 | |
jvanverth | e1a3bc6 | 2016-08-12 10:40:38 -0700 | [diff] [blame] | 36 | SkPoint3 fLightPos; |
Hal Canary | d7639af | 2019-07-17 09:08:11 -0400 | [diff] [blame] | 37 | SkScalar fZDelta = 0; |
| 38 | SkScalar fAnimTranslate = 0; |
| 39 | SkScalar fAnimAngle = 0; |
| 40 | SkScalar fAnimAlpha = 1; |
jvanverth | e1a3bc6 | 2016-08-12 10:40:38 -0700 | [diff] [blame] | 41 | |
Hal Canary | d7639af | 2019-07-17 09:08:11 -0400 | [diff] [blame] | 42 | bool fShowAmbient = true; |
| 43 | bool fShowSpot = true; |
| 44 | bool fUseAlt = false; |
| 45 | bool fShowObject = true; |
| 46 | bool fIgnoreShadowAlpha = false; |
| 47 | bool fDoAlphaAnimation = false; |
jvanverth | e1a3bc6 | 2016-08-12 10:40:38 -0700 | [diff] [blame] | 48 | |
jvanverth | e1a3bc6 | 2016-08-12 10:40:38 -0700 | [diff] [blame] | 49 | void onOnceBeforeDraw() override { |
| 50 | fCirclePath.addCircle(0, 0, 50); |
| 51 | fRectPath.addRect(SkRect::MakeXYWH(-100, -50, 200, 100)); |
| 52 | fRRPath.addRRect(SkRRect::MakeRectXY(SkRect::MakeXYWH(-100, -50, 200, 100), 4, 4)); |
Mike Reed | 4241f5e | 2019-09-14 19:13:23 +0000 | [diff] [blame] | 53 | fFunkyRRPath.addRoundRect(SkRect::MakeXYWH(-50, -50, SK_Scalar1 * 100, SK_Scalar1 * 100), |
| 54 | 40 * SK_Scalar1, 20 * SK_Scalar1, |
Mike Reed | 30bc527 | 2019-11-22 18:34:02 +0000 | [diff] [blame] | 55 | SkPathDirection::kCW); |
Jim Van Verth | bce7496 | 2017-01-25 09:39:46 -0500 | [diff] [blame] | 56 | fCubicPath.cubicTo(100 * SK_Scalar1, 50 * SK_Scalar1, |
| 57 | 20 * SK_Scalar1, 100 * SK_Scalar1, |
| 58 | 0 * SK_Scalar1, 0 * SK_Scalar1); |
Jim Van Verth | 872da6b | 2018-04-10 11:24:11 -0400 | [diff] [blame] | 59 | fStarPath.moveTo(0.0f, -50.0f); |
| 60 | fStarPath.lineTo(14.43f, -25.0f); |
| 61 | fStarPath.lineTo(43.30f, -25.0f); |
| 62 | fStarPath.lineTo(28.86f, 0.0f); |
| 63 | fStarPath.lineTo(43.30f, 25.0f); |
| 64 | fStarPath.lineTo(14.43f, 25.0f); |
| 65 | fStarPath.lineTo(0.0f, 50.0f); |
| 66 | fStarPath.lineTo(-14.43f, 25.0f); |
| 67 | fStarPath.lineTo(-43.30f, 25.0f); |
| 68 | fStarPath.lineTo(-28.86f, 0.0f); |
| 69 | fStarPath.lineTo(-43.30f, -25.0f); |
| 70 | fStarPath.lineTo(-14.43f, -25.0f); |
Jim Van Verth | 2c1cd6d | 2017-03-10 14:34:51 -0500 | [diff] [blame] | 71 | fSquareRRectPath.addRRect(SkRRect::MakeRectXY(SkRect::MakeXYWH(-50, -50, 100, 100), |
| 72 | 10, 10)); |
| 73 | fWideRectPath.addRect(SkRect::MakeXYWH(0, 0, 630, 70)); |
| 74 | fWideOvalPath.addOval(SkRect::MakeXYWH(0, 0, 630, 70)); |
Jim Van Verth | bce7496 | 2017-01-25 09:39:46 -0500 | [diff] [blame] | 75 | |
Jim Van Verth | 872da6b | 2018-04-10 11:24:11 -0400 | [diff] [blame] | 76 | fNotchPath.moveTo(0, 80); |
| 77 | fNotchPath.arcTo(SkRect::MakeLTRB(-20, 80, 20, 120), -90, -90, false); |
| 78 | fNotchPath.lineTo(-75, 100); |
| 79 | fNotchPath.lineTo(-75, -100); |
| 80 | fNotchPath.lineTo(75, -100); |
| 81 | fNotchPath.lineTo(75, 100); |
| 82 | fNotchPath.arcTo(SkRect::MakeLTRB(-20, 80, 20, 120), 0, -90, false); |
| 83 | |
| 84 | fTabPath.moveTo(-75, -100); |
| 85 | fTabPath.lineTo(75, -100); |
| 86 | fTabPath.lineTo(75, 100); |
| 87 | fTabPath.arcTo(SkRect::MakeLTRB(-20, 80, 20, 120), 0, 90, false); |
| 88 | fTabPath.arcTo(SkRect::MakeLTRB(-20, 80, 20, 120), 90, 90, false); |
| 89 | fTabPath.lineTo(-75, 100); |
| 90 | |
Jim Van Verth | b6069df | 2017-04-28 11:00:35 -0400 | [diff] [blame] | 91 | fLightPos = SkPoint3::Make(350, 0, 600); |
jvanverth | e1a3bc6 | 2016-08-12 10:40:38 -0700 | [diff] [blame] | 92 | } |
| 93 | |
Hal Canary | 8a02731 | 2019-07-03 10:55:44 -0400 | [diff] [blame] | 94 | SkString name() override { return SkString("AndroidShadows"); } |
jvanverth | e1a3bc6 | 2016-08-12 10:40:38 -0700 | [diff] [blame] | 95 | |
Hal Canary | 6cc65e1 | 2019-07-03 15:53:04 -0400 | [diff] [blame] | 96 | bool onChar(SkUnichar uni) override { |
Jim Van Verth | 6f44969 | 2017-02-14 15:16:46 -0500 | [diff] [blame] | 97 | bool handled = false; |
jvanverth | e1a3bc6 | 2016-08-12 10:40:38 -0700 | [diff] [blame] | 98 | switch (uni) { |
Jim Van Verth | 2aa535e | 2017-02-06 14:36:01 -0500 | [diff] [blame] | 99 | case 'W': |
jvanverth | e1a3bc6 | 2016-08-12 10:40:38 -0700 | [diff] [blame] | 100 | fShowAmbient = !fShowAmbient; |
Jim Van Verth | 6f44969 | 2017-02-14 15:16:46 -0500 | [diff] [blame] | 101 | handled = true; |
jvanverth | e1a3bc6 | 2016-08-12 10:40:38 -0700 | [diff] [blame] | 102 | break; |
| 103 | case 'S': |
| 104 | fShowSpot = !fShowSpot; |
Jim Van Verth | 6f44969 | 2017-02-14 15:16:46 -0500 | [diff] [blame] | 105 | handled = true; |
jvanverth | e1a3bc6 | 2016-08-12 10:40:38 -0700 | [diff] [blame] | 106 | break; |
jvanverth | d7315f91 | 2016-08-17 10:06:18 -0700 | [diff] [blame] | 107 | case 'T': |
| 108 | fUseAlt = !fUseAlt; |
Jim Van Verth | 6f44969 | 2017-02-14 15:16:46 -0500 | [diff] [blame] | 109 | handled = true; |
jvanverth | d7315f91 | 2016-08-17 10:06:18 -0700 | [diff] [blame] | 110 | break; |
jvanverth | e1a3bc6 | 2016-08-12 10:40:38 -0700 | [diff] [blame] | 111 | case 'O': |
| 112 | fShowObject = !fShowObject; |
Jim Van Verth | 6f44969 | 2017-02-14 15:16:46 -0500 | [diff] [blame] | 113 | handled = true; |
jvanverth | e1a3bc6 | 2016-08-12 10:40:38 -0700 | [diff] [blame] | 114 | break; |
Jim Van Verth | 744cbb3 | 2017-12-19 13:02:38 -0500 | [diff] [blame] | 115 | case 'N': |
| 116 | fDoAlphaAnimation = !fDoAlphaAnimation; |
| 117 | if (!fDoAlphaAnimation) { |
| 118 | fAnimAlpha = 1; |
| 119 | } |
| 120 | handled = true; |
| 121 | break; |
jvanverth | e1a3bc6 | 2016-08-12 10:40:38 -0700 | [diff] [blame] | 122 | case '>': |
Jim Van Verth | 2aa535e | 2017-02-06 14:36:01 -0500 | [diff] [blame] | 123 | fZDelta += 0.5f; |
Jim Van Verth | 6f44969 | 2017-02-14 15:16:46 -0500 | [diff] [blame] | 124 | handled = true; |
jvanverth | e1a3bc6 | 2016-08-12 10:40:38 -0700 | [diff] [blame] | 125 | break; |
| 126 | case '<': |
Jim Van Verth | 2aa535e | 2017-02-06 14:36:01 -0500 | [diff] [blame] | 127 | fZDelta -= 0.5f; |
Jim Van Verth | 6f44969 | 2017-02-14 15:16:46 -0500 | [diff] [blame] | 128 | handled = true; |
jvanverth | e1a3bc6 | 2016-08-12 10:40:38 -0700 | [diff] [blame] | 129 | break; |
Robert Phillips | 95304e3 | 2016-10-07 14:44:07 -0400 | [diff] [blame] | 130 | case '?': |
| 131 | fIgnoreShadowAlpha = !fIgnoreShadowAlpha; |
Jim Van Verth | 6f44969 | 2017-02-14 15:16:46 -0500 | [diff] [blame] | 132 | handled = true; |
Robert Phillips | 95304e3 | 2016-10-07 14:44:07 -0400 | [diff] [blame] | 133 | break; |
jvanverth | e1a3bc6 | 2016-08-12 10:40:38 -0700 | [diff] [blame] | 134 | default: |
| 135 | break; |
| 136 | } |
Jim Van Verth | 6f44969 | 2017-02-14 15:16:46 -0500 | [diff] [blame] | 137 | if (handled) { |
Jim Van Verth | 6f44969 | 2017-02-14 15:16:46 -0500 | [diff] [blame] | 138 | return true; |
| 139 | } |
Hal Canary | 6cc65e1 | 2019-07-03 15:53:04 -0400 | [diff] [blame] | 140 | return false; |
jvanverth | e1a3bc6 | 2016-08-12 10:40:38 -0700 | [diff] [blame] | 141 | } |
| 142 | |
Jim Van Verth | da96550 | 2017-04-11 15:29:14 -0400 | [diff] [blame] | 143 | void drawShadowedPath(SkCanvas* canvas, const SkPath& path, |
Jim Van Verth | e308a12 | 2017-05-08 14:19:30 -0400 | [diff] [blame] | 144 | const SkPoint3& zPlaneParams, |
jvanverth | d7315f91 | 2016-08-17 10:06:18 -0700 | [diff] [blame] | 145 | const SkPaint& paint, SkScalar ambientAlpha, |
| 146 | const SkPoint3& lightPos, SkScalar lightWidth, SkScalar spotAlpha) { |
Jim Van Verth | e770578 | 2017-05-04 14:00:59 -0400 | [diff] [blame] | 147 | if (fIgnoreShadowAlpha) { |
Jim Van Verth | 872da6b | 2018-04-10 11:24:11 -0400 | [diff] [blame] | 148 | ambientAlpha = 1; |
| 149 | spotAlpha = 1; |
Jim Van Verth | e770578 | 2017-05-04 14:00:59 -0400 | [diff] [blame] | 150 | } |
Jim Van Verth | 060d982 | 2017-05-04 09:58:17 -0400 | [diff] [blame] | 151 | if (!fShowAmbient) { |
| 152 | ambientAlpha = 0; |
| 153 | } |
| 154 | if (!fShowSpot) { |
| 155 | spotAlpha = 0; |
| 156 | } |
| 157 | uint32_t flags = 0; |
Jim Van Verth | 3c1b7db | 2016-10-31 16:06:51 -0400 | [diff] [blame] | 158 | if (fUseAlt) { |
Jim Van Verth | 060d982 | 2017-05-04 09:58:17 -0400 | [diff] [blame] | 159 | flags |= SkShadowFlags::kGeometricOnly_ShadowFlag; |
Jim Van Verth | 3c1b7db | 2016-10-31 16:06:51 -0400 | [diff] [blame] | 160 | } |
Jim Van Verth | 34d6e4b | 2017-06-09 11:09:03 -0400 | [diff] [blame] | 161 | |
Jim Van Verth | a556684 | 2018-02-22 10:58:34 -0500 | [diff] [blame] | 162 | SkColor ambientColor = SkColorSetARGB(ambientAlpha * 255, 0, 0, 0); |
| 163 | SkColor spotColor = SkColorSetARGB(spotAlpha * 255, 0, 0, 0); |
| 164 | SkShadowUtils::DrawShadow(canvas, path, zPlaneParams, lightPos, lightWidth, |
| 165 | ambientColor, spotColor, flags); |
Jim Van Verth | 3c1b7db | 2016-10-31 16:06:51 -0400 | [diff] [blame] | 166 | |
jvanverth | e1a3bc6 | 2016-08-12 10:40:38 -0700 | [diff] [blame] | 167 | if (fShowObject) { |
| 168 | canvas->drawPath(path, paint); |
Robert Phillips | 95304e3 | 2016-10-07 14:44:07 -0400 | [diff] [blame] | 169 | } else { |
| 170 | SkPaint strokePaint; |
| 171 | |
| 172 | strokePaint.setColor(paint.getColor()); |
| 173 | strokePaint.setStyle(SkPaint::kStroke_Style); |
| 174 | |
| 175 | canvas->drawPath(path, strokePaint); |
jvanverth | e1a3bc6 | 2016-08-12 10:40:38 -0700 | [diff] [blame] | 176 | } |
| 177 | } |
| 178 | |
| 179 | void onDrawContent(SkCanvas* canvas) override { |
Hal Canary | d7639af | 2019-07-17 09:08:11 -0400 | [diff] [blame] | 180 | canvas->drawColor(0xFFDDDDDD); |
| 181 | |
Jim Van Verth | b6069df | 2017-04-28 11:00:35 -0400 | [diff] [blame] | 182 | const SkScalar kLightWidth = 800; |
Jim Van Verth | 4c8c1e8 | 2018-04-23 17:14:48 -0400 | [diff] [blame] | 183 | const SkScalar kAmbientAlpha = 0.039f; |
| 184 | const SkScalar kSpotAlpha = 0.19f; |
jvanverth | e1a3bc6 | 2016-08-12 10:40:38 -0700 | [diff] [blame] | 185 | |
| 186 | SkPaint paint; |
| 187 | paint.setAntiAlias(true); |
| 188 | |
jvanverth | d7315f91 | 2016-08-17 10:06:18 -0700 | [diff] [blame] | 189 | SkPoint3 lightPos = fLightPos; |
Jim Van Verth | e308a12 | 2017-05-08 14:19:30 -0400 | [diff] [blame] | 190 | SkPoint3 zPlaneParams = SkPoint3::Make(0, 0, 0); |
jvanverth | d7315f91 | 2016-08-17 10:06:18 -0700 | [diff] [blame] | 191 | |
jvanverth | e1a3bc6 | 2016-08-12 10:40:38 -0700 | [diff] [blame] | 192 | paint.setColor(SK_ColorWHITE); |
| 193 | canvas->translate(200, 90); |
Brian Osman | 788b916 | 2020-02-07 10:36:46 -0500 | [diff] [blame] | 194 | zPlaneParams.fZ = std::max(1.0f, 2 + fZDelta); |
Jim Van Verth | 744cbb3 | 2017-12-19 13:02:38 -0500 | [diff] [blame] | 195 | this->drawShadowedPath(canvas, fRRPath, zPlaneParams, paint, fAnimAlpha*kAmbientAlpha, |
| 196 | lightPos, kLightWidth, fAnimAlpha*kSpotAlpha); |
jvanverth | e1a3bc6 | 2016-08-12 10:40:38 -0700 | [diff] [blame] | 197 | |
| 198 | paint.setColor(SK_ColorRED); |
| 199 | canvas->translate(250, 0); |
Brian Osman | 788b916 | 2020-02-07 10:36:46 -0500 | [diff] [blame] | 200 | zPlaneParams.fZ = std::max(1.0f, 8 + fZDelta); |
Jim Van Verth | 744cbb3 | 2017-12-19 13:02:38 -0500 | [diff] [blame] | 201 | this->drawShadowedPath(canvas, fRectPath, zPlaneParams, paint, fAnimAlpha*kAmbientAlpha, |
| 202 | lightPos, kLightWidth, fAnimAlpha*kSpotAlpha); |
jvanverth | e1a3bc6 | 2016-08-12 10:40:38 -0700 | [diff] [blame] | 203 | |
| 204 | paint.setColor(SK_ColorBLUE); |
| 205 | canvas->translate(-250, 110); |
Brian Osman | 788b916 | 2020-02-07 10:36:46 -0500 | [diff] [blame] | 206 | zPlaneParams.fZ = std::max(1.0f, 12 + fZDelta); |
Jim Van Verth | 744cbb3 | 2017-12-19 13:02:38 -0500 | [diff] [blame] | 207 | this->drawShadowedPath(canvas, fCirclePath, zPlaneParams, paint, fAnimAlpha*kAmbientAlpha, |
| 208 | lightPos, kLightWidth, fAnimAlpha*0.5f); |
jvanverth | 6c177a1 | 2016-08-17 07:59:41 -0700 | [diff] [blame] | 209 | |
| 210 | paint.setColor(SK_ColorGREEN); |
| 211 | canvas->translate(250, 0); |
Brian Osman | 788b916 | 2020-02-07 10:36:46 -0500 | [diff] [blame] | 212 | zPlaneParams.fZ = std::max(1.0f, 64 + fZDelta); |
Jim Van Verth | 744cbb3 | 2017-12-19 13:02:38 -0500 | [diff] [blame] | 213 | this->drawShadowedPath(canvas, fRRPath, zPlaneParams, paint, fAnimAlpha*kAmbientAlpha, |
| 214 | lightPos, kLightWidth, fAnimAlpha*kSpotAlpha); |
Jim Van Verth | bce7496 | 2017-01-25 09:39:46 -0500 | [diff] [blame] | 215 | |
| 216 | paint.setColor(SK_ColorYELLOW); |
| 217 | canvas->translate(-250, 110); |
Brian Osman | 788b916 | 2020-02-07 10:36:46 -0500 | [diff] [blame] | 218 | zPlaneParams.fZ = std::max(1.0f, 8 + fZDelta); |
Jim Van Verth | 744cbb3 | 2017-12-19 13:02:38 -0500 | [diff] [blame] | 219 | this->drawShadowedPath(canvas, fFunkyRRPath, zPlaneParams, paint, fAnimAlpha*kAmbientAlpha, |
| 220 | lightPos, kLightWidth, fAnimAlpha*kSpotAlpha); |
Jim Van Verth | bce7496 | 2017-01-25 09:39:46 -0500 | [diff] [blame] | 221 | |
| 222 | paint.setColor(SK_ColorCYAN); |
| 223 | canvas->translate(250, 0); |
Brian Osman | 788b916 | 2020-02-07 10:36:46 -0500 | [diff] [blame] | 224 | zPlaneParams.fZ = std::max(1.0f, 16 + fZDelta); |
Jim Van Verth | 744cbb3 | 2017-12-19 13:02:38 -0500 | [diff] [blame] | 225 | this->drawShadowedPath(canvas, fCubicPath, zPlaneParams, paint, fAnimAlpha*kAmbientAlpha, |
| 226 | lightPos, kLightWidth, fAnimAlpha*kSpotAlpha); |
Jim Van Verth | 2c1cd6d | 2017-03-10 14:34:51 -0500 | [diff] [blame] | 227 | |
Jim Van Verth | 872da6b | 2018-04-10 11:24:11 -0400 | [diff] [blame] | 228 | paint.setColor(SK_ColorWHITE); |
| 229 | canvas->translate(250, -180); |
Brian Osman | 788b916 | 2020-02-07 10:36:46 -0500 | [diff] [blame] | 230 | zPlaneParams.fZ = std::max(1.0f, 8 + fZDelta); |
Jim Van Verth | 872da6b | 2018-04-10 11:24:11 -0400 | [diff] [blame] | 231 | this->drawShadowedPath(canvas, fStarPath, zPlaneParams, paint, |
| 232 | kAmbientAlpha, lightPos, kLightWidth, kSpotAlpha); |
| 233 | |
| 234 | paint.setColor(SK_ColorWHITE); |
| 235 | canvas->translate(150, 0); |
Brian Osman | 788b916 | 2020-02-07 10:36:46 -0500 | [diff] [blame] | 236 | zPlaneParams.fZ = std::max(1.0f, 2 + fZDelta); |
Jim Van Verth | 872da6b | 2018-04-10 11:24:11 -0400 | [diff] [blame] | 237 | this->drawShadowedPath(canvas, fNotchPath, zPlaneParams, paint, |
| 238 | kAmbientAlpha, lightPos, kLightWidth, kSpotAlpha); |
| 239 | |
| 240 | paint.setColor(SK_ColorWHITE); |
| 241 | canvas->translate(200, 0); |
Brian Osman | 788b916 | 2020-02-07 10:36:46 -0500 | [diff] [blame] | 242 | zPlaneParams.fZ = std::max(1.0f, 16 + fZDelta); |
Jim Van Verth | 872da6b | 2018-04-10 11:24:11 -0400 | [diff] [blame] | 243 | this->drawShadowedPath(canvas, fTabPath, zPlaneParams, paint, |
| 244 | kAmbientAlpha, lightPos, kLightWidth, kSpotAlpha); |
| 245 | |
Jim Van Verth | 2c1cd6d | 2017-03-10 14:34:51 -0500 | [diff] [blame] | 246 | // circular reveal |
| 247 | SkPath tmpPath; |
| 248 | SkPath tmpClipPath; |
| 249 | tmpClipPath.addCircle(fAnimTranslate, 0, 60); |
| 250 | Op(fSquareRRectPath, tmpClipPath, kIntersect_SkPathOp, &tmpPath); |
| 251 | |
| 252 | paint.setColor(SK_ColorMAGENTA); |
Jim Van Verth | 872da6b | 2018-04-10 11:24:11 -0400 | [diff] [blame] | 253 | canvas->translate(-725, 240); |
Brian Osman | 788b916 | 2020-02-07 10:36:46 -0500 | [diff] [blame] | 254 | zPlaneParams.fZ = std::max(1.0f, 32 + fZDelta); |
Jim Van Verth | e308a12 | 2017-05-08 14:19:30 -0400 | [diff] [blame] | 255 | this->drawShadowedPath(canvas, tmpPath, zPlaneParams, paint, .1f, |
Jim Van Verth | 2c1cd6d | 2017-03-10 14:34:51 -0500 | [diff] [blame] | 256 | lightPos, kLightWidth, .5f); |
| 257 | |
Jim Van Verth | f507c28 | 2018-05-11 10:48:20 -0400 | [diff] [blame] | 258 | // path ops bug |
| 259 | SkPath tmpClipPathBug; |
| 260 | tmpClipPathBug.addCircle(88.0344925f, 0, 60); |
| 261 | Op(fSquareRRectPath, tmpClipPathBug, kIntersect_SkPathOp, &tmpPath); |
| 262 | |
| 263 | canvas->translate(250, 0); |
Brian Osman | 788b916 | 2020-02-07 10:36:46 -0500 | [diff] [blame] | 264 | zPlaneParams.fZ = std::max(1.0f, 32 + fZDelta); |
Jim Van Verth | f507c28 | 2018-05-11 10:48:20 -0400 | [diff] [blame] | 265 | this->drawShadowedPath(canvas, tmpPath, zPlaneParams, paint, .1f, |
| 266 | lightPos, kLightWidth, .5f); |
| 267 | |
Jim Van Verth | 2c1cd6d | 2017-03-10 14:34:51 -0500 | [diff] [blame] | 268 | // perspective paths |
| 269 | SkPoint pivot = SkPoint::Make(fWideRectPath.getBounds().width()/2, |
| 270 | fWideRectPath.getBounds().height()/2); |
Jim Van Verth | da96550 | 2017-04-11 15:29:14 -0400 | [diff] [blame] | 271 | SkPoint translate = SkPoint::Make(100, 450); |
Jim Van Verth | 2c1cd6d | 2017-03-10 14:34:51 -0500 | [diff] [blame] | 272 | paint.setColor(SK_ColorWHITE); |
| 273 | Sk3DView view; |
| 274 | view.save(); |
Jim Van Verth | da96550 | 2017-04-11 15:29:14 -0400 | [diff] [blame] | 275 | view.rotateX(fAnimAngle); |
Jim Van Verth | 2c1cd6d | 2017-03-10 14:34:51 -0500 | [diff] [blame] | 276 | SkMatrix persp; |
| 277 | view.getMatrix(&persp); |
| 278 | persp.preTranslate(-pivot.fX, -pivot.fY); |
| 279 | persp.postTranslate(pivot.fX + translate.fX, pivot.fY + translate.fY); |
| 280 | canvas->setMatrix(persp); |
Jim Van Verth | da96550 | 2017-04-11 15:29:14 -0400 | [diff] [blame] | 281 | SkScalar radians = SkDegreesToRadians(fAnimAngle); |
Jim Van Verth | e308a12 | 2017-05-08 14:19:30 -0400 | [diff] [blame] | 282 | zPlaneParams = SkPoint3::Make(0, |
Jim Van Verth | 0b7645f | 2018-08-31 12:36:52 -0400 | [diff] [blame] | 283 | SkScalarSin(radians), |
Brian Osman | 788b916 | 2020-02-07 10:36:46 -0500 | [diff] [blame] | 284 | std::max(1.0f, 16 + fZDelta) - SkScalarSin(radians)*pivot.fY); |
Jim Van Verth | e308a12 | 2017-05-08 14:19:30 -0400 | [diff] [blame] | 285 | this->drawShadowedPath(canvas, fWideRectPath, zPlaneParams, paint, .1f, |
Jim Van Verth | 2c1cd6d | 2017-03-10 14:34:51 -0500 | [diff] [blame] | 286 | lightPos, kLightWidth, .5f); |
| 287 | |
| 288 | pivot = SkPoint::Make(fWideOvalPath.getBounds().width() / 2, |
| 289 | fWideOvalPath.getBounds().height() / 2); |
Jim Van Verth | da96550 | 2017-04-11 15:29:14 -0400 | [diff] [blame] | 290 | translate = SkPoint::Make(100, 600); |
Jim Van Verth | 2c1cd6d | 2017-03-10 14:34:51 -0500 | [diff] [blame] | 291 | view.restore(); |
Jim Van Verth | e39bc9f | 2018-06-14 14:43:00 -0400 | [diff] [blame] | 292 | view.save(); |
Jim Van Verth | da96550 | 2017-04-11 15:29:14 -0400 | [diff] [blame] | 293 | view.rotateY(fAnimAngle); |
Jim Van Verth | 2c1cd6d | 2017-03-10 14:34:51 -0500 | [diff] [blame] | 294 | view.getMatrix(&persp); |
| 295 | persp.preTranslate(-pivot.fX, -pivot.fY); |
| 296 | persp.postTranslate(pivot.fX + translate.fX, pivot.fY + translate.fY); |
| 297 | canvas->setMatrix(persp); |
Jim Van Verth | e308a12 | 2017-05-08 14:19:30 -0400 | [diff] [blame] | 298 | zPlaneParams = SkPoint3::Make(-SkScalarSin(radians), |
| 299 | 0, |
Brian Osman | 788b916 | 2020-02-07 10:36:46 -0500 | [diff] [blame] | 300 | std::max(1.0f, 32 + fZDelta) + SkScalarSin(radians)*pivot.fX); |
Jim Van Verth | e308a12 | 2017-05-08 14:19:30 -0400 | [diff] [blame] | 301 | this->drawShadowedPath(canvas, fWideOvalPath, zPlaneParams, paint, .1f, |
Jim Van Verth | 2c1cd6d | 2017-03-10 14:34:51 -0500 | [diff] [blame] | 302 | lightPos, kLightWidth, .5f); |
Jim Van Verth | e39bc9f | 2018-06-14 14:43:00 -0400 | [diff] [blame] | 303 | |
| 304 | pivot = SkPoint::Make(fStarPath.getBounds().width() / 2, |
| 305 | fStarPath.getBounds().height() / 2); |
| 306 | translate = SkPoint::Make(700, 250); |
| 307 | view.restore(); |
| 308 | view.rotateY(fAnimAngle); |
| 309 | view.getMatrix(&persp); |
| 310 | persp.preTranslate(-pivot.fX, -pivot.fY); |
| 311 | persp.postTranslate(pivot.fX + translate.fX, pivot.fY + translate.fY); |
| 312 | canvas->setMatrix(persp); |
| 313 | zPlaneParams = SkPoint3::Make(-SkScalarSin(radians), |
| 314 | 0, |
Brian Osman | 788b916 | 2020-02-07 10:36:46 -0500 | [diff] [blame] | 315 | std::max(1.0f, 8 + fZDelta) + SkScalarSin(radians)*pivot.fX); |
Jim Van Verth | e39bc9f | 2018-06-14 14:43:00 -0400 | [diff] [blame] | 316 | this->drawShadowedPath(canvas, fStarPath, zPlaneParams, paint, .1f, |
| 317 | lightPos, kLightWidth, .5f); |
Jim Van Verth | 2c1cd6d | 2017-03-10 14:34:51 -0500 | [diff] [blame] | 318 | } |
| 319 | |
Hal Canary | 4124807 | 2019-07-11 16:32:53 -0400 | [diff] [blame] | 320 | bool onAnimate(double nanos) override { |
| 321 | fAnimTranslate = TimeUtils::PingPong(1e-9 * nanos, 30, 0, 125, -125); |
| 322 | fAnimAngle = TimeUtils::PingPong(1e-9 * nanos, 15, 0, 0, 20); |
Jim Van Verth | 744cbb3 | 2017-12-19 13:02:38 -0500 | [diff] [blame] | 323 | if (fDoAlphaAnimation) { |
Hal Canary | 4124807 | 2019-07-11 16:32:53 -0400 | [diff] [blame] | 324 | fAnimAlpha = TimeUtils::PingPong(1e-9 * nanos, 5, 0, 1, 0); |
Jim Van Verth | 744cbb3 | 2017-12-19 13:02:38 -0500 | [diff] [blame] | 325 | } |
Jim Van Verth | 2c1cd6d | 2017-03-10 14:34:51 -0500 | [diff] [blame] | 326 | return true; |
jvanverth | e1a3bc6 | 2016-08-12 10:40:38 -0700 | [diff] [blame] | 327 | } |
| 328 | |
jvanverth | e1a3bc6 | 2016-08-12 10:40:38 -0700 | [diff] [blame] | 329 | private: |
John Stiles | 7571f9e | 2020-09-02 22:42:33 -0400 | [diff] [blame] | 330 | using INHERITED = Sample; |
jvanverth | e1a3bc6 | 2016-08-12 10:40:38 -0700 | [diff] [blame] | 331 | }; |
| 332 | |
| 333 | ////////////////////////////////////////////////////////////////////////////// |
| 334 | |
Ben Wagner | b2c4ea6 | 2018-08-08 11:36:17 -0400 | [diff] [blame] | 335 | DEF_SAMPLE( return new ShadowsView(); ) |