From 03ceb27e909e6cc6ce8364259c188d178dc59525 Mon Sep 17 00:00:00 2001 From: drh Date: Mon, 16 Dec 2024 22:08:20 +0000 Subject: [PATCH] Add camera pan inversion option Fixes: #6539 --- binaries/data/config/default.cfg | 1 + .../public/gui/credits/texts/programming.json | 1 + .../data/mods/public/gui/options/options.json | 14 +++++++++++++ source/graphics/CameraController.cpp | 21 ++++++++++++++++--- source/graphics/CameraController.h | 7 ++++++- 5 files changed, 40 insertions(+), 4 deletions(-) diff --git a/binaries/data/config/default.cfg b/binaries/data/config/default.cfg index 324461202f..22f05819ec 100644 --- a/binaries/data/config/default.cfg +++ b/binaries/data/config/default.cfg @@ -598,6 +598,7 @@ rotate.y.speed.wheel = 0.45 rotate.y.default = 0.0 rotate.speed.modifier = 1.05 ; Multiplier for changing rotation speed drag.speed = 0.5 +drag.inverted = false ; Pan in the opposite direction of drag movement zoom.speed = 256.0 zoom.speed.wheel = 32.0 zoom.min = 50.0 diff --git a/binaries/data/mods/public/gui/credits/texts/programming.json b/binaries/data/mods/public/gui/credits/texts/programming.json index 5dee992cd4..b2765580bd 100644 --- a/binaries/data/mods/public/gui/credits/texts/programming.json +++ b/binaries/data/mods/public/gui/credits/texts/programming.json @@ -83,6 +83,7 @@ { "nick": "DigitalSeraphim", "name": "Nick Owens" }, { "nick": "dp304" }, { "nick": "dpiquet", "name": "Damien Piquet" }, + { "nick": "drh", "name": "David Haynes" }, { "nick": "dumbo" }, { "nick": "Dunedan", "name": "Daniel Roschka" }, { "nick": "dvangennip", "name": "Doménique" }, diff --git a/binaries/data/mods/public/gui/options/options.json b/binaries/data/mods/public/gui/options/options.json index 3764410487..024d7fe2af 100644 --- a/binaries/data/mods/public/gui/options/options.json +++ b/binaries/data/mods/public/gui/options/options.json @@ -149,6 +149,20 @@ "min": "1", "max": "200" }, + { + "type": "boolean", + "label": "Mouse pan inverted", + "tooltip": "Invert middle-click drag pan direction.", + "config": "view.drag.inverted" + }, + { + "type": "slider", + "label": "Mouse pan speed", + "tooltip": "Speed mouse pans the map when holding middle-click and dragging.", + "config": "view.drag.speed", + "min": 0.01, + "max": 0.6 + }, { "type": "boolean", "label": "Mouse grab in fullscreen", diff --git a/source/graphics/CameraController.cpp b/source/graphics/CameraController.cpp index c1344744a5..1935a9f222 100644 --- a/source/graphics/CameraController.cpp +++ b/source/graphics/CameraController.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2024 Wildfire Games. +/* Copyright (C) 2025 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -68,6 +68,7 @@ CCameraController::CCameraController(CCamera& camera) m_ViewRotateYDefault(0), m_ViewRotateSpeedModifier(1), m_ViewDragSpeed(0), + m_ViewDragInverted(false), m_ViewZoomSpeed(0), m_ViewZoomSpeedWheel(0), m_ViewZoomMin(0), @@ -87,6 +88,13 @@ CCameraController::CCameraController(CCamera& camera) m_RotateX(0, 0, 0.001f), m_RotateY(0, 0, 0.001f) { + m_ViewDragInvertedConfigHook = std::make_unique(g_ConfigDB.RegisterHookAndCall("view.drag.inverted", [this]() { + CFG_GET_VAL("view.drag.inverted", m_ViewDragInverted); + })); + m_ViewDragSpeedConfigHook = std::make_unique(g_ConfigDB.RegisterHookAndCall("view.drag.speed", [this]() { + CFG_GET_VAL("view.drag.speed", m_ViewDragSpeed); + })); + SViewPort vp; vp.m_X = 0; vp.m_Y = 0; @@ -115,6 +123,7 @@ void CCameraController::LoadConfig() CFG_GET_VAL("view.rotate.y.default", m_ViewRotateYDefault); CFG_GET_VAL("view.rotate.speed.modifier", m_ViewRotateSpeedModifier); CFG_GET_VAL("view.drag.speed", m_ViewDragSpeed); + CFG_GET_VAL("view.drag.inverted", m_ViewDragInverted); CFG_GET_VAL("view.zoom.speed", m_ViewZoomSpeed); CFG_GET_VAL("view.zoom.speed.wheel", m_ViewZoomSpeedWheel); CFG_GET_VAL("view.zoom.min", m_ViewZoomMin); @@ -180,8 +189,14 @@ void CCameraController::Update(const float deltaRealTime) if (HotkeyIsPressed("camera.pan")) { - moveRightward += m_ViewDragSpeed * mouse_dx; - moveForward += m_ViewDragSpeed * -mouse_dy; + if (m_ViewDragInverted) { + moveRightward += m_ViewDragSpeed * -mouse_dx; + moveForward += m_ViewDragSpeed * mouse_dy; + } + else { + moveRightward += m_ViewDragSpeed * mouse_dx; + moveForward += m_ViewDragSpeed * -mouse_dy; + } } if (g_mouse_active && m_ViewScrollMouseDetectDistance > 0) diff --git a/source/graphics/CameraController.h b/source/graphics/CameraController.h index dc07f2efed..370ac8fe38 100644 --- a/source/graphics/CameraController.h +++ b/source/graphics/CameraController.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2022 Wildfire Games. +/* Copyright (C) 2025 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -20,6 +20,7 @@ #include "graphics/ICameraController.h" #include "graphics/SmoothedValue.h" +#include "ps/ConfigDB.h" class CCameraController : public ICameraController { @@ -99,6 +100,7 @@ private: float m_ViewRotateYDefault; float m_ViewRotateSpeedModifier; float m_ViewDragSpeed; + bool m_ViewDragInverted; float m_ViewZoomSpeed; float m_ViewZoomSpeedWheel; float m_ViewZoomMin; @@ -118,6 +120,9 @@ private: CSmoothedValue m_Zoom; CSmoothedValue m_RotateX; // inclination around x axis (relative to camera) CSmoothedValue m_RotateY; // rotation around y (vertical) axis + + std::unique_ptr m_ViewDragInvertedConfigHook; + std::unique_ptr m_ViewDragSpeedConfigHook; }; #endif // INCLUDED_CAMERACONTROLLER