OpenTTD Source  13.2.1
widget.cpp File Reference
#include "stdafx.h"
#include "company_func.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.

Enumerations

enum  WidgetDrawDistances {
  WD_IMGBTN_LEFT = 1, WD_IMGBTN_RIGHT = 2, WD_IMGBTN_TOP = 1, WD_IMGBTN_BOTTOM = 2,
  WD_INSET_LEFT = 2, WD_INSET_RIGHT = 2, WD_INSET_TOP = 1, WD_VSCROLLBAR_LEFT = 2,
  WD_VSCROLLBAR_RIGHT = 2, WD_VSCROLLBAR_TOP = 3, WD_VSCROLLBAR_BOTTOM = 3, WD_HSCROLLBAR_LEFT = 3,
  WD_HSCROLLBAR_RIGHT = 3, WD_HSCROLLBAR_TOP = 2, WD_HSCROLLBAR_BOTTOM = 2, WD_BEVEL_LEFT = 1,
  WD_BEVEL_RIGHT = 1, WD_BEVEL_TOP = 1, WD_BEVEL_BOTTOM = 1, WD_FRAMERECT_LEFT = 2,
  WD_FRAMERECT_RIGHT = 2, WD_FRAMERECT_TOP = 1, WD_FRAMERECT_BOTTOM = 1, WD_FRAMETEXT_LEFT = 6,
  WD_FRAMETEXT_RIGHT = 6, WD_FRAMETEXT_TOP = 6, WD_FRAMETEXT_BOTTOM = 6, WD_MATRIX_LEFT = 2,
  WD_MATRIX_RIGHT = 2, WD_MATRIX_TOP = 3, WD_MATRIX_BOTTOM = 1, WD_SHADEBOX_WIDTH = 12,
  WD_SHADEBOX_LEFT = 2, WD_SHADEBOX_RIGHT = 2, WD_SHADEBOX_TOP = 3, WD_SHADEBOX_BOTTOM = 3,
  WD_STICKYBOX_WIDTH = 12, WD_STICKYBOX_LEFT = 2, WD_STICKYBOX_RIGHT = 2, WD_STICKYBOX_TOP = 3,
  WD_STICKYBOX_BOTTOM = 3, WD_DEBUGBOX_WIDTH = 12, WD_DEBUGBOX_LEFT = 2, WD_DEBUGBOX_RIGHT = 2,
  WD_DEBUGBOX_TOP = 3, WD_DEBUGBOX_BOTTOM = 3, WD_DEFSIZEBOX_WIDTH = 12, WD_DEFSIZEBOX_LEFT = 2,
  WD_DEFSIZEBOX_RIGHT = 2, WD_DEFSIZEBOX_TOP = 3, WD_DEFSIZEBOX_BOTTOM = 3, WD_RESIZEBOX_WIDTH = 12,
  WD_RESIZEBOX_LEFT = 2, WD_RESIZEBOX_RIGHT = 2, WD_RESIZEBOX_TOP = 2, WD_RESIZEBOX_BOTTOM = 2,
  WD_CLOSEBOX_WIDTH = 11, WD_CLOSEBOX_LEFT = 2, WD_CLOSEBOX_RIGHT = 1, WD_CLOSEBOX_TOP = 2,
  WD_CLOSEBOX_BOTTOM = 2, WD_CAPTION_HEIGHT = 14, WD_CAPTIONTEXT_LEFT = 2, WD_CAPTIONTEXT_RIGHT = 2,
  WD_CAPTIONTEXT_TOP = 2, WD_CAPTIONTEXT_BOTTOM = 2, WD_DROPDOWN_HEIGHT = 12, WD_DROPDOWNTEXT_LEFT = 2,
  WD_DROPDOWNTEXT_RIGHT = 2, WD_DROPDOWNTEXT_TOP = 1, WD_DROPDOWNTEXT_BOTTOM = 1, WD_PAR_VSEP_NORMAL = 2,
  WD_PAR_VSEP_WIDE = 8
}
 Distances used in drawing widgets. More...
 

