From b0967158a99adb94e4a04299bf6853ae16ffe21e Mon Sep 17 00:00:00 2001 From: Johannes Winkler Date: Sat, 8 Jun 2024 15:18:47 +0200 Subject: [PATCH] Show Sprite Numbers --- mainwindow.cpp | 4 + mainwindow.ui | 377 +++++++++++++++++++++++++------------------------ sprite.cpp | 13 ++ sprite.h | 1 + 4 files changed, 210 insertions(+), 185 deletions(-) diff --git a/mainwindow.cpp b/mainwindow.cpp index f03948b..430d750 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -332,6 +332,10 @@ MainWindow::MainWindow(QWidget *parent) this->opt.show_grid_lines = val; this->ui->graphicsView->scene()->update(); }); + connect(this->ui->check_sprite_numbers, &QCheckBox::toggled, [=](bool val) { + this->opt.show_numbers = val; + this->ui->graphicsView->scene()->update(); + }); connect(this->ui->spin_horizontal_spacing, &QSpinBox::valueChanged, [=](int val) { this->opt.sprite_spacing_x = val; this->ui->graphicsView->redraw(); diff --git a/mainwindow.ui b/mainwindow.ui index ac750c9..30bb1d7 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -48,12 +48,25 @@ Options - - - - Multicolor - - + + + + + + + 0 + 0 + + + + true + + + + + + + @@ -62,47 +75,158 @@ - - + + - Show editor grid lines - - - true + Expand X - - - - + + + + - + 0 0 - - true + + Horizontal Spacing: + + + + + + + + 0 + 0 + - + Vertical Spacing: + + + + + + + 1 + + + 4 + + + + + + + Choose Color + + + + + + + + 0 + 0 + + + + Show Sprites per Line + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 0 + 0 + + + + 100 + + + 30 + + + + + + + + 0 + 0 + + + + 100 + + + 30 + + + + + + + + 0 + 0 + + + + Spacing Color: + + + + + + + + 0 + 0 + + + + Selection Color: + + + + + + + Choose Color - - + + - Selecting an animation select it's images + Show editor grid lines - - - - - - Overlay next sprite + + true @@ -113,10 +237,20 @@ - - + + - Expand X + Selecting an animation select it's images + + + + + + + Automatically set overlays to single color + + + true @@ -502,7 +636,28 @@ - + + + + Scale: + + + + + + + Overlay next sprite + + + + + + + Multicolor + + + + 500 @@ -515,152 +670,7 @@ - - - - Scale: - - - - - - - - - - 0 - 0 - - - - Horizontal Spacing: - - - - - - - - 0 - 0 - - - - Vertical Spacing: - - - - - - - 1 - - - 4 - - - - - - - Choose Color - - - - - - - - 0 - 0 - - - - Show Sprites per Line - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - 0 - 0 - - - - 100 - - - 30 - - - - - - - - 0 - 0 - - - - 100 - - - 30 - - - - - - - - 0 - 0 - - - - Spacing Color: - - - - - - - - 0 - 0 - - - - Selection Color: - - - - - - - Choose Color - - - - - - + Qt::Vertical @@ -673,13 +683,10 @@ - - + + - Automatically set overlays to single color - - - true + Show Sprite Numbers diff --git a/sprite.cpp b/sprite.cpp index 6fa6115..0c00287 100644 --- a/sprite.cpp +++ b/sprite.cpp @@ -132,6 +132,19 @@ void Sprite::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QW } + if (opt->show_numbers) + { + + int w = 10 * (expand_y ? 0.5 : 1); + int h = 10 * (expand_x ? 0.5 : 1); + + QFont font = painter->font(); + font.setPixelSize(qMin(0.8*24*w, 0.8*21*h)); + painter->setFont(font); + painter->drawText(0,0,24*w,21*h, Qt::AlignVCenter | Qt::AlignHCenter, QString::number(id)); + } + + if (id >= opt->selection_from && id <= opt->selection_to) { QPen pen; diff --git a/sprite.h b/sprite.h index 4945033..da2f652 100644 --- a/sprite.h +++ b/sprite.h @@ -26,6 +26,7 @@ struct options { QList sprite_list; SpriteView *spriteview; bool show_grid_lines = true; + bool show_numbers = false; int sprite_spacing_x = 30; int sprite_spacing_y = 30; int sprites_per_row = 4;