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