OpenTTD Source 20260801-master-g0de95fb529
NWidgetSmallmapButtons Class Reference

Custom container for smallmap buttons. More...

Inheritance diagram for NWidgetSmallmapButtons:
NWidgetContainer NWidgetBase

Public Member Functions

 NWidgetSmallmapButtons ()
 Construct a new NWidgetSmallmapButtons object.
void SetupSmallestSize (Window *w) override
 Compute smallest size needed by the widget.
std::pair< uint, uint > GetPreferredSizeForSize (uint given_width, uint given_height) override
 Get a widget's preferred size for a given size.
void AssignSizePosition (SizingType sizing, int x, int y, uint given_width, uint given_height, bool rtl) override
 Assign size and position to the widget.
Public Member Functions inherited from NWidgetContainer
 NWidgetContainer (WidgetType tp, WidgetID index=INVALID_WIDGET)
void AdjustPaddingForZoom () override
 Adjust the padding based on the user interface zoom.
void Add (std::unique_ptr< NWidgetBase > &&wid)
 Append widget wid to container.
void FillWidgetLookup (WidgetLookup &widget_lookup) override
 Fill the Window::widget_lookup with pointers to nested widgets in the tree.
void Draw (const Window *w) override
 Draw the widgets of the tree.
NWidgetCoreGetWidgetFromPos (int x, int y) override
 Retrieve a widget by its position.
bool IsEmpty ()
 Return whether the container is empty.
NWidgetBaseGetWidgetOfType (WidgetType tp) override
 Retrieve a widget by its type.
void UnfocusWidgets (Window *parent_window)
 Unfocuses the focused widget of the window, if the focused widget is contained inside the container.
void Clear (Window *parent_window)
 Clears the container, deleting all widgets that were contained.
Public Member Functions inherited from NWidgetBase
 NWidgetBase (WidgetType tp, WidgetID index=INVALID_WIDGET)
virtual ~NWidgetBase ()=default
 Ensure the destructor of the sub classes are called as well.
void ApplyAspectRatio ()
template<class NWID>
NWID * GetParentWidget ()
 Get parent widget of type NWID.
template<class NWID>
const NWID * GetParentWidget () const
 Get parent widget of type NWID.
WidgetID GetIndex () const
virtual bool IsHighlighted () const
 Whether the widget is currently highlighted or not.
virtual TextColour GetHighlightColour () const
 Get the colour of the highlighted text.
virtual void SetHighlighted (TextColour highlight_colour)
 Highlight the widget or not.
void SetPadding (uint8_t top, uint8_t right, uint8_t bottom, uint8_t left)
 Set additional space (padding) around the widget.
void SetPadding (const RectPadding &padding)
 Set additional space (padding) around the widget.
uint GetHorizontalStepSize (SizingType sizing) const
 Get the horizontal sizing step.
uint GetVerticalStepSize (SizingType sizing) const
 Get the vertical sizing step.
virtual void SetDirty (const Window *w) const
 Mark the widget as 'dirty' (in need of repaint).
Rect GetCurrentRect () const

Static Public Member Functions

static std::unique_ptr< NWidgetBaseMake ()
 Create NWidgetSMallmapButtons widget.

Private Attributes

uint num_buttons
 The number of buttons excluding spacers.
Dimension button
 The size of a button.

Static Private Attributes

static constexpr std::tuple< WidgetID, WidgetType, SpriteID, StringIDbuttons []
 Smallmap button definitions.

Additional Inherited Members

Data Fields inherited from NWidgetBase
WidgetType type {}
 Type of the widget / nested widget.
uint fill_x = 0
 Horizontal fill stepsize (from initial size, 0 means not resizable).
uint fill_y = 0
 Vertical fill stepsize (from initial size, 0 means not resizable).
uint resize_x = 0
 Horizontal resize step (0 means not resizable).
uint resize_y = 0
 Vertical resize step (0 means not resizable).
uint smallest_x = 0
 Smallest horizontal size of the widget in a filled window.
uint smallest_y = 0
 Smallest vertical size of the widget in a filled window.
uint current_x = 0
 Current horizontal size (after resizing).
uint current_y = 0
 Current vertical size (after resizing).
float aspect_ratio = 0
 Desired aspect ratio of widget.
AspectFlags aspect_flags = AspectFlag::ResizeX
 Which dimensions can be resized.
int pos_x = 0
 Horizontal position of top-left corner of the widget in the window.
int pos_y = 0
 Vertical position of top-left corner of the widget in the window.
RectPadding padding {}
 Padding added to the widget. Managed by parent container widget. (parent container may swap left and right for RTL).
