Also scroll tile separators in the train depot
[openttd/fttd.git] / src / textfile.h
blob231184286ec46cb5c8195bd783dad1f2536795f8
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 */
8 /** @file textfile.h Code related to textfiles. */
10 #ifndef TEXTFILE_H
11 #define TEXTFILE_H
13 #include <vector>
15 #include "core/pointer.h"
16 #include "fileio_type.h"
17 #include "strings_func.h"
18 #include "window_gui.h"
20 /** Additional text files accompanying Tar archives */
21 enum TextfileType {
22 TFT_BEGIN,
24 TFT_README = TFT_BEGIN, ///< NewGRF readme
25 TFT_CHANGELOG, ///< NewGRF changelog
26 TFT_LICENSE, ///< NewGRF license
28 TFT_END,
30 DECLARE_POSTFIX_INCREMENT(TextfileType)
32 /** Description of a textfile. */
33 struct TextfileDesc {
34 enum Format {
35 FORMAT_RAW, ///< Raw text file
36 #ifdef WITH_ZLIB
37 FORMAT_GZ, ///< Gzipped text file
38 #endif
39 #ifdef WITH_LZMA
40 FORMAT_XZ, ///< Xzipped text file
41 #endif
42 FORMAT_END,
45 /* Move semantics are enough for our current use of TextfileDesc,
46 * so this is a unique_ptr. If we ever need copy semantics, then
47 * this could be changed to a shared_ptr. */
48 ttd_unique_free_ptr <char> path; ///< Textfile path
49 const TextfileType type; ///< Textfile type
50 const Subdirectory dir; ///< Textfile directory
51 Format format; ///< Textfile format
53 TextfileDesc (void) : path(), type(TFT_END), dir(NO_DIRECTORY), format(FORMAT_END) { }
55 TextfileDesc (TextfileType type, Subdirectory dir, const char *filename);
57 bool valid (void) const
59 return (bool)(this->path);
62 char *read (size_t *len) const;
65 /** Window for displaying a textfile */
66 struct TextfileWindow : public Window {
67 TextfileType file_type; ///< Type of textfile to view.
68 Scrollbar *vscroll; ///< Vertical scrollbar.
69 Scrollbar *hscroll; ///< Horizontal scrollbar.
70 char *text; ///< Lines of text from the NewGRF's textfile.
71 std::vector<const char *> lines; ///< #text, split into lines in a table with lines.
73 static const int TOP_SPACING = WD_FRAMETEXT_TOP; ///< Additional spacing at the top of the #WID_TF_BACKGROUND widget.
74 static const int BOTTOM_SPACING = WD_FRAMETEXT_BOTTOM; ///< Additional spacing at the bottom of the #WID_TF_BACKGROUND widget.
76 TextfileWindow (const TextfileDesc &txt);
77 virtual ~TextfileWindow();
78 virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize);
79 virtual void OnClick(Point pt, int widget, int click_count);
80 void DrawWidget (BlitArea *dpi, const Rect &r, int widget) const OVERRIDE;
81 virtual void OnResize();
83 private:
84 struct GlyphSearcher : ::MissingGlyphSearcher {
85 const std::vector<const char *>::const_iterator begin;
86 const std::vector<const char *>::const_iterator end;
87 std::vector<const char *>::const_iterator iter;
89 GlyphSearcher (const TextfileWindow &tfw)
90 : MissingGlyphSearcher (FS_MONO, true),
91 begin (tfw.lines.begin()),
92 end (tfw.lines.end()),
93 iter (tfw.lines.begin())
97 void Reset() OVERRIDE;
98 const char *NextString() OVERRIDE;
101 uint GetContentHeight();
102 void SetupScrollbars();
104 public:
105 void CheckForMissingGlyphs (void) const
107 GlyphSearcher searcher (*this);
108 ::CheckForMissingGlyphs (true, &searcher);
112 #endif /* TEXTFILE_H */