OpenTTDDevBlackBook/Window/TextEdit

From OpenTTD
(Difference between revisions)
Jump to: navigation, search
(I was told by frosch that the one-textbox-per-window bug has been fixed.)
Line 1: Line 1:
 
{{DevDoc}}
 
{{DevDoc}}
 +
{{Outdated}}
  
Only one edit box per window is allowed. The way users interact with edit boxes is influenced by the [[OpenTTDDevBlackBook/Window/WidgetFocus|widget focus system]]. This page describes what modifications that are necessary to add a text box to a window that do not have it yet.  
+
 
 +
The way users interact with edit boxes is influenced by the [[OpenTTDDevBlackBook/Window/WidgetFocus|widget focus system]]. This page describes what modifications that are necessary to add a text box to a window that do not have it yet.  
  
 
== Checklist for adding a text box to a window ==
 
== Checklist for adding a text box to a window ==
 
<!--* Does the window already have a text box? Only one edit box can exist per window. If you need more, you have to either fix that limitation or use the query string window.-->
 
 
  
 
* Add a constant for the widget index eg. OP_WIDGET_NUM_PIZZAS_EDIT (OP = Order Pizza window). Follow the naming pattern of the other widgets in the same window.
 
* Add a constant for the widget index eg. OP_WIDGET_NUM_PIZZAS_EDIT (OP = Order Pizza window). Follow the naming pattern of the other widgets in the same window.

Revision as of 13:43, 5 August 2013

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


Outdated content.png

Out of Date
This article or section is outdated. Some of its content may no longer be accurate due to changes in the latest release. Please update this article.


The way users interact with edit boxes is influenced by the widget focus system. This page describes what modifications that are necessary to add a text box to a window that do not have it yet.

Checklist for adding a text box to a window

  • Add a constant for the widget index eg. OP_WIDGET_NUM_PIZZAS_EDIT (OP = Order Pizza window). Follow the naming pattern of the other widgets in the same window.


  • Add an edit box to the nested widget array:
NWidget(WWT_EDITBOX, COLOUR_WHITE, OP_WIDGET_NUM_PIZZAS_EDIT), 
  SetDataTip(STR_ORDER_PIZZA_NUM_PIZZAS_OSKTITLE, STR_ORDER_PIZZA_NUM_PIZZAS_TOOLTIP),

(should be on one line, but has been broken up on two lines here on the wiki to avoid horizontal scrolling)


  • Make the window class derive from QueryStringBaseWindow instead of just Window.
OrderPizzaWindow(const WindowDesc *desc, WindowNumber number) : 
  QueryStringBaseWindow(MAX_NUM_PIZZA_STRING_LENGTH)

(should be on one line)


  • In your constructor you must do:
InitializeTextBuffer(&this->text, this->edit_str_buf, 
  this->edit_str_size, MAX_NUM_PIZZA_STRING_LENGTH);

(should be on one line)

If you want to focus the edit box by default when the window opens, call the SetFocusedWidget function:

this->SetFocusedWidget(OP_WIDGET_NUM_PIZZAS_EDIT);


  • Make sure that OnMouseLoop is implemented and make it call HandleEditBox. If you don't do this, the carret will not flash when the edit box is focused.
virtual void OnMouseLoop()
{
  this->HandleEditBox(OP_WIDGET_NUM_PIZZAS_EDIT);
}


  • In OnPaint call this->DrawEditBox(OP_WIDGET_NUM_PIZZAS_EDIT) after making sure that the window is not shaded (this->IsShaded()).


  • Make sure that OnKeyPress is implemented and make it call this->HandleEditBoxInput(..). The HandleEditBoxKey function has some interesting return values that are worth to check out. It will tell you if the enter/escape button was pressed or if no input was processed because the edit box was not in global focus.
virtual EventState OnKeyPress(uint16 key, uint16 keycode)
{
  EventState state = ES_NOT_HANDLED;
  this->HandleEditBoxKey(OP_WIDGET_NUM_PIZZAS_EDIT, key, keycode, state);
  return state;
}

Related articles

Understanding the widget focus system

Personal tools