| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "chrome/browser/gtk/nine_box.h" | 5 #include "chrome/browser/gtk/nine_box.h" |
| 6 | 6 |
| 7 #include "base/gfx/gtk_util.h" | 7 #include "base/gfx/gtk_util.h" |
| 8 #include "base/gfx/point.h" | 8 #include "base/gfx/point.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 | 10 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 const int x1 = gdk_pixbuf_get_width(images[0]); | 61 const int x1 = gdk_pixbuf_get_width(images[0]); |
| 62 const int y1 = gdk_pixbuf_get_height(images[0]); | 62 const int y1 = gdk_pixbuf_get_height(images[0]); |
| 63 const int x2 = images[2] ? dst_width - gdk_pixbuf_get_width(images[2]) : x1; | 63 const int x2 = images[2] ? dst_width - gdk_pixbuf_get_width(images[2]) : x1; |
| 64 const int y2 = images[6] ? dst_height - gdk_pixbuf_get_height(images[6]) : y1; | 64 const int y2 = images[6] ? dst_height - gdk_pixbuf_get_height(images[6]) : y1; |
| 65 DCHECK(x2 >= x1); | 65 DCHECK(x2 >= x1); |
| 66 DCHECK(y2 >= y1); | 66 DCHECK(y2 >= y1); |
| 67 | 67 |
| 68 if (images[0]) | 68 if (images[0]) |
| 69 DrawPixbuf(dst, images[0], 0, 0); | 69 DrawPixbuf(dst, images[0], 0, 0); |
| 70 if (images[1]) | 70 if (images[1]) |
| 71 RenderTopCenterStrip(dst, x1, x2); | 71 RenderTopCenterStrip(dst, x1, x2, 0); |
| 72 if (images[2]) | 72 if (images[2]) |
| 73 DrawPixbuf(dst, images[2], x2, 0); | 73 DrawPixbuf(dst, images[2], x2, 0); |
| 74 | 74 |
| 75 // Center row. Needs vertical tiling. | 75 // Center row. Needs vertical tiling. |
| 76 images = &images_[1 * 3]; | 76 images = &images_[1 * 3]; |
| 77 if (images[0]) { | 77 if (images[0]) { |
| 78 TileImage(dst, images[0], | 78 TileImage(dst, images[0], |
| 79 0, y1, | 79 0, y1, |
| 80 0, y2); | 80 0, y2); |
| 81 } | 81 } |
| (...skipping 17 matching lines...) Expand all Loading... |
| 99 DrawPixbuf(dst, images[0], 0, y2); | 99 DrawPixbuf(dst, images[0], 0, y2); |
| 100 if (images[1]) { | 100 if (images[1]) { |
| 101 TileImage(dst, images[1], | 101 TileImage(dst, images[1], |
| 102 x1, y2, | 102 x1, y2, |
| 103 x2, y2); | 103 x2, y2); |
| 104 } | 104 } |
| 105 if (images[2]) | 105 if (images[2]) |
| 106 DrawPixbuf(dst, images[2], x2, y2); | 106 DrawPixbuf(dst, images[2], x2, y2); |
| 107 } | 107 } |
| 108 | 108 |
| 109 void NineBox::RenderTopCenterStrip(GtkWidget* dst, int x1, int x2) { | 109 void NineBox::RenderTopCenterStrip(GtkWidget* dst, int x1, int x2, int y1) { |
| 110 TileImage(dst, images_[1], | 110 TileImage(dst, images_[1], |
| 111 x1, 0, | 111 x1, y1, |
| 112 x2, 0); | 112 x2, y1); |
| 113 } | 113 } |
| 114 | 114 |
| 115 void NineBox::TileImage(GtkWidget* dst, GdkPixbuf* src, | 115 void NineBox::TileImage(GtkWidget* dst, GdkPixbuf* src, |
| 116 int x1, int y1, int x2, int y2) { | 116 int x1, int y1, int x2, int y2) { |
| 117 GdkGC* gc = dst->style->fg_gc[GTK_WIDGET_STATE(dst)]; | 117 GdkGC* gc = dst->style->fg_gc[GTK_WIDGET_STATE(dst)]; |
| 118 const int src_width = gdk_pixbuf_get_width(src); | 118 const int src_width = gdk_pixbuf_get_width(src); |
| 119 const int src_height = gdk_pixbuf_get_height(src); | 119 const int src_height = gdk_pixbuf_get_height(src); |
| 120 const int dst_width = dst->allocation.width; | 120 const int dst_width = dst->allocation.width; |
| 121 const int dst_height = dst->allocation.height; | 121 const int dst_height = dst->allocation.height; |
| 122 | 122 |
| 123 gfx::Point offset = GetWindowRelativeCoords(dst); | 123 gfx::Point offset = GetWindowRelativeCoords(dst); |
| 124 | 124 |
| 125 // We only tile along one axis (see above TODO about nuking all this code), | 125 // We only tile along one axis (see above TODO about nuking all this code), |
| 126 // dx or dy will be nonzero along that axis. | 126 // dx or dy will be nonzero along that axis. |
| 127 int dx = 0, dy = 0; | 127 int dx = 0, dy = 0; |
| 128 if (x2 > x1) | 128 if (x2 > x1) |
| 129 dx = src_width; | 129 dx = src_width; |
| 130 if (y2 > y1) | 130 if (y2 > y1) |
| 131 dy = src_height; | 131 dy = src_height; |
| 132 DCHECK(dx == 0 || dy == 0); | 132 DCHECK(dx == 0 || dy == 0); |
| 133 | 133 |
| 134 for (int x = x1, y = y1; x < x2 || y < y2; x += dx, y += dy) { | 134 for (int x = x1, y = y1; x < x2 || y < y2; x += dx, y += dy) { |
| 135 gdk_draw_pixbuf(dst->window, gc, src, 0, 0, | 135 gdk_draw_pixbuf(dst->window, gc, src, 0, 0, |
| 136 offset.x() + x, offset.y() + y, | 136 offset.x() + x, offset.y() + y, |
| 137 dx ? std::min(src_width, dst_width - x) : src_width, | 137 dx ? std::min(src_width, dst_width - x) : src_width, |
| 138 dy ? std::min(src_height, dst_height - y) : src_height, | 138 dy ? std::min(src_height, dst_height - y) : src_height, |
| 139 GDK_RGB_DITHER_NONE, 0, 0); | 139 GDK_RGB_DITHER_NONE, 0, 0); |
| 140 } | 140 } |
| 141 } | 141 } |
| OLD | NEW |