mirror of https://github.com/OpenTTD/OpenTTD
(svn r7310) -Codechange: Change scrolling dropdown box to use 1 scroll unit = 1 line
of text, instead of 1 row of pixels. This fixes behaviour of scrolling with the scrollbar buttons and the mouse wheel.release/0.5
parent
04773f5eb4
commit
af017c198c
43
widget.c
43
widget.c
|
@ -486,7 +486,7 @@ static int GetDropdownItem(const Window *w)
|
||||||
if (GetWidgetFromPos(w, _cursor.pos.x - w->left, _cursor.pos.y - w->top) < 0)
|
if (GetWidgetFromPos(w, _cursor.pos.x - w->left, _cursor.pos.y - w->top) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
y = _cursor.pos.y - w->top - 2 + w->vscroll.pos;
|
y = _cursor.pos.y - w->top - 2 + w->vscroll.pos * 10;
|
||||||
|
|
||||||
if (y < 0)
|
if (y < 0)
|
||||||
return - 1;
|
return - 1;
|
||||||
|
@ -509,34 +509,21 @@ static void DropdownMenuWndProc(Window *w, WindowEvent *e)
|
||||||
switch (e->event) {
|
switch (e->event) {
|
||||||
case WE_PAINT: {
|
case WE_PAINT: {
|
||||||
int x,y,i,sel;
|
int x,y,i,sel;
|
||||||
int width;
|
int width, height;
|
||||||
bool scroll = w->vscroll.count > 0;
|
|
||||||
DrawPixelInfo tmp_dpi, *old_dpi = NULL;
|
|
||||||
|
|
||||||
DrawWindowWidgets(w);
|
DrawWindowWidgets(w);
|
||||||
|
|
||||||
x = 1;
|
x = 1;
|
||||||
y = 2 - w->vscroll.pos;
|
y = 2 - w->vscroll.pos * 10;
|
||||||
|
|
||||||
if (scroll) {
|
|
||||||
/* Set up the bounding box for drawing the list content */
|
|
||||||
if (!FillDrawPixelInfo(&tmp_dpi, w->widget[0].left + 1, w->widget[0].top + 1, w->widget[0].right - 1, w->widget[0].bottom - 1)) return;
|
|
||||||
old_dpi = _cur_dpi;
|
|
||||||
_cur_dpi = &tmp_dpi;
|
|
||||||
|
|
||||||
/* Adjust x and y for the 1 pixel offset of the bounding box */
|
|
||||||
x--;
|
|
||||||
y--;
|
|
||||||
}
|
|
||||||
|
|
||||||
sel = WP(w,dropdown_d).selected_index;
|
sel = WP(w,dropdown_d).selected_index;
|
||||||
width = w->widget[0].right - 3;
|
width = w->widget[0].right - 3;
|
||||||
|
height = w->widget[0].bottom - 3;
|
||||||
|
|
||||||
for (i = 0; WP(w,dropdown_d).items[i] != INVALID_STRING_ID; i++) {
|
for (i = 0; WP(w,dropdown_d).items[i] != INVALID_STRING_ID; i++, sel--) {
|
||||||
if (HASBIT(WP(w,dropdown_d).hidden_state, i)) {
|
if (HASBIT(WP(w,dropdown_d).hidden_state, i)) continue;
|
||||||
sel--;
|
|
||||||
continue;
|
if (y >= 0 && y <= height) {
|
||||||
}
|
|
||||||
if (WP(w,dropdown_d).items[i] != STR_NULL) {
|
if (WP(w,dropdown_d).items[i] != STR_NULL) {
|
||||||
if (sel == 0) GfxFillRect(x + 1, y, x + width, y + 9, 0);
|
if (sel == 0) GfxFillRect(x + 1, y, x + width, y + 9, 0);
|
||||||
DrawStringTruncated(x + 2, y, WP(w,dropdown_d).items[i], sel == 0 ? 12 : 16, x + width);
|
DrawStringTruncated(x + 2, y, WP(w,dropdown_d).items[i], sel == 0 ? 12 : 16, x + width);
|
||||||
|
@ -553,12 +540,9 @@ static void DropdownMenuWndProc(Window *w, WindowEvent *e)
|
||||||
GfxFillRect(x + 1, y + 3, x + w->width - 5, y + 3, c1);
|
GfxFillRect(x + 1, y + 3, x + w->width - 5, y + 3, c1);
|
||||||
GfxFillRect(x + 1, y + 4, x + w->width - 5, y + 4, c2);
|
GfxFillRect(x + 1, y + 4, x + w->width - 5, y + 4, c2);
|
||||||
}
|
}
|
||||||
y += 10;
|
|
||||||
sel--;
|
|
||||||
}
|
}
|
||||||
|
y += 10;
|
||||||
/* Reset the bounding box if we had set it up */
|
}
|
||||||
if (scroll) _cur_dpi = old_dpi;
|
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
case WE_CLICK: {
|
case WE_CLICK: {
|
||||||
|
@ -664,7 +648,8 @@ void ShowDropDownMenu(Window *w, const StringID *strings, int selected, int butt
|
||||||
} else {
|
} else {
|
||||||
/* ... and lastly if it won't, enable the scroll bar and fit the
|
/* ... and lastly if it won't, enable the scroll bar and fit the
|
||||||
* list in below the widget */
|
* list in below the widget */
|
||||||
height = screen_bottom - top;
|
int rows = (screen_bottom - 4 - top) / 10;
|
||||||
|
height = rows * 10 + 4;
|
||||||
scroll = true;
|
scroll = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -693,8 +678,8 @@ void ShowDropDownMenu(Window *w, const StringID *strings, int selected, int butt
|
||||||
w2->widget[1].bottom = height - 1;
|
w2->widget[1].bottom = height - 1;
|
||||||
w2->widget[0].right -= 12;
|
w2->widget[0].right -= 12;
|
||||||
|
|
||||||
w2->vscroll.cap = height - 1;
|
w2->vscroll.cap = (height - 4) / 10;
|
||||||
w2->vscroll.count = i * 10 + 3;
|
w2->vscroll.count = i;
|
||||||
}
|
}
|
||||||
|
|
||||||
w2->desc_flags = WDF_DEF_WIDGET;
|
w2->desc_flags = WDF_DEF_WIDGET;
|
||||||
|
|
Loading…
Reference in New Issue