OpenTTD Source  13.2.1
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 - WidgetDimensions::scaled.frametext.Horizontal();
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 + WidgetDimensions::scaled.frametext.Vertical(); // 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));
131  this->hscroll->SetCount(this->max_length + WidgetDimensions::scaled.frametext.Horizontal());
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  Rect fr = r.Shrink(WidgetDimensions::scaled.frametext);
152 
153  DrawPixelInfo new_dpi;
154  if (!FillDrawPixelInfo(&new_dpi, fr.left, fr.top, fr.Width(), fr.Height())) return;
155  DrawPixelInfo *old_dpi = _cur_dpi;
156  _cur_dpi = &new_dpi;
157 
158  /* Draw content (now coordinates given to DrawString* are local to the new clipping region). */
159  fr = fr.Translate(-fr.left, -fr.top);
160  int line_height = FONT_HEIGHT_MONO;
161  int pos = this->vscroll->GetPosition();
162  int cap = this->vscroll->GetCapacity();
163 
164  for (auto &line : this->lines) {
165  if (line.bottom < pos) continue;
166  if (line.top > pos + cap) break;
167 
168  int y_offset = (line.top - pos) * line_height;
170  DrawStringMultiLine(0, fr.right, y_offset, fr.bottom, line.text, TC_BLACK, SA_TOP | SA_LEFT, false, FS_MONO);
171  } else {
172  DrawString(-this->hscroll->GetPosition(), fr.right, y_offset, line.text, TC_BLACK, SA_TOP | SA_LEFT, false, FS_MONO);
173  }
174  }
175 
176  _cur_dpi = old_dpi;
177 }
178 
179 /* virtual */ void TextfileWindow::OnResize()
180 {
181  this->vscroll->SetCapacityFromWidget(this, WID_TF_BACKGROUND, WidgetDimensions::scaled.frametext.Vertical());
183 
184  this->SetupScrollbars(false);
185 }
186 
187 /* virtual */ void TextfileWindow::OnInvalidateData(int data, bool gui_scope)
188 {
189  if (!gui_scope) return;
190 
191  this->SetupScrollbars(true);
192 }
193 
194 /* virtual */ void TextfileWindow::Reset()
195 {
196  this->search_iterator = 0;
197 }
198 
200 {
201  return FS_MONO;
202 }
203 
204 /* virtual */ const char *TextfileWindow::NextString()
205 {
206  if (this->search_iterator >= this->lines.size()) return nullptr;
207 
208  return this->lines[this->search_iterator++].text;
209 }
210 
211 /* virtual */ bool TextfileWindow::Monospace()
212 {
213  return true;
214 }
215 
216 /* virtual */ void TextfileWindow::SetFontNames(FontCacheSettings *settings, const char *font_name, const void *os_data)
217 {
218 #if defined(WITH_FREETYPE) || defined(_WIN32) || defined(WITH_COCOA)
219  settings->mono.font = font_name;
220  settings->mono.os_handle = os_data;
221 #endif
222 }
223 
224 #if defined(WITH_ZLIB)
225 
240 static void Gunzip(byte **bufp, size_t *sizep)
241 {
242  static const int BLOCKSIZE = 8192;
243  byte *buf = nullptr;
244  size_t alloc_size = 0;
245  z_stream z;
246  int res;
247 
248  memset(&z, 0, sizeof(z));
249  z.next_in = *bufp;
250  z.avail_in = (uInt)*sizep;
251 
252  /* window size = 15, add 32 to enable gzip or zlib header processing */
253  res = inflateInit2(&z, 15 + 32);
254  /* Z_BUF_ERROR just means we need more space */
255  while (res == Z_OK || (res == Z_BUF_ERROR && z.avail_out == 0)) {
256  /* When we get here, we're either just starting, or
257  * inflate is out of output space - allocate more */
258  alloc_size += BLOCKSIZE;
259  z.avail_out += BLOCKSIZE;
260  buf = ReallocT(buf, alloc_size);
261  z.next_out = buf + alloc_size - z.avail_out;
262  res = inflate(&z, Z_FINISH);
263  }
264 
265  free(*bufp);
266  inflateEnd(&z);
267 
268  if (res == Z_STREAM_END) {
269  *bufp = buf;
270  *sizep = alloc_size - z.avail_out;
271  } else {
272  /* Something went wrong */
273  *bufp = nullptr;
274  *sizep = 0;
275  free(buf);
276  }
277 }
278 #endif
279 
280 #if defined(WITH_LIBLZMA)
281 
296 static void Xunzip(byte **bufp, size_t *sizep)
297 {
298  static const int BLOCKSIZE = 8192;
299  byte *buf = nullptr;
300  size_t alloc_size = 0;
301  lzma_stream z = LZMA_STREAM_INIT;
302  int res;
303 
304  z.next_in = *bufp;
305  z.avail_in = *sizep;
306 
307  res = lzma_auto_decoder(&z, UINT64_MAX, LZMA_CONCATENATED);
308  /* Z_BUF_ERROR just means we need more space */
309  while (res == LZMA_OK || (res == LZMA_BUF_ERROR && z.avail_out == 0)) {
310  /* When we get here, we're either just starting, or
311  * inflate is out of output space - allocate more */
312  alloc_size += BLOCKSIZE;
313  z.avail_out += BLOCKSIZE;
314  buf = ReallocT(buf, alloc_size);
315  z.next_out = buf + alloc_size - z.avail_out;
316  res = lzma_code(&z, LZMA_FINISH);
317  }
318 
319  free(*bufp);
320  lzma_end(&z);
321 
322  if (res == LZMA_STREAM_END) {
323  *bufp = buf;
324  *sizep = alloc_size - z.avail_out;
325  } else {
326  /* Something went wrong */
327  *bufp = nullptr;
328  *sizep = 0;
329  free(buf);
330  }
331 }
332 #endif
333 
334 
338 /* virtual */ void TextfileWindow::LoadTextfile(const char *textfile, Subdirectory dir)
339 {
340  if (textfile == nullptr) return;
341 
342  this->lines.clear();
343 
344  /* Get text from file */
345  size_t filesize;
346  FILE *handle = FioFOpenFile(textfile, "rb", dir, &filesize);
347  if (handle == nullptr) return;
348 
349  this->text = ReallocT(this->text, filesize);
350  size_t read = fread(this->text, 1, filesize, handle);
351  fclose(handle);
352 
353  if (read != filesize) return;
354 
355 #if defined(WITH_ZLIB) || defined(WITH_LIBLZMA)
356  const char *suffix = strrchr(textfile, '.');
357  if (suffix == nullptr) return;
358 #endif
359 
360 #if defined(WITH_ZLIB)
361  /* In-place gunzip */
362  if (strcmp(suffix, ".gz") == 0) Gunzip((byte**)&this->text, &filesize);
363 #endif
364 
365 #if defined(WITH_LIBLZMA)
366  /* In-place xunzip */
367  if (strcmp(suffix, ".xz") == 0) Xunzip((byte**)&this->text, &filesize);
368 #endif
369 
370  if (!this->text) return;
371 
372  /* Add space for trailing \0 */
373  this->text = ReallocT(this->text, filesize + 1);
374  this->text[filesize] = '\0';
375 
376  /* Replace tabs and line feeds with a space since StrMakeValidInPlace removes those. */
377  for (char *p = this->text; *p != '\0'; p++) {
378  if (*p == '\t' || *p == '\r') *p = ' ';
379  }
380 
381  /* Check for the byte-order-mark, and skip it if needed. */
382  char *p = this->text + (strncmp(u8"\ufeff", this->text, 3) == 0 ? 3 : 0);
383 
384  /* Make sure the string is a valid UTF-8 sequence. */
386 
387  /* Split the string on newlines. */
388  int row = 0;
389  this->lines.emplace_back(row, p);
390  for (; *p != '\0'; p++) {
391  if (*p == '\n') {
392  *p = '\0';
393  this->lines.emplace_back(++row, p + 1);
394  }
395  }
396 
397  /* Calculate maximum text line length. */
398  uint max_length = 0;
399  for (auto &line : this->lines) {
400  max_length = std::max(max_length, GetStringBoundingBox(line.text, FS_MONO).width);
401  }
402  this->max_length = max_length;
403 
404  CheckForMissingGlyphs(true, this);
405 }
406 
414 const char *GetTextfile(TextfileType type, Subdirectory dir, const char *filename)
415 {
416  static const char * const prefixes[] = {
417  "readme",
418  "changelog",
419  "license",
420  };
421  static_assert(lengthof(prefixes) == TFT_END);
422 
423  const char *prefix = prefixes[type];
424 
425  if (filename == nullptr) return nullptr;
426 
427  static char file_path[MAX_PATH];
428  strecpy(file_path, filename, lastof(file_path));
429 
430  char *slash = strrchr(file_path, PATHSEPCHAR);
431  if (slash == nullptr) return nullptr;
432 
433  static const char * const exts[] = {
434  "txt",
435 #if defined(WITH_ZLIB)
436  "txt.gz",
437 #endif
438 #if defined(WITH_LIBLZMA)
439  "txt.xz",
440 #endif
441  };
442 
443  for (size_t i = 0; i < lengthof(exts); i++) {
444  seprintf(slash + 1, lastof(file_path), "%s_%s.%s", prefix, GetCurrentLanguageIsoCode(), exts[i]);
445  if (FioCheckFileExists(file_path, dir)) return file_path;
446 
447  seprintf(slash + 1, lastof(file_path), "%s_%.2s.%s", prefix, GetCurrentLanguageIsoCode(), exts[i]);
448  if (FioCheckFileExists(file_path, dir)) return file_path;
449 
450  seprintf(slash + 1, lastof(file_path), "%s.%s", prefix, exts[i]);
451  if (FioCheckFileExists(file_path, dir)) return file_path;
452  }
453  return nullptr;
454 }
TextfileWindow::DefaultSize
FontSize DefaultSize() override
Get the default (font) size of the string.
Definition: textfile_gui.cpp:199
WID_TF_HSCROLLBAR
@ WID_TF_HSCROLLBAR
Horizontal scrollbar to scroll through the textfile left-to-right.
Definition: misc_widget.h:55
Rect::Height
int Height() const
Get height of Rect.
Definition: geometry_type.hpp:85
TextfileWindow::LoadTextfile
virtual void LoadTextfile(const char *textfile, Subdirectory dir)
Loads the textfile text from file and setup lines.
Definition: textfile_gui.cpp:338
SVS_ALLOW_NEWLINE
@ SVS_ALLOW_NEWLINE
Allow newlines.
Definition: string_type.h:52
SetScrollbar
static NWidgetPart SetScrollbar(int index)
Attach a scrollbar to a widget.
Definition: widget_type.h:1210
GetCurrentLanguageIsoCode
const char * GetCurrentLanguageIsoCode()
Get the ISO language code of the currently loaded language.
Definition: strings.cpp:2051
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:669
Rect::Shrink
Rect Shrink(int s) const
Copy and shrink Rect by s pixels.
Definition: geometry_type.hpp:92
Xunzip
static void Xunzip(byte **bufp, size_t *sizep)
Do an in-memory xunzip operation.
Definition: textfile_gui.cpp:296
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:240
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:179
Scrollbar::SetCount
void SetCount(int num)
Sets the number of elements in the list.
Definition: widget_type.h:717
TextfileWindow::OnInvalidateData
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
Definition: textfile_gui.cpp:187
SetResize
static NWidgetPart SetResize(int16 dx, int16 dy)
Widget part function for setting the resize step.
Definition: widget_type.h:997
fileio_func.h
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:644
TextfileWindow::SetFontNames
void SetFontNames(FontCacheSettings *settings, const char *font_name, const void *os_data) override
Set the right font names.
Definition: textfile_gui.cpp:216
_nested_textfile_widgets
static const NWidgetPart _nested_textfile_widgets[]
Widgets for the textfile window.
Definition: textfile_gui.cpp:33
NWidgetPart
Partial widget specification to allow NWidgets to be written nested.
Definition: widget_type.h:975
textfile_gui.h
SetDataTip
static NWidgetPart SetDataTip(uint32 data, StringID tip)
Widget part function for setting the data and tooltip.
Definition: widget_type.h:1111
GetStringBoundingBox
Dimension GetStringBoundingBox(const char *str, FontSize start_fontsize)
Return the string dimension in pixels.
Definition: gfx.cpp:890
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:789
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:102
WID_TF_WRAPTEXT
@ WID_TF_WRAPTEXT
Whether or not to wrap the text.
Definition: misc_widget.h:52
FontCacheSettings
Settings for the four different fonts.
Definition: fontcache.h:212
Window::resize
ResizeInfo resize
Resize information.
Definition: window_gui.h:251
SA_TOP
@ SA_TOP
Top align the text.
Definition: gfx_type.h:339
Rect::Translate
Rect Translate(int x, int y) const
Copy and translate Rect by x,y pixels.
Definition: geometry_type.hpp:168
Window::height
int height
Height of the window (number of pixels down in y direction)
Definition: window_gui.h:249
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:273
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
RectPadding::Horizontal
uint Horizontal() const
Get total horizontal padding of RectPadding.
Definition: geometry_type.hpp:59
FONT_HEIGHT_MONO
#define FONT_HEIGHT_MONO
Height of characters in the large (FS_MONO) font.
Definition: gfx_func.h:212
Window::SetWidgetDisabledState
void SetWidgetDisabledState(byte widget_index, bool disab_stat)
Sets the enabled/disabled status of a widget.
Definition: window_gui.h:321
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:204
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
stdafx.h
TextfileWindow::text
char * text
Lines of text from the NewGRF's textfile.
Definition: textfile_gui.h:33
RectPadding::Vertical
uint Vertical() const
Get total vertical padding of RectPadding.
Definition: geometry_type.hpp:65
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:3194
WC_NONE
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
Definition: window_type.h:38
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:1786
GetStringHeight
int GetStringHeight(const char *str, int maxw, FontSize fontsize)
Calculates height of string (in pixels).
Definition: gfx.cpp:715
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:194
EndContainer
static NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME,...
Definition: widget_type.h:1096
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:414
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:1229
SetMinimalSize
static NWidgetPart SetMinimalSize(int16 x, int16 y)
Widget part function for setting the minimal size.
Definition: widget_type.h:1014
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:422
TextfileWindow::Monospace
bool Monospace() override
Whether to search for a monospace font or not.
Definition: textfile_gui.cpp:211
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:678
seprintf
int CDECL seprintf(char *str, const char *last, const char *format,...)
Safer implementation of snprintf; same as snprintf except:
Definition: string.cpp:554
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:334
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:2158
Window::ToggleWidgetLoweredState
void ToggleWidgetLoweredState(byte widget_index)
Invert the lowered/raised status of a widget.
Definition: window_gui.h:392
lengthof
#define lengthof(x)
Return the length of an fixed size array.
Definition: stdafx.h:386
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:2427
FS_MONO
@ FS_MONO
Index of the monospaced font in the font tables.
Definition: gfx_type.h:206
fontcache.h
FontSize
FontSize
Available font sizes.
Definition: gfx_type.h:202
Window
Data structure for an opened window.
Definition: window_gui.h:213
TextfileType
TextfileType
Additional text files accompanying Tar archives.
Definition: textfile_type.h:14
WidgetDimensions::frametext
RectPadding frametext
Offsets within a text frame area.
Definition: window_gui.h:48
Rect::Width
int Width() const
Get width of Rect.
Definition: geometry_type.hpp:79
WidgetDimensions::scaled
static WidgetDimensions scaled
Widget dimensions scaled for current zoom level.
Definition: window_gui.h:68
strecpy
char * strecpy(char *dst, const char *src, const char *last)
Copies characters from one buffer to another.
Definition: string.cpp:113
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:470
gfx_type.h
Rect
Specification of a rectangle with absolute coordinates of all edges.
Definition: geometry_type.hpp:69
WC_TEXTFILE
@ WC_TEXTFILE
textfile; Window numbers:
Definition: window_type.h:180
lastof
#define lastof(x)
Get the last element of an fixed size array.
Definition: stdafx.h:402
SVS_REPLACE_WITH_QUESTION_MARK
@ SVS_REPLACE_WITH_QUESTION_MARK
Replace the unknown/bad bits with question marks.
Definition: string_type.h:51
WDP_CENTER
@ WDP_CENTER
Center the window.
Definition: window_gui.h:91
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
TextfileWindow::vscroll
Scrollbar * vscroll
Vertical scrollbar.
Definition: textfile_gui.h:31
DrawPixelInfo
Data about how and where to blit pixels.
Definition: gfx_type.h:151