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/>.
8 /** @file textfile_gui.h GUI functions related to textfiles. */
10 #ifndef TEXTFILE_GUI_H
11 #define TEXTFILE_GUI_H
13 #include "fileio_type.h"
14 #include "strings_func.h"
15 #include "textfile_type.h"
16 #include "window_gui.h"
18 const char *GetTextfile(TextfileType type
, Subdirectory dir
, const char *filename
);
20 /** Window for displaying a textfile */
21 struct TextfileWindow
: public Window
, MissingGlyphSearcher
{
23 int top
; ///< Top scroll position.
24 int bottom
; ///< Bottom scroll position.
25 const char *text
; ///< Pointer to text buffer.
27 Line(int top
, const char *text
) : top(top
), bottom(top
+ 1), text(text
) {}
30 TextfileType file_type
; ///< Type of textfile to view.
31 Scrollbar
*vscroll
; ///< Vertical scrollbar.
32 Scrollbar
*hscroll
; ///< Horizontal scrollbar.
33 char *text
; ///< Lines of text from the NewGRF's textfile.
34 std::vector
<Line
> lines
; ///< #text, split into lines in a table with lines.
35 uint search_iterator
; ///< Iterator for the font check search.
37 uint max_length
; ///< Maximum length of unwrapped text line.
39 static const int TOP_SPACING
= WD_FRAMETEXT_TOP
; ///< Additional spacing at the top of the #WID_TF_BACKGROUND widget.
40 static const int BOTTOM_SPACING
= WD_FRAMETEXT_BOTTOM
; ///< Additional spacing at the bottom of the #WID_TF_BACKGROUND widget.
42 TextfileWindow(TextfileType file_type
);
45 void UpdateWidgetSize(int widget
, Dimension
*size
, const Dimension
&padding
, Dimension
*fill
, Dimension
*resize
) override
;
46 void OnClick(Point pt
, int widget
, int click_count
) override
;
47 void DrawWidget(const Rect
&r
, int widget
) const override
;
48 void OnResize() override
;
49 void OnInvalidateData(int data
= 0, bool gui_scope
= true) override
;
51 void Reset() override
;
52 FontSize
DefaultSize() override
;
53 const char *NextString() override
;
54 bool Monospace() override
;
55 void SetFontNames(FontCacheSettings
*settings
, const char *font_name
, const void *os_data
) override
;
57 virtual void LoadTextfile(const char *textfile
, Subdirectory dir
);
61 uint
GetContentHeight();
62 void SetupScrollbars(bool force_reflow
);
65 #endif /* TEXTFILE_GUI_H */