From OpenTTD
Jump to: navigation, search
HAL (Hardware Abstraction Layer)


Window System

Using the Window System
Colour codes that exist in OpenTTD
Adding a text box
Understanding the widget focus system


Add a setting
Add a squirrel function
Do a savegame BUMP

The Map / Scenario

Understanding the Dynamic Landscape Array
Understanding the SaveGame Handler
HOWTO - Create good Scenarios
HOWTO - Add New Town Name Generators

The actual simulation

Using Orders
Train Acceleration

Language and Strings

Format of langfiles
Using OpenTTD Strings
List of Special Strings


The Core Interface

Starting a Server
Connecting to a Server
Using the list of LAN/Internet Games

The OpenTTD TCP Protocol
The OpenTTD UDP Protocol
HOWTO - Debug desyncs

Ingame Console

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

This document aims to give a short introduction to the widget focus system.


Focus levels

The focus system in OpenTTD has two levels. First there is a pointer that keeps track of which window has focus. Then each window instance keeps track of which widget is focused within that window. This means that a window that is not focused will still remember which widget was globally focused before another window stole the window focus. This widget might later become the globally focused widget if its window gets focused without changing the focused widget. (for example by clicking on the title bar)

The term globally focused widget refers to the focused widget of the focused window. Window::IsWidgetGloballyFocused will only return if given widget as well as the window instance is focused. Window::IsWidgetFocused on the other hand only requires that the given widget is focused within the window instance, but the window itself does not need to be focused.

The term local focus refers to focus within a window regardless if the window is focused or not.

How to interact with the focus system

For the last and most accurate details please refer to the source code.

Global functions

  • SetFocusedWindow(Window *w) : Sets the focused window

Window members

  • IsWidgetFocused(byte widget_index) : Checks if given widget is focused within window
  • IsWidgetGloballyFocused(byte widget_index) : Checks if given widget is globally focused
  • SetFocusedWidget(byte widget_index) : Set local widget focus to given widget
  • UnfocusFocusedWidget() : Set local widget focus to null


If you want to unfocus the currently locally focused widget but does not want to give another widget focus then you have to use the following code: (written as how to write from within a Window)

if (this->nested_focus != NULL) {
  this->nested_focus = NULL;

If the window however uses the old non-nested widget system the code above becomes:

if (this->focused_widget != NULL) {
  this->InvalidateWidget(this->focused_widget - this->widget);
  this->focused_widget = NULL;
Personal tools