# window_gui.h File Reference

Functions, definitions and such used only by the GUI. More...

`#include "core/geometry_type.hpp"`
`#include "vehicle_type.h"`
`#include "viewport_type.h"`
`#include "company_type.h"`
`#include "core/alloc_type.hpp"`
`#include "window_type.h"`
`#include "tile_type.h"`
`#include "widget_type.h"`

Go to the source code of this file.

## Data Structures
struct | WindowDesc
| High level window description. More...
struct | Scrollbar
| Scrollbar data structure. More...
struct | ResizeInfo
| Data structure for resizing a window. More...
struct | ViewportData
| Data structure for a window viewport. More...
struct | Window
| Data structure for an opened window. More...
class | PickerWindowBase
| Data structure for a window opened from a toolbar. More...
## Defines
#define | FOR_ALL_WINDOWS_FROM_BACK_FROM(w, start) for (w = start; w != NULL; w = w->z_front) if (w->window_class != WC_INVALID)
| Iterate over all windows.
#define | FOR_ALL_WINDOWS_FROM_FRONT_FROM(w, start) for (w = start; w != NULL; w = w->z_back) if (w->window_class != WC_INVALID)
#define | FOR_ALL_WINDOWS_FROM_BACK(w) FOR_ALL_WINDOWS_FROM_BACK_FROM(w, _z_back_window)
#define | FOR_ALL_WINDOWS_FROM_FRONT(w) FOR_ALL_WINDOWS_FROM_FRONT_FROM(w, _z_front_window)
## Enumerations
enum | FrameFlags { FR_NONE = 0, FR_TRANSPARENT = 1 << 0, FR_BORDERONLY = 1 << 4, FR_LOWERED = 1 << 5, FR_DARKENED = 1 << 6 }
| Flags to describe the look of the frame. More...
enum | WindowDefaultFlag { WDF_STD_TOOLTIPS = 1 << 0, WDF_DEF_WIDGET = 1 << 1, WDF_STD_BTN = 1 << 2, WDF_CONSTRUCTION = 1 << 3, WDF_UNCLICK_BUTTONS = 1 << 4, WDF_STICKY_BUTTON = 1 << 5, WDF_RESIZABLE = 1 << 6, WDF_MODAL = 1 << 7, WDF_NO_FOCUS = 1 << 8 }
| Window default widget/window handling flags. More...
enum | WindowDefaultPosition { WDP_AUTO = -1, WDP_CENTER = -2, WDP_ALIGN_TBR = -3, WDP_ALIGN_TBL = -4 }
| Special values for 'left' and 'top' to cause a specific placement. More...
enum | SortButtonState { SBS_OFF, SBS_DOWN, SBS_UP }
enum | WindowFlags { WF_TIMEOUT_TRIGGER = 1, WF_TIMEOUT_BEGIN = 7, WF_TIMEOUT_MASK = 7, WF_DRAGGING = 1 << 3, WF_SCROLL_UP = 1 << 4, WF_SCROLL_DOWN = 1 << 5, WF_SCROLL_MIDDLE = 1 << 6, WF_HSCROLL = 1 << 7, WF_SIZING = 1 << 8, WF_STICKY = 1 << 9, WF_DISABLE_VP_SCROLL = 1 << 10, WF_WHITE_BORDER_ONE = 1 << 11, WF_WHITE_BORDER_MASK = 1 << 12 | WF_WHITE_BORDER_ONE, WF_SCROLL2 = 1 << 13 }
| Window flags. More...
enum | SpecialMouseMode { WSM_NONE = 0, WSM_DRAGDROP = 1, WSM_SIZING = 2, WSM_PRESIZE = 3 }
## Functions
| DECLARE_ENUM_AS_BIT_SET (FrameFlags)
void | DrawFrameRect (int left, int top, int right, int bottom, Colours colour, FrameFlags flags)
| Draw frame rectangle.
Window * | BringWindowToFrontById (WindowClass cls, WindowNumber number)
| Find a window and make it the top-window on the screen.
Window * | FindWindowFromPt (int x, int y)
| Do a search for a window at specific coordinates.
template<typename Wcls>
Wcls * | AllocateWindowDescFront (const WindowDesc *desc, int window_number)
| Open a new window.
void | RelocateAllWindows (int neww, int newh)
| Relocate all windows to fit the new size of the game application screen.
void | GuiShowTooltips (StringID str, uint paramcount=0, const uint64 params[]=NULL, bool use_left_mouse_button=false)
| Shows a tooltip.
int | GetWidgetFromPos (const Window *w, int x, int y)
| Returns the index for the widget located at the given position relative to the window.
Window * | GetCallbackWnd ()
void | SetFocusedWindow (Window *w)
| Set the window that has the focus.
const Widget * | GetGloballyFocusedWidget ()
| Gets the globally focused widget.
bool | EditBoxInGlobalFocus ()
| Check if an edit box is in global focus.
void | ScrollbarClickHandler (Window *w, const Widget *wi, int x, int y)
| Special handling for the scrollbar widget type.
void | ResizeButtons (Window *w, byte left, byte right)
| Evenly distribute some widgets when resizing horizontally (often a button row) When only two arguments are given, the widgets are presumed to be on a line and only the ends are given.
void | ResizeWindowForWidget (Window *w, uint widget, int delta_x, int delta_y)
| Resize a widget and shuffle other widgets around to fit.
void | SetVScrollCount (Window *w, int num)
| Set the number of items of the vertical scrollbar.
void | SetVScroll2Count (Window *w, int num)
| Set the number of items of the second vertical scrollbar.
void | SetHScrollCount (Window *w, int num)
| Set the number of items of the horizontal scrollbar.
## Variables
Window * | _z_front_window
| List of windows opened at the screen sorted from the front.
Window * | _z_back_window
| List of windows opened at the screen sorted from the back.
Window * | _focused_window
Point | _cursorpos_drag_start
int | _scrollbar_start_pos
int | _scrollbar_size
byte | _scroller_click_timeout
bool | _scrolling_scrollbar
bool | _scrolling_viewport
byte | _special_mouse_mode

