reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2006 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 | #ifndef SkGradientShader_DEFINED |
| 18 | #define SkGradientShader_DEFINED |
| 19 | |
| 20 | #include "SkShader.h" |
| 21 | |
| 22 | class SkUnitMapper; |
| 23 | |
| 24 | /** \class SkGradientShader |
| 25 | |
| 26 | SkGradientShader hosts factories for creating subclasses of SkShader that |
| 27 | render linear and radial gradients. |
| 28 | */ |
ctguil@chromium.org | 7ffb1b2 | 2011-03-15 21:27:08 +0000 | [diff] [blame^] | 29 | class SK_API SkGradientShader { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 30 | public: |
| 31 | /** Returns a shader that generates a linear gradient between the two |
| 32 | specified points. |
| 33 | <p /> |
| 34 | CreateLinear returns a shader with a reference count of 1. |
| 35 | The caller should decrement the shader's reference count when done with the shader. |
| 36 | It is an error for count to be < 2. |
| 37 | @param pts The start and end points for the gradient. |
| 38 | @param colors The array[count] of colors, to be distributed between the two points |
| 39 | @param pos May be NULL. array[count] of SkScalars, or NULL, of the relative position of |
| 40 | each corresponding color in the colors array. If this is NULL, |
| 41 | the the colors are distributed evenly between the start and end point. |
| 42 | If this is not null, the values must begin with 0, end with 1.0, and |
| 43 | intermediate values must be strictly increasing. |
| 44 | @param count Must be >=2. The number of colors (and pos if not NULL) entries. |
| 45 | @param mode The tiling mode |
| 46 | @param mapper May be NULL. Callback to modify the spread of the colors. |
| 47 | */ |
| 48 | static SkShader* CreateLinear( const SkPoint pts[2], |
| 49 | const SkColor colors[], const SkScalar pos[], int count, |
| 50 | SkShader::TileMode mode, |
| 51 | SkUnitMapper* mapper = NULL); |
| 52 | |
| 53 | /** Returns a shader that generates a radial gradient given the center and radius. |
| 54 | <p /> |
| 55 | CreateRadial returns a shader with a reference count of 1. |
| 56 | The caller should decrement the shader's reference count when done with the shader. |
| 57 | It is an error for colorCount to be < 2, or for radius to be <= 0. |
| 58 | @param center The center of the circle for this gradient |
| 59 | @param radius Must be positive. The radius of the circle for this gradient |
| 60 | @param colors The array[count] of colors, to be distributed between the center and edge of the circle |
| 61 | @param pos May be NULL. The array[count] of SkScalars, or NULL, of the relative position of |
| 62 | each corresponding color in the colors array. If this is NULL, |
| 63 | the the colors are distributed evenly between the center and edge of the circle. |
| 64 | If this is not null, the values must begin with 0, end with 1.0, and |
| 65 | intermediate values must be strictly increasing. |
| 66 | @param count Must be >= 2. The number of colors (and pos if not NULL) entries |
| 67 | @param mode The tiling mode |
| 68 | @param mapper May be NULL. Callback to modify the spread of the colors. |
| 69 | */ |
| 70 | static SkShader* CreateRadial( const SkPoint& center, SkScalar radius, |
| 71 | const SkColor colors[], const SkScalar pos[], int count, |
| 72 | SkShader::TileMode mode, |
| 73 | SkUnitMapper* mapper = NULL); |
| 74 | |
senorblanco@chromium.org | 7ef071f | 2009-09-22 17:25:29 +0000 | [diff] [blame] | 75 | /** Returns a shader that generates a radial gradient given the start position, start radius, end position and end radius. |
| 76 | <p /> |
| 77 | CreateTwoPointRadial returns a shader with a reference count of 1. |
| 78 | The caller should decrement the shader's reference count when done with the shader. |
| 79 | It is an error for colorCount to be < 2, for startRadius or endRadius to be < 0, or for |
| 80 | startRadius to be equal to endRadius. |
| 81 | @param start The center of the start circle for this gradient |
| 82 | @param startRadius Must be positive. The radius of the start circle for this gradient. |
| 83 | @param end The center of the end circle for this gradient |
| 84 | @param endRadius Must be positive. The radius of the end circle for this gradient. |
| 85 | @param colors The array[count] of colors, to be distributed between the center and edge of the circle |
| 86 | @param pos May be NULL. The array[count] of SkScalars, or NULL, of the relative position of |
| 87 | each corresponding color in the colors array. If this is NULL, |
| 88 | the the colors are distributed evenly between the center and edge of the circle. |
| 89 | If this is not null, the values must begin with 0, end with 1.0, and |
| 90 | intermediate values must be strictly increasing. |
| 91 | @param count Must be >= 2. The number of colors (and pos if not NULL) entries |
| 92 | @param mode The tiling mode |
| 93 | @param mapper May be NULL. Callback to modify the spread of the colors. |
| 94 | */ |
| 95 | static SkShader* CreateTwoPointRadial(const SkPoint& start, |
| 96 | SkScalar startRadius, |
| 97 | const SkPoint& end, |
| 98 | SkScalar endRadius, |
| 99 | const SkColor colors[], |
| 100 | const SkScalar pos[], int count, |
| 101 | SkShader::TileMode mode, |
| 102 | SkUnitMapper* mapper = NULL); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 103 | /** Returns a shader that generates a sweep gradient given a center. |
| 104 | <p /> |
senorblanco@chromium.org | 7ef071f | 2009-09-22 17:25:29 +0000 | [diff] [blame] | 105 | CreateSweep returns a shader with a reference count of 1. |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 106 | The caller should decrement the shader's reference count when done with the shader. |
| 107 | It is an error for colorCount to be < 2. |
| 108 | @param cx The X coordinate of the center of the sweep |
| 109 | @param cx The Y coordinate of the center of the sweep |
| 110 | @param colors The array[count] of colors, to be distributed around the center. |
| 111 | @param pos May be NULL. The array[count] of SkScalars, or NULL, of the relative position of |
| 112 | each corresponding color in the colors array. If this is NULL, |
| 113 | the the colors are distributed evenly between the center and edge of the circle. |
| 114 | If this is not null, the values must begin with 0, end with 1.0, and |
| 115 | intermediate values must be strictly increasing. |
| 116 | @param count Must be >= 2. The number of colors (and pos if not NULL) entries |
| 117 | @param mapper May be NULL. Callback to modify the spread of the colors. |
| 118 | */ |
| 119 | static SkShader* CreateSweep(SkScalar cx, SkScalar cy, |
| 120 | const SkColor colors[], const SkScalar pos[], |
| 121 | int count, SkUnitMapper* mapper = NULL); |
| 122 | }; |
| 123 | |
| 124 | #endif |
| 125 | |