OpenTTD Source  12.0-beta2
textfile_gui.h
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 #ifndef TEXTFILE_GUI_H
11 #define TEXTFILE_GUI_H
12 
13 #include "fileio_type.h"
14 #include "strings_func.h"
15 #include "textfile_type.h"
16 #include "window_gui.h"
17 
18 const char *GetTextfile(TextfileType type, Subdirectory dir, const char *filename);
19 
22  struct Line {
23  int top;
24  int bottom;
25  const char *text;
26 
27  Line(int top, const char *text) : top(top), bottom(top + 1), text(text) {}
28  };
29 
33  char *text;
34  std::vector<Line> lines;
36 
37  uint max_length;
38 
39  static const int TOP_SPACING = WD_FRAMETEXT_TOP;
40  static const int BOTTOM_SPACING = WD_FRAMETEXT_BOTTOM;
41 
43  ~TextfileWindow();
44 
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;
50 
51  void Reset() override;
52  FontSize DefaultSize() override;
53  const char *NextString() override;
54  bool Monospace() override;
55  void SetFontNames(FreeTypeSettings *settings, const char *font_name, const void *os_data) override;
56 
57  virtual void LoadTextfile(const char *textfile, Subdirectory dir);
58 
59 private:
60  uint ReflowContent();
61  uint GetContentHeight();
62  void SetupScrollbars(bool force_reflow);
63 };
64 
65 #endif /* TEXTFILE_GUI_H */
TextfileWindow::DefaultSize
FontSize DefaultSize() override
Get the default (font) size of the string.
Definition: textfile_gui.cpp:201
TextfileWindow::LoadTextfile
virtual void LoadTextfile(const char *textfile, Subdirectory dir)
Loads the textfile text from file and setup lines.
Definition: textfile_gui.cpp:340
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
MissingGlyphSearcher
A searcher for missing glyphs.
Definition: strings_func.h:242
Dimension
Dimensions (a width and height) of a rectangle in 2D.
Definition: geometry_type.hpp:27
TextfileWindow::Line::bottom
int bottom
Bottom scroll position.
Definition: textfile_gui.h:24
TextfileWindow::ReflowContent
uint ReflowContent()
Get the total height of the content displayed in this window, if wrapping is disabled.
Definition: textfile_gui.cpp:81
TextfileWindow::OnResize
void OnResize() override
Called after the window got resized.
Definition: textfile_gui.cpp:181
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
WD_FRAMETEXT_TOP
@ WD_FRAMETEXT_TOP
Top offset of the text of the frame.
Definition: window_gui.h:74
TextfileWindow::Line::top
int top
Top scroll position.
Definition: textfile_gui.h:23
Scrollbar
Scrollbar data structure.
Definition: widget_type.h:629
TextfileWindow::file_type
TextfileType file_type
Type of textfile to view.
Definition: textfile_gui.h:30
window_gui.h
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
textfile_type.h
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
TextfileWindow::Line
Definition: textfile_gui.h:22
WD_FRAMETEXT_BOTTOM
@ WD_FRAMETEXT_BOTTOM
Bottom offset of the text of the frame.
Definition: window_gui.h:75
TextfileWindow::Line::text
const char * text
Pointer to text buffer.
Definition: textfile_gui.h:25
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
TextfileWindow::text
char * text
Lines of text from the NewGRF's textfile.
Definition: textfile_gui.h:33
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
strings_func.h
TextfileWindow::search_iterator
uint search_iterator
Iterator for the font check search.
Definition: textfile_gui.h:35
TextfileWindow::DrawWidget
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
Definition: textfile_gui.cpp:147
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
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
fileio_type.h
Subdirectory
Subdirectory
The different kinds of subdirectories OpenTTD uses.
Definition: fileio_type.h:108
TextfileWindow
Window for displaying a textfile.
Definition: textfile_gui.h:21
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
Rect
Specification of a rectangle with absolute coordinates of all edges.
Definition: geometry_type.hpp:47
FreeTypeSettings
Settings for the freetype fonts.
Definition: fontcache.h:225
TextfileWindow::vscroll
Scrollbar * vscroll
Vertical scrollbar.
Definition: textfile_gui.h:31