## Detailed Description

Functions, definitions and such used only by the GUI.

Definition in file window_gui.h.

## Enumeration Type Documentation

enum FrameFlags

Flags to describe the look of the frame.

Enumerator:

  FR_TRANSPARENT | Makes the background transparent if set.
  FR_BORDERONLY | Draw border only, no background.
  FR_LOWERED | If set the frame is lowered and the background colour brighter (ie. buttons when pressed).
  FR_DARKENED | If set the background is darker, allows for lowered frames with normal background colour when used with FR_LOWERED (ie. dropdown boxes).

Definition at line 20 of file window_gui.h.

enum WindowDefaultFlag

Window default widget/window handling flags.

Enumerator:

  WDF_STD_TOOLTIPS | use standard routine when displaying tooltips
  WDF_DEF_WIDGET | Default widget control for some widgets in the on click event,. See also: DispatchLeftClickEvent()
  WDF_STD_BTN | Default handling for close and titlebar widgets (widget no 0 and 1).
  WDF_CONSTRUCTION | This window is used for construction; close it whenever changing company.
  WDF_UNCLICK_BUTTONS | Unclick buttons when the window event times out.
  WDF_STICKY_BUTTON | Set window to sticky mode; they are not closed unless closed with 'X' (widget 2).
  WDF_RESIZABLE | Window can be resized.
  WDF_MODAL | The window is a modal child of some other window, meaning the parent is 'inactive'.
  WDF_NO_FOCUS | This window won't get focus/make any other window lose focus when click.

Definition at line 61 of file window_gui.h.

enum WindowDefaultPosition

Special values for 'left' and 'top' to cause a specific placement.

Enumerator:

  WDP_AUTO | Find a place automatically.
  WDP_CENTER | Center the window (left/right or top/bottom).
  WDP_ALIGN_TBR | Align the right side of the window with the right side of the main toolbar.
  WDP_ALIGN_TBL | Align the left side of the window with the left side of the main toolbar.

Definition at line 78 of file window_gui.h.

enum WindowFlags

Window flags.

Enumerator:

  WF_TIMEOUT_TRIGGER | When the timeout should start triggering.
  WF_TIMEOUT_BEGIN | The initial value for the timeout.
  WF_TIMEOUT_MASK | Window timeout counter bit mask (3 bits).
  WF_DRAGGING | Window is being dragged.
  WF_SCROLL_UP | Upper scroll button has been pressed,. See also: ScrollbarClickHandler()
  WF_SCROLL_DOWN | Lower scroll button has been pressed,. See also: ScrollbarClickHandler()
  WF_SCROLL_MIDDLE | Scrollbar scrolling,. See also: ScrollbarClickHandler()
  WF_SIZING | Window is being resized.
  WF_STICKY | Window is made sticky by user.
  WF_DISABLE_VP_SCROLL | Window does not do autoscroll,. See also: HandleAutoscroll()

Definition at line 582 of file window_gui.h.

## Function Documentation

template<typename Wcls>

Wcls* AllocateWindowDescFront | ( | const WindowDesc * | desc,
|  | int | window_number |
| ) |  |  | `[inline]`

Open a new window.

