OpenTTD Source  12.0-beta2
textfile_gui.cpp File Reference
#include "stdafx.h"
#include "fileio_func.h"
#include "fontcache.h"
#include "gfx_type.h"
#include "gfx_func.h"
#include "string_func.h"
#include "textfile_gui.h"
#include "widgets/misc_widget.h"
#include "table/strings.h"
#include <zlib.h>
#include <lzma.h>
#include "safeguards.h"

Go to the source code of this file.

Functions

static void Gunzip (byte **bufp, size_t *sizep)
 Do an in-memory gunzip operation. More...
 
static void Xunzip (byte **bufp, size_t *sizep)
 Do an in-memory xunzip operation. More...
 
const char * GetTextfile (TextfileType type, Subdirectory dir, const char *filename)
 Search a textfile file next to the given content. More...
 

Variables

static const NWidgetPart _nested_textfile_widgets []
 Widgets for the textfile window. More...
 
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.
 

Detailed Description

Implementation of textfile window.

Definition in file textfile_gui.cpp.

Function Documentation

◆ GetTextfile()

const char* GetTextfile ( TextfileType  type,
Subdirectory  dir,
const char *  filename 
)

Search a textfile file next to the given content.

Parameters
typeThe type of the textfile to search for.
dirThe subdirectory to search in.
filenameThe filename of the content to look for.
Returns
The path to the textfile, nullptr otherwise.

Definition at line 416 of file textfile_gui.cpp.

References lengthof.

Referenced by ScriptConfig::GetTextfile(), and GRFConfig::GetTextfile().

◆ Gunzip()

static void Gunzip ( byte **  bufp,
size_t *  sizep 
)
static

Do an in-memory gunzip operation.

This works on a raw deflate stream, or a file with gzip or zlib header.

Parameters
bufpA pointer to a buffer containing the input data. This buffer will be freed and replaced by a buffer containing the uncompressed data.
sizepA pointer to the buffer size. Before the call, the value pointed to should contain the size of the input buffer. After the call, it contains the size of the uncompressed data.

When decompressing fails, *bufp is set to nullptr and *sizep to 0. The compressed buffer passed in is still freed in this case.

Definition at line 242 of file textfile_gui.cpp.

References free(), and ReallocT().

Referenced by TextfileWindow::LoadTextfile().

◆ Xunzip()

static void Xunzip ( byte **  bufp,
size_t *  sizep 
)
static

Do an in-memory xunzip operation.

This works on a .xz or (legacy) .lzma file.

Parameters
bufpA pointer to a buffer containing the input data. This buffer will be freed and replaced by a buffer containing the uncompressed data.
sizepA pointer to the buffer size. Before the call, the value pointed to should contain the size of the input buffer. After the call, it contains the size of the uncompressed data.

When decompressing fails, *bufp is set to nullptr and *sizep to 0. The compressed buffer passed in is still freed in this case.

Definition at line 298 of file textfile_gui.cpp.

Referenced by TextfileWindow::LoadTextfile().

Variable Documentation

◆ _nested_textfile_widgets

const NWidgetPart _nested_textfile_widgets[]
static
Initial value:
= {
NWidget(WWT_CLOSEBOX, COLOUR_MAUVE),
NWidget(WWT_CAPTION, COLOUR_MAUVE, WID_TF_CAPTION), SetDataTip(STR_NULL, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
NWidget(WWT_TEXTBTN, COLOUR_MAUVE, WID_TF_WRAPTEXT), SetDataTip(STR_TEXTFILE_WRAP_TEXT, STR_TEXTFILE_WRAP_TEXT_TOOLTIP),
NWidget(WWT_DEFSIZEBOX, COLOUR_MAUVE),
NWidget(WWT_RESIZEBOX, COLOUR_MAUVE),
}

Widgets for the textfile window.

Definition at line 33 of file textfile_gui.cpp.

WID_TF_HSCROLLBAR
@ WID_TF_HSCROLLBAR
Horizontal scrollbar to scroll through the textfile left-to-right.
Definition: misc_widget.h:55
SetScrollbar
static NWidgetPart SetScrollbar(int index)
Attach a scrollbar to a widget.
Definition: widget_type.h:1188
NWID_HSCROLLBAR
@ NWID_HSCROLLBAR
Horizontal scrollbar.
Definition: widget_type.h:81
WWT_CAPTION
@ WWT_CAPTION
Window caption (window title between closebox and stickybox)
Definition: widget_type.h:59
WWT_DEFSIZEBOX
@ WWT_DEFSIZEBOX
Default window size box (at top-right of a window, between WWT_SHADEBOX and WWT_STICKYBOX)
Definition: widget_type.h:63
NWID_HORIZONTAL
@ NWID_HORIZONTAL
Horizontal container.
Definition: widget_type.h:73
SetResize
static NWidgetPart SetResize(int16 dx, int16 dy)
Widget part function for setting the resize step.
Definition: widget_type.h:993
SetDataTip
static NWidgetPart SetDataTip(uint32 data, StringID tip)
Widget part function for setting the data and tooltip.
Definition: widget_type.h:1107
WID_TF_BACKGROUND
@ WID_TF_BACKGROUND
Panel to draw the textfile on.
Definition: misc_widget.h:53
WID_TF_WRAPTEXT
@ WID_TF_WRAPTEXT
Whether or not to wrap the text.
Definition: misc_widget.h:52
NWID_VERTICAL
@ NWID_VERTICAL
Vertical container.
Definition: widget_type.h:75
WWT_CLOSEBOX
@ WWT_CLOSEBOX
Close box (at top-left of a window)
Definition: widget_type.h:67
WWT_RESIZEBOX
@ WWT_RESIZEBOX
Resize box (normally at bottom-right of a window)
Definition: widget_type.h:66
EndContainer
static NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME,...
Definition: widget_type.h:1092
NWID_VSCROLLBAR
@ NWID_VSCROLLBAR
Vertical scrollbar.
Definition: widget_type.h:82
WID_TF_VSCROLLBAR
@ WID_TF_VSCROLLBAR
Vertical scrollbar to scroll through the textfile up-and-down.
Definition: misc_widget.h:54
NWidget
static NWidgetPart NWidget(WidgetType tp, Colours col, int16 idx=-1)
Widget part function for starting a new 'real' widget.
Definition: widget_type.h:1207
SetMinimalSize
static NWidgetPart SetMinimalSize(int16 x, int16 y)
Widget part function for setting the minimal size.
Definition: widget_type.h:1010
WWT_PANEL
@ WWT_PANEL
Simple depressed panel.
Definition: widget_type.h:48
WID_TF_CAPTION
@ WID_TF_CAPTION
The caption of the window.
Definition: misc_widget.h:51
WWT_TEXTBTN
@ WWT_TEXTBTN
(Toggle) Button with text
Definition: widget_type.h:53