OpenTTD Source  12.0-beta2
signs_gui.cpp
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 #include "stdafx.h"
11 #include "company_gui.h"
12 #include "company_func.h"
13 #include "signs_base.h"
14 #include "signs_func.h"
15 #include "debug.h"
16 #include "command_func.h"
17 #include "strings_func.h"
18 #include "window_func.h"
19 #include "map_func.h"
20 #include "viewport_func.h"
21 #include "querystring_gui.h"
22 #include "sortlist_type.h"
23 #include "stringfilter_type.h"
24 #include "string_func.h"
25 #include "core/geometry_func.hpp"
26 #include "hotkeys.h"
27 #include "transparency.h"
28 #include "gui.h"
29 
30 #include "widgets/sign_widget.h"
31 
32 #include "table/strings.h"
33 #include "table/sprites.h"
34 
35 #include "safeguards.h"
36 
37 struct SignList {
42 
43  GUISignList signs;
44 
46  static bool match_case;
47  static char default_name[64];
48 
53  {
54  }
55 
56  void BuildSignsList()
57  {
58  if (!this->signs.NeedRebuild()) return;
59 
60  Debug(misc, 3, "Building sign list");
61 
62  this->signs.clear();
63 
64  for (const Sign *si : Sign::Iterate()) this->signs.push_back(si);
65 
66  this->signs.SetFilterState(true);
67  this->FilterSignList();
68  this->signs.shrink_to_fit();
69  this->signs.RebuildDone();
70  }
71 
73  static bool SignNameSorter(const Sign * const &a, const Sign * const &b)
74  {
75  /* Signs are very very rarely using the default text, but there can also be
76  * a lot of them. Therefore a worthwhile performance gain can be made by
77  * directly comparing Sign::name instead of going through the string
78  * system for each comparison. */
79  const char *a_name = a->name.empty() ? SignList::default_name : a->name.c_str();
80  const char *b_name = b->name.empty() ? SignList::default_name : b->name.c_str();
81 
82  int r = strnatcmp(a_name, b_name); // Sort by name (natural sorting).
83 
84  return r != 0 ? r < 0 : (a->index < b->index);
85  }
86 
87  void SortSignsList()
88  {
89  if (!this->signs.Sort(&SignNameSorter)) return;
90  }
91 
93  static bool CDECL SignNameFilter(const Sign * const *a, StringFilter &filter)
94  {
95  /* Same performance benefit as above for sorting. */
96  const char *a_name = (*a)->name.empty() ? SignList::default_name : (*a)->name.c_str();
97 
98  filter.ResetState();
99  filter.AddLine(a_name);
100  return filter.GetState();
101  }
102 
104  static bool CDECL OwnerDeityFilter(const Sign * const *a, StringFilter &filter)
105  {
106  /* You should never be able to edit signs of owner DEITY */
107  return (*a)->owner != OWNER_DEITY;
108  }
109 
111  static bool CDECL OwnerVisibilityFilter(const Sign * const *a, StringFilter &filter)
112  {
114  /* Hide sign if non-own signs are hidden in the viewport */
115  return (*a)->owner == _local_company || (*a)->owner == OWNER_DEITY;
116  }
117 
120  {
121  this->signs.Filter(&SignNameFilter, this->string_filter);
122  if (_game_mode != GM_EDITOR) this->signs.Filter(&OwnerDeityFilter, this->string_filter);
124  this->signs.Filter(&OwnerVisibilityFilter, this->string_filter);
125  }
126  }
127 };
128 
129 bool SignList::match_case = false;
130 char SignList::default_name[64];
131 
135 };
136 
140  Scrollbar *vscroll;
141 
143  {
144  this->CreateNestedTree();
145  this->vscroll = this->GetScrollbar(WID_SIL_SCROLLBAR);
146  this->FinishInitNested(window_number);
147  this->SetWidgetLoweredState(WID_SIL_FILTER_MATCH_CASE_BTN, SignList::match_case);
148 
149  /* Initialize the text edit widget */
151  this->filter_editbox.cancel_button = QueryString::ACTION_CLEAR;
152 
153  /* Initialize the filtering variables */
154  this->SetFilterString("");
155 
156  /* Create initial list. */
157  this->signs.ForceRebuild();
158  this->signs.ForceResort();
159  this->BuildSortSignList();
160  }
161 
162  void OnInit() override
163  {
164  /* Default sign name, used if Sign::name is nullptr. */
165  GetString(SignList::default_name, STR_DEFAULT_SIGN_NAME, lastof(SignList::default_name));
166  this->signs.ForceResort();
167  this->SortSignsList();
168  this->SetDirty();
169  }
170 
177  void SetFilterString(const char *new_filter_string)
178  {
179  /* check if there is a new filter string */
180  this->string_filter.SetFilterTerm(new_filter_string);
181 
182  /* Rebuild the list of signs */
183  this->InvalidateData();
184  }
185 
186  void OnPaint() override
187  {
188  if (!this->IsShaded() && this->signs.NeedRebuild()) this->BuildSortSignList();
189  this->DrawWidgets();
190  }
191 
192  void DrawWidget(const Rect &r, int widget) const override
193  {
194  switch (widget) {
195  case WID_SIL_LIST: {
196  uint y = r.top + WD_FRAMERECT_TOP; // Offset from top of widget.
197  uint text_offset_y = (this->resize.step_height - FONT_HEIGHT_NORMAL + 1) / 2;
198  /* No signs? */
199  if (this->vscroll->GetCount() == 0) {
200  DrawString(r.left + WD_FRAMETEXT_LEFT, r.right - WD_FRAMETEXT_RIGHT, y + text_offset_y, STR_STATION_LIST_NONE);
201  return;
202  }
203 
204  Dimension d = GetSpriteSize(SPR_COMPANY_ICON);
205  bool rtl = _current_text_dir == TD_RTL;
206  int sprite_offset_y = (this->resize.step_height - d.height + 1) / 2;
207  uint icon_left = 4 + (rtl ? r.right - this->text_offset : r.left);
208  uint text_left = r.left + (rtl ? WD_FRAMERECT_LEFT : this->text_offset);
209  uint text_right = r.right - (rtl ? this->text_offset : WD_FRAMERECT_RIGHT);
210 
211  /* At least one sign available. */
212  for (uint16 i = this->vscroll->GetPosition(); this->vscroll->IsVisible(i) && i < this->vscroll->GetCount(); i++) {
213  const Sign *si = this->signs[i];
214 
215  if (si->owner != OWNER_NONE) DrawCompanyIcon(si->owner, icon_left, y + sprite_offset_y);
216 
217  SetDParam(0, si->index);
218  DrawString(text_left, text_right, y + text_offset_y, STR_SIGN_NAME, TC_YELLOW);
219  y += this->resize.step_height;
220  }
221  break;
222  }
223  }
224  }
225 
226  void SetStringParameters(int widget) const override
227  {
228  if (widget == WID_SIL_CAPTION) SetDParam(0, this->vscroll->GetCount());
229  }
230 
231  void OnClick(Point pt, int widget, int click_count) override
232  {
233  switch (widget) {
234  case WID_SIL_LIST: {
235  uint id_v = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_SIL_LIST, WD_FRAMERECT_TOP);
236  if (id_v == INT_MAX) return;
237 
238  const Sign *si = this->signs[id_v];
239  ScrollMainWindowToTile(TileVirtXY(si->x, si->y));
240  break;
241  }
242 
244  if (this->signs.size() >= 1) {
245  const Sign *si = this->signs[0];
246  ScrollMainWindowToTile(TileVirtXY(si->x, si->y));
247  }
248  break;
249 
251  SignList::match_case = !SignList::match_case; // Toggle match case
252  this->SetWidgetLoweredState(WID_SIL_FILTER_MATCH_CASE_BTN, SignList::match_case); // Toggle button pushed state
253  this->InvalidateData(); // Rebuild the list of signs
254  break;
255  }
256  }
257 
258  void OnResize() override
259  {
261  }
262 
263  void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
264  {
265  switch (widget) {
266  case WID_SIL_LIST: {
267  Dimension spr_dim = GetSpriteSize(SPR_COMPANY_ICON);
268  this->text_offset = WD_FRAMETEXT_LEFT + spr_dim.width + 2; // 2 pixels space between icon and the sign text.
269  resize->height = std::max<uint>(FONT_HEIGHT_NORMAL, spr_dim.height + 2);
270  Dimension d = {(uint)(this->text_offset + WD_FRAMETEXT_RIGHT), WD_FRAMERECT_TOP + 5 * resize->height + WD_FRAMERECT_BOTTOM};
271  *size = maxdim(*size, d);
272  break;
273  }
274 
275  case WID_SIL_CAPTION:
277  *size = GetStringBoundingBox(STR_SIGN_LIST_CAPTION);
278  size->height += padding.height;
279  size->width += padding.width;
280  break;
281  }
282  }
283 
284  EventState OnHotkey(int hotkey) override
285  {
286  switch (hotkey) {
289  SetFocusedWindow(this); // The user has asked to give focus to the text box, so make sure this window is focused.
290  break;
291 
292  default:
293  return ES_NOT_HANDLED;
294  }
295 
296  return ES_HANDLED;
297  }
298 
299  void OnEditboxChanged(int widget) override
300  {
301  if (widget == WID_SIL_FILTER_TEXT) this->SetFilterString(this->filter_editbox.text.buf);
302  }
303 
304  void BuildSortSignList()
305  {
306  if (this->signs.NeedRebuild()) {
307  this->BuildSignsList();
308  this->vscroll->SetCount((uint)this->signs.size());
310  }
311  this->SortSignsList();
312  }
313 
314  void OnHundredthTick() override
315  {
316  this->BuildSortSignList();
317  this->SetDirty();
318  }
319 
325  void OnInvalidateData(int data = 0, bool gui_scope = true) override
326  {
327  /* When there is a filter string, we always need to rebuild the list even if
328  * the amount of signs in total is unchanged, as the subset of signs that is
329  * accepted by the filter might has changed. */
330  if (data == 0 || data == -1 || !this->string_filter.IsEmpty()) { // New or deleted sign, changed visibility setting or there is a filter string
331  /* This needs to be done in command-scope to enforce rebuilding before resorting invalid data */
332  this->signs.ForceRebuild();
333  } else { // Change of sign contents while there is no filter string
334  this->signs.ForceResort();
335  }
336  }
337 
338  static HotkeyList hotkeys;
339 };
340 
347 {
348  if (_game_mode == GM_MENU) return ES_NOT_HANDLED;
349  Window *w = ShowSignList();
350  if (w == nullptr) return ES_NOT_HANDLED;
351  return w->OnHotkey(hotkey);
352 }
353 
354 static Hotkey signlist_hotkeys[] = {
355  Hotkey('F', "focus_filter_box", SLHK_FOCUS_FILTER_BOX),
356  HOTKEY_LIST_END
357 };
358 HotkeyList SignListWindow::hotkeys("signlist", signlist_hotkeys, SignListGlobalHotkeys);
359 
360 static const NWidgetPart _nested_sign_list_widgets[] = {
362  NWidget(WWT_CLOSEBOX, COLOUR_BROWN),
363  NWidget(WWT_CAPTION, COLOUR_BROWN, WID_SIL_CAPTION), SetDataTip(STR_SIGN_LIST_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
364  NWidget(WWT_SHADEBOX, COLOUR_BROWN),
365  NWidget(WWT_DEFSIZEBOX, COLOUR_BROWN),
366  NWidget(WWT_STICKYBOX, COLOUR_BROWN),
367  EndContainer(),
373  NWidget(WWT_PANEL, COLOUR_BROWN), SetFill(1, 1),
374  NWidget(WWT_EDITBOX, COLOUR_BROWN, WID_SIL_FILTER_TEXT), SetMinimalSize(80, 12), SetResize(1, 0), SetFill(1, 0), SetPadding(2, 2, 2, 2),
375  SetDataTip(STR_LIST_FILTER_OSKTITLE, STR_LIST_FILTER_TOOLTIP),
376  EndContainer(),
377  NWidget(WWT_TEXTBTN, COLOUR_BROWN, WID_SIL_FILTER_MATCH_CASE_BTN), SetDataTip(STR_SIGN_LIST_MATCH_CASE, STR_SIGN_LIST_MATCH_CASE_TOOLTIP),
378  EndContainer(),
379  EndContainer(),
381  NWidget(NWID_VERTICAL), SetFill(0, 1),
382  NWidget(NWID_VSCROLLBAR, COLOUR_BROWN, WID_SIL_SCROLLBAR),
383  EndContainer(),
384  NWidget(WWT_RESIZEBOX, COLOUR_BROWN),
385  EndContainer(),
386  EndContainer(),
387 };
388 
389 static WindowDesc _sign_list_desc(
390  WDP_AUTO, "list_signs", 358, 138,
392  0,
393  _nested_sign_list_widgets, lengthof(_nested_sign_list_widgets),
394  &SignListWindow::hotkeys
395 );
396 
403 {
404  return AllocateWindowDescFront<SignListWindow>(&_sign_list_desc, 0);
405 }
406 
413 static bool RenameSign(SignID index, const char *text)
414 {
415  bool remove = StrEmpty(text);
416  DoCommandP(0, index, 0, CMD_RENAME_SIGN | (StrEmpty(text) ? CMD_MSG(STR_ERROR_CAN_T_DELETE_SIGN) : CMD_MSG(STR_ERROR_CAN_T_CHANGE_SIGN_NAME)), nullptr, text);
417  return remove;
418 }
419 
421  QueryString name_editbox;
422  SignID cur_sign;
423 
425  {
426  this->querystrings[WID_QES_TEXT] = &this->name_editbox;
427  this->name_editbox.caption = STR_EDIT_SIGN_CAPTION;
428  this->name_editbox.cancel_button = WID_QES_CANCEL;
429  this->name_editbox.ok_button = WID_QES_OK;
430 
432 
433  UpdateSignEditWindow(si);
435  }
436 
437  void UpdateSignEditWindow(const Sign *si)
438  {
439  /* Display an empty string when the sign hasn't been edited yet */
440  if (!si->name.empty()) {
441  SetDParam(0, si->index);
442  this->name_editbox.text.Assign(STR_SIGN_NAME);
443  } else {
444  this->name_editbox.text.DeleteAll();
445  }
446 
447  this->cur_sign = si->index;
448 
451  }
452 
458  const Sign *PrevNextSign(bool next)
459  {
460  /* Rebuild the sign list */
461  this->signs.ForceRebuild();
462  this->signs.NeedResort();
463  this->BuildSignsList();
464  this->SortSignsList();
465 
466  /* Search through the list for the current sign, excluding
467  * - the first sign if we want the previous sign or
468  * - the last sign if we want the next sign */
469  size_t end = this->signs.size() - (next ? 1 : 0);
470  for (uint i = next ? 0 : 1; i < end; i++) {
471  if (this->cur_sign == this->signs[i]->index) {
472  /* We've found the current sign, so return the sign before/after it */
473  return this->signs[i + (next ? 1 : -1)];
474  }
475  }
476  /* If we haven't found the current sign by now, return the last/first sign */
477  return next ? this->signs.front() : this->signs.back();
478  }
479 
480  void SetStringParameters(int widget) const override
481  {
482  switch (widget) {
483  case WID_QES_CAPTION:
484  SetDParam(0, this->name_editbox.caption);
485  break;
486  }
487  }
488 
489  void OnClick(Point pt, int widget, int click_count) override
490  {
491  switch (widget) {
492  case WID_QES_LOCATION: {
493  const Sign *si = Sign::Get(this->cur_sign);
494  TileIndex tile = TileVirtXY(si->x, si->y);
495  if (_ctrl_pressed) {
497  } else {
499  }
500  break;
501  }
502 
503  case WID_QES_PREVIOUS:
504  case WID_QES_NEXT: {
505  const Sign *si = this->PrevNextSign(widget == WID_QES_NEXT);
506 
507  /* Rebuild the sign list */
508  this->signs.ForceRebuild();
509  this->signs.NeedResort();
510  this->BuildSignsList();
511  this->SortSignsList();
512 
513  /* Scroll to sign and reopen window */
514  ScrollMainWindowToTile(TileVirtXY(si->x, si->y));
515  UpdateSignEditWindow(si);
516  break;
517  }
518 
519  case WID_QES_DELETE:
520  /* Only need to set the buffer to null, the rest is handled as the OK button */
521  RenameSign(this->cur_sign, "");
522  /* don't delete this, we are deleted in Sign::~Sign() -> DeleteRenameSignWindow() */
523  break;
524 
525  case WID_QES_OK:
526  if (RenameSign(this->cur_sign, this->name_editbox.text.buf)) break;
527  FALLTHROUGH;
528 
529  case WID_QES_CANCEL:
530  this->Close();
531  break;
532  }
533  }
534 };
535 
536 static const NWidgetPart _nested_query_sign_edit_widgets[] = {
538  NWidget(WWT_CLOSEBOX, COLOUR_GREY),
539  NWidget(WWT_CAPTION, COLOUR_GREY, WID_QES_CAPTION), SetDataTip(STR_WHITE_STRING, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
540  NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_QES_LOCATION), SetMinimalSize(12, 14), SetDataTip(SPR_GOTO_LOCATION, STR_EDIT_SIGN_LOCATION_TOOLTIP),
541  EndContainer(),
542  NWidget(WWT_PANEL, COLOUR_GREY),
543  NWidget(WWT_EDITBOX, COLOUR_GREY, WID_QES_TEXT), SetMinimalSize(256, 12), SetDataTip(STR_EDIT_SIGN_SIGN_OSKTITLE, STR_NULL), SetPadding(2, 2, 2, 2),
544  EndContainer(),
546  NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_QES_OK), SetMinimalSize(61, 12), SetDataTip(STR_BUTTON_OK, STR_NULL),
547  NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_QES_CANCEL), SetMinimalSize(60, 12), SetDataTip(STR_BUTTON_CANCEL, STR_NULL),
548  NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_QES_DELETE), SetMinimalSize(60, 12), SetDataTip(STR_TOWN_VIEW_DELETE_BUTTON, STR_NULL),
549  NWidget(WWT_PANEL, COLOUR_GREY), SetFill(1, 1), EndContainer(),
550  NWidget(WWT_PUSHARROWBTN, COLOUR_GREY, WID_QES_PREVIOUS), SetMinimalSize(11, 12), SetDataTip(AWV_DECREASE, STR_EDIT_SIGN_PREVIOUS_SIGN_TOOLTIP),
551  NWidget(WWT_PUSHARROWBTN, COLOUR_GREY, WID_QES_NEXT), SetMinimalSize(11, 12), SetDataTip(AWV_INCREASE, STR_EDIT_SIGN_NEXT_SIGN_TOOLTIP),
552  EndContainer(),
553 };
554 
555 static WindowDesc _query_sign_edit_desc(
556  WDP_CENTER, "query_sign", 0, 0,
559  _nested_query_sign_edit_widgets, lengthof(_nested_query_sign_edit_widgets)
560 );
561 
566 void HandleClickOnSign(const Sign *si)
567 {
568  if (_ctrl_pressed && (si->owner == _local_company || (si->owner == OWNER_DEITY && _game_mode == GM_EDITOR))) {
569  RenameSign(si->index, "");
570  return;
571  }
573 }
574 
579 void ShowRenameSignWindow(const Sign *si)
580 {
581  /* Delete all other edit windows */
583 
584  new SignWindow(&_query_sign_edit_desc, si);
585 }
586 
592 {
594 
595  if (w != nullptr && w->cur_sign == sign) w->Close();
596 }
DO_SHOW_COMPETITOR_SIGNS
@ DO_SHOW_COMPETITOR_SIGNS
Display signs, station names and waypoint names of opponent companies. Buoys and oilrig-stations are ...
Definition: openttd.h:51
ES_HANDLED
@ ES_HANDLED
The passed event is handled.
Definition: window_type.h:718
SignListWindow::OnResize
void OnResize() override
Called after the window got resized.
Definition: signs_gui.cpp:258
SignListWindow::OnPaint
void OnPaint() override
The window must be repainted.
Definition: signs_gui.cpp:186
WD_FRAMERECT_TOP
@ WD_FRAMERECT_TOP
Offset at top to draw the frame rectangular area.
Definition: window_gui.h:64
CMD_MSG
#define CMD_MSG(x)
Used to combine a StringID with the command.
Definition: command_type.h:372
TileIndex
uint32 TileIndex
The index/ID of a Tile.
Definition: tile_type.h:83
WID_QES_TEXT
@ WID_QES_TEXT
Text of the query.
Definition: sign_widget.h:28
Pool::PoolItem<&_sign_pool >::Get
static Titem * Get(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:337
ScrollMainWindowToTile
bool ScrollMainWindowToTile(TileIndex tile, bool instant)
Scrolls the viewport of the main window to a given location.
Definition: viewport.cpp:2445
QueryString::ok_button
int ok_button
Widget button of parent window to simulate when pressing OK in OSK.
Definition: querystring_gui.h:27
querystring_gui.h
SetScrollbar
static NWidgetPart SetScrollbar(int index)
Attach a scrollbar to a widget.
Definition: widget_type.h:1188
ShowExtraViewportWindow
void ShowExtraViewportWindow(TileIndex tile=INVALID_TILE)
Show a new Extra Viewport window.
Definition: viewport_gui.cpp:168
HotkeyList
List of hotkeys for a window.
Definition: hotkeys.h:40
SetFocusedWindow
void SetFocusedWindow(Window *w)
Set the window that has the focus.
Definition: window.cpp:445
Dimension
Dimensions (a width and height) of a rectangle in 2D.
Definition: geometry_type.hpp:27
command_func.h
WWT_STICKYBOX
@ WWT_STICKYBOX
Sticky box (at top-right of a window, after WWT_DEFSIZEBOX)
Definition: widget_type.h:64
SetPadding
static NWidgetPart SetPadding(uint8 top, uint8 right, uint8 bottom, uint8 left)
Widget part function for setting additional space around a widget.
Definition: widget_type.h:1139
GUIList::Sort
bool Sort(Comp compare)
Sort the list.
Definition: sortlist_type.h:247
Window::GetScrollbar
const Scrollbar * GetScrollbar(uint widnum) const
Return the Scrollbar to a widget index.
Definition: window.cpp:320
WDF_CONSTRUCTION
@ WDF_CONSTRUCTION
This window is used for construction; close it whenever changing company.
Definition: window_gui.h:210
StringFilter::IsEmpty
bool IsEmpty() const
Check whether any filter words were entered.
Definition: stringfilter_type.h:59
SignListWindow::filter_editbox
QueryString filter_editbox
Filter editbox;.
Definition: signs_gui.cpp:138
StringFilter::SetFilterTerm
void SetFilterTerm(const char *str)
Set the term to filter on.
Definition: stringfilter.cpp:27
SignList::SignList
SignList()
Creates a SignList with filtering disabled by default.
Definition: signs_gui.cpp:52
SignList
Definition: signs_gui.cpp:37
signs_func.h
WWT_CAPTION
@ WWT_CAPTION
Window caption (window title between closebox and stickybox)
Definition: widget_type.h:59
SignList::default_name
static char default_name[64]
Default sign name, used if Sign::name is nullptr.
Definition: signs_gui.cpp:47
company_gui.h
GUIList< const Sign *, StringFilter & >
Textbuf::Assign
void Assign(StringID string)
Render a string into the textbuffer.
Definition: textbuf.cpp:396
SignWindow
Definition: signs_gui.cpp:420
DeleteRenameSignWindow
void DeleteRenameSignWindow(SignID sign)
Close the sign window associated with the given sign.
Definition: signs_gui.cpp:591
WWT_DEFSIZEBOX
@ WWT_DEFSIZEBOX
Default window size box (at top-right of a window, between WWT_SHADEBOX and WWT_STICKYBOX)
Definition: widget_type.h:63
Window::CreateNestedTree
void CreateNestedTree(bool fill_nested=true)
Perform the first part of the initialization of a nested widget tree.
Definition: window.cpp:1760
map_func.h
Pool::PoolItem::index
Tindex index
Index of this pool item.
Definition: pool_type.hpp:235
NWID_HORIZONTAL
@ NWID_HORIZONTAL
Horizontal container.
Definition: widget_type.h:73
maxdim
Dimension maxdim(const Dimension &d1, const Dimension &d2)
Compute bounding box of both dimensions.
Definition: geometry_func.cpp:22
SignList::FilterSignList
void FilterSignList()
Filter out signs from the sign list that does not match the name filter.
Definition: signs_gui.cpp:119
FindWindowById
Window * FindWindowById(WindowClass cls, WindowNumber number)
Find a window by its class and window number.
Definition: window.cpp:1146
MAX_LENGTH_SIGN_NAME_CHARS
static const uint MAX_LENGTH_SIGN_NAME_CHARS
The maximum length of a sign name in characters including '\0'.
Definition: signs_type.h:19
HasBit
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
Definition: bitmath_func.hpp:103
sign_widget.h
WC_SIGN_LIST
@ WC_SIGN_LIST
Sign list; Window numbers:
Definition: window_type.h:270
Scrollbar::SetCount
void SetCount(int num)
Sets the number of elements in the list.
Definition: widget_type.h:710
_ctrl_pressed
bool _ctrl_pressed
Is Ctrl pressed?
Definition: gfx.cpp:35
WID_SIL_SCROLLBAR
@ WID_SIL_SCROLLBAR
Scrollbar of list.
Definition: sign_widget.h:18
SetResize
static NWidgetPart SetResize(int16 dx, int16 dy)
Widget part function for setting the resize step.
Definition: widget_type.h:993
WID_QES_DELETE
@ WID_QES_DELETE
Delete button.
Definition: sign_widget.h:31
SignListHotkeys
SignListHotkeys
Enum referring to the Hotkeys in the sign list window.
Definition: signs_gui.cpp:133
DrawString
int DrawString(int left, int right, int top, const char *str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly truncated to make it fit in its allocated space.
Definition: gfx.cpp:642
WWT_PUSHARROWBTN
@ WWT_PUSHARROWBTN
Normal push-button (no toggle button) with arrow caption.
Definition: widget_type.h:106
StringFilter::AddLine
void AddLine(const char *str)
Pass another text line from the current item to the filter.
Definition: stringfilter.cpp:104
WindowNumber
int32 WindowNumber
Number to differentiate different windows of the same class.
Definition: window_type.h:711
_display_opt
byte _display_opt
What do we want to draw/do?
Definition: transparency_gui.cpp:26
Scrollbar::GetScrolledRowFromWidget
int GetScrolledRowFromWidget(int clickpos, const Window *const w, int widget, int padding=0) const
Compute the row of a scrolled widget that a user clicked in.
Definition: widget.cpp:2098
SignWindow::OnClick
void OnClick(Point pt, int widget, int click_count) override
A click with the left mouse button has been made on the window.
Definition: signs_gui.cpp:489
Scrollbar
Scrollbar data structure.
Definition: widget_type.h:629
WD_FRAMETEXT_LEFT
@ WD_FRAMETEXT_LEFT
Left offset of the text of the frame.
Definition: window_gui.h:72
Window::OnHotkey
virtual EventState OnHotkey(int hotkey)
A hotkey has been pressed.
Definition: window.cpp:621
Window::Window
Window(WindowDesc *desc)
Empty constructor, initialization has been moved to InitNested() called from the constructor of the d...
Definition: window.cpp:1799
SetDParam
static void SetDParam(uint n, uint64 v)
Set a string parameter v at index n in the global string parameter array.
Definition: strings_func.h:196
NWidgetPart
Partial widget specification to allow NWidgets to be written nested.
Definition: widget_type.h:971
SetDataTip
static NWidgetPart SetDataTip(uint32 data, StringID tip)
Widget part function for setting the data and tooltip.
Definition: widget_type.h:1107
QueryString
Data stored about a string that can be modified in the GUI.
Definition: querystring_gui.h:20
GetStringBoundingBox
Dimension GetStringBoundingBox(const char *str, FontSize start_fontsize)
Return the string dimension in pixels.
Definition: gfx.cpp:888
Textbuf::buf
char *const buf
buffer in which text is saved
Definition: textbuf_type.h:32
Window::querystrings
SmallMap< int, QueryString * > querystrings
QueryString associated to WWT_EDITBOX widgets.
Definition: window_gui.h:323
MAX_CHAR_LENGTH
static const int MAX_CHAR_LENGTH
Max. length of UTF-8 encoded unicode character.
Definition: strings_type.h:18
SignWindow::PrevNextSign
const Sign * PrevNextSign(bool next)
Returns a pointer to the (alphabetically) previous or next sign of the current sign.
Definition: signs_gui.cpp:458
WindowDesc
High level window description.
Definition: window_gui.h:168
Pool::PoolItem<&_sign_pool >::GetPoolSize
static size_t GetPoolSize()
Returns first unused index.
Definition: pool_type.hpp:358
WC_QUERY_STRING
@ WC_QUERY_STRING
Query string window; Window numbers:
Definition: window_type.h:115
SignList::string_filter
StringFilter string_filter
The match string to be used when the GUIList is (re)-sorted.
Definition: signs_gui.cpp:45
WDP_AUTO
@ WDP_AUTO
Find a place automatically.
Definition: window_gui.h:156
GUIList::SetFilterState
void SetFilterState(bool state)
Enable or disable the filter.
Definition: sortlist_type.h:302
Window::resize
ResizeInfo resize
Resize information.
Definition: window_gui.h:317
Scrollbar::GetCount
uint16 GetCount() const
Gets the number of elements in the list.
Definition: widget_type.h:653
DoCommandP
bool DoCommandP(const CommandContainer *container, bool my_cmd)
Shortcut for the long DoCommandP when having a container with the data.
Definition: command.cpp:541
SignList::OwnerVisibilityFilter
static bool CDECL OwnerVisibilityFilter(const Sign *const *a, StringFilter &filter)
Filter sign list by owner.
Definition: signs_gui.cpp:111
Window::InitNested
void InitNested(WindowNumber number=0)
Perform complete initialization of the Window with nested widgets, to allow use.
Definition: window.cpp:1789
WWT_EDITBOX
@ WWT_EDITBOX
a textbox for typing
Definition: widget_type.h:69
ShowRenameSignWindow
void ShowRenameSignWindow(const Sign *si)
Show the window to change the text of a sign.
Definition: signs_gui.cpp:579
Window::SetDirty
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
Definition: window.cpp:993
WD_FRAMERECT_LEFT
@ WD_FRAMERECT_LEFT
Offset at left to draw the frame rectangular area.
Definition: window_gui.h:62
WID_SIL_FILTER_ENTER_BTN
@ WID_SIL_FILTER_ENTER_BTN
Scroll to first sign.
Definition: sign_widget.h:21
WD_FRAMERECT_RIGHT
@ WD_FRAMERECT_RIGHT
Offset at right to draw the frame rectangular area.
Definition: window_gui.h:63
ES_NOT_HANDLED
@ ES_NOT_HANDLED
The passed event is not handled.
Definition: window_type.h:719
WD_FRAMERECT_BOTTOM
@ WD_FRAMERECT_BOTTOM
Offset at bottom to draw the frame rectangular area.
Definition: window_gui.h:65
WWT_PUSHTXTBTN
@ WWT_PUSHTXTBTN
Normal push-button (no toggle button) with text caption.
Definition: widget_type.h:104
HandleClickOnSign
void HandleClickOnSign(const Sign *si)
Handle clicking on a sign.
Definition: signs_gui.cpp:566
SignListGlobalHotkeys
static EventState SignListGlobalHotkeys(int hotkey)
Handler for global hotkeys of the SignListWindow.
Definition: signs_gui.cpp:346
SignListWindow::SetStringParameters
void SetStringParameters(int widget) const override
Initialize string parameters for a widget.
Definition: signs_gui.cpp:226
_local_company
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
Definition: company_cmd.cpp:46
safeguards.h
sortlist_type.h
StrEmpty
static bool StrEmpty(const char *s)
Check if a string buffer is empty.
Definition: string_func.h:64
SignListWindow::OnInit
void OnInit() override
Notification that the nested widget tree gets initialized.
Definition: signs_gui.cpp:162
sprites.h
Point
Coordinates of a point in 2D.
Definition: geometry_type.hpp:21
SignListWindow::OnHundredthTick
void OnHundredthTick() override
Called once every 100 (game) ticks, or once every 3s, whichever comes last.
Definition: signs_gui.cpp:314
WID_QES_CAPTION
@ WID_QES_CAPTION
Caption of the window.
Definition: sign_widget.h:26
WD_FRAMETEXT_RIGHT
@ WD_FRAMETEXT_RIGHT
Right offset of the text of the frame.
Definition: window_gui.h:73
Window::SetFocusedWidget
bool SetFocusedWidget(int widget_index)
Set focus within this window to the given widget.
Definition: window.cpp:506
stdafx.h
Window::window_number
WindowNumber window_number
Window number within the window class.
Definition: window_gui.h:307
ResizeInfo::step_height
uint step_height
Step-size of height resize changes.
Definition: window_gui.h:220
GUIList::NeedResort
bool NeedResort()
Check if a resort is needed next loop If used the resort timer will decrease every call till 0.
Definition: sortlist_type.h:199
Window::InvalidateData
void InvalidateData(int data=0, bool gui_scope=true)
Mark this window's data as invalid (in need of re-computing)
Definition: window.cpp:3158
SignList::GUISignList
GUIList< const Sign *, StringFilter & > GUISignList
A GUIList contains signs and uses a StringFilter for filtering.
Definition: signs_gui.cpp:41
viewport_func.h
WC_NONE
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
Definition: window_type.h:37
NWID_VERTICAL
@ NWID_VERTICAL
Vertical container.
Definition: widget_type.h:75
DrawCompanyIcon
void DrawCompanyIcon(CompanyID c, int x, int y)
Draw the icon of a company.
Definition: company_cmd.cpp:143
WID_QES_LOCATION
@ WID_QES_LOCATION
Scroll to sign location.
Definition: sign_widget.h:27
GetSpriteSize
Dimension GetSpriteSize(SpriteID sprid, Point *offset, ZoomLevel zoom)
Get the size of a sprite.
Definition: gfx.cpp:976
WWT_CLOSEBOX
@ WWT_CLOSEBOX
Close box (at top-left of a window)
Definition: widget_type.h:67
WWT_RESIZEBOX
@ WWT_RESIZEBOX
Resize box (normally at bottom-right of a window)
Definition: widget_type.h:66
GUIList::NeedRebuild
bool NeedRebuild() const
Check if a rebuild is needed.
Definition: sortlist_type.h:362
WID_SIL_CAPTION
@ WID_SIL_CAPTION
Caption of the window.
Definition: sign_widget.h:16
string_func.h
WN_QUERY_STRING_SIGN
@ WN_QUERY_STRING_SIGN
Query string for signs.
Definition: window_type.h:22
WWT_PUSHIMGBTN
@ WWT_PUSHIMGBTN
Normal push-button (no toggle button) with image caption.
Definition: widget_type.h:105
QueryString::cancel_button
int cancel_button
Widget button of parent window to simulate when pressing CANCEL in OSK.
Definition: querystring_gui.h:28
EndContainer
static NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME,...
Definition: widget_type.h:1092
Pool::PoolItem<&_sign_pool >::Iterate
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.
Definition: pool_type.hpp:386
strings_func.h
NWID_VSCROLLBAR
@ NWID_VSCROLLBAR
Vertical scrollbar.
Definition: widget_type.h:82
SignList::match_case
static bool match_case
Should case sensitive matching be used?
Definition: signs_gui.cpp:46
WID_QES_OK
@ WID_QES_OK
OK button.
Definition: sign_widget.h:29
Window::IsShaded
bool IsShaded() const
Is window shaded currently?
Definition: window_gui.h:520
FONT_HEIGHT_NORMAL
#define FONT_HEIGHT_NORMAL
Height of characters in the normal (FS_NORMAL) font.
Definition: gfx_func.h:165
WID_QES_CANCEL
@ WID_QES_CANCEL
Cancel button.
Definition: sign_widget.h:30
SignListWindow
Definition: signs_gui.cpp:137
NWidget
static NWidgetPart NWidget(WidgetType tp, Colours col, int16 idx=-1)
Widget part function for starting a new 'real' widget.
Definition: widget_type.h:1207
Scrollbar::IsVisible
bool IsVisible(uint16 item) const
Checks whether given current item is visible in the list.
Definition: widget_type.h:681
geometry_func.hpp
SetDParamMaxValue
void SetDParamMaxValue(uint n, uint64 max_value, uint min_count, FontSize size)
Set DParam n to some number that is suitable for string size computations.
Definition: strings.cpp:94
CloseWindowByClass
void CloseWindowByClass(WindowClass cls)
Close all windows of a given class.
Definition: window.cpp:1188
SetMinimalSize
static NWidgetPart SetMinimalSize(int16 x, int16 y)
Widget part function for setting the minimal size.
Definition: widget_type.h:1010
ShowSignList
Window * ShowSignList()
Open the sign list window.
Definition: signs_gui.cpp:402
transparency.h
StringFilter::ResetState
void ResetState()
Reset the matching state to process a new item.
Definition: stringfilter.cpp:88
WWT_PANEL
@ WWT_PANEL
Simple depressed panel.
Definition: widget_type.h:48
OWNER_NONE
@ OWNER_NONE
The tile has no ownership.
Definition: company_type.h:25
SignListWindow::UpdateWidgetSize
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
Update size and resize step of a widget in the window.
Definition: signs_gui.cpp:263
EventState
EventState
State of handling an event.
Definition: window_type.h:717
SignListWindow::OnEditboxChanged
void OnEditboxChanged(int widget) override
The text in an editbox has been edited.
Definition: signs_gui.cpp:299
Scrollbar::GetPosition
uint16 GetPosition() const
Gets the position of the first visible element in the list.
Definition: widget_type.h:671
Sign
Definition: signs_base.h:22
StringFilter::GetState
bool GetState() const
Get the matching state of the current item.
Definition: stringfilter_type.h:69
SignList::SignNameFilter
static bool CDECL SignNameFilter(const Sign *const *a, StringFilter &filter)
Filter sign list by sign name.
Definition: signs_gui.cpp:93
OWNER_DEITY
@ OWNER_DEITY
The object is owned by a superuser / goal script.
Definition: company_type.h:27
GUIList::Filter
bool Filter(FilterFunction *decide, F filter_data)
Filter the list.
Definition: sortlist_type.h:318
Window::FinishInitNested
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
Definition: window.cpp:1776
company_func.h
QueryString::ACTION_CLEAR
static const int ACTION_CLEAR
Clear editbox.
Definition: querystring_gui.h:24
GUIList::ForceResort
void ForceResort()
Force a resort next Sort call Reset the resort timer if used too.
Definition: sortlist_type.h:213
window_func.h
GUIList::ForceRebuild
void ForceRebuild()
Force that a rebuild is needed.
Definition: sortlist_type.h:370
Debug
#define Debug(name, level, format_string,...)
Ouptut a line of debugging information.
Definition: debug.h:37
lengthof
#define lengthof(x)
Return the length of an fixed size array.
Definition: stdafx.h:378
stringfilter_type.h
Scrollbar::SetCapacityFromWidget
void SetCapacityFromWidget(Window *w, int widget, int padding=0)
Set capacity of visible elements from the size and resize properties of a widget.
Definition: widget.cpp:2172
SignListWindow::OnHotkey
EventState OnHotkey(int hotkey) override
A hotkey has been pressed.
Definition: signs_gui.cpp:284
SignListWindow::text_offset
int text_offset
Offset of the sign text relative to the left edge of the WID_SIL_LIST widget.
Definition: signs_gui.cpp:139
SignList::OwnerDeityFilter
static bool CDECL OwnerDeityFilter(const Sign *const *a, StringFilter &filter)
Filter sign list excluding OWNER_DEITY.
Definition: signs_gui.cpp:104
strnatcmp
int strnatcmp(const char *s1, const char *s2, bool ignore_garbage_at_front)
Compares two strings using case insensitive natural sort.
Definition: string.cpp:718
WID_SIL_LIST
@ WID_SIL_LIST
List of signs.
Definition: sign_widget.h:17
SetFill
static NWidgetPart SetFill(uint fill_x, uint fill_y)
Widget part function for setting filling.
Definition: widget_type.h:1076
SignListWindow::OnInvalidateData
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
Definition: signs_gui.cpp:325
gui.h
Window
Data structure for an opened window.
Definition: window_gui.h:279
GUIList::RebuildDone
void RebuildDone()
Notify the sortlist that the rebuild is done.
Definition: sortlist_type.h:380
WID_QES_PREVIOUS
@ WID_QES_PREVIOUS
Previous button.
Definition: sign_widget.h:32
SLHK_FOCUS_FILTER_BOX
@ SLHK_FOCUS_FILTER_BOX
Focus the edit box for editing the filter string.
Definition: signs_gui.cpp:134
Window::DrawWidgets
void DrawWidgets() const
Paint all widgets of a window.
Definition: widget.cpp:636
SignListWindow::SetFilterString
void SetFilterString(const char *new_filter_string)
This function sets the filter string of the sign list.
Definition: signs_gui.cpp:177
Window::SetWidgetDirty
void SetWidgetDirty(byte widget_index) const
Invalidate a widget, i.e.
Definition: window.cpp:608
SignWindow::SetStringParameters
void SetStringParameters(int widget) const override
Initialize string parameters for a widget.
Definition: signs_gui.cpp:480
CMD_RENAME_SIGN
@ CMD_RENAME_SIGN
rename a sign
Definition: command_type.h:252
Rect
Specification of a rectangle with absolute coordinates of all edges.
Definition: geometry_type.hpp:47
AWV_INCREASE
@ AWV_INCREASE
Arrow to the right or in case of RTL to the left.
Definition: widget_type.h:36
SignListWindow::DrawWidget
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
Definition: signs_gui.cpp:192
lastof
#define lastof(x)
Get the last element of an fixed size array.
Definition: stdafx.h:394
WDP_CENTER
@ WDP_CENTER
Center the window.
Definition: window_gui.h:157
Window::SetWidgetLoweredState
void SetWidgetLoweredState(byte widget_index, bool lowered_stat)
Sets the lowered/raised status of a widget.
Definition: window_gui.h:447
Textbuf::DeleteAll
void CDECL void DeleteAll()
Delete every character in the textbuffer.
Definition: textbuf.cpp:116
TD_RTL
@ TD_RTL
Text is written right-to-left by default.
Definition: strings_type.h:24
_current_text_dir
TextDirection _current_text_dir
Text direction of the currently selected language.
Definition: strings.cpp:48
signs_base.h
StringFilter
String filter and state.
Definition: stringfilter_type.h:31
WID_QES_NEXT
@ WID_QES_NEXT
Next button.
Definition: sign_widget.h:33
WWT_TEXTBTN
@ WWT_TEXTBTN
(Toggle) Button with text
Definition: widget_type.h:53
SignListWindow::OnClick
void OnClick(Point pt, int widget, int click_count) override
A click with the left mouse button has been made on the window.
Definition: signs_gui.cpp:231
SignList::SignNameSorter
static bool SignNameSorter(const Sign *const &a, const Sign *const &b)
Sort signs by their name.
Definition: signs_gui.cpp:73
SignID
uint16 SignID
The type of the IDs of signs.
Definition: signs_type.h:14
debug.h
AWV_DECREASE
@ AWV_DECREASE
Arrow to the left or in case of RTL to the right.
Definition: widget_type.h:35
WID_SIL_FILTER_TEXT
@ WID_SIL_FILTER_TEXT
Text box for typing a filter string.
Definition: sign_widget.h:19
WID_SIL_FILTER_MATCH_CASE_BTN
@ WID_SIL_FILTER_MATCH_CASE_BTN
Button to toggle if case sensitive filtering should be used.
Definition: sign_widget.h:20
RenameSign
static bool RenameSign(SignID index, const char *text)
Actually rename the sign.
Definition: signs_gui.cpp:413
TileVirtXY
static TileIndex TileVirtXY(uint x, uint y)
Get a tile from the virtual XY-coordinate.
Definition: map_func.h:194
Hotkey
All data for a single hotkey.
Definition: hotkeys.h:22
hotkeys.h
WWT_SHADEBOX
@ WWT_SHADEBOX
Shade box (at top-right of a window, between WWT_DEBUGBOX and WWT_DEFSIZEBOX)
Definition: widget_type.h:62
Window::Close
virtual void Close()
Hide the window and all its child windows, and mark them for a later deletion.
Definition: window.cpp:1092