Chromium Code Reviews| Index: ui/views/painter.cc |
| diff --git a/ui/views/painter.cc b/ui/views/painter.cc |
| index 96d063d8134c8ac7b69db90078c8ea37b2464740..fc29db5c7acbc8c29a5760e2954e7a788713c5b3 100644 |
| --- a/ui/views/painter.cc |
| +++ b/ui/views/painter.cc |
| @@ -20,8 +20,11 @@ namespace { |
| class GradientPainter : public Painter { |
| public: |
| - GradientPainter(bool horizontal, SkColor top, SkColor bottom) |
| - : horizontal_(horizontal) { |
| + GradientPainter(bool horizontal, SkColor top, SkColor bottom, double start, |
|
msw
2012/08/08 17:12:20
nit: one param per line
markusheintz_
2012/08/08 21:53:55
Done.
|
| + double end) |
| + : horizontal_(horizontal), |
| + start_(start), |
| + end_(end) { |
| colors_[0] = top; |
| colors_[1] = bottom; |
| } |
| @@ -33,11 +36,13 @@ class GradientPainter : public Painter { |
| virtual void Paint(gfx::Canvas* canvas, const gfx::Size& size) OVERRIDE { |
| SkPaint paint; |
| SkPoint p[2]; |
| - p[0].iset(0, 0); |
| - if (horizontal_) |
| - p[1].iset(size.width(), 0); |
| - else |
| - p[1].iset(0, size.height()); |
| + if (horizontal_) { |
| + p[0].iset(size.width() * start_, 0); |
| + p[1].iset(size.width() * end_, 0); |
| + } else { |
| + p[0].iset(0, size.height() * start_); |
| + p[1].iset(0, size.height() * end_); |
| + } |
| SkShader* s = SkGradientShader::CreateLinear(p, colors_, NULL, 2, |
| SkShader::kClamp_TileMode, NULL); |
| @@ -52,8 +57,16 @@ class GradientPainter : public Painter { |
| } |
| private: |
| + // If |horizontal_| is true then the gradiant is painted horizontally. |
| bool horizontal_; |
| + // The start and the end color of the gradient. |
| SkColor colors_[2]; |
| + // The start of the gradient specified as percentage of the total size of the |
|
msw
2012/08/08 17:12:20
nit: s/percentage/ratio/, ditto below
markusheintz_
2012/08/08 21:53:55
obsolete
|
| + // background. |
| + double start_; |
|
msw
2012/08/08 17:12:20
Consider using SkScalar/floats here, instead of do
markusheintz_
2012/08/08 21:53:55
Done.
|
| + // The end of the gradient specified as percentage of the total size of the |
| + // background. |
| + double end_; |
| DISALLOW_COPY_AND_ASSIGN(GradientPainter); |
| }; |
| @@ -163,12 +176,18 @@ void Painter::PaintPainterAt(gfx::Canvas* canvas, |
| // static |
| Painter* Painter::CreateHorizontalGradient(SkColor c1, SkColor c2) { |
| - return new GradientPainter(true, c1, c2); |
| + return new GradientPainter(true, c1, c2, 0.0f, 1.0f); |
| } |
| // static |
| Painter* Painter::CreateVerticalGradient(SkColor c1, SkColor c2) { |
| - return new GradientPainter(false, c1, c2); |
| + return new GradientPainter(false, c1, c2, 0.0f, 1.0f); |
| +} |
| + |
| +// static |
| +Painter* Painter::CreateVerticalGradientRange( |
| + SkColor c1, SkColor c2, float start, float end) { |
|
msw
2012/08/08 17:12:20
nit: one param per line
markusheintz_
2012/08/08 21:53:55
Done.
|
| + return new GradientPainter(false, c1, c2, start, end); |
| } |
| // static |