OpenTTDDevBlackBook/Window/UseWindows
From OpenTTD
Audio
Music
Graphic
Using the Window System
Events used by the Window System
Colour codes that exist in OpenTTD
Understanding the Dynamic Landscape Array
Understanding the SaveGame Handler
HOWTO - Create good Scenarios
HOWTO - Add New Town Name Generators
Vehicles
Using Orders
Pathfinding
Ratings
Train Acceleration
The OpenTTD TCP Protocol
The OpenTTD UDP Protocol
HOWTO - Debug desyncs
The Console Window
Using Console Scripting
HOWTO - Add Functions/Commands to the Console
HOWTO - Add Variables to the Console
HOWTO - Direct Variable Access using ICONSOLE_VAR_POINTER
OpenTTD Console Commands
OpenTTD Console Variables
Development History
A window is drawn on the game screen at every WE_PAINT window event.
Contents |
[edit] Opening a window
The function AllocateWindowDesc opens a window. It should be provided with a description (AllocateWindowDesc(&_mywindow_desc);). It returns the window pointer of the newly created window.
- Example:
void ShowMyNewWindow(void)
{
AllocateWindowDesc(&_mywindow_desc);
}
[edit] Describing a window
Set up a WindowDesc with the name you gave AllocateWindowDesc.
- Syntax:
static const WindowDesc _mywindow_desc = {
X-coordinate of window top-left corner,
Y-coordinate of window top-left corner,
window width, window height,
window class,
window parent class,
window flags,
widget definition,
window procedure name
};
- Example:
static const WindowDesc _mywindow_desc = {
100, 100, 150, 200,
WC_ERRMSG,
0,
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET,
_mywindow_widgets,
MyWindowProc
};
[edit] Coordinate variables
These variables can be used to replace static coordinate numbers.
WDP_AUTO- Finds a location automatically
WDP_CENTER- Centers the window (left/right or top/bottom)
WDP_ALIGN_TBR- Aligns the right side of the window with the right side of the main toolbar
WDP_ALIGN_TBL- Aligns the left side of the window with the left side of the main toolbar
[edit] Window classes
Whoever added this template didn't specify what was to be done, so it should be removed or updated with the correct action.
WC_MAIN_WINDOW, WC_MAIN_TOOLBAR, WC_STATUS_BAR, WC_BUILD_TOOLBAR, WC_NEWS_WINDOW, WC_TOWN_DIRECTORY, WC_STATION_LIST, WC_TOWN_VIEW, WC_SMALLMAP, WC_TRAINS_LIST, WC_ROADVEH_LIST, WC_SHIPS_LIST, WC_AIRCRAFT_LIST, WC_VEHICLE_VIEW, WC_VEHICLE_DETAILS, WC_VEHICLE_REFIT, WC_VEHICLE_ORDERS, WC_STATION_VIEW, WC_VEHICLE_DEPOT, WC_BUILD_VEHICLE, WC_BUILD_BRIDGE, WC_ERRMSG, WC_BUILD_STATION, WC_BUS_STATION, WC_TRUCK_STATION, WC_BUILD_DEPOT, WC_COMPANY, WC_FINANCES, WC_PLAYER_COLOR, WC_QUERY_STRING, WC_SAVELOAD, WC_SELECT_GAME, WC_TOOLBAR_MENU, WC_INCOME_GRAPH, WC_OPERATING_PROFIT, WC_TOOLTIPS, WC_INDUSTRY_VIEW, WC_PLAYER_FACE, WC_LAND_INFO, WC_TOWN_AUTHORITY, WC_SUBSIDIES_LIST, WC_GRAPH_LEGEND, WC_DELIVERED_CARGO, WC_PERFORMANCE_HISTORY, WC_COMPANY_VALUE, WC_COMPANY_LEAGUE, WC_BUY_COMPANY, WC_PAYMENT_RATES, WC_ENGINE_PREVIEW, WC_MUSIC_WINDOW, WC_MUSIC_TRACK_SELECTION, WC_SCEN_LAND_GEN, WC_SCEN_TOWN_GEN, WC_SCEN_INDUSTRY, WC_SCEN_BUILD_ROAD, WC_BUILD_TREES, WC_SEND_NETWORK_MSG, WC_DROPDOWN_MENU, WC_BUILD_INDUSTRY, WC_GAME_OPTIONS, WC_NETWORK_WINDOW, WC_INDUSTRY_DIRECTORY, WC_MESSAGE_HISTORY, WC_CHEATS, WC_PERFORMANCE_DETAIL, WC_CONSOLE, WC_EXTRA_VIEW_PORT, WC_CLIENT_LIST, WC_NETWORK_STATUS_WINDOW, WC_CUSTOM_CURRENCY, WC_REPLACE_VEHICLE, WC_HIGHSCORE, WC_ENDSCREEN, WC_SIGN_LIST, WC_GENERATE_LANDSCAPE, WC_GENERATE_PROGRESS_WINDOW, WC_CONFIRM_POPUP_QUERY,
[edit] Flags
WDF_STD_TOOLTIPS- Use standard routine when displaying tooltips
WDF_DEF_WIDGET- Default widget control for some widgets in the onClick event
WDF_STD_BTN- Default handling for close and drag widgets (widget n:o 0 and 1)
WDF_UNCLICK_BUTTONS- Unclick buttons when the window event times out
WDF_STICKY_BUTTON- Set window to sticky mode; they are not closed unless closed with 'X' (widget 2)
WDF_RESIZABLE- A window can be resized
WDF_MODAL- The window is a modal child of some other window, meaning the parent is 'inactive'
[edit] Setting up widgets
- Syntax:
static const Widget _mywindow_widgets[] = {
{ Widget type, flags, color, position-left, position-right, position-top, position-bottom, string/image identifier, tooltip string identifier},
};
- Example:
static const Widget _mywindow_widgets[] = {
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
{ WWT_CAPTION, RESIZE_NONE, 14, 11, 419, 0, 13, STR_015B_OPENTTD, STR_NULL},
{ WWT_PANEL, RESIZE_NONE, 14, 0, 419, 14, 271, 0x0, STR_NULL},
{ WWT_FRAME, RESIZE_NONE, 14, 5, 414, 40, 245, STR_NULL, STR_NULL},
{ WIDGETS_END},
};
[edit] 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_LAST
WWT_MASK- 0x1F
WWT_PUSHBTN
WWT_PUSHTXTBTN
WWT_PUSHIMGBTN
[edit] Flags
Quote from window.h lines 16 onwards:
/* How the resize system works:
First, you need to add a WWT_RESIZEBOX to the widgets, and you need
to add the flag WDF_RESIZABLE to the window. Now the window is ready
to resize itself.
As you may have noticed, all widgets have a RESIZE_XXX in their line.
This lines controls how the widgets behave on resize. RESIZE_NONE means
it doesn't do anything. Any other option let's one of the borders
move with the changed width/height. So if a widget has
RESIZE_RIGHT, and the window is made 5 pixels wider by the user,
the right of the window will also be made 5 pixels wider.
Now, what if you want to clamp a widget to the bottom? Give it the flag
RESIZE_TB. This is RESIZE_TOP + RESIZE_BOTTOM. Now if the window gets
5 pixels bigger, both the top and bottom gets 5 bigger, so the whole
widgets moves downwards without resizing, and appears to be clamped
to the bottom. Nice aint it?
You should know one more thing about this system. Most windows can't
handle an increase of 1 pixel. So there is a step function, which
let the windowsize only be changed by X pixels. You configure this
after making the window, like this:
w->resize.step_height = 10;
Now the window will only change in height in steps of 10.
You can also give a minimum width and height. The default value is
the default height/width of the window itself. You can change this
AFTER window-creation, with:
w->resize.width or w->resize.height.
That was all.. good luck, and enjoy :) -- TrueLight */
RESIZE_NONE
RESIZE_LEFT
RESIZE_RIGHT
RESIZE_TOP
RESIZE_BOTTOM
RESIZE_LR
RESIZE_RB
RESIZE_TB
RESIZE_LRB
RESIZE_LRTB
RESIZE_RTB
WIDG_DISABLED
- Widget is disabled (greyed out)
WIDG_HIDDEN
- Widget is invisible
WIDG_LOWERED
- Widget pressed
[edit] Colors
For a list of available colors, see OpenTTDDevBlackBook/Window/Colours.
[edit] Maintaining the window
Set up a window procedure to be run each time WE_PAINT is called.
- Example:
static void MyWindowProc(Window *w, WindowEvent *e)
{
switch (e->event) {
case WE_PAINT: {
DrawWindowWidgets(w);
} break;
}
}

