UseWindows
OpenTTD Development Documentation
External Links

OpenTTD GitHub
Contributing to OpenTTD - guidelines
OpenTTD Doxygen

General Reference

Coding style
Compiling OpenTTD
Debugging
Add a setting
Add a squirrel function
Understanding the SaveGame handler
Bumping the savegame version
Doing an OpenTTD release

Language and Strings

Manual of style
Format of langfiles
Using OpenTTD strings
List of special strings

Window System

Using the window system
Colour codes that exist in OpenTTD
Adding a text box
Understanding the widget focus system
GUI style guide

Multiplayer

The OpenTTD TCP protocol
The OpenTTD UDP protocol
Debugging desyncs
Server Admin Port development

Ingame Console

The console window
Console commands
Console variables
Using console scripting
Adding functions/commands to the console
Adding variables to the console
Console development history

Content APIs (modding frameworks)

Graphics and similar (NewGRF)
AI framework (NoAI)
GameScript framework (NoGO)
Social Integration

Other Reference

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
/File/en/Klipper.png
To Do
-Include an explanation.
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
/File/en/Klipper.png
To Do
-Include an explanation.
WWT_SCROLLBAR
/File/en/Klipper.png
To Do
-Include an explanation.
WWT_FRAME
/File/en/Klipper.png
To Do
-Include an explanation.
WWT_CAPTION
/File/en/Klipper.png
To Do
-Include an explanation.
WWT_HSCROLLBAR
/File/en/Klipper.png
To Do
-Include an explanation.
WWT_STICKYBOX

The button for stickying a window.

WWT_SCROLL2BAR
/File/en/Klipper.png
To Do
-Include an explanation.
WWT_RESIZEBOX

The button for resizing a window.

WWT_CLOSEBOX

The button for closing a window.

WWT_PUSHBTN
/File/en/Klipper.png
To Do
-Include an explanation.
WWT_PUSHTXTBTN
/File/en/Klipper.png
To Do
-Include an explanation.
WWT_PUSHIMGBTN
/File/en/Klipper.png
To Do
-Include an explanation.

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()
        {
        }
        ....
}