Functions

static RectPadding ScaleGUITrad (const RectPadding &r)
 Scale a RectPadding to GUI zoom level. More...
 
static Dimension ScaleGUITrad (const Dimension &dim)
 Scale a Dimension to GUI zoom level. More...
 
Dimension GetScaledSpriteSize (SpriteID sprid)
 Scale sprite size for GUI. More...
 
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. More...
 
static Point HandleScrollbarHittest (const Scrollbar *sb, int top, int bottom, bool horizontal)
 Compute the vertical position of the draggable part of scrollbar. More...
 
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. More...
 
void ScrollbarClickHandler (Window *w, NWidgetCore *nw, int x, int y)
 Special handling for the scrollbar widget type. More...
 
int GetWidgetFromPos (const Window *w, int x, int y)
 Returns the index for the widget located at the given position relative to the window. More...
 
void DrawFrameRect (int left, int top, int right, int bottom, Colours colour, FrameFlags flags)
 Draw frame rectangle. More...
 
void DrawSpriteIgnorePadding (SpriteID img, PaletteID pal, const Rect &r, bool clicked, StringAlignment align)
 
static void DrawImageButtons (const Rect &r, WidgetType type, Colours colour, bool clicked, SpriteID img, StringAlignment align)
 Draw an image button. More...
 
static void DrawLabel (const Rect &r, WidgetType type, bool clicked, TextColour colour, StringID str, StringAlignment align)
 Draw the label-part of a widget. More...
 
static void DrawText (const Rect &r, TextColour colour, StringID str, StringAlignment align)
 Draw text. More...
 
static void DrawInset (const Rect &r, Colours colour, TextColour text_colour, StringID str, StringAlignment align)
 Draw an inset widget. More...
 
static void DrawMatrix (const Rect &r, Colours colour, bool clicked, uint16 data, uint resize_x, uint resize_y)
 Draw a matrix widget. More...
 
static void DrawVerticalScrollbar (const Rect &r, Colours colour, bool up_clicked, bool bar_dragged, bool down_clicked, const Scrollbar *scrollbar)
 Draw a vertical scrollbar. More...
 
static void DrawHorizontalScrollbar (const Rect &r, Colours colour, bool left_clicked, bool bar_dragged, bool right_clicked, const Scrollbar *scrollbar)
 Draw a horizontal scrollbar. More...
 
static void DrawFrame (const Rect &r, Colours colour, TextColour text_colour, StringID str, StringAlignment align)
 Draw a frame widget. More...
 
static void DrawShadeBox (const Rect &r, Colours colour, bool clicked)
 Draw a shade box. More...
 
static void DrawStickyBox (const Rect &r, Colours colour, bool clicked)
 Draw a sticky box. More...
 
static void DrawDefSizeBox (const Rect &r, Colours colour, bool clicked)
 Draw a defsize box. More...
 
static void DrawDebugBox (const Rect &r, Colours colour, bool clicked)
 Draw a NewGRF debug box. More...
 
static void DrawResizeBox (const Rect &r, Colours colour, bool at_left, bool clicked)
 Draw a resize box. More...
 
static void DrawCloseBox (const Rect &r, Colours colour)
 Draw a close box. More...
 
void DrawCaption (const Rect &r, Colours colour, Owner owner, TextColour text_colour, StringID str, StringAlignment align)
 Draw a caption bar. More...
 
static void DrawButtonDropdown (const Rect &r, Colours colour, bool clicked_button, bool clicked_dropdown, StringID str, StringAlignment align)
 Draw a button with a dropdown (WWT_DROPDOWN and NWID_BUTTON_DROPDOWN). More...
 
