OpenTTD
Data Structures | Functions | Variables
dropdown.cpp File Reference

Implementation of the dropdown widget. More...

#include "../stdafx.h"
#include "../window_gui.h"
#include "../string_func.h"
#include "../strings_func.h"
#include "../window_func.h"
#include "dropdown_type.h"
#include "dropdown_widget.h"
#include "../safeguards.h"

Go to the source code of this file.

Data Structures

struct  DropdownWindow
 Drop-down menu window. More...
 

Functions

void ShowDropDownListAt (Window *w, const DropDownList *list, int selected, int button, Rect wi_rect, Colours wi_colour, bool auto_width, bool instant_close)
 Show a drop down list. More...
 
void ShowDropDownList (Window *w, const DropDownList *list, int selected, int button, uint width, bool auto_width, bool instant_close)
 Show a drop down list. More...
 
void ShowDropDownMenu (Window *w, const StringID *strings, int selected, int button, uint32 disabled_mask, uint32 hidden_mask, uint width)
 Show a dropdown menu window near a widget of the parent window. More...
 
int HideDropDownMenu (Window *pw)
 Delete the drop-down menu from window pw. More...
 

Variables

static const NWidgetPart _nested_dropdown_menu_widgets []
 
static WindowDesc _dropdown_desc (WDP_MANUAL, NULL, 0, 0, WC_DROPDOWN_MENU, WC_NONE, WDF_NO_FOCUS, _nested_dropdown_menu_widgets, lengthof(_nested_dropdown_menu_widgets))
 

Detailed Description

Implementation of the dropdown widget.

Definition in file dropdown.cpp.

Function Documentation

◆ HideDropDownMenu()

int HideDropDownMenu ( Window pw)

Delete the drop-down menu from window pw.

Parameters
pwParent window of the drop-down menu window
Returns
Parent widget number if the drop-down was found and closed, -1 if the window was not found.

Definition at line 486 of file dropdown.cpp.

Referenced by NewGRFParametersWindow::OnClick(), OrdersWindow::OnInvalidateData(), VehicleGroupWindow::OnPaint(), and VehicleListWindow::OnPaint().

◆ ShowDropDownList()

void ShowDropDownList ( Window w,
const DropDownList list,
int  selected,
int  button,
uint  width,
bool  auto_width,
bool  instant_close 
)

Show a drop down list.

Parameters
wParent window for the list.
listPrepopulated DropDownList. Will be deleted when the list is closed.
selectedThe initially selected list item.
buttonThe widget within the parent window that is used to determine the list's location.
widthOverride the width determined by the selected widget.
auto_widthMaximum width is determined by the widest item in the list.
instant_closeSet to true if releasing mouse button should close the list regardless of where the cursor is.

Definition at line 421 of file dropdown.cpp.

Referenced by ReplaceVehicleWindow::OnClick(), BuildAirportWindow::OnClick(), GenerateLandscapeWindow::OnClick(), StoryBookWindow::OnClick(), CreateScenarioWindow::OnClick(), GameSettingsWindow::OnClick(), and PopupMainToolbMenu().

◆ ShowDropDownListAt()

void ShowDropDownListAt ( Window w,
const DropDownList list,
int  selected,
int  button,
Rect  wi_rect,
Colours  wi_colour,
bool  auto_width,
bool  instant_close 
)

Show a drop down list.

Parameters
wParent window for the list.
listPrepopulated DropDownList. Will be deleted when the list is closed.
selectedThe initially selected list item.
buttonThe 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_rectCoord of the parent drop down button, used to position the dropdown menu.
auto_widthThe width is determined by the widest item in the list, in this case only one of left or right is used (depending on text direction).
instant_closeSet to true if releasing mouse button should close the list regardless of where the cursor is.

Definition at line 337 of file dropdown.cpp.

References DeleteWindowById(), Window::top, and WC_DROPDOWN_MENU.

◆ ShowDropDownMenu()

void ShowDropDownMenu ( Window w,
const StringID strings,
int  selected,
int  button,
uint32  disabled_mask,
uint32  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
wParent window that wants the dropdown menu.
stringsMenu list, end with INVALID_STRING_ID
selectedIndex of initial selected item.
buttonButton widget number of the parent window w that wants the dropdown menu.
disabled_maskBitmask for disabled items (items with their bit set are displayed, but not selectable in the dropdown list).
hidden_maskBitmask for hidden items (items with their bit set are not copied to the dropdown list).
widthWidth of the dropdown menu. If 0, use the width of parent widget button.

Definition at line 462 of file dropdown.cpp.

Referenced by BuildBridgeWindow::OnClick(), ReplaceVehicleWindow::OnClick(), VehicleGroupWindow::OnClick(), NetworkGameWindow::OnClick(), TownDirectoryWindow::OnClick(), BuildVehicleWindow::OnClick(), IndustryDirectoryWindow::OnClick(), VehicleListWindow::OnClick(), and VehicleDetailsWindow::OnClick().

Variable Documentation

◆ _nested_dropdown_menu_widgets

const NWidgetPart _nested_dropdown_menu_widgets[]
static
Initial value:
= {
}
Horizontal container.
Definition: widget_type.h:75
static NWidgetPart SetMinimalSize(int16 x, int16 y)
Widget part function for setting the minimal size.
Definition: widget_type.h:947
Simple depressed panel.
Definition: widget_type.h:50
static NWidgetPart NWidget(WidgetType tp, Colours col, int16 idx=-1)
Widget part function for starting a new 'real' widget.
Definition: widget_type.h:1114
static NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME, WWT_INSET, or WWT_PANEL).
Definition: widget_type.h:999
Vertical scrollbar.
Definition: widget_type.h:84
Stacked widgets, only one visible at a time (eg in a panel with tabs).
Definition: widget_type.h:80
static NWidgetPart SetScrollbar(int index)
Attach a scrollbar to a widget.
Definition: widget_type.h:1095

Definition at line 73 of file dropdown.cpp.