all repos — mgba @ ccf66299e684f6dd1f27afb3e1ec32d2ac26ec7a

mGBA Game Boy Advance Emulator

Qt: Very broken tile viewer resizing
Jeffrey Pfau jeffrey@endrift.com
Fri, 22 Jul 2016 19:16:30 -0700
commit

ccf66299e684f6dd1f27afb3e1ec32d2ac26ec7a

parent

b1f750e441af63b35141702ac00fd2f13313bd44

M src/platform/qt/Swatch.cppsrc/platform/qt/Swatch.cpp

@@ -18,7 +18,6 @@ Swatch::Swatch(QWidget* parent)

: QWidget(parent) { m_size = 10; - setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding); } void Swatch::setSize(int size) {
M src/platform/qt/TilePainter.cppsrc/platform/qt/TilePainter.cpp

@@ -16,6 +16,7 @@ : QWidget(parent)

{ m_backing = QPixmap(256, 768); m_backing.fill(Qt::transparent); + resize(256, 768); } void TilePainter::paintEvent(QPaintEvent* event) {

@@ -23,18 +24,31 @@ QPainter painter(this);

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); +}
M src/platform/qt/TilePainter.hsrc/platform/qt/TilePainter.h

@@ -20,6 +20,7 @@ TilePainter(QWidget* parent = nullptr);

public slots: void setTile(int index, const uint16_t*); + void setTileCount(int tiles); signals: void indexPressed(int index);

@@ -27,6 +28,7 @@

protected: void paintEvent(QPaintEvent*) override; void mousePressEvent(QMouseEvent*) override; + void resizeEvent(QResizeEvent*) override; private: QPixmap m_backing;
M src/platform/qt/TileView.cppsrc/platform/qt/TileView.cpp

@@ -8,6 +8,7 @@

#include "GBAApp.h" #include <QFontDatabase> +#include <QTimer> extern "C" { #include "gba/gba.h"

@@ -66,7 +67,7 @@ }

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 @@ GBA* gba = static_cast<GBA*>(m_controller->thread()->core->board);

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); + }); +}
M src/platform/qt/TileView.hsrc/platform/qt/TileView.h

@@ -26,11 +26,15 @@ TileView(GameController* controller, QWidget* parent = nullptr);

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;
M src/platform/qt/TileView.uisrc/platform/qt/TileView.ui

@@ -6,8 +6,8 @@ <property name="geometry">

<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,43 +23,31 @@ </widget>

</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"> - <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> + <widget class="QGBA::Swatch" name="preview" native="true"> + <property name="minimumSize"> + <size> + <width>87</width> + <height>87</height> + </size> + </property> + </widget> </item> <item> <layout class="QHBoxLayout" name="horizontalLayout">

@@ -108,6 +96,12 @@ </widget>

</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,15 +132,9 @@ <property name="geometry">

<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">

@@ -167,11 +155,17 @@ </property>

<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 @@ <container>1</container>

</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>