32 #include "../ui_main.h"
33 #include "../ui_nodes.h"
34 #include "../ui_font.h"
35 #include "../ui_parse.h"
36 #include "../ui_behaviour.h"
37 #include "../ui_input.h"
38 #include "../ui_render.h"
39 #include "../ui_sprite.h"
40 #include "../ui_lua.h"
46 #include "../../client.h"
47 #include "../../../shared/utf8.h"
49 #include "../../../common/scripts_lua.h"
51 #if SDL_VERSION_ATLEAST(2,0,0)
55 #include <SDL/SDL_screenkeyboard.h>
59 #define EXTRADATA_TYPE textEntryExtraData_t
60 #define EXTRADATA(node) UI_EXTRADATA(node, EXTRADATA_TYPE)
67 #define MAX_CVAR_EDITING_LENGTH 256
111 editedCvar =
nullptr;
174 assert(editedCvar ==
nullptr);
176 const char* cvarRef =
"*cvar:";
177 editedCvar =
Cvar_Get(&((
const char*)node->
text)[strlen(cvarRef)]);
183 #if SDL_VERSION_ATLEAST(2,0,0)
184 SDL_StartTextInput();
187 SDL_Rect r = {
static_cast<int>(pos[0]), static_cast<int>(pos[1]),
static_cast<int>(node->
box.
size[0]), static_cast<int>(node->
box.
size[1])};
188 SDL_SetTextInputRect(&r);
193 SDL_ANDROID_GetScreenKeyboardTextInput(buf,
sizeof(buf));
207 if (editedCvar ==
nullptr)
216 #if SDL_VERSION_ATLEAST(2,0,0)
237 }
else if (unicode ==
K_DEL) {
242 int length = strlen(buffer);
246 if (length + charLength >=
sizeof(buffer))
250 if (insertedLength > 0)
305 if (unicode < 32 || (unicode >= 127 && unicode < 192))
315 const float* textColor;
323 }
else if (node->
state) {
324 textColor = node->
color;
327 textColor = node->
color;
388 behaviour->
name =
"textentry";
void onLoading(uiNode_t *node) override
Call before the script initialization of the node.
int UI_DrawStringInBox(const char *fontID, align_t align, int x, int y, int width, int height, const char *text, longlines_t method)
draw a line into a bounding box
size_t UTF8_strlen(const char *str)
Count the number of character (not the number of bytes) of a zero termination string.
struct uiAction_s * onChange
This is a cvar definition. Cvars can be user modified and used in our menus e.g.
void UI_TextEntry_SetBackgroundByName(uiNode_t *node, const char *name)
set background sprite
char * UTF8_strncpyz(char *dest, const char *src, size_t limit)
UTF8 capable string copy function.
#define MAX_CVAR_EDITING_LENGTH
void UI_RegisterTextEntryNode(uiBehaviour_t *behaviour)
bool UI_ExecuteLuaEventScript(uiNode_t *node, LUA_EVENT event)
Executes a lua event handler.
void UI_DrawSpriteInBox(bool flip, const uiSprite_t *sprite, uiSpriteStatus_t status, int posX, int posY, int sizeX, int sizeY)
void onFocusGained(uiNode_t *node) override
Called when the node got the focus.
static void UI_TextEntryNodeEdit(uiNode_t *node, unsigned int unicode)
edit the current cvar with a char
struct uiAction_s * onClick
static cvar_t * editedCvar
#define UI_RegisterExtradataNodeProperty(BEHAVIOUR, NAME, TYPE, EXTRADATATYPE, ATTRIBUTE)
Initialize a property from extradata of node.
void R_Color(const vec4_t rgba)
Change the color to given value.
void draw(uiNode_t *node) override
static const char CURSOR_OFF
void Q_strncpyz(char *dest, const char *src, size_t destsize)
Safe strncpy that ensures a trailing zero.
int UTF8_delete_char_at(char *s, int pos)
Delete a whole (possibly multibyte) character from a string.
align_t
We need this here for checking the boundaries from script values.
cvar_t * Cvar_Get(const char *var_name, const char *var_value, int flags, const char *desc)
Init or return a cvar.
#define Vector4Set(v, r, g, b, a)
QGL_EXTERN GLuint GLsizei GLsizei * length
static const char HIDECHAR
SharedPtr< uiNode > UINodePtr
#define UI_RegisterOveridedNodeProperty(BEHAVIOUR, NAME)
Initialize a property which override an inherited property. It is yet only used for the documentation...
int UTF8_insert_char_at(char *s, int n, int pos, int c)
Insert a (possibly multibyte) UTF-8 character into a string.
char const * Q_strstart(char const *str, char const *start)
Matches the start of a string.
int UTF8_encoded_len(int c)
static void UI_TextEntryNodeValidateEdition(uiNode_t *node)
callback from the keyboard
#define UI_EXTRADATA(NODE, TYPE)
void UI_ExecuteEventActions(uiNode_t *source, const uiAction_t *firstAction)
bool UI_ExecuteLuaEventScript_XY(uiNode_t *node, LUA_EVENT event, int x, int y)
Executes a lua event handler with (x,y) argument.
const char * UI_GetReferenceString(const uiNode_t *const node, const char *ref)
Atomic structure used to define most of the UI.
void * UI_SWIG_TypeQuery(const char *name)
This function queries the SWIG type table for a type information structure. It is used in combination...
void UI_TextEntryNodeUnFocus(uiNode_t *node, const uiCallContext_t *context)
force exit the edit mode of a textentry node
void UI_GetNodeAbsPos(const uiNode_t *node, vec2_t pos)
Returns the absolute position of a node.
static const char CURSOR_ON
Contain the context of the calling of a function.
const char * UI_GetFontFromNode(const uiNode_t *const node)
Return the font for a specific node or default font.
node behaviour, how a node work
void onFocusLost(uiNode_t *node) override
Called when the node lost the focus.
QGL_EXTERN GLuint GLsizei GLsizei GLint GLenum GLchar * name
bool onKeyPressed(uiNode_t *node, unsigned int key, unsigned short unicode) override
Called when we press a key when the node got the focus.
cvar_t * Cvar_ForceSet(const char *varName, const char *value)
Will set the variable even if NOSET or LATCH.
void onLeftClick(uiNode_t *node, int x, int y) override
Called when the user click with the right mouse button.
static void UI_TextEntryNodeAbortEdition(uiNode_t *node)
callback from the keyboard
static char cvarValueBackup[MAX_CVAR_EDITING_LENGTH]
uiSprite_t * UI_GetSpriteByName(const char *name)
Return an sprite by is name.
const struct value_s * UI_RegisterNodeMethod(uiBehaviour_t *behaviour, const char *name, uiNodeMethod_t function)
Register a node method to a behaviour.
void UI_TextEntryNodeFocus(uiNode_t *node, const uiCallContext_t *context)
force edition of a textentry node
int CL_Milliseconds(void)