OpenTTD: NWidgetLeaf Class Reference

OpenTTD

- Main Page
- Related Pages
- Modules
- Namespaces
- Data Structures
- Files

- Data Structures
- Class Hierarchy
- Data Fields

Public Member Functions | Static Public Member Functions | Static Public Attributes | Static Private Attributes
NWidgetLeaf Class Reference
Hierarchical widgets

Leaf widget. More...

`#include <widget_type.h>`

Inheritance diagram for NWidgetLeaf:

## Public Member Functions
| NWidgetLeaf (WidgetType tp, Colours colour, int index, uint32 data, StringID tip)
| Nested leaf widget.
void | SetupSmallestSize (Window *w, bool init_array)
| Compute smallest size needed by the widget.
void | Draw (const Window *w)
| Draw the widgets of the tree.
bool | ButtonHit (const Point &pt)
| For a NWID_BUTTON_DROPDOWN, test whether pt refers to the button or to the drop-down.
Public Member Functions inherited from NWidgetCore
| NWidgetCore (WidgetType tp, Colours colour, uint fill_x, uint fill_y, uint32 widget_data, StringID tool_tip)
| Initialization of a 'real' widget.
void | SetIndex (int index)
| Set index of the nested widget in the widget array.
void | SetDataTip (uint32 widget_data, StringID tool_tip)
| Set data and tool tip of the nested widget.
void | SetLowered (bool lowered)
| Lower or raise the widget.
bool | IsLowered () const
| Return whether the widget is lowered.
void | SetDisabled (bool disabled)
| Disable (grey-out) or enable the widget.
bool | IsDisabled () const
| Return whether the widget is disabled.
void | FillNestedArray (NWidgetBase **array, uint length)
NWidgetCore * | GetWidgetFromPos (int x, int y)
| Retrieve a widget by its position.
bool | IsHighlighted () const
| Return whether the widget is highlighted.
TextColour | GetHighlightColour () const
| Return the colour of the highlight.
void | SetHighlighted (TextColour highlight_colour)
| Highlight the widget or not.
Public Member Functions inherited from NWidgetResizeBase
| NWidgetResizeBase (WidgetType tp, uint fill_x, uint fill_y)
| Constructor for resizable nested widgets.
void | SetMinimalSize (uint min_x, uint min_y)
| Set minimal size of the widget.
void | SetMinimalTextLines (uint8 min_lines, uint8 spacing, FontSize size)
| Set minimal text lines for the widget.
void | SetFill (uint fill_x, uint fill_y)
| Set the filling of the widget from initial size.
void | SetResize (uint resize_x, uint resize_y)
| Set resize step of the widget.
void | AssignSizePosition (SizingType sizing, uint x, uint y, uint given_width, uint given_height, bool rtl)
| Assign size and position to the widget.
Public Member Functions inherited from NWidgetBase
| NWidgetBase (WidgetType tp)
| Base class constructor.
virtual NWidgetBase * | GetWidgetOfType (WidgetType tp)
| Retrieve a widget by its type.
void | SetPadding (uint8 top, uint8 right, uint8 bottom, uint8 left)
| 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).
Public Member Functions inherited from ZeroedMemoryAllocator
void * | operator new (size_t size)
| Memory allocator for a single class instance.
void * | operator new[] (size_t size)
| Memory allocator for an array of class instances.
void | operator delete (void *ptr)
| Memory release for a single class instance.
void | operator delete[] (void *ptr)
| Memory release for an array of class instances.

## Static Public Member Functions
static void | InvalidateDimensionCache ()
| Reset the cached dimensions.

## Static Public Attributes
static Dimension | dropdown_dimension = {0, 0}
| Cached size of a dropdown widget.

## Static Private Attributes
static Dimension | shadebox_dimension = {0, 0}
| Cached size of a shadebox widget.
static Dimension | debugbox_dimension = {0, 0}
| Cached size of a debugbox widget.
static Dimension | defsizebox_dimension = {0, 0}
| Cached size of a defsizebox widget.
static Dimension | stickybox_dimension = {0, 0}
| Cached size of a stickybox widget.
static Dimension | resizebox_dimension = {0, 0}
| Cached size of a resizebox widget.
static Dimension | closebox_dimension = {0, 0}
| Cached size of a closebox widget.

