OpenTTD
window_gui.h
Go to the documentation of this file.
1 /*
2  * This file is part of OpenTTD.
3  * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4  * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5  * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
6  */
7 
10 #ifndef WINDOW_GUI_H
11 #define WINDOW_GUI_H
12 
13 #include "vehicle_type.h"
14 #include "viewport_type.h"
15 #include "company_type.h"
16 #include "tile_type.h"
17 #include "widget_type.h"
18 #include "core/smallvec_type.hpp"
19 #include "core/smallmap_type.hpp"
20 #include "string_type.h"
21 
25 enum FrameFlags {
26  FR_NONE = 0,
27  FR_TRANSPARENT = 1 << 0,
28  FR_BORDERONLY = 1 << 4,
29  FR_LOWERED = 1 << 5,
30  FR_DARKENED = 1 << 6,
31 };
32 
34 
35 
37  /* WWT_IMGBTN(_2) */
42 
43  /* WWT_INSET */
47 
52 
53  /* Size of the pure frame bevel without any padding. */
58 
59  /* FrameRect widgets, all text buttons, panel, editbox */
64 
65  /* Extra space at top/bottom of text panels */
68 
69  /* WWT_FRAME */
74 
75  /* WWT_MATRIX */
80 
81  /* WWT_SHADEBOX */
87 
88  /* WWT_STICKYBOX */
94 
95  /* WWT_DEBUGBOX */
101 
102  /* WWT_DEFSIZEBOX */
108 
109  /* WWT_RESIZEBOX */
115 
116  /* WWT_CLOSEBOX */
122 
123  /* WWT_CAPTION */
129 
130  /* Dropdown widget. */
136 
139 };
140 
141 /* widget.cpp */
142 void DrawFrameRect(int left, int top, int right, int bottom, Colours colour, FrameFlags flags);
143 void DrawCaption(const Rect &r, Colours colour, Owner owner, StringID str);
144 
145 /* window.cpp */
146 extern Window *_z_front_window;
147 extern Window *_z_back_window;
148 extern Window *_focused_window;
149 
150 
157 };
158 
159 Point GetToolbarAlignedWindowPosition(int window_width);
160 
161 struct HotkeyList;
162 
167 
168  WindowDesc(WindowPosition default_pos, const char *ini_key, int16 def_width_trad, int16 def_height_trad,
169  WindowClass window_class, WindowClass parent_class, uint32 flags,
170  const NWidgetPart *nwid_parts, int16 nwid_length, HotkeyList *hotkeys = nullptr);
171 
172  ~WindowDesc();
173 
177  const char *ini_key;
178  uint32 flags;
180  int16 nwid_length;
182 
183  bool pref_sticky;
184  int16 pref_width;
185  int16 pref_height;
186 
187  int16 GetDefaultWidth() const;
188  int16 GetDefaultHeight() const;
189 
190  static void LoadFromConfig();
191  static void SaveToConfig();
192 
193 private:
196 
201  WindowDesc(const WindowDesc &other);
202 };
203 
208  WDF_CONSTRUCTION = 1 << 0,
209  WDF_MODAL = 1 << 1,
210  WDF_NO_FOCUS = 1 << 2,
211 };
212 
216 struct ResizeInfo {
217  uint step_width;
218  uint step_height;
219 };
220 
226 };
227 
232  WF_TIMEOUT = 1 << 0,
233 
234  WF_DRAGGING = 1 << 3,
235  WF_SIZING_RIGHT = 1 << 4,
236  WF_SIZING_LEFT = 1 << 5,
238  WF_STICKY = 1 << 6,
240  WF_WHITE_BORDER = 1 << 8,
241  WF_HIGHLIGHTED = 1 << 9,
242  WF_CENTERED = 1 << 10,
243 };
245 
246 static const int TIMEOUT_DURATION = 7;
247 static const int WHITE_BORDER_DURATION = 3;
248 
258  int32 scrollpos_x;
259  int32 scrollpos_y;
262 };
263 
264 struct QueryString;
265 
266 /* misc_gui.cpp */
267 enum TooltipCloseCondition {
268  TCC_RIGHT_CLICK,
269  TCC_HOVER,
270  TCC_NONE,
271 };
272 
277 protected:
278  void InitializeData(WindowNumber window_number);
279  void InitializePositionSize(int x, int y, int min_width, int min_height);
280  virtual void FindWindowPlacementAndResize(int def_width, int def_height);
281 
282  std::vector<int> scheduled_invalidation_data;
283 
284 public:
285  Window(WindowDesc *desc);
286 
287  virtual ~Window();
288 
295  inline void *operator new[](size_t size)
296  {
297  NOT_REACHED();
298  }
299 
305  inline void operator delete(void *ptr)
306  {
307  }
308 
313 
316 
317  int left;
318  int top;
319  int width;
320  int height;
321 
323 
325 
334 
336 
340 
341  template <class NWID>
342  inline const NWID *GetWidget(uint widnum) const;
343  template <class NWID>
344  inline NWID *GetWidget(uint widnum);
345 
346  const Scrollbar *GetScrollbar(uint widnum) const;
347  Scrollbar *GetScrollbar(uint widnum);
348 
349  const QueryString *GetQueryString(uint widnum) const;
350  QueryString *GetQueryString(uint widnum);
351 
352  virtual const char *GetFocusedText() const;
353  virtual const char *GetCaret() const;
354  virtual const char *GetMarkedText(size_t *length) const;
355  virtual Point GetCaretPosition() const;
356  virtual Rect GetTextBoundingRect(const char *from, const char *to) const;
357  virtual const char *GetTextCharacterAtPosition(const Point &pt) const;
358 
359  void InitNested(WindowNumber number = 0);
360  void CreateNestedTree(bool fill_nested = true);
361  void FinishInitNested(WindowNumber window_number = 0);
362 
366  inline void SetTimeout()
367  {
368  this->flags |= WF_TIMEOUT;
369  this->timeout_timer = TIMEOUT_DURATION;
370  }
371 
375  inline void SetWhiteBorder()
376  {
377  this->flags |= WF_WHITE_BORDER;
378  this->white_border_timer = WHITE_BORDER_DURATION;
379  }
380 
381  void DisableAllWidgetHighlight();
382  void SetWidgetHighlight(byte widget_index, TextColour highlighted_colour);
383  bool IsWidgetHighlighted(byte widget_index) const;
384 
392  inline void SetWidgetDisabledState(byte widget_index, bool disab_stat)
393  {
394  assert(widget_index < this->nested_array_size);
395  if (this->nested_array[widget_index] != nullptr) this->GetWidget<NWidgetCore>(widget_index)->SetDisabled(disab_stat);
396  }
397 
402  inline void DisableWidget(byte widget_index)
403  {
404  SetWidgetDisabledState(widget_index, true);
405  }
406 
411  inline void EnableWidget(byte widget_index)
412  {
413  SetWidgetDisabledState(widget_index, false);
414  }
415 
421  inline bool IsWidgetDisabled(byte widget_index) const
422  {
423  assert(widget_index < this->nested_array_size);
424  return this->GetWidget<NWidgetCore>(widget_index)->IsDisabled();
425  }
426 
432  inline bool IsWidgetFocused(byte widget_index) const
433  {
434  return this->nested_focus != nullptr && this->nested_focus->index == widget_index;
435  }
436 
443  inline bool IsWidgetGloballyFocused(byte widget_index) const
444  {
445  return _focused_window == this && IsWidgetFocused(widget_index);
446  }
447 
453  inline void SetWidgetLoweredState(byte widget_index, bool lowered_stat)
454  {
455  assert(widget_index < this->nested_array_size);
456  this->GetWidget<NWidgetCore>(widget_index)->SetLowered(lowered_stat);
457  }
458 
463  inline void ToggleWidgetLoweredState(byte widget_index)
464  {
465  assert(widget_index < this->nested_array_size);
466  bool lowered_state = this->GetWidget<NWidgetCore>(widget_index)->IsLowered();
467  this->GetWidget<NWidgetCore>(widget_index)->SetLowered(!lowered_state);
468  }
469 
474  inline void LowerWidget(byte widget_index)
475  {
476  SetWidgetLoweredState(widget_index, true);
477  }
478 
483  inline void RaiseWidget(byte widget_index)
484  {
485  SetWidgetLoweredState(widget_index, false);
486  }
487 
493  inline bool IsWidgetLowered(byte widget_index) const
494  {
495  assert(widget_index < this->nested_array_size);
496  return this->GetWidget<NWidgetCore>(widget_index)->IsLowered();
497  }
498 
499  void UnfocusFocusedWidget();
500  bool SetFocusedWidget(int widget_index);
501 
502  EventState HandleEditBoxKey(int wid, WChar key, uint16 keycode);
503  virtual void InsertTextString(int wid, const char *str, bool marked, const char *caret, const char *insert_location, const char *replacement_end);
504 
505  void HandleButtonClick(byte widget);
506  int GetRowFromWidget(int clickpos, int widget, int padding, int line_height = -1) const;
507 
508  void RaiseButtons(bool autoraise = false);
509  void CDECL SetWidgetsDisabledState(bool disab_stat, int widgets, ...);
510  void CDECL SetWidgetsLoweredState(bool lowered_stat, int widgets, ...);
511  void SetWidgetDirty(byte widget_index) const;
512 
513  void DrawWidgets() const;
514  void DrawViewport() const;
515  void DrawSortButtonState(int widget, SortButtonState state) const;
516  static int SortButtonWidth();
517 
518  void DeleteChildWindows(WindowClass wc = WC_INVALID) const;
519 
520  void SetDirty() const;
521  void ReInit(int rx = 0, int ry = 0);
522 
524  inline bool IsShaded() const
525  {
526  return this->shade_select != nullptr && this->shade_select->shown_plane == SZSP_HORIZONTAL;
527  }
528 
529  void SetShaded(bool make_shaded);
530 
531  void InvalidateData(int data = 0, bool gui_scope = true);
532  void ProcessScheduledInvalidations();
533  void ProcessHighlightedInvalidations();
534 
535  /*** Event handling ***/
536 
541  virtual void OnInit() { }
542 
543  virtual void ApplyDefaults();
544 
552  virtual Point OnInitialPosition(int16 sm_width, int16 sm_height, int window_number);
553 
558  virtual void OnPaint()
559  {
560  this->DrawWidgets();
561  }
562 
569  virtual void DrawWidget(const Rect &r, int widget) const {}
570 
583  virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) {}
584 
591  virtual void SetStringParameters(int widget) const {}
592 
593  virtual void OnFocus();
594 
595  virtual void OnFocusLost();
596 
604  virtual EventState OnKeyPress(WChar key, uint16 keycode) { return ES_NOT_HANDLED; }
605 
606  virtual EventState OnHotkey(int hotkey);
607 
614 
615 
622  virtual void OnClick(Point pt, int widget, int click_count) {}
623 
631  virtual bool OnRightClick(Point pt, int widget) { return false; }
632 
638  virtual void OnHover(Point pt, int widget) {}
639 
646  virtual bool OnTooltip(Point pt, int widget, TooltipCloseCondition close_cond) { return false; }
647 
653  virtual void OnMouseDrag(Point pt, int widget) {}
654 
660  virtual void OnDragDrop(Point pt, int widget) {}
661 
666  virtual void OnScroll(Point delta) {}
667 
674  virtual void OnMouseOver(Point pt, int widget) {}
675 
680  virtual void OnMouseWheel(int wheel) {}
681 
682 
686  virtual void OnMouseLoop() {}
687 
691  virtual void OnGameTick() {}
692 
696  virtual void OnHundredthTick() {}
697 
701  virtual void OnRealtimeTick(uint delta_ms) {}
702 
706  virtual void OnTimeout() {}
707 
708 
713  virtual void OnResize() {}
714 
720  virtual void OnDropdownSelect(int widget, int index) {}
721 
722  virtual void OnDropdownClose(Point pt, int widget, int index, bool instant_close);
723 
728  virtual void OnEditboxChanged(int widget) {}
729 
736  virtual void OnQueryTextFinished(char *str) {}
737 
743  virtual void OnInvalidateData(int data = 0, bool gui_scope = true) {}
744 
751  virtual void OnPlaceObject(Point pt, TileIndex tile) {}
752 
758  virtual bool OnVehicleSelect(const struct Vehicle *v) { return false; }
759 
763  virtual void OnPlaceObjectAbort() {}
764 
765 
773  virtual void OnPlaceDrag(ViewportPlaceMethod select_method, ViewportDragDropSelectionProcess select_proc, Point pt) {}
774 
784  virtual void OnPlaceMouseUp(ViewportPlaceMethod select_method, ViewportDragDropSelectionProcess select_proc, Point pt, TileIndex start_tile, TileIndex end_tile) {}
785 
793  virtual void OnPlacePresize(Point pt, TileIndex tile) {}
794 
795  /*** End of the event handling ***/
796 
801  virtual bool IsNewGRFInspectable() const { return false; }
802 
809  virtual void ShowNewGRFInspectWindow() const { NOT_REACHED(); }
810 };
811 
818 template <class NWID>
819 inline NWID *Window::GetWidget(uint widnum)
820 {
821  if (widnum >= this->nested_array_size || this->nested_array[widnum] == nullptr) return nullptr;
822  NWID *nwid = dynamic_cast<NWID *>(this->nested_array[widnum]);
823  assert(nwid != nullptr);
824  return nwid;
825 }
826 
828 template <>
829 inline const NWidgetBase *Window::GetWidget<NWidgetBase>(uint widnum) const
830 {
831  if (widnum >= this->nested_array_size) return nullptr;
832  return this->nested_array[widnum];
833 }
834 
841 template <class NWID>
842 inline const NWID *Window::GetWidget(uint widnum) const
843 {
844  return const_cast<Window *>(this)->GetWidget<NWID>(widnum);
845 }
846 
847 
851 class PickerWindowBase : public Window {
852 
853 public:
854  PickerWindowBase(WindowDesc *desc, Window *parent) : Window(desc)
855  {
856  this->parent = parent;
857  }
858 
859  virtual ~PickerWindowBase();
860 };
861 
863 Window *FindWindowFromPt(int x, int y);
864 
873 template <typename Wcls>
874 Wcls *AllocateWindowDescFront(WindowDesc *desc, int window_number, bool return_existing = false)
875 {
876  Wcls *w = static_cast<Wcls *>(BringWindowToFrontById(desc->cls, window_number));
877  if (w != nullptr) return return_existing ? w : nullptr;
878  return new Wcls(desc, window_number);
879 }
880 
881 void RelocateAllWindows(int neww, int newh);
882 
883 void GuiShowTooltips(Window *parent, StringID str, uint paramcount = 0, const uint64 params[] = nullptr, TooltipCloseCondition close_tooltip = TCC_HOVER);
884 
885 /* widget.cpp */
886 int GetWidgetFromPos(const Window *w, int x, int y);
887 
889 #define FOR_ALL_WINDOWS_FROM_BACK_FROM(w, start) for (w = start; w != nullptr; w = w->z_front) if (w->window_class != WC_INVALID)
890 #define FOR_ALL_WINDOWS_FROM_FRONT_FROM(w, start) for (w = start; w != nullptr; w = w->z_back) if (w->window_class != WC_INVALID)
891 #define FOR_ALL_WINDOWS_FROM_BACK(w) FOR_ALL_WINDOWS_FROM_BACK_FROM(w, _z_back_window)
892 #define FOR_ALL_WINDOWS_FROM_FRONT(w) FOR_ALL_WINDOWS_FROM_FRONT_FROM(w, _z_front_window)
893 
894 extern Point _cursorpos_drag_start;
895 
896 extern int _scrollbar_start_pos;
897 extern int _scrollbar_size;
898 extern byte _scroller_click_timeout;
899 
900 extern bool _scrolling_viewport;
901 extern bool _mouse_hovering;
902 
909 };
911 
912 void SetFocusedWindow(Window *w);
913 
914 void ScrollbarClickHandler(Window *w, NWidgetCore *nw, int x, int y);
915 
916 #endif /* WINDOW_GUI_H */
EventState
State of handling an event.
Definition: window_type.h:711
ViewportDragDropSelectionProcess
Drag and drop selection process, or, what to do with an area of land when you&#39;ve selected it...
Owner
Enum for all companies/owners.
Definition: company_type.h:18
virtual void OnQueryTextFinished(char *str)
The query window opened from this window has closed.
Definition: window_gui.h:736
SpecialMouseMode
Mouse modes.
Definition: window_gui.h:904
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...
Definition: window_gui.h:793
Left offset of sticky sprite.
Definition: window_gui.h:90
Window * _z_front_window
List of windows opened at the screen sorted from the front.
Definition: window.cpp:57
DECLARE_ENUM_AS_BIT_SET(GenderEthnicity) enum CompanyManagerFaceVariable
Bitgroups of the CompanyManagerFace variable.
virtual void OnScroll(Point delta)
Handle the request for (viewport) scrolling.
Definition: window_gui.h:666
ResizeInfo resize
Resize information.
Definition: window_gui.h:322
void SetWidgetDisabledState(byte widget_index, bool disab_stat)
Sets the enabled/disabled status of a widget.
Definition: window_gui.h:392
Offset at right of a matrix cell.
Definition: window_gui.h:77
No special mouse mode.
Definition: window_gui.h:905
const NWidgetCore * nested_focus
Currently focused nested widget, or nullptr if no nested widget has focus.
Definition: window_gui.h:327
void SetWidgetLoweredState(byte widget_index, bool lowered_stat)
Sets the lowered/raised status of a widget.
Definition: window_gui.h:453
void SetTimeout()
Set the timeout flag of the window and initiate the timer.
Definition: window_gui.h:366
Right offset of closebox string.
Definition: window_gui.h:119
Window * parent
Parent window.
Definition: window_gui.h:337
High level window description.
Definition: window_gui.h:166
void DrawFrameRect(int left, int top, int right, int bottom, Colours colour, FrameFlags flags)
Draw frame rectangle.
Definition: widget.cpp:175
virtual void OnDragDrop(Point pt, int widget)
A dragged &#39;object&#39; has been released.
Definition: window_gui.h:660
Window is being resized towards the right.
Definition: window_gui.h:235
Simple vector class that allows allocating an item without the need to copy this->data needlessly...
WindowFlags flags
Window flags.
Definition: window_gui.h:310
int left
x position of left edge of the window
Definition: window_gui.h:317
Width of left bevel border.
Definition: window_gui.h:54
Left offset of scrollbar.
Definition: window_gui.h:48
Right offset of debug sprite.
Definition: window_gui.h:98
virtual bool OnTooltip(Point pt, int widget, TooltipCloseCondition close_cond)
Event to display a custom tooltip.
Definition: window_gui.h:646
bool _scrolling_viewport
A viewport is being scrolled with the mouse.
Definition: window.cpp:77
int16 pref_height
User-preferred height of the window. Zero if unset.
Definition: window_gui.h:185
Height of a drop down widget.
Definition: window_gui.h:131
Scrollbar data structure.
Definition: widget_type.h:587
Stacked widgets, widgets all occupying the same space in the window.
Definition: widget_type.h:403
Top offset of scrollbar.
Definition: window_gui.h:50
Offset at top to draw the frame rectangular area.
Definition: window_gui.h:62
Normal amount of vertical space between two paragraphs of text.
Definition: window_gui.h:137
Dragging an object.
Definition: window_gui.h:906
The passed event is not handled.
Definition: window_type.h:713
Dimension unshaded_size
Last known unshaded size (only valid while shaded).
Definition: window_gui.h:333
Bottom offset of shade sprite.
Definition: window_gui.h:86
void ScrollbarClickHandler(Window *w, NWidgetCore *nw, int x, int y)
Special handling for the scrollbar widget type.
Definition: widget.cpp:136
Left offset of shade sprite.
Definition: window_gui.h:83
Implementation of simple mapping class.
Definitions about widgets.
If set the background is darker, allows for lowered frames with normal background colour when used wi...
Definition: window_gui.h:30
SpecialMouseMode _special_mouse_mode
Mode of the mouse.
Definition: window.cpp:80
Vehicle data structure.
Definition: vehicle_base.h:210
int top
y position of top edge of the window
Definition: window_gui.h:318
void ToggleWidgetLoweredState(byte widget_index)
Invert the lowered/raised status of a widget.
Definition: window_gui.h:463
virtual void OnEditboxChanged(int widget)
The text in an editbox has been edited.
Definition: window_gui.h:728
Width of right bevel border.
Definition: window_gui.h:55
Offset at top of a matrix cell.
Definition: window_gui.h:78
NWidgetStacked * shade_select
Selection widget (NWID_SELECTION) to use for shading the window. If nullptr, window cannot shade...
Definition: window_gui.h:332
Width of a standard defsize box widget.
Definition: window_gui.h:103
virtual void OnMouseLoop()
Called for every mouse loop run, which is at least once per (game) tick.
Definition: window_gui.h:686
Bottom offset of defsize sprite.
Definition: window_gui.h:107
WindowClass
Window classes.
Definition: window_type.h:37
void DisableWidget(byte widget_index)
Sets a widget to disabled.
Definition: window_gui.h:402
int16 default_width_trad
Preferred initial width of the window (pixels at 1x zoom).
Definition: window_gui.h:194
static const int TIMEOUT_DURATION
The initial timeout value for WF_TIMEOUT.
Definition: window_gui.h:246
virtual void OnPlaceDrag(ViewportPlaceMethod select_method, ViewportDragDropSelectionProcess select_proc, Point pt)
The user is dragging over the map when the tile highlight mode has been set.
Definition: window_gui.h:773
Invalid window.
Definition: window_type.h:694
Top offset of debug sprite.
Definition: window_gui.h:99
virtual void OnPlaceObjectAbort()
The user cancelled a tile highlight mode that has been set.
Definition: window_gui.h:763
Left offset of debug sprite.
Definition: window_gui.h:97
void RaiseWidget(byte widget_index)
Marks a widget as raised.
Definition: window_gui.h:483
WindowClass cls
Class of the window,.
Definition: window_gui.h:175
Window is made sticky by user.
Definition: window_gui.h:238
Presizing mode (docks, tunnels).
Definition: window_gui.h:908
virtual void OnTimeout()
Called when this window&#39;s timeout has been reached.
Definition: window_gui.h:706
Window is being resized towards the left.
Definition: window_gui.h:236
Large amount of vertical space between two paragraphs of text.
Definition: window_gui.h:138
virtual bool OnVehicleSelect(const struct Vehicle *v)
The user clicked on a vehicle while HT_VEHICLE has been set.
Definition: window_gui.h:758
virtual bool IsNewGRFInspectable() const
Is the data related to this window NewGRF inspectable?
Definition: window_gui.h:801
FrameFlags
Flags to describe the look of the frame.
Definition: window_gui.h:25
Width of a close box widget.
Definition: window_gui.h:117
Simple mapping class targeted for small sets of data.
static const int WHITE_BORDER_DURATION
The initial timeout value for WF_WHITE_BORDER.
Definition: window_gui.h:247
Partial widget specification to allow NWidgets to be written nested.
Definition: widget_type.h:908
virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
Update size and resize step of a widget in the window.
Definition: window_gui.h:583
Types related to viewports.
const char * ini_key
Key to store window defaults in openttd.cfg. nullptr if nothing shall be stored.
Definition: window_gui.h:177
Data structure for an opened window.
Definition: window_gui.h:276
Bottom offset of image in the button.
Definition: window_gui.h:41
WidgetDrawDistances
Distances used in drawing widgets.
Definition: window_gui.h:36
Bottom offset of the text of the frame.
Definition: window_gui.h:73
void SetFocusedWindow(Window *w)
Set the window that has the focus.
Definition: window.cpp:434
int16 GetDefaultHeight() const
Determine default height of window.
Definition: window.cpp:133
int16 default_height_trad
Preferred initial height of the window (pixels at 1x zoom).
Definition: window_gui.h:195
NWidgetBase ** nested_array
Array of pointers into the tree. Do not access directly, use Window::GetWidget() instead.
Definition: window_gui.h:330
Data structure for resizing a window.
Definition: window_gui.h:216
Right offset of resize sprite.
Definition: window_gui.h:112
Point GetToolbarAlignedWindowPosition(int window_width)
Computer the position of the top-left corner of a window to be opened right under the toolbar...
Definition: window.cpp:1732
Width of a standard shade box widget.
Definition: window_gui.h:82
Offset at bottom of a matrix cell.
Definition: window_gui.h:79
Right offset of defsize sprite.
Definition: window_gui.h:105
virtual EventState OnKeyPress(WChar key, uint16 keycode)
A key has been pressed.
Definition: window_gui.h:604
virtual void OnInit()
Notification that the nested widget tree gets initialized.
Definition: window_gui.h:541
This window is used for construction; close it whenever changing company.
Definition: window_gui.h:208
void GuiShowTooltips(Window *parent, StringID str, uint paramcount=0, const uint64 params[]=nullptr, TooltipCloseCondition close_tooltip=TCC_HOVER)
Shows a tooltip.
Definition: misc_gui.cpp:764
bool IsWidgetLowered(byte widget_index) const
Gets the lowered state of a widget.
Definition: window_gui.h:493
int16 GetDefaultWidth() const
Determine default width of window.
Definition: window.cpp:123
Window * _z_back_window
List of windows opened at the screen sorted from the back.
Definition: window.cpp:59
Sort descending.
Definition: window_gui.h:225
uint32 VehicleID
The type all our vehicle IDs have.
Definition: vehicle_type.h:16
Window is being dragged.
Definition: window_gui.h:234
ViewportPlaceMethod
Viewport place method (type of highlighted area and placed objects)
Definition: viewport_type.h:96
SmallMap< int, QueryString * > querystrings
QueryString associated to WWT_EDITBOX widgets.
Definition: window_gui.h:328
virtual void DrawWidget(const Rect &r, int widget) const
Draw the contents of a nested widget.
Definition: window_gui.h:569
Data stored about a string that can be modified in the GUI.
Display plane with zero size vertically, and filling and resizing horizontally.
Definition: widget_type.h:387
Left offset of string.
Definition: window_gui.h:44
Bottom offset of resize sprite.
Definition: window_gui.h:114
WindowPosition default_pos
Preferred position of the window.
Definition: window_gui.h:174
Window is centered and shall stay centered after ReInit.
Definition: window_gui.h:242
Height of bottom bevel border.
Definition: window_gui.h:57
void SetWhiteBorder()
Set the timeout flag of the window and initiate the timer.
Definition: window_gui.h:375
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
Definition: gfx_type.h:245
List of hotkeys for a window.
Definition: hotkeys.h:40
void DrawCaption(const Rect &r, Colours colour, Owner owner, StringID str)
Draw a caption bar.
Definition: widget.cpp:538
Wcls * AllocateWindowDescFront(WindowDesc *desc, int window_number, bool return_existing=false)
Open a new window.
Definition: window_gui.h:874
int GetWidgetFromPos(const Window *w, int x, int y)
Returns the index for the widget located at the given position relative to the window.
Definition: widget.cpp:160
Left offset of defsize sprite.
Definition: window_gui.h:104
Height of a title bar.
Definition: window_gui.h:124
static void SaveToConfig()
Save all WindowDesc settings to _windows_file.
Definition: window.cpp:164
bool IsWidgetDisabled(byte widget_index) const
Gets the enabled/disabled status of a widget.
Definition: window_gui.h:421
Offset at bottom to draw below the text.
Definition: window_gui.h:67
uint nested_array_size
Size of the nested array.
Definition: window_gui.h:331
const NWidgetPart * nwid_parts
Nested widget parts describing the window.
Definition: window_gui.h:179
WindowDefaultFlag
Window default widget/window handling flags.
Definition: window_gui.h:207
virtual void OnHover(Point pt, int widget)
The mouse is hovering over a widget in the window, perform an action for it.
Definition: window_gui.h:638
Window timeout counter.
Definition: window_gui.h:232
Data structure for a window viewport.
Definition: window_gui.h:256
int16 nwid_length
Length of the nwid_parts array.
Definition: window_gui.h:180
int32 scrollpos_x
Currently shown x coordinate (virtual screen coordinate of topleft corner of the viewport).
Definition: window_gui.h:258
uint step_height
Step-size of height resize changes.
Definition: window_gui.h:218
void LowerWidget(byte widget_index)
Marks a widget as lowered.
Definition: window_gui.h:474
Offset at left of a matrix cell.
Definition: window_gui.h:76
virtual void OnMouseOver(Point pt, int widget)
The mouse is currently moving over the window or has just moved outside of the window.
Definition: window_gui.h:674
Top offset of resize sprite.
Definition: window_gui.h:113
virtual void OnDropdownSelect(int widget, int index)
A dropdown option associated to this window has been selected.
Definition: window_gui.h:720
Center the window.
Definition: window_gui.h:155
WindowDesc(WindowPosition default_pos, const char *ini_key, int16 def_width_trad, int16 def_height_trad, WindowClass window_class, WindowClass parent_class, uint32 flags, const NWidgetPart *nwid_parts, int16 nwid_length, HotkeyList *hotkeys=nullptr)
Window description constructor.
Definition: window.cpp:92
SortButtonState
State of a sort direction button.
Definition: window_gui.h:222
Right offset of sticky sprite.
Definition: window_gui.h:91
Offset at bottom to draw the frame rectangular area.
Definition: window_gui.h:63
Sizing mode.
Definition: window_gui.h:907
Baseclass for nested widgets.
Definition: widget_type.h:124
uint8 white_border_timer
Timer value of the WF_WHITE_BORDER for flags.
Definition: window_gui.h:315
Offset of the caption text at the left.
Definition: window_gui.h:125
Right offset of the text of the frame.
Definition: window_gui.h:71
VehicleID follow_vehicle
VehicleID to follow if following a vehicle, INVALID_VEHICLE otherwise.
Definition: window_gui.h:257
Right offset of the image in the button.
Definition: window_gui.h:39
Top offset of the text of the frame.
Definition: window_gui.h:72
Left offset of the text of the frame.
Definition: window_gui.h:70
Top offset of defsize sprite.
Definition: window_gui.h:106
Window has a widget that has a highlight.
Definition: window_gui.h:241
Base class that provides memory initialization on dynamically created objects.
Definition: alloc_type.hpp:85
bool pref_sticky
Preferred stickyness.
Definition: window_gui.h:183
WindowFlags
Window flags.
Definition: window_gui.h:231
uint32 StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:16
Window is being resized.
Definition: window_gui.h:237
Window * FindWindowFromPt(int x, int y)
Do a search for a window at specific coordinates.
Definition: window.cpp:1878
Left offset of resize sprite.
Definition: window_gui.h:111
Bottom offset of closebox string.
Definition: window_gui.h:121
int32 dest_scrollpos_y
Current destination y coordinate to display (virtual screen coordinate of topleft corner of the viewp...
Definition: window_gui.h:261
Draw border only, no background.
Definition: window_gui.h:28
Offset at top to draw above the text.
Definition: window_gui.h:66
The window is a modal child of some other window, meaning the parent is &#39;inactive&#39;.
Definition: window_gui.h:209
uint32 flags
Flags.
Definition: window_gui.h:178
bool IsWidgetGloballyFocused(byte widget_index) const
Check if given widget has user input focus.
Definition: window_gui.h:443
Offset of the caption text at the top.
Definition: window_gui.h:127
Window * z_back
The window behind us in z-order.
Definition: window_gui.h:339
Width of a standard debug box widget.
Definition: window_gui.h:96
void RelocateAllWindows(int neww, int newh)
Relocate all windows to fit the new size of the game application screen.
Definition: window.cpp:3564
virtual bool OnRightClick(Point pt, int widget)
A click with the right mouse button has been made on the window.
Definition: window_gui.h:631
Top offset of shade sprite.
Definition: window_gui.h:85
Width of a standard sticky box widget.
Definition: window_gui.h:89
Bottom offset of scrollbar.
Definition: window_gui.h:51
virtual void OnPaint()
The window must be repainted.
Definition: window_gui.h:558
int32 dest_scrollpos_x
Current destination x coordinate to display (virtual screen coordinate of topleft corner of the viewp...
Definition: window_gui.h:260
Height of top bevel border.
Definition: window_gui.h:56
Align toward the toolbar.
Definition: window_gui.h:156
Data structure for viewport, display of a part of the world.
Definition: viewport_type.h:22
If set the frame is lowered and the background colour brighter (ie. buttons when pressed) ...
Definition: window_gui.h:29
Bottom offset of sticky sprite.
Definition: window_gui.h:93
Offset of the caption text at the bottom.
Definition: window_gui.h:128
Bottom offset of debug sprite.
Definition: window_gui.h:100
uint32 TileIndex
The index/ID of a Tile.
Definition: tile_type.h:78
Window * z_front
The window in front of us in z-order.
Definition: window_gui.h:338
WindowClass parent_cls
Class of the parent window.
Definition: window_gui.h:176
virtual EventState OnCTRLStateChange()
The state of the control key has changed.
Definition: window_gui.h:613
virtual void ShowNewGRFInspectWindow() const
Show the NewGRF inspection window.
Definition: window_gui.h:809
virtual void SetStringParameters(int widget) const
Initialize string parameters for a widget.
Definition: window_gui.h:591
This window won&#39;t get focus/make any other window lose focus when click.
Definition: window_gui.h:210
Sort ascending.
Definition: window_gui.h:224
static void LoadFromConfig()
Load all WindowDesc settings from _windows_file.
Definition: window.cpp:141
int index
Index of the nested widget in the widget array of the window (-1 means &#39;not used&#39;).
Definition: widget_type.h:302
Top offset of image in the button.
Definition: window_gui.h:40
Types related to vehicles.
virtual void OnGameTick()
Called once per (game) tick.
Definition: window_gui.h:691
int shown_plane
Plane being displayed (for NWID_SELECTION only).
Definition: widget_type.h:418
Right offset of string.
Definition: window_gui.h:45
Top offset of sticky sprite.
Definition: window_gui.h:92
virtual void OnRealtimeTick(uint delta_ms)
Called periodically.
Definition: window_gui.h:701
uint step_width
Step-size of width resize changes.
Definition: window_gui.h:217
HotkeyList * hotkeys
Hotkeys for the window.
Definition: window_gui.h:181
Bottom offset of the dropdown widget string.
Definition: window_gui.h:135
Right offset of scrollbar.
Definition: window_gui.h:49
Coordinates of a point in 2D.
int16 pref_width
User-preferred width of the window. Zero if unset.
Definition: window_gui.h:184
Types related to companies.
Window does not do autoscroll,.
Definition: window_gui.h:239
Owner owner
The owner of the content shown in this window. Company colour is acquired from this variable...
Definition: window_gui.h:324
virtual void OnMouseDrag(Point pt, int widget)
An &#39;object&#39; is being dragged at the provided position, highlight the target if possible.
Definition: window_gui.h:653
Right offset of shade sprite.
Definition: window_gui.h:84
Width of a resize box widget.
Definition: window_gui.h:110
Offset at right to draw the frame rectangular area.
Definition: window_gui.h:61
virtual void OnClick(Point pt, int widget, int click_count)
A click with the left mouse button has been made on the window.
Definition: window_gui.h:622
int width
width of the window (number of pixels to the right in x direction)
Definition: window_gui.h:319
Types for strings.
virtual void OnResize()
Called after the window got resized.
Definition: window_gui.h:713
int32 WindowNumber
Number to differentiate different windows of the same class.
Definition: window_type.h:705
WindowClass window_class
Window class.
Definition: window_gui.h:311
virtual void OnMouseWheel(int wheel)
The mouse wheel has been turned.
Definition: window_gui.h:680
Specification of a rectangle with absolute coordinates of all edges.
virtual void OnPlaceObject(Point pt, TileIndex tile)
The user clicked some place on the map when a tile highlight mode has been set.
Definition: window_gui.h:751
bool IsShaded() const
Is window shaded currently?
Definition: window_gui.h:524
WindowNumber window_number
Window number within the window class.
Definition: window_gui.h:312
std::vector< int > scheduled_invalidation_data
Data of scheduled OnInvalidateData() calls.
Definition: window_gui.h:282
Left offset of the dropdown widget string.
Definition: window_gui.h:132
Find a place automatically.
Definition: window_gui.h:154
Types related to tiles.
Manually align the window (so no automatic location finding)
Definition: window_gui.h:153
virtual void OnHundredthTick()
Called once every 100 (game) ticks.
Definition: window_gui.h:696
Makes the background transparent if set.
Definition: window_gui.h:27
ViewportData * viewport
Pointer to viewport data, if present.
Definition: window_gui.h:326
uint8 timeout_timer
Timer value of the WF_TIMEOUT for flags.
Definition: window_gui.h:314
uint32 WChar
Type for wide characters, i.e.
Definition: string_type.h:35
bool IsWidgetFocused(byte widget_index) const
Check if given widget is focused within this window.
Definition: window_gui.h:432
const NWID * GetWidget(uint widnum) const
Get the nested widget with number widnum from the nested widget tree.
Definition: window_gui.h:842
Do not sort (with this button).
Definition: window_gui.h:223
bool _mouse_hovering
The mouse is hovering over the same point.
Definition: window.cpp:78
Window white border counter bit mask.
Definition: window_gui.h:240
Left offset of the image in the button.
Definition: window_gui.h:38
int32 scrollpos_y
Currently shown y coordinate (virtual screen coordinate of topleft corner of the viewport).
Definition: window_gui.h:259
Left offset of closebox string.
Definition: window_gui.h:118
WindowPosition
How do we the window to be placed?
Definition: window_gui.h:152
NWidgetBase * nested_root
Root of the nested tree.
Definition: window_gui.h:329
Dimensions (a width and height) of a rectangle in 2D.
Offset at left to draw the frame rectangular area.
Definition: window_gui.h:60
WindowDesc * window_desc
Window description.
Definition: window_gui.h:309
Base class for windows opened from a toolbar.
Definition: window_gui.h:851
Right offset of the dropdown widget string.
Definition: window_gui.h:133
Top offset of the dropdown widget string.
Definition: window_gui.h:134
Offset of the caption text at the right.
Definition: window_gui.h:126
virtual void OnPlaceMouseUp(ViewportPlaceMethod select_method, ViewportDragDropSelectionProcess select_proc, Point pt, TileIndex start_tile, TileIndex end_tile)
The user has dragged over the map when the tile highlight mode has been set.
Definition: window_gui.h:784
Window * BringWindowToFrontById(WindowClass cls, WindowNumber number)
Find a window and make it the relative top-window on the screen.
Definition: window.cpp:1259
int mouse_capture_widget
Widgetindex of current mouse capture widget (e.g. dragged scrollbar). -1 if no widget has mouse captu...
Definition: window_gui.h:335
Top offset of closebox string.
Definition: window_gui.h:120
int height
Height of the window (number of pixels down in y direction)
Definition: window_gui.h:320
void EnableWidget(byte widget_index)
Sets a widget to Enabled.
Definition: window_gui.h:411
virtual void OnInvalidateData(int data=0, bool gui_scope=true)
Some data on this window has become invalid.
Definition: window_gui.h:743
Top offset of string.
Definition: window_gui.h:46
Base class for a &#39;real&#39; widget.
Definition: widget_type.h:282