OpenTTD Source 20241224-master-gf74b0cf984
IConsoleWindow Struct Reference
Inheritance diagram for IConsoleWindow:
Window ZeroedMemoryAllocator

Public Member Functions

void OnInit () override
 Notification that the nested widget tree gets initialized.
 
void Close (int data=0) override
 Hide the window and all its child windows, and mark them for a later deletion.
 
void Scroll (int amount)
 Scroll the content of the console.
 
void OnPaint () override
 The window must be repainted.
 
void OnMouseLoop () override
 Called for every mouse loop run, which is at least once per (game) tick.
 
EventState OnKeyPress (char32_t key, uint16_t keycode) override
 A key has been pressed.
 
void InsertTextString (WidgetID, const char *str, bool marked, const char *caret, const char *insert_location, const char *replacement_end) override
 Insert a text string at the cursor position into the edit box widget.
 
const TextbufGetFocusedTextbuf () const override
 Get the current input text buffer.
 
Point GetCaretPosition () const override
 Get the current caret position if an edit box has the focus.
 
Rect GetTextBoundingRect (const char *from, const char *to) const override
 Get the bounding rectangle for a text range if an edit box has the focus.
 
ptrdiff_t GetTextCharacterAtPosition (const Point &pt) const override
 Get the character that is rendered at a position by the focused edit box.
 
void OnMouseWheel (int wheel) override
 The mouse wheel has been turned.
 
void OnFocus () override
 The window has gained focus.
 
void OnFocusLost (bool) override
 The window has lost focus.
 
- Public Member Functions inherited from Window
 Window (WindowDesc &desc)
 Empty constructor, initialization has been moved to InitNested() called from the constructor of the derived class.
 
voidoperator new[] (size_t size)=delete
 Helper allocation function to disallow something.
 
template<class NWID >
const NWID * GetWidget (WidgetID widnum) const
 Get the nested widget with number widnum from the nested widget tree.
 
template<class NWID >
NWID * GetWidget (WidgetID widnum)
 Get the nested widget with number widnum from the nested widget tree.
 
const ScrollbarGetScrollbar (WidgetID widnum) const
 Return the Scrollbar to a widget index.
 
ScrollbarGetScrollbar (WidgetID widnum)
 Return the Scrollbar to a widget index.
 
const QueryStringGetQueryString (WidgetID widnum) const
 Return the querystring associated to a editbox.
 
QueryStringGetQueryString (WidgetID widnum)
 Return the querystring associated to a editbox.
 
void UpdateQueryStringSize ()
 Update size of all QueryStrings of this window.
 
void InitNested (WindowNumber number=0)
 Perform complete initialization of the Window with nested widgets, to allow use.
 
void CreateNestedTree ()
 Perform the first part of the initialization of a nested widget tree.
 
void FinishInitNested (WindowNumber window_number=0)
 Perform the second part of the initialization of a nested widget tree.
 
template<typename T , std::enable_if_t< std::is_base_of< StrongTypedefBase, T >::value, int > = 0>
void FinishInitNested (T number)
 
void SetTimeout ()
 Set the timeout flag of the window and initiate the timer.
 
void SetWhiteBorder ()
 Set the timeout flag of the window and initiate the timer.
 
void DisableAllWidgetHighlight ()
 Disable the highlighted status of all widgets.
 
void SetWidgetHighlight (WidgetID widget_index, TextColour highlighted_colour)
 Sets the highlighted status of a widget.
 
bool IsWidgetHighlighted (WidgetID widget_index) const
 Gets the highlighted status of a widget.
 
void SetWidgetDisabledState (WidgetID widget_index, bool disab_stat)
 Sets the enabled/disabled status of a widget.
 
void DisableWidget (WidgetID widget_index)
 Sets a widget to disabled.
 
void EnableWidget (WidgetID widget_index)
 Sets a widget to Enabled.
 
bool IsWidgetDisabled (WidgetID widget_index) const
 Gets the enabled/disabled status of a widget.
 
