| 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; | |
| 15 | |
| 16 namespace gfx { | 14 namespace gfx { |
| 17 class Canvas; | 15 class Canvas; |
| 16 class ImageSkia; |
| 18 class Insets; | 17 class Insets; |
| 19 class Rect; | 18 class Rect; |
| 20 class Size; | 19 class Size; |
| 21 } | 20 } |
| 22 | 21 |
| 23 namespace views { | 22 namespace views { |
| 24 | 23 |
| 25 // Painter, as the name implies, is responsible for painting in a particular | 24 // 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 | 25 // region. Think of Painter as a Border or Background that can be painted |
| 27 // in any region of a View. | 26 // in any region of a View. |
| 28 class VIEWS_EXPORT Painter { | 27 class VIEWS_EXPORT Painter { |
| 29 public: | 28 public: |
| 30 // A convenience method for painting a Painter in a particular region. | 29 // A convenience method for painting a Painter in a particular region. |
| 31 // This translates the canvas to x/y and paints the painter. | 30 // This translates the canvas to x/y and paints the painter. |
| 32 static void PaintPainterAt(gfx::Canvas* canvas, | 31 static void PaintPainterAt(gfx::Canvas* canvas, |
| 33 Painter* painter, | 32 Painter* painter, |
| 34 const gfx::Rect& rect); | 33 const gfx::Rect& rect); |
| 35 | 34 |
| 36 // Creates a painter that draws a gradient between the two colors. | 35 // Creates a painter that draws a gradient between the two colors. |
| 37 static Painter* CreateHorizontalGradient(SkColor c1, SkColor c2); | 36 static Painter* CreateHorizontalGradient(SkColor c1, SkColor c2); |
| 38 static Painter* CreateVerticalGradient(SkColor c1, SkColor c2); | 37 static Painter* CreateVerticalGradient(SkColor c1, SkColor c2); |
| 39 | 38 |
| 40 // Creates a painter that divides |image| into nine regions. The four corners | 39 // 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 | 40 // are rendered at the size specified in insets (for example, the upper |
| 42 // left corners is rendered at 0x0 with a size of | 41 // left corners is rendered at 0x0 with a size of |
| 43 // insets.left()xinsets.right()). The four edges are stretched to fill the | 42 // insets.left()xinsets.right()). The four edges are stretched to fill the |
| 44 // destination size. | 43 // destination size. |
| 45 // Ownership is passed to the caller. | 44 // Ownership is passed to the caller. |
| 46 static Painter* CreateImagePainter(const SkBitmap& image, | 45 static Painter* CreateImagePainter(const gfx::ImageSkia& image, |
| 47 const gfx::Insets& insets, | 46 const gfx::Insets& insets, |
| 48 bool paint_center); | 47 bool paint_center); |
| 49 | 48 |
| 50 virtual ~Painter() {} | 49 virtual ~Painter() {} |
| 51 | 50 |
| 52 // Paints the painter in the specified region. | 51 // Paints the painter in the specified region. |
| 53 virtual void Paint(gfx::Canvas* canvas, const gfx::Size& size) = 0; | 52 virtual void Paint(gfx::Canvas* canvas, const gfx::Size& size) = 0; |
| 54 }; | 53 }; |
| 55 | 54 |
| 56 // HorizontalPainter paints 3 images into a box: left, center and right. The | 55 // HorizontalPainter paints 3 images into a box: left, center and right. The |
| (...skipping 18 matching lines...) Expand all Loading... |
| 75 // The image chunks. | 74 // The image chunks. |
| 76 enum BorderElements { | 75 enum BorderElements { |
| 77 LEFT, | 76 LEFT, |
| 78 CENTER, | 77 CENTER, |
| 79 RIGHT | 78 RIGHT |
| 80 }; | 79 }; |
| 81 | 80 |
| 82 // The height. | 81 // The height. |
| 83 int height_; | 82 int height_; |
| 84 // NOTE: the images are owned by ResourceBundle. Don't free them. | 83 // NOTE: the images are owned by ResourceBundle. Don't free them. |
| 85 const SkBitmap* images_[3]; | 84 const gfx::ImageSkia* images_[3]; |
| 86 | 85 |
| 87 DISALLOW_COPY_AND_ASSIGN(HorizontalPainter); | 86 DISALLOW_COPY_AND_ASSIGN(HorizontalPainter); |
| 88 }; | 87 }; |
| 89 | 88 |
| 90 } // namespace views | 89 } // namespace views |
| 91 | 90 |
| 92 #endif // UI_VIEWS_PAINTER_H_ | 91 #endif // UI_VIEWS_PAINTER_H_ |
| OLD | NEW |