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

Unified Diff: ui/views/controls/button/border_images.cc

Issue 11262002: Merge TextButton and LabelButton border images util structs, etc. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rename BorderImages and const image id arrays, etc. Created 8 years, 2 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 side-by-side diff with in-line comments
Download patch
Index: ui/views/controls/button/border_images.cc
diff --git a/ui/views/controls/button/border_images.cc b/ui/views/controls/button/border_images.cc
new file mode 100644
index 0000000000000000000000000000000000000000..e53dd62d11b3468423bafe42db37ec50f16d124b
--- /dev/null
+++ b/ui/views/controls/button/border_images.cc
@@ -0,0 +1,71 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ui/views/controls/button/border_images.h"
+
+#include "base/logging.h"
+#include "grit/ui_resources.h"
+#include "ui/base/resource/resource_bundle.h"
+#include "ui/gfx/canvas.h"
+#include "ui/gfx/rect.h"
+
+#define BORDER_IMAGES(x) x ## _TOP_LEFT, x ## _TOP, x ## _TOP_RIGHT, \
+ x ## _LEFT, x ## _CENTER, x ## _RIGHT, \
+ 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
+
+namespace views {
+
+// static
+const int BorderImages::kHot[] = { BORDER_IMAGES(IDR_TEXTBUTTON_HOVER) };
+// static
+const int BorderImages::kPushed[] = { BORDER_IMAGES(IDR_TEXTBUTTON_PRESSED) };
+
+BorderImages::BorderImages() {}
+
+BorderImages::BorderImages(const int image_ids[]) {
+ ResourceBundle& rb = ResourceBundle::GetSharedInstance();
+ top_left = *rb.GetImageSkiaNamed(image_ids[0]);
+ top = *rb.GetImageSkiaNamed(image_ids[1]);
+ top_right = *rb.GetImageSkiaNamed(image_ids[2]);
+ left = *rb.GetImageSkiaNamed(image_ids[3]);
+ center = *rb.GetImageSkiaNamed(image_ids[4]);
+ right = *rb.GetImageSkiaNamed(image_ids[5]);
+ bottom_left = *rb.GetImageSkiaNamed(image_ids[6]);
+ bottom = *rb.GetImageSkiaNamed(image_ids[7]);
+ bottom_right = *rb.GetImageSkiaNamed(image_ids[8]);
+}
+
+BorderImages::~BorderImages() {}
+
+void BorderImages::Paint(const gfx::Rect& rect, gfx::Canvas* canvas) const {
+ DCHECK(!top_left.isNull());
+
+ // Images must share widths by column and heights by row as depicted below.
+ // x0 x1 x2 x3
+ // y0__|____|____|____|
+ // y1__|_tl_|_t__|_tr_|
+ // y2__|_l__|_c__|_r__|
+ // y3__|_bl_|_b__|_br_|
+ const int x[] = { rect.x(), rect.x() + top_left.width(),
+ rect.right() - top_right.width(), rect.right() };
+ const int y[] = { rect.y(), rect.y() + top_left.height(),
+ rect.bottom() - bottom_left.height(), rect.bottom() };
+
+ canvas->DrawImageInt(top_left, x[0], y[0]);
+ 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
+ x[1], y[0], x[2] - x[1], y[1] - y[0], false);
+ canvas->DrawImageInt(top_right, x[2], y[0]);
+ canvas->DrawImageInt(left, 0, 0, left.width(), left.height(),
+ x[0], y[1], x[1] - x[0], y[2] - y[1], false);
+ canvas->DrawImageInt(center, 0, 0, center.width(), center.height(),
+ x[1], y[1], x[2] - x[1], y[2] - y[1], false);
+ canvas->DrawImageInt(right, 0, 0, right.width(), right.height(),
+ x[2], y[1], x[3] - x[2], y[2] - y[1], false);
+ canvas->DrawImageInt(bottom_left, 0, y[2]);
+ canvas->DrawImageInt(bottom, 0, 0, bottom.width(), bottom.height(),
+ x[1], y[2], x[2] - x[1], y[3] - y[2], false);
+ canvas->DrawImageInt(bottom_right, x[2], y[2]);
+}
+
+} // namespace views

Powered by Google App Engine
This is Rietveld 408576698