bool IsWidgetFocused (WidgetID widget_index) const
 Check if given widget is focused within this window.
 
bool IsWidgetGloballyFocused (WidgetID widget_index) const
 Check if given widget has user input focus.
 
void SetWidgetLoweredState (WidgetID widget_index, bool lowered_stat)
 Sets the lowered/raised status of a widget.
 
void ToggleWidgetLoweredState (WidgetID widget_index)
 Invert the lowered/raised status of a widget.
 
void LowerWidget (WidgetID widget_index)
 Marks a widget as lowered.
 
void RaiseWidget (WidgetID widget_index)
 Marks a widget as raised.
 
void RaiseWidgetWhenLowered (WidgetID widget_index)
 Marks a widget as raised and dirty (redraw), when it is marked as lowered.
 
bool IsWidgetLowered (WidgetID widget_index) const
 Gets the lowered state of a widget.
 
void UnfocusFocusedWidget ()
 Makes no widget on this window have focus.
 
bool SetFocusedWidget (WidgetID widget_index)
 Set focus within this window to the given widget.
 
EventState HandleEditBoxKey (WidgetID wid, char32_t key, uint16_t keycode)
 Process keypress for editbox widget.
 
void HandleButtonClick (WidgetID widget)
 Do all things to make a button look clicked and mark it to be unclicked in a few ticks.
 
int GetRowFromWidget (int clickpos, WidgetID widget, int padding, int line_height=-1) const
 Compute the row of a widget that a user clicked in.
 
void RaiseButtons (bool autoraise=false)
 Raise the buttons of the window.
 
template<typename... Args>
void SetWidgetsDisabledState (bool disab_stat, Args... widgets)
 Sets the enabled/disabled status of a list of widgets.
 
template<typename... Args>
void SetWidgetsLoweredState (bool lowered_stat, Args... widgets)
 Sets the lowered/raised status of a list of widgets.
 
template<typename... Args>
void RaiseWidgetsWhenLowered (Args... widgets)
 Raises the widgets and sets widgets dirty that are lowered.
 
void SetWidgetDirty (WidgetID widget_index) const
 Invalidate a widget, i.e.
 
void DrawWidgets () const
 Paint all widgets of a window.
 
void DrawViewport () const
 Draw the viewport of this window.
 
void DrawSortButtonState (WidgetID widget, SortButtonState state) const
 Draw a sort button's up or down arrow symbol.
 
WindowFindChildWindow (WindowClass wc=WC_INVALID) const
 Find the Window whose parent pointer points to this window.
 
void CloseChildWindows (WindowClass wc=WC_INVALID) const
 Close all children a window might have in a head-recursive manner.
 
void SetDirty () const
 Mark entire window as dirty (in need of re-paint)
 
void ReInit (int rx=0, int ry=0, bool reposition=false)
 Re-initialize a window, and optionally change its size.
 
bool IsShaded () const
 Is window shaded currently?
 
void SetShaded (bool make_shaded)
 Set the shaded state of the window to make_shaded.
 
void ScheduleResize ()
 Mark this window as resized and in need of OnResize() event.
 
void ProcessScheduledResize ()
 Process scheduled OnResize() event.
 
void InvalidateData (int data=0, bool gui_scope=true)
 Mark this window's data as invalid (in need of re-computing)
 
void ProcessScheduledInvalidations ()
 Process all scheduled invalidations.
 
void ProcessHighlightedInvalidations ()
 Process all invalidation of highlighted widgets.
 
virtual void ApplyDefaults ()
 Read default values from WindowDesc configuration an apply them to the window.
 
virtual Point OnInitialPosition (int16_t sm_width, int16_t sm_height, int window_number)
 Compute the initial position of the window.
 
virtual void DrawWidget (const Rect &r, WidgetID widget) const
 Draw the contents of a nested widget.
 
