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;
170 Point pt = _cursor.pos;
190 if (
GetWidgetFromPos(
this, _cursor.pos.x - this->left, _cursor.pos.y - this->top) < 0)
return false;
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 top = w->
top + wi_rect.top - height - 4;
371 int avg_height = height / (int)list->
Length();
372 int rows = (screen_bottom - 4 - top) / avg_height;
373 height = rows * avg_height;
377 max_item_width += NWidgetScrollbar::GetVerticalDimension().width;
381 if (auto_width) width =
max(width, max_item_width);
384 Dimension dw_size = {width, (uint)height};
385 new DropdownWindow(w, list, selected, button, instant_close, dw_pos, dw_size, wi_colour, scroll);
407 wi_rect.left = nwi->
pos_x;
409 wi_rect.top = nwi->
pos_y;
411 Colours wi_colour = nwi->
colour;
422 wi_rect.left = wi_rect.right + 1 - width;
424 wi_rect.right = wi_rect.left + width - 1;
428 ShowDropDownListAt(w, list, selected, button, wi_rect, wi_colour, auto_width, instant_close);
447 if (!
HasBit(hidden_mask, i)) {
453 if (list->
Length() == 0) {
469 FOR_ALL_WINDOWS_FROM_BACK(w) {
478 return parent_button;