- en
- pl
OpenTTD GitHub
Contributing to OpenTTD - guidelines
OpenTTD Doxygen
Coding style
Compiling OpenTTD
Debugging
Add a setting
Add a squirrel function
Understanding the SaveGame handler
Bumping the savegame version
Doing an OpenTTD release
Manual of style
Format of langfiles
Using OpenTTD strings
List of special strings
Using the window system
Colour codes that exist in OpenTTD
Adding a text box
Understanding the widget focus system
GUI style guide
The OpenTTD TCP protocol
The OpenTTD UDP protocol
Debugging desyncs
Server Admin Port development
The console window
Console commands
Console variables
Using console scripting
Adding functions/commands to the console
Adding variables to the console
Console development history
Graphics and similar (NewGRF)
AI framework (NoAI)
GameScript framework (NoGO)
Social Integration
Map array (landscape grid)
Vehicles
Pathfinding
Train acceleration
Sound IDs
A window is drawn on the game screen at every WE_PAINT
window event.
Contents |
Opening a window
Creating a new struct of a window opens a new window. It should be provided with a doxygen comment explaining the function.
Example:
/**
* Opens a new instance of a MyNew window.
* @param void Any parameters required by window
*/
void ShowMyNewWindow(void)
{
DeleteWindowByClass(window class);
new MyNewWindow(void);
}
Describing a window
Set up a WindowDesc
with the name you gave this->CreateNestedTree()
and this->FinishInitNested()
.
Syntax:
/** Window description for my new window. */
static const WindowDesc _mywindow_desc(
window positioning,
default width,
default height,
window class,
parent window class,
window flags
widget parts,
lengthof(widget parts)
);
You will also need a struct describing You can find plenty of examples in the source code, look in a *_gui.cpp file.
Window positioning
The window positioning is one of the values of the WindowPosition enum defined in src/window_gui.h.
Window classes
A window class is a unique number that represents a (set of) windows, for example a window that displays a town has class WC_TOWN_VIEW. To differentiate which town is displayed by an actual window, the latter has an additional window number.
The list of available window classes is defined by the WindowClass enum, in src/window_type.h.
Setting up widgets
Syntax:
static const NWidgetPart _nested_mywindow_widgets[] = {
NWidget(nwid),
NWidget(wwt, colour, wid), SetDataTip(STR_NULL, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
EndContainer(),
};
</pre>
:;<nowiki>Example:</nowiki>
<pre>
static const NWidgetPart _nested_mywindow_widgets[] = {
NWidget(NWID_HORIZONTAL),
NWidget(WWT_TEXT, COLOUR_MAUVE), SetDataTip(STR_NEWGRF_SETTINGS_SELECT_PRESET, STR_NULL),
SetPadding(0, WD_FRAMETEXT_RIGHT, 0, 0),
NWidget(WWT_DROPDOWN, COLOUR_YELLOW, WID_NS_PRESET_LIST), SetFill(1, 0), SetResize(1, 0),
SetDataTip(STR_JUST_STRING, STR_NEWGRF_SETTINGS_PRESET_LIST_TOOLTIP),
EndContainer(),
};
Widget types
-
WWT_EMPTY
-
WWT_PANEL
A simple depressed panel.
-
WWT_INSET
A depressed panel, most commonly used as a combo box text area.
-
WWT_IMGBTN
Image button.
-
WWT_IMGBTN_2
Image button. Image changes when button is pressed.
-
WWT_TEXTBTN
Text button.
-
WWT_TEXTBTN_2
Text button. Text changes when button is pressed.
-
WWT_LABEL
A centered label.
-
WWT_MATRIX
-
WWT_SCROLLBAR
-
WWT_FRAME
-
WWT_CAPTION
-
WWT_HSCROLLBAR
-
WWT_STICKYBOX
The button for stickying a window.
-
WWT_SCROLL2BAR
-
WWT_RESIZEBOX
The button for resizing a window.
-
WWT_CLOSEBOX
The button for closing a window.
-
WWT_PUSHBTN
-
WWT_PUSHTXTBTN
-
WWT_PUSHIMGBTN
Colours
For a list of available colors, see Colours.
Maintaining the window
Define what to do with the window in a struct, with a constructor
Example:
struct MyNewWindow {
MyNewWindow()
{
}
....
}