OpenTTD Source: src/widget.cpp File Reference

OpenTTD Source 15.0-RC2

Data Structures | Functions | Variables
widget.cpp File Reference

Handling of the default/simple widgets. More...

`#include "stdafx.h"`
`#include "core/backup_type.hpp"`
`#include "company_func.h"`
`#include "settings_gui.h"`
`#include "strings_type.h"`
`#include "window_gui.h"`
`#include "viewport_func.h"`
`#include "zoom_func.h"`
`#include "strings_func.h"`
`#include "transparency.h"`
`#include "core/geometry_func.hpp"`
`#include "settings_type.h"`
`#include "querystring_gui.h"`
`#include "table/sprites.h"`
`#include "table/strings.h"`
`#include "table/string_colours.h"`
`#include "safeguards.h"`

Go to the source code of this file.

## Data Structures
class | NWidgetLayer

## Functions
static std::string | GetStringForWidget (const Window *w, const NWidgetCore *nwid, bool secondary=false)
static RectPadding | ScaleGUITrad (const RectPadding &r)
| Scale a RectPadding to GUI zoom level.
static Dimension | ScaleGUITrad (const Dimension &dim)
| Scale a Dimension to GUI zoom level.
Dimension | GetScaledSpriteSize (SpriteID sprid)
| Scale sprite size for GUI.
void | SetupWidgetDimensions ()
| Set up pre-scaled versions of Widget Dimensions.
static Point | GetAlignedPosition (const Rect &r, const Dimension &d, StringAlignment align)
| Calculate x and y coordinates for an aligned object within a window.
static std::pair< int, int > | HandleScrollbarHittest (const Scrollbar *sb, int mi, int ma, bool horizontal)
| Compute the vertical position of the draggable part of scrollbar.
static void | ScrollbarClickPositioning (Window *w, NWidgetScrollbar *sb, int x, int y, int mi, int ma)
| Compute new position of the scrollbar after a click and updates the window flags.
void | ScrollbarClickHandler (Window *w, NWidgetCore *nw, int x, int y)
| Special handling for the scrollbar widget type.
WidgetID | GetWidgetFromPos (const Window *w, int x, int y)
| Returns the index for the widget located at the given position relative to the window.
void | DrawFrameRect (int left, int top, int right, int bottom, Colours colour, FrameFlags flags)
| Draw frame rectangle.
void | DrawSpriteIgnorePadding (SpriteID img, PaletteID pal, const Rect &r, StringAlignment align)
static void | DrawImageButtons (const Rect &r, WidgetType type, Colours colour, bool clicked, SpriteID img, StringAlignment align)
| Draw an image button.
static void | DrawImageTextButtons (const Rect &r, Colours colour, bool clicked, SpriteID img, TextColour text_colour, const std::string &text, StringAlignment align, FontSize fs)
| Draw a button with image and rext.
static void | DrawLabel (const Rect &r, TextColour colour, std::string_view str, StringAlignment align, FontSize fs)
| Draw the label-part of a widget.
static void | DrawText (const Rect &r, TextColour colour, std::string_view str, StringAlignment align, FontSize fs)
| Draw text.
static void | DrawInset (const Rect &r, Colours colour, TextColour text_colour, std::string_view str, StringAlignment align, FontSize fs)
| Draw an inset widget.
static void | DrawMatrix (const Rect &r, Colours colour, bool clicked, uint32_t num_columns, uint32_t num_rows, uint resize_x, uint resize_y)
| Draw a matrix widget.
static void | DrawVerticalScrollbar (const Rect &r, Colours colour, bool up_clicked, bool bar_dragged, bool down_clicked, const Scrollbar *scrollbar)
| Draw a vertical scrollbar.
static void | DrawHorizontalScrollbar (const Rect &r, Colours colour, bool left_clicked, bool bar_dragged, bool right_clicked, const Scrollbar *scrollbar)
| Draw a horizontal scrollbar.
static void | DrawFrame (const Rect &r, Colours colour, TextColour text_colour, std::string_view str, StringAlignment align, FontSize fs)
| Draw a frame widget.
static void | DrawShadeBox (const Rect &r, Colours colour, bool clicked)
| Draw a shade box.
static void | DrawStickyBox (const Rect &r, Colours colour, bool clicked)
| Draw a sticky box.
static void | DrawDefSizeBox (const Rect &r, Colours colour, bool clicked)
| Draw a defsize box.
static void | DrawDebugBox (const Rect &r, Colours colour, bool clicked)
| Draw a NewGRF debug box.
static void | DrawResizeBox (const Rect &r, Colours colour, bool at_left, bool clicked, bool bevel)
| Draw a resize box.
static void | DrawCloseBox (const Rect &r, Colours colour)
| Draw a close box.
void | DrawCaption (const Rect &r, Colours colour, Owner owner, TextColour text_colour, std::string_view str, StringAlignment align, FontSize fs)
| Draw a caption bar.
static void | DrawButtonDropdown (const Rect &r, Colours colour, bool clicked_button, bool clicked_dropdown, std::string_view str, StringAlignment align)
| Draw a button with a dropdown (WWT_DROPDOWN and NWID_BUTTON_DROPDOWN).
static void | DrawOutline (const Window *, const NWidgetBase *wid)
Rect | ScrollRect (Rect r, const Scrollbar &sb, int resize_step)
| Apply 'scroll' to a rect to be drawn in.
static bool | IsAttributeWidgetPartType (WidgetType tp)
| Test if (an NWidgetPart) WidgetType is an attribute widget part type.
void | ApplyNWidgetPartAttribute (const NWidgetPart &nwid, NWidgetBase *dest)
| Apply an attribute NWidgetPart to an NWidget.
static std::unique_ptr< NWidgetBase > | MakeNWidget (const NWidgetPart &nwid)
| Make NWidget from an NWidgetPart.
static std::span< constNWidgetPart >::iterator | MakeNWidget (std::span< const NWidgetPart >::iterator nwid_begin, std::span< const NWidgetPart >::iterator nwid_end, std::unique_ptr< NWidgetBase > &dest, bool &fill_dest)
| Construct a single nested widget in *dest from its parts.
bool | IsContainerWidgetType (WidgetType tp)
| Test if WidgetType is a container widget.
static std::span< constNWidgetPart >::iterator | MakeWidgetTree (std::span< const NWidgetPart >::iterator nwid_begin, std::span< const NWidgetPart >::iterator nwid_end, std::unique_ptr< NWidgetBase > &parent)
| Build a nested widget tree by recursively filling containers with nested widgets read from their parts.
std::unique_ptr< NWidgetBase > | MakeNWidgets (std::span< const NWidgetPart > nwid_parts, std::unique_ptr< NWidgetBase > &&container)
| Construct a nested widget tree from an array of parts.
std::unique_ptr< NWidgetBase > | MakeWindowNWidgetTree (std::span< const NWidgetPart > nwid_parts, NWidgetStacked **shade_select)
| Make a nested widget tree for a window from a parts array.
std::unique_ptr< NWidgetBase > | MakeCompanyButtonRows (WidgetID widget_first, WidgetID widget_last, Colours button_colour, int max_length, StringID button_tooltip, bool resizable)
| Make a number of rows with button-like graphics, for enabling/disabling each company.

