(svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that

-Codechange: use always 'e' for WindowsEvent, neverr 'we'
This commit is contained in:
truelight 2006-08-21 14:59:58 +00:00
parent 305d6eeaef
commit 2849e4fea9
4 changed files with 60 additions and 40 deletions

View File

@ -2329,6 +2329,10 @@ static void MainWindowWndProc(Window *w, WindowEvent *e)
WP(w, vp_d).scrollpos_x += e->scroll.delta.x << vp->zoom; WP(w, vp_d).scrollpos_x += e->scroll.delta.x << vp->zoom;
WP(w, vp_d).scrollpos_y += e->scroll.delta.y << vp->zoom; WP(w, vp_d).scrollpos_y += e->scroll.delta.y << vp->zoom;
} break; } break;
case WE_MOUSEWHEEL:
ZoomInOrOutToCursorWindow(e->wheel.wheel < 0, w);
break;
} }
} }

View File

@ -1052,6 +1052,10 @@ static void ExtraViewPortWndProc(Window *w, WindowEvent *e)
WP(w, vp_d).scrollpos_x += e->scroll.delta.x << vp->zoom; WP(w, vp_d).scrollpos_x += e->scroll.delta.x << vp->zoom;
WP(w, vp_d).scrollpos_y += e->scroll.delta.y << vp->zoom; WP(w, vp_d).scrollpos_y += e->scroll.delta.y << vp->zoom;
} break; } break;
case WE_MOUSEWHEEL:
ZoomInOrOutToCursorWindow(e->wheel.wheel < 0, w);
break;
} }
} }

View File

@ -1146,7 +1146,7 @@ static bool HandleScrollbarScrolling(void)
static bool HandleViewportScroll(void) static bool HandleViewportScroll(void)
{ {
WindowEvent we; WindowEvent e;
Window *w; Window *w;
if (!_scrolling_viewport) return true; if (!_scrolling_viewport) return true;
@ -1160,16 +1160,16 @@ static bool HandleViewportScroll(void)
} }
if (_patches.reverse_scroll) { if (_patches.reverse_scroll) {
we.scroll.delta.x = -_cursor.delta.x; e.scroll.delta.x = -_cursor.delta.x;
we.scroll.delta.y = -_cursor.delta.y; e.scroll.delta.y = -_cursor.delta.y;
} else { } else {
we.scroll.delta.x = _cursor.delta.x; e.scroll.delta.x = _cursor.delta.x;
we.scroll.delta.y = _cursor.delta.y; e.scroll.delta.y = _cursor.delta.y;
} }
/* Create a scroll-event and send it to the window */ /* Create a scroll-event and send it to the window */
we.event = WE_SCROLL; e.event = WE_SCROLL;
w->wndproc(w, &we); w->wndproc(w, &e);
_cursor.delta.x = 0; _cursor.delta.x = 0;
_cursor.delta.y = 0; _cursor.delta.y = 0;
@ -1339,19 +1339,25 @@ static void MouseLoop(int click, int mousewheel)
if (w == NULL) return; if (w == NULL) return;
w = MaybeBringWindowToFront(w); w = MaybeBringWindowToFront(w);
vp = IsPtInWindowViewport(w, x, y); vp = IsPtInWindowViewport(w, x, y);
if (vp != NULL) {
if (_game_mode == GM_MENU || IsGeneratingWorld()) return;
// only allow zooming in-out in main window, or in viewports /* Don't allow any action in a viewport if either in menu of in generating world */
if (mousewheel && if (vp != NULL && (_game_mode == GM_MENU || IsGeneratingWorld())) return;
!(w->flags4 & WF_DISABLE_VP_SCROLL) && (
w->window_class == WC_MAIN_WINDOW || if (mousewheel != 0) {
w->window_class == WC_EXTRA_VIEW_PORT WindowEvent e;
)) {
ZoomInOrOutToCursorWindow(mousewheel < 0,w); /* Send WE_MOUSEWHEEL event to window */
e.event = WE_MOUSEWHEEL;
e.wheel.wheel = mousewheel;
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 (click == 1) { if (vp != NULL) {
switch (click) {
case 1:
DEBUG(misc, 2) ("cursor: 0x%X (%d)", _cursor.sprite, _cursor.sprite); DEBUG(misc, 2) ("cursor: 0x%X (%d)", _cursor.sprite, _cursor.sprite);
if (_thd.place_mode != 0 && if (_thd.place_mode != 0 &&
// query button and place sign button work in pause mode // query button and place sign button work in pause mode
@ -1367,16 +1373,16 @@ static void MouseLoop(int click, int mousewheel)
} else { } else {
PlaceObject(); PlaceObject();
} }
} else if (click == 2) { break;
case 2:
if (!(w->flags4 & WF_DISABLE_VP_SCROLL)) { if (!(w->flags4 & WF_DISABLE_VP_SCROLL)) {
_scrolling_viewport = true; _scrolling_viewport = true;
_cursor.fix_at = true; _cursor.fix_at = true;
} }
break;
} }
} else { } else {
if (mousewheel)
DispatchMouseWheelEvent(w, GetWidgetFromPos(w, x - w->left, y - w->top), mousewheel);
switch (click) { switch (click) {
case 1: DispatchLeftClickEvent(w, x - w->left, y - w->top); break; case 1: DispatchLeftClickEvent(w, x - w->left, y - w->top); break;
case 2: DispatchRightClickEvent(w, x - w->left, y - w->top); break; case 2: DispatchRightClickEvent(w, x - w->left, y - w->top); break;

View File

@ -141,6 +141,11 @@ union WindowEvent {
byte event; byte event;
Point delta; // delta position against position of last call Point delta; // delta position against position of last call
} scroll; } scroll;
struct {
byte event;
int wheel; // how much was 'wheel'd'
} wheel;
}; };
enum WindowKeyCodes { enum WindowKeyCodes {
@ -513,6 +518,7 @@ enum WindowEvents {
WE_RESIZE = 22, WE_RESIZE = 22,
WE_MESSAGE = 23, WE_MESSAGE = 23,
WE_SCROLL = 24, WE_SCROLL = 24,
WE_MOUSEWHEEL = 25,
}; };