43#include "table/strings.h"
87Point _cursorpos_drag_start;
89int _scrollbar_start_pos;
91uint8_t _scroller_click_timeout = 0;
109 WindowClass window_class, WindowClass parent_class, WindowDefaultFlags
flags,
111 const std::source_location location) :
127WindowDesc::~WindowDesc()
160 if (wd->ini_key.empty())
continue;
184 if (wd->ini_key.empty())
continue;
215 if (line_height < 0) line_height = wid->
resize_y;
216 if (clickpos < wid->pos_y + padding)
return INT_MAX;
217 return (clickpos - wid->
pos_y - padding) / line_height;
244 if (nwid ==
nullptr)
return;
249 if (highlighted_colour != TC_INVALID) {
274 if (nwid ==
nullptr)
return false;
289 if (widget < 0)
return;
339 return query != this->
querystrings.end() ? query->second :
nullptr;
350 return query != this->
querystrings.end() ? query->second :
nullptr;
359 qs.second->text.UpdateSize();
402 Rect r = {0, 0, 0, 0};
426 if (_focused_window == w)
return;
432 if (_focused_window !=
nullptr) {
433 if (_focused_window->nested_focus !=
nullptr) _focused_window->nested_focus->SetDirty(_focused_window);
437 Window *old_focused = _focused_window;
441 if (old_focused !=
nullptr) old_focused->
OnFocusLost(
false);
442 if (_focused_window !=
nullptr) _focused_window->OnFocus();
452 if (_focused_window ==
nullptr)
return false;
455 if (_focused_window->window_class ==
WC_CONSOLE)
return true;
457 return _focused_window->nested_focus !=
nullptr && _focused_window->nested_focus->type ==
WWT_EDITBOX;
466 return _focused_window && _focused_window->window_class ==
WC_CONSOLE;
491 assert(widget !=
nullptr);
509 if (stringid == STR_NULL)
return {};
538 if (wid !=
nullptr && ((type & ~WWB_PUSHBUTTON) <
WWT_LAST || type == NWID_PUSHBUTTON_DROPDOWN) &&
548 if (wid !=
nullptr) {
565 it->second->SetDirty(
this);
627 bool focused_widget_changed =
false;
630 if (_focused_window != w) {
633 focused_widget_changed =
true;
635 }
else if (_focused_window !=
nullptr && _focused_window->window_class ==
WC_DROPDOWN_MENU) {
642 if (nw ==
nullptr)
return;
647 WidgetID widget_index = nw->GetIndex();
672 switch (widget_type) {
680 if (query !=
nullptr) query->ClickEditBox(w, pt, widget_index, click_count, focused_widget_changed);
701 if (click_count > 1) {
747 if (widget_index < 0)
return;
755 w->
OnClick(pt, widget_index, click_count);
767 if (wid ==
nullptr)
return;
772 if (wid->GetIndex() >= 0) {
798 if (wid ==
nullptr)
return;
809 if (wid->GetIndex() < 0)
return;
811 w->
OnHover(pt, wid->GetIndex());
823 if (nwid ==
nullptr)
return;
890 for (; !it.IsEnd(); ++it) {
895 left < v->left + v->
width &&
896 top < v->top + v->
height) {
900 if (left < (x = v->
left)) {
912 if (top < (x = v->
top)) {
930 dp->width = right - left;
931 dp->height = bottom - top;
932 dp->left = left - w->
left;
933 dp->top = top - w->
top;
934 dp->pitch = _screen.pitch;
957 left < w->left + w->width &&
958 top < w->top + w->height) {
960 DrawOverlappedWindow(w, std::max(left, w->left), std::max(top, w->top), std::min(right, w->left + w->width), std::min(bottom, w->top + w->height));
1000 window_width = std::max(window_width + rx, this->
width);
1001 window_height = std::max(window_height + ry, this->
height);
1002 int dx = (this->
resize.step_width == 0) ? 0 : window_width - this->
width;
1003 int dy = (this->
resize.step_height == 0) ? 0 : window_height - this->
height;
1006 if (this->
resize.step_width > 1) dx -= dx % (int)this->
resize.step_width;
1007 if (this->
resize.step_height > 1) dy -= dy % (int)this->
resize.step_height;
1053 if ((wc ==
WC_INVALID || wc == v->window_class) && v->parent ==
this)
return v;
1068 if (wc == v->window_class && number == v->window_number && v->parent ==
this)
return v;
1081 while (child !=
nullptr) {
1096 while (child !=
nullptr) {
1109 if (*this->z_position ==
nullptr)
return;
1111 *this->z_position =
nullptr;
1113 if (_thd.window_class == this->window_class &&
1114 _thd.window_number == this->window_number) {
1128 if (_focused_window ==
this) {
1130 _focused_window =
nullptr;
1137 Window::closed_windows.push_back(
this);
1146 assert(*this->z_position ==
nullptr);
1158 if (w->window_class == cls && w->window_number == number)
return w;
1173 if (w->window_class == cls)
return w;
1187 assert(w !=
nullptr);
1215 if (w->window_class == cls) {
1231 if (w->owner ==
id) {
1250 if (w->owner != old_owner)
continue;
1252 switch (w->window_class) {
1267 w->owner = new_owner;
1297static inline bool IsVitalWindow(
const Window *w)
1323 uint z_priority = 0;
1406 WindowList::iterator dest =
_z_windows.begin();
1409 if (dest != w->z_position) {
1446 bool dropdown_active = _focused_window !=
nullptr && _focused_window->window_class ==
WC_DROPDOWN_MENU;
1465 this->
width = sm_width;
1466 this->
height = sm_height;
1483 def_width = std::max(def_width, this->
width);
1484 def_height = std::max(def_height, this->
height);
1490 if (this->
width != def_width || this->
height != def_height) {
1492 int free_height = _screen.height;
1494 if (wt !=
nullptr) free_height -= wt->
height;
1496 if (wt !=
nullptr) free_height -= wt->
height;
1498 int enlarge_x = std::max(std::min(def_width - this->
width, _screen.width - this->width), 0);
1499 int enlarge_y = std::max(std::min(def_height - this->
height, free_height - this->
height), 0);
1504 if (this->
resize.step_width > 1) enlarge_x -= enlarge_x % (int)this->
resize.step_width;
1505 if (this->
resize.step_height > 1) enlarge_y -= enlarge_y % (int)this->
resize.step_height;
1515 int nx = this->
left;
1518 if (nx + this->
width > _screen.width) nx -= (nx + this->
width - _screen.width);
1521 ny = std::max(ny, (wt ==
nullptr ||
this == wt || this->
top == 0) ? 0 : wt->
height);
1522 nx = std::max(nx, 0);
1548 int right = width + left;
1549 int bottom = height + top;
1551 if (left < 0 || top < toolbar_y || right > _screen.width || bottom > _screen.height)
return false;
1557 if (right > w->
left &&
1590 if (left < -(width >> 1) || left > _screen.width - (width >> 2))
return false;
1592 if (left < -(width >> 2) || left > _screen.width - (width >> 1))
return false;
1596 if (top < toolbar_y || top > _screen.height - (height >> 2))
return false;
1602 if (left + width > w->
left &&
1604 top + height > w->
top &&
1629 const int toolbar_y = main_toolbar !=
nullptr ? main_toolbar->
height : 0;
1630 if (
IsGoodAutoPlace1(rtl ? _screen.width - width : 0, toolbar_y, width, height, toolbar_y, pt))
return pt;
1665 int left = rtl ? _screen.width - width : 0, top = toolbar_y;
1671 if (w->
left == left && w->
top == top) {
1692 assert(w !=
nullptr);
1743 pt.
x = w->
left + (rtl ? w->
width - default_width : 0);
1752 if (w->
top + 3 * indent_y < _screen.height) {
1753 pt.
y = w->
top + indent_y;
1757 pt.
x = std::max(w->
left + w->
width - default_width - indent_close, 0);
1758 if (pt.
x + default_width >= indent_close && pt.
x + indent_resize <= _screen.width)
return pt;
1760 pt.
x = std::min(w->
left + indent_close, _screen.width - default_width);
1761 if (pt.
x + default_width >= indent_resize && pt.
x + indent_close <= _screen.width)
return pt;
1775 pt.
x = (_screen.width - default_width) / 2;
1776 pt.
y = (_screen.height - default_height) / 2;
1865 _focused_window =
nullptr;
1873 NWidgetScrollbar::InvalidateDimensionCache();
1904static void DecreaseWindowCounters()
1906 if (_scroller_click_timeout != 0) _scroller_click_timeout--;
1909 if (_scroller_click_timeout == 0) {
1915 if (sb->
disp_flags.
Any({NWidgetDisplayFlag::ScrollbarUp, NWidgetDisplayFlag::ScrollbarDown})) {
1926 pair.second->HandleEditBox(w, pair.first);
1942static void HandlePlacePresize()
1946 Window *w = _thd.GetCallbackWnd();
1947 if (w ==
nullptr)
return;
1949 Point pt = GetTileBelowCursor();
1968 Window *w = _thd.GetCallbackWnd();
1972 pt.
x = _cursor.pos.x - w->
left;
1973 pt.
y = _cursor.pos.y - w->
top;
1993 Point pt = { -1, -1 };
2002 Point pt = { _cursor.pos.x - w->
left, _cursor.pos.y - w->
top };
2004 if (widget !=
nullptr) w->
OnMouseOver(pt, widget->GetIndex());
2026 if (v ==
nullptr)
return;
2028 const int min_visible = rect.
Height();
2032 int safe_y = (dir ==
PHD_UP) ? (v->
top - min_visible - rect.top) : (v_bottom + min_visible - rect.bottom);
2034 if (*ny + rect.top <= v->
top - min_visible)
return;
2035 if (*ny + rect.bottom >= v_bottom + min_visible)
return;
2038 if (*nx + rect.left + min_visible < v->left) {
2039 if (v->
left < min_visible) *ny = safe_y;
2042 if (*nx + rect.right - min_visible > v_right) {
2043 if (v_right > _screen.width - min_visible) *ny = safe_y;
2048 if (px + rect.left < v->
left && v->
left >= min_visible) {
2049 *nx = v->
left - min_visible - rect.left;
2050 }
else if (px + rect.right > v_right && v_right <= _screen.width - min_visible) {
2051 *nx = v_right + min_visible - rect.right;
2068 if (caption !=
nullptr) {
2069 const Rect caption_rect = caption->GetCurrentRect();
2071 const int min_visible = caption_rect.
Height();
2074 nx =
Clamp(nx, min_visible - caption_rect.right, _screen.width - min_visible - caption_rect.left);
2075 ny =
Clamp(ny, 0, _screen.height - min_visible);
2104 if (delta_x != 0 || delta_y != 0) {
2105 if (clamp_to_screen) {
2108 int new_right = w->
left + w->
width + delta_x;
2109 int new_bottom = w->
top + w->
height + delta_y;
2110 if (new_right >= (
int)_screen.width) delta_x -=
Ceil(new_right - _screen.width, std::max(1U, w->
nested_root->resize_x));
2111 if (new_bottom >= (
int)_screen.height) delta_y -=
Ceil(new_bottom - _screen.height, std::max(1U, w->
nested_root->resize_y));
2129 if (schedule_resize) {
2145 return (w ==
nullptr) ? 0 : w->
top + w->
height;
2156 return (w ==
nullptr) ? _screen.height : w->
top;
2195 if (v == w)
continue;
2197 if (y + w->
height > v->top && y < v->top + v->height) {
2199 delta =
abs(v->left + v->width - x);
2200 if (delta <= hsnap) {
2201 nx = v->left + v->width;
2206 delta =
abs(v->left - x - w->
width);
2207 if (delta <= hsnap) {
2208 nx = v->left - w->
width;
2213 if (w->
top + w->
height >= v->top && w->
top <= v->top + v->height) {
2215 delta =
abs(v->left - x);
2216 if (delta <= hsnap) {
2222 delta =
abs(v->left + v->width - x - w->
width);
2223 if (delta <= hsnap) {
2224 nx = v->left + v->width - w->
width;
2229 if (x + w->
width > v->left && x < v->left + v->width) {
2231 delta =
abs(v->top + v->height - y);
2232 if (delta <= vsnap) {
2233 ny = v->top + v->height;
2239 if (delta <= vsnap) {
2245 if (w->
left + w->
width >= v->left && w->
left <= v->left + v->width) {
2247 delta =
abs(v->top - y);
2248 if (delta <= vsnap) {
2254 delta =
abs(v->top + v->height - y - w->
height);
2255 if (delta <= vsnap) {
2256 ny = v->top + v->height - w->
height;
2291 if (w->
top + w->
height + y > _screen.height) {
2292 y = _screen.height - w->
height - w->
top;
2377 i = _cursor.pos.x - _cursorpos_drag_start.x;
2380 i = _cursor.pos.y - _cursorpos_drag_start.y;
2383 if (sb->
disp_flags.
Any({NWidgetDisplayFlag::ScrollbarUp, NWidgetDisplayFlag::ScrollbarDown})) {
2384 if (_scroller_click_timeout == 1) {
2385 _scroller_click_timeout = 3;
2396 if (range <= 0)
return;
2398 int pos =
RoundDivSU((i + _scrollbar_start_pos) * range, std::max(1, _scrollbar_size));
2399 if (rtl) pos = range - pos;
2427 if (_cursor.delta.x == 0 && _cursor.delta.y == 0)
return ES_HANDLED;
2429 Point pt = { _cursor.pos.x - w->
left, _cursor.pos.y - w->
top };
2455 _cursor.fix_at =
false;
2469 if (scrollwheel_scrolling) {
2472 delta.
x =
static_cast<int>(_cursor.h_wheel);
2473 delta.
y =
static_cast<int>(_cursor.v_wheel);
2476 _cursor.v_wheel = std::modf(_cursor.v_wheel, &temp);
2477 _cursor.h_wheel = std::modf(_cursor.h_wheel, &temp);
2480 delta.
x = -_cursor.delta.x;
2481 delta.
y = -_cursor.delta.y;
2483 delta.
x = _cursor.delta.x;
2484 delta.
y = _cursor.delta.y;
2491 _cursor.delta.x = 0;
2492 _cursor.delta.y = 0;
2493 _cursor.wheel_moved =
false;
2509 bool bring_to_front =
false;
2519 int w_width = w->
width;
2520 int w_height = w->
height;
2528 for (; !it.IsEnd(); ++it) {
2545 if (w->
left + w_width <= u->left ||
2547 w->
top + w_height <= u->top ||
2552 bring_to_front =
true;
2574 switch (query->text.HandleKeyPress(key, keycode)) {
2618 if (query->text.
GetText().empty()) {
2669 if (key >= 0xE000 && key <= 0xF8FF) key = 0;
2674 if (key == 0 && keycode == 0)
return;
2679 if (_focused_window->window_class ==
WC_CONSOLE) {
2680 if (_focused_window->OnKeyPress(key, keycode) ==
ES_HANDLED)
return;
2682 if (_focused_window->HandleEditBoxKey(_focused_window->nested_focus->GetIndex(), key, keycode) ==
ES_HANDLED)
return;
2706 HandleGlobalHotkeys(key, keycode);
2729 void Window::InsertTextString(
WidgetID wid, std::string_view str,
bool marked, std::optional<size_t> caret, std::optional<size_t> insert_location, std::optional<size_t> replacement_end)
2732 if (query ==
nullptr)
return;
2734 if (query->text.
InsertString(str, marked, caret, insert_location, replacement_end) || marked) {
2748void HandleTextInput(std::string_view str,
bool marked, std::optional<size_t> caret, std::optional<size_t> insert_location, std::optional<size_t> replacement_end)
2752 _focused_window->InsertTextString(_focused_window->window_class ==
WC_CONSOLE ? 0 : _focused_window->nested_focus->GetIndex(), str, marked, caret, insert_location, replacement_end);
2765 int x = _cursor.pos.x;
2766 int y = _cursor.pos.y;
2772 if (vp ==
nullptr)
return;
2779 static const int SCROLLSPEED = 3;
2783 }
else if (15 - (vp->
width - x) > 0) {
2790 }
else if (15 - (vp->
height - y) > 0) {
2796enum MouseClick : uint8_t {
2811static void ScrollMainViewport(
int x,
int y)
2813 if (_game_mode != GM_MENU && _game_mode != GM_BOOTSTRAP) {
2848static void HandleKeyScrolling()
2857 if (_game_mode != GM_MENU && _game_mode != GM_BOOTSTRAP) {
2860 main_window->
viewport->CancelFollow(*main_window);
2867static void MouseLoop(MouseClick click,
int mousewheel)
2873 HandlePlacePresize();
2885 if (click == MC_NONE && mousewheel == 0 && !scrollwheel_scrolling)
return;
2887 int x = _cursor.pos.x;
2888 int y = _cursor.pos.y;
2890 if (w ==
nullptr)
return;
2896 if (vp !=
nullptr && (_game_mode == GM_MENU ||
HasModalProgress()))
return;
2898 if (mousewheel != 0) {
2910 if (vp !=
nullptr) {
2913 _cursor.fix_at =
true;
2918 case MC_DOUBLE_LEFT:
2920 if (HandleViewportClicked(*vp, x, y))
return;
2924 _cursor.fix_at =
false;
2947 case MC_DOUBLE_LEFT:
2967 _cursor.h_wheel = 0.0f;
2968 _cursor.v_wheel = 0.0f;
2969 _cursor.wheel_moved =
false;
2981 static std::chrono::steady_clock::time_point double_click_time = {};
2982 static Point double_click_pos = {0, 0};
2985 MouseClick click = MC_NONE;
2991 click = MC_DOUBLE_LEFT;
2993 double_click_time = std::chrono::steady_clock::now();
2994 double_click_pos = _cursor.pos;
3002 if (_cursor.wheel) {
3003 mousewheel = _cursor.wheel;
3007 static std::chrono::steady_clock::time_point hover_time = {};
3008 static Point hover_pos = {0, 0};
3014 hover_pos = _cursor.pos;
3015 hover_time = std::chrono::steady_clock::now();
3018 if (std::chrono::steady_clock::now() > hover_time + std::chrono::milliseconds(
_settings_client.gui.hover_delay_ms)) {
3021 hover_time = std::chrono::steady_clock::now();
3034 MouseLoop(click, mousewheel);
3039 _cursor.delta.x = 0;
3040 _cursor.delta.y = 0;
3051 uint deletable_count = 0;
3052 Window *last_deletable =
nullptr;
3063 assert(last_deletable !=
nullptr);
3064 last_deletable->
Close();
3086static std::chrono::time_point<std::chrono::steady_clock> _realtime_tick_start;
3088bool CanContinueRealtimeTick()
3090 auto now = std::chrono::steady_clock::now();
3091 return std::chrono::duration_cast<std::chrono::milliseconds>(now - _realtime_tick_start).count() < (
MILLISECONDS_PER_TICK * 3 / 4);
3099 _realtime_tick_start = std::chrono::steady_clock::now();
3107 extern int _caret_timer;
3111 HandleKeyScrolling();
3113 DecreaseWindowCounters();
3138 static auto last_time = std::chrono::steady_clock::now();
3139 auto now = std::chrono::steady_clock::now();
3140 auto delta_ms = std::chrono::duration_cast<std::chrono::milliseconds>(now - last_time);
3142 if (delta_ms.count() == 0)
return;
3269 this->scheduled_invalidation_data.clear();
3280 if (pair.second->IsHighlighted()) pair.second->SetDirty(
this);
3416void ReInitWindow(
Window *w,
bool zoom_changed)
3418 if (w ==
nullptr)
return;
3431 NWidgetScrollbar::InvalidateDimensionCache();
3441 ReInitWindow(w, zoom_changed);
3464 if (w ==
nullptr)
return 0;
3466 int old_left = w->
left;
3468 case 1: w->
left = (_screen.width - w->
width) / 2;
break;
3469 case 2: w->
left = _screen.width - w->
width;
break;
3470 default: w->
left = 0;
break;
3484 Debug(misc, 5,
"Repositioning Main Toolbar...");
3495 Debug(misc, 5,
"Repositioning statusbar...");
3506 Debug(misc, 5,
"Repositioning news message...");
3517 Debug(misc, 5,
"Repositioning network chat window...");
3531 w->
viewport->follow_vehicle = to_index;
3555 ws->top = newh - ws->height;
3593 top = (newh - w->
height) >> 1;
3594 left = (neww - w->
width) >> 1;
3599 if (left + (w->
width >> 1) >= neww) left = neww - w->
width;
3600 if (left < 0) left = 0;
3603 if (top + (w->
height >> 1) >= newh) top = newh - w->
height;
constexpr bool Test(Tvalue_type value) const
Test if the value-th bit is set.
constexpr Timpl & Reset()
Reset all bits.
constexpr Timpl & Flip(Tvalue_type value)
Flip the value-th bit.
constexpr Timpl & Set()
Set all bits.
constexpr bool Any(const Timpl &other) const
Test if any of the given values are set.
static Blitter * GetCurrentBlitter()
Get the current active blitter (always set by calling SelectBlitter).
How all blitters should look like.
virtual void * MoveTo(void *video, int x, int y)=0
Move the destination pointer the requested amount x and y, keeping in mind any pitch and bpp of the r...
static void NewEvent(class ScriptEvent *event)
Queue a new event for a Game Script.
An interval timer will fire every interval, and will continue to fire until it is deleted.
void Close(int data=0) override
Hide the window and all its child windows, and mark them for a later deletion.
static bool Elapsed(TElapsed value)
Called when time for this timer elapsed.
virtual void EditBoxLostFocus()
An edit box lost the input focus.
static VideoDriver * GetInstance()
Get the currently active instance of the video driver.
virtual void EditBoxGainedFocus()
An edit box gained the input focus.
Functions related to companies.
bool IsLocalCompany()
Is the current company the local company?
static constexpr Owner INVALID_OWNER
An invalid owner.
Console functions used outside of the console code.
void IConsoleClose()
Close the in-game console.
void IConsoleResize(Window *w)
Change the size of the in-game console window after the screen size changed, or the window state chan...
GUI related functions in the console.
#define Debug(category, level, format_string,...)
Output a line of debugging information.
Functions related to depots.
void InitDepotWindowBlockSizes()
Set the size of the blocks in the window so we can be sure that they are big enough for the vehicle s...
Functions related to errors.
void UnshowCriticalError()
Unshow the critical error.
void ShowFirstError()
Show the first error of the queue.
Factory to 'query' all available blitters.
@ NO_DIRECTORY
A path without any base directory.
int GetCharacterHeight(FontSize size)
Get height of a character for a given font size.
void ProcessPendingPerformanceMeasurements()
This drains the PFE_SOUND measurement data queue into _pf_data.
Types for recording game performance data.
@ PFE_DRAWING
Speed of drawing world and GUI.
@ PFE_DRAWWORLD
Time spent drawing world viewports in GUI.
Base functions for all Games.
bool _shift_pressed
Is Shift pressed?
bool _left_button_down
Is left mouse button pressed?
bool _ctrl_pressed
Is Ctrl pressed?
uint8_t _dirkeys
1 = left, 2 = up, 4 = right, 8 = down
bool _left_button_clicked
Is left mouse button clicked?
bool _right_button_clicked
Is right mouse button clicked?
bool _right_button_down
Is right mouse button pressed?
int _gui_scale
GUI scale, 100 is 100%.
Functions related to the gfx engine.
@ FS_NORMAL
Index of the normal font in the font tables.
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
static const uint MILLISECONDS_PER_TICK
The number of milliseconds per game tick.
void SetDirty() const
Mark entire window as dirty (in need of re-paint).
void AddDirtyBlock(int left, int top, int right, int bottom)
Extend the internal _invalid_rect rectangle to contain the rectangle defined by the given parameters.
void DrawDirtyBlocks()
Repaints the rectangle blocks which are marked as 'dirty'.
void MarkWholeScreenDirty()
This function mark the whole screen as dirty.
Hotkey related functions.
Types related to reading/writing '*.ini' files.
#define Rect
Macro that prevents name conflicts between included headers.
#define Point
Macro that prevents name conflicts between included headers.
static TileIndex TileVirtXY(uint x, uint y)
Get a tile from the virtual XY-coordinate.
constexpr bool IsInsideBS(const T x, const size_t base, const size_t size)
Checks if a value is between a window started at some base point.
constexpr T abs(const T a)
Returns the absolute value of (scalar) variable.
constexpr int RoundDivSU(int a, uint b)
Computes round(a / b) for signed a and unsigned b.
constexpr uint Ceil(uint a, uint b)
Computes ceil(a / b) * b for non-negative a and b.
constexpr T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
void GuiShowTooltips(Window *parent, EncodedString &&text, TooltipCloseCondition close_tooltip)
Shows a tooltip.
bool _networking
are we in networking mode?
bool _network_dedicated
are we a dedicated server?
Basic functions/variables used all over the place.
void NetworkDrawChatMessage()
Draw the chat message-box.
void NetworkReInitChatBoxSize()
Initialize all font-dependent chat box sizes.
void NetworkUndrawChatMessage()
Hide the chatbox.
Network functions used by other parts of OpenTTD.
Functions/types related to NewGRF debugging.
NewGrfDebugSpritePicker _newgrf_debug_sprite_picker
The sprite picker.
Functions related to news.
void InitNewsItemStructs()
Initialize the news-items data structures.
Functions related to modal progress.
bool HasModalProgress()
Check if we are currently in a modal progress state.
Base for the GUIs that have an edit box in them.
A number of safeguards to prevent using unsafe methods.
void IniLoadWindowSettings(IniFile &ini, std::string_view grpname, WindowDesc *desc)
Load a WindowDesc from config.
void IniSaveWindowSettings(IniFile &ini, std::string_view grpname, WindowDesc *desc)
Save a WindowDesc to config.
ClientSettings _settings_client
The current settings for this game.
Functions related to setting/changing the settings.
Types related to global configuration settings.
@ MapRMBFixed
Map moves with mouse movement on holding right mouse button, cursor position is fixed.
@ ViewportRMBFixed
Viewport moves with mouse movement on holding right mouse button, cursor position is fixed.
@ MapLMB
Map moves with mouse movement on holding left mouse button, cursor moves.
@ ScrollMap
Scroll wheel scrolls the map.
bool ScrollMainWindowTo(int x, int y, int z, bool instant)
Scrolls the main window to given coordinates.
void SndClickBeep()
Play a beep sound for a click event if enabled in settings.
Functions related to sound.
Functions, definitions and such used only by the GUI.
@ SBI_NEWS_DELETED
abort current news display (active news were deleted)
Definition of base types and functions in a cross-platform compatible way.
EncodedString GetEncodedString(StringID str)
Encode a string with no parameters into an encoded string.
std::string GetString(StringID string)
Resolve the given StringID into a std::string with formatting but no parameters.
TextDirection _current_text_dir
Text direction of the currently selected language.
Functions related to OTTD's strings.
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
@ TD_RTL
Text is written right-to-left by default.
Class to backup a specific variable and restore it upon destruction of this object to prevent stack v...
Data about how and where to blit pixels.
List of hotkeys for a window.
int CheckMatch(uint16_t keycode, bool global_only=false) const
Check if a keycode is bound to something.
Ini file that supports both loading and saving.
bool SaveToDisk(const std::string &filename)
Save the Ini file's data to the disk.
void LoadFromDisk(std::string_view filename, Subdirectory subdir)
Load the Ini file's data from the disk.
static Vehicle * Get(auto index)
Data stored about a string that can be modified in the GUI.
int ok_button
Widget button of parent window to simulate when pressing OK in OSK.
static const int ACTION_DESELECT
Deselect editbox.
int cancel_button
Widget button of parent window to simulate when pressing CANCEL in OSK.
ptrdiff_t GetCharAtPosition(const Window *w, WidgetID wid, const Point &pt) const
Get the character that is rendered at a position.
static const int ACTION_NOTHING
Nothing.
static const int ACTION_CLEAR
Clear editbox.
Point GetCaretPosition(const Window *w, WidgetID wid) const
Get the current caret position.
Rect GetBoundingRect(const Window *w, WidgetID wid, size_t from, size_t to) const
Get the bounding rectangle for a range of the query string.
Specification of a rectangle with absolute coordinates of all edges.
int Height() const
Get height of Rect.
uint step_height
Step-size of height resize changes.
uint step_width
Step-size of width resize changes.
Helper/buffer for input fields.
void DeleteAll()
Delete every character in the textbuffer.
std::string_view GetText() const
Get the current text.
bool InsertString(std::string_view str, bool marked, std::optional< size_t > caret=std::nullopt, std::optional< size_t > insert_location=std::nullopt, std::optional< size_t > replacement_end=std::nullopt)
Insert a string into the text buffer.
int32_t z_pos
z coordinate.
int32_t y_pos
y coordinate.
int32_t x_pos
x coordinate.
Data structure for viewport, display of a part of the world.
int top
Screen coordinate top edge of the viewport.
int width
Screen width of the viewport.
ZoomLevel zoom
The zoom level of the viewport.
int left
Screen coordinate left edge of the viewport.
int height
Screen height of the viewport.
High level window description.
int16_t GetDefaultWidth() const
Determine default width of window.
static void SaveToConfig()
Save all WindowDesc settings to _windows_file.
int16_t pref_width
User-preferred width of the window. Zero if unset.
const WindowPosition default_pos
Preferred position of the window.
bool pref_sticky
Preferred stickyness.
int16_t pref_height
User-preferred height of the window. Zero if unset.
int16_t GetDefaultHeight() const
Determine default height of window.
const int16_t default_height_trad
Preferred initial height of the window (pixels at 1x zoom).
const int16_t default_width_trad
Preferred initial width of the window (pixels at 1x zoom).
const WindowClass cls
Class of the window,.
const std::string_view ini_key
Key to store window defaults in openttd.cfg. An empty string if nothing shall be stored.
const std::source_location source_location
Source location of this definition.
const WindowDefaultFlags flags
Flags.
static void LoadFromConfig()
Load all WindowDesc settings from _windows_file.
const WindowClass parent_cls
Class of the parent window.
const HotkeyList * hotkeys
Hotkeys for the window.
WindowDesc(WindowPosition default_pos, std::string_view ini_key, int16_t def_width_trad, int16_t def_height_trad, WindowClass window_class, WindowClass parent_class, WindowDefaultFlags flags, const std::span< const NWidgetPart > nwid_parts, HotkeyList *hotkeys=nullptr, const std::source_location location=std::source_location::current())
Window description constructor.
const std::span< const NWidgetPart > nwid_parts
Span of nested widget parts describing the window.
Number to differentiate different windows of the same class.
Data structure for an opened window.
virtual const struct Textbuf * GetFocusedTextbuf() const
Get the current input text buffer.
void SetWidgetHighlight(WidgetID widget_index, TextColour highlighted_colour)
Sets the highlighted status of a widget.
void ReInit(int rx=0, int ry=0, bool reposition=false)
Re-initialize a window, and optionally change its size.
virtual void Close(int data=0)
Hide the window and all its child windows, and mark them for a later deletion.
virtual void OnInvalidateData(int data=0, bool gui_scope=true)
Some data on this window has become invalid.
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
std::map< WidgetID, QueryString * > querystrings
QueryString associated to WWT_EDITBOX widgets.
virtual void ApplyDefaults()
Read default values from WindowDesc configuration an apply them to the window.
uint8_t white_border_timer
Timer value of the WindowFlag::WhiteBorder for flags.
NWidgetStacked * shade_select
Selection widget (NWID_SELECTION) to use for shading the window. If nullptr, window cannot shade.
void InitializePositionSize(int x, int y, int min_width, int min_height)
Set the position and smallest size of the window.
Dimension unshaded_size
Last known unshaded size (only valid while shaded).
void InvalidateData(int data=0, bool gui_scope=true)
Mark this window's data as invalid (in need of re-computing).
virtual EventState OnKeyPress(char32_t key, uint16_t keycode)
A key has been pressed.
Window * parent
Parent window.
AllWindows< false > IterateFromBack
Iterate all windows in Z order from back to front.
virtual ~Window()
Remove window and all its child windows from the window stack.
void RaiseWidget(WidgetID widget_index)
Marks a widget as raised.
void SetWidgetDirty(WidgetID widget_index) const
Invalidate a widget, i.e.
uint8_t timeout_timer
Timer value of the WindowFlag::Timeout for flags.
std::unique_ptr< ViewportData > viewport
Pointer to viewport data, if present.
virtual std::string GetWidgetString(WidgetID widget, StringID stringid) const
Get the raw string for a widget.
WidgetID mouse_capture_widget
ID of current mouse capture widget (e.g. dragged scrollbar). INVALID_WIDGET if no widget has mouse ca...
virtual void OnGameTick()
Called once per (game) tick.
virtual void ShowNewGRFInspectWindow() const
Show the NewGRF inspection window.
virtual bool OnRightClick(Point pt, WidgetID widget)
A click with the right mouse button has been made on the window.
virtual void OnScrollbarScroll(WidgetID widget)
Notify window that a scrollbar position has been updated.
virtual void OnDropdownSelect(WidgetID widget, int index, int click_result)
A dropdown option associated to this window has been selected.
void ProcessScheduledInvalidations()
Process all scheduled invalidations.
void CloseChildWindows(WindowClass wc=WC_INVALID) const
Close all children a window might have in a head-recursive manner.
ResizeInfo resize
Resize information.
void UnfocusFocusedWidget()
Makes no widget on this window have focus.
virtual void OnMouseLoop()
Called for every mouse loop run, which is at least once per (game) tick.
void SetShaded(bool make_shaded)
Set the shaded state of the window to make_shaded.
int scale
Scale of this window – used to determine how to resize.
void ScheduleResize()
Mark this window as resized and in need of OnResize() event.
virtual void OnPaint()
The window must be repainted.
virtual void OnDragDrop(Point pt, WidgetID widget)
A dragged 'object' has been released.
void CreateNestedTree()
Perform the first part of the initialization of a nested widget tree.
WindowDesc & window_desc
Window description.
WindowClass window_class
Window class.
virtual void OnRealtimeTick(uint delta_ms)
Called periodically.
virtual void OnMouseWheel(int wheel, WidgetID widget)
The mouse wheel has been turned.
AllWindows< true > IterateFromFront
Iterate all windows in Z order from front to back.
void CloseChildWindowById(WindowClass wc, WindowNumber number) const
Close all children a window might have in a head-recursive manner.
void SetWhiteBorder()
Set the timeout flag of the window and initiate the timer.
bool SetFocusedWidget(WidgetID widget_index)
Set focus within this window to the given widget.
virtual void OnFocusLost(bool closing)
The window has lost focus.
bool IsWidgetLowered(WidgetID widget_index) const
Gets the lowered state of a widget.
static std::vector< Window * > closed_windows
List of closed windows to delete.
void RaiseButtons(bool autoraise=false)
Raise the buttons of the window.
virtual Point OnInitialPosition(int16_t sm_width, int16_t sm_height, int window_number)
Compute the initial position of the window.
Owner owner
The owner of the content shown in this window. Company colour is acquired from this variable.
virtual Point GetCaretPosition() const
Get the current caret position if an edit box has the focus.
virtual void FindWindowPlacementAndResize(int def_width, int def_height, bool allow_resize)
Resize window towards the default size.
virtual void OnDropdownClose(Point pt, WidgetID widget, int index, int click_result, bool instant_close)
A dropdown window associated to this window has been closed.
virtual void InsertTextString(WidgetID wid, std::string_view str, bool marked, std::optional< size_t > caret, std::optional< size_t > insert_location, std::optional< size_t > replacement_end)
Insert a text string at the cursor position into the edit box widget.
WindowIterator< false > IteratorToFront
Iterate in Z order towards front.
int left
x position of left edge of the window
bool IsShaded() const
Is window shaded currently?
Window * FindChildWindow(WindowClass wc=WC_INVALID) const
Find the Window whose parent pointer points to this window.
void SetTimeout()
Set the timeout flag of the window and initiate the timer.
const NWidgetCore * nested_focus
Currently focused nested widget, or nullptr if no nested widget has focus.
virtual void OnEditboxChanged(WidgetID widget)
The text in an editbox has been edited.
void UpdateQueryStringSize()
Update size of all QueryStrings of this window.
int top
y position of top edge of the window
virtual void OnClick(Point pt, WidgetID widget, int click_count)
A click with the left mouse button has been made on the window.
const QueryString * GetQueryString(WidgetID widnum) const
Return the querystring associated to a editbox.
WidgetLookup widget_lookup
Indexed access to the nested widget tree. Do not access directly, use Window::GetWidget() instead.
virtual ptrdiff_t GetTextCharacterAtPosition(const Point &pt) const
Get the character that is rendered at a position by the focused edit box.
std::vector< int > scheduled_invalidation_data
Data of scheduled OnInvalidateData() calls.
void InitializeData(WindowNumber window_number)
Initializes the data (except the position and initial size) of a new Window.
virtual void OnMouseOver(Point pt, WidgetID widget)
The mouse is currently moving over the window or has just moved outside of the window.
Window(WindowDesc &desc)
Empty constructor, initialization has been moved to InitNested() called from the constructor of the d...
int GetRowFromWidget(int clickpos, WidgetID widget, int padding, int line_height=-1) const
Compute the row of a widget that a user clicked in.
const NWID * GetWidget(WidgetID widnum) const
Get the nested widget with number widnum from the nested widget tree.
virtual bool OnTooltip(Point pt, WidgetID widget, TooltipCloseCondition close_cond)
Event to display a custom tooltip.
void LowerWidget(WidgetID widget_index)
Marks a widget as lowered.
virtual EventState OnCTRLStateChange()
The state of the control key has changed.
void ProcessScheduledResize()
Process scheduled OnResize() event.
EventState HandleEditBoxKey(WidgetID wid, char32_t key, uint16_t keycode)
Process keypress for editbox widget.
virtual void OnMouseDrag(Point pt, WidgetID widget)
An 'object' is being dragged at the provided position, highlight the target if possible.
void HandleButtonClick(WidgetID widget)
Do all things to make a button look clicked and mark it to be unclicked in a few ticks.
virtual void OnResize()
Called after the window got resized.
Window * FindChildWindowById(WindowClass wc, WindowNumber number) const
Find the Window whose parent pointer points to this window.
virtual void OnFocus()
The window has gained focus.
void InitNested(WindowNumber number=0)
Perform complete initialization of the Window with nested widgets, to allow use.
virtual void OnTimeout()
Called when this window's timeout has been reached.
WindowFlags flags
Window flags.
const Scrollbar * GetScrollbar(WidgetID widnum) const
Return the Scrollbar to a widget index.
void ProcessHighlightedInvalidations()
Process all invalidation of highlighted widgets.
virtual EventState OnHotkey(int hotkey)
A hotkey has been pressed.
static void DeleteClosedWindows()
Delete all closed windows.
std::unique_ptr< NWidgetBase > nested_root
Root of the nested tree.
bool scheduled_resize
Set if window has been resized.
virtual Rect GetTextBoundingRect(size_t from, size_t to) const
Get the bounding rectangle for a text range if an edit box has the focus.
bool IsWidgetHighlighted(WidgetID widget_index) const
Gets the highlighted status of a widget.
void DisableAllWidgetHighlight()
Disable the highlighted status of all widgets.
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...
AllWindows< false > Iterate
Iterate all windows in whatever order is easiest.
int height
Height of the window (number of pixels down in y direction).
virtual void OnHover(Point pt, WidgetID widget)
The mouse is hovering over a widget in the window, perform an action for it.
int width
width of the window (number of pixels to the right in x direction)
virtual void OnInit()
Notification that the nested widget tree gets initialized.
WindowNumber window_number
Window number within the window class.
std::vector< WindowDesc * > * _window_descs
List of WindowDescs.
@ HKPR_NOT_HANDLED
Key does not affect editboxes.
@ HKPR_CANCEL
Escape key pressed.
@ HKPR_EDITING
Textbuf content changed.
@ HKPR_CONFIRM
Return or enter key pressed.
@ HKPR_CURSOR
Non-text change, e.g. cursor position.
Functions related to tile highlights.
void ResetObjectToPlace()
Reset the cursor and mouse mode handling back to default (normal cursor, only clicking in windows).
void UpdateTileSelection()
Updates tile highlighting for all cases.
Definition of Interval and OneShot timers.
Definition of the Window system.
static constexpr std::chrono::milliseconds TIMER_BLINK_INTERVAL
Interval used by blinking interface elements.
Base class for all vehicles.
PoolID< uint32_t, struct VehicleIDTag, 0xFF000, 0xFFFFF > VehicleID
The type all our vehicle IDs have.
Base of all video drivers.
Viewport * IsPtInWindowViewport(const Window *w, int x, int y)
Is a xy position inside the viewport of the window?
void UpdateViewportPosition(Window *w, uint32_t delta_ms)
Update the viewport position being displayed.
Functions related to (drawing on) viewports.
int PositionStatusbar(Window *w)
(Re)position statusbar window at the screen.
static void PreventHiding(int *nx, int *ny, const Rect &rect, const Window *v, int px, PreventHideDirection dir)
Do not allow hiding of the rectangle with base coordinates nx and ny behind window v.
static bool _dragging_window
A window is being dragged or resized.
static const IntervalTimer< TimerWindow > white_border_interval(std::chrono::milliseconds(30), [](auto) { if(_network_dedicated) return;for(Window *w :Window::Iterate()) { if(w->flags.Test(WindowFlag::WhiteBorder) &&--w->white_border_timer==0) { w->flags.Reset(WindowFlag::WhiteBorder);w->SetDirty();} } })
Blink all windows marked with a white border.
void CloseConstructionWindows()
Close all windows that are used for construction of vehicle etc.
void CloseWindowById(WindowClass cls, WindowNumber number, bool force, int data)
Close a window by its class and window number (if it is open).
static Point LocalGetWindowPlacement(const WindowDesc &desc, int16_t sm_width, int16_t sm_height, int window_number)
Compute the position of the top-left corner of a new window that is opened.
Window * GetMainWindow()
Get the main window, i.e.
static Point _drag_delta
delta between mouse cursor and upper left corner of dragged window
static bool MayBeShown(const Window *w)
Returns whether a window may be shown or not.
void CloseCompanyWindows(CompanyID id)
Close all windows of a company.
void HandleCtrlChanged()
State of CONTROL key has changed.
static void DrawOverlappedWindow(Window *w, int left, int top, int right, int bottom)
Generate repaint events for the visible part of window w within the rectangle.
bool _scrolling_viewport
A viewport is being scrolled with the mouse.
void InputLoop()
Regular call from the global game loop.
void UpdateWindows()
Update the continuously changing contents of the windows, such as the viewports.
int PositionMainToolbar(Window *w)
(Re)position main toolbar window at the screen.
void CloseNonVitalWindows()
Try to close a non-vital window.
void DrawOverlappedWindowForAll(int left, int top, int right, int bottom)
From a rectangle that needs redrawing, find the windows that intersect with the rectangle.
void ResizeWindow(Window *w, int delta_x, int delta_y, bool clamp_to_screen, bool schedule_resize)
Resize the window.
static bool IsGoodAutoPlace2(int left, int top, int width, int height, int toolbar_y, Point &pos)
Decide whether a given rectangle is a good place to open a mostly visible new window.
int PositionNetworkChatWindow(Window *w)
(Re)position network chat window at the screen.
static void StartWindowSizing(Window *w, bool to_left)
Start resizing a window.
static Point GetAutoPlacePosition(int width, int height)
Find a good place for opening a new window of a given width and height.
PreventHideDirection
Direction for moving the window.
@ PHD_DOWN
Below v is a safe position.
@ PHD_UP
Above v is a safe position.
static void HandleAutoscroll()
If needed and switched on, perform auto scrolling (automatically moving window contents when mouse is...
bool _window_highlight_colour
If false, highlight is white, otherwise the by the widget defined colour.
void HandleToolbarHotkey(int hotkey)
Handle Toolbar hotkey events - can come from a source like the MacBook Touch Bar.
static int PositionWindow(Window *w, WindowClass clss, int setting)
(Re)position a window at the screen.
void SetFocusedWindow(Window *w)
Set the window that has the focus.
static bool IsGoodAutoPlace1(int left, int top, int width, int height, int toolbar_y, Point &pos)
Decide whether a given rectangle is a good place to open a completely visible new window.
static constexpr int MAX_OFFSET_DOUBLE_CLICK
How much the mouse is allowed to move to call it a double click.
Window * FindWindowByClass(WindowClass cls)
Find any window by its class.
void ChangeVehicleViewports(VehicleID from_index, VehicleID to_index)
Switches viewports following vehicles, which get autoreplaced.
const std::chrono::milliseconds TIME_BETWEEN_DOUBLE_CLICK(500)
Time between 2 left clicks before it becoming a double click.
static EventState HandleViewportScroll()
Handle viewport scrolling with the mouse.
static void DispatchMouseWheelEvent(Window *w, NWidgetCore *nwid, int wheel)
Dispatch the mousewheel-action to the window.
static void DispatchLeftClickEvent(Window *w, int x, int y, int click_count)
Dispatch left mouse-button (possibly double) click in window.
Window * FindWindowFromPt(int x, int y)
Do a search for a window at specific coordinates.
void DeleteAllMessages()
Delete all messages and close their corresponding window (if any).
static Window * _last_scroll_window
Window of the last scroll event.
int GetMainViewTop()
Return the top of the main view available for general use.
static void BringWindowToFront(Window *w, bool dirty=true)
On clicking on a window, make it the frontmost window of all windows with an equal or lower z-priorit...
void ReInitAllWindows(bool zoom_changed)
Re-initialize all windows.
static void EnsureVisibleCaption(Window *w, int nx, int ny)
Make sure at least a part of the caption bar is still visible by moving the window if necessary.
void CloseWindowByClass(WindowClass cls, int data)
Close all windows of a given class.
void HandleMouseEvents()
Handle a mouse event from the video driver.
Point GetToolbarAlignedWindowPosition(int window_width)
Computer the position of the top-left corner of a window to be opened right under the toolbar.
static EventState HandleWindowDragging()
Handle dragging/resizing of a window.
int PositionNewsMessage(Window *w)
(Re)position news message window at the screen.
int GetMainViewBottom()
Return the bottom of the main view available for general use.
static void DispatchHoverEvent(Window *w, int x, int y)
Dispatch hover of the mouse over a window.
void ChangeWindowOwner(Owner old_owner, Owner new_owner)
Change the owner of all the windows one company can take over from another company in the case of a c...
void HandleKeypress(uint keycode, char32_t key)
Handle keyboard input.
void SetWindowClassesDirty(WindowClass cls)
Mark all windows of a particular class as dirty (in need of repainting).
EventState VpHandlePlaceSizingDrag()
Handle the mouse while dragging for placement/resizing.
static constexpr int MAX_OFFSET_HOVER
Maximum mouse movement before stopping a hover event.
bool FocusedWindowIsConsole()
Check if a console is focused.
void ResetWindowSystem()
Reset the windowing system, by means of shutting it down followed by re-initialization.
static uint GetWindowZPriority(WindowClass wc)
Get the z-priority for a given window.
bool EditBoxInGlobalFocus()
Check if an edit box is in global focus.
void InvalidateWindowData(WindowClass cls, WindowNumber number, int data, bool gui_scope)
Mark window data of the window of a given class and specific window number as invalid (in need of re-...
void HideVitalWindows()
Close all always on-top windows to get an empty screen.
static const IntervalTimer< TimerWindow > highlight_interval(TIMER_BLINK_INTERVAL, [](auto) { _window_highlight_colour=!_window_highlight_colour;})
Blink the window highlight colour constantly.
static bool DescSorter(WindowDesc *const &a, WindowDesc *const &b)
Sort WindowDesc by ini_key.
Window * BringWindowToFrontById(WindowClass cls, WindowNumber number)
Find a window and make it the relative top-window on the screen.
Point AlignInitialConstructionToolbar(int window_width)
Compute the position of the construction toolbars.
void RelocateAllWindows(int neww, int newh)
Relocate all windows to fit the new size of the game application screen.
std::string _windows_file
Config file to store WindowDesc.
static void HandleScrollbarScrolling(Window *w)
Handle scrollbar scrolling with the mouse.
bool _mouse_hovering
The mouse is hovering over the same point.
static void StartWindowDrag(Window *w)
Start window dragging.
void CallWindowGameTickEvent()
Dispatch OnGameTick event over all windows.
static EventState HandleActiveWidget()
Handle active widget (mouse dragging on widget) with the mouse.
static void DispatchRightClickEvent(Window *w, int x, int y)
Dispatch right mouse-button click in window.
ViewportAutoscrolling
Values for _settings_client.gui.auto_scrolling.
@ VA_MAIN_VIEWPORT_FULLSCREEN
Scroll main viewport at edge when using fullscreen.
@ VA_MAIN_VIEWPORT
Scroll main viewport at edge.
@ VA_EVERY_VIEWPORT
Scroll all viewports at their edges.
@ VA_DISABLED
Do not autoscroll when mouse is at edge of viewport.
static const int8_t scrollamt[16][2]
Describes all the different arrow key combinations the game allows when it is in scrolling mode.
static bool MaybeBringWindowToFront(Window *w)
Check if a window can be made relative top-most window, and if so do it.
WindowList _z_windows
List of windows opened at the screen sorted from the front to back.
void CallWindowRealtimeTickEvent(uint delta_ms)
Dispatch OnRealtimeTick event over all windows.
SpecialMouseMode _special_mouse_mode
Mode of the mouse.
static EventState HandleMouseDragDrop()
Handle dragging and dropping in mouse dragging mode (WSM_DRAGDROP).
void CloseAllNonVitalWindows()
It is possible that a stickied window gets to a position where the 'close' button is outside the gami...
static void HandleMouseOver()
Report position of the mouse to the underlying window.
static const IntervalTimer< TimerWindow > window_interval(std::chrono::milliseconds(30), [](auto) { extern int _caret_timer;_caret_timer+=3;CursorTick();HandleKeyScrolling();HandleAutoscroll();DecreaseWindowCounters();})
Update various of window-related information on a regular interval.
static Window * _mouseover_last_w
Window of the last OnMouseOver event.
static void CheckSoftLimit()
Check the soft limit of deletable (non vital, non sticky) windows.
Window * FindWindowById(WindowClass cls, WindowNumber number)
Find a window by its class and window number.
void UnInitWindowSystem()
Close down the windowing system.
void InitWindowSystem()
(re)initialize the windowing system
void SetWindowWidgetDirty(WindowClass cls, WindowNumber number, WidgetID widget_index)
Mark a particular widget in a particular window as dirty (in need of repainting).
void HandleTextInput(std::string_view str, bool marked, std::optional< size_t > caret, std::optional< size_t > insert_location, std::optional< size_t > replacement_end)
Handle text input.
void SetWindowDirty(WindowClass cls, WindowNumber number)
Mark window as dirty (in need of repainting).
void InvalidateWindowClassesData(WindowClass cls, int data, bool gui_scope)
Mark window data of all windows of a given class as invalid (in need of re-computing) Note that by de...
Window functions not directly related to making/drawing windows.
@ Construction
This window is used for construction; close it whenever changing company.
@ NoClose
This window can't be interactively closed.
@ NoFocus
This window won't get focus/make any other window lose focus when click.
@ Modal
The window is a modal child of some other window, meaning the parent is 'inactive'.
void SetFocusedWindow(Window *w)
Set the window that has the focus.
@ SizingLeft
Window is being resized towards the left.
@ DisableVpScroll
Window does not do autoscroll,.
@ Highlighted
Window has a widget that has a highlight.
@ Centred
Window is centered and shall stay centered after ReInit.
@ Dragging
Window is being dragged.
@ SizingRight
Window is being resized towards the right.
@ WhiteBorder
Window white border counter bit mask.
@ Timeout
Window timeout counter.
@ Sticky
Window is made sticky by user.
static const int TIMEOUT_DURATION
The initial timeout value for WindowFlag::Timeout.
WidgetID GetWidgetFromPos(const Window *w, int x, int y)
Returns the index for the widget located at the given position relative to the window.
SpecialMouseMode
Mouse modes.
@ WSM_DRAGDROP
Drag&drop an object.
@ WSM_PRESIZE
Presizing mode (docks, tunnels).
WindowPosition
How do we the window to be placed?
@ WDP_CENTER
Center the window.
@ WDP_AUTO
Find a place automatically.
@ WDP_ALIGN_TOOLBAR
Align toward the toolbar.
@ WDP_MANUAL
Manually align the window (so no automatic location finding).
WindowList _z_windows
List of windows opened at the screen sorted from the front to back.
EventState
State of handling an event.
@ ES_HANDLED
The passed event is handled.
@ ES_NOT_HANDLED
The passed event is not handled.
static constexpr WidgetID INVALID_WIDGET
An invalid widget index.
@ WC_INVALID
Invalid window.
@ WC_OSK
On Screen Keyboard; Window numbers:
@ WC_CONSOLE
Console; Window numbers:
@ WC_NEWS_WINDOW
News window; Window numbers:
@ WC_HIGHSCORE
Highscore; Window numbers:
@ WC_BUY_COMPANY
Buyout company (merger); Window numbers:
@ WC_SPRITE_ALIGNER
Sprite aligner (debug); Window numbers:
@ WC_COMPANY_INFRASTRUCTURE
Company infrastructure overview; Window numbers:
@ WC_ENDSCREEN
Endscreen; Window numbers:
@ WC_COMPANY_COLOUR
Company colour selection; Window numbers:
@ WC_STATION_LIST
Station list; Window numbers:
@ WC_ROADVEH_LIST
Road vehicle list; Window numbers:
@ WC_STATUS_BAR
Statusbar (at the bottom of your screen); Window numbers:
@ WC_VEHICLE_ORDERS
Vehicle orders; Window numbers:
@ WC_SEND_NETWORK_MSG
Chatbox; Window numbers:
@ WC_ERRMSG
Error message; Window numbers:
@ WC_BUILD_TOOLBAR
Build toolbar; Window numbers:
@ WC_NETWORK_ASK_RELAY
Network ask relay window; Window numbers:
@ WC_SCRIPT_SETTINGS
Script settings; Window numbers:
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
@ WC_SCEN_LAND_GEN
Landscape generation (in Scenario Editor); Window numbers:
@ WC_SCRIPT_LIST
Scripts list; Window numbers:
@ WC_SAVE_PRESET
Save preset; Window numbers:
@ WC_SHIPS_LIST
Ships list; Window numbers:
@ WC_MESSAGE_HISTORY
News history list; Window numbers:
@ WC_CONFIRM_POPUP_QUERY
Popup with confirm question; Window numbers:
@ WC_GENERATE_LANDSCAPE
Generate landscape (newgame); Window numbers:
@ WC_CUSTOM_CURRENCY
Custom currency; Window numbers:
@ WC_MAIN_WINDOW
Main window; Window numbers:
@ WC_TRAINS_LIST
Trains list; Window numbers:
@ WC_GAME_OPTIONS
Game options window; Window numbers:
@ WC_NETWORK_WINDOW
Network window; Window numbers:
@ WC_FINANCES
Finances of a company; Window numbers:
@ WC_TEXTFILE
textfile; Window numbers:
@ WC_DROPDOWN_MENU
Drop down menu; Window numbers:
@ WC_QUERY_STRING
Query string window; Window numbers:
@ WC_SMALLMAP
Small map; Window numbers:
@ WC_BOOTSTRAP
Bootstrap; Window numbers:
@ WC_SAVELOAD
Saveload window; Window numbers:
@ WC_GRF_PARAMETERS
NewGRF parameters; Window numbers:
@ WC_MODAL_PROGRESS
Progress report of landscape generation; Window numbers:
@ WC_MAIN_TOOLBAR
Main toolbar (the long bar at the top); Window numbers:
@ WC_TOOLTIPS
Tooltip window; Window numbers:
@ WC_COMPANY
Company view; Window numbers:
@ WC_NETWORK_STATUS_WINDOW
Network status window; Window numbers:
@ WC_AIRCRAFT_LIST
Aircraft list; Window numbers:
Functions related to zooming.
int ScaleByZoom(int value, ZoomLevel zoom)
Scale by zoom level, usually shift left (when zoom > ZoomLevel::Min) When shifting right,...