Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
1,046 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// Copyright 2018 Dolphin Emulator Project | ||
// SPDX-License-Identifier: GPL-2.0-or-later | ||
|
||
#include "Core/Config/MouseSettings.h" | ||
|
||
namespace Config | ||
{ | ||
const Info<double> MOUSE_SENSITIVITY{{System::Main, "Input", "MouseSensitivity"}, 1.0}; | ||
const Info<double> SNAPPING_DISTANCE{{System::Main, "Input", "SnappingDistance"}, 0.0}; | ||
const Info<unsigned short> CENTER_MOUSE_KEY{{System::Main, "Input", "CenterMouseKey"}, | ||
CENTER_MOUSE_KEY_UNBOUND_VALUE}; | ||
const Info<bool> OCTAGONAL_MOUSE_JAIL_ENABLED{{System::Main, "Input", "OctagonalMouseJailEnabled"}, | ||
false}; | ||
} // namespace Config |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// Copyright 2018 Dolphin Emulator Project | ||
// SPDX-License-Identifier: GPL-2.0-or-later | ||
|
||
#pragma once | ||
|
||
#include "Common/Config/Config.h" | ||
|
||
namespace Config | ||
{ | ||
extern const Info<double> MOUSE_SENSITIVITY; | ||
static constexpr double scaling_factor_to_make_mouse_sensitivity_one_for_fullscreen = 2.0; | ||
extern const Info<double> SNAPPING_DISTANCE; | ||
extern const Info<unsigned short> CENTER_MOUSE_KEY; | ||
static constexpr unsigned short CENTER_MOUSE_KEY_UNBOUND_VALUE = 0xFFFF; | ||
extern const Info<bool> OCTAGONAL_MOUSE_JAIL_ENABLED; | ||
} // namespace Config |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,227 @@ | ||
#include "DolphinQt/Config/MouseSettingsWidget.h" | ||
#ifdef _WIN32 | ||
#include <Windows.h> | ||
#endif | ||
|
||
#include <memory> | ||
|
||
#include <QApplication> | ||
#include <QCheckBox> | ||
#include <QDoubleSpinBox> | ||
#include <QLabel> | ||
#include <QVBoxLayout> | ||
|
||
#include "Core/Config/MouseSettings.h" | ||
#include "DolphinQt/QtUtils/MultiClickSignalButton.h" | ||
#include "InputCommon/ControllerInterface/OctagonalMouseJail.h" | ||
|
||
MouseSettingsWidget::MouseSettingsWidget(QWidget* parent) : QGroupBox(parent) | ||
{ | ||
CreateLayout(); | ||
LoadSettings(); | ||
ConnectWidgets(); | ||
} | ||
|
||
void MouseSettingsWidget::CreateLayout() | ||
{ | ||
QVBoxLayout* primary_layout = new QVBoxLayout{}; | ||
|
||
QHBoxLayout* sensitivity_layout = CreateSensitivityLayout(); | ||
QHBoxLayout* snapping_distance_layout = CreateSnappingDistanceLayout(); | ||
QHBoxLayout* center_mouse_key_layout = CreateCenterMouseKeyLayout(); | ||
|
||
QHBoxLayout* octagonal_mouse_jail_is_enabled = CreateOctagonalMouseJailIsEnabledLayout(); | ||
|
||
primary_layout->addLayout(octagonal_mouse_jail_is_enabled); | ||
primary_layout->addLayout(sensitivity_layout); | ||
primary_layout->addLayout(snapping_distance_layout); | ||
primary_layout->addLayout(center_mouse_key_layout); | ||
|
||
this->setLayout(primary_layout); | ||
} | ||
|
||
void MouseSettingsWidget::ConnectWidgets() | ||
{ | ||
// I'm not sure what QOverland does in this, but it was in the example in the | ||
// qt documentation and it doesn't work without it. | ||
connect(m_sensitivity_control, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this, | ||
&MouseSettingsWidget::SaveSettings); | ||
connect(m_snapping_distance_control, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this, | ||
&MouseSettingsWidget::SaveSettings); | ||
connect(m_center_mouse_key_control, &MultiClickSignalButton::LeftClick, [this]() { | ||
m_center_mouse_key_control->setText(QString{tr("...")}); | ||
|
||
unsigned short temp_center_mouse_key = GetNextKeyCode(); | ||
|
||
Config::SetBaseOrCurrent(Config::CENTER_MOUSE_KEY, temp_center_mouse_key); | ||
Config::Save(); | ||
ciface::OctagonalMouseJail::GetInstance().RefreshConfigValues(); | ||
|
||
if (temp_center_mouse_key == Config::CENTER_MOUSE_KEY_UNBOUND_VALUE) | ||
{ | ||
m_center_mouse_key_control->setText(QString{tr(" ")}); | ||
} | ||
else | ||
{ | ||
m_center_mouse_key_control->setText(tr(std::string{(char)temp_center_mouse_key}.c_str())); | ||
} | ||
}); | ||
connect(m_center_mouse_key_control, &MultiClickSignalButton::MiddleClick, [this]() { | ||
m_center_mouse_key_control->setText(QString{tr(" ")}); | ||
Config::SetBaseOrCurrent(Config::CENTER_MOUSE_KEY, Config::CENTER_MOUSE_KEY_UNBOUND_VALUE); | ||
Config::Save(); | ||
ciface::OctagonalMouseJail::GetInstance().RefreshConfigValues(); | ||
}); | ||
connect(m_octagonal_mouse_jail_is_enabled_control, &QCheckBox::stateChanged, [this](int state) { | ||
Config::SetBaseOrCurrent(Config::OCTAGONAL_MOUSE_JAIL_ENABLED, (bool)state); | ||
SaveSettings(); | ||
}); | ||
} | ||
|
||
void MouseSettingsWidget::LoadSettings() | ||
{ | ||
m_sensitivity_control->setValue(Config::Get(Config::MOUSE_SENSITIVITY)); | ||
m_snapping_distance_control->setValue(Config::Get(Config::SNAPPING_DISTANCE)); | ||
|
||
unsigned short temp_center_mouse_key = Config::Get(Config::CENTER_MOUSE_KEY); | ||
if (temp_center_mouse_key == Config::CENTER_MOUSE_KEY_UNBOUND_VALUE) | ||
{ | ||
m_center_mouse_key_control->setText(QString{}); | ||
} | ||
else | ||
{ | ||
m_center_mouse_key_control->setText(tr(std::string{(char)temp_center_mouse_key}.c_str())); | ||
} | ||
|
||
m_octagonal_mouse_jail_is_enabled_control->setChecked( | ||
Config::Get(Config::OCTAGONAL_MOUSE_JAIL_ENABLED)); | ||
} | ||
|
||
void MouseSettingsWidget::SaveSettings() | ||
{ | ||
Config::SetBaseOrCurrent(Config::MOUSE_SENSITIVITY, m_sensitivity_control->value()); | ||
Config::SetBaseOrCurrent(Config::SNAPPING_DISTANCE, m_snapping_distance_control->value()); | ||
// CenterMouseKeyHandled in lambda attached to m_center_mouse_key_control | ||
Config::SetBaseOrCurrent(Config::OCTAGONAL_MOUSE_JAIL_ENABLED, | ||
m_octagonal_mouse_jail_is_enabled_control->isChecked()); | ||
Config::Save(); | ||
ciface::OctagonalMouseJail::GetInstance().RefreshConfigValues(); | ||
} | ||
|
||
QHBoxLayout* MouseSettingsWidget::CreateSensitivityLayout() | ||
{ | ||
QHBoxLayout* sensitivity_layout = new QHBoxLayout{}; | ||
|
||
m_sensitivity_control = new QDoubleSpinBox{}; | ||
m_sensitivity_control->setRange(1.00, 9999.50); | ||
m_sensitivity_control->setDecimals(2); | ||
m_sensitivity_control->setSingleStep(0.5); | ||
m_sensitivity_control->setWrapping(true); | ||
QString sensitivity_tool_tip{ | ||
tr("Adjusts how quickly the mouse cursor moves the Cursor X/Y +/- inputs." | ||
"\nChanges the distance at which your mouse snaps to notches. May make your snapping feel " | ||
"weird." | ||
"\n\n1.0(default) sensitivity maps the mouse to the full screen" | ||
"\n\nRecommended value: 7.5")}; | ||
m_sensitivity_control->setToolTip(sensitivity_tool_tip); | ||
|
||
QLabel* sensitivity_label = new QLabel{}; | ||
sensitivity_label->setToolTip(sensitivity_tool_tip); | ||
sensitivity_label->setText(tr("Sensitivity")); | ||
|
||
sensitivity_layout->addWidget(sensitivity_label); | ||
sensitivity_layout->addWidget(m_sensitivity_control); | ||
|
||
return sensitivity_layout; | ||
} | ||
|
||
QHBoxLayout* MouseSettingsWidget::CreateSnappingDistanceLayout() | ||
{ | ||
QHBoxLayout* snapping_distance_layout = new QHBoxLayout{}; | ||
m_snapping_distance_control = new QDoubleSpinBox{}; | ||
|
||
m_snapping_distance_control->setRange(0.00, 9999.50); | ||
m_snapping_distance_control->setDecimals(2); | ||
m_snapping_distance_control->setSingleStep(0.5); | ||
m_snapping_distance_control->setWrapping(true); | ||
QString snapping_distance_tool_tip{ | ||
tr("Distance (in pixels, can do partial pixels) around notches where cursor snaps to notch." | ||
"\nMouse is only locked into notches and snapping will " | ||
"only occur when the game is started and has focus." | ||
"\n\n0.0(default) disables snapping" | ||
"\n\nRecommended Value: 4.5")}; | ||
m_snapping_distance_control->setToolTip(snapping_distance_tool_tip); | ||
|
||
QLabel* snapping_distance_label = new QLabel{}; | ||
snapping_distance_label->setText(tr("Snapping Distance")); | ||
snapping_distance_label->setToolTip(snapping_distance_tool_tip); | ||
|
||
snapping_distance_layout->addWidget(snapping_distance_label); | ||
snapping_distance_layout->addWidget(m_snapping_distance_control); | ||
return snapping_distance_layout; | ||
} | ||
|
||
QHBoxLayout* MouseSettingsWidget::CreateCenterMouseKeyLayout() | ||
{ | ||
QHBoxLayout* center_mouse_key_layout = new QHBoxLayout{}; | ||
m_center_mouse_key_control = new MultiClickSignalButton{}; | ||
QString center_mouse_key_tool_tip{tr("Centers the cursor after 2 frames." | ||
"\nLeft-click to detect. Middle-click to clear")}; | ||
m_center_mouse_key_control->setToolTip(center_mouse_key_tool_tip); | ||
|
||
QLabel* center_mouse_key_label = new QLabel{}; | ||
center_mouse_key_label->setText(tr("Center Mouse Key")); | ||
center_mouse_key_label->setToolTip(center_mouse_key_tool_tip); | ||
|
||
center_mouse_key_layout->addWidget(center_mouse_key_label); | ||
center_mouse_key_layout->addWidget(m_center_mouse_key_control); | ||
return center_mouse_key_layout; | ||
} | ||
|
||
QHBoxLayout* MouseSettingsWidget::CreateOctagonalMouseJailIsEnabledLayout() | ||
{ | ||
QHBoxLayout* octagonal_mouse_jail_is_enabled_layout = new QHBoxLayout{}; | ||
m_octagonal_mouse_jail_is_enabled_control = new QCheckBox{}; | ||
QString octagonal_mouse_jail_is_enabled_tool_tip = {tr( | ||
"Locks the mouse cursor into a simulated octagonal gate. \n(Think of the edge around a " | ||
"gamecube controller stick)\nLow sensitivity(under 2.0ish) may not feel like anything is " | ||
"happening. \nSomething is happening, the mouse gate is just REALLY big. \n(Try moving your " | ||
"mouse to the edge of the screen)" | ||
"\n\nSnapping is disabled if this is disabled" | ||
"\n\nLocking and snapping only occur when a game is started and focused" | ||
"\n\nYou can make the mouse cursor invisible at:" | ||
"\nConfig->Interface Tab->Mouse Cursor Visibility->Never" | ||
"\n(Lock Mouse Cursor locks mouse into the game window. \nDifferent and unreleated to the " | ||
"mouse notches)")}; | ||
m_octagonal_mouse_jail_is_enabled_control->setToolTip(octagonal_mouse_jail_is_enabled_tool_tip); | ||
QLabel* octagonal_mouse_jail_is_enabled_text = new QLabel{}; | ||
octagonal_mouse_jail_is_enabled_text->setText(tr("Mouse Notches")); | ||
octagonal_mouse_jail_is_enabled_text->setToolTip(octagonal_mouse_jail_is_enabled_tool_tip); | ||
octagonal_mouse_jail_is_enabled_layout->addWidget(octagonal_mouse_jail_is_enabled_text); | ||
octagonal_mouse_jail_is_enabled_layout->addWidget(m_octagonal_mouse_jail_is_enabled_control); | ||
return octagonal_mouse_jail_is_enabled_layout; | ||
} | ||
|
||
unsigned short MouseSettingsWidget::GetNextKeyCode() | ||
{ | ||
#ifdef _WIN32 | ||
static constexpr unsigned short highest_virtual_key_hex = 0xFE; | ||
while (true) | ||
{ | ||
QApplication::processEvents(); | ||
for (unsigned short i = 0; i < highest_virtual_key_hex; i++) | ||
{ | ||
if (GetAsyncKeyState(i) & 0x8000) | ||
{ | ||
if (i == VK_LBUTTON) | ||
{ | ||
continue; | ||
} | ||
return i; | ||
} | ||
} | ||
} | ||
#else | ||
return 0xFFFF; | ||
#endif | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#pragma once | ||
|
||
#include <QGroupBox> | ||
class QDoubleSpinBox; | ||
class MultiClickSignalButton; | ||
class QCheckBox; | ||
class QHBoxLayout; | ||
|
||
class MouseSettingsWidget final : public QGroupBox | ||
{ | ||
Q_OBJECT | ||
public: | ||
MouseSettingsWidget(QWidget* parent); | ||
|
||
private: | ||
void CreateLayout(); | ||
void ConnectWidgets(); | ||
|
||
void LoadSettings(); | ||
void SaveSettings(); | ||
|
||
QHBoxLayout* CreateSensitivityLayout(); | ||
QHBoxLayout* CreateSnappingDistanceLayout(); | ||
QHBoxLayout* CreateCenterMouseKeyLayout(); | ||
QHBoxLayout* CreateOctagonalMouseJailIsEnabledLayout(); | ||
|
||
// Gets the next key code pressed. | ||
// Returns 0xFFFF if unimplemented for the current build target. | ||
// | ||
// @return Next key code pressed as an unsigned short or 0xFFFF if unimplemented for current build | ||
// target | ||
unsigned short GetNextKeyCode(); | ||
|
||
QDoubleSpinBox* m_sensitivity_control = nullptr; | ||
QDoubleSpinBox* m_snapping_distance_control = nullptr; | ||
MultiClickSignalButton* m_center_mouse_key_control = nullptr; | ||
QCheckBox* m_octagonal_mouse_jail_is_enabled_control = nullptr; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.