OpenTTD

textfile_gui.cpp
Go to the documentation of this file.
1 /* $Id: textfile_gui.cpp 27381 2015-08-10 20:24:13Z michi_cc $ */
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 #include "stdafx.h"
13 #include "fileio_func.h"
14 #include "fontcache.h"
15 #include "gfx_type.h"
16 #include "gfx_func.h"
17 #include "string_func.h"
18 #include "textfile_gui.h"
19
20 #include "widgets/misc_widget.h"
21
22 #include "table/strings.h"
23
24 #if defined(WITH_ZLIB)
25 #include <zlib.h>
26 #endif
27
28 #if defined(WITH_LZMA)
29 #include <lzma.h>
30 #endif
31
32 #include "safeguards.h"
33
35 static const NWidgetPart _nested_textfile_widgets[] = {
36 NWidget(NWID_HORIZONTAL),
37 NWidget(WWT_CLOSEBOX, COLOUR_MAUVE),
38 NWidget(WWT_CAPTION, COLOUR_MAUVE, WID_TF_CAPTION), SetDataTip(STR_NULL, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
39 NWidget(WWT_TEXTBTN, COLOUR_MAUVE, WID_TF_WRAPTEXT), SetDataTip(STR_TEXTFILE_WRAP_TEXT, STR_TEXTFILE_WRAP_TEXT_TOOLTIP),
40 NWidget(WWT_DEFSIZEBOX, COLOUR_MAUVE),
41 EndContainer(),
42 NWidget(NWID_HORIZONTAL),
43 NWidget(WWT_PANEL, COLOUR_MAUVE, WID_TF_BACKGROUND), SetMinimalSize(200, 125), SetResize(1, 12), SetScrollbar(WID_TF_VSCROLLBAR),
44 EndContainer(),
45 NWidget(NWID_VERTICAL),
46 NWidget(NWID_VSCROLLBAR, COLOUR_MAUVE, WID_TF_VSCROLLBAR),
47 EndContainer(),
48 EndContainer(),
49 NWidget(NWID_HORIZONTAL),
50 NWidget(NWID_HSCROLLBAR, COLOUR_MAUVE, WID_TF_HSCROLLBAR),
51 NWidget(WWT_RESIZEBOX, COLOUR_MAUVE),
52 EndContainer(),
53 };
54
56 static WindowDesc _textfile_desc(
57 WDP_CENTER, "textfile", 630, 460,
58 WC_TEXTFILE, WC_NONE,
59 0,
60 _nested_textfile_widgets, lengthof(_nested_textfile_widgets)
61 );
62
63 TextfileWindow::TextfileWindow(TextfileType file_type) : Window(&_textfile_desc), file_type(file_type)
64 {
65 this->CreateNestedTree();
66 this->vscroll = this->GetScrollbar(WID_TF_VSCROLLBAR);
67 this->hscroll = this->GetScrollbar(WID_TF_HSCROLLBAR);
68 this->FinishInitNested();
69 this->GetWidget<NWidgetCore>(WID_TF_CAPTION)->SetDataTip(STR_TEXTFILE_README_CAPTION + file_type, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS);
70
71 this->hscroll->SetStepSize(10); // Speed up horizontal scrollbar
72 this->vscroll->SetStepSize(FONT_HEIGHT_MONO);
73 }
74
75 /* virtual */ TextfileWindow::~TextfileWindow()
76 {
77 free(this->text);
78 }
79
84 uint TextfileWindow::GetContentHeight()
85 {
86 int max_width = this->GetWidget<NWidgetCore>(WID_TF_BACKGROUND)->current_x - WD_FRAMETEXT_LEFT - WD_FRAMERECT_RIGHT;
87
88 uint height = 0;
89 for (uint i = 0; i < this->lines.Length(); i++) {
90 height += GetStringHeight(this->lines[i], max_width, FS_MONO);
91 }
92
93 return height;
94 }
95
96 /* virtual */ void TextfileWindow::UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
97 {
98 switch (widget) {
99 case WID_TF_BACKGROUND:
100 resize->height = 1;
101
102 size->height = 4 * resize->height + TOP_SPACING + BOTTOM_SPACING; // At least 4 lines are visible.
103 size->width = max(200u, size->width); // At least 200 pixels wide.
104 break;
105 }
106 }
107
109 void TextfileWindow::SetupScrollbars()
110 {
111 if (IsWidgetLowered(WID_TF_WRAPTEXT)) {
112 this->vscroll->SetCount(this->GetContentHeight());
113 this->hscroll->SetCount(0);
114 } else {
115 uint max_length = 0;
116 for (uint i = 0; i < this->lines.Length(); i++) {
117 max_length = max(max_length, GetStringBoundingBox(this->lines[i], FS_MONO).width);
118 }
119 this->vscroll->SetCount(this->lines.Length() * FONT_HEIGHT_MONO);
120 this->hscroll->SetCount(max_length + WD_FRAMETEXT_LEFT + WD_FRAMETEXT_RIGHT);
121 }
122
123 this->SetWidgetDisabledState(WID_TF_HSCROLLBAR, IsWidgetLowered(WID_TF_WRAPTEXT));
124 }
125
126 /* virtual */ void TextfileWindow::OnClick(Point pt, int widget, int click_count)
127 {
128 switch (widget) {
129 case WID_TF_WRAPTEXT:
130 this->ToggleWidgetLoweredState(WID_TF_WRAPTEXT);
131 this->SetupScrollbars();
132 this->InvalidateData();
133 break;
134 }
135 }
136
137 /* virtual */ void TextfileWindow::DrawWidget(const Rect &r, int widget) const
138 {
139 if (widget != WID_TF_BACKGROUND) return;
140
141 const int x = r.left + WD_FRAMETEXT_LEFT;
142 const int y = r.top + WD_FRAMETEXT_TOP;
143 const int right = r.right - WD_FRAMETEXT_RIGHT;
144 const int bottom = r.bottom - WD_FRAMETEXT_BOTTOM;
145
146 DrawPixelInfo new_dpi;
147 if (!FillDrawPixelInfo(&new_dpi, x, y, right - x + 1, bottom - y + 1)) return;
148 DrawPixelInfo *old_dpi = _cur_dpi;
149 _cur_dpi = &new_dpi;
150
151 /* Draw content (now coordinates given to DrawString* are local to the new clipping region). */
152 int line_height = FONT_HEIGHT_MONO;
153 int y_offset = -this->vscroll->GetPosition();
154
155 for (uint i = 0; i < this->lines.Length(); i++) {
156 if (IsWidgetLowered(WID_TF_WRAPTEXT)) {
157 y_offset = DrawStringMultiLine(0, right - x, y_offset, bottom - y, this->lines[i], TC_WHITE, SA_TOP | SA_LEFT, false, FS_MONO);
158 } else {
159 DrawString(-this->hscroll->GetPosition(), right - x, y_offset, this->lines[i], TC_WHITE, SA_TOP | SA_LEFT, false, FS_MONO);
160 y_offset += line_height; // margin to previous element
161 }
162 }
163
164 _cur_dpi = old_dpi;
165 }
166
167 /* virtual */ void TextfileWindow::OnResize()
168 {
169 this->vscroll->SetCapacityFromWidget(this, WID_TF_BACKGROUND, TOP_SPACING + BOTTOM_SPACING);
170 this->hscroll->SetCapacityFromWidget(this, WID_TF_BACKGROUND);
171
172 this->SetupScrollbars();
173 }
174
175 /* virtual */ void TextfileWindow::Reset()
176 {
177 this->search_iterator = 0;
178 }
179
180 /* virtual */ FontSize TextfileWindow::DefaultSize()
181 {
182 return FS_MONO;
183 }
184
185 /* virtual */ const char *TextfileWindow::NextString()
186 {
187 if (this->search_iterator >= this->lines.Length()) return NULL;
188
189 return this->lines[this->search_iterator++];
190 }
191
192 /* virtual */ bool TextfileWindow::Monospace()
193 {
194 return true;
195 }
196
197 /* virtual */ void TextfileWindow::SetFontNames(FreeTypeSettings *settings, const char *font_name)
198 {
199 #ifdef WITH_FREETYPE
200 strecpy(settings->mono.font, font_name, lastof(settings->mono.font));
201 #endif /* WITH_FREETYPE */
202 }
203
204 #if defined(WITH_ZLIB)
205
220 static void Gunzip(byte **bufp, size_t *sizep)
221 {
222 static const int BLOCKSIZE = 8192;
223 byte *buf = NULL;
224 size_t alloc_size = 0;
225 z_stream z;
226 int res;
227
228 memset(&z, 0, sizeof(z));
229 z.next_in = *bufp;
230 z.avail_in = (uInt)*sizep;
231
232 /* window size = 15, add 32 to enable gzip or zlib header processing */
233 res = inflateInit2(&z, 15 + 32);
234 /* Z_BUF_ERROR just means we need more space */
235 while (res == Z_OK || (res == Z_BUF_ERROR && z.avail_out == 0)) {
236 /* When we get here, we're either just starting, or
237 * inflate is out of output space - allocate more */
238 alloc_size += BLOCKSIZE;
239 z.avail_out += BLOCKSIZE;
240 buf = ReallocT(buf, alloc_size);
241 z.next_out = buf + alloc_size - z.avail_out;
242 res = inflate(&z, Z_FINISH);
243 }
244
245 free(*bufp);
246 inflateEnd(&z);
247
248 if (res == Z_STREAM_END) {
249 *bufp = buf;
250 *sizep = alloc_size - z.avail_out;
251 } else {
252 /* Something went wrong */
253 *bufp = NULL;
254 *sizep = 0;
255 free(buf);
256 }
257 }
258 #endif
259
260 #if defined(WITH_LZMA)
261
276 static void Xunzip(byte **bufp, size_t *sizep)
277 {
278 static const int BLOCKSIZE = 8192;
279 byte *buf = NULL;
280 size_t alloc_size = 0;
281 lzma_stream z = LZMA_STREAM_INIT;
282 int res;
283
284 z.next_in = *bufp;
285 z.avail_in = *sizep;
286
287 res = lzma_auto_decoder(&z, UINT64_MAX, LZMA_CONCATENATED);
288 /* Z_BUF_ERROR just means we need more space */
289 while (res == LZMA_OK || (res == LZMA_BUF_ERROR && z.avail_out == 0)) {
290 /* When we get here, we're either just starting, or
291 * inflate is out of output space - allocate more */
292 alloc_size += BLOCKSIZE;
293 z.avail_out += BLOCKSIZE;
294 buf = ReallocT(buf, alloc_size);
295 z.next_out = buf + alloc_size - z.avail_out;
296 res = lzma_code(&z, LZMA_FINISH);
297 }
298
299 free(*bufp);
300 lzma_end(&z);
301
302 if (res == LZMA_STREAM_END) {
303 *bufp = buf;
304 *sizep = alloc_size - z.avail_out;
305 } else {
306 /* Something went wrong */
307 *bufp = NULL;
308 *sizep = 0;
309 free(buf);
310 }
311 }
312 #endif
313
314
318 /* virtual */ void TextfileWindow::LoadTextfile(const char *textfile, Subdirectory dir)
319 {
320 if (textfile == NULL) return;
321
322 this->lines.Clear();
323
324 /* Get text from file */
325 size_t filesize;
326 FILE *handle = FioFOpenFile(textfile, "rb", dir, &filesize);
327 if (handle == NULL) return;
328
329 this->text = ReallocT(this->text, filesize);
330 size_t read = fread(this->text, 1, filesize, handle);
331 fclose(handle);
332
333 if (read != filesize) return;
334
335 #if defined(WITH_ZLIB) || defined(WITH_LZMA)
336 const char *suffix = strrchr(textfile, '.');
337 if (suffix == NULL) return;
338 #endif
339
340 #if defined(WITH_ZLIB)
341 /* In-place gunzip */
342 if (strcmp(suffix, ".gz") == 0) Gunzip((byte**)&this->text, &filesize);
343 #endif
344
345 #if defined(WITH_LZMA)
346 /* In-place xunzip */
347 if (strcmp(suffix, ".xz") == 0) Xunzip((byte**)&this->text, &filesize);
348 #endif
349
350 if (!this->text) return;
351
352 /* Add space for trailing \0 */
353 this->text = ReallocT(this->text, filesize + 1);
354 this->text[filesize] = '\0';
355
356 /* Replace tabs and line feeds with a space since str_validate removes those. */
357 for (char *p = this->text; *p != '\0'; p++) {
358 if (*p == '\t' || *p == '\r') *p = ' ';
359 }
360
361 /* Check for the byte-order-mark, and skip it if needed. */
362 char *p = this->text + (strncmp("\xEF\xBB\xBF", this->text, 3) == 0 ? 3 : 0);
363
364 /* Make sure the string is a valid UTF-8 sequence. */
365 str_validate(p, this->text + filesize, SVS_REPLACE_WITH_QUESTION_MARK | SVS_ALLOW_NEWLINE);
366
367 /* Split the string on newlines. */
368 *this->lines.Append() = p;
369 for (; *p != '\0'; p++) {
370 if (*p == '\n') {
371 *p = '\0';
372 *this->lines.Append() = p + 1;
373 }
374 }
375
376 CheckForMissingGlyphs(true, this);
377 }
378
386 const char *GetTextfile(TextfileType type, Subdirectory dir, const char *filename)
387 {
388 static const char * const prefixes[] = {
389 "readme",
390 "changelog",
391 "license",
392 };
393 assert_compile(lengthof(prefixes) == TFT_END);
394
395 const char *prefix = prefixes[type];
396
397 if (filename == NULL) return NULL;
398
399 static char file_path[MAX_PATH];
400 strecpy(file_path, filename, lastof(file_path));
401
402 char *slash = strrchr(file_path, PATHSEPCHAR);
403 if (slash == NULL) return NULL;
404
405 static const char * const exts[] = {
406 "txt",
407 #if defined(WITH_ZLIB)
408 "txt.gz",
409 #endif
410 #if defined(WITH_LZMA)
411 "txt.xz",
412 #endif
413 };
414
415 for (size_t i = 0; i < lengthof(exts); i++) {
416 seprintf(slash + 1, lastof(file_path), "%s_%s.%s", prefix, GetCurrentLanguageIsoCode(), exts[i]);
417 if (FioCheckFileExists(file_path, dir)) return file_path;
418
419 seprintf(slash + 1, lastof(file_path), "%s_%.2s.%s", prefix, GetCurrentLanguageIsoCode(), exts[i]);
420 if (FioCheckFileExists(file_path, dir)) return file_path;
421
422 seprintf(slash + 1, lastof(file_path), "%s.%s", prefix, exts[i]);
423 if (FioCheckFileExists(file_path, dir)) return file_path;
424 }
425 return NULL;
426 }
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:2089
DrawPixelInfo
Data about how and where to blit pixels.
Definition: gfx_type.h:156
Window::resize
ResizeInfo resize
Resize information.
Definition: window_gui.h:317
SetResize
static NWidgetPart SetResize(int16 dx, int16 dy)
Widget part function for setting the resize step.
Definition: widget_type.h:930
Window::SetWidgetDisabledState
void SetWidgetDisabledState(byte widget_index, bool disab_stat)
Sets the enabled/disabled status of a widget.
Definition: window_gui.h:387
Xunzip
static void Xunzip(byte **bufp, size_t *sizep)
Do an in-memory xunzip operation.
Definition: textfile_gui.cpp:276
TextfileWindow::UpdateWidgetSize
virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
Update size and resize step of a widget in the window.
Definition: textfile_gui.cpp:96
Subdirectory
Subdirectory
The different kinds of subdirectories OpenTTD uses.
Definition: fileio_type.h:110
WindowDesc
High level window description.
Definition: window_gui.h:168
TextfileWindow::text
char * text
Lines of text from the NewGRF&#39;s textfile.
Definition: textfile_gui.h:27
_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.
seprintf
int CDECL seprintf(char *str, const char *last, const char *format,...)
Safer implementation of snprintf; same as snprintf except:
Definition: string.cpp:398
WC_TEXTFILE
textfile; Window numbers:
Definition: window_type.h:182
NWID_HORIZONTAL
Horizontal container.
Definition: widget_type.h:75
FONT_HEIGHT_MONO
#define FONT_HEIGHT_MONO
Height of characters in the large (FS_MONO) font.
Definition: gfx_func.h:186
FS_MONO
Index of the monospaced font in the font tables.
Definition: gfx_type.h:207
TextfileWindow::Reset
virtual void Reset()
Reset the search, i.e.
Definition: textfile_gui.cpp:175
Gunzip
static void Gunzip(byte **bufp, size_t *sizep)
Do an in-memory gunzip operation.
Definition: textfile_gui.cpp:220
WWT_RESIZEBOX
Resize box (normally at bottom-right of a window)
Definition: widget_type.h:68
TextfileWindow::DefaultSize
virtual FontSize DefaultSize()
Get the default (font) size of the string.
Definition: textfile_gui.cpp:180
WID_TF_HSCROLLBAR
Horizontal scrollbar to scroll through the textfile left-to-right.
Definition: misc_widget.h:54
SmallVector::Clear
void Clear()
Remove all items from the list.
Definition: smallvec_type.hpp:98
Window::ToggleWidgetLoweredState
void ToggleWidgetLoweredState(byte widget_index)
Invert the lowered/raised status of a widget.
Definition: window_gui.h:458
GetStringHeight
int GetStringHeight(const char *str, int maxw, FontSize fontsize)
Calculates height of string (in pixels).
Definition: gfx.cpp:547
WWT_CLOSEBOX
Close box (at top-left of a window)
Definition: widget_type.h:69
fileio_func.h
Functions for Standard In/Out file operations.
lastof
#define lastof(x)
Get the last element of an fixed size array.
Definition: depend.cpp:50
max
static T max(const T a, const T b)
Returns the maximum of two values.
Definition: math_func.hpp:26
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:1480
FreeTypeSettings
Settings for the freetype fonts.
Definition: fontcache.h:204
SmallVector::Append
T * Append(uint to_add=1)
Append an item and return it.
Definition: smallvec_type.hpp:134
Scrollbar::SetCount
void SetCount(int num)
Sets the number of elements in the list.
Definition: widget_type.h:670
NWidgetPart
Partial widget specification to allow NWidgets to be written nested.
Definition: widget_type.h:910
Window
Data structure for an opened window.
Definition: window_gui.h:271
TextfileWindow::DrawWidget
virtual void DrawWidget(const Rect &r, int widget) const
Draw the contents of a nested widget.
Definition: textfile_gui.cpp:137
fontcache.h
Functions to read fonts from files and cache them.
WD_FRAMETEXT_BOTTOM
Bottom offset of the text of the frame.
Definition: window_gui.h:75
TextfileWindow::GetContentHeight
uint GetContentHeight()
Get the total height of the content displayed in this window, if wrapping is disabled.
Definition: textfile_gui.cpp:84
string_func.h
Functions related to low-level strings.
TextfileWindow::search_iterator
uint search_iterator
Iterator for the font check search.
Definition: textfile_gui.h:29
TextfileWindow::Monospace
virtual bool Monospace()
Whether to search for a monospace font or not.
Definition: textfile_gui.cpp:192
WWT_DEFSIZEBOX
Default window size box (at top-right of a window, between WWT_SHADEBOX and WWT_STICKYBOX) ...
Definition: widget_type.h:65
SmallVector::Length
uint Length() const
Get the number of items in the list.
Definition: smallvec_type.hpp:262
Window::IsWidgetLowered
bool IsWidgetLowered(byte widget_index) const
Gets the lowered state of a widget.
Definition: window_gui.h:488
str_validate
void str_validate(char *str, const char *last, StringValidationSettings settings)
Scans the string for valid characters and if it finds invalid ones, replaces them with a question mar...
Definition: string.cpp:184
FreeTypeSettings::mono
FreeTypeSubSetting mono
The mono space font used for license/readme viewers.
Definition: fontcache.h:208
WID_TF_WRAPTEXT
Whether or not to wrap the text.
Definition: misc_widget.h:51
misc_widget.h
Types related to the misc widgets.
SetDataTip
static NWidgetPart SetDataTip(uint32 data, StringID tip)
Widget part function for setting the data and tooltip.
Definition: widget_type.h:1014
gfx_func.h
Functions related to the gfx engine.
SetMinimalSize
static NWidgetPart SetMinimalSize(int16 x, int16 y)
Widget part function for setting the minimal size.
Definition: widget_type.h:947
FioFOpenFile
FILE * FioFOpenFile(const char *filename, const char *mode, Subdirectory subdir, size_t *filesize)
Opens a OpenTTD file somewhere in a personal or global directory.
Definition: fileio.cpp:474
stdafx.h
Definition of base types and functions in a cross-platform compatible way.
TextfileWindow::BOTTOM_SPACING
static const int BOTTOM_SPACING
Additional spacing at the bottom of the WID_TF_BACKGROUND widget.
Definition: textfile_gui.h:32
SVS_ALLOW_NEWLINE
Allow newlines.
Definition: string_type.h:51
SA_TOP
Top align the text.
Definition: gfx_func.h:103
safeguards.h
A number of safeguards to prevent using unsafe methods.
WWT_PANEL
Simple depressed panel.
Definition: widget_type.h:50
NWID_HSCROLLBAR
Horizontal scrollbar.
Definition: widget_type.h:83
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:113
TextfileWindow::OnClick
virtual void OnClick(Point pt, int widget, int click_count)
A click with the left mouse button has been made on the window.
Definition: textfile_gui.cpp:126
WDP_CENTER
Center the window.
Definition: window_gui.h:157
TextfileWindow::LoadTextfile
virtual void LoadTextfile(const char *textfile, Subdirectory dir)
Loads the textfile text from file and setup lines.
Definition: textfile_gui.cpp:318
NWidget
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
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:499
WD_FRAMETEXT_RIGHT
Right offset of the text of the frame.
Definition: window_gui.h:73
lengthof
#define lengthof(x)
Return the length of an fixed size array.
Definition: depend.cpp:42
TextfileType
TextfileType
Additional text files accompanying Tar archives.
Definition: textfile_type.h:16
WD_FRAMETEXT_TOP
Top offset of the text of the frame.
Definition: window_gui.h:74
WD_FRAMETEXT_LEFT
Left offset of the text of the frame.
Definition: window_gui.h:72
FioCheckFileExists
bool FioCheckFileExists(const char *filename, Subdirectory subdir)
Check whether the given file exists.
Definition: fileio.cpp:312
TextfileWindow::TOP_SPACING
static const int TOP_SPACING
Additional spacing at the top of the WID_TF_BACKGROUND widget.
Definition: textfile_gui.h:31
TextfileWindow::hscroll
Scrollbar * hscroll
Horizontal scrollbar.
Definition: textfile_gui.h:26
TextfileWindow::SetupScrollbars
void SetupScrollbars()
Set scrollbars to the right lengths.
Definition: textfile_gui.cpp:109
GetStringBoundingBox
Dimension GetStringBoundingBox(const char *str, FontSize start_fontsize)
Return the string dimension in pixels.
Definition: gfx.cpp:699
WC_NONE
No window, redirects to WC_MAIN_WINDOW.
Definition: window_type.h:40
FreeTypeSubSetting::font
char font[MAX_PATH]
The name of the font, or path to the font.
Definition: fontcache.h:198
GetCurrentLanguageIsoCode
const char * GetCurrentLanguageIsoCode()
Get the ISO language code of the currently loaded language.
Definition: strings.cpp:1992
_nested_textfile_widgets
static const NWidgetPart _nested_textfile_widgets[]
Widgets for the textfile window.
Definition: textfile_gui.cpp:35
WWT_CAPTION
Window caption (window title between closebox and stickybox)
Definition: widget_type.h:61
SVS_REPLACE_WITH_QUESTION_MARK
Replace the unknown/bad bits with question marks.
Definition: string_type.h:50
TextfileWindow::SetFontNames
virtual void SetFontNames(FreeTypeSettings *settings, const char *font_name)
Set the right font names.
Definition: textfile_gui.cpp:197
WID_TF_BACKGROUND
Panel to draw the textfile on.
Definition: misc_widget.h:52
NWID_VERTICAL
Vertical container.
Definition: widget_type.h:77
EndContainer
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
FontSize
FontSize
Available font sizes.
Definition: gfx_type.h:203
TextfileWindow::vscroll
Scrollbar * vscroll
Vertical scrollbar.
Definition: textfile_gui.h:25
strecpy
char * strecpy(char *dst, const char *src, const char *last)
Copies characters from one buffer to another.
Definition: depend.cpp:68
TextfileWindow::OnResize
virtual void OnResize()
Called after the window got resized.
Definition: textfile_gui.cpp:167
Point
Coordinates of a point in 2D.
Definition: geometry_type.hpp:28
free
static void free(const void *ptr)
Version of the standard free that accepts const pointers.
Definition: depend.cpp:114
WD_FRAMERECT_RIGHT
Offset at right to draw the frame rectangular area.
Definition: window_gui.h:63
Window::width
int width
width of the window (number of pixels to the right in x direction)
Definition: window_gui.h:314
WID_TF_CAPTION
The caption of the window.
Definition: misc_widget.h:50
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:1973
Rect
Specification of a rectangle with absolute coordinates of all edges.
Definition: geometry_type.hpp:40
NWID_VSCROLLBAR
Vertical scrollbar.
Definition: widget_type.h:84
SA_LEFT
Left align the text.
Definition: gfx_func.h:98
GetTextfile
const char * GetTextfile(TextfileType type, Subdirectory dir, const char *filename)
Search a textfile file next to the given content.
Definition: textfile_gui.cpp:386
WID_TF_VSCROLLBAR
Vertical scrollbar to scroll through the textfile up-and-down.
Definition: misc_widget.h:53
SetScrollbar
static NWidgetPart SetScrollbar(int index)
Attach a scrollbar to a widget.
Definition: widget_type.h:1095
TextfileWindow::NextString
virtual const char * NextString()
Get the next string to search through.
Definition: textfile_gui.cpp:185
Dimension
Dimensions (a width and height) of a rectangle in 2D.
Definition: geometry_type.hpp:34
TextfileWindow::lines
SmallVector< const char *, 64 > lines
text, split into lines in a table with lines.
Definition: textfile_gui.h:28
gfx_type.h
Types related to the graphics and/or input devices.
Window::InvalidateData
void InvalidateData(int data=0, bool gui_scope=true)
Mark this window&#39;s data as invalid (in need of re-computing)
Definition: window.cpp:3161
Window::height
int height
Height of the window (number of pixels down in y direction)
Definition: window_gui.h:315
textfile_gui.h
GUI functions related to textfiles.
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:620
WWT_TEXTBTN
(Toggle) Button with text
Definition: widget_type.h:55
Scrollbar::GetPosition
uint16 GetPosition() const
Gets the position of the first visible element in the list.
Definition: widget_type.h:631