From d6613e07153a598135199de93d00e9cc7ae2349e Mon Sep 17 00:00:00 2001 From: Louis Moureaux Date: Sat, 11 Sep 2021 20:15:19 +0200 Subject: [PATCH] Show how sprites combine within layers in the debugger This allows one to understand better what the layers are made of and how they works. See #632. --- client/gui-qt/tileset_debugger.cpp | 37 +++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/client/gui-qt/tileset_debugger.cpp b/client/gui-qt/tileset_debugger.cpp index 0bda0215ac..d5294269e0 100644 --- a/client/gui-qt/tileset_debugger.cpp +++ b/client/gui-qt/tileset_debugger.cpp @@ -26,6 +26,7 @@ #include "fcintl.h" #include +#include #include #include #include @@ -111,10 +112,44 @@ void tileset_debugger::set_tile(const ::tile *t) const auto sprites = layer->fill_sprite_array(t, nullptr, nullptr, unit, tile_city(t), nullptr); + if (sprites.empty()) { + continue; + } + + // Generate a sprite with this layer only + // Geometry + auto rectangle = QRect(); + for (const auto &ds : sprites) { + rectangle |= QRect(ds.offset_x, ds.offset_y, ds.sprite->width(), + ds.sprite->height()); + } + + // Draw the composite picture + auto this_layer = QPixmap(rectangle.size()); + this_layer.fill(Qt::transparent); + auto p = QPainter(); + p.begin(&this_layer); + // If there are negative offsets, the pixmap was extended in the negative + // direction. Compensate by offsetting the painter back... + p.translate(-rectangle.topLeft()); + for (const auto &ds : sprites) { + p.drawPixmap(ds.offset_x, ds.offset_y, *ds.sprite); + } + p.end(); + item->setIcon(0, QIcon(this_layer)); + // Add the sprites as children for (const auto &ds : sprites) { auto child = new QTreeWidgetItem(item); - child->setIcon(0, QIcon(*ds.sprite)); + auto this_sprite = QPixmap(rectangle.size()); + this_sprite.fill(Qt::transparent); + p.begin(&this_sprite); + // We inherit the translation set above + p.drawPixmap(ds.offset_x, ds.offset_y, *ds.sprite); + p.end(); + child->setIcon(0, QIcon(this_sprite)); + child->setText( + 0, QString(_("Offset: %1, %2")).arg(ds.offset_x).arg(ds.offset_y)); maxSize = maxSize.expandedTo(ds.sprite->size()); } }