mirror of https://github.com/mgba-emu/mgba.git
Qt: Tile viewer improvements, magnification
This commit is contained in:
parent
f491196bc4
commit
0241952133
|
@ -13,10 +13,12 @@ using namespace QGBA;
|
|||
|
||||
TilePainter::TilePainter(QWidget* parent)
|
||||
: QWidget(parent)
|
||||
, m_size(8)
|
||||
{
|
||||
m_backing = QPixmap(256, 768);
|
||||
m_backing.fill(Qt::transparent);
|
||||
resize(256, 768);
|
||||
setTileCount(3072);
|
||||
}
|
||||
|
||||
void TilePainter::paintEvent(QPaintEvent* event) {
|
||||
|
@ -25,30 +27,37 @@ void TilePainter::paintEvent(QPaintEvent* event) {
|
|||
}
|
||||
|
||||
void TilePainter::resizeEvent(QResizeEvent* event) {
|
||||
if (width() / 8 != m_backing.width() / 8) {
|
||||
m_backing = QPixmap(width(), (3072 * 8) / (width() / 8));
|
||||
int calculatedHeight = (m_tileCount * m_size) / (width() / m_size) + m_size / 2;
|
||||
if (width() / m_size != m_backing.width() / m_size || m_backing.height() != calculatedHeight) {
|
||||
m_backing = QPixmap(width(), calculatedHeight);
|
||||
m_backing.fill(Qt::transparent);
|
||||
}
|
||||
}
|
||||
|
||||
void TilePainter::mousePressEvent(QMouseEvent* event) {
|
||||
int x = event->x() / 8;
|
||||
int y = event->y() / 8;
|
||||
emit indexPressed(y * (width() / 8) + x);
|
||||
int x = event->x() / m_size;
|
||||
int y = event->y() / m_size;
|
||||
emit indexPressed(y * (width() / m_size) + x);
|
||||
}
|
||||
|
||||
void TilePainter::setTile(int index, const uint16_t* data) {
|
||||
QPainter painter(&m_backing);
|
||||
int w = width() / 8;
|
||||
int w = width() / m_size;
|
||||
int x = index % w;
|
||||
int y = index / w;
|
||||
QRect r(x * 8, y * 8, 8, 8);
|
||||
QRect r(x * m_size, y * m_size, m_size, m_size);
|
||||
QImage tile(reinterpret_cast<const uchar*>(data), 8, 8, QImage::Format_RGB555);
|
||||
painter.fillRect(r, tile.rgbSwapped());
|
||||
painter.drawImage(r, tile.rgbSwapped());
|
||||
update(r);
|
||||
}
|
||||
|
||||
void TilePainter::setTileCount(int tiles) {
|
||||
setMinimumSize(16, (tiles * 8) / (width() / 8));
|
||||
m_tileCount = tiles;
|
||||
setMinimumSize(16, (tiles * m_size) / (width() / m_size));
|
||||
resizeEvent(nullptr);
|
||||
}
|
||||
|
||||
void TilePainter::setTileMagnification(int mag) {
|
||||
m_size = mag * 8;
|
||||
setTileCount(m_tileCount);
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@ public:
|
|||
public slots:
|
||||
void setTile(int index, const uint16_t*);
|
||||
void setTileCount(int tiles);
|
||||
void setTileMagnification(int mag);
|
||||
|
||||
signals:
|
||||
void indexPressed(int index);
|
||||
|
@ -32,6 +33,8 @@ protected:
|
|||
|
||||
private:
|
||||
QPixmap m_backing;
|
||||
int m_size;
|
||||
int m_tileCount;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@ TileView::TileView(GameController* controller, QWidget* parent)
|
|||
|
||||
m_ui.preview->setDimensions(QSize(8, 8));
|
||||
m_updateTimer.setSingleShot(true);
|
||||
m_updateTimer.setInterval(10);
|
||||
m_updateTimer.setInterval(1);
|
||||
connect(&m_updateTimer, SIGNAL(timeout()), this, SLOT(updateTiles()));
|
||||
|
||||
const QFont font = QFontDatabase::systemFont(QFontDatabase::FixedFont);
|
||||
|
@ -38,7 +38,12 @@ TileView::TileView(GameController* controller, QWidget* parent)
|
|||
connect(m_controller, SIGNAL(gameStopped(mCoreThread*)), this, SLOT(close()));
|
||||
connect(m_ui.tiles, SIGNAL(indexPressed(int)), this, SLOT(selectIndex(int)));
|
||||
connect(m_ui.paletteId, SIGNAL(valueChanged(int)), this, SLOT(updatePalette(int)));
|
||||
connect(m_ui.palette256, SIGNAL(toggled(bool)), this, SLOT(updateTiles()));
|
||||
connect(m_ui.palette256, &QAbstractButton::toggled, [this]() {
|
||||
updateTiles(true);
|
||||
});
|
||||
connect(m_ui.magnification, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), [this]() {
|
||||
updateTiles(true);
|
||||
});
|
||||
}
|
||||
|
||||
TileView::~TileView() {
|
||||
|
@ -131,5 +136,5 @@ void TileView::resizeEvent(QResizeEvent*) {
|
|||
}
|
||||
|
||||
void TileView::showEvent(QShowEvent*) {
|
||||
m_updateTimer.start();
|
||||
updateTiles(true);
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<item row="3" column="0">
|
||||
<widget class="QGroupBox" name="groupBox">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
|
||||
|
@ -116,7 +116,7 @@
|
|||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<item row="4" column="0">
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
|
@ -129,7 +129,7 @@
|
|||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="0" column="1" rowspan="4">
|
||||
<item row="0" column="1" rowspan="5">
|
||||
<widget class="QScrollArea" name="scrollArea">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Minimum" vsizetype="Expanding">
|
||||
|
@ -145,7 +145,7 @@
|
|||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>271</width>
|
||||
<width>290</width>
|
||||
<height>768</height>
|
||||
</rect>
|
||||
</property>
|
||||
|
@ -185,6 +185,36 @@
|
|||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_4">
|
||||
<item>
|
||||
<widget class="QSpinBox" name="magnification">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="suffix">
|
||||
<string>×</string>
|
||||
</property>
|
||||
<property name="minimum">
|
||||
<number>1</number>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<number>4</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>Magnification</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
|
@ -193,6 +223,9 @@
|
|||
<extends>QWidget</extends>
|
||||
<header>TilePainter.h</header>
|
||||
<container>1</container>
|
||||
<slots>
|
||||
<slot>setTileMagnification(int)</slot>
|
||||
</slots>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>QGBA::Swatch</class>
|
||||
|
@ -219,5 +252,21 @@
|
|||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>magnification</sender>
|
||||
<signal>valueChanged(int)</signal>
|
||||
<receiver>tiles</receiver>
|
||||
<slot>setTileMagnification(int)</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>36</x>
|
||||
<y>83</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>339</x>
|
||||
<y>396</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
</ui>
|
||||
|
|
Loading…
Reference in New Issue