virtual void UpdateWidgetSize (WidgetID widget, Dimension &size, const Dimension &padding, Dimension &fill, Dimension &resize)
 Update size and resize step of a widget in the window.
 
virtual void SetStringParameters (WidgetID widget) const
 Initialize string parameters for a widget.
 
virtual EventState OnHotkey (int hotkey)
 A hotkey has been pressed.
 
virtual EventState OnCTRLStateChange ()
 The state of the control key has changed.
 
virtual void OnClick (Point pt, WidgetID widget, int click_count)
 A click with the left mouse button has been made on the window.
 
virtual bool OnRightClick (Point pt, WidgetID widget)
 A click with the right mouse button has been made on the window.
 
virtual void OnHover (Point pt, WidgetID widget)
 The mouse is hovering over a widget in the window, perform an action for it.
 
virtual bool OnTooltip (Point pt, WidgetID widget, TooltipCloseCondition close_cond)
 Event to display a custom tooltip.
 
virtual void OnMouseDrag (Point pt, WidgetID widget)
 An 'object' is being dragged at the provided position, highlight the target if possible.
 
virtual void OnDragDrop (Point pt, WidgetID widget)
 A dragged 'object' has been released.
 
virtual void OnScroll (Point delta)
 Handle the request for (viewport) scrolling.
 
virtual void OnMouseOver (Point pt, WidgetID widget)
 The mouse is currently moving over the window or has just moved outside of the window.
 
virtual void OnGameTick ()
 Called once per (game) tick.
 
virtual void OnRealtimeTick (uint delta_ms)
 Called periodically.
 
virtual void OnTimeout ()
 Called when this window's timeout has been reached.
 
virtual void OnResize ()
 Called after the window got resized.
 
virtual void OnDropdownSelect (WidgetID widget, int index)
 A dropdown option associated to this window has been selected.
 
virtual void OnDropdownClose (Point pt, WidgetID widget, int index, bool instant_close)
 A dropdown window associated to this window has been closed.
 
virtual void OnEditboxChanged (WidgetID widget)
 The text in an editbox has been edited.
 
virtual void OnQueryTextFinished (std::optional< std::string > str)
 The query window opened from this window has closed.
 
virtual void OnInvalidateData (int data=0, bool gui_scope=true)
 Some data on this window has become invalid.
 
virtual void OnPlaceObject (Point pt, TileIndex tile)
 The user clicked some place on the map when a tile highlight mode has been set.
 
virtual bool OnVehicleSelect (const struct Vehicle *v)
 The user clicked on a vehicle while HT_VEHICLE has been set.
 
virtual bool OnVehicleSelect (VehicleList::const_iterator begin, VehicleList::const_iterator end)
 The user clicked on a vehicle while HT_VEHICLE has been set.
 
virtual void OnPlaceObjectAbort ()
 The user cancelled a tile highlight mode that has been set.
 
virtual void OnPlaceDrag (ViewportPlaceMethod select_method, ViewportDragDropSelectionProcess select_proc, Point pt)
 The user is dragging over the map when the tile highlight mode has been set.
 
virtual void OnPlaceMouseUp (ViewportPlaceMethod select_method, ViewportDragDropSelectionProcess select_proc, Point pt, TileIndex start_tile, TileIndex end_tile)
 The user has dragged over the map when the tile highlight mode has been set.
 
virtual void OnPlacePresize (Point pt, TileIndex tile)
 The user moves over the map when a tile highlight mode has been set when the special mouse mode has been set to 'PRESIZE' mode.
 
virtual bool IsNewGRFInspectable () const
 Is the data related to this window NewGRF inspectable?
 
virtual void ShowNewGRFInspectWindow () const
 Show the NewGRF inspection window.
 
template<>
const NWidgetBaseGetWidget (WidgetID widnum) const
 Specialized case of Window::GetWidget for the nested widget base class.
 
- Public Member Functions inherited from ZeroedMemoryAllocator
void * operator new (size_t size)
 Memory allocator for a single class instance.
 