## Additional Inherited Members
Data Fields inherited from NWidgetCore
NWidgetDisplay | disp_flags
| Flags that affect display and interaction with the widget.
Colours | colour
| Colour of this widget.
int | index
| Index of the nested widget in the widget array of the window (`-1` means 'not used').
uint32 | widget_data
| Data of the widget.
StringID | tool_tip
| Tooltip of the widget.
int | scrollbar_index
| Index of an attached scrollbar.
TextColour | highlight_colour
| Colour of highlight.
Protected Member Functions inherited from NWidgetBase
void | StoreSizePosition (SizingType sizing, uint x, uint y, uint given_width, uint given_height)
| Store size and position.

## Detailed Description

Leaf widget.

Definition at line 770 of file widget_type.h.

## Constructor & Destructor Documentation

NWidgetLeaf::NWidgetLeaf | ( | WidgetType | tp,
|  | Colours | colour,
|  | int | index,
|  | uint32 | data,
|  | StringID | tip
| ) |  |

Nested leaf widget.

Parameters

  tp | Type of leaf widget.
  colour | Colour of the leaf widget.
  index | Index in the widget array used by the window system.
  data | Data of the widget.
  tip | Tooltip of the widget.

Definition at line 2112 of file widget.cpp.

References NWidgetResizeBase::min_x, NWidgetResizeBase::min_y, NWID_BUTTON_DROPDOWN, NWidgetCore::SetDataTip(), NWidgetResizeBase::SetFill(), NWidgetCore::SetIndex(), NWidgetResizeBase::SetMinimalSize(), NWidgetResizeBase::SetResize(), WD_CAPTION_HEIGHT, WD_CLOSEBOX_WIDTH, WD_DEBUGBOX_TOP, WD_DEFSIZEBOX_TOP, WD_DROPDOWN_HEIGHT, WD_RESIZEBOX_WIDTH, WD_SHADEBOX_TOP, WD_STICKYBOX_WIDTH, WWT_ARROWBTN, WWT_CAPTION, WWT_CLOSEBOX, WWT_DEBUGBOX, WWT_DEFSIZEBOX, WWT_DROPDOWN, WWT_EDITBOX, WWT_EMPTY, WWT_IMGBTN, WWT_IMGBTN_2, WWT_LABEL, WWT_MATRIX, WWT_PUSHARROWBTN, WWT_PUSHBTN, WWT_PUSHIMGBTN, WWT_PUSHTXTBTN, WWT_RESIZEBOX, WWT_SHADEBOX, WWT_STICKYBOX, WWT_TEXT, WWT_TEXTBTN, and WWT_TEXTBTN_2.

## Member Function Documentation

bool NWidgetLeaf::ButtonHit | ( | const Point & | pt | ) |

For a NWID_BUTTON_DROPDOWN, test whether pt refers to the button or to the drop-down.

Parameters

  pt | Point in the widget.

Returns
  The point refers to the button.

Note
  The magic constants are also used at DrawButtonDropdown.

Definition at line 2524 of file widget.cpp.

References _current_text_dir, NWidgetBase::current_x, NWidgetBase::pos_x, and TD_LTR.

void NWidgetLeaf::Draw | ( | const Window * | w | ) |
| virtual

Draw the widgets of the tree.

The function calls Window::DrawWidget for each widget with a non-negative index, after the widget itself is painted.

Parameters

  w | Window that owns the tree.

Implements NWidgetBase.

Definition at line 2392 of file widget.cpp.

References _colour_gradient, _current_text_dir, AWV_DECREASE, AWV_INCREASE, AWV_LEFT, AWV_RIGHT, NWidgetCore::colour, NWidgetBase::current_x, NWidgetBase::current_y, NWidgetCore::disp_flags, DrawButtonDropdown(), DrawCaption(), DrawCloseBox(), DrawDebugBox(), DrawDefSizeBox(), DrawDropdown(), DrawFrameRect(), DrawImageButtons(), DrawLabel(), DrawMatrix(), DrawResizeBox(), DrawShadeBox(), DrawStickyBox(), DrawText(), Window::DrawWidget(), FILLRECT_CHECKER, Window::flags, FR_LOWERED, Window::GetQueryString(), GfxFillRect(), NWidgetCore::index, NWidgetCore::IsDisabled(), NWidgetCore::IsLowered(), Window::IsShaded(), ND_DROPDOWN_ACTIVE, NWID_BUTTON_DROPDOWN, Window::owner, NWidgetBase::pos_x, NWidgetBase::pos_y, NWidgetBase::resize_x, NWidgetBase::resize_y, Window::SetStringParameters(), TD_RTL, NWidgetBase::type, WF_SIZING, WF_STICKY, NWidgetCore::widget_data, Window::width, WWT_ARROWBTN, WWT_CAPTION, WWT_CLOSEBOX, WWT_DEBUGBOX, WWT_DEFSIZEBOX, WWT_DROPDOWN, WWT_EDITBOX, WWT_EMPTY, WWT_IMGBTN, WWT_IMGBTN_2, WWT_LABEL, WWT_MATRIX, WWT_PUSHARROWBTN, WWT_PUSHBTN, WWT_PUSHIMGBTN, WWT_PUSHTXTBTN, WWT_RESIZEBOX, WWT_SHADEBOX, WWT_STICKYBOX, WWT_TEXT, WWT_TEXTBTN, and WWT_TEXTBTN_2.