## Variables
bool | _draw_widget_outlines

## Detailed Description

Handling of the default/simple widgets.

Definition in file widget.cpp.

## Function Documentation

## ◆ ApplyNWidgetPartAttribute()

void ApplyNWidgetPartAttribute | ( | const NWidgetPart & | nwid,
|  | NWidgetBase * | dest
| ) |  |

Apply an attribute NWidgetPart to an NWidget.

Parameters

  nwid | Attribute NWidgetPart
  dest | NWidget to apply attribute to.

Precondition
  NWidgetPart must be an attribute NWidgetPart.

Definition at line 3138 of file widget.cpp.

References NWidgetPartAlignment::align, NWidgetPart::NWidgetPartUnion::align, NWidgetPart::NWidgetPartUnion::aspect, NWidgetBase::aspect_flags, NWidgetBase::aspect_ratio, NWidgetPartTextStyle::colour, NWidgetPartDataTip::data, NWidgetPart::NWidgetPartUnion::data_tip, FS_BEGIN, NWidgetPartWidget::index, NWidgetPartTextLines::lines, NWidgetPart::NWidgetPartUnion::padding, NWidgetPart::NWidgetPartUnion::pip, NWidgetPartPIP::post, NWidgetCore::scrollbar_index, NWidgetCore::SetAlignment(), NWidgetResizeBase::SetFill(), NWidgetResizeBase::SetMinimalSize(), NWidgetResizeBase::SetMinimalTextLines(), NWidgetBase::SetPadding(), NWidgetPIPContainer::SetPIP(), NWidgetBackground::SetPIP(), NWidgetPIPContainer::SetPIPRatio(), NWidgetBackground::SetPIPRatio(), NWidgetResizeBase::SetResize(), NWidgetCore::SetTextStyle(), NWidgetCore::SetToolTip(), NWidgetPartTextLines::size, NWidgetPartTextStyle::size, NWidgetPartTextLines::spacing, NWidgetPart::NWidgetPartUnion::text_lines, NWidgetPart::NWidgetPartUnion::text_style, NWidgetPartDataTip::tooltip, NWidgetPart::type, NWidgetPart::NWidgetPartUnion::widget, NWidgetCore::widget_data, WPT_ALIGNMENT, WPT_ASPECT, WPT_DATATIP, WPT_FILL, WPT_MINSIZE, WPT_MINTEXTLINES, WPT_PADDING, WPT_PIPRATIO, WPT_PIPSPACE, WPT_RESIZE, WPT_SCROLLBAR, WPT_TEXTSTYLE, Coord2D< T >::x, NWidgetPart::NWidgetPartUnion::xy, and Coord2D< T >::y.

Referenced by MakeNWidget().

## ◆ DrawButtonDropdown()

static void DrawButtonDropdown | ( | const Rect & | r,
|  | Colours | colour,
|  | bool | clicked_button,
|  | bool | clicked_dropdown,
|  | std::string_view | str,
|  | StringAlignment | align
| ) |  |
| inlinestatic

Draw a button with a dropdown (WWT_DROPDOWN and NWID_BUTTON_DROPDOWN).

Parameters

  r | Rectangle containing the widget.
  colour | Background colour of the widget.
  clicked_button | The button-part is clicked.
  clicked_dropdown | The drop-down part is clicked.
  str | Text of the button.
  align | Alignment of the text within the dropdown.

Note
  Magic constants are also used in NWidgetLeaf::ButtonHit.

Definition at line 748 of file widget.cpp.

References _current_text_dir, Rect::CentreToHeight(), DrawFrameRect(), DrawImageButtons(), DrawString(), NWidgetLeaf::dropdown_dimension, FS_NORMAL, GetCharacterHeight(), Rect::Indent(), Lowered, SA_CENTER, WidgetDimensions::scaled, TD_RTL, Rect::WithWidth(), and WWT_DROPDOWN.

Referenced by NWidgetLeaf::Draw().

