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

Side by Side Diff: views/painter.cc

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/painter.h ('k') | views/view.h » ('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 #include "views/painter.h" 5 #include "views/painter.h"
6 6
7 #include "app/gfx/chrome_canvas.h" 7 #include "app/gfx/canvas.h"
8 #include "app/resource_bundle.h" 8 #include "app/resource_bundle.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "third_party/skia/include/core/SkBitmap.h" 10 #include "third_party/skia/include/core/SkBitmap.h"
11 #include "third_party/skia/include/effects/SkGradientShader.h" 11 #include "third_party/skia/include/effects/SkGradientShader.h"
12 12
13 namespace views { 13 namespace views {
14 14
15 namespace { 15 namespace {
16 16
17 class GradientPainter : public Painter { 17 class GradientPainter : public Painter {
18 public: 18 public:
19 GradientPainter(bool horizontal, const SkColor& top, const SkColor& bottom) 19 GradientPainter(bool horizontal, const SkColor& top, const SkColor& bottom)
20 : horizontal_(horizontal) { 20 : horizontal_(horizontal) {
21 colors_[0] = top; 21 colors_[0] = top;
22 colors_[1] = bottom; 22 colors_[1] = bottom;
23 } 23 }
24 24
25 virtual ~GradientPainter() { 25 virtual ~GradientPainter() {
26 } 26 }
27 27
28 void Paint(int w, int h, ChromeCanvas* canvas) { 28 void Paint(int w, int h, gfx::Canvas* canvas) {
29 SkPaint paint; 29 SkPaint paint;
30 SkPoint p[2]; 30 SkPoint p[2];
31 p[0].set(SkIntToScalar(0), SkIntToScalar(0)); 31 p[0].set(SkIntToScalar(0), SkIntToScalar(0));
32 if (horizontal_) 32 if (horizontal_)
33 p[1].set(SkIntToScalar(w), SkIntToScalar(0)); 33 p[1].set(SkIntToScalar(w), SkIntToScalar(0));
34 else 34 else
35 p[1].set(SkIntToScalar(0), SkIntToScalar(h)); 35 p[1].set(SkIntToScalar(0), SkIntToScalar(h));
36 36
37 SkShader* s = 37 SkShader* s =
38 SkGradientShader::CreateLinear(p, colors_, NULL, 2, 38 SkGradientShader::CreateLinear(p, colors_, NULL, 2,
(...skipping 12 matching lines...) Expand all
51 SkColor colors_[2]; 51 SkColor colors_[2];
52 52
53 DISALLOW_EVIL_CONSTRUCTORS(GradientPainter); 53 DISALLOW_EVIL_CONSTRUCTORS(GradientPainter);
54 }; 54 };
55 55
56 56
57 } 57 }
58 58
59 // static 59 // static
60 void Painter::PaintPainterAt(int x, int y, int w, int h, 60 void Painter::PaintPainterAt(int x, int y, int w, int h,
61 ChromeCanvas* canvas, Painter* painter) { 61 gfx::Canvas* canvas, Painter* painter) {
62 DCHECK(canvas && painter); 62 DCHECK(canvas && painter);
63 if (w < 0 || h < 0) 63 if (w < 0 || h < 0)
64 return; 64 return;
65 canvas->save(); 65 canvas->save();
66 canvas->TranslateInt(x, y); 66 canvas->TranslateInt(x, y);
67 painter->Paint(w, h, canvas); 67 painter->Paint(w, h, canvas);
68 canvas->restore(); 68 canvas->restore();
69 } 69 }
70 70
71 ImagePainter::ImagePainter(const int image_resource_names[], 71 ImagePainter::ImagePainter(const int image_resource_names[],
72 bool draw_center) 72 bool draw_center)
73 : draw_center_(draw_center) { 73 : draw_center_(draw_center) {
74 DCHECK(image_resource_names); 74 DCHECK(image_resource_names);
75 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); 75 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
76 for (int i = 0, max = draw_center ? 9 : 8; i < max; ++i) 76 for (int i = 0, max = draw_center ? 9 : 8; i < max; ++i)
77 images_.push_back(rb.GetBitmapNamed(image_resource_names[i])); 77 images_.push_back(rb.GetBitmapNamed(image_resource_names[i]));
78 } 78 }
79 79
80 void ImagePainter::Paint(int w, int h, ChromeCanvas* canvas) { 80 void ImagePainter::Paint(int w, int h, gfx::Canvas* canvas) {
81 canvas->DrawBitmapInt(*images_[BORDER_TOP_LEFT], 0, 0); 81 canvas->DrawBitmapInt(*images_[BORDER_TOP_LEFT], 0, 0);
82 canvas->TileImageInt(*images_[BORDER_TOP], 82 canvas->TileImageInt(*images_[BORDER_TOP],
83 images_[BORDER_TOP_LEFT]->width(), 83 images_[BORDER_TOP_LEFT]->width(),
84 0, 84 0,
85 w - images_[BORDER_TOP_LEFT]->width() - 85 w - images_[BORDER_TOP_LEFT]->width() -
86 images_[BORDER_TOP_RIGHT]->width(), 86 images_[BORDER_TOP_RIGHT]->width(),
87 images_[BORDER_TOP_LEFT]->height()); 87 images_[BORDER_TOP_LEFT]->height());
88 canvas->DrawBitmapInt(*images_[BORDER_TOP_RIGHT], 88 canvas->DrawBitmapInt(*images_[BORDER_TOP_RIGHT],
89 w - images_[BORDER_TOP_RIGHT]->width(), 89 w - images_[BORDER_TOP_RIGHT]->width(),
90 0); 90 0);
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 140
141 HorizontalPainter::HorizontalPainter(const int image_resource_names[]) { 141 HorizontalPainter::HorizontalPainter(const int image_resource_names[]) {
142 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); 142 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
143 for (int i = 0; i < 3; ++i) 143 for (int i = 0; i < 3; ++i)
144 images_[i] = rb.GetBitmapNamed(image_resource_names[i]); 144 images_[i] = rb.GetBitmapNamed(image_resource_names[i]);
145 height_ = images_[LEFT]->height(); 145 height_ = images_[LEFT]->height();
146 DCHECK(images_[LEFT]->height() == images_[RIGHT]->height() && 146 DCHECK(images_[LEFT]->height() == images_[RIGHT]->height() &&
147 images_[LEFT]->height() == images_[CENTER]->height()); 147 images_[LEFT]->height() == images_[CENTER]->height());
148 } 148 }
149 149
150 void HorizontalPainter::Paint(int w, int h, ChromeCanvas* canvas) { 150 void HorizontalPainter::Paint(int w, int h, gfx::Canvas* canvas) {
151 if (w < (images_[LEFT]->width() + images_[CENTER]->width() + 151 if (w < (images_[LEFT]->width() + images_[CENTER]->width() +
152 images_[RIGHT]->width())) { 152 images_[RIGHT]->width())) {
153 // No room to paint. 153 // No room to paint.
154 return; 154 return;
155 } 155 }
156 canvas->DrawBitmapInt(*images_[LEFT], 0, 0); 156 canvas->DrawBitmapInt(*images_[LEFT], 0, 0);
157 canvas->DrawBitmapInt(*images_[RIGHT], w - images_[RIGHT]->width(), 0); 157 canvas->DrawBitmapInt(*images_[RIGHT], w - images_[RIGHT]->width(), 0);
158 canvas->TileImageInt(*images_[CENTER], 158 canvas->TileImageInt(*images_[CENTER],
159 images_[LEFT]->width(), 159 images_[LEFT]->width(),
160 0, 160 0,
161 w - images_[LEFT]->width() - images_[RIGHT]->width(), 161 w - images_[LEFT]->width() - images_[RIGHT]->width(),
162 height_); 162 height_);
163 } 163 }
164 164
165 } // namespace views 165 } // namespace views
OLDNEW
« no previous file with comments | « views/painter.h ('k') | views/view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698