Go to the documentation of this file.
76 DrawFrameRect(r.left, r.top, r.right, r.bottom, colour, flags);
82 using WindowList = std::list<Window *>;
84 extern Window *_focused_window;
203 enum TooltipCloseCondition {
236 inline void *
operator new[](
size_t size) =
delete;
267 WindowList::iterator z_position;
269 template <
class NWID>
270 inline const NWID *
GetWidget(uint widnum)
const;
271 template <
class NWID>
282 virtual const char *
GetCaret()
const;
324 if (this->nested_array[widget_index] !=
nullptr) this->GetWidget<NWidgetCore>(widget_index)->SetDisabled(disab_stat);
353 return this->GetWidget<NWidgetCore>(widget_index)->IsDisabled();
363 return this->nested_focus !=
nullptr && this->nested_focus->
index == widget_index;
385 this->GetWidget<NWidgetCore>(widget_index)->SetLowered(lowered_stat);
395 bool lowered_state = this->GetWidget<NWidgetCore>(widget_index)->IsLowered();
396 this->GetWidget<NWidgetCore>(widget_index)->SetLowered(!lowered_state);
425 return this->GetWidget<NWidgetCore>(widget_index)->IsLowered();
432 virtual void InsertTextString(
int wid,
const char *str,
bool marked,
const char *caret,
const char *insert_location,
const char *replacement_end);
435 int GetRowFromWidget(
int clickpos,
int widget,
int padding,
int line_height = -1)
const;
448 virtual void Close();
452 void ReInit(
int rx = 0,
int ry = 0);
577 virtual bool OnTooltip(
Point pt,
int widget, TooltipCloseCondition close_cond) {
return false; }
700 virtual bool OnVehicleSelect(VehicleList::const_iterator begin, VehicleList::const_iterator end) {
return false; }
757 template <
bool TtoBack>
762 typedef size_t difference_type;
763 typedef std::forward_iterator_tag iterator_category;
771 bool operator==(
const WindowIterator &other)
const {
return this->it == other.it; }
772 bool operator!=(
const WindowIterator &other)
const {
return !(*
this == other); }
773 Window * operator*()
const {
return *this->it; }
774 WindowIterator & operator++() { this->Next(); this->Validate();
return *
this; }
776 bool IsEnd()
const {
return this->it ==
_z_windows.end(); }
779 WindowList::iterator it;
782 while (!this->IsEnd() && *this->it ==
nullptr) this->Next();
786 if constexpr (!TtoBack) {
802 template <
bool Tfront>
807 if constexpr (Tfront) {
829 template <
class It,
class Pred>
832 return std::adjacent_find(begin, end, std::not_fn(pred)) == end;
841 template <
class NWID>
845 NWID *nwid =
dynamic_cast<NWID *
>(this->
nested_array[widnum]);
846 assert(nwid !=
nullptr);
852 inline const NWidgetBase *Window::GetWidget<NWidgetBase>(uint widnum)
const
864 template <
class NWID>
867 return const_cast<Window *
>(
this)->GetWidget<NWID>(widnum);
882 void Close()
override;
896 template <
typename Wcls>
900 if (w !=
nullptr)
return return_existing ? w :
nullptr;
901 return new Wcls(desc, window_number);
906 void GuiShowTooltips(
Window *parent,
StringID str, uint paramcount = 0,
const uint64 params[] =
nullptr, TooltipCloseCondition close_tooltip = TCC_HOVER);
911 extern Point _cursorpos_drag_start;
913 extern int _scrollbar_start_pos;
914 extern int _scrollbar_size;
915 extern byte _scroller_click_timeout;
Iterator to iterate all valid Windows.
Data structure for a window viewport.
void Close() override
Hide the window and all its child windows, and mark them for a later deletion.
void SetTimeout()
Set the timeout flag of the window and initiate the timer.
@ WC_INVALID
Invalid window.
uint8 timeout_timer
Timer value of the WF_TIMEOUT for flags.
virtual void OnHundredthTick()
Called once every 100 (game) ticks, or once every 3s, whichever comes last.
char32_t WChar
Type for wide characters, i.e.
@ WF_SIZING
Window is being resized.
virtual void OnEditboxChanged(int widget)
The text in an editbox has been edited.
void SetWhiteBorder()
Set the timeout flag of the window and initiate the timer.
SortButtonState
State of a sort direction button.
List of hotkeys for a window.
Dimensions (a width and height) of a rectangle in 2D.
virtual ~Window()
Remove window and all its child windows from the window stack.
Wcls * AllocateWindowDescFront(WindowDesc *desc, int window_number, bool return_existing=false)
Open a new window.
void DrawSortButtonState(int widget, SortButtonState state) const
Draw a sort button's up or down arrow symbol.
NWidgetBase * nested_root
Root of the nested tree.
const Scrollbar * GetScrollbar(uint widnum) const
Return the Scrollbar to a widget index.
@ WDF_CONSTRUCTION
This window is used for construction; close it whenever changing company.
bool _scrolling_viewport
A viewport is being scrolled with the mouse.
NWidgetStacked * shade_select
Selection widget (NWID_SELECTION) to use for shading the window. If nullptr, window cannot shade.
@ WF_SIZING_RIGHT
Window is being resized towards the right.
virtual void OnHover(Point pt, int widget)
The mouse is hovering over a widget in the window, perform an action for it.
virtual void ApplyDefaults()
Read default values from WindowDesc configuration an apply them to the window.
void ReInit(int rx=0, int ry=0)
Re-initialize a window, and optionally change its size.
virtual void DrawWidget(const Rect &r, int widget) const
Draw the contents of a nested widget.
ViewportDragDropSelectionProcess
Drag and drop selection process, or, what to do with an area of land when you've selected it.
void ScrollbarClickHandler(Window *w, NWidgetCore *nw, int x, int y)
Special handling for the scrollbar widget type.
void InitializePositionSize(int x, int y, int min_width, int min_height)
Set the position and smallest size of the window.
WindowList _z_windows
List of windows opened at the screen sorted from the front to back.
@ WF_DISABLE_VP_SCROLL
Window does not do autoscroll,.
ViewportData * viewport
Pointer to viewport data, if present.
int32 scrollpos_y
Currently shown y coordinate (virtual screen coordinate of topleft corner of the viewport).
FrameFlags
Flags to describe the look of the frame.
void CreateNestedTree(bool fill_nested=true)
Perform the first part of the initialization of a nested widget tree.
@ WDP_ALIGN_TOOLBAR
Align toward the toolbar.
virtual void OnGameTick()
Called once per (game) tick.
virtual bool IsNewGRFInspectable() const
Is the data related to this window NewGRF inspectable?
@ WF_STICKY
Window is made sticky by user.
@ WDF_NO_FOCUS
This window won't get focus/make any other window lose focus when click.
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
virtual void OnInvalidateData(int data=0, bool gui_scope=true)
Some data on this window has become invalid.
void RaiseButtons(bool autoraise=false)
Raise the buttons of the window.
StringAlignment
How to align the to-be drawn text.
void SetWidgetHighlight(byte widget_index, TextColour highlighted_colour)
Sets the highlighted status of a widget.
WindowClass cls
Class of the window,.
virtual void OnTimeout()
Called when this window's timeout has been reached.
Owner owner
The owner of the content shown in this window. Company colour is acquired from this variable.
virtual void OnDropdownClose(Point pt, int widget, int index, bool instant_close)
A dropdown window associated to this window has been closed.
int32 WindowNumber
Number to differentiate different windows of the same class.
@ FR_LOWERED
If set the frame is lowered and the background colour brighter (ie. buttons when pressed)
ViewportPlaceMethod
Viewport place method (type of highlighted area and placed objects)
void HandleButtonClick(byte widget)
Do all things to make a button look clicked and mark it to be unclicked in a few ticks.
virtual Point GetCaretPosition() const
Get the current caret position if an edit box has the focus.
Owner
Enum for all companies/owners.
@ FR_TRANSPARENT
Makes the background transparent if set.
virtual EventState OnHotkey(int hotkey)
A hotkey has been pressed.
Window(WindowDesc *desc)
Empty constructor, initialization has been moved to InitNested() called from the constructor of the d...
const NWidgetCore * nested_focus
Currently focused nested widget, or nullptr if no nested widget has focus.
Data stored about a string that can be modified in the GUI.
std::vector< int > scheduled_invalidation_data
Data of scheduled OnInvalidateData() calls.
bool IsWidgetHighlighted(byte widget_index) const
Gets the highlighted status of a widget.
virtual const char * GetCaret() const
Get the string at the caret if an edit box has the focus.
virtual EventState OnCTRLStateChange()
The state of the control key has changed.
virtual const char * GetTextCharacterAtPosition(const Point &pt) const
Get the character that is rendered at a position by the focused edit box.
SmallMap< int, QueryString * > querystrings
QueryString associated to WWT_EDITBOX widgets.
virtual void OnPlaceMouseUp(ViewportPlaceMethod select_method, ViewportDragDropSelectionProcess select_proc, Point pt, TileIndex start_tile, TileIndex end_tile)
The user has dragged over the map when the tile highlight mode has been set.
void ProcessScheduledInvalidations()
Process all scheduled invalidations.
int16 default_width_trad
Preferred initial width of the window (pixels at 1x zoom).
WindowPosition default_pos
Preferred position of the window.
High level window description.
void SetFocusedWindow(Window *w)
Set the window that has the focus.
virtual void SetStringParameters(int widget) const
Initialize string parameters for a widget.
@ WF_SIZING_LEFT
Window is being resized towards the left.
void SetShaded(bool make_shaded)
Set the shaded state of the window to make_shaded.
Padding dimensions to apply to each side of a Rect.
const NWID * GetWidget(uint widnum) const
Get the nested widget with number widnum from the nested widget tree.
void DrawCaption(const Rect &r, Colours colour, Owner owner, TextColour text_colour, StringID str, StringAlignment align)
Draw a caption bar.
virtual void OnFocusLost()
Called when window loses focus.
Data structure for viewport, display of a part of the world.
bool _mouse_hovering
The mouse is hovering over the same point.
void UnfocusFocusedWidget()
Makes no widget on this window have focus.
@ WDP_AUTO
Find a place automatically.
const char * ini_key
Key to store window defaults in openttd.cfg. nullptr if nothing shall be stored.
ResizeInfo resize
Resize information.
@ WSM_PRESIZE
Presizing mode (docks, tunnels).
virtual bool OnVehicleSelect(VehicleList::const_iterator begin, VehicleList::const_iterator end)
The user clicked on a vehicle while HT_VEHICLE has been set.
void EnableWidget(byte widget_index)
Sets a widget to Enabled.
void InitNested(WindowNumber number=0)
Perform complete initialization of the Window with nested widgets, to allow use.
void ProcessHighlightedInvalidations()
Process all invalidation of highlighted widgets.
int height
Height of the window (number of pixels down in y direction)
@ WF_CENTERED
Window is centered and shall stay centered after ReInit.
@ WF_WHITE_BORDER
Window white border counter bit mask.
SpecialMouseMode
Mouse modes.
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
Point GetToolbarAlignedWindowPosition(int window_width)
Computer the position of the top-left corner of a window to be opened right under the toolbar.
virtual void OnFocus()
Called when window gains focus.
Base class that provides memory initialization on dynamically created objects.
@ ES_NOT_HANDLED
The passed event is not handled.
virtual bool OnVehicleSelect(const struct Vehicle *v)
The user clicked on a vehicle while HT_VEHICLE has been set.
EventState HandleEditBoxKey(int wid, WChar key, uint16 keycode)
Process keypress for editbox widget.
void DisableAllWidgetHighlight()
Disable the highlighted status of all widgets.
virtual void OnPlaceObject(Point pt, TileIndex tile)
The user clicked some place on the map when a tile highlight mode has been set.
virtual void OnDropdownSelect(int widget, int index)
A dropdown option associated to this window has been selected.
const QueryString * GetQueryString(uint widnum) const
Return the querystring associated to a editbox.
int16 GetDefaultWidth() const
Determine default width of window.
void SetWidgetDisabledState(byte widget_index, bool disab_stat)
Sets the enabled/disabled status of a widget.
static void DeleteClosedWindows()
Delete all closed windows.
Window * parent
Parent window.
bool IsWidgetGloballyFocused(byte widget_index) const
Check if given widget has user input focus.
int left
x position of left edge of the window
virtual void OnDragDrop(Point pt, int widget)
A dragged 'object' has been released.
WindowFlags flags
Window flags.
void DrawFrameRect(int left, int top, int right, int bottom, Colours colour, FrameFlags flags)
Draw frame rectangle.
@ WF_TIMEOUT
Window timeout counter.
WindowClass
Window classes.
virtual void ShowNewGRFInspectWindow() const
Show the NewGRF inspection window.
int16 default_height_trad
Preferred initial height of the window (pixels at 1x zoom).
int GetWidgetFromPos(const Window *w, int x, int y)
Returns the index for the widget located at the given position relative to the window.
@ WDF_MODAL
The window is a modal child of some other window, meaning the parent is 'inactive'.
int16 GetDefaultHeight() const
Determine default height of window.
static const int TIMEOUT_DURATION
The initial timeout value for WF_TIMEOUT.
Coordinates of a point in 2D.
@ WF_HIGHLIGHTED
Window has a widget that has a highlight.
const NWidgetPart * nwid_parts
Nested widget parts describing the window.
WindowDefaultFlag
Window default widget/window handling flags.
int32 dest_scrollpos_y
Current destination y coordinate to display (virtual screen coordinate of topleft corner of the viewp...
bool IsWidgetFocused(byte widget_index) const
Check if given widget is focused within this window.
@ WSM_DRAGDROP
Drag&drop an object.
virtual void OnInit()
Notification that the nested widget tree gets initialized.
Dimension unshaded_size
Last known unshaded size (only valid while shaded).
static void SaveToConfig()
Save all WindowDesc settings to _windows_file.
bool SetFocusedWidget(int widget_index)
Set focus within this window to the given widget.
WindowNumber window_number
Window number within the window class.
uint step_height
Step-size of height resize changes.
WindowDesc(WindowPosition default_pos, const char *ini_key, int16 def_width_trad, int16 def_height_trad, WindowClass window_class, WindowClass parent_class, uint32 flags, const NWidgetPart *nwid_parts, int16 nwid_length, HotkeyList *hotkeys=nullptr)
Window description constructor.
void InvalidateData(int data=0, bool gui_scope=true)
Mark this window's data as invalid (in need of re-computing)
int mouse_capture_widget
Widgetindex of current mouse capture widget (e.g. dragged scrollbar). -1 if no widget has mouse captu...
Iterable ensemble of all valid Windows.
NWidgetBase ** nested_array
Array of pointers into the tree. Do not access directly, use Window::GetWidget() instead.
virtual void OnPlacePresize(Point pt, TileIndex tile)
The user moves over the map when a tile highlight mode has been set when the special mouse mode has b...
uint32 StringID
Numeric value that represents a string, independent of the selected language.
virtual void OnClick(Point pt, int widget, int click_count)
A click with the left mouse button has been made on the window.
@ SBS_DOWN
Sort ascending.
int32 scrollpos_x
Currently shown x coordinate (virtual screen coordinate of topleft corner of the viewport).
virtual void OnMouseLoop()
Called for every mouse loop run, which is at least once per (game) tick.
int16 nwid_length
Length of the nwid_parts array.
uint step_width
Step-size of width resize changes.
virtual void OnMouseWheel(int wheel)
The mouse wheel has been turned.
bool IsShaded() const
Is window shaded currently?
virtual void OnPlaceObjectAbort()
The user cancelled a tile highlight mode that has been set.
Data structure for resizing a window.
void GuiShowTooltips(Window *parent, StringID str, uint paramcount=0, const uint64 params[]=nullptr, TooltipCloseCondition close_tooltip=TCC_HOVER)
Shows a tooltip.
static std::vector< Window * > closed_windows
List of closed windows to delete.
void CloseChildWindows(WindowClass wc=WC_INVALID) const
Close all children a window might have in a head-recursive manner.
void CDECL SetWidgetsLoweredState(bool lowered_stat, int widgets,...)
Sets the lowered/raised status of a list of widgets.
virtual bool OnTooltip(Point pt, int widget, TooltipCloseCondition close_cond)
Event to display a custom tooltip.
virtual Rect GetTextBoundingRect(const char *from, const char *to) const
Get the bounding rectangle for a text range if an edit box has the focus.
virtual void OnPaint()
The window must be repainted.
void CDECL SetWidgetsDisabledState(bool disab_stat, int widgets,...)
Sets the enabled/disabled status of a list of widgets.
bool IsWidgetLowered(byte widget_index) const
Gets the lowered state of a widget.
virtual void OnMouseOver(Point pt, int widget)
The mouse is currently moving over the window or has just moved outside of the window.
EventState
State of handling an event.
bool pref_sticky
Preferred stickyness.
@ WF_DRAGGING
Window is being dragged.
virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
Update size and resize step of a widget in the window.
@ WSM_DRAGGING
Dragging mode (trees).
WindowClass window_class
Window class.
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
Base class for windows opened from a toolbar.
SpecialMouseMode _special_mouse_mode
Mode of the mouse.
void UpdateQueryStringSize()
Update size of all QueryStrings of this window.
int top
y position of top edge of the window
void DrawViewport() const
Draw the viewport of this window.
DECLARE_ENUM_AS_BIT_SET(GenderEthnicity) enum CompanyManagerFaceVariable
Bitgroups of the CompanyManagerFace variable.
uint32 VehicleID
The type all our vehicle IDs have.
static const int WHITE_BORDER_DURATION
The initial timeout value for WF_WHITE_BORDER.
virtual void OnMouseDrag(Point pt, int widget)
An 'object' is being dragged at the provided position, highlight the target if possible.
VehicleID follow_vehicle
VehicleID to follow if following a vehicle, INVALID_VEHICLE otherwise.
virtual Point OnInitialPosition(int16 sm_width, int16 sm_height, int window_number)
Compute the initial position of the window.
void ToggleWidgetLoweredState(byte widget_index)
Invert the lowered/raised status of a widget.
int width
width of the window (number of pixels to the right in x direction)
static void LoadFromConfig()
Load all WindowDesc settings from _windows_file.
void RelocateAllWindows(int neww, int newh)
Relocate all windows to fit the new size of the game application screen.
int32 dest_scrollpos_x
Current destination x coordinate to display (virtual screen coordinate of topleft corner of the viewp...
@ WDP_MANUAL
Manually align the window (so no automatic location finding)
static int SortButtonWidth()
Get width of up/down arrow of sort button state.
@ FR_DARKENED
If set the background is darker, allows for lowered frames with normal background colour when used wi...
virtual void InsertTextString(int wid, const char *str, bool marked, const char *caret, const char *insert_location, const char *replacement_end)
Insert a text string at the cursor position into the edit box widget.
WindowDesc * window_desc
Window description.
virtual void OnPlaceDrag(ViewportPlaceMethod select_method, ViewportDragDropSelectionProcess select_proc, Point pt)
The user is dragging over the map when the tile highlight mode has been set.
virtual void OnRealtimeTick(uint delta_ms)
Called periodically.
WindowClass parent_cls
Class of the parent window.
Data structure for an opened window.
void RaiseWidget(byte widget_index)
Marks a widget as raised.
void DrawWidgets() const
Paint all widgets of a window.
Window * FindWindowFromPt(int x, int y)
Do a search for a window at specific coordinates.
virtual bool OnRightClick(Point pt, int widget)
A click with the right mouse button has been made on the window.
bool AllEqual(It begin, It end, Pred pred)
Generic helper function that checks if all elements of the range are equal with respect to the given ...
virtual void OnQueryTextFinished(char *str)
The query window opened from this window has closed.
virtual void OnScroll(Point delta)
Handle the request for (viewport) scrolling.
@ SBS_OFF
Do not sort (with this button).
uint nested_array_size
Size of the nested array.
bool IsWidgetDisabled(byte widget_index) const
Gets the enabled/disabled status of a widget.
void SetWidgetDirty(byte widget_index) const
Invalidate a widget, i.e.
Specification of a rectangle with absolute coordinates of all edges.
void LowerWidget(byte widget_index)
Marks a widget as lowered.
virtual const char * GetMarkedText(size_t *length) const
Get the range of the currently marked input text.
int GetRowFromWidget(int clickpos, int widget, int padding, int line_height=-1) const
Compute the row of a widget that a user clicked in.
virtual void OnResize()
Called after the window got resized.
void DisableWidget(byte widget_index)
Sets a widget to disabled.
HotkeyList * hotkeys
Hotkeys for the window.
WindowPosition
How do we the window to be placed?
@ WDP_CENTER
Center the window.
void SetWidgetLoweredState(byte widget_index, bool lowered_stat)
Sets the lowered/raised status of a widget.
int16 pref_height
User-preferred height of the window. Zero if unset.
uint8 white_border_timer
Timer value of the WF_WHITE_BORDER for flags.
@ WSM_NONE
No special mouse mode.
int16 pref_width
User-preferred width of the window. Zero if unset.
void InitializeData(WindowNumber window_number)
Initializes the data (except the position and initial size) of a new Window.
@ FR_BORDERONLY
Draw border only, no background.
virtual const char * GetFocusedText() const
Get the current input text if an edit box has the focus.
virtual void FindWindowPlacementAndResize(int def_width, int def_height)
Resize window towards the default size.
virtual EventState OnKeyPress(WChar key, uint16 keycode)
A key has been pressed.
virtual void Close()
Hide the window and all its child windows, and mark them for a later deletion.
Window * BringWindowToFrontById(WindowClass cls, WindowNumber number)
Find a window and make it the relative top-window on the screen.