Parameters:

  | desc | The pointer to the WindowDesc to be created
  | window_number | the window number of the new window

Returns:
  see Window pointer of the newly created window

Definition at line 611 of file window_gui.h.

References BringWindowToFrontById(), and WindowDesc::cls.

Window* BringWindowToFrontById | ( | WindowClass | cls,
|  | WindowNumber | number |
| ) |  |  |

Find a window and make it the top-window on the screen.

The window gets a white border for a brief period of time to visualize its "activation"

Parameters:

  | cls | WindowClass of the window to activate
  | number | WindowNumber of the window to activate

Returns:
  a pointer to the window thus activated

Definition at line 675 of file window.cpp.

References BringWindowToFront(), FindWindowById(), Window::flags4, and Window::SetDirty().

Referenced by AllocateWindowDescFront(), DoSelectCompanyManagerFace(), DoShowCompanyFinances(), CompanyWindow::OnClick(), ShowDepotWindow(), ShowGenerateWorldProgress(), and ShowSelectStationIfNeeded().

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:
  _colour_gradient

Parameters:

  | flags | Flags controlling how to draw the frame.

See also:
  FrameFlags

Definition at line 169 of file widget.cpp.

References _colour_gradient, FILLRECT_RECOLOUR, FR_BORDERONLY, FR_DARKENED, FR_LOWERED, FR_TRANSPARENT, and GfxFillRect().

Referenced by DrawArrowButtons(), SettingEntry::DrawSetting(), Window::DrawWidgets(), and AISettingsWindow::OnPaint().

bool EditBoxInGlobalFocus | ( |  | ) |

Check if an edit box is in global focus.

That is if focused window has a edit box as focused widget, or if a console is focused.

Returns:
  returns true if an edit box is in global focus or if the focused window is a console, else false

Definition at line 109 of file window.cpp.

References GetGloballyFocusedWidget(), Widget::type, Window::window_class, and WWT_EDITBOX.

Referenced by HandleKeypress(), and Window::Initialize().

Window* FindWindowFromPt | ( | int | x,
|  | int | y |
| ) |  |  |

Do a search for a window at specific coordinates.

For this we start at the topmost window, obviously and work our way down to the bottom

Parameters:

  | x | position x to query
  | y | position y to query

Returns:
  a pointer to the found window if any, NULL otherwise

Definition at line 1169 of file window.cpp.

References Window::height, IsInsideBS(), Window::left, Window::top, and Window::width.

Referenced by HandleAutoscroll().

const Widget* GetGloballyFocusedWidget | ( |  | ) |

Gets the globally focused widget.

Which is the focused widget of the focused window.

Returns:
  A pointer to the globally focused Widget, or NULL if there is no globally focused widget.

Definition at line 99 of file window.cpp.

References Window::focused_widget.

Referenced by EditBoxInGlobalFocus().

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:

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

Returns:
  A widget index, or -1 if no widget was found.

Definition at line 140 of file widget.cpp.

References Window::IsWidgetHidden(), Widget::left, Widget::top, Widget::type, Window::widget, Window::widget_count, WWT_EMPTY, and WWT_FRAME.

Referenced by DispatchLeftClickEvent(), and DispatchRightClickEvent().

void GuiShowTooltips | ( | StringID | str,
|  | uint | paramcount,
|  | const uint64 | params[],
|  | bool | use_left_mouse_button |
| ) |  |  |

Shows a tooltip.

Parameters:

  | str | String to be displayed
  | paramcount | number of params to deal with
  | params | (optional) up to 5 pieces of additional information that may be added to a tooltip
  | use_left_mouse_button | close the tooltip when the left (true) or right (false) mousebutton is released

Definition at line 669 of file misc_gui.cpp.

References Clamp(), DeleteWindowById(), GetStringBoundingBox(), Dimension::height, lastof, CursorVars::offs, CursorVars::pos, CursorVars::size, Dimension::width, Point::x, and Point::y.

Referenced by DispatchRightClickEvent(), and ShowMeasurementTooltips().

void RelocateAllWindows | ( | int | neww,
|  | int | newh |
| ) |  |  |

Relocate all windows to fit the new size of the game application screen.

Parameters:

  | neww | New width of the game application screen
  | newh | New height of the game appliction screen

Definition at line 2398 of file window.cpp.

References Clamp(), FindWindowById(), Window::height, ViewPort::height, ViewPort::left, Window::left, min(), Window::OnResize(), PositionMainToolbar(), ResizeWindow(), ScaleByZoom(), ViewPort::top, Window::top, Window::viewport, ViewPort::virtual_height, ViewPort::virtual_width, Window::width, ViewPort::width, Window::window_class, Point::x, Point::y, and ViewPort::zoom.

