From f6b17149c6650036361ef2d3441788960b9d4aa0 Mon Sep 17 00:00:00 2001 From: truelight Date: Mon, 21 Aug 2006 14:34:59 +0000 Subject: [PATCH] (svn r6036) -Codechange: do not handle SCROLL in a central function, but let windows handle them theirself. Added WE_SCROLL for this. --- main_gui.c | 12 +++++++ smallmap_gui.c | 73 ++++++++++++++++++++++++++++++++++++++++ window.c | 91 ++++++-------------------------------------------- window.h | 8 ++++- 4 files changed, 103 insertions(+), 81 deletions(-) diff --git a/main_gui.c b/main_gui.c index 3a9564d08f..2e0653de9b 100644 --- a/main_gui.c +++ b/main_gui.c @@ -2317,6 +2317,18 @@ static void MainWindowWndProc(Window *w, WindowEvent *e) } e->keypress.cont = false; break; + + case WE_SCROLL: { + ViewPort *vp = IsPtInWindowViewport(w, _cursor.pos.x, _cursor.pos.y); + + if (vp == NULL) { + _cursor.fix_at = false; + _scrolling_viewport = false; + } + + WP(w, vp_d).scrollpos_x += e->scroll.delta.x << vp->zoom; + WP(w, vp_d).scrollpos_y += e->scroll.delta.y << vp->zoom; + } break; } } diff --git a/smallmap_gui.c b/smallmap_gui.c index 7e71e77aeb..dbec6036d3 100644 --- a/smallmap_gui.c +++ b/smallmap_gui.c @@ -882,6 +882,67 @@ static void SmallMapWindowProc(Window *w, WindowEvent *e) /* update the window every now and then */ if ((++w->vscroll.pos & 0x1F) == 0) SetWindowDirty(w); break; + + case WE_SCROLL: { + int x; + int y; + int sub; + int hx; + int hy; + int hvx; + int hvy; + + _cursor.fix_at = true; + + x = WP(w, smallmap_d).scroll_x; + y = WP(w, smallmap_d).scroll_y; + + sub = WP(w, smallmap_d).subscroll + e->scroll.delta.x; + + x -= (sub >> 2) << 4; + y += (sub >> 2) << 4; + sub &= 3; + + x += (e->scroll.delta.y >> 1) << 4; + y += (e->scroll.delta.y >> 1) << 4; + + if (e->scroll.delta.y & 1) { + x += TILE_SIZE; + sub += 2; + if (sub > 3) { + sub -= 4; + x -= TILE_SIZE; + y += TILE_SIZE; + } + } + + hx = (w->widget[4].right - w->widget[4].left) / 2; + hy = (w->widget[4].bottom - w->widget[4].top ) / 2; + hvx = hx * -4 + hy * 8; + hvy = hx * 4 + hy * 8; + if (x < -hvx) { + x = -hvx; + sub = 0; + } + if (x > (int)MapMaxX() * TILE_SIZE - hvx) { + x = MapMaxX() * TILE_SIZE - hvx; + sub = 0; + } + if (y < -hvy) { + y = -hvy; + sub = 0; + } + if (y > (int)MapMaxY() * TILE_SIZE - hvy) { + y = MapMaxY() * TILE_SIZE - hvy; + sub = 0; + } + + WP(w, smallmap_d).scroll_x = x; + WP(w, smallmap_d).scroll_y = y; + WP(w, smallmap_d).subscroll = sub; + + SetWindowDirty(w); + } break; } } @@ -979,6 +1040,18 @@ static void ExtraViewPortWndProc(Window *w, WindowEvent *e) w->viewport->virtual_width += e->sizing.diff.x; w->viewport->virtual_height += e->sizing.diff.y; break; + + case WE_SCROLL: { + ViewPort *vp = IsPtInWindowViewport(w, _cursor.pos.x, _cursor.pos.y); + + if (vp == NULL) { + _cursor.fix_at = false; + _scrolling_viewport = false; + } + + WP(w, vp_d).scrollpos_x += e->scroll.delta.x << vp->zoom; + WP(w, vp_d).scrollpos_y += e->scroll.delta.y << vp->zoom; + } break; } } diff --git a/window.c b/window.c index b22629b33d..c281724624 100644 --- a/window.c +++ b/window.c @@ -1146,99 +1146,30 @@ static bool HandleScrollbarScrolling(void) static bool HandleViewportScroll(void) { + WindowEvent we; Window *w; - int dx; - int dy; if (!_scrolling_viewport) return true; - if (!_right_button_down) { -stop_capt:; + w = FindWindowFromPt(_cursor.pos.x, _cursor.pos.y); + + if (!_right_button_down || w == NULL) { _cursor.fix_at = false; _scrolling_viewport = false; return true; } - w = FindWindowFromPt(_cursor.pos.x, _cursor.pos.y); - if (w == NULL) goto stop_capt; - if (_patches.reverse_scroll) { - dx = -_cursor.delta.x; - dy = -_cursor.delta.y; + we.scroll.delta.x = -_cursor.delta.x; + we.scroll.delta.y = -_cursor.delta.y; } else { - dx = _cursor.delta.x; - dy = _cursor.delta.y; + we.scroll.delta.x = _cursor.delta.x; + we.scroll.delta.y = _cursor.delta.y; } - if (w->window_class != WC_SMALLMAP) { - ViewPort *vp = IsPtInWindowViewport(w, _cursor.pos.x, _cursor.pos.y); - - if (vp == NULL) - goto stop_capt; - - WP(w,vp_d).scrollpos_x += dx << vp->zoom; - WP(w,vp_d).scrollpos_y += dy << vp->zoom; - - } else { - int x; - int y; - int sub; - int hx; - int hy; - int hvx; - int hvy; - - _cursor.fix_at = true; - - x = WP(w,smallmap_d).scroll_x; - y = WP(w,smallmap_d).scroll_y; - - sub = WP(w,smallmap_d).subscroll + dx; - - x -= (sub >> 2) << 4; - y += (sub >> 2) << 4; - sub &= 3; - - x += (dy >> 1) << 4; - y += (dy >> 1) << 4; - - if (dy & 1) { - x += TILE_SIZE; - sub += 2; - if (sub > 3) { - sub -= 4; - x -= TILE_SIZE; - y += TILE_SIZE; - } - } - - hx = (w->widget[4].right - w->widget[4].left) / 2; - hy = (w->widget[4].bottom - w->widget[4].top ) / 2; - hvx = hx * -4 + hy * 8; - hvy = hx * 4 + hy * 8; - if (x < -hvx) { - x = -hvx; - sub = 0; - } - if (x > (int)MapMaxX() * TILE_SIZE - hvx) { - x = MapMaxX() * TILE_SIZE - hvx; - sub = 0; - } - if (y < -hvy) { - y = -hvy; - sub = 0; - } - if (y > (int)MapMaxY() * TILE_SIZE - hvy) { - y = MapMaxY() * TILE_SIZE - hvy; - sub = 0; - } - - WP(w,smallmap_d).scroll_x = x; - WP(w,smallmap_d).scroll_y = y; - WP(w,smallmap_d).subscroll = sub; - - SetWindowDirty(w); - } + /* Create a scroll-event and send it to the window */ + we.event = WE_SCROLL; + w->wndproc(w, &we); _cursor.delta.x = 0; _cursor.delta.y = 0; diff --git a/window.h b/window.h index 6dff1d9679..9bdfc1bceb 100644 --- a/window.h +++ b/window.h @@ -136,6 +136,11 @@ union WindowEvent { uint wparam; // additional message-specific information uint lparam; // additional message-specific information } message; + + struct { + byte event; + Point delta; // delta position against position of last call + } scroll; }; enum WindowKeyCodes { @@ -506,7 +511,8 @@ enum WindowEvents { WE_MOUSEOVER = 20, WE_ON_EDIT_TEXT_CANCEL = 21, WE_RESIZE = 22, - WE_MESSAGE = 23 + WE_MESSAGE = 23, + WE_SCROLL = 24, };