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

Unified Diff: chrome/browser/gtk/nine_box.cc

Issue 524025: Alter NineBox so that it can accept a single sprite resource with insets that... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 12 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
« no previous file with comments | « chrome/browser/gtk/nine_box.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/gtk/nine_box.cc
===================================================================
--- chrome/browser/gtk/nine_box.cc (revision 35462)
+++ chrome/browser/gtk/nine_box.cc (working copy)
@@ -32,7 +32,8 @@
} // namespace
NineBox::NineBox(int top_left, int top, int top_right, int left, int center,
- int right, int bottom_left, int bottom, int bottom_right) {
+ int right, int bottom_left, int bottom, int bottom_right)
+ : unref_pixbufs_on_destroy_(false) {
ResourceBundle& rb = ResourceBundle::GetSharedInstance();
images_[0] = top_left ? rb.GetPixbufNamed(top_left) : NULL;
images_[1] = top ? rb.GetPixbufNamed(top) : NULL;
@@ -45,7 +46,45 @@
images_[8] = bottom_right ? rb.GetPixbufNamed(bottom_right) : NULL;
}
+NineBox::NineBox(int image, int top_margin, int bottom_margin, int left_margin,
+ int right_margin)
+ : unref_pixbufs_on_destroy_(true) {
+ ResourceBundle& rb = ResourceBundle::GetSharedInstance();
+ GdkPixbuf* pixbuf = rb.GetPixbufNamed(image);
+ int width = gdk_pixbuf_get_width(pixbuf);
+ int height = gdk_pixbuf_get_height(pixbuf);
+ int inset_width = left_margin + right_margin;
+ int inset_height = top_margin + bottom_margin;
+
+ images_[0] = gdk_pixbuf_new_subpixbuf(pixbuf, 0, 0, left_margin, top_margin);
+ images_[1] = gdk_pixbuf_new_subpixbuf(pixbuf, left_margin, 0,
+ width - inset_width, top_margin);
+ images_[2] = gdk_pixbuf_new_subpixbuf(pixbuf, width - right_margin, 0,
+ right_margin, top_margin);
+ images_[3] = gdk_pixbuf_new_subpixbuf(pixbuf, 0, top_margin,
+ left_margin, height - inset_height);
+ images_[4] = gdk_pixbuf_new_subpixbuf(pixbuf, left_margin, top_margin,
+ width - inset_width,
+ height - inset_height);
+ images_[5] = gdk_pixbuf_new_subpixbuf(pixbuf, width - right_margin,
+ top_margin, right_margin,
+ height - inset_height);
+ images_[6] = gdk_pixbuf_new_subpixbuf(pixbuf, 0, height - bottom_margin,
+ left_margin, bottom_margin);
+ images_[7] = gdk_pixbuf_new_subpixbuf(pixbuf, left_margin,
+ height - bottom_margin,
+ width - inset_width, bottom_margin);
+ images_[8] = gdk_pixbuf_new_subpixbuf(pixbuf, width - right_margin,
+ height - bottom_margin,
+ right_margin, bottom_margin);
+}
+
NineBox::~NineBox() {
+ if (unref_pixbufs_on_destroy_) {
+ for (int i = 0; i < 9; i++) {
+ g_object_unref(images_[i]);
+ }
+ }
}
void NineBox::RenderToWidget(GtkWidget* dst) const {
« no previous file with comments | « chrome/browser/gtk/nine_box.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698