void * operator new[] (size_t size)
 Memory allocator for an array of class instances.
 
void operator delete (void *ptr)
 Memory release for a single class instance.
 
void operator delete[] (void *ptr)
 Memory release for an array of class instances.
 

Data Fields

int line_height
 Height of one line of text in the console.
 
int line_offset
 
int cursor_width
 
IntervalTimer< TimerWindowtruncate_interval
 Check on a regular interval if the console buffer needs truncating.
 
- Data Fields inherited from Window
WindowDescwindow_desc
 Window description.
 
WindowFlags flags
 Window flags.
 
WindowClass window_class
 Window class.
 
WindowNumber window_number
 Window number within the window class.
 
int scale
 Scale of this window – used to determine how to resize.
 
uint8_t timeout_timer
 Timer value of the WF_TIMEOUT for flags.
 
uint8_t white_border_timer
 Timer value of the WF_WHITE_BORDER for flags.
 
int left
 x position of left edge of the window
 
int top
 y position of top edge of the window
 
int width
 width of the window (number of pixels to the right in x direction)
 
int height
 Height of the window (number of pixels down in y direction)
 
ResizeInfo resize
 Resize information.
 
Owner owner
 The owner of the content shown in this window. Company colour is acquired from this variable.
 
ViewportDataviewport
 Pointer to viewport data, if present.
 
const NWidgetCorenested_focus
 Currently focused nested widget, or nullptr if no nested widget has focus.
 
std::map< WidgetID, QueryString * > querystrings
 QueryString associated to WWT_EDITBOX widgets.
 
std::unique_ptr< NWidgetBasenested_root
 Root of the nested tree.
 
WidgetLookup widget_lookup
 Indexed access to the nested widget tree. Do not access directly, use Window::GetWidget() instead.
 
NWidgetStackedshade_select
 Selection widget (NWID_SELECTION) to use for shading the window. If nullptr, window cannot shade.
 
Dimension unshaded_size
 Last known unshaded size (only valid while shaded).
 
WidgetID mouse_capture_widget
 ID of current mouse capture widget (e.g. dragged scrollbar). -1 if no widget has mouse capture.
 
Windowparent
 Parent window.
 
WindowList::iterator z_position
 

Static Public Attributes

static size_t scroll = 0
 

Additional Inherited Members

- Public Types inherited from Window
using IteratorToFront = WindowIterator< false >
 Iterate in Z order towards front.
 
using IteratorToBack = WindowIterator< true >
 Iterate in Z order towards back.
 
using Iterate = AllWindows< false >
 Iterate all windows in whatever order is easiest.
 
using IterateFromBack = AllWindows< false >
 Iterate all windows in Z order from back to front.
 
using IterateFromFront = AllWindows< true >
 Iterate all windows in Z order from front to back.
 
- Static Public Member Functions inherited from Window
static int SortButtonWidth ()
 Get width of up/down arrow of sort button state.
 
static void DeleteClosedWindows ()
 Delete all closed windows.
 
- Protected Member Functions inherited from Window
void InitializeData (WindowNumber window_number)
 Initializes the data (except the position and initial size) of a new Window.
 
void InitializePositionSize (int x, int y, int min_width, int min_height)
 Set the position and smallest size of the window.
 
virtual void FindWindowPlacementAndResize (int def_width, int def_height)
 Resize window towards the default size.
 
virtual ~Window ()
 Remove window and all its child windows from the window stack.
 
- Protected Attributes inherited from Window
std::vector< intscheduled_invalidation_data
 Data of scheduled OnInvalidateData() calls.
 
bool scheduled_resize
 Set if window has been resized.
 

Detailed Description

Definition at line 150 of file console_gui.cpp.

Constructor & Destructor Documentation

◆ IConsoleWindow()

IConsoleWindow::IConsoleWindow ( )
inline

Definition at line 157 of file console_gui.cpp.

Member Function Documentation

◆ Close()