static int MakeNWidget (const NWidgetPart *parts, int count, NWidgetBase **dest, bool *fill_dest, int *biggest_index)
 Construct a single nested widget in *dest from its parts. More...
 
static int MakeWidgetTree (const NWidgetPart *parts, int count, NWidgetBase **parent, int *biggest_index)
 Build a nested widget tree by recursively filling containers with nested widgets read from their parts. More...
 
NWidgetContainerMakeNWidgets (const NWidgetPart *parts, int count, int *biggest_index, NWidgetContainer *container)
 Construct a nested widget tree from an array of parts. More...
 
NWidgetContainerMakeWindowNWidgetTree (const NWidgetPart *parts, int count, int *biggest_index, NWidgetStacked **shade_select)
 Make a nested widget tree for a window from a parts array. More...
 
NWidgetBaseMakeCompanyButtonRows (int *biggest_index, int widget_first, int widget_last, Colours button_colour, int max_length, StringID button_tooltip)
 Make a number of rows with button-like graphics, for enabling/disabling each company. More...
 

Detailed Description

Handling of the default/simple widgets.

Definition in file widget.cpp.

Enumeration Type Documentation

◆ WidgetDrawDistances

Distances used in drawing widgets.

Enumerator
WD_IMGBTN_LEFT 

Left offset of the image in the button.

WD_IMGBTN_RIGHT 

Right offset of the image in the button.

WD_IMGBTN_TOP 

Top offset of image in the button.

WD_IMGBTN_BOTTOM 

Bottom offset of image in the button.

WD_INSET_LEFT 

Left offset of string.

WD_INSET_RIGHT 

Right offset of string.

WD_INSET_TOP 

Top offset of string.

WD_VSCROLLBAR_LEFT 

Left offset of vertical scrollbar.

WD_VSCROLLBAR_RIGHT 

Right offset of vertical scrollbar.

WD_VSCROLLBAR_TOP 

Top offset of vertical scrollbar.

WD_VSCROLLBAR_BOTTOM 

Bottom offset of vertical scrollbar.

WD_HSCROLLBAR_LEFT 

Left offset of horizontal scrollbar.

WD_HSCROLLBAR_RIGHT 

Right offset of horizontal scrollbar.

WD_HSCROLLBAR_TOP 

Top offset of horizontal scrollbar.

WD_HSCROLLBAR_BOTTOM 

Bottom offset of horizontal scrollbar.

WD_BEVEL_LEFT 

Width of left bevel border.

WD_BEVEL_RIGHT 

Width of right bevel border.

WD_BEVEL_TOP 

Height of top bevel border.

WD_BEVEL_BOTTOM 

Height of bottom bevel border.

WD_FRAMERECT_LEFT 

Offset at left to draw the frame rectangular area.

WD_FRAMERECT_RIGHT 

Offset at right to draw the frame rectangular area.

WD_FRAMERECT_TOP 

Offset at top to draw the frame rectangular area.

WD_FRAMERECT_BOTTOM 

Offset at bottom to draw the frame rectangular area.

WD_FRAMETEXT_LEFT 

Left offset of the text of the frame.

WD_FRAMETEXT_RIGHT 

Right offset of the text of the frame.

WD_FRAMETEXT_TOP 

Top offset of the text of the frame.

WD_FRAMETEXT_BOTTOM 

Bottom offset of the text of the frame.

WD_MATRIX_LEFT 

Offset at left of a matrix cell.

WD_MATRIX_RIGHT 

Offset at right of a matrix cell.

WD_MATRIX_TOP 

Offset at top of a matrix cell.

WD_MATRIX_BOTTOM 

Offset at bottom of a matrix cell.

WD_SHADEBOX_WIDTH 

Width of a standard shade box widget.

WD_SHADEBOX_LEFT 

Left offset of shade sprite.

WD_SHADEBOX_RIGHT 

Right offset of shade sprite.

WD_SHADEBOX_TOP 

Top offset of shade sprite.

