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

Side by Side Diff: ui/views/controls/button/image_button.cc

Issue 10174014: views: Add optional overlay image to ImageButton (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: remove debugging tweak Created 8 years, 8 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
OLDNEW
1 // Copyright (c) 2011 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 #include "ui/views/controls/button/image_button.h" 5 #include "ui/views/controls/button/image_button.h"
6 6
7 #include "base/utf_string_conversions.h" 7 #include "base/utf_string_conversions.h"
8 #include "ui/base/animation/throb_animation.h" 8 #include "ui/base/animation/throb_animation.h"
9 #include "ui/gfx/canvas.h" 9 #include "ui/gfx/canvas.h"
10 #include "ui/gfx/skbitmap_operations.h" 10 #include "ui/gfx/skbitmap_operations.h"
11 11
(...skipping 29 matching lines...) Expand all
41 const SkBitmap* mask) { 41 const SkBitmap* mask) {
42 if (!image || !mask) { 42 if (!image || !mask) {
43 background_image_.reset(); 43 background_image_.reset();
44 return; 44 return;
45 } 45 }
46 46
47 background_image_ = 47 background_image_ =
48 SkBitmapOperations::CreateButtonBackground(color, *image, *mask); 48 SkBitmapOperations::CreateButtonBackground(color, *image, *mask);
49 } 49 }
50 50
51 void ImageButton::SetOverlayImage(const SkBitmap* image) {
52 if (!image) {
53 overlay_image_.reset();
54 return;
55 }
56 overlay_image_ = *image;
57 }
58
51 void ImageButton::SetImageAlignment(HorizontalAlignment h_align, 59 void ImageButton::SetImageAlignment(HorizontalAlignment h_align,
52 VerticalAlignment v_align) { 60 VerticalAlignment v_align) {
53 h_alignment_ = h_align; 61 h_alignment_ = h_align;
54 v_alignment_ = v_align; 62 v_alignment_ = v_align;
55 SchedulePaint(); 63 SchedulePaint();
56 } 64 }
57 65
58 //////////////////////////////////////////////////////////////////////////////// 66 ////////////////////////////////////////////////////////////////////////////////
59 // ImageButton, View overrides: 67 // ImageButton, View overrides:
60 68
(...skipping 17 matching lines...) Expand all
78 else if (h_alignment_ == ALIGN_RIGHT) 86 else if (h_alignment_ == ALIGN_RIGHT)
79 x = width() - img.width(); 87 x = width() - img.width();
80 88
81 if (v_alignment_ == ALIGN_MIDDLE) 89 if (v_alignment_ == ALIGN_MIDDLE)
82 y = (height() - img.height()) / 2; 90 y = (height() - img.height()) / 2;
83 else if (v_alignment_ == ALIGN_BOTTOM) 91 else if (v_alignment_ == ALIGN_BOTTOM)
84 y = height() - img.height(); 92 y = height() - img.height();
85 93
86 if (!background_image_.empty()) 94 if (!background_image_.empty())
87 canvas->DrawBitmapInt(background_image_, x, y); 95 canvas->DrawBitmapInt(background_image_, x, y);
96
88 canvas->DrawBitmapInt(img, x, y); 97 canvas->DrawBitmapInt(img, x, y);
98
99 if (!overlay_image_.empty())
100 canvas->DrawBitmapInt(overlay_image_, x, y);
89 } 101 }
90 OnPaintFocusBorder(canvas); 102 OnPaintFocusBorder(canvas);
91 } 103 }
92 104
93 //////////////////////////////////////////////////////////////////////////////// 105 ////////////////////////////////////////////////////////////////////////////////
94 // ImageButton, protected: 106 // ImageButton, protected:
95 107
96 SkBitmap ImageButton::GetImageToPaint() { 108 SkBitmap ImageButton::GetImageToPaint() {
97 SkBitmap img; 109 SkBitmap img;
98 110
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 bool ToggleImageButton::GetTooltipText(const gfx::Point& p, 177 bool ToggleImageButton::GetTooltipText(const gfx::Point& p,
166 string16* tooltip) const { 178 string16* tooltip) const {
167 if (!toggled_ || toggled_tooltip_text_.empty()) 179 if (!toggled_ || toggled_tooltip_text_.empty())
168 return Button::GetTooltipText(p, tooltip); 180 return Button::GetTooltipText(p, tooltip);
169 181
170 *tooltip = toggled_tooltip_text_; 182 *tooltip = toggled_tooltip_text_;
171 return true; 183 return true;
172 } 184 }
173 185
174 } // namespace views 186 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/controls/button/image_button.h ('k') | ui/views/controls/button/image_button_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698