mirror of
https://github.com/cemu-project/Cemu.git
synced 2026-07-10 01:24:41 -06:00
UI: Add MouseController settings to enable/disable position through a checkbox
This commit is contained in:
parent
f0ccc3fbf4
commit
0277f2e60e
@ -88,6 +88,8 @@ add_library(CemuWxGui STATIC
|
||||
input/settings/DefaultControllerSettings.h
|
||||
input/settings/WiimoteControllerSettings.cpp
|
||||
input/settings/WiimoteControllerSettings.h
|
||||
input/settings/MouseControllerSettings.cpp
|
||||
input/settings/MouseControllerSettings.h
|
||||
LoggingWindow.cpp
|
||||
LoggingWindow.h
|
||||
MainWindow.cpp
|
||||
|
||||
@ -25,6 +25,7 @@
|
||||
#include "wxgui/input/PairingDialog.h"
|
||||
#endif
|
||||
|
||||
#include "input/api/Mouse/MouseController.h"
|
||||
#include "wxgui/input/panels/VPADInputPanel.h"
|
||||
#include "wxgui/input/panels/ProControllerInputPanel.h"
|
||||
|
||||
@ -35,6 +36,7 @@
|
||||
#include "util/EventService.h"
|
||||
|
||||
#include "resource/embedded/resources.h"
|
||||
#include "settings/MouseControllerSettings.h"
|
||||
|
||||
bool g_inputConfigWindowHasFocus = false;
|
||||
|
||||
@ -960,7 +962,14 @@ void InputSettings2::on_controller_settings(wxCommandEvent& event)
|
||||
wnd.ShowModal();
|
||||
break;
|
||||
}
|
||||
|
||||
case InputAPI::Mouse:
|
||||
{
|
||||
const auto mouse_controller = std::dynamic_pointer_cast<MouseController>(controller);
|
||||
wxASSERT(mouse_controller);
|
||||
MouseControllerSettings wnd(this, wxGetMousePosition() + wxSize(5, 5), mouse_controller);
|
||||
wnd.ShowModal();
|
||||
break;
|
||||
}
|
||||
case InputAPI::Keyboard: break;
|
||||
|
||||
#ifdef SUPPORTS_WIIMOTE
|
||||
|
||||
72
src/gui/wxgui/input/settings/MouseControllerSettings.cpp
Normal file
72
src/gui/wxgui/input/settings/MouseControllerSettings.cpp
Normal file
@ -0,0 +1,72 @@
|
||||
#include "MouseControllerSettings.h"
|
||||
|
||||
#include "input/api/Mouse/MouseController.h"
|
||||
|
||||
#include <wx/sizer.h>
|
||||
#include <wx/button.h>
|
||||
#include <wx/checkbox.h>
|
||||
#include <wx/statbox.h>
|
||||
|
||||
#include "wxgui/helpers/wxHelpers.h"
|
||||
#include "wxgui/input/InputAPIAddWindow.h"
|
||||
|
||||
|
||||
MouseControllerSettings::MouseControllerSettings(wxWindow* parent, const wxPoint& position, std::shared_ptr<MouseController> controller)
|
||||
: wxDialog(parent, wxID_ANY, _("Controller settings"), position, wxDefaultSize,
|
||||
wxDEFAULT_DIALOG_STYLE), m_controller(std::move(controller))
|
||||
{
|
||||
this->SetSizeHints(wxDefaultSize, wxDefaultSize);
|
||||
|
||||
auto* sizer = new wxBoxSizer(wxVERTICAL);
|
||||
|
||||
// options
|
||||
{
|
||||
auto* box = new wxStaticBox(this, wxID_ANY, _("Options"));
|
||||
auto* box_sizer = new wxStaticBoxSizer(box, wxVERTICAL);
|
||||
|
||||
// Position (wiimote pointer)
|
||||
m_usePosition = new wxCheckBox(box, wxID_ANY, _("Use position"));
|
||||
m_usePosition->SetValue(m_controller->IsPositionEnabled());
|
||||
m_usePosition->Enable(m_controller->has_position());
|
||||
box_sizer->Add(m_usePosition, 0, wxEXPAND | wxALL, 5);
|
||||
|
||||
sizer->Add(box_sizer, 1, wxALL|wxEXPAND, 5);
|
||||
}
|
||||
|
||||
{
|
||||
auto* control_sizer = new wxFlexGridSizer(0, 3, 0, 0);
|
||||
control_sizer->AddGrowableCol(2);
|
||||
|
||||
auto* ok_button = new wxButton(this, wxID_ANY, _("OK"));
|
||||
ok_button->Bind(wxEVT_BUTTON, [this](auto&) { UpdateSettings(); EndModal(wxID_OK); });
|
||||
control_sizer->Add(ok_button, 0, wxALL, 5);
|
||||
|
||||
control_sizer->Add(0, 0, 0, wxEXPAND, 5);
|
||||
|
||||
auto* cancel_button = new wxButton(this, wxID_ANY, _("Cancel"));
|
||||
cancel_button->Bind(wxEVT_BUTTON, [this](auto&) { EndModal(wxID_CANCEL); });
|
||||
control_sizer->Add(cancel_button, 0, wxALL, 5);
|
||||
|
||||
sizer->Add(control_sizer, 0, wxEXPAND, 5);
|
||||
}
|
||||
|
||||
this->SetSizer(sizer);
|
||||
this->Layout();
|
||||
this->Fit();
|
||||
|
||||
this->Bind(wxEVT_CLOSE_WINDOW, &MouseControllerSettings::OnClose, this);
|
||||
}
|
||||
|
||||
void MouseControllerSettings::UpdateSettings()
|
||||
{
|
||||
if (m_usePosition)
|
||||
m_controller->SetPositionEnabled(m_usePosition->GetValue());
|
||||
}
|
||||
|
||||
void MouseControllerSettings::OnClose(wxCloseEvent& event)
|
||||
{
|
||||
if (this->GetReturnCode() == 0 || this->GetReturnCode() == wxID_OK)
|
||||
UpdateSettings();
|
||||
|
||||
event.Skip();
|
||||
}
|
||||
25
src/gui/wxgui/input/settings/MouseControllerSettings.h
Normal file
25
src/gui/wxgui/input/settings/MouseControllerSettings.h
Normal file
@ -0,0 +1,25 @@
|
||||
#pragma once
|
||||
|
||||
#include "input/api/Controller.h"
|
||||
#include "wx/dialog.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
class wxCheckBox;
|
||||
class wxPoint;
|
||||
class wxWindow;
|
||||
class MouseController;
|
||||
|
||||
class MouseControllerSettings : public wxDialog
|
||||
{
|
||||
public:
|
||||
MouseControllerSettings(wxWindow* parent, const wxPoint& position, std::shared_ptr<MouseController> controller);
|
||||
|
||||
private:
|
||||
std::shared_ptr<MouseController> m_controller;
|
||||
|
||||
wxCheckBox* m_usePosition = nullptr;
|
||||
|
||||
void UpdateSettings();
|
||||
void OnClose(wxCloseEvent& event);
|
||||
};
|
||||
@ -7,7 +7,20 @@ std::string_view MouseController::api_name() const
|
||||
return to_string(InputAPI::Mouse);
|
||||
}
|
||||
|
||||
MouseController& MouseController::SetPositionEnabled(bool value)
|
||||
{
|
||||
m_isPositionEnabled = value;
|
||||
return *this;
|
||||
}
|
||||
|
||||
glm::vec2 MouseController::get_position()
|
||||
{
|
||||
return InputManager::instance().GetMousePositionInRenderBox();
|
||||
}
|
||||
|
||||
PositionVisibility MouseController::GetPositionVisibility()
|
||||
{
|
||||
return IsPositionEnabled()
|
||||
? PositionVisibility::FULL
|
||||
: PositionVisibility::NONE;
|
||||
}
|
||||
|
||||
@ -15,7 +15,12 @@ public:
|
||||
ControllerState raw_state() override { return {}; }
|
||||
|
||||
bool has_position() override { return true; }
|
||||
bool IsPositionEnabled() const { return m_isPositionEnabled; }
|
||||
MouseController& SetPositionEnabled(bool value);
|
||||
glm::vec2 get_position() override;
|
||||
PositionVisibility GetPositionVisibility() override { return PositionVisibility::FULL; }
|
||||
PositionVisibility GetPositionVisibility() override;
|
||||
|
||||
private:
|
||||
bool m_isPositionEnabled = false;
|
||||
};
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user