summaryrefslogtreecommitdiff
path: root/src/widgets
diff options
context:
space:
mode:
authorpeter1138 <peter1138@openttd.org>2008-01-15 16:30:08 +0000
committerpeter1138 <peter1138@openttd.org>2008-01-15 16:30:08 +0000
commitab7cb0804de68b015dcc774a4fbcc82e356d2c87 (patch)
tree3e30c579b7b341732ed32cf39b01997d5bc220a5 /src/widgets
parent245f05a7cc3b333387da0d31b7f797bebf0720fb (diff)
downloadopenttd-ab7cb0804de68b015dcc774a4fbcc82e356d2c87.tar.xz
(svn r11865) -Feature(tte): Support scrolling of drop down lists when in drag mode by moving the pointer above or below the list.
Diffstat (limited to 'src/widgets')
-rw-r--r--src/widgets/dropdown.cpp23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/widgets/dropdown.cpp b/src/widgets/dropdown.cpp
index 9488216be..bed6895ed 100644
--- a/src/widgets/dropdown.cpp
+++ b/src/widgets/dropdown.cpp
@@ -8,6 +8,7 @@
#include "../strings_type.h"
#include "../gfx_func.h"
#include "../window_func.h"
+#include "../core/math_func.hpp"
#include "dropdown_type.h"
#include "dropdown_func.h"
@@ -51,6 +52,7 @@ struct dropdown_d {
byte selected_index;
byte click_delay;
bool drag_mode;
+ int scrolling;
};
assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(dropdown_d));
@@ -133,6 +135,17 @@ static void DropDownMenuWndProc(Window *w, WindowEvent *e)
}
} break;
+ case WE_TICK:
+ if (WP(w, dropdown_d).scrolling == -1) {
+ w->vscroll.pos = max(0, w->vscroll.pos - 1);
+ SetWindowDirty(w);
+ } else if (WP(w, dropdown_d).scrolling == 1) {
+ w->vscroll.pos = min(w->vscroll.count - w->vscroll.cap, w->vscroll.pos + 1);
+ SetWindowDirty(w);
+ }
+ WP(w, dropdown_d).scrolling = 0;
+ break;
+
case WE_MOUSELOOP: {
Window *w2 = FindWindowById(WP(w, dropdown_d).parent_wnd_class, WP(w,dropdown_d).parent_wnd_num);
if (w2 == NULL) {
@@ -158,6 +171,16 @@ static void DropDownMenuWndProc(Window *w, WindowEvent *e)
if (item < 0) return;
WP(w, dropdown_d).click_delay = 2;
} else {
+ if (_cursor.pos.y <= w->top + 2) {
+ /* Cursor is above the list, set scroll up */
+ WP(w, dropdown_d).scrolling = -1;
+ return;
+ } else if (_cursor.pos.y >= w->top + w->height - 2) {
+ /* Cursor is below list, set scroll down */
+ WP(w, dropdown_d).scrolling = 1;
+ return;
+ }
+
if (item < 0) return;
}