mirror of
https://github.com/libretro/mgba.git
synced 2024-11-30 19:50:34 +00:00
Qt: Add map export
This commit is contained in:
parent
697c1cfa9d
commit
229d138dac
@ -7,6 +7,9 @@
|
|||||||
|
|
||||||
#include "CoreController.h"
|
#include "CoreController.h"
|
||||||
#include "GBAApp.h"
|
#include "GBAApp.h"
|
||||||
|
#include "LogController.h"
|
||||||
|
|
||||||
|
#include <mgba-util/png-io.h>
|
||||||
|
|
||||||
#include <QButtonGroup>
|
#include <QButtonGroup>
|
||||||
#include <QFontDatabase>
|
#include <QFontDatabase>
|
||||||
@ -59,6 +62,11 @@ MapView::MapView(std::shared_ptr<CoreController> controller, QWidget* parent)
|
|||||||
});
|
});
|
||||||
group->addButton(button);
|
group->addButton(button);
|
||||||
}
|
}
|
||||||
|
#ifdef USE_PNG
|
||||||
|
connect(m_ui.exportButton, &QAbstractButton::clicked, this, &MapView::exportMap);
|
||||||
|
#else
|
||||||
|
m_ui.exportButton->setVisible(false);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void MapView::selectMap(int map) {
|
void MapView::selectMap(int map) {
|
||||||
@ -73,14 +81,13 @@ void MapView::selectMap(int map) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void MapView::updateTilesGBA(bool force) {
|
void MapView::updateTilesGBA(bool force) {
|
||||||
QImage bg;
|
|
||||||
{
|
{
|
||||||
CoreController::Interrupter interrupter(m_controller);
|
CoreController::Interrupter interrupter(m_controller);
|
||||||
mMapCache* mapCache = mMapCacheSetGetPointer(&m_cacheSet->maps, m_map);
|
mMapCache* mapCache = mMapCacheSetGetPointer(&m_cacheSet->maps, m_map);
|
||||||
int tilesW = 1 << mMapCacheSystemInfoGetTilesWide(mapCache->sysConfig);
|
int tilesW = 1 << mMapCacheSystemInfoGetTilesWide(mapCache->sysConfig);
|
||||||
int tilesH = 1 << mMapCacheSystemInfoGetTilesHigh(mapCache->sysConfig);
|
int tilesH = 1 << mMapCacheSystemInfoGetTilesHigh(mapCache->sysConfig);
|
||||||
bg = QImage(QSize(tilesW * 8, tilesH * 8), QImage::Format_ARGB32);
|
m_rawMap = QImage(QSize(tilesW * 8, tilesH * 8), QImage::Format_ARGB32);
|
||||||
uchar* bgBits = bg.bits();
|
uchar* bgBits = m_rawMap.bits();
|
||||||
for (int j = 0; j < tilesH; ++j) {
|
for (int j = 0; j < tilesH; ++j) {
|
||||||
for (int i = 0; i < tilesW; ++i) {
|
for (int i = 0; i < tilesW; ++i) {
|
||||||
mMapCacheCleanTile(mapCache, &m_mapStatus[i + j * tilesW], i, j);
|
mMapCacheCleanTile(mapCache, &m_mapStatus[i + j * tilesW], i, j);
|
||||||
@ -90,8 +97,8 @@ void MapView::updateTilesGBA(bool force) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
bg = bg.convertToFormat(QImage::Format_RGB32).rgbSwapped();
|
m_rawMap = m_rawMap.rgbSwapped();
|
||||||
QPixmap map = QPixmap::fromImage(bg);
|
QPixmap map = QPixmap::fromImage(m_rawMap.convertToFormat(QImage::Format_RGB32));
|
||||||
if (m_ui.magnification->value() > 1) {
|
if (m_ui.magnification->value() > 1) {
|
||||||
map = map.scaled(map.size() * m_ui.magnification->value());
|
map = map.scaled(map.size() * m_ui.magnification->value());
|
||||||
}
|
}
|
||||||
@ -104,3 +111,23 @@ void MapView::updateTilesGB(bool force) {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef USE_PNG
|
||||||
|
void MapView::exportMap() {
|
||||||
|
QString filename = GBAApp::app()->getSaveFileName(this, tr("Export map"),
|
||||||
|
tr("Portable Network Graphics (*.png)"));
|
||||||
|
VFile* vf = VFileDevice::open(filename, O_WRONLY | O_CREAT | O_TRUNC);
|
||||||
|
if (!vf) {
|
||||||
|
LOG(QT, ERROR) << tr("Failed to open output PNG file: %1").arg(filename);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
CoreController::Interrupter interrupter(m_controller);
|
||||||
|
png_structp png = PNGWriteOpen(vf);
|
||||||
|
png_infop info = PNGWriteHeaderA(png, m_rawMap.width(), m_rawMap.height());
|
||||||
|
|
||||||
|
mMapCache* mapCache = mMapCacheSetGetPointer(&m_cacheSet->maps, m_map);
|
||||||
|
QImage map = m_rawMap.rgbSwapped();
|
||||||
|
PNGWritePixelsA(png, map.width(), map.height(), map.bytesPerLine() / 4, static_cast<const void*>(map.constBits()));
|
||||||
|
PNGWriteClose(png, info);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
@ -21,6 +21,11 @@ Q_OBJECT
|
|||||||
public:
|
public:
|
||||||
MapView(std::shared_ptr<CoreController> controller, QWidget* parent = nullptr);
|
MapView(std::shared_ptr<CoreController> controller, QWidget* parent = nullptr);
|
||||||
|
|
||||||
|
#ifdef USE_PNG
|
||||||
|
public slots:
|
||||||
|
void exportMap();
|
||||||
|
#endif
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void selectMap(int);
|
void selectMap(int);
|
||||||
|
|
||||||
@ -37,6 +42,7 @@ private:
|
|||||||
std::shared_ptr<CoreController> m_controller;
|
std::shared_ptr<CoreController> m_controller;
|
||||||
mMapCacheEntry m_mapStatus[1024 * 1024] = {}; // TODO: Correct size
|
mMapCacheEntry m_mapStatus[1024 * 1024] = {}; // TODO: Correct size
|
||||||
int m_map = 0;
|
int m_map = 0;
|
||||||
|
QImage m_rawMap;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,10 @@
|
|||||||
<string>Maps</string>
|
<string>Maps</string>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QGridLayout" name="gridLayout">
|
<layout class="QGridLayout" name="gridLayout">
|
||||||
<item row="0" column="1" rowspan="4">
|
<item row="0" column="0">
|
||||||
|
<layout class="QVBoxLayout" name="bgLayout"/>
|
||||||
|
</item>
|
||||||
|
<item row="0" column="1" rowspan="5">
|
||||||
<widget class="QScrollArea" name="scrollArea">
|
<widget class="QScrollArea" name="scrollArea">
|
||||||
<property name="widgetResizable">
|
<property name="widgetResizable">
|
||||||
<bool>true</bool>
|
<bool>true</bool>
|
||||||
@ -71,7 +74,7 @@
|
|||||||
<item row="2" column="0">
|
<item row="2" column="0">
|
||||||
<widget class="QGBA::AssetTile" name="tile"/>
|
<widget class="QGBA::AssetTile" name="tile"/>
|
||||||
</item>
|
</item>
|
||||||
<item row="3" column="0">
|
<item row="4" column="0">
|
||||||
<spacer name="verticalSpacer">
|
<spacer name="verticalSpacer">
|
||||||
<property name="orientation">
|
<property name="orientation">
|
||||||
<enum>Qt::Vertical</enum>
|
<enum>Qt::Vertical</enum>
|
||||||
@ -114,8 +117,12 @@
|
|||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
<item row="0" column="0">
|
<item row="3" column="0">
|
||||||
<layout class="QVBoxLayout" name="bgLayout"/>
|
<widget class="QPushButton" name="exportButton">
|
||||||
|
<property name="text">
|
||||||
|
<string>Export</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
|
Loading…
Reference in New Issue
Block a user