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