OpenTTDDevBlackBook/Window/UseWindows

From OpenTTD
Revision as of 09:55, 24 July 2012 by LordAro (Talk | contribs)

Jump to: navigation, search
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

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)

Other Reference

Map array (landscape grid)
Vehicles
Pathfinding
Train acceleration


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(),
};
Example:
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
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
Klipper.png

To Do
-Include an explanation.

WWT_SCROLLBAR
Klipper.png

To Do
-Include an explanation.

WWT_FRAME
Klipper.png

To Do
-Include an explanation.

WWT_CAPTION
Klipper.png

To Do
-Include an explanation.

WWT_HSCROLLBAR
Klipper.png

To Do
-Include an explanation.

WWT_STICKYBOX
The button for stickying a window.
WWT_SCROLL2BAR
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
Klipper.png

To Do
-Include an explanation.

WWT_PUSHTXTBTN
Klipper.png

To Do
-Include an explanation.

WWT_PUSHIMGBTN
Klipper.png

To Do
-Include an explanation.

Flags

RESIZE_NONE
Klipper.png

To Do
-Include an explanation.

RESIZE_LEFT
Klipper.png

To Do
-Include an explanation.

RESIZE_RIGHT
Klipper.png

To Do
-Include an explanation.

RESIZE_TOP
Klipper.png

To Do
-Include an explanation.

RESIZE_BOTTOM
Klipper.png

To Do
-Include an explanation.

RESIZE_LR
Klipper.png

To Do
-Include an explanation.

RESIZE_RB
Klipper.png

To Do
-Include an explanation.

RESIZE_TB
Klipper.png

To Do
-Include an explanation.

RESIZE_LRB
Klipper.png

To Do
-Include an explanation.

RESIZE_LRTB
Klipper.png

To Do
-Include an explanation.

RESIZE_RTB
Klipper.png

To Do
-Include an explanation.

WIDG_DISABLED
Widget is disabled (greyed out)
WIDG_HIDDEN
Widget is invisible
WIDG_LOWERED
Widget pressed

Colours

For a list of available colors, see OpenTTDDevBlackBook/Window/Colours.

Maintaining the window

Define what to do with the window in a struct, with a constructor

Example:
struct MyNewWindow {
        MyNewWindow()
        {
        }
        ....
}
Personal tools