SkGradientShader.h revision 8a1c16ff38322f0210116fa7293eb8817c7e477e
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 22class SkUnitMapper; 23 24/** \class SkGradientShader 25 26 SkGradientShader hosts factories for creating subclasses of SkShader that 27 render linear and radial gradients. 28*/ 29class SkGradientShader { 30public: 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 75 /** Returns a shader that generates a sweep gradient given a center. 76 <p /> 77 CreateRadial 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. 80 @param cx The X coordinate of the center of the sweep 81 @param cx The Y coordinate of the center of the sweep 82 @param colors The array[count] of colors, to be distributed around the center. 83 @param pos May be NULL. The array[count] of SkScalars, or NULL, of the relative position of 84 each corresponding color in the colors array. If this is NULL, 85 the the colors are distributed evenly between the center and edge of the circle. 86 If this is not null, the values must begin with 0, end with 1.0, and 87 intermediate values must be strictly increasing. 88 @param count Must be >= 2. The number of colors (and pos if not NULL) entries 89 @param mapper May be NULL. Callback to modify the spread of the colors. 90 */ 91 static SkShader* CreateSweep(SkScalar cx, SkScalar cy, 92 const SkColor colors[], const SkScalar pos[], 93 int count, SkUnitMapper* mapper = NULL); 94}; 95 96#endif 97 98