summaryrefslogtreecommitdiff
path: root/src/object_gui.cpp
diff options
context:
space:
mode:
authorfrosch <frosch@openttd.org>2012-05-28 13:44:55 +0000
committerfrosch <frosch@openttd.org>2012-05-28 13:44:55 +0000
commit1f3227eb69c5cfca354136fde9ed20febc873519 (patch)
tree601f23b73b6c52c6937d85a5e1eefbab790d6c67 /src/object_gui.cpp
parentf9df5f65c7e3708196627b0bc29bdf4cf938fa44 (diff)
downloadopenttd-1f3227eb69c5cfca354136fde9ed20febc873519.tar.xz
(svn r24299) -Change [FS#5057]: Center object previews in 1- and 2-view selectors based on the 4-view selector layout.
Diffstat (limited to 'src/object_gui.cpp')
-rw-r--r--src/object_gui.cpp11
1 files changed, 9 insertions, 2 deletions
diff --git a/src/object_gui.cpp b/src/object_gui.cpp
index d8d82af26..646cc230f 100644
--- a/src/object_gui.cpp
+++ b/src/object_gui.cpp
@@ -181,6 +181,13 @@ public:
const ObjectSpec *spec = ObjectClass::Get(_selected_object_class)->GetSpec(_selected_object_index);
if (spec == NULL) break;
+ /* Height of the selection matrix.
+ * Depending on the number of views, the matrix has a 1x1, 1x2, 2x1 or 2x2 layout. To make the previews
+ * look nice in all layouts, we use the 4x4 layout (smallest previews) as starting point. For the bigger
+ * previews in the layouts with less views we add space homogenously on all sides, so the 4x4 preview-rectangle
+ * is centered in the 2x1, 1x2 resp. 1x1 buttons. */
+ uint matrix_height = this->GetWidget<NWidgetMatrix>(WID_BO_OBJECT_MATRIX)->current_y;
+
DrawPixelInfo tmp_dpi;
/* Set up a clipping area for the preview. */
if (FillDrawPixelInfo(&tmp_dpi, r.left, r.top, r.right - r.left + 1, r.bottom - r.top + 1)) {
@@ -189,9 +196,9 @@ public:
if (spec->grf_prop.grffile == NULL) {
extern const DrawTileSprites _objects[];
const DrawTileSprites *dts = &_objects[spec->grf_prop.local_id];
- DrawOrigTileSeqInGUI((r.right - r.left) / 2 - 1, r.bottom - r.top - OBJECT_MARGIN - TILE_PIXELS, dts, PAL_NONE);
+ DrawOrigTileSeqInGUI((r.right - r.left) / 2 - 1, (r.bottom - r.top + matrix_height / 2) / 2 - OBJECT_MARGIN - TILE_PIXELS, dts, PAL_NONE);
} else {
- DrawNewObjectTileInGUI((r.right - r.left) / 2 - 1, r.bottom - r.top - OBJECT_MARGIN - TILE_PIXELS, spec, GB(widget, 16, 16));
+ DrawNewObjectTileInGUI((r.right - r.left) / 2 - 1, (r.bottom - r.top + matrix_height / 2) / 2 - OBJECT_MARGIN - TILE_PIXELS, spec, GB(widget, 16, 16));
}
_cur_dpi = old_dpi;
}