WD_SHADEBOX_BOTTOM 

Bottom offset of shade sprite.

WD_STICKYBOX_WIDTH 

Width of a standard sticky box widget.

WD_STICKYBOX_LEFT 

Left offset of sticky sprite.

WD_STICKYBOX_RIGHT 

Right offset of sticky sprite.

WD_STICKYBOX_TOP 

Top offset of sticky sprite.

WD_STICKYBOX_BOTTOM 

Bottom offset of sticky sprite.

WD_DEBUGBOX_WIDTH 

Width of a standard debug box widget.

WD_DEBUGBOX_LEFT 

Left offset of debug sprite.

WD_DEBUGBOX_RIGHT 

Right offset of debug sprite.

WD_DEBUGBOX_TOP 

Top offset of debug sprite.

WD_DEBUGBOX_BOTTOM 

Bottom offset of debug sprite.

WD_DEFSIZEBOX_WIDTH 

Width of a standard defsize box widget.

WD_DEFSIZEBOX_LEFT 

Left offset of defsize sprite.

WD_DEFSIZEBOX_RIGHT 

Right offset of defsize sprite.

WD_DEFSIZEBOX_TOP 

Top offset of defsize sprite.

WD_DEFSIZEBOX_BOTTOM 

Bottom offset of defsize sprite.

WD_RESIZEBOX_WIDTH 

Width of a resize box widget.

WD_RESIZEBOX_LEFT 

Left offset of resize sprite.

WD_RESIZEBOX_RIGHT 

Right offset of resize sprite.

WD_RESIZEBOX_TOP 

Top offset of resize sprite.

WD_RESIZEBOX_BOTTOM 

Bottom offset of resize sprite.

WD_CLOSEBOX_WIDTH 

Width of a close box widget.

WD_CLOSEBOX_LEFT 

Left offset of closebox string.

WD_CLOSEBOX_RIGHT 

Right offset of closebox string.

WD_CLOSEBOX_TOP 

Top offset of closebox string.

WD_CLOSEBOX_BOTTOM 

Bottom offset of closebox string.

WD_CAPTION_HEIGHT 

Height of a title bar.

WD_CAPTIONTEXT_LEFT 

Offset of the caption text at the left.

WD_CAPTIONTEXT_RIGHT 

Offset of the caption text at the right.

WD_CAPTIONTEXT_TOP 

Offset of the caption text at the top.

WD_CAPTIONTEXT_BOTTOM 

Offset of the caption text at the bottom.

WD_DROPDOWN_HEIGHT 

Height of a drop down widget.

WD_DROPDOWNTEXT_LEFT 

Left offset of the dropdown widget string.

WD_DROPDOWNTEXT_RIGHT 

Right offset of the dropdown widget string.

WD_DROPDOWNTEXT_TOP 

Top offset of the dropdown widget string.

WD_DROPDOWNTEXT_BOTTOM 

Bottom offset of the dropdown widget string.

WD_PAR_VSEP_NORMAL 

Normal amount of vertical space between two paragraphs of text.

WD_PAR_VSEP_WIDE 

Large amount of vertical space between two paragraphs of text.

Definition at line 28 of file widget.cpp.

Function Documentation

◆ DrawButtonDropdown()

static void DrawButtonDropdown ( const Rect r,
Colours  colour,
bool  clicked_button,
bool  clicked_dropdown,
StringID  str,
StringAlignment  align 
)
inlinestatic

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

Parameters
rRectangle containing the widget.
colourBackground colour of the widget.
clicked_buttonThe button-part is lowered.
clicked_dropdownThe drop-down part is lowered.
strText of the button.
alignAlignment of the text within the dropdown.
Note
Magic constants are also used in NWidgetLeaf::ButtonHit.

Definition at line 834 of file widget.cpp.

References _current_text_dir, DrawFrameRect(), NWidgetLeaf::dropdown_dimension, FR_LOWERED, and TD_LTR.