RectPadding uz_padding {}
 Unscaled padding, for resize calculation.
NWidgetBaseparent = nullptr
 Parent widget of this widget, automatically filled in when added to container.
Protected Member Functions inherited from NWidgetBase
void StoreSizePosition (SizingType sizing, int x, int y, uint given_width, uint given_height)
 Store size and position.
Protected Attributes inherited from NWidgetContainer
std::vector< std::unique_ptr< NWidgetBase > > children {}
 Child widgets in container.
Protected Attributes inherited from NWidgetBase
const WidgetID index = INVALID_WIDGET
 Index of the nested widget (INVALID_WIDGET means 'not used').

Detailed Description

Custom container for smallmap buttons.

This container can switch from a 1-column to a 2-column layout depending on the given height.

Definition at line 1943 of file smallmap_gui.cpp.

Constructor & Destructor Documentation

◆ NWidgetSmallmapButtons()

NWidgetSmallmapButtons::NWidgetSmallmapButtons ( )
inline

Construct a new NWidgetSmallmapButtons object.

Definition at line 1968 of file smallmap_gui.cpp.

References NWidgetContainer::Add(), Brown, buttons, INVALID_WIDGET, NWID_VERTICAL, and WWT_PANEL.

Member Function Documentation

◆ AssignSizePosition()

void NWidgetSmallmapButtons::AssignSizePosition ( SizingType sizing,
int x,
int y,
uint given_width,
uint given_height,
bool rtl )
inlineoverridevirtual

Assign size and position to the widget.

Parameters
sizingType of resizing to perform.
xHorizontal offset of the widget relative to the left edge of the window.
yVertical offset of the widget relative to the top edge of the window.
given_widthWidth allocated to the widget.
given_heightHeight allocated to the widget.
rtlAdapt for right-to-left languages (position contents of horizontal containers backwards).

Afterwards, pos_x and pos_y contain the top-left position of the widget, smallest_x and smallest_y contain the smallest size such that all widgets of the window are consistent, and current_x and current_y contain the current size.

Implements NWidgetBase.

Definition at line 2010 of file smallmap_gui.cpp.

References CeilDiv(), NWidgetContainer::children, NWidgetBase::current_x, NWidgetBase::current_y, NWidgetBase::pos_x, NWidgetBase::pos_y, NWidgetBase::smallest_x, WID_SM_BLANK, and WWT_PANEL.

◆ GetPreferredSizeForSize()

std::pair< uint, uint > NWidgetSmallmapButtons::GetPreferredSizeForSize ( uint given_width,
uint given_height )
inlineoverridevirtual

Get a widget's preferred size for a given size.

Parameters
given_widthThe given width.
given_heightThe given height.
Returns
pair containing preferred width and height.

Reimplemented from NWidgetBase.

Definition at line 2004 of file smallmap_gui.cpp.

◆ Make()

std::unique_ptr< NWidgetBase > NWidgetSmallmapButtons::Make ( )
inlinestatic

Create NWidgetSMallmapButtons widget.

Returns
Pointer to created NWidget.

Definition at line 2048 of file smallmap_gui.cpp.

◆ SetupSmallestSize()

void NWidgetSmallmapButtons::SetupSmallestSize ( Window * w)
inlineoverridevirtual

Compute smallest size needed by the widget.

The smallest size of a widget is the smallest size that a widget needs to display itself properly. In addition, filling and resizing of the widget are computed. The function calls Window::UpdateWidgetSize for each leaf widget and background widget without child with a non-negative index.

Parameters
wWindow owning the widget.
Note
After the computation, the results can be queried by accessing the smallest_x and smallest_y data members of the widget.

Implements NWidgetBase.

Definition at line 1982 of file smallmap_gui.cpp.

References CeilDiv(), NWidgetContainer::children, NWidgetBase::fill_x, NWidgetBase::fill_y, NWidgetBase::index, INVALID_WIDGET, NWidgetBase::resize_x, NWidgetBase::resize_y, NWidgetBase::smallest_x, NWidgetBase::smallest_y, and WID_SM_BLANK.

Field Documentation

◆ button

Dimension NWidgetSmallmapButtons::button
private

The size of a button.

Definition at line 1962 of file smallmap_gui.cpp.

◆ buttons

