12 #include "../stdafx.h"
13 #include "../window_gui.h"
14 #include "../string_func.h"
15 #include "../strings_func.h"
16 #include "../window_func.h"
21 #include "../safeguards.h"
24 void DropDownListItem::Draw(
int left,
int right,
int top,
int bottom,
bool sel,
int bg_colour)
const
29 int mid = top + this->Height(0) / 2;
30 GfxFillRect(left + 1, mid - 2, right - 1, mid - 2, c1);
31 GfxFillRect(left + 1, mid - 1, right - 1, mid - 1, c2);
34 uint DropDownListStringItem::Width()
const
37 GetString(buffer, this->String(),
lastof(buffer));
41 void DropDownListStringItem::Draw(
int left,
int right,
int top,
int bottom,
bool sel,
int bg_colour)
const
55 char buffer1[512], buffer2[512];
56 GetString(buffer1, static_cast<const DropDownListStringItem*>(*first)->String(),
lastof(buffer1));
57 GetString(buffer2, static_cast<const DropDownListStringItem*>(*second)->String(),
lastof(buffer2));
61 StringID DropDownListParamStringItem::String()
const
67 StringID DropDownListCharStringItem::String()
const
73 static const NWidgetPart _nested_dropdown_menu_widgets[] = {
86 _nested_dropdown_menu_widgets,
lengthof(_nested_dropdown_menu_widgets)
119 assert(list->
Length() > 0);
127 uint items_width = size.width - (scroll ? NWidgetScrollbar::GetVerticalDimension().width : 0);
144 list_height += item->Height(items_width);
157 this->drag_mode =
true;
193 int y = _cursor.
pos.y - this->top - nwi->
pos_y - 2;
201 if (--pos >= 0)
continue;
204 int item_height = item->Height(width);
206 if (y < item_height) {
207 if (item->
masked || !item->Selectable())
return false;
222 Colours colour = this->GetWidget<NWidgetCore>(widget)->colour;
228 int item_height = item->Height(r.right - r.left + 1);
231 if (--pos >= 0)
continue;
233 if (y + item_height < r.bottom) {
237 item->Draw(r.left, r.right, y, y + item_height, selected, colour);
291 if (this->drag_mode) {
295 this->drag_mode =
false;
302 if (_cursor.
pos.y <= this->top + 2) {
306 }
else if (_cursor.
pos.y >= this->top + this->height - 2) {
342 int top = w->
top + wi_rect.bottom + 1;
345 uint width = wi_rect.right - wi_rect.left + 1;
348 uint max_item_width = 0;
355 height += item->Height(width);
356 if (auto_width) max_item_width =
max(max_item_width, item->Width() + 5);
364 if (top + height + 4 >= screen_bottom) {
367 if (w->
top + wi_rect.top > screen_top + height) {
368 top = w->
top + wi_rect.top - height - 4;
371 int avg_height = height / (int)list->
Length();
375 bool put_above =
false;
376 int available_height = screen_bottom - w->
top - wi_rect.bottom;
377 if (w->
top + wi_rect.top - screen_top > available_height) {
379 available_height = w->
top + wi_rect.top - screen_top;
384 assert(available_height >= avg_height);
387 int rows = available_height / avg_height;
388 height = rows * avg_height;
392 max_item_width += NWidgetScrollbar::GetVerticalDimension().width;
396 top = w->
top + wi_rect.top - height - 4;
401 if (auto_width) width =
max(width, max_item_width);
404 Dimension dw_size = {width, (uint)height};
405 new DropdownWindow(w, list, selected, button, instant_close, dw_pos, dw_size, wi_colour, scroll);
427 wi_rect.left = nwi->
pos_x;
429 wi_rect.top = nwi->
pos_y;
431 Colours wi_colour = nwi->
colour;
442 wi_rect.left = wi_rect.right + 1 - width;
444 wi_rect.right = wi_rect.left + width - 1;
448 ShowDropDownListAt(w, list, selected, button, wi_rect, wi_colour, auto_width, instant_close);
467 if (!
HasBit(hidden_mask, i)) {
473 if (list->
Length() == 0) {
489 FOR_ALL_WINDOWS_FROM_BACK(w) {
498 return parent_button;