Chromium Code Reviews| 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, | |
|
Peter Kasting
2012/10/25 23:56:38
Nit: If we're using this macro in multiple files,
msw
2012/10/27 07:40:57
The macros differ with the IDR naming schemes, but
| |
| 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->DrawImageInt(top, 0, 0, top.width(), top.height(), | |
|
Peter Kasting
2012/10/25 23:56:38
Maybe the t/l/c/r/b images should be TileImageInt
msw
2012/10/27 07:40:57
Done for t/l/r/b, but scaling center makes more se
| |
| 57 x[1], y[0], x[2] - x[1], y[1] - y[0], false); | |
| 58 canvas->DrawImageInt(top_right, x[2], y[0]); | |
| 59 canvas->DrawImageInt(left, 0, 0, left.width(), left.height(), | |
| 60 x[0], y[1], x[1] - x[0], y[2] - y[1], false); | |
| 61 canvas->DrawImageInt(center, 0, 0, center.width(), center.height(), | |
| 62 x[1], y[1], x[2] - x[1], y[2] - y[1], false); | |
| 63 canvas->DrawImageInt(right, 0, 0, right.width(), right.height(), | |
| 64 x[2], y[1], x[3] - x[2], y[2] - y[1], false); | |
| 65 canvas->DrawImageInt(bottom_left, 0, y[2]); | |
| 66 canvas->DrawImageInt(bottom, 0, 0, bottom.width(), bottom.height(), | |
| 67 x[1], y[2], x[2] - x[1], y[3] - y[2], false); | |
| 68 canvas->DrawImageInt(bottom_right, x[2], y[2]); | |
| 69 } | |
| 70 | |
| 71 } // namespace views | |
| OLD | NEW |