OpenTTD Source: src/dropdown.cpp File Reference

OpenTTD Source 15.0-RC2

Data Structures | Functions | Variables
dropdown.cpp File Reference

Implementation of the dropdown widget. More...

`#include "stdafx.h"`
`#include "core/backup_type.hpp"`
`#include "dropdown_type.h"`
`#include "dropdown_func.h"`
`#include "strings_func.h"`
`#include "sound_func.h"`
`#include "timer/timer.h"`
`#include "timer/timer_window.h"`
`#include "window_gui.h"`
`#include "window_func.h"`
`#include "zoom_func.h"`
`#include "widgets/dropdown_widget.h"`
`#include "table/strings.h"`
`#include "dropdown_common_type.h"`
`#include "safeguards.h"`

Go to the source code of this file.

## Data Structures
struct | DropdownWindow
| Drop-down menu window. More...

## Functions
std::unique_ptr< DropDownListItem > | MakeDropDownListDividerItem ()
std::unique_ptr< DropDownListItem > | MakeDropDownListStringItem (StringID str, int value, bool masked, bool shaded)
std::unique_ptr< DropDownListItem > | MakeDropDownListStringItem (std::string &&str, int value, bool masked, bool shaded)
std::unique_ptr< DropDownListItem > | MakeDropDownListIconItem (SpriteID sprite, PaletteID palette, StringID str, int value, bool masked, bool shaded)
std::unique_ptr< DropDownListItem > | MakeDropDownListIconItem (const Dimension &dim, SpriteID sprite, PaletteID palette, StringID str, int value, bool masked, bool shaded)
std::unique_ptr< DropDownListItem > | MakeDropDownListCheckedItem (bool checked, StringID str, int value, bool masked, bool shaded, uint indent)
void | ReplaceDropDownList (Window *parent, DropDownList &&list, std::optional< int > selected_result)
Dimension | GetDropDownListDimension (const DropDownList &list)
| Determine width and height required to fully display a DropDownList.
void | ShowDropDownListAt (Window *w, DropDownList &&list, int selected, WidgetID button, Rect wi_rect, Colours wi_colour, DropDownOptions options)
| Show a drop down list.
void | ShowDropDownList (Window *w, DropDownList &&list, int selected, WidgetID button, uint width, DropDownOptions options)
| Show a drop down list.
void | ShowDropDownMenu (Window *w, std::span< const StringID > strings, int selected, WidgetID button, uint32_t disabled_mask, uint32_t hidden_mask, uint width)
| Show a dropdown menu window near a widget of the parent window.

## Variables
static constexpr std::initializer_list< NWidgetPart > | _nested_dropdown_menu_widgets
static WindowDesc | _dropdown_desc (WDP_MANUAL, {}, 0, 0, WC_DROPDOWN_MENU, WC_NONE, WindowDefaultFlag::NoFocus, _nested_dropdown_menu_widgets)

## Detailed Description

Implementation of the dropdown widget.

Definition in file dropdown.cpp.

## Function Documentation

## ◆ GetDropDownListDimension()

Dimension GetDropDownListDimension | ( | const DropDownList & | list | ) |

Determine width and height required to fully display a DropDownList.

Parameters

  list | The list.

Returns
  Dimension required to display the list.

Definition at line 381 of file dropdown.cpp.

References WidgetDimensions::dropdowntext, RectPadding::Horizontal(), and WidgetDimensions::scaled.

Referenced by DropdownWindow::UpdateSizeAndPosition(), BuildVehicleWindow::UpdateWidgetSize(), VehicleGroupWindow::UpdateWidgetSize(), GameOptionsWindow::UpdateWidgetSize(), and VehicleListWindow::UpdateWidgetSize().

## ◆ MakeDropDownListCheckedItem()

std::unique_ptr< DropDownListItem > MakeDropDownListCheckedItem | ( | bool | checked,
|  | StringID | str,
|  | int | value,
|  | bool | masked,
|  | bool | shaded,
|  | uint | indent
| ) |  |

Definition at line 55 of file dropdown.cpp.

## ◆ MakeDropDownListDividerItem()

std::unique_ptr< DropDownListItem > MakeDropDownListDividerItem | ( |  | ) |