## ◆ DrawCaption()

void DrawCaption | ( | const Rect & | r,
|  | Colours | colour,
|  | Owner | owner,
|  | TextColour | text_colour,
|  | std::string_view | str,
|  | StringAlignment | align,
|  | FontSize | fs
| ) |  |

Draw a caption bar.

Parameters

  r | Rectangle of the bar.
  colour | Colour of the window.
  owner | 'Owner' of the window.
  text_colour | Colour of the text.
  str | Text to draw in the bar.
  align | Alignment of the text.
  fs | Font size of the text.

Definition at line 718 of file widget.cpp.

References _company_colours, WidgetDimensions::bevel, BorderOnly, WidgetDimensions::captiontext, Darkened, DrawFrameRect(), DrawString(), GetAlignedPosition(), GetColourGradient(), GetStringBoundingBox(), GfxFillRect(), Lowered, WidgetDimensions::scaled, Rect::Shrink(), and Coord2D< T >::y.

Referenced by NWidgetLeaf::Draw(), and NewsWindow::DrawWidget().

## ◆ DrawCloseBox()

static void DrawCloseBox | ( | const Rect & | r,
|  | Colours | colour
| ) |  |
| inlinestatic

Draw a close box.

Parameters

  r | Rectangle of the box.`
  colour | Colour of the close box.

Definition at line 697 of file widget.cpp.

References CentreBounds(), DrawFrameRect(), DrawSprite(), GetSpriteSize(), PALETTE_TEXT_RECOLOUR, and ScaleSpriteTrad().

Referenced by NWidgetLeaf::Draw().

## ◆ DrawDebugBox()

static void DrawDebugBox | ( | const Rect & | r,
|  | Colours | colour,
|  | bool | clicked
| ) |  |
| inlinestatic

Draw a NewGRF debug box.

Parameters

  r | Rectangle of the box.
  colour | Colour of the debug box.
  clicked | Box is lowered.

Definition at line 669 of file widget.cpp.

References DrawImageButtons(), SA_CENTER, and WWT_DEBUGBOX.

Referenced by NWidgetLeaf::Draw().

## ◆ DrawDefSizeBox()

static void DrawDefSizeBox | ( | const Rect & | r,
|  | Colours | colour,
|  | bool | clicked
| ) |  |
| inlinestatic

Draw a defsize box.

Parameters

  r | Rectangle of the box.
  colour | Colour of the defsize box.
  clicked | Box is lowered.

Definition at line 658 of file widget.cpp.

References DrawImageButtons(), SA_CENTER, and WWT_DEFSIZEBOX.

Referenced by NWidgetLeaf::Draw().

## ◆ DrawFrame()

static void DrawFrame | ( | const Rect & | r,
|  | Colours | colour,
|  | TextColour | text_colour,
|  | std::string_view | str,
|  | StringAlignment | align,
|  | FontSize | fs
| ) |  |
| inlinestatic

Draw a frame widget.

Parameters

  r | Rectangle of the frame.
  colour | Colour of the frame.
  text_colour | Colour of the text.
  str | Text of the frame.
  align | Alignment of the text in the frame.
  fs | Font size of the text.

Definition at line 583 of file widget.cpp.

References _current_text_dir, WidgetDimensions::bevel, DrawString(), Rect::Expand(), WidgetDimensions::frametext, FS_NORMAL, GetCharacterHeight(), GetColourGradient(), GfxFillRect(), WidgetDimensions::scaled, ScaleGUITrad(), Rect::Shrink(), and TD_LTR.

Referenced by NWidgetBackground::Draw().

## ◆ DrawFrameRect()

void DrawFrameRect | ( | int | left,
|  | int | top,
|  | int | right,
|  | int | bottom,
|  | Colours | colour,
|  | FrameFlags | flags
| ) |  |

Draw frame rectangle.

Parameters

  left | Left edge of the frame
  top | Top edge of the frame
  right | Right edge of the frame
  bottom | Bottom edge of the frame
  colour | Colour table to use.

See also
  Colours

Parameters

  flags | Flags controlling how to draw the frame.

See also
  FrameFlags

Definition at line 289 of file widget.cpp.

References BorderOnly, Darkened, FILLRECT_RECOLOUR, GetColourGradient(), GfxFillRect(), Lowered, PALETTE_TO_TRANSPARENT, WidgetDimensions::scaled, Rect::Shrink(), BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test(), and Transparent.

Referenced by NWidgetBackground::Draw(), NWidgetLeaf::Draw(), DrawAircraftImage(), DrawArrowButtons(), DrawBoolButton(), DrawButtonDropdown(), ButtonLine::DrawButtons(), DrawCaption(), DrawCloseBox(), DrawDropDownButton(), DrawHorizontalScrollbar(), DrawImageButtons(), DrawImageTextButtons(), DrawInset(), DrawMatrix(), DrawResizeBox(), DrawRoadVehImage(), DrawShipImage(), DrawSliderWidget(), DrawTrainImage(), DrawUpDownButtons(), NewGRFInspectWindow::DrawVehicleChainWidget(), DrawVerticalScrollbar(), GenerateProgressWindow::DrawWidget(), BaseGraphWindow::DrawWidget(), BaseCargoGraphWindow::DrawWidget(), BaseNetworkContentDownloadStatusWindow::DrawWidget(), NetworkJoinStatusWindow::DrawWidget(), ScanProgressWindow::DrawWidget(), StoryBookWindow::DrawWidget(), TransparenciesWindow::DrawWidget(), RefitWindow::DrawWidget(), and Window::DrawWidgets().

## ◆ DrawHorizontalScrollbar()

static void DrawHorizontalScrollbar | ( | const Rect & | r,
|  | Colours | colour,
|  | bool | left_clicked,
|  | bool | bar_dragged,
|  | bool | right_clicked,
|  | const Scrollbar * | scrollbar
| ) |  |
| inlinestatic

Draw a horizontal scrollbar.

Parameters

  r | Rectangle of the scrollbar widget.
  colour | Colour of the scrollbar widget.
  left_clicked | Left-arrow is clicked.
  bar_dragged | Bar is dragged.
  right_clicked | Right-arrow is clicked.
  scrollbar | Scrollbar size, offset, and capacity information.

Definition at line 542 of file widget.cpp.

References WidgetDimensions::bevel, DrawFrameRect(), DrawImageButtons(), FILLRECT_CHECKER, GetColourGradient(), GfxFillRect(), HandleScrollbarHittest(), Rect::Height(), Lowered, NWID_HSCROLLBAR, SA_CENTER, WidgetDimensions::scaled, Rect::Shrink(), Rect::WithWidth(), and Rect::WithY().

Referenced by NWidgetScrollbar::Draw().

## ◆ DrawImageButtons()

static void DrawImageButtons | ( | const Rect & | r,
|  | WidgetType | type,
|  | Colours | colour,
|  | bool | clicked,
|  | SpriteID | img,
|  | StringAlignment | align
| ) |  |
| inlinestatic

Draw an image button.

Parameters

  r | Rectangle of the button.
  type | Widget type (WWT_IMGBTN or WWT_IMGBTN_2).
  colour | Colour of the button.
  clicked | Button is clicked.
  img | Sprite to draw.
  align | Alignment of the sprite.

Definition at line 344 of file widget.cpp.

References DrawFrameRect(), Lowered, and WWT_IMGBTN_2.

Referenced by NWidgetLeaf::Draw(), DrawButtonDropdown(), DrawDebugBox(), DrawDefSizeBox(), DrawHorizontalScrollbar(), DrawShadeBox(), DrawStickyBox(), and DrawVerticalScrollbar().

## ◆ DrawImageTextButtons()

static void DrawImageTextButtons | ( | const Rect & | r,
|  | Colours | colour,
|  | bool | clicked,
|  | SpriteID | img,
|  | TextColour | text_colour,
|  | const std::string & | text,
|  | StringAlignment | align,
|  | FontSize | fs
| ) |  |
| inlinestatic

Draw a button with image and rext.

Parameters

  r | Rectangle of the button.
  colour | Colour of the button.
  clicked | Button is clicked.
  img | Image caption.
  text_colour | Colour of the text.
  text | Text caption.
  align | Alignment of the caption.
  fs | Font size of the text.

Definition at line 364 of file widget.cpp.

References _current_text_dir, DrawFrameRect(), DrawString(), GetAlignedPosition(), GetScaledSpriteSize(), GetStringBoundingBox(), Rect::Indent(), Lowered, SA_HOR_CENTER, SA_VERT_MASK, WidgetDimensions::scaled, Rect::Shrink(), TD_RTL, Rect::WithWidth(), and Coord2D< T >::y.

Referenced by NWidgetLeaf::Draw().

## ◆ DrawInset()

static void DrawInset | ( | const Rect & | r,
|  | Colours | colour,
|  | TextColour | text_colour,
|  | std::string_view | str,
|  | StringAlignment | align,
|  | FontSize | fs
| ) |  |
| inlinestatic

Draw an inset widget.

Parameters

  r | Rectangle of the background.
  colour | Colour of the inset.
  text_colour | Colour of the text.
  str | Text to draw.
  align | Alignment of the text.
  fs | Font size of the text.

Definition at line 427 of file widget.cpp.

References Darkened, DrawFrameRect(), DrawString(), WidgetDimensions::inset, Lowered, WidgetDimensions::scaled, and Rect::Shrink().

Referenced by NWidgetBackground::Draw().

## ◆ DrawLabel()

static void DrawLabel | ( | const Rect & | r,
|  | TextColour | colour,
|  | std::string_view | str,
|  | StringAlignment | align,
|  | FontSize | fs
| ) |  |
| inlinestatic

Draw the label-part of a widget.

Parameters

  r | Rectangle of the label background.
  colour | Colour of the text.
  str | Text to draw.
  align | Alignment of the text.
  fs | Font size of the text.

Definition at line 392 of file widget.cpp.

References DrawString(), GetAlignedPosition(), GetStringBoundingBox(), and Coord2D< T >::y.

Referenced by NWidgetLeaf::Draw().

## ◆ DrawMatrix()

static void DrawMatrix | ( | const Rect & | r,
|  | Colours | colour,
|  | bool | clicked,
|  | uint32_t | num_columns,
|  | uint32_t | num_rows,
|  | uint | resize_x,
|  | uint | resize_y
| ) |  |
| inlinestatic

Draw a matrix widget.

Parameters

  r | Rectangle of the matrix background.
  colour | Colour of the background.
  clicked | Matrix is rendered lowered.
  num_columns | The number of columns in the matrix.
  num_rows | The number of rows in the matrix.
  resize_x | Matrix resize unit size.
  resize_y | Matrix resize unit size.

Definition at line 443 of file widget.cpp.

References WidgetDimensions::bevel, DrawFrameRect(), GetColourGradient(), GfxFillRect(), Rect::Height(), Lowered, WidgetDimensions::scaled, and Rect::Width().

Referenced by NWidgetLeaf::Draw().

## ◆ DrawOutline()

static void DrawOutline | ( | const Window * | ,
|  | const NWidgetBase * | wid
| ) |  |
| static

Definition at line 822 of file widget.cpp.

## ◆ DrawResizeBox()

static void DrawResizeBox | ( | const Rect & | r,
|  | Colours | colour,
|  | bool | at_left,
|  | bool | clicked,
|  | bool | bevel
| ) |  |
| inlinestatic

Draw a resize box.

Parameters

  r | Rectangle of the box.
  colour | Colour of the resize box.
  at_left | Resize box is at left-side of the window,
  clicked | Box is lowered.
  bevel | Draw bevel iff set.

Definition at line 682 of file widget.cpp.

References WidgetDimensions::bevel, DrawFrameRect(), GetColourGradient(), GfxFillRect(), Lowered, SA_BOTTOM, SA_FORCE, SA_LEFT, SA_RIGHT, WidgetDimensions::scaled, ScaleGUITrad(), and Rect::Shrink().

Referenced by NWidgetLeaf::Draw().

## ◆ DrawShadeBox()

static void DrawShadeBox | ( | const Rect & | r,
|  | Colours | colour,
|  | bool | clicked
| ) |  |
| inlinestatic

Draw a shade box.

Parameters

  r | Rectangle of the box.
  colour | Colour of the shade box.
  clicked | Box is lowered.

Definition at line 636 of file widget.cpp.

References DrawImageButtons(), SA_CENTER, and WWT_SHADEBOX.

Referenced by NWidgetLeaf::Draw().

## ◆ DrawSpriteIgnorePadding()

void DrawSpriteIgnorePadding | ( | SpriteID | img,
|  | PaletteID | pal,
|  | const Rect & | r,
|  | StringAlignment | align
| ) |  |

Definition at line 324 of file widget.cpp.

## ◆ DrawStickyBox()

static void DrawStickyBox | ( | const Rect & | r,
|  | Colours | colour,
|  | bool | clicked
| ) |  |
| inlinestatic

Draw a sticky box.

Parameters

  r | Rectangle of the box.
  colour | Colour of the sticky box.
  clicked | Box is lowered.

Definition at line 647 of file widget.cpp.

References DrawImageButtons(), SA_CENTER, and WWT_STICKYBOX.

Referenced by NWidgetLeaf::Draw().

## ◆ DrawText()

static void DrawText | ( | const Rect & | r,
|  | TextColour | colour,
|  | std::string_view | str,
|  | StringAlignment | align,
|  | FontSize | fs
| ) |  |
| inlinestatic

Draw text.

Parameters

  r | Rectangle of the background.
  colour | Colour of the text.
  str | Text to draw.
  align | Alignment of the text.
  fs | Font size of the text.

Definition at line 409 of file widget.cpp.

References DrawString(), GetAlignedPosition(), GetStringBoundingBox(), and Coord2D< T >::y.

Referenced by NWidgetLeaf::Draw().

## ◆ DrawVerticalScrollbar()

static void DrawVerticalScrollbar | ( | const Rect & | r,
|  | Colours | colour,
|  | bool | up_clicked,
|  | bool | bar_dragged,
|  | bool | down_clicked,
|  | const Scrollbar * | scrollbar
| ) |  |
| inlinestatic

Draw a vertical scrollbar.

Parameters

  r | Rectangle of the scrollbar widget.
  colour | Colour of the scrollbar widget.
  up_clicked | Up-arrow is clicked.
  bar_dragged | Bar is dragged.
  down_clicked | Down-arrow is clicked.
  scrollbar | Scrollbar size, offset, and capacity information.

Definition at line 501 of file widget.cpp.

References WidgetDimensions::bevel, DrawFrameRect(), DrawImageButtons(), FILLRECT_CHECKER, GetColourGradient(), GfxFillRect(), HandleScrollbarHittest(), Lowered, NWID_VSCROLLBAR, SA_CENTER, WidgetDimensions::scaled, Rect::Shrink(), Rect::Width(), Rect::WithHeight(), and Rect::WithX().

Referenced by NWidgetScrollbar::Draw().

## ◆ GetAlignedPosition()

static Point GetAlignedPosition | ( | const Rect & | r,
|  | const Dimension & | d,
|  | StringAlignment | align
| ) |  |
| inlinestatic

Calculate x and y coordinates for an aligned object within a window.

Parameters

  r | Rectangle of the widget to be drawn in.
  d | Dimension of the object to be drawn.
  align | Alignment of the object.

Returns
  A point containing the position at which to draw.

Definition at line 120 of file widget.cpp.

References _current_text_dir, CentreBounds(), SA_BOTTOM, SA_FORCE, SA_HOR_CENTER, SA_HOR_MASK, SA_LEFT, SA_RIGHT, SA_TOP, SA_VERT_CENTER, SA_VERT_MASK, TD_RTL, Coord2D< T >::x, and Coord2D< T >::y.

Referenced by NWidgetLeaf::Draw(), DrawCaption(), DrawImageTextButtons(), DrawLabel(), and DrawText().

## ◆ GetScaledSpriteSize()

Dimension GetScaledSpriteSize | ( | SpriteID | sprid | ) |

Scale sprite size for GUI.

Offset is ignored.

Definition at line 68 of file widget.cpp.

References GetSpriteSize(), Normal, ScaleGUITrad(), Coord2D< T >::x, and Coord2D< T >::y.

Referenced by VehicleGroupWindow::ComputeGroupInfoSize(), CompanyButtonLine::Draw(), ClientButtonLine::Draw(), DrawEngineList(), DrawImageTextButtons(), VehicleViewWindow::DrawWidget(), QueryString::GetBoundingRect(), QueryString::GetCaretPosition(), QueryString::GetCharAtPosition(), ClientButtonLine::GetTooltip(), DepotWindow::OnInit(), NetworkContentListWindow::OnInit(), NetworkGameWindow::OnInit(), NWidgetLeaf::SetupSmallestSize(), BuildBridgeWindow::UpdateWidgetSize(), SelectCompanyManagerFaceWindow::UpdateWidgetSize(), CompanyWindow::UpdateWidgetSize(), BuyCompanyWindow::UpdateWidgetSize(), ErrmsgWindow::UpdateWidgetSize(), NetworkClientListWindow::UpdateWidgetSize(), NewGRFWindow::UpdateWidgetSize(), NewsWindow::UpdateWidgetSize(), and VehicleViewWindow::UpdateWidgetSize().

## ◆ GetStringForWidget()

static std::string GetStringForWidget | ( | const Window * | w,
|  | const NWidgetCore * | nwid,
|  | bool | secondary = `false`
| ) |  |
| static

Definition at line 32 of file widget.cpp.

## ◆ GetWidgetFromPos()

WidgetID GetWidgetFromPos | ( | const Window * | w,
|  | int | x,
|  | int | y
| ) |  |

Returns the index for the widget located at the given position relative to the window.

It includes all widget-corner pixels as well.

Parameters

  *w | Window to look inside
  x | The Window client X coordinate
  y | The Window client y coordinate

Returns
  A widget index, or `INVALID_WIDGET` if no widget was found.

Definition at line 274 of file widget.cpp.

References INVALID_WIDGET, and Window::nested_root.

Referenced by DropdownWindow::GetDropDownItem(), HandleMouseDragDrop(), and Window::OnDropdownClose().

## ◆ HandleScrollbarHittest()

static std::pair< int, int > HandleScrollbarHittest | ( | const Scrollbar * | sb,
|  | int | mi,
|  | int | ma,
|  | bool | horizontal
| ) |  |
| static

Compute the vertical position of the draggable part of scrollbar.

Parameters

  sb | Scrollbar list data
  mi | Minimum coordinate of the scroll bar.
  ma | Maximum coordinate of the scroll bar.
  horizontal | Whether the scrollbar is horizontal or not

Returns
  A pair, with first containing the minimum coordinate of the draggable part, and second containing the maximum coordinate of the draggable part

Definition at line 149 of file widget.cpp.

References _current_text_dir, Scrollbar::GetCapacity(), Scrollbar::GetCount(), Scrollbar::GetPosition(), and TD_RTL.

Referenced by DrawHorizontalScrollbar(), DrawVerticalScrollbar(), and ScrollbarClickPositioning().

## ◆ IsAttributeWidgetPartType()

static bool IsAttributeWidgetPartType | ( | WidgetType | tp | ) |
| static

Test if (an NWidgetPart) WidgetType is an attribute widget part type.

Parameters

  tp | WidgetType to test.

Returns
  True iff WidgetType is an attribute widget.

Definition at line 3127 of file widget.cpp.

References WPT_ATTRIBUTE_BEGIN, and WPT_ATTRIBUTE_END.

Referenced by MakeNWidget(), and MakeNWidget().

## ◆ IsContainerWidgetType()

bool IsContainerWidgetType | ( | WidgetType | tp | ) |

Test if WidgetType is a container widget.

Parameters

  tp | WidgetType to test.

Returns
  True iff WidgetType is a container widget.

Definition at line 3317 of file widget.cpp.

References NWID_HORIZONTAL, NWID_HORIZONTAL_LTR, NWID_LAYER, NWID_MATRIX, NWID_SELECTION, NWID_VERTICAL, WWT_FRAME, WWT_INSET, and WWT_PANEL.

Referenced by IsNWidgetTreeClosed(), MakeNWidget(), and MakeWidgetTree().

## ◆ MakeCompanyButtonRows()

std::unique_ptr< NWidgetBase > MakeCompanyButtonRows | ( | WidgetID | widget_first,
|  | WidgetID | widget_last,
|  | Colours | button_colour,
|  | int | max_length,
|  | StringID | button_tooltip,
|  | bool | resizable
| ) |  |

Make a number of rows with button-like graphics, for enabling/disabling each company.

Parameters

  widget_first | The first widget index to use.
  widget_last | The last widget index to use.
  colour | The colour in which to draw the button.
  max_length | Maximal number of company buttons in one row.
  button_tooltip | The tooltip-string of every button.
  resizable | Whether the rows are resizable.

Returns
  Panel with rows of company buttons.

Definition at line 3435 of file widget.cpp.

References GetSpriteSize(), RectPadding::Horizontal(), WidgetDimensions::matrix, Normal, WidgetDimensions::unscaled, RectPadding::Vertical(), and WWT_PANEL.

Referenced by MakeCompanyButtonRowsGraphGUI(), MakeCompanyButtonRowsLinkGraphGUI(), and MakeCompanyButtonRowsScriptDebug().

## ◆ MakeNWidget() [1/2]

static std::unique_ptr< NWidgetBase > MakeNWidget | ( | const NWidgetPart & | nwid | ) |
| static

Make NWidget from an NWidgetPart.

Parameters

  nwid | NWidgetPart.

Precondition
  NWidgetPart must not be an attribute NWidgetPart nor WPT_ENDCONTAINER.

Returns
  Pointer to created NWidget.

Definition at line 3246 of file widget.cpp.

References NWidgetPartWidget::colour, NWidgetPart::NWidgetPartUnion::container, NWidgetPart::NWidgetPartUnion::func_ptr, NWidgetPartWidget::index, IsAttributeWidgetPartType(), NWID_BUTTON_DROPDOWN, NWID_HORIZONTAL, NWID_HORIZONTAL_LTR, NWID_HSCROLLBAR, NWID_LAYER, NWID_MATRIX, NWID_SELECTION, NWID_SPACER, NWID_VERTICAL, NWID_VIEWPORT, NWID_VSCROLLBAR, NWidgetPart::type, NWidgetPart::NWidgetPartUnion::widget, WPT_ENDCONTAINER, WPT_FUNCTION, WWT_FRAME, WWT_INSET, WWT_LAST, and WWT_PANEL.

Referenced by MakeNWidget(), and MakeWidgetTree().

## ◆ MakeNWidget() [2/2]

static std::span< constNWidgetPart >::iterator MakeNWidget | ( | std::span< const NWidgetPart >::iterator | nwid_begin,
|  | std::span< const NWidgetPart >::iterator | nwid_end,
|  | std::unique_ptr< NWidgetBase > & | dest,
|  | bool & | fill_dest
| ) |  |
| static

Construct a single nested widget in *dest from its parts.

Construct a NWidgetBase object from a NWidget function, and apply all attributes that follow it, until encountering a EndContainer, another NWidget, or the end of the parts array.

Parameters

  | nwid_begin | Iterator to beginning of nested widget parts.
  | nwid_end | Iterator to ending of nested widget parts.
  [out] | dest | Address of pointer to use for returning the composed widget.
  [out] | fill_dest | Fill the composed widget with child widgets.

Returns
  Iterator to remaining nested widget parts.

Definition at line 3290 of file widget.cpp.

References ApplyNWidgetPartAttribute(), IsAttributeWidgetPartType(), IsContainerWidgetType(), MakeNWidget(), and WPT_ENDCONTAINER.

## ◆ MakeWidgetTree()

static std::span< constNWidgetPart >::iterator MakeWidgetTree | ( | std::span< const NWidgetPart >::iterator | nwid_begin,
|  | std::span< const NWidgetPart >::iterator | nwid_end,
|  | std::unique_ptr< NWidgetBase > & | parent
| ) |  |
| static

Build a nested widget tree by recursively filling containers with nested widgets read from their parts.

Parameters

  nwid_begin | Iterator to beginning of nested widget parts.
  nwid_end | Iterator to ending of nested widget parts.
  parent | Pointer or container to use for storing the child widgets (*parent == nullptr or *parent == container or background widget).

Returns
  Iterator to remaining nested widget parts.

Definition at line 3330 of file widget.cpp.

References NWidgetBackground::Add(), NWidgetContainer::Add(), IsContainerWidgetType(), MakeNWidget(), MakeWidgetTree(), and WPT_ENDCONTAINER.

Referenced by MakeNWidgets(), MakeWidgetTree(), and MakeWindowNWidgetTree().

## ◆ ScaleGUITrad() [1/2]

static Dimension ScaleGUITrad | ( | const Dimension & | dim | ) |
| inlinestatic

Scale a Dimension to GUI zoom level.

Parameters

  d | Dimension at ZOOM_BASE (traditional "normal" interface size).

Returns
  Dimension at current interface size.

Definition at line 59 of file widget.cpp.

References ScaleGUITrad().

## ◆ ScaleGUITrad() [2/2]

static RectPadding ScaleGUITrad | ( | const RectPadding & | r | ) |
| inlinestatic

Scale a RectPadding to GUI zoom level.

Parameters

  r | RectPadding at ZOOM_BASE (traditional "normal" interface size).

Returns
  RectPadding at current interface size.

Definition at line 49 of file widget.cpp.

References ScaleGUITrad().

Referenced by NWidgetServerListHeader::AssignSizePosition(), NWidgetNewGRFDisplay::AssignSizePosition(), SpriteFontCache::ClearFontCache(), ClickSliderWidget(), NWidgetLeaf::Draw(), DrawBadgeColumn(), DrawCargoIconOverlay(), LinkGraphOverlay::DrawContent(), DrawFrame(), BaseGraphWindow::DrawGraph(), DrawLayoutLine(), LinkGraphOverlay::DrawLinks(), DrawResizeBox(), DrawSliderWidget(), SmallMapWindow::DrawSmallMap(), LinkGraphOverlay::DrawStationDots(), BaseVehicleListWindow::DrawVehicleListItems(), LinkGraphOverlay::DrawVertex(), DepotWindow::DrawWidget(), PickerWindow::DrawWidget(), SmallMapWindow::DrawWidget(), StatusBarWindow::DrawWidget(), ScenarioEditorLandscapeGenerationWindow::DrawWidget(), BuildTreesWindow::DrawWidget(), VehicleDetailsWindow::DrawWidget(), WindowDesc::GetDefaultHeight(), WindowDesc::GetDefaultWidth(), NWidgetBadgeFilter::GetDropDownList(), GetMaxTreeSpriteSize(), VehicleDetailsWindow::GetRoadVehDetailsHeight(), GetScaledSpriteSize(), GetVehicleListHeight(), GUIBadgeClasses::GUIBadgeClasses(), HandleWindowDragging(), NetworkDrawChatMessage(), NetworkInitChatMessage(), NetworkReInitChatBoxSize(), IndustryCargoesWindow::OnInit(), MainWindow::OnPaint(), ScaleGUITrad(), ScaleGUITrad(), NWidgetResizeBase::SetMinimalSize(), NWidgetResizeBase::SetMinimalTextLines(), NWidgetPIPContainer::SetPIP(), NWidgetLeaf::SetupSmallestSize(), SetupWidgetDimensions(), ShowDropDownList(), SpriteFontCache::SpriteFontCache(), StationsWndShowStationRating(), UpdateGUIZoom(), BuildDocksDepotWindow::UpdateWidgetSize(), FrametimeGraphWindow::UpdateWidgetSize(), BaseGraphWindow::UpdateWidgetSize(), LandInfoWindow::UpdateWidgetSize(), TooltipsWindow::UpdateWidgetSize(), NetworkClientListWindow::UpdateWidgetSize(), SpriteAlignerWindow::UpdateWidgetSize(), BuildObjectWindow::UpdateWidgetSize(), PickerWindow::UpdateWidgetSize(), BuildRailStationWindow::UpdateWidgetSize(), BuildRailDepotWindow::UpdateWidgetSize(), BuildRoadDepotWindow::UpdateWidgetSize(), BuildRoadStationWindow::UpdateWidgetSize(), CompanyStationsWindow::UpdateWidgetSize(), ScenarioEditorLandscapeGenerationWindow::UpdateWidgetSize(), BuildTreesWindow::UpdateWidgetSize(), RefitWindow::UpdateWidgetSize(), and VehicleDetailsWindow::UpdateWidgetSize().

## ◆ ScrollbarClickHandler()

void ScrollbarClickHandler | ( | Window * | w,
|  | NWidgetCore * | nw,
|  | int | x,
|  | int | y
| ) |  |

Special handling for the scrollbar widget type.

Handles the special scrolling buttons and other scrolling.

Parameters

  w | Window on which a scroll was performed.
  nw | Pointer to the scrollbar widget.
  x | The X coordinate of the mouse click.
  y | The Y coordinate of the mouse click.

Definition at line 250 of file widget.cpp.

References NWidgetBase::current_x, NWidgetBase::current_y, NWID_HSCROLLBAR, NWidgetBase::pos_x, NWidgetBase::pos_y, ScrollbarClickPositioning(), and NWidgetBase::type.

Referenced by DispatchLeftClickEvent().

## ◆ ScrollbarClickPositioning()

static void ScrollbarClickPositioning | ( | Window * | w,
|  | NWidgetScrollbar * | sb,
|  | int | x,
|  | int | y,
|  | int | mi,
|  | int | ma
| ) |  |
| static

Compute new position of the scrollbar after a click and updates the window flags.

Parameters

  w | Window on which a scroll was performed.
  sb | Scrollbar
  x | The X coordinate of the mouse click.
  y | The Y coordinate of the mouse click.
  mi | Minimum coordinate of the scroll bar.
  ma | Maximum coordinate of the scroll bar.

Definition at line 185 of file widget.cpp.

References _current_text_dir, NWidgetCore::disp_flags, HandleScrollbarHittest(), Window::mouse_capture_widget, NWID_HSCROLLBAR, Window::OnScrollbarScroll(), CursorVars::pos, ScrollbarDown, ScrollbarUp, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Set(), Window::SetDirty(), NWidgetBase::SetDirty(), Scrollbar::SS_BIG, TD_RTL, NWidgetBase::type, and Scrollbar::UpdatePosition().

Referenced by ScrollbarClickHandler().

## ◆ ScrollRect()

Rect ScrollRect | ( | Rect | r,
|  | const Scrollbar & | sb,
|  | int | resize_step
| ) |  |

Apply 'scroll' to a rect to be drawn in.

Parameters

  r | Rect to be 'scrolled'.
  sb | The scrollbar affecting the scroll.
  resize_step | Resize step of the widget/scrollbar (1 if the scrollbar is pixel-based.)

Returns
  Scrolled rect.

Definition at line 2516 of file widget.cpp.

References _current_text_dir, Scrollbar::GetCount(), Scrollbar::GetPosition(), Scrollbar::IsVertical(), and TD_RTL.

Referenced by IndustryDirectoryWindow::DrawWidget(), TextfileWindow::DrawWidget(), and ScriptDebugWindow::DrawWidgetLog().

## ◆ SetupWidgetDimensions()

void SetupWidgetDimensions | ( |  | ) |

Set up pre-scaled versions of Widget Dimensions.

Definition at line 80 of file widget.cpp.

References _settings_client, WidgetDimensions::bevel, WidgetDimensions::captiontext, WidgetDimensions::closebox, WidgetDimensions::debugbox, WidgetDimensions::defsizebox, WidgetDimensions::dropdownlist, WidgetDimensions::dropdowntext, WidgetDimensions::framerect, WidgetDimensions::frametext, WidgetDimensions::fullbevel, ClientSettings::gui, WidgetDimensions::hscrollbar, WidgetDimensions::hsep_indent, WidgetDimensions::hsep_normal, WidgetDimensions::hsep_wide, WidgetDimensions::imgbtn, WidgetDimensions::inset, WidgetDimensions::matrix, WidgetDimensions::modalpopup, WidgetDimensions::resizebox, GUISettings::scale_bevels, WidgetDimensions::scaled, ScaleGUITrad(), WidgetDimensions::shadebox, WidgetDimensions::stickybox, WidgetDimensions::unscaled, WidgetDimensions::vscrollbar, WidgetDimensions::vsep_normal, and WidgetDimensions::vsep_wide.

Referenced by AdjustGUIZoom(), InitWindowSystem(), GameOptionsWindow::OnClick(), and ReInitAllWindows().

## Variable Documentation

## ◆ _draw_widget_outlines

bool _draw_widget_outlines

Definition at line 820 of file widget.cpp.