Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(41)

Side by Side Diff: views/painter.h

Issue 113443: ChromeCanvas->gfx::Canvas (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 11 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « views/drag_utils.cc ('k') | views/painter.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 VIEWS_PAINTER_H_ 5 #ifndef VIEWS_PAINTER_H_
6 #define VIEWS_PAINTER_H_ 6 #define VIEWS_PAINTER_H_
7 7
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
11 #include "third_party/skia/include/core/SkColor.h" 11 #include "third_party/skia/include/core/SkColor.h"
12 12
13 class ChromeCanvas; 13 namespace gfx {
14 class Canvas;
15 }
14 class SkBitmap; 16 class SkBitmap;
15 17
16 namespace views { 18 namespace views {
17 19
18 // Painter, as the name implies, is responsible for painting in a particular 20 // Painter, as the name implies, is responsible for painting in a particular
19 // region. Think of Painter as a Border or Background that can be painted 21 // region. Think of Painter as a Border or Background that can be painted
20 // in any region of a View. 22 // in any region of a View.
21 class Painter { 23 class Painter {
22 public: 24 public:
23 // A convenience method for painting a Painter in a particular region. 25 // A convenience method for painting a Painter in a particular region.
24 // This translates the canvas to x/y and paints the painter. 26 // This translates the canvas to x/y and paints the painter.
25 static void PaintPainterAt(int x, int y, int w, int h, 27 static void PaintPainterAt(int x, int y, int w, int h,
26 ChromeCanvas* canvas, Painter* painter); 28 gfx::Canvas* canvas, Painter* painter);
27 29
28 // Creates a painter that draws a gradient between the two colors. 30 // Creates a painter that draws a gradient between the two colors.
29 static Painter* CreateHorizontalGradient(SkColor c1, SkColor c2); 31 static Painter* CreateHorizontalGradient(SkColor c1, SkColor c2);
30 static Painter* CreateVerticalGradient(SkColor c1, SkColor c2); 32 static Painter* CreateVerticalGradient(SkColor c1, SkColor c2);
31 33
32 virtual ~Painter() {} 34 virtual ~Painter() {}
33 35
34 // Paints the painter in the specified region. 36 // Paints the painter in the specified region.
35 virtual void Paint(int w, int h, ChromeCanvas* canvas) = 0; 37 virtual void Paint(int w, int h, gfx::Canvas* canvas) = 0;
36 }; 38 };
37 39
38 // ImagePainter paints 8 (or 9) images into a box. The four corner 40 // ImagePainter paints 8 (or 9) images into a box. The four corner
39 // images are drawn at the size of the image, the top/left/bottom/right 41 // images are drawn at the size of the image, the top/left/bottom/right
40 // images are tiled to fit the area, and the center (if rendered) is 42 // images are tiled to fit the area, and the center (if rendered) is
41 // stretched. 43 // stretched.
42 class ImagePainter : public Painter { 44 class ImagePainter : public Painter {
43 public: 45 public:
44 enum BorderElements { 46 enum BorderElements {
45 BORDER_TOP_LEFT = 0, 47 BORDER_TOP_LEFT = 0,
(...skipping 11 matching lines...) Expand all
57 // The images must be in the order defined by the BorderElements. 59 // The images must be in the order defined by the BorderElements.
58 // If draw_center is false, there must be 8 image names, if draw_center 60 // If draw_center is false, there must be 8 image names, if draw_center
59 // is true, there must be 9 image names with the last giving the name 61 // is true, there must be 9 image names with the last giving the name
60 // of the center image. 62 // of the center image.
61 ImagePainter(const int image_resource_names[], 63 ImagePainter(const int image_resource_names[],
62 bool draw_center); 64 bool draw_center);
63 65
64 virtual ~ImagePainter() {} 66 virtual ~ImagePainter() {}
65 67
66 // Paints the images. 68 // Paints the images.
67 virtual void Paint(int w, int h, ChromeCanvas* canvas); 69 virtual void Paint(int w, int h, gfx::Canvas* canvas);
68 70
69 // Returns the specified image. The returned image should NOT be deleted. 71 // Returns the specified image. The returned image should NOT be deleted.
70 SkBitmap* GetImage(BorderElements element) { 72 SkBitmap* GetImage(BorderElements element) {
71 return images_[element]; 73 return images_[element];
72 } 74 }
73 75
74 private: 76 private:
75 bool tile_; 77 bool tile_;
76 bool draw_center_; 78 bool draw_center_;
77 bool tile_center_; 79 bool tile_center_;
78 // NOTE: the images are owned by ResourceBundle. Don't free them. 80 // NOTE: the images are owned by ResourceBundle. Don't free them.
79 std::vector<SkBitmap*> images_; 81 std::vector<SkBitmap*> images_;
80 82
81 DISALLOW_EVIL_CONSTRUCTORS(ImagePainter); 83 DISALLOW_EVIL_CONSTRUCTORS(ImagePainter);
82 }; 84 };
83 85
84 // HorizontalPainter paints 3 images into a box: left, center and right. The 86 // HorizontalPainter paints 3 images into a box: left, center and right. The
85 // left and right images are drawn to size at the left/right edges of the 87 // left and right images are drawn to size at the left/right edges of the
86 // region. The center is tiled in the remaining space. All images must have the 88 // region. The center is tiled in the remaining space. All images must have the
87 // same height. 89 // same height.
88 class HorizontalPainter : public Painter { 90 class HorizontalPainter : public Painter {
89 public: 91 public:
90 // Constructs a new HorizontalPainter loading the specified image names. 92 // Constructs a new HorizontalPainter loading the specified image names.
91 // The images must be in the order left, right and center. 93 // The images must be in the order left, right and center.
92 explicit HorizontalPainter(const int image_resource_names[]); 94 explicit HorizontalPainter(const int image_resource_names[]);
93 95
94 virtual ~HorizontalPainter() {} 96 virtual ~HorizontalPainter() {}
95 97
96 // Paints the images. 98 // Paints the images.
97 virtual void Paint(int w, int h, ChromeCanvas* canvas); 99 virtual void Paint(int w, int h, gfx::Canvas* canvas);
98 100
99 // Height of the images. 101 // Height of the images.
100 int height() const { return height_; } 102 int height() const { return height_; }
101 103
102 private: 104 private:
103 // The image chunks. 105 // The image chunks.
104 enum BorderElements { 106 enum BorderElements {
105 LEFT, 107 LEFT,
106 CENTER, 108 CENTER,
107 RIGHT 109 RIGHT
108 }; 110 };
109 111
110 // The height. 112 // The height.
111 int height_; 113 int height_;
112 // NOTE: the images are owned by ResourceBundle. Don't free them. 114 // NOTE: the images are owned by ResourceBundle. Don't free them.
113 SkBitmap* images_[3]; 115 SkBitmap* images_[3];
114 116
115 DISALLOW_EVIL_CONSTRUCTORS(HorizontalPainter); 117 DISALLOW_EVIL_CONSTRUCTORS(HorizontalPainter);
116 }; 118 };
117 119
118 } // namespace views 120 } // namespace views
119 121
120 #endif // VIEWS_PAINTER_H_ 122 #endif // VIEWS_PAINTER_H_
OLDNEW
« no previous file with comments | « views/drag_utils.cc ('k') | views/painter.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698