Definition at line 30 of file dropdown.cpp.

## ◆ MakeDropDownListIconItem() [1/2]

std::unique_ptr< DropDownListItem > MakeDropDownListIconItem | ( | const Dimension & | dim,
|  | SpriteID | sprite,
|  | PaletteID | palette,
|  | StringID | str,
|  | int | value,
|  | bool | masked,
|  | bool | shaded
| ) |  |

Definition at line 50 of file dropdown.cpp.

## ◆ MakeDropDownListIconItem() [2/2]

std::unique_ptr< DropDownListItem > MakeDropDownListIconItem | ( | SpriteID | sprite,
|  | PaletteID | palette,
|  | StringID | str,
|  | int | value,
|  | bool | masked,
|  | bool | shaded
| ) |  |

Definition at line 45 of file dropdown.cpp.

## ◆ MakeDropDownListStringItem() [1/2]

std::unique_ptr< DropDownListItem > MakeDropDownListStringItem | ( | std::string && | str,
|  | int | value,
|  | bool | masked,
|  | bool | shaded
| ) |  |

Definition at line 40 of file dropdown.cpp.

## ◆ MakeDropDownListStringItem() [2/2]

std::unique_ptr< DropDownListItem > MakeDropDownListStringItem | ( | StringID | str,
|  | int | value,
|  | bool | masked,
|  | bool | shaded
| ) |  |

Definition at line 35 of file dropdown.cpp.

## ◆ ReplaceDropDownList()

void ReplaceDropDownList | ( | Window * | parent,
|  | DropDownList && | list,
|  | std::optional< int > | selected_result
| ) |  |

Definition at line 370 of file dropdown.cpp.

## ◆ ShowDropDownList()

void ShowDropDownList | ( | Window * | w,
|  | DropDownList && | list,
|  | int | selected,
|  | WidgetID | button,
|  | uint | width,
|  | DropDownOptions | options
| ) |  |

Show a drop down list.

Parameters

  w | Parent window for the list.
  list | Prepopulated DropDownList.
  selected | The initially selected list item.
  button | The widget within the parent window that is used to determine the list's location.
  width | Override the minimum width determined by the selected widget and list contents.
  options | Drop Down options for this menu.

Definition at line 418 of file dropdown.cpp.

References _current_text_dir, NWidgetCore::colour, NWidgetCore::disp_flags, DropdownActive, Window::GetWidget(), NWID_BUTTON_DROPDOWN, ScaleGUITrad(), BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Set(), NWidgetBase::SetDirty(), NWidgetCore::SetLowered(), ShowDropDownListAt(), SndClickBeep(), TD_RTL, and NWidgetBase::type.

Referenced by BuildAirportWindow::OnClick(), ReplaceVehicleWindow::OnClick(), BuildVehicleWindow::OnClick(), GenerateLandscapeWindow::OnClick(), CreateScenarioWindow::OnClick(), VehicleGroupWindow::OnClick(), IndustryDirectoryWindow::OnClick(), IndustryCargoesWindow::OnClick(), MusicTrackSelectionWindow::OnClick(), NetworkStartServerWindow::OnClick(), NetworkClientListWindow::OnClick(), NewGRFWindow::OnClick(), OrdersWindow::OnClick(), PickerWindow::OnClick(), GameOptionsWindow::OnClick(), CompanyStationsWindow::OnClick(), StoryBookWindow::OnClick(), TextfileWindow::OnClick(), VehicleListWindow::OnClick(), PopupMainToolbarMenu(), SetDateWindow::ShowDateDropDown(), ShowDropDownMenu(), and ToolbarOptionsClick().

## ◆ ShowDropDownListAt()

void ShowDropDownListAt | ( | Window * | w,
|  | DropDownList && | list,
|  | int | selected,
|  | WidgetID | button,
|  | Rect | wi_rect,
|  | Colours | wi_colour,
|  | DropDownOptions | options
| ) |  |

Show a drop down list.

Parameters

  w | Parent window for the list.
  list | Prepopulated DropDownList.
  selected | The initially selected list item.
  button | The widget which is passed to Window::OnDropdownSelect and OnDropdownClose. Unless you override those functions, this should be then widget index of the dropdown button.
  wi_rect | Coord of the parent drop down button, used to position the dropdown menu.
  options | Drop Down options for this menu.