◆ DrawCaption()

void DrawCaption ( const Rect r,
Colours  colour,
Owner  owner,
TextColour  text_colour,
StringID  str,
StringAlignment  align 
)

Draw a caption bar.

Parameters
rRectangle of the bar.
colourColour of the window.
owner'Owner' of the window.
text_colourColour of the text.
strText to draw in the bar.
alignAlignment of the text.

Definition at line 804 of file widget.cpp.

References _colour_gradient, _company_colours, WidgetDimensions::bevel, WidgetDimensions::captiontext, DrawFrameRect(), DrawString(), FR_BORDERONLY, FR_DARKENED, FR_LOWERED, GetAlignedPosition(), GetStringBoundingBox(), GfxFillRect(), MAX_COMPANIES, WidgetDimensions::scaled, and Rect::Shrink().

Referenced by NewsWindow::DrawWidget().

◆ DrawCloseBox()

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

Draw a close box.

Parameters
rRectangle of the box.`
colourColour of the close box.

Definition at line 784 of file widget.cpp.

◆ DrawDebugBox()

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

Draw a NewGRF debug box.

Parameters
rRectangle of the box.
colourColour of the debug box.
clickedBox is lowered.

Definition at line 761 of file widget.cpp.

References DrawImageButtons(), and WWT_DEBUGBOX.

◆ DrawDefSizeBox()

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

Draw a defsize box.

Parameters
rRectangle of the box.
colourColour of the defsize box.
clickedBox is lowered.

Definition at line 750 of file widget.cpp.

References DrawImageButtons(), and WWT_DEFSIZEBOX.

◆ DrawFrame()

static void DrawFrame ( const Rect r,
Colours  colour,
TextColour  text_colour,
StringID  str,
StringAlignment  align 
)
inlinestatic

Draw a frame widget.

Parameters
rRectangle of the frame.
colourColour of the frame.
text_colourColour of the text.
strText of the frame.
alignAlignment of the text in the frame.

Definition at line 675 of file widget.cpp.

References _colour_gradient, _current_text_dir, WidgetDimensions::bevel, DrawString(), Rect::Expand(), FONT_HEIGHT_NORMAL, WidgetDimensions::frametext, GfxFillRect(), WidgetDimensions::scaled, ScaleGUITrad(), Rect::Shrink(), and TD_LTR.

◆ DrawFrameRect()

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

Draw frame rectangle.

Parameters
leftLeft edge of the frame
topTop edge of the frame
rightRight edge of the frame
bottomBottom edge of the frame
colourColour table to use.
See also
_colour_gradient
Parameters
flagsFlags controlling how to draw the frame.
See also
FrameFlags

Definition at line 414 of file widget.cpp.

Referenced by DrawButtonDropdown(), DrawCaption(), DrawImageButtons(), DrawInset(), DrawMatrix(), DrawResizeBox(), BaseNetworkContentDownloadStatusWindow::DrawWidget(), GenerateProgressWindow::DrawWidget(), NetworkJoinStatusWindow::DrawWidget(), ScanProgressWindow::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
rRectangle of the scrollbar widget.
colourColour of the scrollbar widget.
left_clickedLeft-arrow is clicked.
bar_draggedBar is dragged.
right_clickedRight-arrow is clicked.
scrollbarScrollbar size, offset, and capacity information.

Definition at line 636 of file widget.cpp.

References DrawImageButtons(), NWID_HSCROLLBAR, and Rect::WithWidth().

◆ DrawImageButtons()

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

Draw an image button.

Parameters
rRectangle of the button.
typeWidget type (WWT_IMGBTN or WWT_IMGBTN_2).
colourColour of the button.
clickedButton is lowered.
imgSprite to draw.
alignAlignment of the sprite.

Definition at line 471 of file widget.cpp.

References DrawFrameRect(), and FR_LOWERED.

Referenced by DrawDebugBox(), DrawDefSizeBox(), DrawHorizontalScrollbar(), DrawShadeBox(), DrawStickyBox(), and DrawVerticalScrollbar().

◆ DrawInset()

static void DrawInset ( const Rect r,
Colours  colour,
TextColour  text_colour,
StringID  str,
StringAlignment  align 
)
inlinestatic

Draw an inset widget.

Parameters
rRectangle of the background.
colourColour of the inset.
text_colourColour of the text.
strText to draw.
alignAlignment of the text.

Definition at line 521 of file widget.cpp.

References DrawFrameRect(), DrawString(), FR_DARKENED, FR_LOWERED, WidgetDimensions::scaled, and Rect::Shrink().

◆ DrawLabel()

static void DrawLabel ( const Rect r,
WidgetType  type,
bool  clicked,
TextColour  colour,
StringID  str,
StringAlignment  align 
)
inlinestatic

Draw the label-part of a widget.

Parameters
rRectangle of the label background.
typeWidget type (WWT_TEXTBTN, WWT_TEXTBTN_2, or WWT_LABEL).
clickedLabel is rendered lowered.
colourColour of the text.
strText to draw.
alignAlignment of the text.

Definition at line 489 of file widget.cpp.

◆ DrawMatrix()

static void DrawMatrix ( const Rect r,
Colours  colour,
bool  clicked,
uint16  data,
uint  resize_x,
uint  resize_y 
)
inlinestatic

Draw a matrix widget.

Parameters
rRectangle of the matrix background.
colourColour of the background.
clickedMatrix is rendered lowered.
dataData of the widget, number of rows and columns of the widget.
resize_xMatrix resize unit size.
resize_yMatrix resize unit size.

Definition at line 536 of file widget.cpp.

References DrawFrameRect(), and FR_LOWERED.

◆ DrawResizeBox()

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

Draw a resize box.

Parameters
rRectangle of the box.
colourColour of the resize box.
at_leftResize box is at left-side of the window,
clickedBox is lowered.

Definition at line 773 of file widget.cpp.

References DrawFrameRect(), and FR_LOWERED.

◆ DrawShadeBox()

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

Draw a shade box.

Parameters
rRectangle of the box.
colourColour of the shade box.
clickedBox is lowered.

Definition at line 728 of file widget.cpp.

References DrawImageButtons(), and WWT_SHADEBOX.

◆ DrawStickyBox()

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

Draw a sticky box.

Parameters
rRectangle of the box.
colourColour of the sticky box.
clickedBox is lowered.

Definition at line 739 of file widget.cpp.

References DrawImageButtons(), and WWT_STICKYBOX.

◆ DrawText()

static void DrawText ( const Rect r,
TextColour  colour,
StringID  str,
StringAlignment  align 
)
inlinestatic

Draw text.

Parameters
rRectangle of the background.
colourColour of the text.
strText to draw.
alignAlignment of the text.

Definition at line 506 of file widget.cpp.

References DrawString(), GetAlignedPosition(), and GetStringBoundingBox().

◆ 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
rRectangle of the scrollbar widget.
colourColour of the scrollbar widget.
up_clickedUp-arrow is clicked.
bar_draggedBar is dragged.
down_clickedDown-arrow is clicked.
scrollbarScrollbar size, offset, and capacity information.

Definition at line 596 of file widget.cpp.

References DrawImageButtons(), NWID_VSCROLLBAR, and Rect::WithHeight().

◆ 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
rRectangle of the widget to be drawn in.
dDimension of the object to be drawn.
alignAlignment of the object.
Returns
A point containing the position at which to draw.

Definition at line 239 of file widget.cpp.

References _current_text_dir, CenterBounds(), SA_FORCE, SA_HOR_CENTER, SA_HOR_MASK, SA_LEFT, SA_RIGHT, and TD_RTL.

Referenced by DrawCaption(), and DrawText().

◆ GetScaledSpriteSize()

Dimension GetScaledSpriteSize ( SpriteID  sprid)

Scale sprite size for GUI.

Offset is ignored.

Definition at line 187 of file widget.cpp.

References GetSpriteSize(), ScaleGUITrad(), and ZOOM_LVL_OUT_4X.

Referenced by DrawEngineList(), DepotWindow::OnInit(), NWidgetLeaf::SetupSmallestSize(), and NewGRFWindow::UpdateWidgetSize().

◆ GetWidgetFromPos()

int 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
*wWindow to look inside
xThe Window client X coordinate
yThe Window client y coordinate
Returns
A widget index, or -1 if no widget was found.

Definition at line 399 of file widget.cpp.

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

◆ HandleScrollbarHittest()

static Point HandleScrollbarHittest ( const Scrollbar sb,
int  top,
int  bottom,
bool  horizontal 
)
static

Compute the vertical position of the draggable part of scrollbar.

Parameters
sbScrollbar list data
topTop position of the scrollbar (top position of the up-button)
bottomBottom position of the scrollbar (bottom position of the down-button)
horizontalWhether the scrollbar is horizontal or not
Returns
A Point, with x containing the top coordinate of the draggable part, and y containing the bottom coordinate of the draggable part

Definition at line 268 of file widget.cpp.

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

◆ MakeCompanyButtonRows()

NWidgetBase* MakeCompanyButtonRows ( int *  biggest_index,
int  widget_first,
int  widget_last,
Colours  button_colour,
int  max_length,
StringID  button_tooltip 
)

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

Parameters
biggest_indexStorage for collecting the biggest index used in the returned tree.
widget_firstThe first widget index to use.
widget_lastThe last widget index to use.
colourThe colour in which to draw the button.
max_lengthMaximal number of company buttons in one row.
button_tooltipThe tooltip-string of every button.
Returns
Panel with rows of company buttons.
Postcondition
*biggest_index contains the largest used index in the tree.

Definition at line 3323 of file widget.cpp.

References GetSpriteSize().

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

◆ MakeNWidget()

static int MakeNWidget ( const NWidgetPart parts,
int  count,
NWidgetBase **  dest,
bool *  fill_dest,
int *  biggest_index 
)
static

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

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

Parameters
partsArray with parts of the nested widget.
countLength of the parts array.
destAddress of pointer to use for returning the composed widget.
fill_destFill the composed widget with child widgets.
biggest_indexPointer to biggest nested widget index in the tree encountered so far.
Returns
Number of widget part elements used to compose the widget.
Precondition
biggest_index != nullptr.

Definition at line 3004 of file widget.cpp.

References NWidgetPartWidget::colour, NWidgetPart::cont_flags, FS_BEGIN, NWidgetPart::func_ptr, NWidgetPartWidget::index, NWID_HORIZONTAL, NWID_HORIZONTAL_LTR, NWID_MATRIX, NWID_SPACER, NWID_VERTICAL, NWidgetResizeBase::SetMinimalSize(), NWidgetResizeBase::SetResize(), NWidgetPartTextLines::size, NWidgetPart::text_lines, NWidgetPart::type, NWidgetPart::widget, WPT_FUNCTION, WPT_MINSIZE, WPT_MINTEXTLINES, WPT_RESIZE, WWT_FRAME, WWT_INSET, WWT_PANEL, and NWidgetPart::xy.

Referenced by MakeWidgetTree().

◆ MakeWidgetTree()

static int MakeWidgetTree ( const NWidgetPart parts,
int  count,
NWidgetBase **  parent,
int *  biggest_index 
)
static

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

Parameters
partsArray with parts of the nested widgets.
countLength of the parts array.
parentPointer or container to use for storing the child widgets (*parent == nullptr or *parent == container or background widget).
biggest_indexPointer to biggest nested widget index in the tree.
Returns
Number of widget part elements used to fill the container.
Postcondition
*biggest_index contains the largest widget index of the tree and -1 if no index is used.

Definition at line 3194 of file widget.cpp.

References NWidgetContainer::Add(), NWidgetBackground::Add(), MakeNWidget(), NWID_HORIZONTAL, NWID_HORIZONTAL_LTR, NWID_MATRIX, NWID_SELECTION, NWID_VERTICAL, NWidgetBase::type, NWidgetPart::type, WPT_ENDCONTAINER, WWT_FRAME, WWT_INSET, and WWT_PANEL.

Referenced by MakeNWidgets(), and MakeWindowNWidgetTree().

◆ ScaleGUITrad() [1/2]

static Dimension ScaleGUITrad ( const Dimension dim)
inlinestatic

Scale a Dimension to GUI zoom level.

Parameters
dDimension at ZOOM_LVL_BASE (traditional "normal" interface size).
Returns
Dimension at #ZOOM_LVL_GUI (current interface size).

Definition at line 178 of file widget.cpp.

◆ ScaleGUITrad() [2/2]

static RectPadding ScaleGUITrad ( const RectPadding r)
inlinestatic

Scale a RectPadding to GUI zoom level.

Parameters
rRectPadding at ZOOM_LVL_BASE (traditional "normal" interface size).
Returns
RectPadding at #ZOOM_LVL_GUI (current interface size).

Definition at line 168 of file widget.cpp.

Referenced by SpriteFontCache::ClearFontCache(), ClickSliderWidget(), NWidgetLeaf::Draw(), LinkGraphOverlay::DrawContent(), DrawFrame(), LinkGraphOverlay::DrawLinks(), DrawSliderWidget(), LinkGraphOverlay::DrawStationDots(), BuildTreesWindow::DrawWidget(), EnsureVisibleCaption(), WindowDesc::GetDefaultHeight(), WindowDesc::GetDefaultWidth(), VehicleDetailsWindow::GetRoadVehDetailsHeight(), GetScaledSpriteSize(), GetVehicleListHeight(), NetworkInitChatMessage(), NetworkReInitChatBoxSize(), BuildObjectWindow::OnInit(), NetworkGameWindow::OnInit(), PaymentRatesGraphWindow::OnInit(), IndustryCargoesWindow::OnInit(), PreventHiding(), NWidgetResizeBase::SetMinimalSize(), NWidgetResizeBase::SetMinimalTextLines(), NWidgetPIPContainer::SetPIP(), SetupWidgetDimensions(), SpriteFontCache::SpriteFontCache(), LandInfoWindow::UpdateWidgetSize(), BuildTreesWindow::UpdateWidgetSize(), BuildObjectWindow::UpdateWidgetSize(), CompanyStationsWindow::UpdateWidgetSize(), BuildDocksDepotWindow::UpdateWidgetSize(), ScenarioEditorLandscapeGenerationWindow::UpdateWidgetSize(), TooltipsWindow::UpdateWidgetSize(), SpriteAlignerWindow::UpdateWidgetSize(), RefitWindow::UpdateWidgetSize(), BuildRoadDepotWindow::UpdateWidgetSize(), BuildRoadStationWindow::UpdateWidgetSize(), BuildRailStationWindow::UpdateWidgetSize(), BuildRailDepotWindow::UpdateWidgetSize(), and BuildRailWaypointWindow::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
wWindow on which a scroll was performed.
nwPointer to the scrollbar widget.
xThe X coordinate of the mouse click.
yThe Y coordinate of the mouse click.

Definition at line 375 of file widget.cpp.

◆ 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
wWindow on which a scroll was performed.
sbScrollbar
miMinimum coordinate of the scroll bar.
maMaximum coordinate of the scroll bar.
xThe X coordinate of the mouse click.
yThe Y coordinate of the mouse click.

Definition at line 311 of file widget.cpp.