| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 |
|
|---|
| 27 |
|
|---|
| 28 |
#ifndef Gradient_h |
|---|
| 29 |
#define Gradient_h |
|---|
| 30 |
|
|---|
| 31 |
#include "AffineTransform.h" |
|---|
| 32 |
#include "FloatPoint.h" |
|---|
| 33 |
#include "Generator.h" |
|---|
| 34 |
#include "GraphicsTypes.h" |
|---|
| 35 |
#include <wtf/PassRefPtr.h> |
|---|
| 36 |
#include <wtf/Vector.h> |
|---|
| 37 |
|
|---|
| 38 |
#if PLATFORM(CG) |
|---|
| 39 |
|
|---|
| 40 |
#define USE_CG_SHADING defined(BUILDING_ON_TIGER) || defined(BUILDING_ON_LEOPARD) |
|---|
| 41 |
|
|---|
| 42 |
#if USE_CG_SHADING |
|---|
| 43 |
typedef struct CGShading* CGShadingRef; |
|---|
| 44 |
typedef CGShadingRef PlatformGradient; |
|---|
| 45 |
#else |
|---|
| 46 |
typedef struct CGGradient* CGGradientRef; |
|---|
| 47 |
typedef CGGradientRef PlatformGradient; |
|---|
| 48 |
#endif |
|---|
| 49 |
|
|---|
| 50 |
#elif PLATFORM(QT) |
|---|
| 51 |
QT_BEGIN_NAMESPACE |
|---|
| 52 |
class QGradient; |
|---|
| 53 |
QT_END_NAMESPACE |
|---|
| 54 |
typedef QGradient* PlatformGradient; |
|---|
| 55 |
#elif PLATFORM(CAIRO) |
|---|
| 56 |
typedef struct _cairo_pattern cairo_pattern_t; |
|---|
| 57 |
typedef cairo_pattern_t* PlatformGradient; |
|---|
| 58 |
#elif PLATFORM(SKIA) |
|---|
| 59 |
class SkShader; |
|---|
| 60 |
typedef class SkShader* PlatformGradient; |
|---|
| 61 |
typedef class SkShader* PlatformPattern; |
|---|
| 62 |
#elif PLATFORM(HAIKU) |
|---|
| 63 |
class BGradient; |
|---|
| 64 |
typedef BGradient* PlatformGradient; |
|---|
| 65 |
#else |
|---|
| 66 |
typedef void* PlatformGradient; |
|---|
| 67 |
#endif |
|---|
| 68 |
|
|---|
| 69 |
namespace WebCore { |
|---|
| 70 |
|
|---|
| 71 |
class Color; |
|---|
| 72 |
|
|---|
| 73 |
class Gradient : public Generator { |
|---|
| 74 |
public: |
|---|
| 75 |
static PassRefPtr<Gradient> create(const FloatPoint& p0, const FloatPoint& p1) |
|---|
| 76 |
{ |
|---|
| 77 |
return adoptRef(new Gradient(p0, p1)); |
|---|
| 78 |
} |
|---|
| 79 |
static PassRefPtr<Gradient> create(const FloatPoint& p0, float r0, const FloatPoint& p1, float r1) |
|---|
| 80 |
{ |
|---|
| 81 |
return adoptRef(new Gradient(p0, r0, p1, r1)); |
|---|
| 82 |
} |
|---|
| 83 |
virtual ~Gradient(); |
|---|
| 84 |
|
|---|
| 85 |
void addColorStop(float, const Color&); |
|---|
| 86 |
|
|---|
| 87 |
void getColor(float value, float* r, float* g, float* b, float* a) const; |
|---|
| 88 |
|
|---|
| 89 |
#if OS(WINCE) && !PLATFORM(QT) |
|---|
| 90 |
const FloatPoint& p0() const { return m_p0; } |
|---|
| 91 |
const FloatPoint& p1() const { return m_p1; } |
|---|
| 92 |
float r0() const { return m_r0; } |
|---|
| 93 |
float r1() const { return m_r1; } |
|---|
| 94 |
bool isRadial() const { return m_radial; } |
|---|
| 95 |
struct ColorStop; |
|---|
| 96 |
const Vector<ColorStop>& getStops() const; |
|---|
| 97 |
#else |
|---|
| 98 |
PlatformGradient platformGradient(); |
|---|
| 99 |
#endif |
|---|
| 100 |
struct ColorStop { |
|---|
| 101 |
float stop; |
|---|
| 102 |
float red; |
|---|
| 103 |
float green; |
|---|
| 104 |
float blue; |
|---|
| 105 |
float alpha; |
|---|
| 106 |
|
|---|
| 107 |
ColorStop() : stop(0), red(0), green(0), blue(0), alpha(0) { } |
|---|
| 108 |
ColorStop(float s, float r, float g, float b, float a) : stop(s), red(r), green(g), blue(b), alpha(a) { } |
|---|
| 109 |
}; |
|---|
| 110 |
|
|---|
| 111 |
void setStopsSorted(bool s) { m_stopsSorted = s; } |
|---|
| 112 |
|
|---|
| 113 |
void setSpreadMethod(GradientSpreadMethod); |
|---|
| 114 |
GradientSpreadMethod spreadMethod() { return m_spreadMethod; } |
|---|
| 115 |
void setGradientSpaceTransform(const AffineTransform& gradientSpaceTransformation); |
|---|
| 116 |
|
|---|
| 117 |
AffineTransform gradientSpaceTransform() { return m_gradientSpaceTransformation; } |
|---|
| 118 |
|
|---|
| 119 |
virtual void fill(GraphicsContext*, const FloatRect&); |
|---|
| 120 |
virtual void adjustParametersForTiledDrawing(IntSize& size, FloatRect& srcRect); |
|---|
| 121 |
|
|---|
| 122 |
void setPlatformGradientSpaceTransform(const AffineTransform& gradientSpaceTransformation); |
|---|
| 123 |
|
|---|
| 124 |
#if PLATFORM(CG) |
|---|
| 125 |
void paint(GraphicsContext*); |
|---|
| 126 |
#endif |
|---|
| 127 |
private: |
|---|
| 128 |
Gradient(const FloatPoint& p0, const FloatPoint& p1); |
|---|
| 129 |
Gradient(const FloatPoint& p0, float r0, const FloatPoint& p1, float r1); |
|---|
| 130 |
|
|---|
| 131 |
void platformInit() { m_gradient = 0; } |
|---|
| 132 |
void platformDestroy(); |
|---|
| 133 |
|
|---|
| 134 |
int findStop(float value) const; |
|---|
| 135 |
void sortStopsIfNecessary(); |
|---|
| 136 |
|
|---|
| 137 |
bool m_radial; |
|---|
| 138 |
FloatPoint m_p0; |
|---|
| 139 |
FloatPoint m_p1; |
|---|
| 140 |
float m_r0; |
|---|
| 141 |
float m_r1; |
|---|
| 142 |
mutable Vector<ColorStop> m_stops; |
|---|
| 143 |
mutable bool m_stopsSorted; |
|---|
| 144 |
mutable int m_lastStop; |
|---|
| 145 |
GradientSpreadMethod m_spreadMethod; |
|---|
| 146 |
AffineTransform m_gradientSpaceTransformation; |
|---|
| 147 |
|
|---|
| 148 |
PlatformGradient m_gradient; |
|---|
| 149 |
}; |
|---|
| 150 |
|
|---|
| 151 |
} |
|---|
| 152 |
|
|---|
| 153 |
#endif |
|---|
| 154 |
|
|---|