std::tuple<WidgetID, WidgetType, SpriteID, StringID> NWidgetSmallmapButtons::buttons[]
staticconstexprprivate
Initial value:
= {
{WID_SM_ZOOM_IN, WWT_PUSHIMGBTN, SPR_IMG_ZOOMIN, STR_TOOLBAR_TOOLTIP_ZOOM_THE_VIEW_IN},
{WID_SM_ZOOM_OUT, WWT_PUSHIMGBTN, SPR_IMG_ZOOMOUT, STR_TOOLBAR_TOOLTIP_ZOOM_THE_VIEW_OUT},
{WID_SM_CENTERMAP, WWT_PUSHIMGBTN, SPR_IMG_SMALLMAP, STR_SMALLMAP_CENTER_TOOLTIP},
{WID_SM_TOGGLETOWNNAME, WWT_IMGBTN, SPR_IMG_TOWN, STR_SMALLMAP_TOOLTIP_TOGGLE_TOWN_NAMES_ON_OFF},
{WID_SM_LINKSTATS, WWT_IMGBTN, SPR_IMG_CARGOFLOW, STR_SMALLMAP_TOOLTIP_SHOW_LINK_STATS_ON_MAP},
{WID_SM_ROUTES, WWT_IMGBTN, SPR_IMG_SHOW_ROUTES, STR_SMALLMAP_TOOLTIP_SHOW_TRANSPORT_ROUTES_ON},
{WID_SM_VEGETATION, WWT_IMGBTN, SPR_IMG_PLANTTREES, STR_SMALLMAP_TOOLTIP_SHOW_VEGETATION_ON_MAP},
{WID_SM_OWNERS, WWT_IMGBTN, SPR_IMG_COMPANY_GENERAL, STR_SMALLMAP_TOOLTIP_SHOW_LAND_OWNERS_ON_MAP},
{WID_SM_CONTOUR, WWT_IMGBTN, SPR_IMG_SHOW_COUNTOURS, STR_SMALLMAP_TOOLTIP_SHOW_LAND_CONTOURS_ON_MAP},
{WID_SM_VEHICLES, WWT_IMGBTN, SPR_IMG_SHOW_VEHICLES, STR_SMALLMAP_TOOLTIP_SHOW_VEHICLES_ON_MAP},
{WID_SM_INDUSTRIES, WWT_IMGBTN, SPR_IMG_INDUSTRY, STR_SMALLMAP_TOOLTIP_SHOW_INDUSTRIES_ON_MAP},
}
@ WID_SM_OWNERS
Button to select the owners view.
@ WID_SM_VEHICLES
Button to select the vehicles view.
@ WID_SM_CENTERMAP
Button to move smallmap center to main window center.
@ WID_SM_VEGETATION
Button to select the vegetation view.
@ WID_SM_TOGGLETOWNNAME
Toggle button to display town names.
@ WID_SM_CONTOUR
Button to select the contour view (height map).
@ WID_SM_ZOOM_OUT
Button to zoom out one step.
@ WID_SM_ZOOM_IN
Button to zoom in one step.
@ WID_SM_BLANK
Empty button as placeholder.
@ WID_SM_LINKSTATS
Button to select the link stats view.
@ WID_SM_ROUTES
Button to select the routes view.
@ WID_SM_INDUSTRIES
Button to select the industries view.
static const SpriteID SPR_IMG_PLANTTREES
Definition sprites.h:1259
static const SpriteID SPR_IMG_COMPANY_GENERAL
Definition sprites.h:1252
static const SpriteID SPR_IMG_INDUSTRY
Definition sprites.h:1258
static const SpriteID SPR_IMG_SHOW_ROUTES
Definition sprites.h:1257
static const SpriteID SPR_IMG_SHOW_VEHICLES
Definition sprites.h:1256
static const SpriteID SPR_IMG_ZOOMIN
Definition sprites.h:1264
static const SpriteID SPR_IMG_SHOW_COUNTOURS
Definition sprites.h:1255
static const SpriteID SPR_IMG_ZOOMOUT
Definition sprites.h:1265
static const SpriteID SPR_IMG_TOWN
Definition sprites.h:1248
static const SpriteID SPR_EMPTY
Empty (transparent blue) sprite.
Definition sprites.h:46
static const SpriteID SPR_IMG_SMALLMAP
Definition sprites.h:1247
@ WWT_IMGBTN
(Toggle) Button with image
Definition widget_type.h:41
@ WWT_PUSHIMGBTN
Normal push-button (no toggle button) with image caption.
@ WWT_PANEL
Simple depressed panel.
Definition widget_type.h:39
static constexpr WidgetID INVALID_WIDGET
An invalid widget index.
Definition window_type.h:24

Smallmap button definitions.

Definition at line 1945 of file smallmap_gui.cpp.

Referenced by NWidgetSmallmapButtons().

◆ num_buttons

uint NWidgetSmallmapButtons::num_buttons
private

The number of buttons excluding spacers.

Definition at line 1961 of file smallmap_gui.cpp.


The documentation for this class was generated from the following file: