summaryrefslogtreecommitdiff
path: root/window.c
diff options
context:
space:
mode:
authordarkvater <darkvater@openttd.org>2005-01-11 00:24:27 +0000
committerdarkvater <darkvater@openttd.org>2005-01-11 00:24:27 +0000
commit085563653fb49794ca2c0ef09f544b08a80012f9 (patch)
tree9cf6f972eeb8747ac28a93dd174c27b9117bde54 /window.c
parent38da06301d7543fa878821e6635b24d09eb4b076 (diff)
downloadopenttd-085563653fb49794ca2c0ef09f544b08a80012f9.tar.xz
(svn r1478) -Fix: [1099195] mouse-wheel in train replace window. Scrollbar1 and Scrollbar2 now work independently. You can only scroll on list and scrollbar itself; scrollbar must be next widget of the list.
-Fix: updated the few gui's that didn't have the scrollbar right after the listbox.
Diffstat (limited to 'window.c')
-rw-r--r--window.c26
1 files changed, 19 insertions, 7 deletions
diff --git a/window.c b/window.c
index 08604eb7e..0135fd8da 100644
--- a/window.c
+++ b/window.c
@@ -96,13 +96,25 @@ void DispatchRightClickEvent(Window *w, int x, int y) {
}
-void DispatchMouseWheelEvent(Window *w, int wheel)
+void DispatchMouseWheelEvent(Window *w, uint widget, int wheel)
{
- if (w->vscroll.count > w->vscroll.cap) {
- int pos = clamp(w->vscroll.pos + wheel, 0, w->vscroll.count - w->vscroll.cap);
- if (pos != w->vscroll.pos) {
- w->vscroll.pos = pos;
- SetWindowDirty(w);
+ const Widget *wi1 = &w->widget[widget];
+ const Widget *wi2 = &w->widget[widget + 1];
+ Scrollbar *sb;
+
+ /* The listbox can only scroll if scrolling was done on the scrollbar itself,
+ * or on the listbox (and the next item is (must be) the scrollbar)
+ * XXX - should be rewritten as a widget-dependent scroller but that's
+ * not happening until someone rewrites the whole widget-code */
+ if ((sb = &w->vscroll, wi1->type == WWT_SCROLLBAR) || (sb = &w->vscroll2, wi1->type == WWT_SCROLL2BAR) ||
+ (sb = &w->vscroll2, wi2->type == WWT_SCROLL2BAR) || (sb = &w->vscroll, wi2->type == WWT_SCROLLBAR) ) {
+
+ if (sb->count > sb->cap) {
+ int pos = clamp(sb->pos + wheel, 0, sb->count - sb->cap);
+ if (pos != sb->pos) {
+ sb->pos = pos;
+ SetWindowDirty(w);
+ }
}
}
}
@@ -1356,7 +1368,7 @@ void MouseLoop()
}
} else {
if (mousewheel)
- DispatchMouseWheelEvent(w, mousewheel);
+ DispatchMouseWheelEvent(w, GetWidgetFromPos(w, x - w->left, y - w->top), mousewheel);
if (click == 1)
DispatchLeftClickEvent(w, x - w->left, y - w->top);