150 extern Window *_focused_window;
274 void InitializePositionSize(
int x,
int y,
int min_width,
int min_height);
275 virtual void FindWindowPlacementAndResize(
int def_width,
int def_height);
290 inline void *
operator new[](
size_t size)
300 inline void operator delete(
void *ptr)
336 template <
class NWID>
337 inline const NWID *GetWidget(uint widnum)
const;
338 template <
class NWID>
339 inline NWID *GetWidget(uint widnum);
341 const Scrollbar *GetScrollbar(uint widnum)
const;
344 const QueryString *GetQueryString(uint widnum)
const;
347 virtual const char *GetFocusedText()
const;
348 virtual const char *GetCaret()
const;
349 virtual const char *GetMarkedText(
size_t *length)
const;
350 virtual Point GetCaretPosition()
const;
351 virtual Rect GetTextBoundingRect(
const char *from,
const char *to)
const;
352 virtual const char *GetTextCharacterAtPosition(
const Point &pt)
const;
355 void CreateNestedTree(
bool fill_nested =
true);
376 void DisableAllWidgetHighlight();
377 void SetWidgetHighlight(byte widget_index,
TextColour highlighted_colour);
378 bool IsWidgetHighlighted(byte widget_index)
const;
389 assert(widget_index < this->nested_array_size);
390 if (this->nested_array[widget_index] != NULL) this->GetWidget<NWidgetCore>(widget_index)->SetDisabled(disab_stat);
399 SetWidgetDisabledState(widget_index,
true);
408 SetWidgetDisabledState(widget_index,
false);
418 assert(widget_index < this->nested_array_size);
419 return this->GetWidget<NWidgetCore>(widget_index)->IsDisabled();
429 return this->nested_focus != NULL && this->nested_focus->
index == widget_index;
440 return _focused_window ==
this && IsWidgetFocused(widget_index);
450 assert(widget_index < this->nested_array_size);
451 this->GetWidget<NWidgetCore>(widget_index)->SetLowered(lowered_stat);
460 assert(widget_index < this->nested_array_size);
461 bool lowered_state = this->GetWidget<NWidgetCore>(widget_index)->IsLowered();
462 this->GetWidget<NWidgetCore>(widget_index)->SetLowered(!lowered_state);
471 SetWidgetLoweredState(widget_index,
true);
480 SetWidgetLoweredState(widget_index,
false);
490 assert(widget_index < this->nested_array_size);
491 return this->GetWidget<NWidgetCore>(widget_index)->IsLowered();
494 void UnfocusFocusedWidget();
495 bool SetFocusedWidget(
int widget_index);
498 virtual void InsertTextString(
int wid,
const char *str,
bool marked,
const char *caret,
const char *insert_location,
const char *replacement_end);
500 void HandleButtonClick(byte widget);
501 int GetRowFromWidget(
int clickpos,
int widget,
int padding,
int line_height = -1)
const;
503 void RaiseButtons(
bool autoraise =
false);
504 void CDECL SetWidgetsDisabledState(
bool disab_stat,
int widgets, ...);
505 void CDECL SetWidgetsLoweredState(
bool lowered_stat,
int widgets, ...);
506 void SetWidgetDirty(byte widget_index)
const;
508 void DrawWidgets()
const;
509 void DrawViewport()
const;
511 static int SortButtonWidth();
515 void SetDirty()
const;
516 void ReInit(
int rx = 0,
int ry = 0);
524 void SetShaded(
bool make_shaded);
526 void InvalidateData(
int data = 0,
bool gui_scope =
true);
527 void ProcessScheduledInvalidations();
528 void ProcessHighlightedInvalidations();
538 virtual void ApplyDefaults();
547 virtual Point OnInitialPosition(int16 sm_width, int16 sm_height,
int window_number);
593 virtual void OnFocusLost();
707 virtual void OnDropdownClose(
Point pt,
int widget,
int index,
bool instant_close);
803 template <
class NWID>
806 if (widnum >= this->nested_array_size || this->nested_array[widnum] == NULL)
return NULL;
807 NWID *nwid =
dynamic_cast<NWID *
>(this->nested_array[widnum]);
808 assert(nwid != NULL);
814 inline const NWidgetBase *Window::GetWidget<NWidgetBase>(uint widnum)
const 816 if (widnum >= this->nested_array_size)
return NULL;
817 return this->nested_array[widnum];
826 template <
class NWID>
829 return const_cast<Window *
>(
this)->GetWidget<NWID>(widnum);
841 this->parent = parent;
858 template <
typename Wcls>
862 if (w != NULL)
return return_existing ? w : NULL;
863 return new Wcls(desc, window_number);
869 enum TooltipCloseCondition {
875 void GuiShowTooltips(
Window *parent,
StringID str, uint paramcount = 0,
const uint64 params[] = NULL, TooltipCloseCondition close_tooltip = TCC_HOVER);
881 #define FOR_ALL_WINDOWS_FROM_BACK_FROM(w, start) for (w = start; w != NULL; w = w->z_front) if (w->window_class != WC_INVALID) 882 #define FOR_ALL_WINDOWS_FROM_FRONT_FROM(w, start) for (w = start; w != NULL; w = w->z_back) if (w->window_class != WC_INVALID) 883 #define FOR_ALL_WINDOWS_FROM_BACK(w) FOR_ALL_WINDOWS_FROM_BACK_FROM(w, _z_back_window) 884 #define FOR_ALL_WINDOWS_FROM_FRONT(w) FOR_ALL_WINDOWS_FROM_FRONT_FROM(w, _z_front_window) 886 extern Point _cursorpos_drag_start;
888 extern int _scrollbar_start_pos;
889 extern int _scrollbar_size;
890 extern byte _scroller_click_timeout;
EventState
State of handling an event.
ViewportDragDropSelectionProcess
Drag and drop selection process, or, what to do with an area of land when you've selected it...
virtual void OnQueryTextFinished(char *str)
The query window opened from this window has closed.
SpecialMouseMode
Mouse modes.
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...
Left offset of sticky sprite.
Window * _z_front_window
List of windows opened at the screen sorted from the front.
DECLARE_ENUM_AS_BIT_SET(GenderEthnicity) enum CompanyManagerFaceVariable
Bitgroups of the CompanyManagerFace variable.
virtual void OnScroll(Point delta)
Handle the request for (viewport) scrolling.
ResizeInfo resize
Resize information.
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=NULL)
Window description constructor.
void SetWidgetDisabledState(byte widget_index, bool disab_stat)
Sets the enabled/disabled status of a widget.
Offset at right of a matrix cell.
const NWidgetCore * nested_focus
Currently focused nested widget, or NULL if no nested widget has focus.
void SetWidgetLoweredState(byte widget_index, bool lowered_stat)
Sets the lowered/raised status of a widget.
void SetTimeout()
Set the timeout flag of the window and initiate the timer.
Right offset of closebox string.
Window * parent
Parent window.
High level window description.
void DrawFrameRect(int left, int top, int right, int bottom, Colours colour, FrameFlags flags)
Draw frame rectangle.
virtual void OnDragDrop(Point pt, int widget)
A dragged 'object' has been released.
Window is being resized towards the right.
Simple vector class that allows allocating an item without the need to copy this->data needlessly...
WindowFlags flags
Window flags.
int left
x position of left edge of the window
Width of left bevel border.
Left offset of scrollbar.
Right offset of debug sprite.
bool _scrolling_viewport
A viewport is being scrolled with the mouse.
int16 pref_height
User-preferred height of the window. Zero if unset.
Height of a drop down widget.
Offset at top to draw the frame rectangular area.
Normal amount of vertical space between two paragraphs of text.
The passed event is not handled.
Dimension unshaded_size
Last known unshaded size (only valid while shaded).
Bottom offset of shade sprite.
void ScrollbarClickHandler(Window *w, NWidgetCore *nw, int x, int y)
Special handling for the scrollbar widget type.
Left offset of shade sprite.
Implementation of simple mapping class.
If set the background is darker, allows for lowered frames with normal background colour when used wi...
SpecialMouseMode _special_mouse_mode
Mode of the mouse.
int top
y position of top edge of the window
virtual void OnTick()
Called once per (game) tick.
void ToggleWidgetLoweredState(byte widget_index)
Invert the lowered/raised status of a widget.
virtual void OnEditboxChanged(int widget)
The text in an editbox has been edited.
Width of right bevel border.
Offset at top of a matrix cell.
NWidgetStacked * shade_select
Selection widget (NWID_SELECTION) to use for shading the window. If NULL, window cannot shade...
Width of a standard defsize box widget.
virtual void OnMouseLoop()
Called for every mouse loop run, which is at least once per (game) tick.
Bottom offset of defsize sprite.
WindowClass
Window classes.
void DisableWidget(byte widget_index)
Sets a widget to disabled.
int16 default_width_trad
Preferred initial width of the window (pixels at 1x zoom).
static const int TIMEOUT_DURATION
The initial timeout value for WF_TIMEOUT.
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.
Top offset of debug sprite.
virtual void OnPlaceObjectAbort()
The user cancelled a tile highlight mode that has been set.
Left offset of debug sprite.
void RaiseWidget(byte widget_index)
Marks a widget as raised.
WindowClass cls
Class of the window,.
Window is made sticky by user.
Presizing mode (docks, tunnels).
virtual void OnTimeout()
Called when this window's timeout has been reached.
Window is being resized towards the left.
Large amount of vertical space between two paragraphs of text.
virtual bool OnVehicleSelect(const struct Vehicle *v)
The user clicked on a vehicle while HT_VEHICLE has been set.
virtual bool IsNewGRFInspectable() const
Is the data related to this window NewGRF inspectable?
FrameFlags
Flags to describe the look of the frame.
Width of a close box widget.
Simple mapping class targeted for small sets of data.
static const int WHITE_BORDER_DURATION
The initial timeout value for WF_WHITE_BORDER.
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.
Types related to viewports.
const char * ini_key
Key to store window defaults in openttd.cfg. NULL if nothing shall be stored.
Data structure for an opened window.
Bottom offset of image in the button.
WidgetDrawDistances
Distances used in drawing widgets.
Bottom offset of the text of the frame.
void SetFocusedWindow(Window *w)
Set the window that has the focus.
int16 GetDefaultHeight() const
Determine default height of window.
int16 default_height_trad
Preferred initial height of the window (pixels at 1x zoom).
NWidgetBase ** nested_array
Array of pointers into the tree. Do not access directly, use Window::GetWidget() instead.
Data structure for resizing a window.
Right offset of resize sprite.
Point GetToolbarAlignedWindowPosition(int window_width)
Computer the position of the top-left corner of a window to be opened right under the toolbar...
Width of a standard shade box widget.
Offset at bottom of a matrix cell.
Right offset of defsize sprite.
virtual EventState OnKeyPress(WChar key, uint16 keycode)
A key has been pressed.
virtual void OnInit()
Notification that the nested widget tree gets initialized.
This window is used for construction; close it whenever changing company.
bool IsWidgetLowered(byte widget_index) const
Gets the lowered state of a widget.
int16 GetDefaultWidth() const
Determine default width of window.
Window * _z_back_window
List of windows opened at the screen sorted from the back.
virtual void OnFocus()
Called when window gains focus.
uint32 VehicleID
The type all our vehicle IDs have.
ViewportPlaceMethod
Viewport place method (type of highlighted area and placed objects)
SmallMap< int, QueryString * > querystrings
QueryString associated to WWT_EDITBOX widgets.
virtual void DrawWidget(const Rect &r, int widget) const
Draw the contents of a nested widget.
Data stored about a string that can be modified in the GUI.
Bottom offset of resize sprite.
SmallVector< int, 4 > scheduled_invalidation_data
Data of scheduled OnInvalidateData() calls.
WindowPosition default_pos
Preferred position of the window.
Window is centered and shall stay centered after ReInit.
Height of bottom bevel border.
void SetWhiteBorder()
Set the timeout flag of the window and initiate the timer.
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
List of hotkeys for a window.
void DrawCaption(const Rect &r, Colours colour, Owner owner, StringID str)
Draw a caption bar.
Wcls * AllocateWindowDescFront(WindowDesc *desc, int window_number, bool return_existing=false)
Open a new window.
int GetWidgetFromPos(const Window *w, int x, int y)
Returns the index for the widget located at the given position relative to the window.
Left offset of defsize sprite.
static void SaveToConfig()
Save all WindowDesc settings to _windows_file.
bool IsWidgetDisabled(byte widget_index) const
Gets the enabled/disabled status of a widget.
Offset at bottom to draw below the text.
uint nested_array_size
Size of the nested array.
const NWidgetPart * nwid_parts
Nested widget parts describing the window.
WindowDefaultFlag
Window default widget/window handling flags.
virtual void OnHover(Point pt, int widget)
The mouse is hovering over a widget in the window, perform an action for it, like opening a custom to...
Data structure for a window viewport.
int16 nwid_length
Length of the nwid_parts array.
int32 scrollpos_x
Currently shown x coordinate (virtual screen coordinate of topleft corner of the viewport).
uint step_height
Step-size of height resize changes.
void LowerWidget(byte widget_index)
Marks a widget as lowered.
Offset at left of a matrix cell.
virtual void OnMouseOver(Point pt, int widget)
The mouse is currently moving over the window or has just moved outside of the window.
Top offset of resize sprite.
void GuiShowTooltips(Window *parent, StringID str, uint paramcount=0, const uint64 params[]=NULL, TooltipCloseCondition close_tooltip=TCC_HOVER)
Shows a tooltip.
virtual void OnDropdownSelect(int widget, int index)
A dropdown option associated to this window has been selected.
SortButtonState
State of a sort direction button.
Right offset of sticky sprite.
Offset at bottom to draw the frame rectangular area.
uint8 white_border_timer
Timer value of the WF_WHITE_BORDER for flags.
Offset of the caption text at the left.
Right offset of the text of the frame.
VehicleID follow_vehicle
VehicleID to follow if following a vehicle, INVALID_VEHICLE otherwise.
Right offset of the image in the button.
Top offset of the text of the frame.
Left offset of the text of the frame.
Top offset of defsize sprite.
Window has a widget that has a highlight.
Base class that provides memory initialization on dynamically created objects.
bool pref_sticky
Preferred stickyness.
uint32 StringID
Numeric value that represents a string, independent of the selected language.
Window * FindWindowFromPt(int x, int y)
Do a search for a window at specific coordinates.
Left offset of resize sprite.
Bottom offset of closebox string.
int32 dest_scrollpos_y
Current destination y coordinate to display (virtual screen coordinate of topleft corner of the viewp...
Draw border only, no background.
Offset at top to draw above the text.
The window is a modal child of some other window, meaning the parent is 'inactive'.
bool IsWidgetGloballyFocused(byte widget_index) const
Check if given widget has user input focus.
Offset of the caption text at the top.
Window * z_back
The window behind us in z-order.
int scrolling_scrollbar
Widgetindex of just being dragged scrollbar. -1 if none is active.
Width of a standard debug box widget.
void RelocateAllWindows(int neww, int newh)
Relocate all windows to fit the new size of the game application screen.
virtual bool OnRightClick(Point pt, int widget)
A click with the right mouse button has been made on the window.
Top offset of shade sprite.
Width of a standard sticky box widget.
Bottom offset of scrollbar.
virtual void OnPaint()
The window must be repainted.
int32 dest_scrollpos_x
Current destination x coordinate to display (virtual screen coordinate of topleft corner of the viewp...
Height of top bevel border.
Align toward the toolbar.
Data structure for viewport, display of a part of the world.
If set the frame is lowered and the background colour brighter (ie. buttons when pressed) ...
Bottom offset of sticky sprite.
Offset of the caption text at the bottom.
Bottom offset of debug sprite.
uint32 TileIndex
The index/ID of a Tile.
Window * z_front
The window in front of us in z-order.
WindowClass parent_cls
Class of the parent window.
virtual EventState OnCTRLStateChange()
The state of the control key has changed.
virtual void ShowNewGRFInspectWindow() const
Show the NewGRF inspection window.
virtual void SetStringParameters(int widget) const
Initialize string parameters for a widget.
This window won't get focus/make any other window lose focus when click.
static void LoadFromConfig()
Load all WindowDesc settings from _windows_file.
Top offset of image in the button.
Types related to vehicles.
Top offset of sticky sprite.
uint step_width
Step-size of width resize changes.
HotkeyList * hotkeys
Hotkeys for the window.
Bottom offset of the dropdown widget string.
Right offset of scrollbar.
Coordinates of a point in 2D.
int16 pref_width
User-preferred width of the window. Zero if unset.
Types related to companies.
Window does not do autoscroll,.
Owner owner
The owner of the content shown in this window. Company colour is acquired from this variable...
virtual void OnMouseDrag(Point pt, int widget)
An 'object' is being dragged at the provided position, highlight the target if possible.
Right offset of shade sprite.
Width of a resize box widget.
Offset at right to draw the frame rectangular area.
virtual void OnClick(Point pt, int widget, int click_count)
A click with the left mouse button has been made on the window.
int width
width of the window (number of pixels to the right in x direction)
virtual void OnResize()
Called after the window got resized.
int32 WindowNumber
Number to differentiate different windows of the same class.
WindowClass window_class
Window class.
virtual void OnMouseWheel(int wheel)
The mouse wheel has been turned.
Specification of a rectangle with absolute coordinates of all edges.
virtual void OnPlaceObject(Point pt, TileIndex tile)
The user clicked some place on the map when a tile highlight mode has been set.
bool IsShaded() const
Is window shaded currently?
WindowNumber window_number
Window number within the window class.
Left offset of the dropdown widget string.
Owner
Enum for all companies/owners.
Find a place automatically.
Manually align the window (so no automatic location finding)
virtual void OnHundredthTick()
Called once every 100 (game) ticks.
Makes the background transparent if set.
ViewportData * viewport
Pointer to viewport data, if present.
uint8 timeout_timer
Timer value of the WF_TIMEOUT for flags.
uint32 WChar
Type for wide characters, i.e.
bool IsWidgetFocused(byte widget_index) const
Check if given widget is focused within this window.
const NWID * GetWidget(uint widnum) const
Get the nested widget with number widnum from the nested widget tree.
Do not sort (with this button).
bool _mouse_hovering
The mouse is hovering over the same point.
Window white border counter bit mask.
Left offset of the image in the button.
int32 scrollpos_y
Currently shown y coordinate (virtual screen coordinate of topleft corner of the viewport).
Left offset of closebox string.
WindowPosition
How do we the window to be placed?
NWidgetBase * nested_root
Root of the nested tree.
Dimensions (a width and height) of a rectangle in 2D.
Offset at left to draw the frame rectangular area.
WindowDesc * window_desc
Window description.
Base class for windows opened from a toolbar.
Right offset of the dropdown widget string.
Top offset of the dropdown widget string.
Offset of the caption text at the right.
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.
Window * BringWindowToFrontById(WindowClass cls, WindowNumber number)
Find a window and make it the relative top-window on the screen.
Top offset of closebox string.
int height
Height of the window (number of pixels down in y direction)
void EnableWidget(byte widget_index)
Sets a widget to Enabled.
virtual void OnInvalidateData(int data=0, bool gui_scope=true)
Some data on this window has become invalid.