OpenTTD Source
1.11.2
|
Helper/buffer for input fields. More...
#include <textbuf_type.h>
Public Member Functions | |
Textbuf (uint16 max_bytes, uint16 max_chars=UINT16_MAX) | |
Initialize the textbuffer by supplying it the buffer to write into and the maximum length of this buffer. More... | |
void | Assign (StringID string) |
Render a string into the textbuffer. More... | |
void | Assign (const char *text) |
Copy a string into the textbuffer. More... | |
void CDECL | Print (const char *format,...) WARN_FORMAT(2 |
Print a formatted string into the textbuffer. | |
void CDECL void | DeleteAll () |
Delete every character in the textbuffer. | |
bool | InsertClipboard () |
Insert a chunk of text from the clipboard onto the textbuffer. More... | |
bool | InsertChar (WChar key) |
Insert a character to a textbuffer. More... | |
bool | InsertString (const char *str, bool marked, const char *caret=nullptr, const char *insert_location=nullptr, const char *replacement_end=nullptr) |
Insert a string into the text buffer. More... | |
bool | DeleteChar (uint16 keycode) |
Delete a character from a textbuffer, either with 'Delete' or 'Backspace' The character is delete from the position the caret is at. More... | |
bool | MovePos (uint16 keycode) |
Handle text navigation with arrow keys left/right. More... | |
HandleKeyPressResult | HandleKeyPress (WChar key, uint16 keycode) |
bool | HandleCaret () |
Handle the flashing of the caret. More... | |
void | UpdateSize () |
Update Textbuf type with its actual physical character and screenlength Get the count of characters in the string as well as the width in pixels. More... | |
void | DiscardMarkedText (bool update=true) |
Discard any marked text. More... | |
Data Fields | |
CharSetFilter | afilter |
Allowed characters. | |
char *const | buf |
buffer in which text is saved | |
uint16 | max_bytes |
the maximum size of the buffer in bytes (including terminating '\0') | |
uint16 | max_chars |
the maximum size of the buffer in characters (including terminating '\0') | |
uint16 | bytes |
the current size of the string in bytes (including terminating '\0') | |
uint16 | chars |
the current size of the string in characters (including terminating '\0') | |
uint16 | pixels |
the current size of the string in pixels | |
bool | caret |
is the caret ("_") visible or not | |
uint16 | caretpos |
the current position of the caret in the buffer, in bytes | |
uint16 | caretxoffs |
the current position of the caret in pixels | |
uint16 | markpos |
the start position of the marked area in the buffer, in bytes | |
uint16 | markend |
the end position of the marked area in the buffer, in bytes | |
uint16 | markxoffs |
the start position of the marked area in pixels | |
uint16 | marklength |
the length of the marked area in pixels | |
Private Member Functions | |
bool | CanDelChar (bool backspace) |
Checks if it is possible to delete a character. More... | |
void | DeleteText (uint16 from, uint16 to, bool update) |
Delete a part of the text. More... | |
void | UpdateStringIter () |
Update the character iter after the text has changed. | |
void | UpdateWidth () |
Update pixel width of the text. | |
void | UpdateCaretPosition () |
Update pixel position of the caret. | |
void | UpdateMarkedText () |
Update pixel positions of the marked text area. | |
Private Attributes | |
StringIterator * | char_iter |
Helper/buffer for input fields.
Definition at line 30 of file textbuf_type.h.
|
explicit |
Initialize the textbuffer by supplying it the buffer to write into and the maximum length of this buffer.
max_bytes | maximum size in bytes, including terminating '\0' |
max_chars | maximum size in chars, including terminating '\0' |
Definition at line 371 of file textbuf.cpp.
References afilter, StringIterator::Create(), CS_ALPHANUMERAL, max_bytes, and max_chars.
void Textbuf::Assign | ( | const char * | text | ) |
Copy a string into the textbuffer.
text | Source. |
Definition at line 406 of file textbuf.cpp.
References buf, max_bytes, strecpy(), and UpdateSize().
void Textbuf::Assign | ( | StringID | string | ) |
Render a string into the textbuffer.
string | String |
Definition at line 396 of file textbuf.cpp.
Referenced by AIDebugWindow::AIDebugWindow(), NetworkChatWindow::ChatTabCompletion(), SavePresetWindow::OnClick(), and SavePresetWindow::SavePresetWindow().
|
private |
Checks if it is possible to delete a character.
backspace | if set, delete the character before the caret, otherwise, delete the character after it. |
Definition at line 42 of file textbuf.cpp.
bool Textbuf::DeleteChar | ( | uint16 | keycode | ) |
Delete a character from a textbuffer, either with 'Delete' or 'Backspace' The character is delete from the position the caret is at.
keycode | Type of deletion, either WKC_BACKSPACE or WKC_DELETE |
Definition at line 53 of file textbuf.cpp.
|
private |
Delete a part of the text.
from | Start of the text to delete. |
to | End of the text to delete. |
update | Set to true if the internal state should be updated. |
Definition at line 240 of file textbuf.cpp.
References buf.
Referenced by DiscardMarkedText(), and InsertString().
void Textbuf::DiscardMarkedText | ( | bool | update = true | ) |
Discard any marked text.
update | Set to true if the internal state should be updated. |
Definition at line 274 of file textbuf.cpp.
References DeleteText(), markend, marklength, markpos, and markxoffs.
Referenced by InsertString().
bool Textbuf::HandleCaret | ( | ) |
Handle the flashing of the caret.
Definition at line 456 of file textbuf.cpp.
bool Textbuf::InsertChar | ( | WChar | key | ) |
Insert a character to a textbuffer.
If maxwidth of the Textbuf is zero, we don't care about the visual-length but only about the physical length of the string
key | Character to be inserted |
Definition at line 132 of file textbuf.cpp.
bool Textbuf::InsertClipboard | ( | ) |
Insert a chunk of text from the clipboard onto the textbuffer.
Get TEXT clipboard and append this up to the maximum length (either absolute or screenlength). If maxlength is zero, we don't care about the screenlength but only about the physical length of the string
Definition at line 225 of file textbuf.cpp.
References GetClipboardContents(), InsertString(), and lastof.
bool Textbuf::InsertString | ( | const char * | str, |
bool | marked, | ||
const char * | caret = nullptr , |
||
const char * | insert_location = nullptr , |
||
const char * | replacement_end = nullptr |
||
) |
Insert a string into the text buffer.
If maxwidth of the Textbuf is zero, we don't care about the visual-length but only about the physical length of the string.
str | String to insert. |
marked | Replace the currently marked text with the new text. |
caret | Move the caret to this point in the insertion string. |
insert_location | Position at which to insert the string. |
replacement_end | Replace all characters from #insert_location up to this location with the new string. |
Definition at line 162 of file textbuf.cpp.
References buf, bytes, caretpos, chars, DeleteText(), DiscardMarkedText(), marklength, and markpos.
Referenced by InsertClipboard(), and Window::InsertTextString().
bool Textbuf::MovePos | ( | uint16 | keycode | ) |
Handle text navigation with arrow keys left/right.
This defines where the caret will blink and the next character interaction will occur
keycode | Direction in which navigation occurs (WKC_CTRL |) WKC_LEFT, (WKC_CTRL |) WKC_RIGHT, WKC_END, WKC_HOME |
Definition at line 319 of file textbuf.cpp.
void Textbuf::UpdateSize | ( | ) |
Update Textbuf type with its actual physical character and screenlength Get the count of characters in the string as well as the width in pixels.
Useful when copying in a larger amount of text at once
Definition at line 430 of file textbuf.cpp.
References buf, bytes, and chars.
Referenced by Assign(), SaveLoadWindow::GenerateFileName(), and Print().