From a7f9983563f76d1bca071be7490c2abf57ce16d5 Mon Sep 17 00:00:00 2001 From: german Date: Thu, 21 Jan 2021 18:51:24 -0600 Subject: Add controller window and single joycon top view --- src/yuzu/debugger/controller.cpp | 62 ++++++++++++++++++++++++++++++++++++++++ src/yuzu/debugger/controller.h | 28 ++++++++++++++++++ 2 files changed, 90 insertions(+) create mode 100644 src/yuzu/debugger/controller.cpp create mode 100644 src/yuzu/debugger/controller.h (limited to 'src/yuzu/debugger') diff --git a/src/yuzu/debugger/controller.cpp b/src/yuzu/debugger/controller.cpp new file mode 100644 index 000000000..23834f063 --- /dev/null +++ b/src/yuzu/debugger/controller.cpp @@ -0,0 +1,62 @@ +// Copyright 2015 Citra Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#include +#include +#include +#include "core/settings.h" +#include "yuzu/configuration/configure_input_player_widget.h" +#include "yuzu/debugger/controller.h" + +ControllerDialog::ControllerDialog(QWidget* parent) : QWidget(parent, Qt::Dialog) { + setObjectName(QStringLiteral("Controller")); + setWindowTitle(tr("Controller P1")); + resize(500, 350); + setMinimumSize(500, 350); + // Remove the "?" button from the titlebar and enable the maximize button + setWindowFlags((windowFlags() & ~Qt::WindowContextHelpButtonHint) | + Qt::WindowMaximizeButtonHint); + + PlayerControlPreview* widget = new PlayerControlPreview(this); + const auto& players = Settings::values.players.GetValue(); + constexpr std::size_t player = 0; + widget->SetPlayerInputRaw(player, players[player].buttons, players[player].analogs); + widget->SetConnectedStatus(players[player].connected); + widget->SetControllerType(players[player].controller_type); + QLayout* layout = new QVBoxLayout(this); + layout->setContentsMargins(0, 0, 0, 0); + layout->addWidget(widget); + setLayout(layout); + + // Configure focus so that widget is focusable and the dialog automatically forwards focus to + // it. + setFocusProxy(widget); + widget->setFocusPolicy(Qt::StrongFocus); + widget->setFocus(); +} + +QAction* ControllerDialog::toggleViewAction() { + if (toggle_view_action == nullptr) { + toggle_view_action = new QAction(windowTitle(), this); + toggle_view_action->setCheckable(true); + toggle_view_action->setChecked(isVisible()); + connect(toggle_view_action, &QAction::toggled, this, &ControllerDialog::setVisible); + } + + return toggle_view_action; +} + +void ControllerDialog::showEvent(QShowEvent* ev) { + if (toggle_view_action) { + toggle_view_action->setChecked(isVisible()); + } + QWidget::showEvent(ev); +} + +void ControllerDialog::hideEvent(QHideEvent* ev) { + if (toggle_view_action) { + toggle_view_action->setChecked(isVisible()); + } + QWidget::hideEvent(ev); +} diff --git a/src/yuzu/debugger/controller.h b/src/yuzu/debugger/controller.h new file mode 100644 index 000000000..da389b6a2 --- /dev/null +++ b/src/yuzu/debugger/controller.h @@ -0,0 +1,28 @@ +// Copyright 2015 Citra Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#pragma once + +#include + +class QAction; +class QHideEvent; +class QShowEvent; + +class ControllerDialog : public QWidget { + Q_OBJECT + +public: + explicit ControllerDialog(QWidget* parent = nullptr); + + /// Returns a QAction that can be used to toggle visibility of this dialog. + QAction* toggleViewAction(); + +protected: + void showEvent(QShowEvent* ev) override; + void hideEvent(QHideEvent* ev) override; + +private: + QAction* toggle_view_action = nullptr; +}; -- cgit v1.2.3