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 #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/image/image_skia_operations.h" | 10 #include "ui/gfx/image/image_skia_operations.h" |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 //////////////////////////////////////////////////////////////////////////////// | 67 //////////////////////////////////////////////////////////////////////////////// |
68 // ImageButton, View overrides: | 68 // ImageButton, View overrides: |
69 | 69 |
70 gfx::Size ImageButton::GetPreferredSize() { | 70 gfx::Size ImageButton::GetPreferredSize() { |
71 if (!images_[STATE_NORMAL].isNull()) { | 71 if (!images_[STATE_NORMAL].isNull()) { |
72 return gfx::Size(images_[STATE_NORMAL].width(), | 72 return gfx::Size(images_[STATE_NORMAL].width(), |
73 images_[STATE_NORMAL].height()); | 73 images_[STATE_NORMAL].height()); |
74 } | 74 } |
75 return preferred_size_; | 75 return preferred_size_; |
76 } | 76 } |
| 77 static float GetScaleFactor() { |
| 78 switch (ui::GetMaxScaleFactor()) { |
| 79 case ui::SCALE_FACTOR_140P: |
| 80 return 1.4f; |
| 81 case ui::SCALE_FACTOR_180P: |
| 82 return 1.8f; |
| 83 } |
| 84 return 1.0f; |
| 85 } |
77 | 86 |
78 void ImageButton::OnPaint(gfx::Canvas* canvas) { | 87 void ImageButton::OnPaint(gfx::Canvas* canvas) { |
79 // Call the base class first to paint any background/borders. | 88 // Call the base class first to paint any background/borders. |
80 View::OnPaint(canvas); | 89 View::OnPaint(canvas); |
81 | 90 |
82 gfx::ImageSkia img = GetImageToPaint(); | 91 gfx::ImageSkia img = GetImageToPaint(); |
83 | 92 |
84 if (!img.isNull()) { | 93 if (!img.isNull()) { |
85 gfx::Point position = ComputeImagePaintPosition(img); | 94 gfx::Point position = ComputeImagePaintPosition(img); |
| 95 static float scale = GetScaleFactor(); |
| 96 scale = 1; |
| 97 // TODO: store and reset the transform.... this implementation will accumula
te errors. |
| 98 canvas->Scale( scale, scale); |
86 if (!background_image_.isNull()) | 99 if (!background_image_.isNull()) |
87 canvas->DrawImageInt(background_image_, position.x(), position.y()); | 100 canvas->DrawImageInt(background_image_, position.x(), position.y()); |
88 | 101 |
89 canvas->DrawImageInt(img, position.x(), position.y()); | 102 canvas->DrawImageInt(img, 0, 0);//position.x(), position.y()); |
90 | 103 |
91 if (!overlay_image_.isNull()) | 104 if (!overlay_image_.isNull()) |
92 canvas->DrawImageInt(overlay_image_, position.x(), position.y()); | 105 canvas->DrawImageInt(overlay_image_, position.x(), position.y()); |
| 106 canvas->Scale( 1/scale, 1/scale); |
93 } | 107 } |
94 OnPaintFocusBorder(canvas); | 108 OnPaintFocusBorder(canvas); |
95 } | 109 } |
96 | 110 |
97 //////////////////////////////////////////////////////////////////////////////// | 111 //////////////////////////////////////////////////////////////////////////////// |
98 // ImageButton, protected: | 112 // ImageButton, protected: |
99 | 113 |
100 gfx::ImageSkia ImageButton::GetImageToPaint() { | 114 gfx::ImageSkia ImageButton::GetImageToPaint() { |
101 gfx::ImageSkia img; | 115 gfx::ImageSkia img; |
102 | 116 |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 bool ToggleImageButton::GetTooltipText(const gfx::Point& p, | 207 bool ToggleImageButton::GetTooltipText(const gfx::Point& p, |
194 string16* tooltip) const { | 208 string16* tooltip) const { |
195 if (!toggled_ || toggled_tooltip_text_.empty()) | 209 if (!toggled_ || toggled_tooltip_text_.empty()) |
196 return Button::GetTooltipText(p, tooltip); | 210 return Button::GetTooltipText(p, tooltip); |
197 | 211 |
198 *tooltip = toggled_tooltip_text_; | 212 *tooltip = toggled_tooltip_text_; |
199 return true; | 213 return true; |
200 } | 214 } |
201 | 215 |
202 } // namespace views | 216 } // namespace views |
OLD | NEW |