OpenTTD
window_gui.h
Go to the documentation of this file.
1 /* $Id$ */
2 
3 /*
4  * This file is part of OpenTTD.
5  * 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.
6  * 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.
7  * 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/>.
8  */
9 
12 #ifndef WINDOW_GUI_H
13 #define WINDOW_GUI_H
14 
15 #include "vehicle_type.h"
16 #include "viewport_type.h"
17 #include "company_type.h"
18 #include "tile_type.h"
19 #include "widget_type.h"
20 #include "core/smallvec_type.hpp"
21 #include "core/smallmap_type.hpp"
22 #include "string_type.h"
23 
27 enum FrameFlags {
28  FR_NONE = 0,
29  FR_TRANSPARENT = 1 << 0,
30  FR_BORDERONLY = 1 << 4,
31  FR_LOWERED = 1 << 5,
32  FR_DARKENED = 1 << 6,
33 };
34 
36 
37 
39  /* WWT_IMGBTN(_2) */
44 
45  /* WWT_INSET */
49 
54 
55  /* Size of the pure frame bevel without any padding. */
60 
61  /* FrameRect widgets, all text buttons, panel, editbox */
66 
67  /* Extra space at top/bottom of text panels */
70 
71  /* WWT_FRAME */
76 
77  /* WWT_MATRIX */
82 
83  /* WWT_SHADEBOX */
89 
90  /* WWT_STICKYBOX */
96 
97  /* WWT_DEBUGBOX */
103 
104  /* WWT_DEFSIZEBOX */
110 
111  /* WWT_RESIZEBOX */
117 
118  /* WWT_CLOSEBOX */
124 
125  /* WWT_CAPTION */
131 
132  /* Dropdown widget. */
138 
141 };
142 
143 /* widget.cpp */
144 void DrawFrameRect(int left, int top, int right, int bottom, Colours colour, FrameFlags flags);
145 void DrawCaption(const Rect &r, Colours colour, Owner owner, StringID str);
146 
147 /* window.cpp */
148 extern Window *_z_front_window;
149 extern Window *_z_back_window;
150 extern Window *_focused_window;
151 
152 
159 };
160 
161 Point GetToolbarAlignedWindowPosition(int window_width);
162 
163 struct HotkeyList;
164 
169 
170  WindowDesc(WindowPosition default_pos, const char *ini_key, int16 def_width_trad, int16 def_height_trad,
171  WindowClass window_class, WindowClass parent_class, uint32 flags,
172  const NWidgetPart *nwid_parts, int16 nwid_length, HotkeyList *hotkeys = NULL);
173 
174  ~WindowDesc();
175 
179  const char *ini_key;
180  uint32 flags;
182  int16 nwid_length;
184 
185  bool pref_sticky;
186  int16 pref_width;
187  int16 pref_height;
188 
189  int16 GetDefaultWidth() const;
190  int16 GetDefaultHeight() const;
191 
192  static void LoadFromConfig();
193  static void SaveToConfig();
194 
195 private:
198 
203  WindowDesc(const WindowDesc &other);
204 };
205 
210  WDF_CONSTRUCTION = 1 << 0,
211  WDF_MODAL = 1 << 1,
212  WDF_NO_FOCUS = 1 << 2,
213 };
214 
218 struct ResizeInfo {
219  uint step_width;
220  uint step_height;
221 };
222 
228 };
229 
234  WF_TIMEOUT = 1 << 0,
235 
236  WF_DRAGGING = 1 << 3,
237  WF_SIZING_RIGHT = 1 << 4,
238  WF_SIZING_LEFT = 1 << 5,
240  WF_STICKY = 1 << 6,
242  WF_WHITE_BORDER = 1 << 8,
243  WF_HIGHLIGHTED = 1 << 9,
244  WF_CENTERED = 1 << 10,
245 };
247 
248 static const int TIMEOUT_DURATION = 7;
249 static const int WHITE_BORDER_DURATION = 3;
250 
260  int32 scrollpos_x;
261  int32 scrollpos_y;
264 };
265 
266 struct QueryString;
267 
268 /* misc_gui.cpp */
269 enum TooltipCloseCondition {
270  TCC_RIGHT_CLICK,
271  TCC_HOVER,
272  TCC_NONE,
273 };
274 
279 protected:
280  void InitializeData(WindowNumber window_number);
281  void InitializePositionSize(int x, int y, int min_width, int min_height);
282  virtual void FindWindowPlacementAndResize(int def_width, int def_height);
283 
285 
286 public:
287  Window(WindowDesc *desc);
288 
289  virtual ~Window();
290 
297  inline void *operator new[](size_t size)
298  {
299  NOT_REACHED();
300  }
301 
307  inline void operator delete(void *ptr)
308  {
309  }
310 
315 
318 
319  int left;
320  int top;
321  int width;
322  int height;
323 
325 
327 
336 
338 
342 
343  template <class NWID>
344  inline const NWID *GetWidget(uint widnum) const;
345  template <class NWID>
346  inline NWID *GetWidget(uint widnum);
347 
348  const Scrollbar *GetScrollbar(uint widnum) const;
349  Scrollbar *GetScrollbar(uint widnum);
350 
351  const QueryString *GetQueryString(uint widnum) const;
352  QueryString *GetQueryString(uint widnum);
353 
354  virtual const char *GetFocusedText() const;
355  virtual const char *GetCaret() const;
356  virtual const char *GetMarkedText(size_t *length) const;
357  virtual Point GetCaretPosition() const;
358  virtual Rect GetTextBoundingRect(const char *from, const char *to) const;
359  virtual const char *GetTextCharacterAtPosition(const Point &pt) const;
360 
361  void InitNested(WindowNumber number = 0);
362  void CreateNestedTree(bool fill_nested = true);
363  void FinishInitNested(WindowNumber window_number = 0);
364 
368  inline void SetTimeout()
369  {
370  this->flags |= WF_TIMEOUT;
371  this->timeout_timer = TIMEOUT_DURATION;
372  }
373 
377  inline void SetWhiteBorder()
378  {
379  this->flags |= WF_WHITE_BORDER;
380  this->white_border_timer = WHITE_BORDER_DURATION;
381  }
382 
383  void DisableAllWidgetHighlight();
384  void SetWidgetHighlight(byte widget_index, TextColour highlighted_colour);
385  bool IsWidgetHighlighted(byte widget_index) const;
386 
394  inline void SetWidgetDisabledState(byte widget_index, bool disab_stat)
395  {
396  assert(widget_index < this->nested_array_size);
397  if (this->nested_array[widget_index] != NULL) this->GetWidget<NWidgetCore>(widget_index)->SetDisabled(disab_stat);
398  }
399 
404  inline void DisableWidget(byte widget_index)
405  {
406  SetWidgetDisabledState(widget_index, true);
407  }
408 
413  inline void EnableWidget(byte widget_index)
414  {
415  SetWidgetDisabledState(widget_index, false);
416  }
417 
423  inline bool IsWidgetDisabled(byte widget_index) const
424  {
425  assert(widget_index < this->nested_array_size);
426  return this->GetWidget<NWidgetCore>(widget_index)->IsDisabled();
427  }
428 
434  inline bool IsWidgetFocused(byte widget_index) const
435  {
436  return this->nested_focus != NULL && this->nested_focus->index == widget_index;
437  }
438 
445  inline bool IsWidgetGloballyFocused(byte widget_index) const
446  {
447  return _focused_window == this && IsWidgetFocused(widget_index);
448  }
449 
455  inline void SetWidgetLoweredState(byte widget_index, bool lowered_stat)
456  {
457  assert(widget_index < this->nested_array_size);
458  this->GetWidget<NWidgetCore>(widget_index)->SetLowered(lowered_stat);
459  }
460 
465  inline void ToggleWidgetLoweredState(byte widget_index)
466  {
467  assert(widget_index < this->nested_array_size);
468  bool lowered_state = this->GetWidget<NWidgetCore>(widget_index)->IsLowered();
469  this->GetWidget<NWidgetCore>(widget_index)->SetLowered(!lowered_state);
470  }
471 
476  inline void LowerWidget(byte widget_index)
477  {
478  SetWidgetLoweredState(widget_index, true);
479  }
480 
485  inline void RaiseWidget(byte widget_index)
486  {
487  SetWidgetLoweredState(widget_index, false);
488  }
489 
495  inline bool IsWidgetLowered(byte widget_index) const
496  {
497  assert(widget_index < this->nested_array_size);
498  return this->GetWidget<NWidgetCore>(widget_index)->IsLowered();
499  }
500 
501  void UnfocusFocusedWidget();
502  bool SetFocusedWidget(int widget_index);
503 
504  EventState HandleEditBoxKey(int wid, WChar key, uint16 keycode);
505  virtual void InsertTextString(int wid, const char *str, bool marked, const char *caret, const char *insert_location, const char *replacement_end);
506 
507  void HandleButtonClick(byte widget);
508  int GetRowFromWidget(int clickpos, int widget, int padding, int line_height = -1) const;
509 
510  void RaiseButtons(bool autoraise = false);
511  void CDECL SetWidgetsDisabledState(bool disab_stat, int widgets, ...);
512  void CDECL SetWidgetsLoweredState(bool lowered_stat, int widgets, ...);
513  void SetWidgetDirty(byte widget_index) const;
514 
515  void DrawWidgets() const;
516  void DrawViewport() const;
517  void DrawSortButtonState(int widget, SortButtonState state) const;
518  static int SortButtonWidth();
519 
520  void DeleteChildWindows(WindowClass wc = WC_INVALID) const;
521 
522  void SetDirty() const;
523  void ReInit(int rx = 0, int ry = 0);
524 
526  inline bool IsShaded() const
527  {
528  return this->shade_select != NULL && this->shade_select->shown_plane == SZSP_HORIZONTAL;
529  }
530 
531  void SetShaded(bool make_shaded);
532 
533  void InvalidateData(int data = 0, bool gui_scope = true);
534  void ProcessScheduledInvalidations();
535  void ProcessHighlightedInvalidations();
536 
537  /*** Event handling ***/
538 
543  virtual void OnInit() { }
544 
545  virtual void ApplyDefaults();
546 
554  virtual Point OnInitialPosition(int16 sm_width, int16 sm_height, int window_number);
555 
560  virtual void OnPaint()
561  {
562  this->DrawWidgets();
563  }
564 
571  virtual void DrawWidget(const Rect &r, int widget) const {}
572 
585  virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) {}
586 
593  virtual void SetStringParameters(int widget) const {}
594 
598  virtual void OnFocus() {}
599 
600  virtual void OnFocusLost();
601 
609  virtual EventState OnKeyPress(WChar key, uint16 keycode) { return ES_NOT_HANDLED; }
610 
611  virtual EventState OnHotkey(int hotkey);
612 
619 
620 
627  virtual void OnClick(Point pt, int widget, int click_count) {}
628 
636  virtual bool OnRightClick(Point pt, int widget) { return false; }
637 
643  virtual void OnHover(Point pt, int widget) {}
644 
651  virtual bool OnTooltip(Point pt, int widget, TooltipCloseCondition close_cond) { return false; }
652 
658  virtual void OnMouseDrag(Point pt, int widget) {}
659 
665  virtual void OnDragDrop(Point pt, int widget) {}
666 
671  virtual void OnScroll(Point delta) {}
672 
679  virtual void OnMouseOver(Point pt, int widget) {}
680 
685  virtual void OnMouseWheel(int wheel) {}
686 
687 
691  virtual void OnMouseLoop() {}
692 
696  virtual void OnGameTick() {}
697 
701  virtual void OnHundredthTick() {}
702 
706  virtual void OnRealtimeTick(uint delta_ms) {}
707 
711  virtual void OnTimeout() {}
712 
713 
718  virtual void OnResize() {}
719 
725  virtual void OnDropdownSelect(int widget, int index) {}
726 
727  virtual void OnDropdownClose(Point pt, int widget, int index, bool instant_close);
728 
733  virtual void OnEditboxChanged(int widget) {}
734 
741  virtual void OnQueryTextFinished(char *str) {}
742 
748  virtual void OnInvalidateData(int data = 0, bool gui_scope = true) {}
749 
756  virtual void OnPlaceObject(Point pt, TileIndex tile) {}
757 
763  virtual bool OnVehicleSelect(const struct Vehicle *v) { return false; }
764 
768  virtual void OnPlaceObjectAbort() {}
769 
770 
778  virtual void OnPlaceDrag(ViewportPlaceMethod select_method, ViewportDragDropSelectionProcess select_proc, Point pt) {}
779 
789  virtual void OnPlaceMouseUp(ViewportPlaceMethod select_method, ViewportDragDropSelectionProcess select_proc, Point pt, TileIndex start_tile, TileIndex end_tile) {}
790 
798  virtual void OnPlacePresize(Point pt, TileIndex tile) {}
799 
800  /*** End of the event handling ***/
801 
806  virtual bool IsNewGRFInspectable() const { return false; }
807 
814  virtual void ShowNewGRFInspectWindow() const { NOT_REACHED(); }
815 };
816 
823 template <class NWID>
824 inline NWID *Window::GetWidget(uint widnum)
825 {
826  if (widnum >= this->nested_array_size || this->nested_array[widnum] == NULL) return NULL;
827  NWID *nwid = dynamic_cast<NWID *>(this->nested_array[widnum]);
828  assert(nwid != NULL);
829  return nwid;
830 }
831 
833 template <>
834 inline const NWidgetBase *Window::GetWidget<NWidgetBase>(uint widnum) const
835 {
836  if (widnum >= this->nested_array_size) return NULL;
837  return this->nested_array[widnum];
838 }
839 
846 template <class NWID>
847 inline const NWID *Window::GetWidget(uint widnum) const
848 {
849  return const_cast<Window *>(this)->GetWidget<NWID>(widnum);
850 }
851 
852 
856 class PickerWindowBase : public Window {
857 
858 public:
859  PickerWindowBase(WindowDesc *desc, Window *parent) : Window(desc)
860  {
861  this->parent = parent;
862  }
863 
864  virtual ~PickerWindowBase();
865 };
866 
868 Window *FindWindowFromPt(int x, int y);
869 
878 template <typename Wcls>
879 Wcls *AllocateWindowDescFront(WindowDesc *desc, int window_number, bool return_existing = false)
880 {
881  Wcls *w = static_cast<Wcls *>(BringWindowToFrontById(desc->cls, window_number));
882  if (w != NULL) return return_existing ? w : NULL;
883  return new Wcls(desc, window_number);
884 }
885 
886 void RelocateAllWindows(int neww, int newh);
887 
888 void GuiShowTooltips(Window *parent, StringID str, uint paramcount = 0, const uint64 params[] = NULL, TooltipCloseCondition close_tooltip = TCC_HOVER);
889 
890 /* widget.cpp */
891 int GetWidgetFromPos(const Window *w, int x, int y);
892 
894 #define FOR_ALL_WINDOWS_FROM_BACK_FROM(w, start) for (w = start; w != NULL; w = w->z_front) if (w->window_class != WC_INVALID)
895 #define FOR_ALL_WINDOWS_FROM_FRONT_FROM(w, start) for (w = start; w != NULL; w = w->z_back) if (w->window_class != WC_INVALID)
896 #define FOR_ALL_WINDOWS_FROM_BACK(w) FOR_ALL_WINDOWS_FROM_BACK_FROM(w, _z_back_window)
897 #define FOR_ALL_WINDOWS_FROM_FRONT(w) FOR_ALL_WINDOWS_FROM_FRONT_FROM(w, _z_front_window)
898 
899 extern Point _cursorpos_drag_start;
900 
901 extern int _scrollbar_start_pos;
902 extern int _scrollbar_size;
903 extern byte _scroller_click_timeout;
904 
905 extern bool _scrolling_viewport;
906 extern bool _mouse_hovering;
907 
914 };
916 
917 void SetFocusedWindow(Window *w);
918 
919 void ScrollbarClickHandler(Window *w, NWidgetCore *nw, int x, int y);
920 
921 #endif /* WINDOW_GUI_H */
EventState
State of handling an event.
Definition: window_type.h:713
ViewportDragDropSelectionProcess
Drag and drop selection process, or, what to do with an area of land when you&#39;ve selected it...
Definition: viewport_type.h:97
virtual void OnQueryTextFinished(char *str)
The query window opened from this window has closed.
Definition: window_gui.h:741
SpecialMouseMode
Mouse modes.
Definition: window_gui.h:909
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:798
Left offset of sticky sprite.
Definition: window_gui.h:92
Window * _z_front_window
List of windows opened at the screen sorted from the front.
Definition: window.cpp:59
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:671
ResizeInfo resize
Resize information.
Definition: window_gui.h:324
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=NULL)
Window description constructor.
Definition: window.cpp:94
void SetWidgetDisabledState(byte widget_index, bool disab_stat)
Sets the enabled/disabled status of a widget.
Definition: window_gui.h:394
Offset at right of a matrix cell.
Definition: window_gui.h:79
No special mouse mode.
Definition: window_gui.h:910
const NWidgetCore * nested_focus
Currently focused nested widget, or NULL if no nested widget has focus.
Definition: window_gui.h:329
void SetWidgetLoweredState(byte widget_index, bool lowered_stat)
Sets the lowered/raised status of a widget.
Definition: window_gui.h:455
void SetTimeout()
Set the timeout flag of the window and initiate the timer.
Definition: window_gui.h:368
Right offset of closebox string.
Definition: window_gui.h:121
Window * parent
Parent window.
Definition: window_gui.h:339
High level window description.
Definition: window_gui.h:168
void DrawFrameRect(int left, int top, int right, int bottom, Colours colour, FrameFlags flags)
Draw frame rectangle.
Definition: widget.cpp:177
virtual void OnDragDrop(Point pt, int widget)
A dragged &#39;object&#39; has been released.
Definition: window_gui.h:665
Window is being resized towards the right.
Definition: window_gui.h:237
Simple vector class that allows allocating an item without the need to copy this->data needlessly...
WindowFlags flags
Window flags.
Definition: window_gui.h:312
int left
x position of left edge of the window
Definition: window_gui.h:319
Width of left bevel border.
Definition: window_gui.h:56
Left offset of scrollbar.
Definition: window_gui.h:50
Right offset of debug sprite.
Definition: window_gui.h:100
virtual bool OnTooltip(Point pt, int widget, TooltipCloseCondition close_cond)
Event to display a custom tooltip.
Definition: window_gui.h:651
bool _scrolling_viewport
A viewport is being scrolled with the mouse.
Definition: window.cpp:79
int16 pref_height
User-preferred height of the window. Zero if unset.
Definition: window_gui.h:187
Height of a drop down widget.
Definition: window_gui.h:133
Scrollbar data structure.
Definition: widget_type.h:589
Stacked widgets, widgets all occupying the same space in the window.
Definition: widget_type.h:405
Top offset of scrollbar.
Definition: window_gui.h:52
Offset at top to draw the frame rectangular area.
Definition: window_gui.h:64
Normal amount of vertical space between two paragraphs of text.
Definition: window_gui.h:139
Dragging an object.
Definition: window_gui.h:911
The passed event is not handled.
Definition: window_type.h:715
Dimension unshaded_size
Last known unshaded size (only valid while shaded).
Definition: window_gui.h:335
Bottom offset of shade sprite.
Definition: window_gui.h:88
void ScrollbarClickHandler(Window *w, NWidgetCore *nw, int x, int y)
Special handling for the scrollbar widget type.
Definition: widget.cpp:138
Left offset of shade sprite.
Definition: window_gui.h:85
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:32
SpecialMouseMode _special_mouse_mode
Mode of the mouse.
Definition: window.cpp:82
Vehicle data structure.
Definition: vehicle_base.h:212
int top
y position of top edge of the window
Definition: window_gui.h:320
void ToggleWidgetLoweredState(byte widget_index)
Invert the lowered/raised status of a widget.
Definition: window_gui.h:465
virtual void OnEditboxChanged(int widget)
The text in an editbox has been edited.
Definition: window_gui.h:733
Width of right bevel border.
Definition: window_gui.h:57
Offset at top of a matrix cell.
Definition: window_gui.h:80
NWidgetStacked * shade_select
Selection widget (NWID_SELECTION) to use for shading the window. If NULL, window cannot shade...
Definition: window_gui.h:334
Width of a standard defsize box widget.
Definition: window_gui.h:105
virtual void OnMouseLoop()
Called for every mouse loop run, which is at least once per (game) tick.
Definition: window_gui.h:691
Bottom offset of defsize sprite.
Definition: window_gui.h:109
WindowClass
Window classes.
Definition: window_type.h:39
void DisableWidget(byte widget_index)
Sets a widget to disabled.
Definition: window_gui.h:404
int16 default_width_trad
Preferred initial width of the window (pixels at 1x zoom).
Definition: window_gui.h:196
static const int TIMEOUT_DURATION
The initial timeout value for WF_TIMEOUT.
Definition: window_gui.h:248
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:778
Invalid window.
Definition: window_type.h:696
Top offset of debug sprite.
Definition: window_gui.h:101
virtual void OnPlaceObjectAbort()
The user cancelled a tile highlight mode that has been set.
Definition: window_gui.h:768
Left offset of debug sprite.
Definition: window_gui.h:99
void RaiseWidget(byte widget_index)
Marks a widget as raised.
Definition: window_gui.h:485
WindowClass cls
Class of the window,.
Definition: window_gui.h:177
Window is made sticky by user.
Definition: window_gui.h:240
Presizing mode (docks, tunnels).
Definition: window_gui.h:913
virtual void OnTimeout()
Called when this window&#39;s timeout has been reached.
Definition: window_gui.h:711
Window is being resized towards the left.
Definition: window_gui.h:238
Large amount of vertical space between two paragraphs of text.
Definition: window_gui.h:140
virtual bool OnVehicleSelect(const struct Vehicle *v)
The user clicked on a vehicle while HT_VEHICLE has been set.
Definition: window_gui.h:763
virtual bool IsNewGRFInspectable() const
Is the data related to this window NewGRF inspectable?
Definition: window_gui.h:806
FrameFlags
Flags to describe the look of the frame.
Definition: window_gui.h:27
Width of a close box widget.
Definition: window_gui.h:119
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:249
Partial widget specification to allow NWidgets to be written nested.
Definition: widget_type.h:910
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:585
Types related to viewports.
const char * ini_key
Key to store window defaults in openttd.cfg. NULL if nothing shall be stored.
Definition: window_gui.h:179
Data structure for an opened window.
Definition: window_gui.h:278
Bottom offset of image in the button.
Definition: window_gui.h:43
WidgetDrawDistances
Distances used in drawing widgets.
Definition: window_gui.h:38
Bottom offset of the text of the frame.
Definition: window_gui.h:75
void SetFocusedWindow(Window *w)
Set the window that has the focus.
Definition: window.cpp:436
int16 GetDefaultHeight() const
Determine default height of window.
Definition: window.cpp:135
int16 default_height_trad
Preferred initial height of the window (pixels at 1x zoom).
Definition: window_gui.h:197
NWidgetBase ** nested_array
Array of pointers into the tree. Do not access directly, use Window::GetWidget() instead.
Definition: window_gui.h:332
Data structure for resizing a window.
Definition: window_gui.h:218
Right offset of resize sprite.
Definition: window_gui.h:114
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:1716
Width of a standard shade box widget.
Definition: window_gui.h:84
Offset at bottom of a matrix cell.
Definition: window_gui.h:81
Right offset of defsize sprite.
Definition: window_gui.h:107
virtual EventState OnKeyPress(WChar key, uint16 keycode)
A key has been pressed.
Definition: window_gui.h:609
virtual void OnInit()
Notification that the nested widget tree gets initialized.
Definition: window_gui.h:543
This window is used for construction; close it whenever changing company.
Definition: window_gui.h:210
bool IsWidgetLowered(byte widget_index) const
Gets the lowered state of a widget.
Definition: window_gui.h:495
int16 GetDefaultWidth() const
Determine default width of window.
Definition: window.cpp:125
Window * _z_back_window
List of windows opened at the screen sorted from the back.
Definition: window.cpp:61
virtual void OnFocus()
Called when window gains focus.
Definition: window_gui.h:598
Sort descending.
Definition: window_gui.h:227
uint32 VehicleID
The type all our vehicle IDs have.
Definition: vehicle_type.h:18
Window is being dragged.
Definition: window_gui.h:236
ViewportPlaceMethod
Viewport place method (type of highlighted area and placed objects)
Definition: viewport_type.h:78
SmallMap< int, QueryString * > querystrings
QueryString associated to WWT_EDITBOX widgets.
Definition: window_gui.h:330
virtual void DrawWidget(const Rect &r, int widget) const
Draw the contents of a nested widget.
Definition: window_gui.h:571
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:389
Left offset of string.
Definition: window_gui.h:46
Bottom offset of resize sprite.
Definition: window_gui.h:116
SmallVector< int, 4 > scheduled_invalidation_data
Data of scheduled OnInvalidateData() calls.
Definition: window_gui.h:284
WindowPosition default_pos
Preferred position of the window.
Definition: window_gui.h:176
Window is centered and shall stay centered after ReInit.
Definition: window_gui.h:244
Height of bottom bevel border.
Definition: window_gui.h:59
void SetWhiteBorder()
Set the timeout flag of the window and initiate the timer.
Definition: window_gui.h:377
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
Definition: gfx_type.h:247
List of hotkeys for a window.
Definition: hotkeys.h:42
void DrawCaption(const Rect &r, Colours colour, Owner owner, StringID str)
Draw a caption bar.
Definition: widget.cpp:540
Wcls * AllocateWindowDescFront(WindowDesc *desc, int window_number, bool return_existing=false)
Open a new window.
Definition: window_gui.h:879
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:162
Left offset of defsize sprite.
Definition: window_gui.h:106
Height of a title bar.
Definition: window_gui.h:126
static void SaveToConfig()
Save all WindowDesc settings to _windows_file.
Definition: window.cpp:166
bool IsWidgetDisabled(byte widget_index) const
Gets the enabled/disabled status of a widget.
Definition: window_gui.h:423
Offset at bottom to draw below the text.
Definition: window_gui.h:69
uint nested_array_size
Size of the nested array.
Definition: window_gui.h:333
const NWidgetPart * nwid_parts
Nested widget parts describing the window.
Definition: window_gui.h:181
WindowDefaultFlag
Window default widget/window handling flags.
Definition: window_gui.h:209
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:643
Window timeout counter.
Definition: window_gui.h:234
Data structure for a window viewport.
Definition: window_gui.h:258
int16 nwid_length
Length of the nwid_parts array.
Definition: window_gui.h:182
int32 scrollpos_x
Currently shown x coordinate (virtual screen coordinate of topleft corner of the viewport).
Definition: window_gui.h:260
uint step_height
Step-size of height resize changes.
Definition: window_gui.h:220
void LowerWidget(byte widget_index)
Marks a widget as lowered.
Definition: window_gui.h:476
Offset at left of a matrix cell.
Definition: window_gui.h:78
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:679
Top offset of resize sprite.
Definition: window_gui.h:115
void GuiShowTooltips(Window *parent, StringID str, uint paramcount=0, const uint64 params[]=NULL, TooltipCloseCondition close_tooltip=TCC_HOVER)
Shows a tooltip.
Definition: misc_gui.cpp:741
virtual void OnDropdownSelect(int widget, int index)
A dropdown option associated to this window has been selected.
Definition: window_gui.h:725
Center the window.
Definition: window_gui.h:157
SortButtonState
State of a sort direction button.
Definition: window_gui.h:224
Right offset of sticky sprite.
Definition: window_gui.h:93
Offset at bottom to draw the frame rectangular area.
Definition: window_gui.h:65
Sizing mode.
Definition: window_gui.h:912
Baseclass for nested widgets.
Definition: widget_type.h:126
uint8 white_border_timer
Timer value of the WF_WHITE_BORDER for flags.
Definition: window_gui.h:317
Offset of the caption text at the left.
Definition: window_gui.h:127
Right offset of the text of the frame.
Definition: window_gui.h:73
VehicleID follow_vehicle
VehicleID to follow if following a vehicle, INVALID_VEHICLE otherwise.
Definition: window_gui.h:259
Right offset of the image in the button.
Definition: window_gui.h:41
Top offset of the text of the frame.
Definition: window_gui.h:74
Left offset of the text of the frame.
Definition: window_gui.h:72
Top offset of defsize sprite.
Definition: window_gui.h:108
Window has a widget that has a highlight.
Definition: window_gui.h:243
Base class that provides memory initialization on dynamically created objects.
Definition: alloc_type.hpp:150
bool pref_sticky
Preferred stickyness.
Definition: window_gui.h:185
WindowFlags
Window flags.
Definition: window_gui.h:233
uint32 StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:18
Window is being resized.
Definition: window_gui.h:239
Window * FindWindowFromPt(int x, int y)
Do a search for a window at specific coordinates.
Definition: window.cpp:1862
Left offset of resize sprite.
Definition: window_gui.h:113
Bottom offset of closebox string.
Definition: window_gui.h:123
int32 dest_scrollpos_y
Current destination y coordinate to display (virtual screen coordinate of topleft corner of the viewp...
Definition: window_gui.h:263
Draw border only, no background.
Definition: window_gui.h:30
Offset at top to draw above the text.
Definition: window_gui.h:68
The window is a modal child of some other window, meaning the parent is &#39;inactive&#39;.
Definition: window_gui.h:211
uint32 flags
Flags.
Definition: window_gui.h:180
bool IsWidgetGloballyFocused(byte widget_index) const
Check if given widget has user input focus.
Definition: window_gui.h:445
Offset of the caption text at the top.
Definition: window_gui.h:129
Window * z_back
The window behind us in z-order.
Definition: window_gui.h:341
Width of a standard debug box widget.
Definition: window_gui.h:98
void RelocateAllWindows(int neww, int newh)
Relocate all windows to fit the new size of the game application screen.
Definition: window.cpp:3550
virtual bool OnRightClick(Point pt, int widget)
A click with the right mouse button has been made on the window.
Definition: window_gui.h:636
Top offset of shade sprite.
Definition: window_gui.h:87
Width of a standard sticky box widget.
Definition: window_gui.h:91
Bottom offset of scrollbar.
Definition: window_gui.h:53
virtual void OnPaint()
The window must be repainted.
Definition: window_gui.h:560
int32 dest_scrollpos_x
Current destination x coordinate to display (virtual screen coordinate of topleft corner of the viewp...
Definition: window_gui.h:262
Height of top bevel border.
Definition: window_gui.h:58
Align toward the toolbar.
Definition: window_gui.h:158
Data structure for viewport, display of a part of the world.
Definition: viewport_type.h:24
If set the frame is lowered and the background colour brighter (ie. buttons when pressed) ...
Definition: window_gui.h:31
Bottom offset of sticky sprite.
Definition: window_gui.h:95
Offset of the caption text at the bottom.
Definition: window_gui.h:130
Bottom offset of debug sprite.
Definition: window_gui.h:102
uint32 TileIndex
The index/ID of a Tile.
Definition: tile_type.h:80
Window * z_front
The window in front of us in z-order.
Definition: window_gui.h:340
WindowClass parent_cls
Class of the parent window.
Definition: window_gui.h:178
virtual EventState OnCTRLStateChange()
The state of the control key has changed.
Definition: window_gui.h:618
virtual void ShowNewGRFInspectWindow() const
Show the NewGRF inspection window.
Definition: window_gui.h:814
virtual void SetStringParameters(int widget) const
Initialize string parameters for a widget.
Definition: window_gui.h:593
This window won&#39;t get focus/make any other window lose focus when click.
Definition: window_gui.h:212
Sort ascending.
Definition: window_gui.h:226
static void LoadFromConfig()
Load all WindowDesc settings from _windows_file.
Definition: window.cpp:143
int index
Index of the nested widget in the widget array of the window (-1 means &#39;not used&#39;).
Definition: widget_type.h:304
Top offset of image in the button.
Definition: window_gui.h:42
Types related to vehicles.
virtual void OnGameTick()
Called once per (game) tick.
Definition: window_gui.h:696
int shown_plane
Plane being displayed (for NWID_SELECTION only).
Definition: widget_type.h:420
Right offset of string.
Definition: window_gui.h:47
Top offset of sticky sprite.
Definition: window_gui.h:94
virtual void OnRealtimeTick(uint delta_ms)
Called periodically.
Definition: window_gui.h:706
uint step_width
Step-size of width resize changes.
Definition: window_gui.h:219
HotkeyList * hotkeys
Hotkeys for the window.
Definition: window_gui.h:183
Bottom offset of the dropdown widget string.
Definition: window_gui.h:137
Right offset of scrollbar.
Definition: window_gui.h:51
Coordinates of a point in 2D.
int16 pref_width
User-preferred width of the window. Zero if unset.
Definition: window_gui.h:186
Types related to companies.
Window does not do autoscroll,.
Definition: window_gui.h:241
Owner owner
The owner of the content shown in this window. Company colour is acquired from this variable...
Definition: window_gui.h:326
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:658
Right offset of shade sprite.
Definition: window_gui.h:86
Width of a resize box widget.
Definition: window_gui.h:112
Offset at right to draw the frame rectangular area.
Definition: window_gui.h:63
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:627
int width
width of the window (number of pixels to the right in x direction)
Definition: window_gui.h:321
Types for strings.
virtual void OnResize()
Called after the window got resized.
Definition: window_gui.h:718
int32 WindowNumber
Number to differentiate different windows of the same class.
Definition: window_type.h:707
WindowClass window_class
Window class.
Definition: window_gui.h:313
virtual void OnMouseWheel(int wheel)
The mouse wheel has been turned.
Definition: window_gui.h:685
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:756
bool IsShaded() const
Is window shaded currently?
Definition: window_gui.h:526
WindowNumber window_number
Window number within the window class.
Definition: window_gui.h:314
Left offset of the dropdown widget string.
Definition: window_gui.h:134
Owner
Enum for all companies/owners.
Definition: company_type.h:20
Find a place automatically.
Definition: window_gui.h:156
Types related to tiles.
Manually align the window (so no automatic location finding)
Definition: window_gui.h:155
virtual void OnHundredthTick()
Called once every 100 (game) ticks.
Definition: window_gui.h:701
Makes the background transparent if set.
Definition: window_gui.h:29
ViewportData * viewport
Pointer to viewport data, if present.
Definition: window_gui.h:328
uint8 timeout_timer
Timer value of the WF_TIMEOUT for flags.
Definition: window_gui.h:316
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:434
const NWID * GetWidget(uint widnum) const
Get the nested widget with number widnum from the nested widget tree.
Definition: window_gui.h:847
Do not sort (with this button).
Definition: window_gui.h:225
bool _mouse_hovering
The mouse is hovering over the same point.
Definition: window.cpp:80
Window white border counter bit mask.
Definition: window_gui.h:242
Left offset of the image in the button.
Definition: window_gui.h:40
int32 scrollpos_y
Currently shown y coordinate (virtual screen coordinate of topleft corner of the viewport).
Definition: window_gui.h:261
Left offset of closebox string.
Definition: window_gui.h:120
WindowPosition
How do we the window to be placed?
Definition: window_gui.h:154
NWidgetBase * nested_root
Root of the nested tree.
Definition: window_gui.h:331
Dimensions (a width and height) of a rectangle in 2D.
Offset at left to draw the frame rectangular area.
Definition: window_gui.h:62
WindowDesc * window_desc
Window description.
Definition: window_gui.h:311
Base class for windows opened from a toolbar.
Definition: window_gui.h:856
Right offset of the dropdown widget string.
Definition: window_gui.h:135
Top offset of the dropdown widget string.
Definition: window_gui.h:136
Offset of the caption text at the right.
Definition: window_gui.h:128
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:789
Window * BringWindowToFrontById(WindowClass cls, WindowNumber number)
Find a window and make it the relative top-window on the screen.
Definition: window.cpp:1243
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:337
Top offset of closebox string.
Definition: window_gui.h:122
int height
Height of the window (number of pixels down in y direction)
Definition: window_gui.h:322
void EnableWidget(byte widget_index)
Sets a widget to Enabled.
Definition: window_gui.h:413
virtual void OnInvalidateData(int data=0, bool gui_scope=true)
Some data on this window has become invalid.
Definition: window_gui.h:748
Top offset of string.
Definition: window_gui.h:48
Base class for a &#39;real&#39; widget.
Definition: widget_type.h:284