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)
|
: QWidget(parent)
|
||||||
{
|
{
|
||||||
m_size = 10;
|
m_size = 10;
|
||||||
setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Swatch::setSize(int size) {
|
void Swatch::setSize(int size) {
|
||||||
|
|
|
@ -16,6 +16,7 @@ TilePainter::TilePainter(QWidget* parent)
|
||||||
{
|
{
|
||||||
m_backing = QPixmap(256, 768);
|
m_backing = QPixmap(256, 768);
|
||||||
m_backing.fill(Qt::transparent);
|
m_backing.fill(Qt::transparent);
|
||||||
|
resize(256, 768);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TilePainter::paintEvent(QPaintEvent* event) {
|
void TilePainter::paintEvent(QPaintEvent* event) {
|
||||||
|
@ -23,18 +24,31 @@ void TilePainter::paintEvent(QPaintEvent* event) {
|
||||||
painter.drawPixmap(QPoint(), m_backing);
|
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) {
|
void TilePainter::mousePressEvent(QMouseEvent* event) {
|
||||||
int x = event->x() / 8;
|
int x = event->x() / 8;
|
||||||
int y = event->y() / 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) {
|
void TilePainter::setTile(int index, const uint16_t* data) {
|
||||||
QPainter painter(&m_backing);
|
QPainter painter(&m_backing);
|
||||||
int x = index & 31;
|
int w = width() / 8;
|
||||||
int y = index / 32;
|
int x = index % w;
|
||||||
|
int y = index / w;
|
||||||
QRect r(x * 8, y * 8, 8, 8);
|
QRect r(x * 8, y * 8, 8, 8);
|
||||||
QImage tile(reinterpret_cast<const uchar*>(data), 8, 8, QImage::Format_RGB555);
|
QImage tile(reinterpret_cast<const uchar*>(data), 8, 8, QImage::Format_RGB555);
|
||||||
painter.fillRect(r, tile.rgbSwapped());
|
painter.fillRect(r, tile.rgbSwapped());
|
||||||
update(r);
|
update(r);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TilePainter::setTileCount(int tiles) {
|
||||||
|
setMinimumSize(16, (tiles * 8) / (width() / 8));
|
||||||
|
resizeEvent(nullptr);
|
||||||
|
}
|
||||||
|
|
|
@ -20,6 +20,7 @@ public:
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void setTile(int index, const uint16_t*);
|
void setTile(int index, const uint16_t*);
|
||||||
|
void setTileCount(int tiles);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void indexPressed(int index);
|
void indexPressed(int index);
|
||||||
|
@ -27,6 +28,7 @@ signals:
|
||||||
protected:
|
protected:
|
||||||
void paintEvent(QPaintEvent*) override;
|
void paintEvent(QPaintEvent*) override;
|
||||||
void mousePressEvent(QMouseEvent*) override;
|
void mousePressEvent(QMouseEvent*) override;
|
||||||
|
void resizeEvent(QResizeEvent*) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QPixmap m_backing;
|
QPixmap m_backing;
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
#include "GBAApp.h"
|
#include "GBAApp.h"
|
||||||
|
|
||||||
#include <QFontDatabase>
|
#include <QFontDatabase>
|
||||||
|
#include <QTimer>
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#include "gba/gba.h"
|
#include "gba/gba.h"
|
||||||
|
@ -66,7 +67,7 @@ void TileView::selectIndex(int index) {
|
||||||
m_ui.preview->update();
|
m_ui.preview->update();
|
||||||
}
|
}
|
||||||
|
|
||||||
void TileView::updateTiles() {
|
void TileView::updateTiles(bool force) {
|
||||||
if (!m_controller->thread() || !m_controller->thread()->core) {
|
if (!m_controller->thread() || !m_controller->thread()->core) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -75,31 +76,39 @@ void TileView::updateTiles() {
|
||||||
GBAVideoTileCacheAssociate(&m_tileCache, &gba->video);
|
GBAVideoTileCacheAssociate(&m_tileCache, &gba->video);
|
||||||
|
|
||||||
if (m_ui.palette256->isChecked()) {
|
if (m_ui.palette256->isChecked()) {
|
||||||
m_ui.tiles->setMinimumSize(256, 384);
|
m_ui.tiles->setTileCount(1536);
|
||||||
for (int i = 0; i < 1024; ++i) {
|
for (int i = 0; i < 1024; ++i) {
|
||||||
const uint16_t* data = GBAVideoTileCacheGetTile256IfDirty(&m_tileCache, i, 0);
|
const uint16_t* data = GBAVideoTileCacheGetTile256IfDirty(&m_tileCache, i, 0);
|
||||||
if (data) {
|
if (data) {
|
||||||
m_ui.tiles->setTile(i, 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) {
|
for (int i = 1024; i < 1536; ++i) {
|
||||||
const uint16_t* data = GBAVideoTileCacheGetTile256IfDirty(&m_tileCache, i, 1);
|
const uint16_t* data = GBAVideoTileCacheGetTile256IfDirty(&m_tileCache, i, 1);
|
||||||
if (data) {
|
if (data) {
|
||||||
m_ui.tiles->setTile(i, data);
|
m_ui.tiles->setTile(i, data);
|
||||||
|
} else if (force) {
|
||||||
|
m_ui.tiles->setTile(i, GBAVideoTileCacheGetTile256(&m_tileCache, i, 1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
m_ui.tiles->setMinimumSize(256, 768);
|
m_ui.tiles->setTileCount(3072);
|
||||||
for (int i = 0; i < 2048; ++i) {
|
for (int i = 0; i < 2048; ++i) {
|
||||||
const uint16_t* data = GBAVideoTileCacheGetTile16IfDirty(&m_tileCache, i, m_paletteId);
|
const uint16_t* data = GBAVideoTileCacheGetTile16IfDirty(&m_tileCache, i, m_paletteId);
|
||||||
if (data) {
|
if (data) {
|
||||||
m_ui.tiles->setTile(i, 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) {
|
for (int i = 2048; i < 3072; ++i) {
|
||||||
const uint16_t* data = GBAVideoTileCacheGetTile16IfDirty(&m_tileCache, i, m_paletteId + 16);
|
const uint16_t* data = GBAVideoTileCacheGetTile16IfDirty(&m_tileCache, i, m_paletteId + 16);
|
||||||
if (data) {
|
if (data) {
|
||||||
m_ui.tiles->setTile(i, 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;
|
m_paletteId = palette;
|
||||||
updateTiles();
|
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();
|
virtual ~TileView();
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void updateTiles();
|
void updateTiles(bool force = false);
|
||||||
void updatePalette(int);
|
void updatePalette(int);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void selectIndex(int);
|
void selectIndex(int);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void resizeEvent(QResizeEvent*) override;
|
||||||
|
void showEvent(QShowEvent*) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::TileView m_ui;
|
Ui::TileView m_ui;
|
||||||
|
|
||||||
|
|
|
@ -6,8 +6,8 @@
|
||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>288</width>
|
<width>509</width>
|
||||||
<height>269</height>
|
<height>265</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="windowTitle">
|
<property name="windowTitle">
|
||||||
|
@ -23,43 +23,31 @@
|
||||||
</item>
|
</item>
|
||||||
<item row="2" column="0">
|
<item row="2" column="0">
|
||||||
<widget class="QGroupBox" name="groupBox">
|
<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">
|
<property name="title">
|
||||||
<string>Preview</string>
|
<string/>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||||
<item>
|
<item>
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout_3">
|
<widget class="QGBA::Swatch" name="preview" native="true">
|
||||||
<item>
|
<property name="minimumSize">
|
||||||
<spacer name="horizontalSpacer">
|
<size>
|
||||||
<property name="orientation">
|
<width>87</width>
|
||||||
<enum>Qt::Horizontal</enum>
|
<height>87</height>
|
||||||
</property>
|
</size>
|
||||||
</spacer>
|
</property>
|
||||||
</item>
|
</widget>
|
||||||
<item>
|
|
||||||
<widget class="QGBA::Swatch" name="preview" native="true">
|
|
||||||
<property name="minimumSize">
|
|
||||||
<size>
|
|
||||||
<width>87</width>
|
|
||||||
<height>87</height>
|
|
||||||
</size>
|
|
||||||
</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>
|
||||||
<item>
|
<item>
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||||
|
@ -108,6 +96,12 @@
|
||||||
</item>
|
</item>
|
||||||
<item row="0" column="0">
|
<item row="0" column="0">
|
||||||
<widget class="QSlider" name="paletteId">
|
<widget class="QSlider" name="paletteId">
|
||||||
|
<property name="maximumSize">
|
||||||
|
<size>
|
||||||
|
<width>170</width>
|
||||||
|
<height>16777215</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
<property name="maximum">
|
<property name="maximum">
|
||||||
<number>15</number>
|
<number>15</number>
|
||||||
</property>
|
</property>
|
||||||
|
@ -138,16 +132,10 @@
|
||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>16</width>
|
<width>282</width>
|
||||||
<height>16</height>
|
<height>768</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="sizePolicy">
|
|
||||||
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
|
||||||
<horstretch>0</horstretch>
|
|
||||||
<verstretch>0</verstretch>
|
|
||||||
</sizepolicy>
|
|
||||||
</property>
|
|
||||||
<layout class="QVBoxLayout" name="verticalLayout">
|
<layout class="QVBoxLayout" name="verticalLayout">
|
||||||
<property name="spacing">
|
<property name="spacing">
|
||||||
<number>0</number>
|
<number>0</number>
|
||||||
|
@ -167,11 +155,17 @@
|
||||||
<item>
|
<item>
|
||||||
<widget class="QGBA::TilePainter" name="tiles" native="true">
|
<widget class="QGBA::TilePainter" name="tiles" native="true">
|
||||||
<property name="sizePolicy">
|
<property name="sizePolicy">
|
||||||
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
|
||||||
<horstretch>0</horstretch>
|
<horstretch>0</horstretch>
|
||||||
<verstretch>0</verstretch>
|
<verstretch>0</verstretch>
|
||||||
</sizepolicy>
|
</sizepolicy>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="minimumSize">
|
||||||
|
<size>
|
||||||
|
<width>256</width>
|
||||||
|
<height>768</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
|
@ -195,5 +189,22 @@
|
||||||
</customwidget>
|
</customwidget>
|
||||||
</customwidgets>
|
</customwidgets>
|
||||||
<resources/>
|
<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>
|
</ui>
|
||||||
|
|
Loading…
Reference in New Issue