OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "ui/views/controls/button/border_images.h" |
| 6 |
| 7 #include "base/logging.h" |
| 8 #include "grit/ui_resources.h" |
| 9 #include "ui/base/resource/resource_bundle.h" |
| 10 #include "ui/gfx/canvas.h" |
| 11 #include "ui/gfx/rect.h" |
| 12 |
| 13 #define BORDER_IMAGES(x) x ## _TOP_LEFT, x ## _TOP, x ## _TOP_RIGHT, \ |
| 14 x ## _LEFT, x ## _CENTER, x ## _RIGHT, \ |
| 15 x ## _BOTTOM_LEFT, x ## _BOTTOM, x ## _BOTTOM_RIGHT, |
| 16 |
| 17 namespace views { |
| 18 |
| 19 // static |
| 20 const int BorderImages::kHot[] = { BORDER_IMAGES(IDR_TEXTBUTTON_HOVER) }; |
| 21 // static |
| 22 const int BorderImages::kPushed[] = { BORDER_IMAGES(IDR_TEXTBUTTON_PRESSED) }; |
| 23 |
| 24 BorderImages::BorderImages() {} |
| 25 |
| 26 BorderImages::BorderImages(const int image_ids[]) { |
| 27 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
| 28 top_left = *rb.GetImageSkiaNamed(image_ids[0]); |
| 29 top = *rb.GetImageSkiaNamed(image_ids[1]); |
| 30 top_right = *rb.GetImageSkiaNamed(image_ids[2]); |
| 31 left = *rb.GetImageSkiaNamed(image_ids[3]); |
| 32 center = *rb.GetImageSkiaNamed(image_ids[4]); |
| 33 right = *rb.GetImageSkiaNamed(image_ids[5]); |
| 34 bottom_left = *rb.GetImageSkiaNamed(image_ids[6]); |
| 35 bottom = *rb.GetImageSkiaNamed(image_ids[7]); |
| 36 bottom_right = *rb.GetImageSkiaNamed(image_ids[8]); |
| 37 } |
| 38 |
| 39 BorderImages::~BorderImages() {} |
| 40 |
| 41 void BorderImages::Paint(const gfx::Rect& rect, gfx::Canvas* canvas) const { |
| 42 DCHECK(!top_left.isNull()); |
| 43 |
| 44 // Images must share widths by column and heights by row as depicted below. |
| 45 // x0 x1 x2 x3 |
| 46 // y0__|____|____|____| |
| 47 // y1__|_tl_|_t__|_tr_| |
| 48 // y2__|_l__|_c__|_r__| |
| 49 // y3__|_bl_|_b__|_br_| |
| 50 const int x[] = { rect.x(), rect.x() + top_left.width(), |
| 51 rect.right() - top_right.width(), rect.right() }; |
| 52 const int y[] = { rect.y(), rect.y() + top_left.height(), |
| 53 rect.bottom() - bottom_left.height(), rect.bottom() }; |
| 54 |
| 55 canvas->DrawImageInt(top_left, x[0], y[0]); |
| 56 canvas->TileImageInt(top, x[1], y[0], x[2] - x[1], y[1] - y[0]); |
| 57 canvas->DrawImageInt(top_right, x[2], y[0]); |
| 58 canvas->TileImageInt(left, x[0], y[1], x[1] - x[0], y[2] - y[1]); |
| 59 canvas->DrawImageInt(center, 0, 0, center.width(), center.height(), |
| 60 x[1], y[1], x[2] - x[1], y[2] - y[1], false); |
| 61 canvas->TileImageInt(right, x[2], y[1], x[3] - x[2], y[2] - y[1]); |
| 62 canvas->DrawImageInt(bottom_left, 0, y[2]); |
| 63 canvas->TileImageInt(bottom, x[1], y[2], x[2] - x[1], y[3] - y[2]); |
| 64 canvas->DrawImageInt(bottom_right, x[2], y[2]); |
| 65 } |
| 66 |
| 67 } // namespace views |
OLD | NEW |