void NWidgetLeaf::InvalidateDimensionCache | ( |  | ) |
| static

Reset the cached dimensions.

Definition at line 2085 of file widget.cpp.

References closebox_dimension, debugbox_dimension, defsizebox_dimension, dropdown_dimension, resizebox_dimension, shadebox_dimension, and stickybox_dimension.

Referenced by InitWindowSystem(), and ReInitAllWindows().

void NWidgetLeaf::SetupSmallestSize | ( | Window * | w,
|  | bool | init_array
| ) |  |
| virtual

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

  w | Window owning the widget.
  init_array | Initialize the `w->nested_array`.

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 2198 of file widget.cpp.

References _current_text_dir, _settings_client, NWidgetBase::fill_x, NWidgetBase::fill_y, GetSpriteSize(), GetStringBoundingBox(), ClientSettings::gui, NWidgetCore::index, Window::IsNewGRFInspectable(), max(), maxdim(), NWidgetResizeBase::min_x, NWidgetResizeBase::min_y, Window::nested_array, Window::nested_array_size, GUISettings::newgrf_developer_tools, NWID_BUTTON_DROPDOWN, NWidgetBase::resize_x, NWidgetBase::resize_y, Window::SetStringParameters(), NWidgetBase::smallest_x, NWidgetBase::smallest_y, TD_RTL, NWidgetBase::type, Window::UpdateWidgetSize(), WD_CAPTIONTEXT_BOTTOM, WD_CAPTIONTEXT_LEFT, WD_CAPTIONTEXT_RIGHT, WD_CAPTIONTEXT_TOP, WD_CLOSEBOX_BOTTOM, WD_CLOSEBOX_LEFT, WD_CLOSEBOX_RIGHT, WD_CLOSEBOX_TOP, WD_DEBUGBOX_BOTTOM, WD_DEBUGBOX_LEFT, WD_DEBUGBOX_RIGHT, WD_DEBUGBOX_TOP, WD_DEFSIZEBOX_BOTTOM, WD_DEFSIZEBOX_LEFT, WD_DEFSIZEBOX_RIGHT, WD_DEFSIZEBOX_TOP, WD_DROPDOWNTEXT_BOTTOM, WD_DROPDOWNTEXT_LEFT, WD_DROPDOWNTEXT_RIGHT, WD_DROPDOWNTEXT_TOP, WD_FRAMERECT_BOTTOM, WD_FRAMERECT_LEFT, WD_FRAMERECT_RIGHT, WD_FRAMERECT_TOP, WD_IMGBTN_BOTTOM, WD_IMGBTN_LEFT, WD_IMGBTN_RIGHT, WD_IMGBTN_TOP, WD_MATRIX_BOTTOM, WD_MATRIX_LEFT, WD_MATRIX_RIGHT, WD_MATRIX_TOP, WD_RESIZEBOX_BOTTOM, WD_RESIZEBOX_LEFT, WD_RESIZEBOX_RIGHT, WD_RESIZEBOX_TOP, WD_SHADEBOX_BOTTOM, WD_SHADEBOX_LEFT, WD_SHADEBOX_RIGHT, WD_SHADEBOX_TOP, WD_STICKYBOX_BOTTOM, WD_STICKYBOX_LEFT, WD_STICKYBOX_RIGHT, WD_STICKYBOX_TOP, NWidgetCore::widget_data, WWT_ARROWBTN, WWT_CAPTION, WWT_CLOSEBOX, WWT_DEBUGBOX, WWT_DEFSIZEBOX, WWT_DROPDOWN, WWT_EDITBOX, WWT_EMPTY, WWT_IMGBTN, WWT_IMGBTN_2, WWT_LABEL, WWT_MATRIX, WWT_PUSHARROWBTN, WWT_PUSHBTN, WWT_PUSHIMGBTN, WWT_PUSHTXTBTN, WWT_RESIZEBOX, WWT_SHADEBOX, WWT_STICKYBOX, WWT_TEXT, WWT_TEXTBTN, and WWT_TEXTBTN_2.

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

- src/widget_type.h
- src/widget.cpp