OpenTTD Source  20241121-master-g67a0fccfad
window_gui.h File Reference

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

#include "vehiclelist.h"
#include "vehicle_type.h"
#include "viewport_type.h"
#include "company_type.h"
#include "tile_type.h"
#include "widget_type.h"
#include "string_type.h"

Go to the source code of this file.

Data Structures

class  WidgetDimensions
 
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...
 
struct  Window::WindowIterator< TtoBack >
 Iterator to iterate all valid Windows. More...
 
struct  Window::AllWindows< Tfront >
 Iterable ensemble of all valid Windows. More...
 
class  PickerWindowBase
 Base class for windows opened from a toolbar. More...
 

Typedefs

using WindowList = std::list< 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  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 , WDF_NO_CLOSE = 1 << 3 }
 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_HOVER , TCC_NONE , TCC_EXIT_VIEWPORT }
 
enum  SpecialMouseMode {
  WSM_NONE , WSM_DRAGDROP , WSM_SIZING , WSM_PRESIZE ,
  WSM_DRAGGING
}
 Mouse modes. More...
 

Functions

void DrawFrameRect (int left, int top, int right, int bottom, Colours colour, FrameFlags flags)
 Draw frame rectangle. More...
 
void DrawFrameRect (const Rect &r, Colours colour, FrameFlags flags)
 
void DrawCaption (const Rect &r, Colours colour, Owner owner, TextColour text_colour, StringID str, StringAlignment align, FontSize fs)
 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...
 
template<class It , class Pred >
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 predicate. 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 T , std::enable_if_t< std::is_base_of< StrongTypedefBase, T >::value, int > = 0>
WindowBringWindowToFrontById (WindowClass cls, T number)
 
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, TooltipCloseCondition close_tooltip, uint paramcount=0)
 Shows a tooltip. More...
 
WidgetID 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...
 
Rect ScrollRect (Rect r, const Scrollbar &sb, int resize_step=1)
 Apply 'scroll' to a rect to be drawn in. More...
 

Variables

WindowList _z_windows
 List of windows opened at the screen sorted from the front to back.
 
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
 
uint8_t _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 24 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 218 of file window_gui.h.

◆ SpecialMouseMode

Mouse modes.

Enumerator
WSM_NONE 

No special mouse mode.

WSM_DRAGDROP 

Drag&drop an object.

WSM_SIZING 

Sizing mode.

WSM_PRESIZE 

Presizing mode (docks, tunnels).

WSM_DRAGGING 

Dragging mode (trees).

Definition at line 1039 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.

WDF_NO_CLOSE 

This window can't be interactively closed.

Definition at line 202 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 227 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 145 of file window_gui.h.

Function Documentation

◆ AllEqual()

template<class It , class Pred >
bool AllEqual ( It  begin,
It  end,
Pred  pred 
)
inline

Generic helper function that checks if all elements of the range are equal with respect to the given predicate.

Parameters
beginThe start of the range.
endThe end of the range.
predThe predicate to use.
Returns
True if all elements are equal, false otherwise.

Definition at line 940 of file window_gui.h.

Referenced by DepotWindow::OnVehicleSelect(), and OrdersWindow::OnVehicleSelect().

◆ 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 nullptr.

Definition at line 1015 of file window_gui.h.

References BringWindowToFrontById(), and WindowDesc::cls.

◆ 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 1223 of file window.cpp.

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

Referenced by AllocateWindowDescFront(), DoSelectCompanyManagerFace(), ShowBuyCompanyDialog(), ShowCompanyFinances(), ShowDepotWindow(), ShowGenerateWorldProgress(), ShowIndustryCargoesWindow(), and ShowScriptDebugWindow().

◆ DrawCaption()

void DrawCaption ( const Rect r,
Colours  colour,
Owner  owner,
TextColour  text_colour,
StringID  str,
StringAlignment  align,
FontSize  fs 
)

Draw a caption bar.

Parameters
rRectangle of the bar.
colourColour of the window.
owner'Owner' of the window.
text_colourColour of the text.
strText to draw in the bar.
alignAlignment of the text.
fsFont size of the text.

Definition at line 679 of file widget.cpp.

References _company_colours, WidgetDimensions::bevel, DrawFrameRect(), FR_BORDERONLY, FR_DARKENED, FR_LOWERED, GetColourGradient(), GfxFillRect(), MAX_COMPANIES, WidgetDimensions::scaled, and Rect::Shrink().

◆ 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
Colours
Parameters
flagsFlags controlling how to draw the frame.
See also
FrameFlags

Definition at line 281 of file widget.cpp.

Referenced by DrawButtonDropdown(), DrawCaption(), DrawImageButtons(), DrawInset(), DrawResizeBox(), 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, nullptr otherwise

Definition at line 1768 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 1627 of file window.cpp.

References _current_text_dir, FindWindowById(), Window::height, Window::left, TD_RTL, Window::top, WC_MAIN_TOOLBAR, and Window::width.

◆ GetWidgetFromPos()

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

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

◆ GuiShowTooltips()

void GuiShowTooltips ( Window parent,
StringID  str,
TooltipCloseCondition  close_tooltip,
uint  paramcount 
)

Shows a tooltip.

Parameters
parentThe window this tooltip is related to.
strString to be displayed
close_tooltipthe condition under which the tooltip closes
paramcountnumber of params to deal with

Definition at line 760 of file misc_gui.cpp.

References CloseWindowById(), and WC_TOOLTIPS.

Referenced by ShowMeasurementTooltips().

◆ RelocateAllWindows()

void RelocateAllWindows ( int  neww,
int  newh 
)

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

◆ ScrollRect()

Rect ScrollRect ( Rect  r,
const Scrollbar sb,
int  resize_step 
)

Apply 'scroll' to a rect to be drawn in.

Parameters
rRect to be 'scrolled'.
sbThe scrollbar affecting the scroll.
resize_stepResize step of the widget/scrollbar (1 if the scrollbar is pixel-based.)
Returns
Scrolled rect.

Definition at line 2411 of file widget.cpp.

References _current_text_dir, Scrollbar::GetCount(), Scrollbar::GetPosition(), Scrollbar::IsVertical(), and TD_RTL.

◆ SetFocusedWindow()

void SetFocusedWindow ( Window w)

Set the window that has the focus.

Parameters
wThe window to set the focus on

Definition at line 422 of file window.cpp.

Referenced by Window::OnHotkey(), BuildVehicleWindow::OnHotkey(), IndustryDirectoryWindow::OnHotkey(), PickerWindow::OnHotkey(), SignListWindow::OnHotkey(), and TownDirectoryWindow::OnHotkey().