OpenTTD
widget_type.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 WIDGET_TYPE_H
11 #define WIDGET_TYPE_H
12 
13 #include "core/alloc_type.hpp"
14 #include "core/bitmath_func.hpp"
15 #include "core/math_func.hpp"
16 #include "strings_type.h"
17 #include "gfx_type.h"
18 #include "window_type.h"
19 
20 static const int WIDGET_LIST_END = -1;
21 
24  /* Number of column bits of the WWT_MATRIX widget data. */
27 
28  /* Number of row bits of the WWT_MATRIX widget data. */
31 };
32 
39 };
40 
44 enum WidgetType {
45  /* Window widget types. */
47 
60 
65 
71 
72  /* Nested widget types. */
83 
84  /* Nested widget part types. */
95 
96  /* Pushable window widget types. */
97  WWT_MASK = 0x7F,
98 
99  WWB_PUSHBUTTON = 1 << 7,
100 
101  WWT_PUSHBTN = WWT_PANEL | WWB_PUSHBUTTON,
102  WWT_PUSHTXTBTN = WWT_TEXTBTN | WWB_PUSHBUTTON,
103  WWT_PUSHIMGBTN = WWT_IMGBTN | WWB_PUSHBUTTON,
104  WWT_PUSHARROWBTN = WWT_ARROWBTN | WWB_PUSHBUTTON,
105  NWID_PUSHBUTTON_DROPDOWN = NWID_BUTTON_DROPDOWN | WWB_PUSHBUTTON,
106 };
107 
112 };
113 
114 /* Forward declarations. */
115 class NWidgetCore;
116 class Scrollbar;
117 
125 public:
127 
128  virtual void SetupSmallestSize(Window *w, bool init_array) = 0;
129  virtual void AssignSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height, bool rtl) = 0;
130 
131  virtual void FillNestedArray(NWidgetBase **array, uint length) = 0;
132 
133  virtual NWidgetCore *GetWidgetFromPos(int x, int y) = 0;
135 
136  virtual bool IsHighlighted() const { return false; }
137  virtual TextColour GetHighlightColour() const { return TC_INVALID; }
138  virtual void SetHighlighted(TextColour highlight_colour) {}
139 
147  inline void SetPadding(uint8 top, uint8 right, uint8 bottom, uint8 left)
148  {
149  this->padding_top = top;
150  this->padding_right = right;
151  this->padding_bottom = bottom;
152  this->padding_left = left;
153  }
154 
155  inline uint GetHorizontalStepSize(SizingType sizing) const;
156  inline uint GetVerticalStepSize(SizingType sizing) const;
157 
158  virtual void Draw(const Window *w) = 0;
159  virtual void SetDirty(const Window *w) const;
160 
162  uint fill_x;
163  uint fill_y;
164  uint resize_x;
165  uint resize_y;
166  /* Size of the widget in the smallest window possible.
167  * Computed by #SetupSmallestSize() followed by #AssignSizePosition().
168  */
169  uint smallest_x;
170  uint smallest_y;
171  /* Current widget size (that is, after resizing). */
172  uint current_x;
173  uint current_y;
174 
175  int pos_x;
176  int pos_y;
177 
180 
181  uint8 padding_top;
184  uint8 padding_left;
185 
186 protected:
187  inline void StoreSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height);
188 };
189 
195 {
196  return (sizing == ST_RESIZE) ? this->resize_x : this->fill_x;
197 }
198 
204 {
205  return (sizing == ST_RESIZE) ? this->resize_y : this->fill_y;
206 }
207 
216 inline void NWidgetBase::StoreSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height)
217 {
218  this->pos_x = x;
219  this->pos_y = y;
220  if (sizing == ST_SMALLEST) {
221  this->smallest_x = given_width;
222  this->smallest_y = given_height;
223  }
224  this->current_x = given_width;
225  this->current_y = given_height;
226 }
227 
228 
234 public:
235  NWidgetResizeBase(WidgetType tp, uint fill_x, uint fill_y);
236 
237  void SetMinimalSize(uint min_x, uint min_y);
238  void SetMinimalTextLines(uint8 min_lines, uint8 spacing, FontSize size);
239  void SetFill(uint fill_x, uint fill_y);
240  void SetResize(uint resize_x, uint resize_y);
241 
242  void AssignSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height, bool rtl);
243 
244  uint min_x;
245  uint min_y;
246 };
247 
250  /* Generic. */
253  /* Viewport widget. */
257  /* Button dropdown widget. */
259  /* Scrollbar widget. */
262  /* Generic. */
264 
275 };
277 
278 
283 public:
284  NWidgetCore(WidgetType tp, Colours colour, uint fill_x, uint fill_y, uint32 widget_data, StringID tool_tip);
285 
286  void SetIndex(int index);
287  void SetDataTip(uint32 widget_data, StringID tool_tip);
288 
289  inline void SetLowered(bool lowered);
290  inline bool IsLowered() const;
291  inline void SetDisabled(bool disabled);
292  inline bool IsDisabled() const;
293 
294  void FillNestedArray(NWidgetBase **array, uint length) override;
295  NWidgetCore *GetWidgetFromPos(int x, int y) override;
296  bool IsHighlighted() const override;
297  TextColour GetHighlightColour() const override;
298  void SetHighlighted(TextColour highlight_colour) override;
299 
301  Colours colour;
302  int index;
303  uint32 widget_data;
307 };
308 
313 inline void NWidgetCore::SetHighlighted(TextColour highlight_colour)
314 {
315  this->disp_flags = highlight_colour != TC_INVALID ? SETBITS(this->disp_flags, ND_HIGHLIGHT) : CLRBITS(this->disp_flags, ND_HIGHLIGHT);
316  this->highlight_colour = highlight_colour;
317 }
318 
320 inline bool NWidgetCore::IsHighlighted() const
321 {
322  return HasBit(this->disp_flags, NDB_HIGHLIGHT);
323 }
324 
327 {
328  return this->highlight_colour;
329 }
330 
335 inline void NWidgetCore::SetLowered(bool lowered)
336 {
337  this->disp_flags = lowered ? SETBITS(this->disp_flags, ND_LOWERED) : CLRBITS(this->disp_flags, ND_LOWERED);
338 }
339 
341 inline bool NWidgetCore::IsLowered() const
342 {
343  return HasBit(this->disp_flags, NDB_LOWERED);
344 }
345 
350 inline void NWidgetCore::SetDisabled(bool disabled)
351 {
352  this->disp_flags = disabled ? SETBITS(this->disp_flags, ND_DISABLED) : CLRBITS(this->disp_flags, ND_DISABLED);
353 }
354 
356 inline bool NWidgetCore::IsDisabled() const
357 {
358  return HasBit(this->disp_flags, NDB_DISABLED);
359 }
360 
361 
367 public:
369  ~NWidgetContainer();
370 
371  void Add(NWidgetBase *wid);
372  void FillNestedArray(NWidgetBase **array, uint length) override;
373 
375  inline bool IsEmpty() { return head == nullptr; }
376 
377  NWidgetBase *GetWidgetOfType(WidgetType tp) override;
378 
379 protected:
382 };
383 
386  SZSP_VERTICAL = INT_MAX / 2,
389 
391 };
392 
404 public:
405  NWidgetStacked();
406 
407  void SetIndex(int index);
408 
409  void SetupSmallestSize(Window *w, bool init_array) override;
410  void AssignSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height, bool rtl) override;
411  void FillNestedArray(NWidgetBase **array, uint length) override;
412 
413  void Draw(const Window *w) override;
414  NWidgetCore *GetWidgetFromPos(int x, int y) override;
415 
416  void SetDisplayedPlane(int plane);
417 
419  int index;
420 };
421 
425 
426  NC_NONE = 0,
428 };
430 
431 
433 public:
435 
436  void SetPIP(uint8 pip_pre, uint8 pip_inter, uint8 pip_post);
437 
438  void Draw(const Window *w) override;
439  NWidgetCore *GetWidgetFromPos(int x, int y) override;
440 
441 protected:
443  uint8 pip_pre;
444  uint8 pip_inter;
445  uint8 pip_post;
446 };
447 
453 public:
455 
456  void SetupSmallestSize(Window *w, bool init_array);
457  void AssignSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height, bool rtl);
458 };
459 
465 public:
467 
468  void AssignSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height, bool rtl);
469 };
470 
476 public:
478 
479  void SetupSmallestSize(Window *w, bool init_array);
480  void AssignSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height, bool rtl);
481 };
482 
492 public:
493  NWidgetMatrix();
494 
495  void SetIndex(int index);
496  void SetColour(Colours colour);
497  void SetClicked(int clicked);
498  void SetCount(int count);
499  void SetScrollbar(Scrollbar *sb);
500 
501  void SetupSmallestSize(Window *w, bool init_array) override;
502  void AssignSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height, bool rtl) override;
503  void FillNestedArray(NWidgetBase **array, uint length) override;
504 
505  NWidgetCore *GetWidgetFromPos(int x, int y) override;
506  void Draw(const Window *w) override;
507 protected:
508  int index;
509  Colours colour;
510  int clicked;
511  int count;
513 private:
514  int widget_w;
515  int widget_h;
516  int widgets_x;
517  int widgets_y;
518 
519  void GetScrollOffsets(int &start_x, int &start_y, int &base_offs_x, int &base_offs_y);
520 };
521 
522 
528 public:
529  NWidgetSpacer(int length, int height);
530 
531  void SetupSmallestSize(Window *w, bool init_array) override;
532  void FillNestedArray(NWidgetBase **array, uint length) override;
533 
534  void Draw(const Window *w) override;
535  void SetDirty(const Window *w) const override;
536  NWidgetCore *GetWidgetFromPos(int x, int y) override;
537 };
538 
544 public:
545  NWidgetBackground(WidgetType tp, Colours colour, int index, NWidgetPIPContainer *child = nullptr);
547 
548  void Add(NWidgetBase *nwid);
549  void SetPIP(uint8 pip_pre, uint8 pip_inter, uint8 pip_post);
550 
551  void SetupSmallestSize(Window *w, bool init_array) override;
552  void AssignSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height, bool rtl) override;
553 
554  void FillNestedArray(NWidgetBase **array, uint length) override;
555 
556  void Draw(const Window *w) override;
557  NWidgetCore *GetWidgetFromPos(int x, int y) override;
558  NWidgetBase *GetWidgetOfType(WidgetType tp) override;
559 
560 private:
562 };
563 
573 class NWidgetViewport : public NWidgetCore {
574 public:
575  NWidgetViewport(int index);
576 
577  void SetupSmallestSize(Window *w, bool init_array) override;
578  void Draw(const Window *w) override;
579 
580  void InitializeViewport(Window *w, uint32 follow_flags, ZoomLevel zoom);
581  void UpdateViewportCoordinates(Window *w);
582 };
583 
587 class Scrollbar {
588 private:
589  const bool is_vertical;
590  uint16 count;
591  uint16 cap;
592  uint16 pos;
593  uint16 stepsize;
594 
595 public:
601  };
602 
603  Scrollbar(bool is_vertical) : is_vertical(is_vertical), stepsize(1)
604  {
605  }
606 
611  inline uint16 GetCount() const
612  {
613  return this->count;
614  }
615 
620  inline uint16 GetCapacity() const
621  {
622  return this->cap;
623  }
624 
629  inline uint16 GetPosition() const
630  {
631  return this->pos;
632  }
633 
639  inline bool IsVisible(uint16 item) const
640  {
641  return IsInsideBS(item, this->GetPosition(), this->GetCapacity());
642  }
643 
648  inline bool IsVertical() const
649  {
650  return this->is_vertical;
651  }
652 
657  void SetStepSize(uint16 stepsize)
658  {
659  assert(stepsize > 0);
660  this->stepsize = stepsize;
661  }
662 
668  void SetCount(int num)
669  {
670  assert(num >= 0);
671  assert(num <= MAX_UVALUE(uint16));
672 
673  this->count = num;
674  num -= this->cap;
675  if (num < 0) num = 0;
676  if (num < this->pos) this->pos = num;
677  }
678 
684  void SetCapacity(int capacity)
685  {
686  assert(capacity > 0);
687  assert(capacity <= MAX_UVALUE(uint16));
688 
689  this->cap = capacity;
690  if (this->cap + this->pos > this->count) this->pos = max(0, this->count - this->cap);
691  }
692 
693  void SetCapacityFromWidget(Window *w, int widget, int padding = 0);
694 
699  void SetPosition(int position)
700  {
701  assert(position >= 0);
702  assert(this->count <= this->cap ? (position == 0) : (position + this->cap <= this->count));
703  this->pos = position;
704  }
705 
712  void UpdatePosition(int difference, ScrollbarStepping unit = SS_SMALL)
713  {
714  if (difference == 0) return;
715  switch (unit) {
716  case SS_SMALL: difference *= this->stepsize; break;
717  case SS_BIG: difference *= this->cap; break;
718  default: break;
719  }
720  this->SetPosition(Clamp(this->pos + difference, 0, max(this->count - this->cap, 0)));
721  }
722 
729  void ScrollTowards(int position)
730  {
731  if (position < this->GetPosition()) {
732  /* scroll up to the item */
733  this->SetPosition(position);
734  } else if (position >= this->GetPosition() + this->GetCapacity()) {
735  /* scroll down so that the item is at the bottom */
736  this->SetPosition(position - this->GetCapacity() + 1);
737  }
738  }
739 
740  int GetScrolledRowFromWidget(int clickpos, const Window * const w, int widget, int padding = 0, int line_height = -1) const;
741 };
742 
748 class NWidgetScrollbar : public NWidgetCore, public Scrollbar {
749 public:
750  NWidgetScrollbar(WidgetType tp, Colours colour, int index);
751 
752  void SetupSmallestSize(Window *w, bool init_array) override;
753  void Draw(const Window *w) override;
754 
755  static void InvalidateDimensionCache();
756  static Dimension GetVerticalDimension();
757  static Dimension GetHorizontalDimension();
758 
759 private:
762 };
763 
768 class NWidgetLeaf : public NWidgetCore {
769 public:
770  NWidgetLeaf(WidgetType tp, Colours colour, int index, uint32 data, StringID tip);
771 
772  void SetupSmallestSize(Window *w, bool init_array) override;
773  void Draw(const Window *w) override;
774 
775  bool ButtonHit(const Point &pt);
776 
777  static void InvalidateDimensionCache();
778 
782 private:
787 };
788 
796 static inline uint ComputeMaxSize(uint base, uint max_space, uint step)
797 {
798  if (base >= max_space || step == 0) return base;
799  if (step == 1) return max_space;
800  uint increment = max_space - base;
801  increment -= increment % step;
802  return base + increment;
803 }
804 
857  uint32 data;
859 };
860 
866  Colours colour;
867  int16 index;
868 };
869 
875  uint8 top, right, bottom, left;
876 };
877 
883  uint8 pre, inter, post;
884 };
885 
891  uint8 lines;
892  uint8 spacing;
894 };
895 
902 typedef NWidgetBase *NWidgetFunctionType(int *biggest_index);
903 
908 struct NWidgetPart {
910  union {
919  } u;
920 };
921 
928 static inline NWidgetPart SetResize(int16 dx, int16 dy)
929 {
930  NWidgetPart part;
931 
932  part.type = WPT_RESIZE;
933  part.u.xy.x = dx;
934  part.u.xy.y = dy;
935 
936  return part;
937 }
938 
945 static inline NWidgetPart SetMinimalSize(int16 x, int16 y)
946 {
947  NWidgetPart part;
948 
949  part.type = WPT_MINSIZE;
950  part.u.xy.x = x;
951  part.u.xy.y = y;
952 
953  return part;
954 }
955 
963 static inline NWidgetPart SetMinimalTextLines(uint8 lines, uint8 spacing, FontSize size = FS_NORMAL)
964 {
965  NWidgetPart part;
966 
967  part.type = WPT_MINTEXTLINES;
968  part.u.text_lines.lines = lines;
969  part.u.text_lines.spacing = spacing;
970  part.u.text_lines.size = size;
971 
972  return part;
973 }
974 
981 static inline NWidgetPart SetFill(uint fill_x, uint fill_y)
982 {
983  NWidgetPart part;
984 
985  part.type = WPT_FILL;
986  part.u.xy.x = fill_x;
987  part.u.xy.y = fill_y;
988 
989  return part;
990 }
991 
997 static inline NWidgetPart EndContainer()
998 {
999  NWidgetPart part;
1000 
1001  part.type = WPT_ENDCONTAINER;
1002 
1003  return part;
1004 }
1005 
1012 static inline NWidgetPart SetDataTip(uint32 data, StringID tip)
1013 {
1014  NWidgetPart part;
1015 
1016  part.type = WPT_DATATIP;
1017  part.u.data_tip.data = data;
1018  part.u.data_tip.tooltip = tip;
1019 
1020  return part;
1021 }
1022 
1030 static inline NWidgetPart SetMatrixDataTip(uint8 cols, uint8 rows, StringID tip)
1031 {
1032  return SetDataTip((rows << MAT_ROW_START) | (cols << MAT_COL_START), tip);
1033 }
1034 
1044 static inline NWidgetPart SetPadding(uint8 top, uint8 right, uint8 bottom, uint8 left)
1045 {
1046  NWidgetPart part;
1047 
1048  part.type = WPT_PADDING;
1049  part.u.padding.top = top;
1050  part.u.padding.right = right;
1051  part.u.padding.bottom = bottom;
1052  part.u.padding.left = left;
1053 
1054  return part;
1055 }
1056 
1062 static inline NWidgetPart SetPadding(uint8 padding)
1063 {
1064  return SetPadding(padding, padding, padding, padding);
1065 }
1066 
1074 static inline NWidgetPart SetPIP(uint8 pre, uint8 inter, uint8 post)
1075 {
1076  NWidgetPart part;
1077 
1078  part.type = WPT_PIPSPACE;
1079  part.u.pip.pre = pre;
1080  part.u.pip.inter = inter;
1081  part.u.pip.post = post;
1082 
1083  return part;
1084 }
1085 
1093 static inline NWidgetPart SetScrollbar(int index)
1094 {
1095  NWidgetPart part;
1096 
1097  part.type = WPT_SCROLLBAR;
1098  part.u.widget.index = index;
1099 
1100  return part;
1101 }
1102 
1112 static inline NWidgetPart NWidget(WidgetType tp, Colours col, int16 idx = -1)
1113 {
1114  NWidgetPart part;
1115 
1116  part.type = tp;
1117  part.u.widget.colour = col;
1118  part.u.widget.index = idx;
1119 
1120  return part;
1121 }
1122 
1130 {
1131  NWidgetPart part;
1132 
1133  part.type = tp;
1134  part.u.cont_flags = cont_flags;
1135 
1136  return part;
1137 }
1138 
1145 {
1146  NWidgetPart part;
1147 
1148  part.type = WPT_FUNCTION;
1149  part.u.func_ptr = func_ptr;
1150 
1151  return part;
1152 }
1153 
1154 NWidgetContainer *MakeNWidgets(const NWidgetPart *parts, int count, int *biggest_index, NWidgetContainer *container);
1155 NWidgetContainer *MakeWindowNWidgetTree(const NWidgetPart *parts, int count, int *biggest_index, NWidgetStacked **shade_select);
1156 
1157 NWidgetBase *MakeCompanyButtonRows(int *biggest_index, int widget_first, int widget_last, int max_length, StringID button_tooltip);
1158 
1159 #endif /* WIDGET_TYPE_H */
Nested widget containing a viewport.
Definition: widget_type.h:79
Colours colour
Colour of this widget.
Definition: widget_type.h:301
Matrix container with implicitly equal sized (virtual) sub-widgets.
Definition: widget_type.h:491
uint16 pos
Index of first visible item of the list.
Definition: widget_type.h:592
static Dimension shadebox_dimension
Cached size of a shadebox widget.
Definition: widget_type.h:783
Empty widget, place holder to reserve space in widget array.
Definition: widget_type.h:46
SizingType
Different forms of sizing nested widgets, using NWidgetBase::AssignSizePosition() ...
Definition: widget_type.h:109
Normal push-button (no toggle button) with image caption.
Definition: widget_type.h:103
DECLARE_ENUM_AS_BIT_SET(GenderEthnicity) enum CompanyManagerFaceVariable
Bitgroups of the CompanyManagerFace variable.
NWidContainerFlags
Nested widget container flags,.
Definition: widget_type.h:423
uint32 widget_data
Data of the widget.
Definition: widget_type.h:303
NWidgetBase(WidgetType tp)
Base class constructor.
Definition: widget.cpp:719
Matrix container.
Definition: widget_type.h:76
Step in single units.
Definition: widget_type.h:598
void ScrollTowards(int position)
Scroll towards the given position; if the item is visible nothing happens, otherwise it will be shown...
Definition: widget_type.h:729
static NWidgetPart SetResize(int16 dx, int16 dy)
Widget part function for setting the resize step.
Definition: widget_type.h:928
NWidgetBase * NWidgetFunctionType(int *biggest_index)
Pointer to function returning a nested widget.
Definition: widget_type.h:902
static NWidgetPart NWidgetFunction(NWidgetFunctionType *func_ptr)
Obtain a nested widget (sub)tree from an external source.
Definition: widget_type.h:1144
uint resize_x
Horizontal resize step (0 means not resizable).
Definition: widget_type.h:164
Lowest bit of the number of columns.
Definition: widget_type.h:25
Widget part for storing data and tooltip information.
Definition: widget_type.h:856
uint min_x
Minimal horizontal size of only this widget.
Definition: widget_type.h:244
(Toggle) Button with diff image when clicked
Definition: widget_type.h:51
Number of bits for the number of columns in the matrix.
Definition: widget_type.h:26
StringID tool_tip
Tooltip of the widget.
Definition: widget_type.h:304
int clicked
The currently clicked widget.
Definition: widget_type.h:510
Baseclass for container widgets.
Definition: widget_type.h:366
Centered label.
Definition: widget_type.h:55
uint16 cap
Number of visible elements of the scroll bar.
Definition: widget_type.h:591
Scrollbar data structure.
Definition: widget_type.h:587
Base class for a resizable nested widget.
Definition: widget_type.h:233
Stacked widgets, widgets all occupying the same space in the window.
Definition: widget_type.h:403
Types related to windows.
static uint ComputeMaxSize(uint base, uint max_space, uint step)
Return the biggest possible size of a nested widget.
Definition: widget_type.h:796
Nested widget to display and control a scrollbar in a window.
Definition: widget_type.h:748
Horizontal container.
Definition: widget_type.h:73
Arrow to the right or in case of RTL to the left.
Definition: widget_type.h:36
Arrow to the left or in case of RTL to the right.
Definition: widget_type.h:35
Bit value of the &#39;no transparency&#39; flag.
Definition: widget_type.h:268
NewGRF debug box (at top-right of a window, between WWT_CAPTION and WWT_SHADEBOX) ...
Definition: widget_type.h:61
WidgetType type
Type of the widget / nested widget.
Definition: widget_type.h:161
static Dimension vertical_dimension
Cached size of vertical scrollbar button.
Definition: widget_type.h:760
NWidgetBase * tail
Pointer to last widget in container.
Definition: widget_type.h:381
Down-button is lowered bit.
Definition: widget_type.h:261
NWidContainerFlags flags
Flags of the container.
Definition: widget_type.h:442
static Dimension closebox_dimension
Cached size of a closebox widget.
Definition: widget_type.h:781
const bool is_vertical
Scrollbar has vertical orientation.
Definition: widget_type.h:589
#define SETBITS(x, y)
Sets several bits in a variable.
uint8 pip_inter
Amount of space between widgets.
Definition: widget_type.h:444
a textbox for typing
Definition: widget_type.h:69
int index
If non-negative, index in the Window::nested_array.
Definition: widget_type.h:419
Resize box (normally at bottom-right of a window)
Definition: widget_type.h:66
Pressed (inset) panel, most commonly used as combo box text area.
Definition: widget_type.h:49
void SetPosition(int position)
Sets the position of the first visible element.
Definition: widget_type.h:699
Horizontal container that doesn&#39;t change the direction of the widgets for RTL languages.
Definition: widget_type.h:464
Dropdown menu of the button dropdown widget is active.
Definition: widget_type.h:258
bool IsHighlighted() const override
Return whether the widget is highlighted.
Definition: widget_type.h:320
Normal push-button (no toggle button) with custom drawing.
Definition: widget_type.h:101
(Toggle) Button with an arrow
Definition: widget_type.h:52
Close box (at top-left of a window)
Definition: widget_type.h:67
Bit value of the &#39;shade to grey&#39; flag.
Definition: widget_type.h:269
Functions related to bit mathematics.
uint8 pip_post
Amount of space after last widget.
Definition: widget_type.h:445
NWidgetFunctionType * func_ptr
Part with a function call.
Definition: widget_type.h:917
static NWidgetPart SetMinimalTextLines(uint8 lines, uint8 spacing, FontSize size=FS_NORMAL)
Widget part function for setting the minimal text lines.
Definition: widget_type.h:963
static Dimension resizebox_dimension
Cached size of a resizebox widget.
Definition: widget_type.h:780
NWidgetPartPIP pip
Part with pre/inter/post spaces.
Definition: widget_type.h:915
#define CLRBITS(x, y)
Clears several bits in a variable.
Step in cap units.
Definition: widget_type.h:600
Helper types related to the allocation of memory.
Spacer widget.
Definition: widget_type.h:527
uint smallest_x
Smallest horizontal size of the widget in a filled window.
Definition: widget_type.h:169
static T max(const T a, const T b)
Returns the maximum of two values.
Definition: math_func.hpp:24
Widget part for specifying a padding.
Definition: widget_type.h:90
Widget part for specifying resizing.
Definition: widget_type.h:85
Widget part for specifying data and tooltip.
Definition: widget_type.h:89
Nested widget to display a viewport in a window.
Definition: widget_type.h:573
NWidgetPartWidget widget
Part with a start of a widget.
Definition: widget_type.h:913
NWidgetContainer * MakeNWidgets(const NWidgetPart *parts, int count, int *biggest_index, NWidgetContainer *container)
Construct a nested widget tree from an array of parts.
Definition: widget.cpp:2790
Pure simple text.
Definition: widget_type.h:56
Point xy
Part with an x/y size.
Definition: widget_type.h:911
uint GetHorizontalStepSize(SizingType sizing) const
Get the horizontal sizing step.
Definition: widget_type.h:194
bool IsDisabled() const
Return whether the widget is disabled.
Definition: widget_type.h:356
Bit value of the disabled flag.
Definition: widget_type.h:266
TextColour GetHighlightColour() const override
Return the colour of the highlight.
Definition: widget_type.h:326
static 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.
Definition: math_func.hpp:248
void SetCapacity(int capacity)
Set the capacity of visible elements.
Definition: widget_type.h:684
uint16 stepsize
Distance to scroll, when pressing the buttons or using the wheel.
Definition: widget_type.h:593
NWidgetDisplay
Nested widget flags that affect display and interaction with &#39;real&#39; widgets.
Definition: widget_type.h:249
Widget is disabled (greyed out) bit.
Definition: widget_type.h:252
Leaf widget.
Definition: widget_type.h:768
void SetCount(int num)
Sets the number of elements in the list.
Definition: widget_type.h:668
Partial widget specification to allow NWidgets to be written nested.
Definition: widget_type.h:908
NWidgetBase * MakeCompanyButtonRows(int *biggest_index, int widget_first, int widget_last, int max_length, StringID button_tooltip)
Make a number of rows with button-like graphics, for enabling/disabling each company.
Definition: widget.cpp:2862
Data structure for an opened window.
Definition: window_gui.h:276
NWidgetBase * next
Pointer to next widget in container. Managed by parent container widget.
Definition: widget_type.h:178
static NWidgetPart SetMatrixDataTip(uint8 cols, uint8 rows, StringID tip)
Widget part function for setting the data and tooltip of WWT_MATRIX widgets.
Definition: widget_type.h:1030
Widget part for specifying fill.
Definition: widget_type.h:88
ArrowWidgetValues
Values for an arrow widget.
Definition: widget_type.h:34
void SetHighlighted(TextColour highlight_colour) override
Highlight the widget or not.
Definition: widget_type.h:313
StringID tooltip
Tooltip of the widget.
Definition: widget_type.h:858
Lowest bit of the number of rows.
Definition: widget_type.h:29
Invisible widget that takes some space.
Definition: widget_type.h:77
int count
Amount of valid widgets.
Definition: widget_type.h:511
WidgetType type
Type of the part.
Definition: widget_type.h:909
Bit value of the &#39;dropdown active&#39; flag.
Definition: widget_type.h:271
Default window size box (at top-right of a window, between WWT_SHADEBOX and WWT_STICKYBOX) ...
Definition: widget_type.h:63
Widget part for specifying pre/inter/post space for containers.
Definition: widget_type.h:91
static Dimension horizontal_dimension
Cached size of horizontal scrollbar button.
Definition: widget_type.h:761
uint32 data
Data value of the widget.
Definition: widget_type.h:857
void SetLowered(bool lowered)
Lower or raise the widget.
Definition: widget_type.h:335
Bit value of the &#39;scrollbar up&#39; flag.
Definition: widget_type.h:272
uint8 padding_top
Paddings added to the top of the widget. Managed by parent container widget.
Definition: widget_type.h:181
uint smallest_y
Smallest vertical size of the widget in a filled window.
Definition: widget_type.h:170
uint current_y
Current vertical size (after resizing).
Definition: widget_type.h:173
static Dimension stickybox_dimension
Cached size of a stickybox widget.
Definition: widget_type.h:786
static NWidgetPart SetDataTip(uint32 data, StringID tip)
Widget part function for setting the data and tooltip.
Definition: widget_type.h:1012
Number of bits for the number of rows in the matrix.
Definition: widget_type.h:30
uint16 count
Number of elements in the list.
Definition: widget_type.h:590
Display plane with zero size vertically, and filling and resizing horizontally.
Definition: widget_type.h:387
static NWidgetPart SetMinimalSize(int16 x, int16 y)
Widget part function for setting the minimal size.
Definition: widget_type.h:945
Widget is lowered (pressed down) bit.
Definition: widget_type.h:251
Widget part for attaching a scrollbar.
Definition: widget_type.h:94
Widget part for storing pre/inter/post spaces.
Definition: widget_type.h:882
virtual NWidgetCore * GetWidgetFromPos(int x, int y)=0
Retrieve a widget by its position.
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
Definition: gfx_type.h:245
Normal push-button (no toggle button) with text caption.
Definition: widget_type.h:102
ScrollbarStepping
Stepping sizes when scrolling.
Definition: widget_type.h:597
Vertical container.
Definition: widget_type.h:475
uint fill_y
Vertical fill stepsize (from initial size, 0 means not resizable).
Definition: widget_type.h:163
Widget part for calling a user function.
Definition: widget_type.h:93
Simple depressed panel.
Definition: widget_type.h:48
NWidgetPartDataTip data_tip
Part with a data/tooltip.
Definition: widget_type.h:912
int16 index
Widget index in the widget array.
Definition: widget_type.h:867
Horizontal scrollbar.
Definition: widget_type.h:81
int pos_x
Horizontal position of top-left corner of the widget in the window.
Definition: widget_type.h:175
Viewport is never transparent.
Definition: widget_type.h:254
void SetPadding(uint8 top, uint8 right, uint8 bottom, uint8 left)
Set additional space (padding) around the widget.
Definition: widget_type.h:147
Frame.
Definition: widget_type.h:58
uint8 padding_left
Paddings added to the left of the widget. Managed by parent container widget. (parent container may s...
Definition: widget_type.h:184
int scrollbar_index
Index of an attached scrollbar.
Definition: widget_type.h:305
static Dimension dropdown_dimension
Cached size of a dropdown widget.
Definition: widget_type.h:779
Bit value of the &#39;dimmed colours&#39; flag.
Definition: widget_type.h:270
static NWidgetPart NWidget(WidgetType tp, Colours col, int16 idx=-1)
Widget part function for starting a new &#39;real&#39; widget.
Definition: widget_type.h:1112
Bit value of the lowered flag.
Definition: widget_type.h:265
Baseclass for nested widgets.
Definition: widget_type.h:124
Button with a drop-down.
Definition: widget_type.h:80
All flags cleared.
Definition: widget_type.h:426
Shade viewport to grey-scale.
Definition: widget_type.h:255
uint resize_y
Vertical resize step (0 means not resizable).
Definition: widget_type.h:165
Container with pre/inter/post child space.
Definition: widget_type.h:432
Grid of rows and columns.
Definition: widget_type.h:57
#define MAX_UVALUE(type)
The largest value that can be entered in a variable.
Definition: stdafx.h:469
Widget part for storing padding.
Definition: widget_type.h:874
void StoreSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height)
Store size and position.
Definition: widget_type.h:216
virtual void Draw(const Window *w)=0
Draw the widgets of the tree.
Display plane with zero size in both directions (none filling and resizing).
Definition: widget_type.h:388
NWidgetBase * prev
Pointer to previous widget in container. Managed by parent container widget.
Definition: widget_type.h:179
Force the arrow to the left.
Definition: widget_type.h:37
NWidgetPIPContainer * child
Child widget.
Definition: widget_type.h:561
static Dimension debugbox_dimension
Cached size of a debugbox widget.
Definition: widget_type.h:784
Horizontal container.
Definition: widget_type.h:452
Base class that provides memory initialization on dynamically created objects.
Definition: alloc_type.hpp:85
uint8 post
Amount of space before/between/after child widgets.
Definition: widget_type.h:883
uint min_y
Minimal vertical size of only this widget.
Definition: widget_type.h:245
uint32 StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:16
Bit value of the highlight flag.
Definition: widget_type.h:267
Highlight of widget is on.
Definition: widget_type.h:263
uint8 padding_bottom
Paddings added to the bottom of the widget. Managed by parent container widget.
Definition: widget_type.h:183
TextColour highlight_colour
Colour of highlight.
Definition: widget_type.h:306
Initialize nested widget tree to smallest size. Also updates current_x and current_y.
Definition: widget_type.h:110
Integer math functions.
static const int WIDGET_LIST_END
indicate the end of widgets&#39; list for vararg functions
Definition: widget_type.h:20
NWidgetPartTextLines text_lines
Part with text line data.
Definition: widget_type.h:916
static T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
Definition: math_func.hpp:137
Colours colour
Colour of this widget.
Definition: widget_type.h:509
bool IsVisible(uint16 item) const
Checks whether given current item is visible in the list.
Definition: widget_type.h:639
int widget_h
The height of the child widget including inter spacing.
Definition: widget_type.h:515
uint16 GetCount() const
Gets the number of elements in the list.
Definition: widget_type.h:611
Colours colour
Widget colour.
Definition: widget_type.h:866
WidgetType
Window widget types, nested widget types, and nested widget part types.
Definition: widget_type.h:44
Step in stepsize units.
Definition: widget_type.h:599
virtual void AssignSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height, bool rtl)=0
Assign size and position to the widget.
virtual NWidgetBase * GetWidgetOfType(WidgetType tp)
Retrieve a widget by its type.
Definition: widget.cpp:793
First zero-size plane.
Definition: widget_type.h:390
bool IsLowered() const
Return whether the widget is lowered.
Definition: widget_type.h:341
Window caption (window title between closebox and stickybox)
Definition: widget_type.h:59
void SetStepSize(uint16 stepsize)
Set the distance to scroll when using the buttons or the wheel.
Definition: widget_type.h:657
NWidgetPartPaddings padding
Part with paddings.
Definition: widget_type.h:914
void UpdatePosition(int difference, ScrollbarStepping unit=SS_SMALL)
Updates the position of the first visible element by the given amount.
Definition: widget_type.h:712
Containers should keep all their (resizing) children equally large.
Definition: widget_type.h:424
Last Item. use WIDGETS_END to fill up padding!!
Definition: widget_type.h:70
uint8 spacing
Extra spacing around lines.
Definition: widget_type.h:892
Bit value of the &#39;scrollbar up&#39; or &#39;scrollbar down&#39; flag.
Definition: widget_type.h:274
Widget part for storing minimal text line data.
Definition: widget_type.h:890
Up-button is lowered bit.
Definition: widget_type.h:260
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
NWidContainerFlags cont_flags
Part with container flags.
Definition: widget_type.h:918
Display dimmed colours in the viewport.
Definition: widget_type.h:256
static Dimension defsizebox_dimension
Cached size of a defsizebox widget.
Definition: widget_type.h:785
Vertical container.
Definition: widget_type.h:75
static NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME, WWT_INSET, or WWT_PANEL).
Definition: widget_type.h:997
(Toggle) Button with diff text when clicked
Definition: widget_type.h:54
FontSize
Available font sizes.
Definition: gfx_type.h:201
int shown_plane
Plane being displayed (for NWID_SELECTION only).
Definition: widget_type.h:418
uint current_x
Current horizontal size (after resizing).
Definition: widget_type.h:172
Index of the normal font in the font tables.
Definition: gfx_type.h:202
NWidgetContainer * MakeWindowNWidgetTree(const NWidgetPart *parts, int count, int *biggest_index, NWidgetStacked **shade_select)
Make a nested widget tree for a window from a parts array.
Definition: widget.cpp:2812
NWidgetBase * head
Pointer to first widget in container.
Definition: widget_type.h:380
void SetDisabled(bool disabled)
Disable (grey-out) or enable the widget.
Definition: widget_type.h:350
Coordinates of a point in 2D.
int index
If non-negative, index in the Window::nested_array.
Definition: widget_type.h:508
Drop down list.
Definition: widget_type.h:68
MatrixWidgetValues
Bits of the WWT_MATRIX widget data.
Definition: widget_type.h:23
Normal push-button (no toggle button) with arrow caption.
Definition: widget_type.h:104
uint16 GetCapacity() const
Gets the number of visible elements of the scrollbar.
Definition: widget_type.h:620
Types related to strings.
int widgets_x
The number of visible widgets in horizontal direction.
Definition: widget_type.h:516
uint8 pip_pre
Amount of space before first widget.
Definition: widget_type.h:443
virtual void SetupSmallestSize(Window *w, bool init_array)=0
Compute smallest size needed by the widget.
Widget part for specifying minimal number of lines of text.
Definition: widget_type.h:87
Widget part to denote end of a container.
Definition: widget_type.h:92
Scrollbar * sb
The scrollbar we&#39;re associated with.
Definition: widget_type.h:512
Display plane with zero size horizontally, and filling and resizing vertically.
Definition: widget_type.h:386
Sticky box (at top-right of a window, after WWT_DEFSIZEBOX)
Definition: widget_type.h:64
uint GetVerticalStepSize(SizingType sizing) const
Get the vertical sizing step.
Definition: widget_type.h:203
static NWidgetPart SetFill(uint fill_x, uint fill_y)
Widget part function for setting filling.
Definition: widget_type.h:981
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
ZoomLevel
All zoom levels we know.
Definition: zoom_type.h:19
Force the arrow to the right.
Definition: widget_type.h:38
Vertical scrollbar.
Definition: widget_type.h:82
StackedZeroSizePlanes
Display planes with zero size for NWidgetStacked.
Definition: widget_type.h:385
Resize the nested widget tree.
Definition: widget_type.h:111
(Toggle) Button with image
Definition: widget_type.h:50
Widget part for storing basic widget information.
Definition: widget_type.h:865
NWidgetDisplay disp_flags
Flags that affect display and interaction with the widget.
Definition: widget_type.h:300
Stacked widgets, only one visible at a time (eg in a panel with tabs).
Definition: widget_type.h:78
uint8 left
Paddings for all directions.
Definition: widget_type.h:875
uint8 lines
Number of text lines.
Definition: widget_type.h:891
FontSize size
Font size of text lines.
Definition: widget_type.h:893
uint8 padding_right
Paddings added to the right of the widget. Managed by parent container widget. (parent container may ...
Definition: widget_type.h:182
virtual void SetDirty(const Window *w) const
Mark the widget as &#39;dirty&#39; (in need of repaint).
Definition: widget.cpp:773
static NWidgetPart SetScrollbar(int index)
Attach a scrollbar to a widget.
Definition: widget_type.h:1093
uint fill_x
Horizontal fill stepsize (from initial size, 0 means not resizable).
Definition: widget_type.h:162
bool IsVertical() const
Is the scrollbar vertical or not?
Definition: widget_type.h:648
Dimensions (a width and height) of a rectangle in 2D.
Value of the NCB_EQUALSIZE flag.
Definition: widget_type.h:427
Bit value of the &#39;scrollbar down&#39; flag.
Definition: widget_type.h:273
Nested widget with a child.
Definition: widget_type.h:543
Shade box (at top-right of a window, between WWT_DEBUGBOX and WWT_DEFSIZEBOX)
Definition: widget_type.h:62
Widget part for specifying minimal size.
Definition: widget_type.h:86
int widget_w
The width of the child widget including inter spacing.
Definition: widget_type.h:514
Horizontal container that doesn&#39;t change the order of the widgets for RTL languages.
Definition: widget_type.h:74
Types related to the graphics and/or input devices.
static NWidgetPart SetPIP(uint8 pre, uint8 inter, uint8 post)
Widget part function for setting a pre/inter/post spaces.
Definition: widget_type.h:1074
bool IsEmpty()
Return whether the container is empty.
Definition: widget_type.h:375
int pos_y
Vertical position of top-left corner of the widget in the window.
Definition: widget_type.h:176
virtual void FillNestedArray(NWidgetBase **array, uint length)=0
Fill the Window::nested_array array with pointers to nested widgets in the tree.
(Toggle) Button with text
Definition: widget_type.h:53
int widgets_y
The number of visible widgets in vertical direction.
Definition: widget_type.h:517
uint16 GetPosition() const
Gets the position of the first visible element in the list.
Definition: widget_type.h:629
Base class for a &#39;real&#39; widget.
Definition: widget_type.h:282