summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbjarni <bjarni@openttd.org>2007-03-11 10:55:35 +0000
committerbjarni <bjarni@openttd.org>2007-03-11 10:55:35 +0000
commit50fe0fe059c0dd3af5acdfdfee144e10dc678157 (patch)
treeb5331cf55f4eaf3f50d7092f65b2f19db44884e0
parent6def45089d56bb59d87f0757807b3522980389d3 (diff)
downloadopenttd-50fe0fe059c0dd3af5acdfdfee144e10dc678157.tar.xz
(svn r9111) -Feature: [OSX] mighty mice and touchpads can now scroll the map (in all directions)
It has to be enabled first (in patches->interface) first and this will disable scrollwheel zooming Note: patch setting "Map scrollwheel speed" might need to be changed since the "correct" setting appears to depend on what kind of mouse is in use (mighty mouse or touchpad)
-rw-r--r--src/gfx.h7
-rw-r--r--src/lang/english.txt4
-rw-r--r--src/settings.cpp2
-rw-r--r--src/settings_gui.cpp7
-rw-r--r--src/variables.h2
-rw-r--r--src/video/cocoa_v.mm5
-rw-r--r--src/window.cpp18
7 files changed, 42 insertions, 3 deletions
diff --git a/src/gfx.h b/src/gfx.h
index 3a3269d41..ed5046e32 100644
--- a/src/gfx.h
+++ b/src/gfx.h
@@ -5,6 +5,7 @@
#ifndef GFX_H
#define GFX_H
+#include "openttd.h"
enum WindowKeyCodes {
WKC_SHIFT = 0x8000,
@@ -115,6 +116,12 @@ struct CursorVars {
SpriteID pal;
int wheel; ///< mouse wheel movement
+
+ /* We need two different vars to keep track of how far the scrollwheel moved.
+ * OSX uses this for scrolling around the map. */
+ int v_wheel;
+ int h_wheel;
+
const AnimCursor *animate_list; ///< in case of animated cursor, list of frames
const AnimCursor *animate_cur; ///< in case of animated cursor, current frame
uint animate_timeout; ///< in case of animated cursor, number of ticks to show the current cursor
diff --git a/src/lang/english.txt b/src/lang/english.txt
index e1e8b9c7b..b1f6012e0 100644
--- a/src/lang/english.txt
+++ b/src/lang/english.txt
@@ -1090,6 +1090,10 @@ STR_CONFIG_PATCHES_LIVERIES_NONE :None
STR_CONFIG_PATCHES_LIVERIES_OWN :Own company
STR_CONFIG_PATCHES_LIVERIES_ALL :All companies
STR_CONFIG_PATCHES_PREFER_TEAMCHAT :{LTBLUE}Prefer team chat with <ENTER>: {ORANGE}{STRING1}
+STR_CONFIG_PATCHES_SCROLLWHEEL_SCROLLING :{LTBLUE}Function of scrollwheel: {ORANGE}{STRING1}
+STR_CONFIG_PATCHES_SCROLLWHEEL_ZOOM :Zoom map
+STR_CONFIG_PATCHES_SCROLLWHEEL_SCROLL :Scroll map
+STR_CONFIG_PATCHES_SCROLLWHEEL_MULTIPLIER :{LTBLUE}Map scrollwheel speed: {ORANGE}{STRING1}
STR_CONFIG_PATCHES_MAX_TRAINS :{LTBLUE}Max trains per player: {ORANGE}{STRING1}
STR_CONFIG_PATCHES_MAX_ROADVEH :{LTBLUE}Max road vehicles per player: {ORANGE}{STRING1}
diff --git a/src/settings.cpp b/src/settings.cpp
index 613156945..78b733857 100644
--- a/src/settings.cpp
+++ b/src/settings.cpp
@@ -1283,6 +1283,8 @@ const SettingDesc _patch_settings[] = {
SDT_BOOL(Patches, link_terraform_toolbar, S, 0, false, STR_CONFIG_PATCHES_LINK_TERRAFORM_TOOLBAR,NULL),
SDT_VAR(Patches, liveries, SLE_UINT8, S,MS, 2, 0, 2, 0, STR_CONFIG_PATCHES_LIVERIES, RedrawScreen),
SDT_BOOL(Patches, prefer_teamchat, S, 0, false, STR_CONFIG_PATCHES_PREFER_TEAMCHAT, NULL),
+ SDT_VAR(Patches, scrollwheel_scrolling,SLE_UINT8,S,MS, 1, 0, 1, 0, STR_CONFIG_PATCHES_SCROLLWHEEL_SCROLLING, NULL),
+ SDT_VAR(Patches,scrollwheel_multiplier,SLE_UINT8,S, 0, 5, 1, 15, 1, STR_CONFIG_PATCHES_SCROLLWHEEL_MULTIPLIER,NULL),
/***************************************************************************/
/* Construction section of the GUI-configure patches window */
diff --git a/src/settings_gui.cpp b/src/settings_gui.cpp
index 53cf59575..93b0cf78d 100644
--- a/src/settings_gui.cpp
+++ b/src/settings_gui.cpp
@@ -575,6 +575,13 @@ static const char *_patches_ui[] = {
"link_terraform_toolbar",
"liveries",
"prefer_teamchat",
+#if defined(__APPLE__)
+ /* While the horizontal scrollwheel scrolling is written as general code, only
+ * the cocoa (OSX) driver generates input for it.
+ * Until some other driver will read this input, we will hide the GUI to control this from other systems. */
+ "scrollwheel_scrolling",
+ "scrollwheel_multiplier",
+#endif
};
static const char *_patches_construction[] = {
diff --git a/src/variables.h b/src/variables.h
index 4607947d1..ef5e9b73c 100644
--- a/src/variables.h
+++ b/src/variables.h
@@ -221,6 +221,8 @@ struct Patches {
/** YAPF settings */
YapfSettings yapf;
+ uint8 scrollwheel_scrolling;
+ uint8 scrollwheel_multiplier;
};
VARDEF Patches _patches;
diff --git a/src/video/cocoa_v.mm b/src/video/cocoa_v.mm
index e7531edbf..d4ae4c3e0 100644
--- a/src/video/cocoa_v.mm
+++ b/src/video/cocoa_v.mm
@@ -68,6 +68,7 @@ extern "C" void HideMenuBar();
#include "../debug.h"
#include "../macros.h"
#include "../os/macosx/splash.h"
+#include "../variables.h"
#include "cocoa_v.h"
#include "cocoa_keys.h"
@@ -653,6 +654,10 @@ static bool QZ_PollEvent()
} else if ([ event deltaY ] < 0.0) { /* Scroll down */
_cursor.wheel++;
} /* else: deltaY was 0.0 and we don't want to do anything */
+
+ /* Set the scroll count for scrollwheel scrolling */
+ _cursor.h_wheel -= (int)([ event deltaX ]* 5 * _patches.scrollwheel_multiplier);
+ _cursor.v_wheel -= (int)([ event deltaY ]* 5 * _patches.scrollwheel_multiplier);
break;
default:
diff --git a/src/window.cpp b/src/window.cpp
index 9e26bee1d..41653e926 100644
--- a/src/window.cpp
+++ b/src/window.cpp
@@ -1390,11 +1390,13 @@ static bool HandleViewportScroll()
WindowEvent e;
Window *w;
+ bool scrollwheel_scrolling = _patches.scrollwheel_scrolling == 1 && (_cursor.v_wheel != 0 || _cursor.h_wheel != 0);
+
if (!_scrolling_viewport) return true;
w = FindWindowFromPt(_cursor.pos.x, _cursor.pos.y);
- if (!_right_button_down || w == NULL) {
+ if (!(_right_button_down || scrollwheel_scrolling) || w == NULL) {
_cursor.fix_at = false;
_scrolling_viewport = false;
return true;
@@ -1408,6 +1410,14 @@ static bool HandleViewportScroll()
e.we.scroll.delta.y = _cursor.delta.y;
}
+ if (scrollwheel_scrolling) {
+ /* We are using scrollwheels for scrolling */
+ e.we.scroll.delta.x = _cursor.h_wheel;
+ e.we.scroll.delta.y = _cursor.v_wheel;
+ _cursor.v_wheel = 0;
+ _cursor.h_wheel = 0;
+ }
+
/* Create a scroll-event and send it to the window */
e.event = WE_SCROLL;
w->wndproc(w, &e);
@@ -1628,6 +1638,7 @@ void MouseLoop(int click, int mousewheel)
int x,y;
Window *w;
ViewPort *vp;
+ bool scrollwheel_scrolling = _patches.scrollwheel_scrolling == 1 && (_cursor.v_wheel != 0 || _cursor.h_wheel != 0);
DecreaseWindowCounters();
HandlePlacePresize();
@@ -1643,7 +1654,7 @@ void MouseLoop(int click, int mousewheel)
x = _cursor.pos.x;
y = _cursor.pos.y;
- if (click == 0 && mousewheel == 0) return;
+ if (click == 0 && mousewheel == 0 && !scrollwheel_scrolling) return;
w = FindWindowFromPt(x, y);
if (w == NULL) return;
@@ -1659,13 +1670,14 @@ void MouseLoop(int click, int mousewheel)
/* Send WE_MOUSEWHEEL event to window */
e.event = WE_MOUSEWHEEL;
e.we.wheel.wheel = mousewheel;
- w->wndproc(w, &e);
+ if (!scrollwheel_scrolling) w->wndproc(w, &e);
/* Dispatch a MouseWheelEvent for widgets if it is not a viewport */
if (vp == NULL) DispatchMouseWheelEvent(w, GetWidgetFromPos(w, x - w->left, y - w->top), mousewheel);
}
if (vp != NULL) {
+ if (scrollwheel_scrolling) click = 2; // we are using the scrollwheel in a viewport, so we emulate right mouse button
switch (click) {
case 1:
DEBUG(misc, 2, "Cursor: 0x%X (%d)", _cursor.sprite, _cursor.sprite);