1 /* 2 * Copyright (C) 2018 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package android.view.shadow; 18 19 /** 20 * Model for ambient shadow rendering. Assumes light sources from centroid of the object. 21 */ 22 class AmbientShadowConfig { 23 24 private final float mEdgeScale; 25 private final float mShadowBoundRatio; 26 private final float mShadowStrength; 27 28 private final float[] mPolygon; 29 private float[] mLightSourcePosition; 30 AmbientShadowConfig(Builder builder)31 private AmbientShadowConfig(Builder builder) { 32 mEdgeScale = builder.mEdgeScale; 33 mShadowBoundRatio = builder.mShadowBoundRatio; 34 mShadowStrength = builder.mShadowStrength; 35 mPolygon = builder.mPolygon; 36 mLightSourcePosition = builder.mLightSourcePosition; 37 } 38 39 /** 40 * Returns scales intensity of the edge of the shadow (opacity) [0-100] 41 */ getEdgeScale()42 public float getEdgeScale() { 43 return mEdgeScale; 44 } 45 46 /** 47 * Returns scales the area (in xy) of the shadow [0-1] 48 */ getShadowBoundRatio()49 public float getShadowBoundRatio() { 50 return mShadowBoundRatio; 51 } 52 53 /** 54 * Returns scales the intensity of the entire shadow (opacity) [0-1] 55 */ getShadowStrength()56 public float getShadowStrength() { 57 return mShadowStrength; 58 } 59 60 /** 61 * Returns opaque polygon to cast shadow 62 */ getPolygon()63 public float[] getPolygon() { 64 return mPolygon; 65 } 66 67 /** 68 * Returns 2D position of the light source 69 */ getLightSourcePosition()70 public float[] getLightSourcePosition() { 71 return mLightSourcePosition; 72 } 73 74 public static class Builder { 75 76 private float mEdgeScale; 77 private float mShadowBoundRatio; 78 private float mShadowStrength; 79 80 private float[] mPolygon; 81 private float[] mLightSourcePosition; 82 setEdgeScale(float edgeScale)83 public Builder setEdgeScale(float edgeScale) { 84 mEdgeScale = edgeScale; 85 return this; 86 } 87 setShadowBoundRatio(float shadowBoundRatio)88 public Builder setShadowBoundRatio(float shadowBoundRatio) { 89 mShadowBoundRatio = shadowBoundRatio; 90 return this; 91 } 92 setShadowStrength(float shadowStrength)93 public Builder setShadowStrength(float shadowStrength) { 94 mShadowStrength = shadowStrength; 95 return this; 96 } 97 setPolygon(float[] polygon)98 public Builder setPolygon(float[] polygon) { 99 mPolygon = polygon; 100 return this; 101 } 102 setLightSourcePosition(float x, float y)103 public Builder setLightSourcePosition(float x, float y) { 104 mLightSourcePosition = new float[] { x, y }; 105 return this; 106 } 107 build()108 public AmbientShadowConfig build() { 109 return new AmbientShadowConfig(this); 110 } 111 } 112 } 113