mirror of https://github.com/mgba-emu/mgba.git
Qt: Very broken tile viewer resizing
This commit is contained in:
parent
b1f750e441
commit
ccf66299e6
|
@ -18,7 +18,6 @@ Swatch::Swatch(QWidget* parent)
|
|||
: QWidget(parent)
|
||||
{
|
||||
m_size = 10;
|
||||
setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
|
||||
}
|
||||
|
||||
void Swatch::setSize(int size) {
|
||||
|
|
|
@ -16,6 +16,7 @@ TilePainter::TilePainter(QWidget* parent)
|
|||
{
|
||||
m_backing = QPixmap(256, 768);
|
||||
m_backing.fill(Qt::transparent);
|
||||
resize(256, 768);
|
||||
}
|
||||
|
||||
void TilePainter::paintEvent(QPaintEvent* event) {
|
||||
|
@ -23,18 +24,31 @@ void TilePainter::paintEvent(QPaintEvent* event) {
|
|||
painter.drawPixmap(QPoint(), m_backing);
|
||||
}
|
||||
|
||||
void TilePainter::resizeEvent(QResizeEvent* event) {
|
||||
if (width() / 8 != m_backing.width() / 8) {
|
||||
m_backing = QPixmap(width(), (3072 * 8) / (width() / 8));
|
||||
m_backing.fill(Qt::transparent);
|
||||
}
|
||||
}
|
||||
|
||||
void TilePainter::mousePressEvent(QMouseEvent* event) {
|
||||
int x = event->x() / 8;
|
||||
int y = event->y() / 8;
|
||||
emit indexPressed(y * 32 + x);
|
||||
emit indexPressed(y * (width() / 8) + x);
|
||||
}
|
||||
|
||||
void TilePainter::setTile(int index, const uint16_t* data) {
|
||||
QPainter painter(&m_backing);
|
||||
int x = index & 31;
|
||||
int y = index / 32;
|
||||
int w = width() / 8;
|
||||
int x = index % w;
|
||||
int y = index / w;
|
||||
QRect r(x * 8, y * 8, 8, 8);
|
||||
QImage tile(reinterpret_cast<const uchar*>(data), 8, 8, QImage::Format_RGB555);
|
||||
painter.fillRect(r, tile.rgbSwapped());
|
||||
update(r);
|
||||
}
|
||||
|
||||
void TilePainter::setTileCount(int tiles) {
|
||||
setMinimumSize(16, (tiles * 8) / (width() / 8));
|
||||
resizeEvent(nullptr);
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@ public:
|
|||
|
||||
public slots:
|
||||
void setTile(int index, const uint16_t*);
|
||||
void setTileCount(int tiles);
|
||||
|
||||
signals:
|
||||
void indexPressed(int index);
|
||||
|
@ -27,6 +28,7 @@ signals:
|
|||
protected:
|
||||
void paintEvent(QPaintEvent*) override;
|
||||
void mousePressEvent(QMouseEvent*) override;
|
||||
void resizeEvent(QResizeEvent*) override;
|
||||
|
||||
private:
|
||||
QPixmap m_backing;
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#include "GBAApp.h"
|
||||
|
||||
#include <QFontDatabase>
|
||||
#include <QTimer>
|
||||
|
||||
extern "C" {
|
||||
#include "gba/gba.h"
|
||||
|
@ -66,7 +67,7 @@ void TileView::selectIndex(int index) {
|
|||
m_ui.preview->update();
|
||||
}
|
||||
|
||||
void TileView::updateTiles() {
|
||||
void TileView::updateTiles(bool force) {
|
||||
if (!m_controller->thread() || !m_controller->thread()->core) {
|
||||
return;
|
||||
}
|
||||
|
@ -75,31 +76,39 @@ void TileView::updateTiles() {
|
|||
GBAVideoTileCacheAssociate(&m_tileCache, &gba->video);
|
||||
|
||||
if (m_ui.palette256->isChecked()) {
|
||||
m_ui.tiles->setMinimumSize(256, 384);
|
||||
m_ui.tiles->setTileCount(1536);
|
||||
for (int i = 0; i < 1024; ++i) {
|
||||
const uint16_t* data = GBAVideoTileCacheGetTile256IfDirty(&m_tileCache, i, 0);
|
||||
if (data) {
|
||||
m_ui.tiles->setTile(i, data);
|
||||
} else if (force) {
|
||||
m_ui.tiles->setTile(i, GBAVideoTileCacheGetTile256(&m_tileCache, i, 0));
|
||||
}
|
||||
}
|
||||
for (int i = 1024; i < 1536; ++i) {
|
||||
const uint16_t* data = GBAVideoTileCacheGetTile256IfDirty(&m_tileCache, i, 1);
|
||||
if (data) {
|
||||
m_ui.tiles->setTile(i, data);
|
||||
} else if (force) {
|
||||
m_ui.tiles->setTile(i, GBAVideoTileCacheGetTile256(&m_tileCache, i, 1));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
m_ui.tiles->setMinimumSize(256, 768);
|
||||
m_ui.tiles->setTileCount(3072);
|
||||
for (int i = 0; i < 2048; ++i) {
|
||||
const uint16_t* data = GBAVideoTileCacheGetTile16IfDirty(&m_tileCache, i, m_paletteId);
|
||||
if (data) {
|
||||
m_ui.tiles->setTile(i, data);
|
||||
} else if (force) {
|
||||
m_ui.tiles->setTile(i, GBAVideoTileCacheGetTile16(&m_tileCache, i, m_paletteId));
|
||||
}
|
||||
}
|
||||
for (int i = 2048; i < 3072; ++i) {
|
||||
const uint16_t* data = GBAVideoTileCacheGetTile16IfDirty(&m_tileCache, i, m_paletteId + 16);
|
||||
if (data) {
|
||||
m_ui.tiles->setTile(i, data);
|
||||
} else if (force) {
|
||||
m_ui.tiles->setTile(i, GBAVideoTileCacheGetTile16(&m_tileCache, i, m_paletteId + 16));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -109,3 +118,14 @@ void TileView::updatePalette(int palette) {
|
|||
m_paletteId = palette;
|
||||
updateTiles();
|
||||
}
|
||||
|
||||
void TileView::resizeEvent(QResizeEvent*) {
|
||||
updateTiles(true);
|
||||
}
|
||||
|
||||
void TileView::showEvent(QShowEvent*) {
|
||||
// XXX: Figure out how to prevent the first resizeEvent
|
||||
QTimer::singleShot(10, [this]() {
|
||||
updateTiles(true);
|
||||
});
|
||||
}
|
||||
|
|
|
@ -26,12 +26,16 @@ public:
|
|||
virtual ~TileView();
|
||||
|
||||
public slots:
|
||||
void updateTiles();
|
||||
void updateTiles(bool force = false);
|
||||
void updatePalette(int);
|
||||
|
||||
private slots:
|
||||
void selectIndex(int);
|
||||
|
||||
protected:
|
||||
void resizeEvent(QResizeEvent*) override;
|
||||
void showEvent(QShowEvent*) override;
|
||||
|
||||
private:
|
||||
Ui::TileView m_ui;
|
||||
|
||||
|
|
|
@ -6,8 +6,8 @@
|
|||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>288</width>
|
||||
<height>269</height>
|
||||
<width>509</width>
|
||||
<height>265</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
|
@ -23,19 +23,22 @@
|
|||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QGroupBox" name="groupBox">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>170</width>
|
||||
<height>192</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="title">
|
||||
<string>Preview</string>
|
||||
<string/>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_3">
|
||||
<item>
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QGBA::Swatch" name="preview" native="true">
|
||||
<property name="minimumSize">
|
||||
|
@ -46,21 +49,6 @@
|
|||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_2">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
|
@ -108,6 +96,12 @@
|
|||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QSlider" name="paletteId">
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>170</width>
|
||||
<height>16777215</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<number>15</number>
|
||||
</property>
|
||||
|
@ -138,16 +132,10 @@
|
|||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>16</width>
|
||||
<height>16</height>
|
||||
<width>282</width>
|
||||
<height>768</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<property name="spacing">
|
||||
<number>0</number>
|
||||
|
@ -167,11 +155,17 @@
|
|||
<item>
|
||||
<widget class="QGBA::TilePainter" name="tiles" native="true">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
||||
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>256</width>
|
||||
<height>768</height>
|
||||
</size>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
|
@ -195,5 +189,22 @@
|
|||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources/>
|
||||
<connections/>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>palette256</sender>
|
||||
<signal>toggled(bool)</signal>
|
||||
<receiver>paletteId</receiver>
|
||||
<slot>setDisabled(bool)</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>100</x>
|
||||
<y>54</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>96</x>
|
||||
<y>22</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
</ui>
|
||||
|
|
Loading…
Reference in New Issue