void IConsoleWindow::Close ( int  data = 0)
inlineoverridevirtual

Hide the window and all its child windows, and mark them for a later deletion.

Reimplemented from Window.

Definition at line 172 of file console_gui.cpp.

References Window::Close(), VideoDriver::EditBoxLostFocus(), VideoDriver::GetInstance(), and ICONSOLE_CLOSED.

◆ GetCaretPosition()

Point IConsoleWindow::GetCaretPosition ( ) const
inlineoverridevirtual

Get the current caret position if an edit box has the focus.

Returns
Top-left location of the caret, relative to the window.

Reimplemented from Window.

Definition at line 340 of file console_gui.cpp.

References Textbuf::caretxoffs, Window::GetWidget(), Window::height, Textbuf::pixels, and Window::width.

◆ GetFocusedTextbuf()

const Textbuf * IConsoleWindow::GetFocusedTextbuf ( ) const
inlineoverridevirtual

Get the current input text buffer.

Returns
The currently focused input text buffer or nullptr if no input focused.

Reimplemented from Window.

Definition at line 335 of file console_gui.cpp.

◆ GetTextBoundingRect()

Rect IConsoleWindow::GetTextBoundingRect ( const char from,
const char to 
) const
inlineoverridevirtual

Get the bounding rectangle for a text range if an edit box has the focus.

Parameters
fromStart of the string range.
toEnd of the string range.
Returns
Rectangle encompassing the string range, relative to the window.

Reimplemented from Window.

Definition at line 348 of file console_gui.cpp.

References Textbuf::buf, FS_NORMAL, GetCharPosInString(), Window::GetWidget(), Window::height, line_height, Textbuf::pixels, and Window::width.

◆ GetTextCharacterAtPosition()

ptrdiff_t IConsoleWindow::GetTextCharacterAtPosition ( const Point pt) const
inlineoverridevirtual

Get the character that is rendered at a position by the focused edit box.

Parameters
ptThe position to test.
Returns
Index of the character position or -1 if no character is at the position.

Reimplemented from Window.

Definition at line 359 of file console_gui.cpp.

References Textbuf::buf, GetCharAtPosition(), Window::GetWidget(), IsInsideMM(), Textbuf::pixels, and Window::width.

◆ InsertTextString()

void IConsoleWindow::InsertTextString ( WidgetID  wid,
const char str,
bool  marked,
const char caret,
const char insert_location,
const char replacement_end 
)
inlineoverridevirtual

Insert a text string at the cursor position into the edit box widget.

Parameters
widEdit box widget.
strText string to insert.

Reimplemented from Window.

Definition at line 325 of file console_gui.cpp.

References Window::GetWidget(), Textbuf::InsertString(), and Window::SetDirty().

◆ OnFocus()

void IConsoleWindow::OnFocus ( )
inlineoverridevirtual

The window has gained focus.

Called when window gains focus.

Reimplemented from Window.

Definition at line 373 of file console_gui.cpp.

References VideoDriver::EditBoxGainedFocus(), and VideoDriver::GetInstance().

◆ OnFocusLost()

void IConsoleWindow::OnFocusLost ( bool  closing)
inlineoverridevirtual

The window has lost focus.

Called when window loses focus.

Parameters
closingTrue iff the window has lost focus in the process of closing.

Reimplemented from Window.

Definition at line 378 of file console_gui.cpp.

References VideoDriver::EditBoxLostFocus(), and VideoDriver::GetInstance().

◆ OnInit()

void IConsoleWindow::OnInit ( )
inlineoverridevirtual

Notification that the nested widget tree gets initialized.

The event can be used to perform general computations.

Note
nested_root and/or widget_lookup (normally accessed via GetWidget()) may not exist during this call.

Reimplemented from Window.

Definition at line 165 of file console_gui.cpp.

References WidgetDimensions::frametext, FS_NORMAL, GetCharacterHeight(), GetCharacterWidth(), GetStringBoundingBox(), WidgetDimensions::hsep_normal, and WidgetDimensions::scaled.