Definition at line 402 of file dropdown.cpp.

References CloseWindowByClass(), and WC_DROPDOWN_MENU.

Referenced by GSConfigWindow::OnClick(), NewGRFParametersWindow::OnClick(), ScriptSettingsWindow::OnClick(), NetworkClientListWindow::OnClickClientAdmin(), NetworkClientListWindow::OnClickCompanyAdmin(), and ShowDropDownList().

## ◆ ShowDropDownMenu()

void ShowDropDownMenu | ( | Window * | w,
|  | std::span< const StringID > | strings,
|  | int | selected,
|  | WidgetID | button,
|  | uint32_t | disabled_mask,
|  | uint32_t | hidden_mask,
|  | uint | width
| ) |  |

Show a dropdown menu window near a widget of the parent window.

The result code of the items is their index in the strings list.

Parameters

  w | Parent window that wants the dropdown menu.
  strings | Menu list.
  selected | Index of initial selected item.
  button | Button widget number of the parent window w that wants the dropdown menu.
  disabled_mask | Bitmask for disabled items (items with their bit set are displayed, but not selectable in the dropdown list).
  hidden_mask | Bitmask for hidden items (items with their bit set are not copied to the dropdown list).
  width | Minimum width of the dropdown menu.

Definition at line 458 of file dropdown.cpp.

References HasBit(), and ShowDropDownList().

Referenced by DisplayVehicleSortDropDown(), ReplaceVehicleWindow::OnClick(), BuildBridgeWindow::OnClick(), GenerateLandscapeWindow::OnClick(), VehicleGroupWindow::OnClick(), IndustryDirectoryWindow::OnClick(), OrdersWindow::OnClick(), CompanyStationsWindow::OnClick(), StationViewWindow::OnClick(), TownDirectoryWindow::OnClick(), VehicleListWindow::OnClick(), and VehicleDetailsWindow::OnClick().

## Variable Documentation

## ◆ _nested_dropdown_menu_widgets

constexpr std::initializer_list<NWidgetPart> _nested_dropdown_menu_widgets
| staticconstexpr

Initial value:
= {
NWidget(NWID_HORIZONTAL),
NWidget(WWT_PANEL, COLOUR_END, WID_DM_ITEMS), SetScrollbar(WID_DM_SCROLL), EndContainer(),
NWidget(NWID_SELECTION, INVALID_COLOUR, WID_DM_SHOW_SCROLL),
NWidget(NWID_VSCROLLBAR, COLOUR_END, WID_DM_SCROLL),
EndContainer(),
EndContainer(),
}
WID_DM_ITEMS
@ WID_DM_ITEMS
Panel showing the dropdown items.
Definition dropdown_widget.h:15
WID_DM_SCROLL
@ WID_DM_SCROLL
Scrollbar.
Definition dropdown_widget.h:17
WID_DM_SHOW_SCROLL
@ WID_DM_SHOW_SCROLL
Hide scrollbar if too few items.
Definition dropdown_widget.h:16
SetScrollbar
constexpr NWidgetPart SetScrollbar(WidgetID index)
Attach a scrollbar to a widget.
Definition widget_type.h:1399
EndContainer
constexpr NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME,...
Definition widget_type.h:1229
NWidget
constexpr NWidgetPart NWidget(WidgetType tp, Colours col, WidgetID idx=INVALID_WIDGET)
Widget part function for starting a new 'real' widget.
Definition widget_type.h:1424
NWID_HORIZONTAL
@ NWID_HORIZONTAL
Horizontal container.
Definition widget_type.h:66
WWT_PANEL
@ WWT_PANEL
Simple depressed panel.
Definition widget_type.h:39
NWID_VSCROLLBAR
@ NWID_VSCROLLBAR
Vertical scrollbar.
Definition widget_type.h:76
NWID_SELECTION
@ NWID_SELECTION
Stacked widgets, only one visible at a time (eg in a panel with tabs).
Definition widget_type.h:71

Definition at line 60 of file dropdown.cpp.