Referenced by GameSizeChanged().

void ResizeButtons | ( | Window * | w,
|  | byte | left,
|  | byte | right |
| ) |  |  |

Evenly distribute some widgets when resizing horizontally (often a button row) When only two arguments are given, the widgets are presumed to be on a line and only the ends are given.

Parameters:

  | w | Window to modify
  | left | The leftmost widget to resize
  | right | The rightmost widget to resize. Since right side of it is used, remember to set it to RESIZE_RIGHT

Definition at line 547 of file widget.cpp.

References Widget::left, ResizeButtons(), Widget::right, and Window::widget.

Referenced by StationViewWindow::OnResize(), NewGRFWindow::OnResize(), ReplaceVehicleWindow::OnResize(), AISettingsWindow::OnResize(), AIListWindow::OnResize(), and ResizeButtons().

void ResizeWindowForWidget | ( | Window * | w,
|  | uint | widget,
|  | int | delta_x,
|  | int | delta_y |
| ) |  |  |

Resize a widget and shuffle other widgets around to fit.

Definition at line 588 of file widget.cpp.

References Widget::bottom, ResizeInfo::height, Window::height, Widget::left, Window::resize, Widget::right, Widget::top, Window::widget, Window::widget_count, ResizeInfo::width, and Window::width.

Referenced by StationViewWindow::OnClick(), and ReplaceVehicleWindow::OnPaint().

void ScrollbarClickHandler | ( | Window * | w,
|  | const Widget * | wi,
|  | 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.
  | wi | Pointer to the scrollbar widget.
  | x | The X coordinate of the mouse click.
  | y | The Y coordinate of the mouse click.

Definition at line 55 of file widget.cpp.

References _left_button_clicked, Widget::bottom, Scrollbar::cap, Scrollbar::count, Window::flags4, HandleScrollbarHittest(), Window::hscroll, Widget::left, max(), min(), CursorVars::pos, Scrollbar::pos, Widget::right, Window::SetDirty(), Widget::top, Widget::type, Window::vscroll, Window::vscroll2, WF_SCROLL_DOWN, WF_SCROLL_MIDDLE, WF_SCROLL_UP, WWT_HSCROLLBAR, WWT_SCROLL2BAR, WWT_SCROLLBAR, Point::x, and Point::y.

Referenced by DispatchLeftClickEvent().

void SetFocusedWindow | ( | Window * | w | ) |

Set the window that has the focus.

Parameters:

  | w | The window to set the focus on

Definition at line 76 of file window.cpp.

References Window::focused_widget, Window::InvalidateWidget(), Window::OnFocus(), Window::OnFocusLost(), and Window::widget.

Referenced by DispatchLeftClickEvent(), and Window::Initialize().

void SetHScrollCount | ( | Window * | w,
|  | int | num |
| ) |  |  |

Set the number of items of the horizontal scrollbar.

Function also updates the position of the scrollbar if necessary.

Parameters:

  | w | Window containing the horizontal scrollbar
  | num | New number of items

Definition at line 2385 of file window.cpp.

References Scrollbar::cap, Scrollbar::count, Window::hscroll, and Scrollbar::pos.

void SetVScroll2Count | ( | Window * | w,
|  | int | num |
| ) |  |  |

Set the number of items of the second vertical scrollbar.

Function also updates the position of the scrollbar if necessary.

Parameters:

  | w | Window containing the second vertical scrollbar
  | num | New number of items

Definition at line 2370 of file window.cpp.

References Scrollbar::cap, Scrollbar::count, Scrollbar::pos, and Window::vscroll2.

Referenced by ReplaceVehicleWindow::GenerateLists().

void SetVScrollCount | ( | Window * | w,
|  | int | num |
| ) |  |  |

Set the number of items of the vertical scrollbar.

Function also updates the position of the scrollbar if necessary.

Parameters:

  | w | Window containing the vertical scrollbar
  | num | New number of items

Definition at line 2355 of file window.cpp.

References Scrollbar::cap, Scrollbar::count, Scrollbar::pos, and Window::vscroll.

Referenced by ReplaceVehicleWindow::GenerateLists(), VehicleListWindow::OnPaint(), StationViewWindow::OnPaint(), CompanyStationsWindow::OnPaint(), NewGRFAddWindow::OnPaint(), and IndustryDirectoryWindow::OnPaint().

## Variable Documentation

Window* _z_back_window

List of windows opened at the screen sorted from the back.

Definition at line 35 of file window.cpp.

Window* _z_front_window

List of windows opened at the screen sorted from the front.

Definition at line 33 of file window.cpp.