OpenTTD
Data Structures | Macros | Enumerations | Functions | Variables
window_gui.h File Reference

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

#include "vehicle_type.h"
#include "viewport_type.h"
#include "company_type.h"
#include "tile_type.h"
#include "widget_type.h"
#include "core/smallvec_type.hpp"
#include "core/smallmap_type.hpp"
#include "string_type.h"

Go to the source code of this file.

Data Structures

struct  WindowDesc
 High level window description. 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
 Base class for windows opened from a toolbar. More...
 

Macros

#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  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_SCROLLBAR_LEFT = 2,
  WD_SCROLLBAR_RIGHT = 2, WD_SCROLLBAR_TOP = 2, WD_SCROLLBAR_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_TEXTPANEL_TOP = 6,
  WD_TEXTPANEL_BOTTOM = 6, 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 = 3, WD_RESIZEBOX_RIGHT = 2,
  WD_RESIZEBOX_TOP = 3, 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...
 
enum  WindowPosition { WDP_MANUAL, WDP_AUTO, WDP_CENTER, WDP_ALIGN_TOOLBAR }
 How do we the window to be placed? More...
 
enum  WindowDefaultFlag { WDF_CONSTRUCTION = 1 << 0, WDF_MODAL = 1 << 1, WDF_NO_FOCUS = 1 << 2 }
 Window default widget/window handling flags. More...
 
enum  SortButtonState { SBS_OFF, SBS_DOWN, SBS_UP }
 State of a sort direction button. More...
 
enum  WindowFlags {
  WF_TIMEOUT = 1 << 0, WF_DRAGGING = 1 << 3, WF_SIZING_RIGHT = 1 << 4, WF_SIZING_LEFT = 1 << 5,
  WF_SIZING = WF_SIZING_RIGHT | WF_SIZING_LEFT, WF_STICKY = 1 << 6, WF_DISABLE_VP_SCROLL = 1 << 7, WF_WHITE_BORDER = 1 << 8,
  WF_HIGHLIGHTED = 1 << 9, WF_CENTERED = 1 << 10
}
 Window flags. More...
 
enum  TooltipCloseCondition { TCC_RIGHT_CLICK, TCC_LEFT_CLICK, TCC_HOVER }
 
enum  SpecialMouseMode { WSM_NONE, WSM_DRAGDROP, WSM_SIZING, WSM_PRESIZE }
 Mouse modes. More...
 

Functions

void DrawFrameRect (int left, int top, int right, int bottom, Colours colour, FrameFlags flags)
 Draw frame rectangle. More...
 
void DrawCaption (const Rect &r, Colours colour, Owner owner, StringID str)
 Draw a caption bar. More...
 
Point GetToolbarAlignedWindowPosition (int window_width)
 Computer the position of the top-left corner of a window to be opened right under the toolbar. More...
 
WindowBringWindowToFrontById (WindowClass cls, WindowNumber number)
 Find a window and make it the relative top-window on the screen. More...
 
WindowFindWindowFromPt (int x, int y)
 Do a search for a window at specific coordinates. More...
 
template<typename Wcls >
Wcls * AllocateWindowDescFront (WindowDesc *desc, int window_number, bool return_existing=false)
 Open a new window. More...
 
void RelocateAllWindows (int neww, int newh)
 Relocate all windows to fit the new size of the game application screen. More...
 
void GuiShowTooltips (Window *parent, StringID str, uint paramcount=0, const uint64 params[]=NULL, TooltipCloseCondition close_tooltip=TCC_HOVER)
 Shows a tooltip. 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 SetFocusedWindow (Window *w)
 Set the window that has the focus. More...
 
void ScrollbarClickHandler (Window *w, NWidgetCore *nw, int x, int y)
 Special handling for the scrollbar widget type. More...
 

Variables

Window_z_front_window
 List of windows opened at the screen sorted from the front. More...
 
Window_z_back_window
 List of windows opened at the screen sorted from the back. More...
 
