mirror of
https://github.com/stenzek/duckstation.git
synced 2025-06-12 14:27:20 +00:00
FullscreenUI: Use system scroll rate and layout scale
Makes scrolling feel much more responsive, and doesn't vary depending on the size of the window.
This commit is contained in:
parent
38aebd0a3e
commit
29e55a2e5b
@ -345,7 +345,11 @@ bool DisplayWidget::event(QEvent* event)
|
|||||||
case QEvent::Wheel:
|
case QEvent::Wheel:
|
||||||
{
|
{
|
||||||
const QWheelEvent* wheel_event = static_cast<QWheelEvent*>(event);
|
const QWheelEvent* wheel_event = static_cast<QWheelEvent*>(event);
|
||||||
emit windowMouseWheelEvent(wheel_event->angleDelta());
|
const QPoint angle_delta = wheel_event->angleDelta();
|
||||||
|
const float dx = static_cast<float>(angle_delta.x()) / static_cast<float>(QWheelEvent::DefaultDeltasPerStep);
|
||||||
|
const float dy = (static_cast<float>(angle_delta.y()) / static_cast<float>(QWheelEvent::DefaultDeltasPerStep)) *
|
||||||
|
static_cast<float>(QApplication::wheelScrollLines());
|
||||||
|
emit windowMouseWheelEvent(dx, dy);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,7 +44,7 @@ Q_SIGNALS:
|
|||||||
void windowKeyEvent(int key_code, bool pressed);
|
void windowKeyEvent(int key_code, bool pressed);
|
||||||
void windowTextEntered(const QString& text);
|
void windowTextEntered(const QString& text);
|
||||||
void windowMouseButtonEvent(int button, bool pressed);
|
void windowMouseButtonEvent(int button, bool pressed);
|
||||||
void windowMouseWheelEvent(const QPoint& angle_delta);
|
void windowMouseWheelEvent(float dx, float dy);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool event(QEvent* event) override;
|
bool event(QEvent* event) override;
|
||||||
|
@ -97,7 +97,8 @@ bool InputBindingDialog::eventFilter(QObject* watched, QEvent* event)
|
|||||||
else if (event_type == QEvent::Wheel)
|
else if (event_type == QEvent::Wheel)
|
||||||
{
|
{
|
||||||
const QPoint delta_angle(static_cast<QWheelEvent*>(event)->angleDelta());
|
const QPoint delta_angle(static_cast<QWheelEvent*>(event)->angleDelta());
|
||||||
const float dx = std::clamp(static_cast<float>(delta_angle.x()) / QtUtils::MOUSE_WHEEL_DELTA, -1.0f, 1.0f);
|
const float dx = std::clamp(
|
||||||
|
static_cast<float>(delta_angle.x()) / static_cast<float>(QWheelEvent::DefaultDeltasPerStep), -1.0f, 1.0f);
|
||||||
if (dx != 0.0f)
|
if (dx != 0.0f)
|
||||||
{
|
{
|
||||||
InputBindingKey key(InputManager::MakePointerAxisKey(0, InputPointerAxis::WheelX));
|
InputBindingKey key(InputManager::MakePointerAxisKey(0, InputPointerAxis::WheelX));
|
||||||
@ -105,7 +106,8 @@ bool InputBindingDialog::eventFilter(QObject* watched, QEvent* event)
|
|||||||
m_new_bindings.push_back(key);
|
m_new_bindings.push_back(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
const float dy = std::clamp(static_cast<float>(delta_angle.y()) / QtUtils::MOUSE_WHEEL_DELTA, -1.0f, 1.0f);
|
const float dy = std::clamp(
|
||||||
|
static_cast<float>(delta_angle.y()) / static_cast<float>(QWheelEvent::DefaultDeltasPerStep), -1.0f, 1.0f);
|
||||||
if (dy != 0.0f)
|
if (dy != 0.0f)
|
||||||
{
|
{
|
||||||
InputBindingKey key(InputManager::MakePointerAxisKey(0, InputPointerAxis::WheelY));
|
InputBindingKey key(InputManager::MakePointerAxisKey(0, InputPointerAxis::WheelY));
|
||||||
|
@ -124,7 +124,8 @@ bool InputBindingWidget::eventFilter(QObject* watched, QEvent* event)
|
|||||||
else if (event_type == QEvent::Wheel)
|
else if (event_type == QEvent::Wheel)
|
||||||
{
|
{
|
||||||
const QPoint delta_angle(static_cast<QWheelEvent*>(event)->angleDelta());
|
const QPoint delta_angle(static_cast<QWheelEvent*>(event)->angleDelta());
|
||||||
const float dx = std::clamp(static_cast<float>(delta_angle.x()) / QtUtils::MOUSE_WHEEL_DELTA, -1.0f, 1.0f);
|
const float dx = std::clamp(
|
||||||
|
static_cast<float>(delta_angle.x()) / static_cast<float>(QWheelEvent::DefaultDeltasPerStep), -1.0f, 1.0f);
|
||||||
if (dx != 0.0f)
|
if (dx != 0.0f)
|
||||||
{
|
{
|
||||||
InputBindingKey key(InputManager::MakePointerAxisKey(0, InputPointerAxis::WheelX));
|
InputBindingKey key(InputManager::MakePointerAxisKey(0, InputPointerAxis::WheelX));
|
||||||
@ -132,7 +133,8 @@ bool InputBindingWidget::eventFilter(QObject* watched, QEvent* event)
|
|||||||
m_new_bindings.push_back(key);
|
m_new_bindings.push_back(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
const float dy = std::clamp(static_cast<float>(delta_angle.y()) / QtUtils::MOUSE_WHEEL_DELTA, -1.0f, 1.0f);
|
const float dy = std::clamp(
|
||||||
|
static_cast<float>(delta_angle.y()) / static_cast<float>(QWheelEvent::DefaultDeltasPerStep), -1.0f, 1.0f);
|
||||||
if (dy != 0.0f)
|
if (dy != 0.0f)
|
||||||
{
|
{
|
||||||
InputBindingKey key(InputManager::MakePointerAxisKey(0, InputPointerAxis::WheelY));
|
InputBindingKey key(InputManager::MakePointerAxisKey(0, InputPointerAxis::WheelY));
|
||||||
|
@ -903,15 +903,13 @@ void EmuThread::onDisplayWindowMouseButtonEvent(int button, bool pressed)
|
|||||||
GenericInputBinding::Unknown);
|
GenericInputBinding::Unknown);
|
||||||
}
|
}
|
||||||
|
|
||||||
void EmuThread::onDisplayWindowMouseWheelEvent(const QPoint& delta_angle)
|
void EmuThread::onDisplayWindowMouseWheelEvent(float dx, float dy)
|
||||||
{
|
{
|
||||||
DebugAssert(isCurrentThread());
|
DebugAssert(isCurrentThread());
|
||||||
|
|
||||||
const float dx = std::clamp(static_cast<float>(delta_angle.x()) / QtUtils::MOUSE_WHEEL_DELTA, -1.0f, 1.0f);
|
|
||||||
if (dx != 0.0f)
|
if (dx != 0.0f)
|
||||||
InputManager::UpdatePointerRelativeDelta(0, InputPointerAxis::WheelX, dx);
|
InputManager::UpdatePointerRelativeDelta(0, InputPointerAxis::WheelX, dx);
|
||||||
|
|
||||||
const float dy = std::clamp(static_cast<float>(delta_angle.y()) / QtUtils::MOUSE_WHEEL_DELTA, -1.0f, 1.0f);
|
|
||||||
if (dy != 0.0f)
|
if (dy != 0.0f)
|
||||||
InputManager::UpdatePointerRelativeDelta(0, InputPointerAxis::WheelY, dy);
|
InputManager::UpdatePointerRelativeDelta(0, InputPointerAxis::WheelY, dy);
|
||||||
}
|
}
|
||||||
|
@ -223,7 +223,7 @@ public Q_SLOTS:
|
|||||||
private Q_SLOTS:
|
private Q_SLOTS:
|
||||||
void stopInThread();
|
void stopInThread();
|
||||||
void onDisplayWindowMouseButtonEvent(int button, bool pressed);
|
void onDisplayWindowMouseButtonEvent(int button, bool pressed);
|
||||||
void onDisplayWindowMouseWheelEvent(const QPoint& delta_angle);
|
void onDisplayWindowMouseWheelEvent(float dx, float dy);
|
||||||
void onDisplayWindowResized(int width, int height, float scale);
|
void onDisplayWindowResized(int width, int height, float scale);
|
||||||
void onDisplayWindowKeyEvent(int key, bool pressed);
|
void onDisplayWindowKeyEvent(int key, bool pressed);
|
||||||
void onDisplayWindowTextEntered(const QString& text);
|
void onDisplayWindowTextEntered(const QString& text);
|
||||||
|
@ -45,9 +45,6 @@ enum class EntryType : u8;
|
|||||||
|
|
||||||
namespace QtUtils {
|
namespace QtUtils {
|
||||||
|
|
||||||
/// Wheel delta is 120 as in winapi.
|
|
||||||
static constexpr float MOUSE_WHEEL_DELTA = 120.0f;
|
|
||||||
|
|
||||||
/// Creates a horizontal line widget.
|
/// Creates a horizontal line widget.
|
||||||
QFrame* CreateHorizontalLine(QWidget* parent);
|
QFrame* CreateHorizontalLine(QWidget* parent);
|
||||||
|
|
||||||
|
@ -808,6 +808,7 @@ void ImGuiFullscreen::PushResetLayout()
|
|||||||
ImGui::PushStyleVar(ImGuiStyleVar_GrabMinSize, LayoutScale(10.0f));
|
ImGui::PushStyleVar(ImGuiStyleVar_GrabMinSize, LayoutScale(10.0f));
|
||||||
ImGui::PushStyleVar(ImGuiStyleVar_TabRounding, LayoutScale(4.0f));
|
ImGui::PushStyleVar(ImGuiStyleVar_TabRounding, LayoutScale(4.0f));
|
||||||
ImGui::PushStyleVar(ImGuiStyleVar_ScrollSmooth, UIStyle.SmoothScrolling ? SMOOTH_SCROLLING_SPEED : 1.0f);
|
ImGui::PushStyleVar(ImGuiStyleVar_ScrollSmooth, UIStyle.SmoothScrolling ? SMOOTH_SCROLLING_SPEED : 1.0f);
|
||||||
|
ImGui::PushStyleVar(ImGuiStyleVar_ScrollStepSize, LayoutScale(LAYOUT_LARGE_FONT_SIZE, LAYOUT_MENU_BUTTON_HEIGHT));
|
||||||
ImGui::PushStyleColor(ImGuiCol_Text, UIStyle.SecondaryTextColor);
|
ImGui::PushStyleColor(ImGuiCol_Text, UIStyle.SecondaryTextColor);
|
||||||
ImGui::PushStyleColor(ImGuiCol_TextDisabled, UIStyle.DisabledColor);
|
ImGui::PushStyleColor(ImGuiCol_TextDisabled, UIStyle.DisabledColor);
|
||||||
ImGui::PushStyleColor(ImGuiCol_Button, UIStyle.SecondaryColor);
|
ImGui::PushStyleColor(ImGuiCol_Button, UIStyle.SecondaryColor);
|
||||||
@ -825,7 +826,7 @@ void ImGuiFullscreen::PushResetLayout()
|
|||||||
void ImGuiFullscreen::PopResetLayout()
|
void ImGuiFullscreen::PopResetLayout()
|
||||||
{
|
{
|
||||||
ImGui::PopStyleColor(12);
|
ImGui::PopStyleColor(12);
|
||||||
ImGui::PopStyleVar(13);
|
ImGui::PopStyleVar(14);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ImGuiFullscreen::QueueResetFocus(FocusResetType type)
|
void ImGuiFullscreen::QueueResetFocus(FocusResetType type)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user