diff options
author | alberth <alberth@openttd.org> | 2009-07-12 10:02:10 +0000 |
---|---|---|
committer | alberth <alberth@openttd.org> | 2009-07-12 10:02:10 +0000 |
commit | c94c18fc0ad33c89583cd5fa4158a4abd89fd07e (patch) | |
tree | 09bbad32345c38a7795041dce0651845b5155c7c /src/widgets | |
parent | e3f429340153403c76a4a105e702abcac25837cb (diff) | |
download | openttd-c94c18fc0ad33c89583cd5fa4158a4abd89fd07e.tar.xz |
(svn r16797) -Codechange: Allow drop-down menus for windows with nested widgets.
Diffstat (limited to 'src/widgets')
-rw-r--r-- | src/widgets/dropdown.cpp | 32 |
1 files changed, 24 insertions, 8 deletions
diff --git a/src/widgets/dropdown.cpp b/src/widgets/dropdown.cpp index 6a0e015b8..447f64a35 100644 --- a/src/widgets/dropdown.cpp +++ b/src/widgets/dropdown.cpp @@ -254,12 +254,28 @@ void ShowDropDownList(Window *w, DropDownList *list, int selected, int button, u /* Our parent's button widget is used to determine where to place the drop * down list window. */ - const Widget *wi = &w->widget[button]; + Rect wi_rect; + Colours wi_colour; + if (w->nested_array != NULL) { + const NWidgetCore *nwi = w->nested_array[button]; + wi_rect.left = nwi->pos_x; + wi_rect.right = nwi->pos_x + nwi->current_x - 1; + wi_rect.top = nwi->pos_y; + wi_rect.bottom = nwi->pos_y + nwi->current_y - 1; + wi_colour = nwi->colour; + } else { + const Widget *wi = &w->widget[button]; + wi_rect.left = wi->left; + wi_rect.right = wi->right; + wi_rect.top = wi->top; + wi_rect.bottom = wi->bottom; + wi_colour = wi->colour; + } /* The preferred position is just below the dropdown calling widget */ - int top = w->top + wi->bottom + 1; + int top = w->top + wi_rect.bottom + 1; - if (width == 0) width = wi->right - wi->left + 1; + if (width == 0) width = wi_rect.right - wi_rect.left + 1; uint max_item_width = 0; @@ -294,8 +310,8 @@ void ShowDropDownList(Window *w, DropDownList *list, int selected, int button, u int screen_top = w3 == NULL ? 0 : w3->top + w3->height; /* If not, check if it will fit above the widget */ - if (w->top + wi->top - height > screen_top) { - top = w->top + wi->top - height - 4; + if (w->top + wi_rect.top - height > screen_top) { + top = w->top + wi_rect.top - height - 4; } else { /* ... and lastly if it won't, enable the scroll bar and fit the * list in below the widget */ @@ -313,9 +329,9 @@ void ShowDropDownList(Window *w, DropDownList *list, int selected, int button, u const Widget *wid = InitializeWidgetArrayFromNestedWidgets(_nested_dropdown_menu_widgets, lengthof(_nested_dropdown_menu_widgets), _dropdown_menu_widgets, &generated_dropdown_menu_widgets); - DropdownWindow *dw = new DropdownWindow(w->left + wi->left, top, width, height + 4, wid); + DropdownWindow *dw = new DropdownWindow(w->left + wi_rect.left, top, width, height + 4, wid); - dw->widget[0].colour = wi->colour; + dw->widget[0].colour = wi_colour; dw->widget[0].right = width - 1; dw->widget[0].bottom = height + 3; @@ -324,7 +340,7 @@ void ShowDropDownList(Window *w, DropDownList *list, int selected, int button, u if (scroll) { /* We're scrolling, so enable the scroll bar and shrink the list by * the scrollbar's width */ - dw->widget[1].colour = wi->colour; + dw->widget[1].colour = wi_colour; dw->widget[1].right = dw->widget[0].right; dw->widget[1].left = dw->widget[1].right - 11; dw->widget[1].bottom = dw->widget[0].bottom; |