summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordominik <dominik@openttd.org>2005-01-28 09:30:19 +0000
committerdominik <dominik@openttd.org>2005-01-28 09:30:19 +0000
commitb4b134e527cb09abbb6985d399afeb019a37a227 (patch)
tree13c8c5c9e34ceffa784392d5729cf1d9fb89b1be
parentc8d084a85e4eb2b20055cffc1bcbddf16b5e337f (diff)
downloadopenttd-b4b134e527cb09abbb6985d399afeb019a37a227.tar.xz
(svn r1703) - Fix: Scrolling with the arrow keys is now smooth and it now also scrolls exactly in tile direction if e.g. up and left are pressed
-rw-r--r--main_gui.c57
-rw-r--r--ttd.c5
2 files changed, 33 insertions, 29 deletions
diff --git a/main_gui.c b/main_gui.c
index 6deba6f1e..974c7b0b9 100644
--- a/main_gui.c
+++ b/main_gui.c
@@ -2201,7 +2201,7 @@ static void StatusBarWndProc(Window *w, WindowEvent *e)
}
}
-static void ScrollMainViewport(int x, int y)
+void ScrollMainViewport(int x, int y)
{
if (_game_mode != GM_MENU) {
Window *w = FindWindowById(WC_MAIN_WINDOW, 0);
@@ -2228,6 +2228,33 @@ static WindowDesc _main_status_desc = {
StatusBarWndProc
};
+static const int8 scrollamt[16][2] = {
+ { 0, 0},
+ {-2, 0}, // 1:left
+ { 0,-2}, // 2:up
+ {-2,-1}, // 3:left + up
+ { 2, 0}, // 4:right
+ { 0, 0}, // 5:left + right
+ { 2,-1}, // 6:right + up
+ { 0,-2}, // 7:left + right + up = up
+ { 0 ,2}, // 8:down
+ {-2 ,1}, // 9:down+left
+ { 0, 0}, // 10:impossible
+ {-2, 0}, // 11:left + up + down = left
+ { 2, 1}, // 12:down+right
+ { 0, 2}, // 13:left + right + down = down
+ { 0,-2}, // 14:left + right + up = up
+ { 0, 0}, // 15:impossible
+};
+
+void HandleKeyScrolling(void)
+{
+ if (_dirkeys) {
+ int factor = _shift_pressed ? 50 : 10;
+ ScrollMainViewport(scrollamt[_dirkeys][0] * factor, scrollamt[_dirkeys][1] * factor);
+ }
+}
+
extern void DebugProc(int i);
static void MainWindowWndProc(Window *w, WindowEvent *e) {
@@ -2272,34 +2299,6 @@ static void MainWindowWndProc(Window *w, WindowEvent *e) {
if (_game_mode == GM_MENU)
break;
- // this is a hack, but this needs to be called at a constant interval and i found
- // no other window event that was suited for that purpose.
- {
- static const int8 scrollamt[16][2] = {
- {0,0},
- {-1,0}, // 1:left
- {0,-1}, // 2:up
- {-1,-1}, // 3:left + up
- {1,0}, // 4:right
- {0,0}, // 5:left + right
- {1,-1}, // 6:right + up
- {0,0}, // 7:impossible
- {0,1}, // 8:down
- {-1,1}, // 9:down+left
- {0,0}, // 10:impossible
- {0,0}, // 11:impossible
- {1,1}, // 12:down+right
- {0,0}, // 13:impossible
- {0,0}, // 14:impossible
- {0,0}, // 15:impossible
- };
-
- if (_dirkeys) {
- int factor = _shift_pressed ? 50 : 10;
- ScrollMainViewport(scrollamt[_dirkeys][0] * factor, scrollamt[_dirkeys][1] * factor);
- }
- }
-
switch(e->keypress.keycode) {
case 'C':
case 'Z': {
diff --git a/ttd.c b/ttd.c
index 20c7798cd..0ebd341cf 100644
--- a/ttd.c
+++ b/ttd.c
@@ -1112,6 +1112,8 @@ static void DoAutosave(void)
ShowErrorMessage(INVALID_STRING_ID, STR_AUTOSAVE_FAILED, 0, 0);
}
+extern void HandleKeyScrolling(void);
+
void GameLoop(void)
{
int m;
@@ -1123,6 +1125,9 @@ void GameLoop(void)
RedrawAutosave();
}
+ // handle scrolling of the main window
+ if (_dirkeys) HandleKeyScrolling();
+
// make a screenshot?
if ((m=_make_screenshot) != 0) {
_make_screenshot = 0;