Window_focused_window
 
static const int TIMEOUT_DURATION = 7
 The initial timeout value for WF_TIMEOUT.
 
static const int WHITE_BORDER_DURATION = 3
 The initial timeout value for WF_WHITE_BORDER.
 
Point _cursorpos_drag_start
 
int _scrollbar_start_pos
 
int _scrollbar_size
 
byte _scroller_click_timeout
 
bool _scrolling_viewport
 A viewport is being scrolled with the mouse.
 
bool _mouse_hovering
 The mouse is hovering over the same point.
 
SpecialMouseMode _special_mouse_mode
 Mode of the mouse.
 

Detailed Description

Functions, definitions and such used only by the GUI.

Definition in file window_gui.h.

Enumeration Type Documentation

◆ FrameFlags

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 27 of file window_gui.h.

◆ SortButtonState

State of a sort direction button.

Enumerator
SBS_OFF 

Do not sort (with this button).

SBS_DOWN 

Sort ascending.

SBS_UP 

Sort descending.

Definition at line 224 of file window_gui.h.

◆ SpecialMouseMode

Mouse modes.

Enumerator
WSM_NONE 

No special mouse mode.

WSM_DRAGDROP 

Dragging an object.

WSM_SIZING 

Sizing mode.

WSM_PRESIZE 

Presizing mode (docks, tunnels).

Definition at line 896 of file window_gui.h.

◆ 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_SCROLLBAR_LEFT 

Left offset of scrollbar.

WD_SCROLLBAR_RIGHT 

Right offset of scrollbar.

WD_SCROLLBAR_TOP 

Top offset of scrollbar.

WD_SCROLLBAR_BOTTOM 

Bottom offset of 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_TEXTPANEL_TOP 

Offset at top to draw above the text.

WD_TEXTPANEL_BOTTOM 

Offset at bottom to draw below the text.

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 38 of file window_gui.h.

◆ WindowDefaultFlag

Window default widget/window handling flags.

Enumerator
WDF_CONSTRUCTION 

This window is used for construction; close it whenever changing company.

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 209 of file window_gui.h.

◆ WindowFlags

Window flags.

Enumerator
WF_TIMEOUT 

Window timeout counter.

WF_DRAGGING 

Window is being dragged.

WF_SIZING_RIGHT 

Window is being resized towards the right.

WF_SIZING_LEFT 

Window is being resized towards the left.

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().
WF_WHITE_BORDER 

Window white border counter bit mask.

WF_HIGHLIGHTED 

Window has a widget that has a highlight.

WF_CENTERED 

Window is centered and shall stay centered after ReInit.

Definition at line 233 of file window_gui.h.

◆ WindowPosition

How do we the window to be placed?

Enumerator
WDP_MANUAL 

Manually align the window (so no automatic location finding)

WDP_AUTO 

Find a place automatically.

WDP_CENTER 

Center the window.

WDP_ALIGN_TOOLBAR 

Align toward the toolbar.

Definition at line 154 of file window_gui.h.

Function Documentation

◆ AllocateWindowDescFront()

template<typename Wcls >
Wcls* AllocateWindowDescFront ( WindowDesc desc,
int  window_number,
bool  return_existing = false 
)

Open a new window.

Template Parameters
WclsWindow class to use if the window does not exist.
Parameters
descThe pointer to the WindowDesc to be created
window_numberthe window number of the new window
return_existingIf set, also return the window if it already existed.
Returns
Window pointer of the newly created window, or the existing one if return_existing is set, or NULL.

Definition at line 859 of file window_gui.h.

References BringWindowToFrontById(), WindowDesc::cls, and RelocateAllWindows().

◆ BringWindowToFrontById()

Window* BringWindowToFrontById ( WindowClass  cls,
WindowNumber  number 
)

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

The window gets unshaded if it was shaded, and a white border is drawn at its edges for a brief period of time to visualize its "activation".

