Merge branch 'master' into jgrpp
# Conflicts: # cmake/SourceList.cmake # src/build_vehicle_gui.cpp # src/company_gui.cpp # src/console_cmds.cpp # src/depot_base.h # src/elrail.cpp # src/network/core/udp.cpp # src/network/network_admin.cpp # src/network/network_chat_gui.cpp # src/network/network_gui.cpp # src/network/network_server.cpp # src/newgrf.cpp # src/newgrf_engine.cpp # src/newgrf_railtype.cpp # src/newgrf_railtype.h # src/newgrf_storage.h # src/os/unix/crashlog_unix.cpp # src/rail.h # src/rail_cmd.cpp # src/rail_gui.cpp # src/road_cmd.cpp # src/road_map.h # src/saveload/labelmaps_sl.cpp # src/settings_gui.cpp # src/settings_type.h # src/sl/oldloader_sl.cpp # src/station_cmd.cpp # src/station_gui.cpp # src/table/settings/world_settings.ini # src/tests/test_script_admin.cpp # src/textfile_gui.cpp # src/toolbar_gui.cpp # src/train_cmd.cpp # src/tunnelbridge_cmd.cpp # src/vehicle_gui.cpp # src/widget.cpp # src/window.cpp # src/window_gui.h # src/window_type.h
This commit is contained in:
@@ -29,9 +29,6 @@ struct TextfileWindow : public Window, MissingGlyphSearcher {
|
||||
TextfileType file_type; ///< Type of textfile to view.
|
||||
Scrollbar *vscroll; ///< Vertical scrollbar.
|
||||
Scrollbar *hscroll; ///< Horizontal scrollbar.
|
||||
uint search_iterator; ///< Iterator for the font check search.
|
||||
|
||||
uint max_length; ///< Maximum length of unwrapped text line.
|
||||
|
||||
TextfileWindow(TextfileType file_type);
|
||||
|
||||
@@ -40,33 +37,86 @@ struct TextfileWindow : public Window, MissingGlyphSearcher {
|
||||
void DrawWidget(const Rect &r, int widget) const override;
|
||||
void OnResize() override;
|
||||
void OnInvalidateData(int data = 0, bool gui_scope = true) override;
|
||||
void OnDropdownSelect(int widget, int index) override;
|
||||
|
||||
void Reset() override;
|
||||
FontSize DefaultSize() override;
|
||||
std::optional<std::string_view> NextString() override;
|
||||
bool Monospace() override;
|
||||
void SetFontNames(FontCacheSettings *settings, const char *font_name, const void *os_data) override;
|
||||
void ScrollToLine(size_t line);
|
||||
|
||||
virtual void LoadTextfile(const char *textfile, Subdirectory dir);
|
||||
|
||||
protected:
|
||||
void LoadText(std::string_view buf);
|
||||
inline void LoadTextfile(const std::string &textfile, Subdirectory dir)
|
||||
{
|
||||
this->LoadTextfile(textfile.c_str(), dir);
|
||||
}
|
||||
|
||||
private:
|
||||
protected:
|
||||
struct Line {
|
||||
int top; ///< Top scroll position.
|
||||
int bottom; ///< Bottom scroll position.
|
||||
std::string_view text; ///< Pointer to text buffer.
|
||||
int top{0}; ///< Top scroll position in visual lines.
|
||||
int bottom{0}; ///< Bottom scroll position in visual lines.
|
||||
std::string text{}; ///< Contents of the line.
|
||||
TextColour colour{TC_WHITE}; ///< Colour to render text line in.
|
||||
|
||||
Line(int top, std::string_view text) : top(top), bottom(top + 1), text(text) {}
|
||||
Line() {}
|
||||
};
|
||||
|
||||
std::string text; ///< Lines of text from the NewGRF's textfile.
|
||||
std::vector<Line> lines; ///< #text, split into lines in a table with lines.
|
||||
struct Hyperlink {
|
||||
size_t line; ///< Which line the link is on.
|
||||
size_t begin; ///< Character position on line the link begins.
|
||||
size_t end; ///< Character position on line the link end.
|
||||
std::string destination; ///< Destination for the link.
|
||||
};
|
||||
|
||||
struct HistoryEntry {
|
||||
std::string filepath; ///< File the history entry is in.
|
||||
int scrollpos; ///< Scrolling position the file was at at navigation time.
|
||||
};
|
||||
|
||||
std::string filename{}; ///< Filename of the textfile.
|
||||
std::string filepath{}; ///< Full path to the filename.
|
||||
|
||||
std::vector<Line> lines; ///< #text, split into lines in a table with lines.
|
||||
std::vector<size_t> jumplist; ///< Table of contents list, line numbers.
|
||||
std::vector<Hyperlink> links; ///< Clickable links in lines.
|
||||
std::vector<Hyperlink> link_anchors; ///< Anchor names of headings that can be linked to.
|
||||
std::vector<HistoryEntry> history; ///< Browsing history in this window.
|
||||
size_t history_pos{0}; ///< Position in browsing history (for forward movement).
|
||||
bool trusted{false}; ///< Whether the content is trusted (read: not from content like NewGRFs, etc).
|
||||
|
||||
void LoadText(std::string_view buf);
|
||||
void FindHyperlinksInMarkdown(Line &line, size_t line_index);
|
||||
|
||||
/**
|
||||
* Handle the clicking on a hyperlink.
|
||||
*
|
||||
* @param link The link that is clicked on.
|
||||
*/
|
||||
virtual void OnHyperlinkClick(const Hyperlink &link);
|
||||
|
||||
/**
|
||||
* Post-processing after the text is loaded.
|
||||
*/
|
||||
virtual void AfterLoadText();
|
||||
|
||||
void NavigateToFile(std::string newfile, size_t line);
|
||||
void AppendHistory(const std::string &filepath);
|
||||
void UpdateHistoryScrollpos();
|
||||
void NavigateHistory(int delta);
|
||||
|
||||
private:
|
||||
uint search_iterator{0}; ///< Iterator for the font check search.
|
||||
uint max_length{0}; ///< Maximum length of unwrapped text line.
|
||||
|
||||
uint ReflowContent();
|
||||
uint GetContentHeight();
|
||||
void SetupScrollbars(bool force_reflow);
|
||||
void CheckHyperlinkClick(Point pt);
|
||||
|
||||
void AfterLoadMarkdown();
|
||||
};
|
||||
|
||||
#endif /* TEXTFILE_GUI_H */
|
||||
|
Reference in New Issue
Block a user