all repos — mgba @ 3d4faa41e281ff042451032190b3191af2737d5a

mGBA Game Boy Advance Emulator

src/platform/qt/PlacementControl.cpp (view raw)

 1/* Copyright (c) 2013-2018 Jeffrey Pfau
 2 *
 3 * This Source Code Form is subject to the terms of the Mozilla Public
 4 * License, v. 2.0. If a copy of the MPL was not distributed with this
 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 6#include "PlacementControl.h"
 7
 8#include "CoreController.h"
 9
10#include <QGridLayout>
11
12#include <mgba/core/core.h>
13
14using namespace QGBA;
15
16PlacementControl::PlacementControl(std::shared_ptr<CoreController> controller, QWidget* parent)
17	: QDialog(parent, Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowCloseButtonHint)
18	, m_controller(controller)
19{
20	m_ui.setupUi(this);
21
22	connect(m_ui.offsetX, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), [this](int x) {
23		adjustLayer(-1, x, m_ui.offsetY->value());
24	});
25
26	connect(m_ui.offsetY, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), [this](int y) {
27		adjustLayer(-1, m_ui.offsetX->value(), y);
28	});
29
30	QGridLayout* grid = static_cast<QGridLayout*>(layout());
31	CoreController::Interrupter interrupter(m_controller);
32	const mCoreChannelInfo* info;
33	size_t nVideo = m_controller->thread()->core->listVideoLayers(m_controller->thread()->core, &info);
34	for (size_t i = 0; i < nVideo; ++i) {
35		QSpinBox* offsetX = new QSpinBox;
36		QSpinBox* offsetY = new QSpinBox;
37
38		offsetX->setWrapping(true);
39		offsetX->setMaximum(127);
40		offsetX->setMinimum(-128);
41		offsetX->setAccelerated(true);
42
43		offsetY->setWrapping(true);
44		offsetY->setMaximum(127);
45		offsetY->setMinimum(-128);
46		offsetY->setAccelerated(true);
47
48		m_layers.append(qMakePair(offsetX, offsetY));
49		int row = grid->rowCount();
50		grid->addWidget(new QLabel(QString(info[i].visibleName)), row, 0, Qt::AlignRight);
51		grid->addWidget(offsetX, row, 1);
52		grid->addWidget(offsetY, row, 2);
53
54		connect(offsetX, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), [this, i, offsetY](int x) {
55			adjustLayer(i, x, offsetY->value());
56		});
57
58		connect(offsetY, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), [this, i, offsetX](int y) {
59			adjustLayer(i, offsetX->value(), y);
60		});
61	}
62}
63
64void PlacementControl::adjustLayer(int layer, int32_t x, int32_t y) {
65	CoreController::Interrupter interrupter(m_controller);
66	mCore* core = m_controller->thread()->core;
67	size_t nVideo = core->listVideoLayers(core, nullptr);
68
69	if (layer < 0) {
70		for (size_t i = 0; i < nVideo; ++i) {
71			core->adjustVideoLayer(core, i, x + m_layers[i].first->value(), y + m_layers[i].second->value());
72		}
73	} else if ((size_t) layer < nVideo) {
74		core->adjustVideoLayer(core, layer, x + m_ui.offsetX->value(), y + m_ui.offsetY->value());
75	}
76}