Index: ui/views/painter.cc |
diff --git a/ui/views/painter.cc b/ui/views/painter.cc |
index 96d063d8134c8ac7b69db90078c8ea37b2464740..454613bbc8fcf592f3f3b42a2789d03dfce1353f 100644 |
--- a/ui/views/painter.cc |
+++ b/ui/views/painter.cc |
@@ -20,13 +20,23 @@ namespace { |
class GradientPainter : public Painter { |
public: |
- GradientPainter(bool horizontal, SkColor top, SkColor bottom) |
- : horizontal_(horizontal) { |
- colors_[0] = top; |
- colors_[1] = bottom; |
+ GradientPainter(bool horizontal, |
+ SkColor* colors, |
+ SkScalar* pos, |
+ int count) |
msw
2012/08/08 23:13:53
nit: ditto for size_t
markusheintz_
2012/08/09 01:00:15
Done.
|
+ : horizontal_(horizontal), count_(count) { |
msw
2012/08/08 23:13:53
nit: I think if the params and initializer list do
markusheintz_
2012/08/09 01:00:15
Done.
|
+ pos_ = new SkScalar[count_]; |
+ colors_ = new SkColor[count_]; |
+ |
+ for (int i = 0; i < count_; ++i) { |
msw
2012/08/08 23:13:53
nit: ditto for size_t
markusheintz_
2012/08/09 01:00:15
Done.
|
+ pos_[i] = pos[i]; |
+ colors_[i] = colors[i]; |
+ } |
} |
virtual ~GradientPainter() { |
+ delete [] pos_; |
msw
2012/08/08 23:13:53
nit: no space in "delete[]", same below.
markusheintz_
2012/08/09 01:00:15
Done.
|
+ delete [] colors_; |
} |
// Overridden from Painter: |
@@ -34,12 +44,13 @@ class GradientPainter : public Painter { |
SkPaint paint; |
SkPoint p[2]; |
p[0].iset(0, 0); |
- if (horizontal_) |
+ if (horizontal_) { |
p[1].iset(size.width(), 0); |
- else |
+ } else { |
p[1].iset(0, size.height()); |
+ } |
- SkShader* s = SkGradientShader::CreateLinear(p, colors_, NULL, 2, |
+ SkShader* s = SkGradientShader::CreateLinear(p, colors_, pos_, count_, |
SkShader::kClamp_TileMode, NULL); |
paint.setStyle(SkPaint::kFill_Style); |
paint.setShader(s); |
@@ -52,8 +63,14 @@ class GradientPainter : public Painter { |
} |
private: |
+ // If |horizontal_| is true then the gradiant is painted horizontally. |
bool horizontal_; |
- SkColor colors_[2]; |
+ // The gradient colors. |
+ SkColor* colors_; |
+ // The relatove positions of the corresponding gradient colors. |
msw
2012/08/08 23:13:53
nit: relative
markusheintz_
2012/08/09 01:00:15
Done.
|
+ SkScalar* pos_; |
+ // The number of elements in |colors_| and |pos_|. |
+ int count_; |
DISALLOW_COPY_AND_ASSIGN(GradientPainter); |
}; |
@@ -163,12 +180,26 @@ void Painter::PaintPainterAt(gfx::Canvas* canvas, |
// static |
Painter* Painter::CreateHorizontalGradient(SkColor c1, SkColor c2) { |
- return new GradientPainter(true, c1, c2); |
+ SkColor colors[2]; |
+ colors[0] = c1; |
+ colors[1] = c2; |
+ SkScalar pos[] = {0, 1}; |
+ return new GradientPainter(true, colors, pos, 2); |
} |
// static |
Painter* Painter::CreateVerticalGradient(SkColor c1, SkColor c2) { |
- return new GradientPainter(false, c1, c2); |
+ SkColor colors[2]; |
+ colors[0] = c1; |
+ colors[1] = c2; |
+ SkScalar pos[] = {0, 1}; |
+ return new GradientPainter(false, colors, pos, 2); |
+} |
+ |
+// static |
+Painter* Painter::CreateVerticalGradientRange( |
msw
2012/08/08 23:13:53
nit: use MultiColor / Range terminology consistent
markusheintz_
2012/08/09 01:00:15
Done.
|
+ SkColor* colors, SkScalar* pos, int count) { |
msw
2012/08/08 23:13:53
nit: one param per line
markusheintz_
2012/08/09 01:00:15
Done.
|
+ return new GradientPainter(false, colors, pos, count); |
} |
// static |