◆ OnKeyPress()

EventState IConsoleWindow::OnKeyPress ( char32_t  key,
uint16_t  keycode 
)
inlineoverridevirtual

A key has been pressed.

Parameters
keythe Unicode value of the key.
keycodethe untranslated key code including shift state.
Returns
ES_HANDLED if the key press has been handled and no other window should receive the event.

Reimplemented from Window.

Definition at line 243 of file console_gui.cpp.

References Textbuf::buf, CC_COMMAND, ES_HANDLED, ES_NOT_HANDLED, Window::GetWidget(), Window::height, HKPR_EDITING, HKPR_NOT_HANDLED, ICONSOLE_FULL, ICONSOLE_OPENED, IConsoleCmdExec(), IConsoleHistoryAdd(), IConsoleHistoryNavigate(), IConsolePrint(), IConsoleResize(), IConsoleSwitch(), line_height, LRM, MarkWholeScreenDirty(), Scroll(), and Window::SetDirty().

◆ OnMouseLoop()

void IConsoleWindow::OnMouseLoop ( )
inlineoverridevirtual

Called for every mouse loop run, which is at least once per (game) tick.

Reimplemented from Window.

Definition at line 238 of file console_gui.cpp.

References Textbuf::HandleCaret(), and Window::SetDirty().

◆ OnMouseWheel()

void IConsoleWindow::OnMouseWheel ( int  wheel)
inlineoverridevirtual

The mouse wheel has been turned.

Parameters
wheelthe amount of movement of the mouse wheel.

Reimplemented from Window.

Definition at line 368 of file console_gui.cpp.

References Scroll().

◆ OnPaint()

void IConsoleWindow::OnPaint ( )
inlineoverridevirtual

◆ Scroll()

void IConsoleWindow::Scroll ( int  amount)
inline

Scroll the content of the console.

Parameters
amountNumber of lines to scroll back.

Definition at line 183 of file console_gui.cpp.

References _iconsole_buffer, Window::GetWidget(), Window::height, line_height, and Window::SetDirty().

Referenced by OnKeyPress(), and OnMouseWheel().

Field Documentation

◆ cursor_width

int IConsoleWindow::cursor_width

Definition at line 155 of file console_gui.cpp.

◆ line_height

int IConsoleWindow::line_height

Height of one line of text in the console.

Definition at line 153 of file console_gui.cpp.

Referenced by GetTextBoundingRect(), OnKeyPress(), and Scroll().

◆ line_offset

int IConsoleWindow::line_offset

Definition at line 154 of file console_gui.cpp.

◆ scroll

size_t IConsoleWindow::scroll = 0
static

Definition at line 152 of file console_gui.cpp.

◆ truncate_interval

IntervalTimer<TimerWindow> IConsoleWindow::truncate_interval
Initial value:
= {std::chrono::seconds(3), [this](auto) {
assert(this->height >= 0 && this->line_height > 0);
size_t visible_lines = static_cast<size_t>(this->height / this->line_height);
if (TruncateBuffer() && IConsoleWindow::scroll + visible_lines > _iconsole_buffer.size()) {
IConsoleWindow::scroll = std::min<size_t>(IConsoleWindow::scroll, max_scroll);
this->SetDirty();
}
}}
static bool TruncateBuffer()
Remove old lines from the backlog buffer.
static std::deque< IConsoleLine > _iconsole_buffer
The console backlog buffer.
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
Definition window.cpp:940
int line_height
Height of one line of text in the console.
const NWID * GetWidget(WidgetID widnum) const
Get the nested widget with number widnum from the nested widget tree.
Definition window_gui.h:977
int height
Height of the window (number of pixels down in y direction)
Definition window_gui.h:312

Check on a regular interval if the console buffer needs truncating.

Definition at line 227 of file console_gui.cpp.


The documentation for this struct was generated from the following file: