| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef UI_VIEWS_PAINTER_H_ | 5 #ifndef UI_VIEWS_PAINTER_H_ |
| 6 #define UI_VIEWS_PAINTER_H_ | 6 #define UI_VIEWS_PAINTER_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| 11 #include "third_party/skia/include/core/SkColor.h" | 11 #include "third_party/skia/include/core/SkColor.h" |
| 12 #include "ui/views/views_export.h" | 12 #include "ui/views/views_export.h" |
| 13 | 13 |
| 14 class SkBitmap; | 14 class SkBitmap; |
| 15 | 15 |
| 16 namespace gfx { | 16 namespace gfx { |
| 17 class Canvas; | 17 class CanvasSkia; |
| 18 class Insets; | 18 class Insets; |
| 19 class Rect; | 19 class Rect; |
| 20 class Size; | 20 class Size; |
| 21 } | 21 } |
| 22 | 22 |
| 23 namespace views { | 23 namespace views { |
| 24 | 24 |
| 25 // Painter, as the name implies, is responsible for painting in a particular | 25 // Painter, as the name implies, is responsible for painting in a particular |
| 26 // region. Think of Painter as a Border or Background that can be painted | 26 // region. Think of Painter as a Border or Background that can be painted |
| 27 // in any region of a View. | 27 // in any region of a View. |
| 28 class VIEWS_EXPORT Painter { | 28 class VIEWS_EXPORT Painter { |
| 29 public: | 29 public: |
| 30 // A convenience method for painting a Painter in a particular region. | 30 // A convenience method for painting a Painter in a particular region. |
| 31 // This translates the canvas to x/y and paints the painter. | 31 // This translates the canvas to x/y and paints the painter. |
| 32 static void PaintPainterAt(gfx::Canvas* canvas, | 32 static void PaintPainterAt(gfx::CanvasSkia* canvas, |
| 33 Painter* painter, | 33 Painter* painter, |
| 34 const gfx::Rect& rect); | 34 const gfx::Rect& rect); |
| 35 | 35 |
| 36 // Creates a painter that draws a gradient between the two colors. | 36 // Creates a painter that draws a gradient between the two colors. |
| 37 static Painter* CreateHorizontalGradient(SkColor c1, SkColor c2); | 37 static Painter* CreateHorizontalGradient(SkColor c1, SkColor c2); |
| 38 static Painter* CreateVerticalGradient(SkColor c1, SkColor c2); | 38 static Painter* CreateVerticalGradient(SkColor c1, SkColor c2); |
| 39 | 39 |
| 40 // Creates a painter that divides |image| into nine regions. The four corners | 40 // Creates a painter that divides |image| into nine regions. The four corners |
| 41 // are rendered at the size specified in insets (for example, the upper | 41 // are rendered at the size specified in insets (for example, the upper |
| 42 // left corners is rendered at 0x0 with a size of | 42 // left corners is rendered at 0x0 with a size of |
| 43 // insets.left()xinsets.right()). The four edges are stretched to fill the | 43 // insets.left()xinsets.right()). The four edges are stretched to fill the |
| 44 // destination size. | 44 // destination size. |
| 45 // Ownership is passed to the caller. | 45 // Ownership is passed to the caller. |
| 46 static Painter* CreateImagePainter(const SkBitmap& image, | 46 static Painter* CreateImagePainter(const SkBitmap& image, |
| 47 const gfx::Insets& insets, | 47 const gfx::Insets& insets, |
| 48 bool paint_center); | 48 bool paint_center); |
| 49 | 49 |
| 50 virtual ~Painter() {} | 50 virtual ~Painter() {} |
| 51 | 51 |
| 52 // Paints the painter in the specified region. | 52 // Paints the painter in the specified region. |
| 53 virtual void Paint(gfx::Canvas* canvas, const gfx::Size& size) = 0; | 53 virtual void Paint(gfx::CanvasSkia* canvas, const gfx::Size& size) = 0; |
| 54 }; | 54 }; |
| 55 | 55 |
| 56 // HorizontalPainter paints 3 images into a box: left, center and right. The | 56 // HorizontalPainter paints 3 images into a box: left, center and right. The |
| 57 // left and right images are drawn to size at the left/right edges of the | 57 // left and right images are drawn to size at the left/right edges of the |
| 58 // region. The center is tiled in the remaining space. All images must have the | 58 // region. The center is tiled in the remaining space. All images must have the |
| 59 // same height. | 59 // same height. |
| 60 class VIEWS_EXPORT HorizontalPainter : public Painter { | 60 class VIEWS_EXPORT HorizontalPainter : public Painter { |
| 61 public: | 61 public: |
| 62 // Constructs a new HorizontalPainter loading the specified image names. | 62 // Constructs a new HorizontalPainter loading the specified image names. |
| 63 // The images must be in the order left, right and center. | 63 // The images must be in the order left, right and center. |
| 64 explicit HorizontalPainter(const int image_resource_names[]); | 64 explicit HorizontalPainter(const int image_resource_names[]); |
| 65 | 65 |
| 66 virtual ~HorizontalPainter() {} | 66 virtual ~HorizontalPainter() {} |
| 67 | 67 |
| 68 // Paints the images. | 68 // Paints the images. |
| 69 virtual void Paint(gfx::Canvas* canvas, const gfx::Size& size) OVERRIDE; | 69 virtual void Paint(gfx::CanvasSkia* canvas, const gfx::Size& size) OVERRIDE; |
| 70 | 70 |
| 71 // Height of the images. | 71 // Height of the images. |
| 72 int height() const { return height_; } | 72 int height() const { return height_; } |
| 73 | 73 |
| 74 private: | 74 private: |
| 75 // The image chunks. | 75 // The image chunks. |
| 76 enum BorderElements { | 76 enum BorderElements { |
| 77 LEFT, | 77 LEFT, |
| 78 CENTER, | 78 CENTER, |
| 79 RIGHT | 79 RIGHT |
| 80 }; | 80 }; |
| 81 | 81 |
| 82 // The height. | 82 // The height. |
| 83 int height_; | 83 int height_; |
| 84 // NOTE: the images are owned by ResourceBundle. Don't free them. | 84 // NOTE: the images are owned by ResourceBundle. Don't free them. |
| 85 SkBitmap* images_[3]; | 85 SkBitmap* images_[3]; |
| 86 | 86 |
| 87 DISALLOW_COPY_AND_ASSIGN(HorizontalPainter); | 87 DISALLOW_COPY_AND_ASSIGN(HorizontalPainter); |
| 88 }; | 88 }; |
| 89 | 89 |
| 90 } // namespace views | 90 } // namespace views |
| 91 | 91 |
| 92 #endif // UI_VIEWS_PAINTER_H_ | 92 #endif // UI_VIEWS_PAINTER_H_ |
| OLD | NEW |