all repos — mgba @ 2c59cb8211c4bf46665d12ed174cf7efe512e0d0

mGBA Game Boy Advance Emulator

Qt: Initial map cache UI
Vicki Pfau vi@endrift.com
Sun, 17 Sep 2017 10:04:19 -0700
commit

2c59cb8211c4bf46665d12ed174cf7efe512e0d0

parent

c6f0d6c5dbb9c77047439fdea8f7b2e28e207428

M src/platform/qt/CMakeLists.txtsrc/platform/qt/CMakeLists.txt

@@ -85,6 +85,7 @@ KeyEditor.cpp

LoadSaveState.cpp LogController.cpp LogView.cpp + MapView.cpp MemoryModel.cpp MemorySearch.cpp MemoryView.cpp

@@ -119,6 +120,7 @@ GIFView.ui

IOViewer.ui LoadSaveState.ui LogView.ui + MapView.ui MemorySearch.ui MemoryView.ui ObjView.ui
A src/platform/qt/MapView.cpp

@@ -0,0 +1,65 @@

+/* Copyright (c) 2013-2017 Jeffrey Pfau + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +#include "MapView.h" + +#include "CoreController.h" +#include "GBAApp.h" + +#include <QFontDatabase> +#include <QTimer> + +using namespace QGBA; + +MapView::MapView(std::shared_ptr<CoreController> controller, QWidget* parent) + : AssetView(controller, parent) + , m_controller(controller) +{ + m_ui.setupUi(this); + m_ui.tile->setController(controller); + + switch (m_controller->platform()) { +#ifdef M_CORE_GBA + case PLATFORM_GBA: + m_ui.tile->setBoundary(2048, 0, 2); + break; +#endif +#ifdef M_CORE_GB + case PLATFORM_GB: + m_ui.tile->setBoundary(1024, 0, 0); + break; +#endif + default: + return; + } + + connect(m_ui.magnification, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), [this]() { + updateTiles(true); + }); +} + +#ifdef M_CORE_GBA +void MapView::updateTilesGBA(bool force) { + QImage bg(QSize(256, 256), QImage::Format_ARGB32); + uchar* bgBits = bg.bits(); + mMapCache* mapCache = mMapCacheSetGetPointer(&m_cacheSet->maps, 0); + for (int j = 0; j < 32; ++j) { + for (int i = 0; i < 32; ++i) { + mMapCacheCleanTile(mapCache, &m_mapStatus[i + j * 32], i, j); + } + for (int i = 0; i < 8; ++i) { + memcpy(static_cast<void*>(&bgBits[256 * 4 * (i + j * 8)]), mMapCacheGetRow(mapCache, i + j * 8), 256 * 4); + } + } + bg = bg.convertToFormat(QImage::Format_RGB32).rgbSwapped(); + m_ui.map->setPixmap(QPixmap::fromImage(bg)); +} +#endif + +#ifdef M_CORE_GB +void MapView::updateTilesGB(bool force) { +} +#endif +
A src/platform/qt/MapView.h

@@ -0,0 +1,38 @@

+/* Copyright (c) 2013-2017 Jeffrey Pfau + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +#pragma once + +#include "AssetView.h" + +#include "ui_MapView.h" + +#include <mgba/core/map-cache.h> + +namespace QGBA { + +class CoreController; + +class MapView : public AssetView { +Q_OBJECT + +public: + MapView(std::shared_ptr<CoreController> controller, QWidget* parent = nullptr); + +private: +#ifdef M_CORE_GBA + void updateTilesGBA(bool force) override; +#endif +#ifdef M_CORE_GB + void updateTilesGB(bool force) override; +#endif + + Ui::MapView m_ui; + + std::shared_ptr<CoreController> m_controller; + mMapCacheEntry m_mapStatus[1024 * 1024] = {}; // TODO: Correct size +}; + +}
A src/platform/qt/MapView.ui

@@ -0,0 +1,101 @@

+<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>MapView</class> + <widget class="QWidget" name="MapView"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>498</width> + <height>335</height> + </rect> + </property> + <property name="windowTitle"> + <string>Maps</string> + </property> + <layout class="QGridLayout" name="gridLayout"> + <item row="1" column="0"> + <widget class="QGBA::AssetTile" name="tile"/> + </item> + <item row="0" column="1" rowspan="3"> + <widget class="QScrollArea" name="scrollArea"> + <property name="widgetResizable"> + <bool>true</bool> + </property> + <widget class="QWidget" name="scrollAreaWidgetContents"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>314</width> + <height>309</height> + </rect> + </property> + <layout class="QVBoxLayout" name="verticalLayout"> + <item> + <widget class="QLabel" name="map"> + <property name="text"> + <string/> + </property> + </widget> + </item> + </layout> + </widget> + </widget> + </item> + <item row="2" column="0"> + <spacer name="verticalSpacer"> + <property name="orientation"> + <enum>Qt::Vertical</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>0</width> + <height>0</height> + </size> + </property> + </spacer> + </item> + <item row="0" 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> + <customwidget> + <class>QGBA::AssetTile</class> + <extends>QGroupBox</extends> + <header>AssetTile.h</header> + <container>1</container> + </customwidget> + </customwidgets> + <resources/> + <connections/> +</ui>
M src/platform/qt/Window.cppsrc/platform/qt/Window.cpp

@@ -35,9 +35,10 @@ #include "GIFView.h"

#include "IOViewer.h" #include "LoadSaveState.h" #include "LogView.h" -#include "MultiplayerController.h" +#include "MapView.h" #include "MemorySearch.h" #include "MemoryView.h" +#include "MultiplayerController.h" #include "OverrideView.h" #include "ObjView.h" #include "PaletteView.h"

@@ -1490,6 +1491,11 @@ QAction* tileView = new QAction(tr("View &tiles..."), toolsMenu);

connect(tileView, &QAction::triggered, openControllerTView<TileView>()); m_gameActions.append(tileView); addControlledAction(toolsMenu, tileView, "tileWindow"); + + QAction* mapView = new QAction(tr("View &map..."), toolsMenu); + connect(mapView, &QAction::triggered, openControllerTView<MapView>()); + m_gameActions.append(mapView); + addControlledAction(toolsMenu, mapView, "mapWindow"); QAction* memoryView = new QAction(tr("View memory..."), toolsMenu); connect(memoryView, &QAction::triggered, openControllerTView<MemoryView>());