Parameters
clsWindowClass of the window to activate
numberWindowNumber of the window to activate
Returns
a pointer to the window thus activated

Definition at line 1234 of file window.cpp.

References BringWindowToFront(), FindWindowById(), Window::IsShaded(), Window::SetDirty(), Window::SetShaded(), and Window::SetWhiteBorder().

Referenced by AllocateWindowDescFront(), DoSelectCompanyManagerFace(), CompanyWindow::OnClick(), ShowAIDebugWindow(), ShowCompanyFinances(), ShowDepotWindow(), ShowGenerateWorldProgress(), and ShowIndustryCargoesWindow().

◆ DrawCaption()

void DrawCaption ( const Rect r,
Colours  colour,
Owner  owner,
StringID  str 
)

Draw a caption bar.

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

Definition at line 540 of file widget.cpp.

References _colour_gradient, _company_colours, DrawFrameRect(), DrawString(), FR_BORDERONLY, FR_DARKENED, FR_LOWERED, GetStringBoundingBox(), GfxFillRect(), max(), MAX_COMPANIES, WD_CAPTIONTEXT_LEFT, and WD_CAPTIONTEXT_RIGHT.

Referenced by NewsWindow::DrawWidget().

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

Referenced by DrawButtonDropdown(), DrawCaption(), DrawInset(), DrawMatrix(), DrawResizeBox(), BaseNetworkContentDownloadStatusWindow::DrawWidget(), GenerateProgressWindow::DrawWidget(), ScanProgressWindow::DrawWidget(), and Window::DrawWidgets().

◆ FindWindowFromPt()

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
xposition x to query
yposition y to query
Returns
a pointer to the found window if any, NULL otherwise

Definition at line 1854 of file window.cpp.

Referenced by HandleMouseOver().

◆ GetToolbarAlignedWindowPosition()

Point GetToolbarAlignedWindowPosition ( int  window_width)

Computer the position of the top-left corner of a window to be opened right under the toolbar.

Parameters
window_widththe width of the window to get the position for
Returns
Coordinate of the top-left corner of the new window.

Definition at line 1708 of file window.cpp.

References FindWindowById(), and WC_MAIN_TOOLBAR.

Referenced by TransparenciesWindow::OnInitialPosition(), and TerraformToolbarWindow::OnInitialPosition().

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

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

◆ GuiShowTooltips()

void GuiShowTooltips ( Window parent,
StringID  str,
uint  paramcount,
const uint64  params[],
TooltipCloseCondition  close_tooltip 
)

Shows a tooltip.

Parameters
parentThe window this tooltip is related to.
strString to be displayed
paramcountnumber of params to deal with
params(optional) up to 5 pieces of additional information that may be added to a tooltip
use_left_mouse_buttonclose the tooltip when the left (true) or right (false) mouse button is released

Definition at line 742 of file misc_gui.cpp.

References DeleteWindowById(), Window::GetWidget(), Window::InvalidateData(), Window::IsWidgetGloballyFocused(), Window::SetWidgetDirty(), WC_OSK, WC_TOOLTIPS, and Window::window_class.

Referenced by IndustryCargoesWindow::OnHover().

◆ RelocateAllWindows()

void RelocateAllWindows ( int  neww,
int  newh 
)

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

Parameters
newwNew width of the game application screen
newhNew height of the game application screen.

Definition at line 3458 of file window.cpp.

Referenced by AllocateWindowDescFront().

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

◆ SetFocusedWindow()

void SetFocusedWindow ( Window w)

Set the window that has the focus.

Parameters
wThe window to set the focus on

Definition at line 432 of file window.cpp.

References Window::nested_focus, and NWidgetBase::SetDirty().

Referenced by Window::InitializeData(), SignListWindow::OnHotkey(), and Window::OnHotkey().

Variable Documentation

◆ _z_back_window

Window* _z_back_window

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

Definition at line 57 of file window.cpp.

◆ _z_front_window

Window* _z_front_window

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

Definition at line 55 of file window.cpp.