OpenTTD Source  12.0-beta2
textfile_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 "fileio_func.h"
12 #include "fontcache.h"
13 #include "gfx_type.h"
14 #include "gfx_func.h"
15 #include "string_func.h"
16 #include "textfile_gui.h"
17 
18 #include "widgets/misc_widget.h"
19 
20 #include "table/strings.h"
21 
22 #if defined(WITH_ZLIB)
23 #include <zlib.h>
24 #endif
25 
26 #if defined(WITH_LIBLZMA)
27 #include <lzma.h>
28 #endif
29 
30 #include "safeguards.h"
31 
35  NWidget(WWT_CLOSEBOX, COLOUR_MAUVE),
36  NWidget(WWT_CAPTION, COLOUR_MAUVE, WID_TF_CAPTION), SetDataTip(STR_NULL, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
37  NWidget(WWT_TEXTBTN, COLOUR_MAUVE, WID_TF_WRAPTEXT), SetDataTip(STR_TEXTFILE_WRAP_TEXT, STR_TEXTFILE_WRAP_TEXT_TOOLTIP),
38  NWidget(WWT_DEFSIZEBOX, COLOUR_MAUVE),
39  EndContainer(),
42  EndContainer(),
45  EndContainer(),
46  EndContainer(),
49  NWidget(WWT_RESIZEBOX, COLOUR_MAUVE),
50  EndContainer(),
51 };
52 
55  WDP_CENTER, "textfile", 630, 460,
57  0,
59 );
60 
61 TextfileWindow::TextfileWindow(TextfileType file_type) : Window(&_textfile_desc), file_type(file_type)
62 {
63  this->CreateNestedTree();
64  this->vscroll = this->GetScrollbar(WID_TF_VSCROLLBAR);
65  this->hscroll = this->GetScrollbar(WID_TF_HSCROLLBAR);
66  this->FinishInitNested(file_type);
67  this->GetWidget<NWidgetCore>(WID_TF_CAPTION)->SetDataTip(STR_TEXTFILE_README_CAPTION + file_type, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS);
68 
69  this->hscroll->SetStepSize(10); // Speed up horizontal scrollbar
70 }
71 
72 /* virtual */ TextfileWindow::~TextfileWindow()
73 {
74  free(this->text);
75 }
76 
82 {
83  uint height = 0;
85  for (auto &line : this->lines) {
86  line.top = height;
87  height++;
88  line.bottom = height;
89  }
90  } else {
91  int max_width = this->GetWidget<NWidgetCore>(WID_TF_BACKGROUND)->current_x - WD_FRAMETEXT_LEFT - WD_FRAMERECT_RIGHT;
92  for (auto &line : this->lines) {
93  line.top = height;
94  height += GetStringHeight(line.text, max_width, FS_MONO) / FONT_HEIGHT_MONO;
95  line.bottom = height;
96  }
97  }
98 
99  return height;
100 }
101 
102 uint TextfileWindow::GetContentHeight()
103 {
104  if (this->lines.size() == 0) return 0;
105  return this->lines.back().bottom;
106 }
107 
108 /* virtual */ void TextfileWindow::UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
109 {
110  switch (widget) {
111  case WID_TF_BACKGROUND:
112  resize->height = FONT_HEIGHT_MONO;
113 
114  size->height = 4 * resize->height + TOP_SPACING + BOTTOM_SPACING; // At least 4 lines are visible.
115  size->width = std::max(200u, size->width); // At least 200 pixels wide.
116  break;
117  }
118 }
119 
121 void TextfileWindow::SetupScrollbars(bool force_reflow)
122 {
124  /* Reflow is mandatory if text wrapping is on */
125  uint height = this->ReflowContent();
126  this->vscroll->SetCount(std::min<uint>(UINT16_MAX, height));
127  this->hscroll->SetCount(0);
128  } else {
129  uint height = force_reflow ? this->ReflowContent() : this->GetContentHeight();
130  this->vscroll->SetCount(std::min<uint>(UINT16_MAX, height));
132  }
133 
135 }
136 
137 /* virtual */ void TextfileWindow::OnClick(Point pt, int widget, int click_count)
138 {
139  switch (widget) {
140  case WID_TF_WRAPTEXT:
142  this->InvalidateData();
143  break;
144  }
145 }
146 
147 /* virtual */ void TextfileWindow::DrawWidget(const Rect &r, int widget) const
148 {
149  if (widget != WID_TF_BACKGROUND) return;
150 
151  const int x = r.left + WD_FRAMETEXT_LEFT;
152  const int y = r.top + WD_FRAMETEXT_TOP;
153  const int right = r.right - WD_FRAMETEXT_RIGHT;
154  const int bottom = r.bottom - WD_FRAMETEXT_BOTTOM;
155 
156  DrawPixelInfo new_dpi;
157  if (!FillDrawPixelInfo(&new_dpi, x, y, right - x + 1, bottom - y + 1)) return;
158  DrawPixelInfo *old_dpi = _cur_dpi;
159  _cur_dpi = &new_dpi;
160 
161  /* Draw content (now coordinates given to DrawString* are local to the new clipping region). */
162  int line_height = FONT_HEIGHT_MONO;
163  int pos = this->vscroll->GetPosition();
164  int cap = this->vscroll->GetCapacity();
165 
166  for (auto &line : this->lines) {
167  if (line.bottom < pos) continue;
168  if (line.top > pos + cap) break;
169 
170  int y_offset = (line.top - pos) * line_height;
172  DrawStringMultiLine(0, right - x, y_offset, bottom - y, line.text, TC_WHITE, SA_TOP | SA_LEFT, false, FS_MONO);
173  } else {
174  DrawString(-this->hscroll->GetPosition(), right - x, y_offset, line.text, TC_WHITE, SA_TOP | SA_LEFT, false, FS_MONO);
175  }
176  }
177 
178  _cur_dpi = old_dpi;
179 }
180 
181 /* virtual */ void TextfileWindow::OnResize()
182 {
185 
186  this->SetupScrollbars(false);
187 }
188 
189 /* virtual */ void TextfileWindow::OnInvalidateData(int data, bool gui_scope)
190 {
191  if (!gui_scope) return;
192 
193  this->SetupScrollbars(true);
194 }
195 
196 /* virtual */ void TextfileWindow::Reset()
197 {
198  this->search_iterator = 0;
199 }
200 
202 {
203  return FS_MONO;
204 }
205 
206 /* virtual */ const char *TextfileWindow::NextString()
207 {
208  if (this->search_iterator >= this->lines.size()) return nullptr;
209 
210  return this->lines[this->search_iterator++].text;
211 }
212 
213 /* virtual */ bool TextfileWindow::Monospace()
214 {
215  return true;
216 }
217 
218 /* virtual */ void TextfileWindow::SetFontNames(FreeTypeSettings *settings, const char *font_name, const void *os_data)
219 {
220 #if defined(WITH_FREETYPE) || defined(_WIN32) || defined(WITH_COCOA)
221  settings->mono.font = font_name;
222  settings->mono.os_handle = os_data;
223 #endif
224 }
225 
226 #if defined(WITH_ZLIB)
227 
242 static void Gunzip(byte **bufp, size_t *sizep)
243 {
244  static const int BLOCKSIZE = 8192;
245  byte *buf = nullptr;
246  size_t alloc_size = 0;
247  z_stream z;
248  int res;
249 
250  memset(&z, 0, sizeof(z));
251  z.next_in = *bufp;
252  z.avail_in = (uInt)*sizep;
253 
254  /* window size = 15, add 32 to enable gzip or zlib header processing */
255  res = inflateInit2(&z, 15 + 32);
256  /* Z_BUF_ERROR just means we need more space */
257  while (res == Z_OK || (res == Z_BUF_ERROR && z.avail_out == 0)) {
258  /* When we get here, we're either just starting, or
259  * inflate is out of output space - allocate more */
260  alloc_size += BLOCKSIZE;
261  z.avail_out += BLOCKSIZE;
262  buf = ReallocT(buf, alloc_size);
263  z.next_out = buf + alloc_size - z.avail_out;
264  res = inflate(&z, Z_FINISH);
265  }
266 
267  free(*bufp);
268  inflateEnd(&z);
269 
270  if (res == Z_STREAM_END) {
271  *bufp = buf;
272  *sizep = alloc_size - z.avail_out;
273  } else {
274  /* Something went wrong */
275  *bufp = nullptr;
276  *sizep = 0;
277  free(buf);
278  }
279 }
280 #endif
281 
282 #if defined(WITH_LIBLZMA)
283 
298 static void Xunzip(byte **bufp, size_t *sizep)
299 {
300  static const int BLOCKSIZE = 8192;
301  byte *buf = nullptr;
302  size_t alloc_size = 0;
303  lzma_stream z = LZMA_STREAM_INIT;
304  int res;
305 
306  z.next_in = *bufp;
307  z.avail_in = *sizep;
308 
309  res = lzma_auto_decoder(&z, UINT64_MAX, LZMA_CONCATENATED);
310  /* Z_BUF_ERROR just means we need more space */
311  while (res == LZMA_OK || (res == LZMA_BUF_ERROR && z.avail_out == 0)) {
312  /* When we get here, we're either just starting, or
313  * inflate is out of output space - allocate more */
314  alloc_size += BLOCKSIZE;
315  z.avail_out += BLOCKSIZE;
316  buf = ReallocT(buf, alloc_size);
317  z.next_out = buf + alloc_size - z.avail_out;
318  res = lzma_code(&z, LZMA_FINISH);
319  }
320 
321  free(*bufp);
322  lzma_end(&z);
323 
324  if (res == LZMA_STREAM_END) {
325  *bufp = buf;
326  *sizep = alloc_size - z.avail_out;
327  } else {
328  /* Something went wrong */
329  *bufp = nullptr;
330  *sizep = 0;
331  free(buf);
332  }
333 }
334 #endif
335 
336 
340 /* virtual */ void TextfileWindow::LoadTextfile(const char *textfile, Subdirectory dir)
341 {
342  if (textfile == nullptr) return;
343 
344  this->lines.clear();
345 
346  /* Get text from file */
347  size_t filesize;
348  FILE *handle = FioFOpenFile(textfile, "rb", dir, &filesize);
349  if (handle == nullptr) return;
350 
351  this->text = ReallocT(this->text, filesize);
352  size_t read = fread(this->text, 1, filesize, handle);
353  fclose(handle);
354 
355  if (read != filesize) return;
356 
357 #if defined(WITH_ZLIB) || defined(WITH_LIBLZMA)
358  const char *suffix = strrchr(textfile, '.');
359  if (suffix == nullptr) return;
360 #endif
361 
362 #if defined(WITH_ZLIB)
363  /* In-place gunzip */
364  if (strcmp(suffix, ".gz") == 0) Gunzip((byte**)&this->text, &filesize);
365 #endif
366 
367 #if defined(WITH_LIBLZMA)
368  /* In-place xunzip */
369  if (strcmp(suffix, ".xz") == 0) Xunzip((byte**)&this->text, &filesize);
370 #endif
371 
372  if (!this->text) return;
373 
374  /* Add space for trailing \0 */
375  this->text = ReallocT(this->text, filesize + 1);
376  this->text[filesize] = '\0';
377 
378  /* Replace tabs and line feeds with a space since StrMakeValidInPlace removes those. */
379  for (char *p = this->text; *p != '\0'; p++) {
380  if (*p == '\t' || *p == '\r') *p = ' ';
381  }
382 
383  /* Check for the byte-order-mark, and skip it if needed. */
384  char *p = this->text + (strncmp(u8"\ufeff", this->text, 3) == 0 ? 3 : 0);
385 
386  /* Make sure the string is a valid UTF-8 sequence. */
388 
389  /* Split the string on newlines. */
390  int row = 0;
391  this->lines.emplace_back(row, p);
392  for (; *p != '\0'; p++) {
393  if (*p == '\n') {
394  *p = '\0';
395  this->lines.emplace_back(++row, p + 1);
396  }
397  }
398 
399  /* Calculate maximum text line length. */
400  uint max_length = 0;
401  for (auto &line : this->lines) {
402  max_length = std::max(max_length, GetStringBoundingBox(line.text, FS_MONO).width);
403  }
404  this->max_length = max_length;
405 
406  CheckForMissingGlyphs(true, this);
407 }
408 
416 const char *GetTextfile(TextfileType type, Subdirectory dir, const char *filename)
417 {
418  static const char * const prefixes[] = {
419  "readme",
420  "changelog",
421  "license",
422  };
423  static_assert(lengthof(prefixes) == TFT_END);
424 
425  const char *prefix = prefixes[type];
426 
427  if (filename == nullptr) return nullptr;
428 
429  static char file_path[MAX_PATH];
430  strecpy(file_path, filename, lastof(file_path));
431 
432  char *slash = strrchr(file_path, PATHSEPCHAR);
433  if (slash == nullptr) return nullptr;
434 
435  static const char * const exts[] = {
436  "txt",
437 #if defined(WITH_ZLIB)
438  "txt.gz",
439 #endif
440 #if defined(WITH_LIBLZMA)
441  "txt.xz",
442 #endif
443  };
444 
445  for (size_t i = 0; i < lengthof(exts); i++) {
446  seprintf(slash + 1, lastof(file_path), "%s_%s.%s", prefix, GetCurrentLanguageIsoCode(), exts[i]);
447  if (FioCheckFileExists(file_path, dir)) return file_path;
448 
449  seprintf(slash + 1, lastof(file_path), "%s_%.2s.%s", prefix, GetCurrentLanguageIsoCode(), exts[i]);
450  if (FioCheckFileExists(file_path, dir)) return file_path;
451 
452  seprintf(slash + 1, lastof(file_path), "%s.%s", prefix, exts[i]);
453  if (FioCheckFileExists(file_path, dir)) return file_path;
454  }
455  return nullptr;
456 }
TextfileWindow::DefaultSize
FontSize DefaultSize() override
Get the default (font) size of the string.
Definition: textfile_gui.cpp:201
WID_TF_HSCROLLBAR
@ WID_TF_HSCROLLBAR
Horizontal scrollbar to scroll through the textfile left-to-right.
Definition: misc_widget.h:55
TextfileWindow::LoadTextfile
virtual void LoadTextfile(const char *textfile, Subdirectory dir)
Loads the textfile text from file and setup lines.
Definition: textfile_gui.cpp:340
SVS_ALLOW_NEWLINE
@ SVS_ALLOW_NEWLINE
Allow newlines.
Definition: string_type.h:51
SetScrollbar
static NWidgetPart SetScrollbar(int index)
Attach a scrollbar to a widget.
Definition: widget_type.h:1188
GetCurrentLanguageIsoCode
const char * GetCurrentLanguageIsoCode()
Get the ISO language code of the currently loaded language.
Definition: strings.cpp:2003
TextfileWindow::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: textfile_gui.cpp:108
Dimension
Dimensions (a width and height) of a rectangle in 2D.
Definition: geometry_type.hpp:27
Scrollbar::GetCapacity
uint16 GetCapacity() const
Gets the number of visible elements of the scrollbar.
Definition: widget_type.h:662
Xunzip
static void Xunzip(byte **bufp, size_t *sizep)
Do an in-memory xunzip operation.
Definition: textfile_gui.cpp:298
NWID_HSCROLLBAR
@ NWID_HSCROLLBAR
Horizontal scrollbar.
Definition: widget_type.h:81
WWT_CAPTION
@ WWT_CAPTION
Window caption (window title between closebox and stickybox)
Definition: widget_type.h:59
Gunzip
static void Gunzip(byte **bufp, size_t *sizep)
Do an in-memory gunzip operation.
Definition: textfile_gui.cpp:242
TextfileWindow::ReflowContent
uint ReflowContent()
Get the total height of the content displayed in this window, if wrapping is disabled.
Definition: textfile_gui.cpp:81
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
NWID_HORIZONTAL
@ NWID_HORIZONTAL
Horizontal container.
Definition: widget_type.h:73
TextfileWindow::OnResize
void OnResize() override
Called after the window got resized.
Definition: textfile_gui.cpp:181
Scrollbar::SetCount
void SetCount(int num)
Sets the number of elements in the list.
Definition: widget_type.h:710
TextfileWindow::OnInvalidateData
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
Definition: textfile_gui.cpp:189
TextfileWindow::BOTTOM_SPACING
static const int BOTTOM_SPACING
Additional spacing at the bottom of the WID_TF_BACKGROUND widget.
Definition: textfile_gui.h:40
SetResize
static NWidgetPart SetResize(int16 dx, int16 dy)
Widget part function for setting the resize step.
Definition: widget_type.h:993
fileio_func.h
WD_FRAMETEXT_TOP
@ WD_FRAMETEXT_TOP
Top offset of the text of the frame.
Definition: window_gui.h:74
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
_nested_textfile_widgets
static const NWidgetPart _nested_textfile_widgets[]
Widgets for the textfile window.
Definition: textfile_gui.cpp:33
WD_FRAMETEXT_LEFT
@ WD_FRAMETEXT_LEFT
Left offset of the text of the frame.
Definition: window_gui.h:72
NWidgetPart
Partial widget specification to allow NWidgets to be written nested.
Definition: widget_type.h:971
textfile_gui.h
SetDataTip
static NWidgetPart SetDataTip(uint32 data, StringID tip)
Widget part function for setting the data and tooltip.
Definition: widget_type.h:1107
GetStringBoundingBox
Dimension GetStringBoundingBox(const char *str, FontSize start_fontsize)
Return the string dimension in pixels.
Definition: gfx.cpp:888
DrawStringMultiLine
int DrawStringMultiLine(int left, int right, int top, int bottom, const char *str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly over multiple lines.
Definition: gfx.cpp:787
WID_TF_BACKGROUND
@ WID_TF_BACKGROUND
Panel to draw the textfile on.
Definition: misc_widget.h:53
gfx_func.h
WindowDesc
High level window description.
Definition: window_gui.h:168
TextfileWindow::SetFontNames
void SetFontNames(FreeTypeSettings *settings, const char *font_name, const void *os_data) override
Set the right font names.
Definition: textfile_gui.cpp:218
WID_TF_WRAPTEXT
@ WID_TF_WRAPTEXT
Whether or not to wrap the text.
Definition: misc_widget.h:52
Window::resize
ResizeInfo resize
Resize information.
Definition: window_gui.h:317
TextfileWindow::TOP_SPACING
static const int TOP_SPACING
Additional spacing at the top of the WID_TF_BACKGROUND widget.
Definition: textfile_gui.h:39
SA_TOP
@ SA_TOP
Top align the text.
Definition: gfx_type.h:333
Window::height
int height
Height of the window (number of pixels down in y direction)
Definition: window_gui.h:315
StrMakeValidInPlace
void StrMakeValidInPlace(char *str, const char *last, StringValidationSettings settings)
Scans the string for invalid characters and replaces then with a question mark '?' (if not ignored).
Definition: string.cpp:255
FioFOpenFile
FILE * FioFOpenFile(const std::string &filename, const char *mode, Subdirectory subdir, size_t *filesize)
Opens a OpenTTD file somewhere in a personal or global directory.
Definition: fileio.cpp:245
WD_FRAMERECT_RIGHT
@ WD_FRAMERECT_RIGHT
Offset at right to draw the frame rectangular area.
Definition: window_gui.h:63
WD_FRAMETEXT_BOTTOM
@ WD_FRAMETEXT_BOTTOM
Bottom offset of the text of the frame.
Definition: window_gui.h:75
FONT_HEIGHT_MONO
#define FONT_HEIGHT_MONO
Height of characters in the large (FS_MONO) font.
Definition: gfx_func.h:171
Window::SetWidgetDisabledState
void SetWidgetDisabledState(byte widget_index, bool disab_stat)
Sets the enabled/disabled status of a widget.
Definition: window_gui.h:386
safeguards.h
TextfileWindow::SetupScrollbars
void SetupScrollbars(bool force_reflow)
Set scrollbars to the right lengths.
Definition: textfile_gui.cpp:121
TextfileWindow::NextString
const char * NextString() override
Get the next string to search through.
Definition: textfile_gui.cpp:206
settings
fluid_settings_t * settings
FluidSynth settings handle.
Definition: fluidsynth.cpp:21
TextfileWindow::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: textfile_gui.cpp:137
Point
Coordinates of a point in 2D.
Definition: geometry_type.hpp:21
WD_FRAMETEXT_RIGHT
@ WD_FRAMETEXT_RIGHT
Right offset of the text of the frame.
Definition: window_gui.h:73
stdafx.h
TextfileWindow::text
char * text
Lines of text from the NewGRF's textfile.
Definition: textfile_gui.h:33
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
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
FillDrawPixelInfo
bool FillDrawPixelInfo(DrawPixelInfo *n, int left, int top, int width, int height)
Set up a clipping area for only drawing into a certain area.
Definition: gfx.cpp:1708
GetStringHeight
int GetStringHeight(const char *str, int maxw, FontSize fontsize)
Calculates height of string (in pixels).
Definition: gfx.cpp:713
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
string_func.h
TextfileWindow::hscroll
Scrollbar * hscroll
Horizontal scrollbar.
Definition: textfile_gui.h:32
TextfileWindow::max_length
uint max_length
Maximum length of unwrapped text line.
Definition: textfile_gui.h:37
TextfileWindow::Reset
void Reset() override
Reset the search, i.e.
Definition: textfile_gui.cpp:196
EndContainer
static NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME,...
Definition: widget_type.h:1092
NWID_VSCROLLBAR
@ NWID_VSCROLLBAR
Vertical scrollbar.
Definition: widget_type.h:82
TextfileWindow::search_iterator
uint search_iterator
Iterator for the font check search.
Definition: textfile_gui.h:35
GetTextfile
const char * GetTextfile(TextfileType type, Subdirectory dir, const char *filename)
Search a textfile file next to the given content.
Definition: textfile_gui.cpp:416
FioCheckFileExists
bool FioCheckFileExists(const std::string &filename, Subdirectory subdir)
Check whether the given file exists.
Definition: fileio.cpp:108
WID_TF_VSCROLLBAR
@ WID_TF_VSCROLLBAR
Vertical scrollbar to scroll through the textfile up-and-down.
Definition: misc_widget.h:54
TextfileWindow::DrawWidget
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
Definition: textfile_gui.cpp:147
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
SetMinimalSize
static NWidgetPart SetMinimalSize(int16 x, int16 y)
Widget part function for setting the minimal size.
Definition: widget_type.h:1010
WWT_PANEL
@ WWT_PANEL
Simple depressed panel.
Definition: widget_type.h:48
Window::IsWidgetLowered
bool IsWidgetLowered(byte widget_index) const
Gets the lowered state of a widget.
Definition: window_gui.h:487
TextfileWindow::Monospace
bool Monospace() override
Whether to search for a monospace font or not.
Definition: textfile_gui.cpp:213
TextfileWindow::lines
std::vector< Line > lines
text, split into lines in a table with lines.
Definition: textfile_gui.h:34
Scrollbar::GetPosition
uint16 GetPosition() const
Gets the position of the first visible element in the list.
Definition: widget_type.h:671
seprintf
int CDECL seprintf(char *str, const char *last, const char *format,...)
Safer implementation of snprintf; same as snprintf except:
Definition: string.cpp:535
Subdirectory
Subdirectory
The different kinds of subdirectories OpenTTD uses.
Definition: fileio_type.h:108
ReallocT
static T * ReallocT(T *t_ptr, size_t num_elements)
Simplified reallocation function that allocates the specified number of elements of the given type.
Definition: alloc_func.hpp:111
SA_LEFT
@ SA_LEFT
Left align the text.
Definition: gfx_type.h:328
CheckForMissingGlyphs
void CheckForMissingGlyphs(bool base_font, MissingGlyphSearcher *searcher)
Check whether the currently loaded language pack uses characters that the currently loaded font does ...
Definition: strings.cpp:2110
Window::ToggleWidgetLoweredState
void ToggleWidgetLoweredState(byte widget_index)
Invert the lowered/raised status of a widget.
Definition: window_gui.h:457
lengthof
#define lengthof(x)
Return the length of an fixed size array.
Definition: stdafx.h:378
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
FS_MONO
@ FS_MONO
Index of the monospaced font in the font tables.
Definition: gfx_type.h:210
fontcache.h
FontSize
FontSize
Available font sizes.
Definition: gfx_type.h:206
Window
Data structure for an opened window.
Definition: window_gui.h:279
TextfileType
TextfileType
Additional text files accompanying Tar archives.
Definition: textfile_type.h:14
strecpy
char * strecpy(char *dst, const char *src, const char *last)
Copies characters from one buffer to another.
Definition: string.cpp:112
WID_TF_CAPTION
@ WID_TF_CAPTION
The caption of the window.
Definition: misc_widget.h:51
free
static void free(const void *ptr)
Version of the standard free that accepts const pointers.
Definition: stdafx.h:460
gfx_type.h
Rect
Specification of a rectangle with absolute coordinates of all edges.
Definition: geometry_type.hpp:47
WC_TEXTFILE
@ WC_TEXTFILE
textfile; Window numbers:
Definition: window_type.h:179
lastof
#define lastof(x)
Get the last element of an fixed size array.
Definition: stdafx.h:394
SVS_REPLACE_WITH_QUESTION_MARK
@ SVS_REPLACE_WITH_QUESTION_MARK
Replace the unknown/bad bits with question marks.
Definition: string_type.h:50
WDP_CENTER
@ WDP_CENTER
Center the window.
Definition: window_gui.h:157
misc_widget.h
_textfile_desc
static WindowDesc _textfile_desc(WDP_CENTER, "textfile", 630, 460, WC_TEXTFILE, WC_NONE, 0, _nested_textfile_widgets, lengthof(_nested_textfile_widgets))
Window definition for the textfile window.
WWT_TEXTBTN
@ WWT_TEXTBTN
(Toggle) Button with text
Definition: widget_type.h:53
FreeTypeSettings
Settings for the freetype fonts.
Definition: fontcache.h:225
TextfileWindow::vscroll
Scrollbar * vscroll
Vertical scrollbar.
Definition: textfile_gui.h:31
DrawPixelInfo
Data about how and where to blit pixels.
Definition: gfx_type.h:155