summaryrefslogtreecommitdiffhomepage
path: root/examples/web/text/text_input_box.c
diff options
context:
space:
mode:
authorraysan5 <[email protected]>2020-12-24 13:26:30 +0100
committerraysan5 <[email protected]>2020-12-24 13:26:30 +0100
commit83ab2cb01746a869b625c9d84fbb4737146b73a9 (patch)
tree010b0794848d863916e5acb4f766ea9e7ecb6e90 /examples/web/text/text_input_box.c
parentd11274dcfcb0f349fba16ab4b83d2b96bcac8d1a (diff)
downloadraylib.com-83ab2cb01746a869b625c9d84fbb4737146b73a9.tar.gz
raylib.com-83ab2cb01746a869b625c9d84fbb4737146b73a9.zip
Updated Web examples to raylib 3.5
Diffstat (limited to 'examples/web/text/text_input_box.c')
-rw-r--r--examples/web/text/text_input_box.c28
1 files changed, 19 insertions, 9 deletions
diff --git a/examples/web/text/text_input_box.c b/examples/web/text/text_input_box.c
index 5ab1457..52120ed 100644
--- a/examples/web/text/text_input_box.c
+++ b/examples/web/text/text_input_box.c
@@ -48,7 +48,7 @@ int main(void)
textBox = (Rectangle){ screenWidth/2 - 100, 180, 225, 50 };
#if defined(PLATFORM_WEB)
- emscripten_set_main_loop(UpdateDrawFrame, 0, 1);
+ emscripten_set_main_loop(UpdateDrawFrame, 60, 1);
#else
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
//--------------------------------------------------------------------------------------
@@ -80,23 +80,33 @@ void UpdateDrawFrame(void)
if (mouseOnText)
{
+ // Set the window's cursor to the I-Beam
+ SetMouseCursor(MOUSE_CURSOR_IBEAM);
+
+ // Get char pressed (unicode character) on the queue
int key = GetCharPressed();
- // NOTE: Only allow keys in range [32..125]
- if ((key >= 32) && (key <= 125) && (letterCount < MAX_INPUT_CHARS))
+ // Check if more characters have been pressed on the same frame
+ while (key > 0)
{
- name[letterCount] = (char)key;
- letterCount++;
+ // NOTE: Only allow keys in range [32..125]
+ if ((key >= 32) && (key <= 125) && (letterCount < MAX_INPUT_CHARS))
+ {
+ name[letterCount] = (char)key;
+ letterCount++;
+ }
+
+ key = GetCharPressed(); // Check next character in the queue
}
if (IsKeyPressed(KEY_BACKSPACE))
{
letterCount--;
- name[letterCount] = '\0';
-
if (letterCount < 0) letterCount = 0;
+ name[letterCount] = '\0';
}
}
+ else if (GetMouseCursor() != MOUSE_CURSOR_DEFAULT) SetMouseCursor(MOUSE_CURSOR_DEFAULT);
if (mouseOnText) framesCounter++;
else framesCounter = 0;
@@ -116,7 +126,7 @@ void UpdateDrawFrame(void)
DrawText(name, textBox.x + 5, textBox.y + 8, 40, MAROON);
- DrawText(FormatText("INPUT CHARS: %i/%i", letterCount, MAX_INPUT_CHARS), 315, 250, 20, DARKGRAY);
+ DrawText(TextFormat("INPUT CHARS: %i/%i", letterCount, MAX_INPUT_CHARS), 315, 250, 20, DARKGRAY);
if (mouseOnText)
{
@@ -137,7 +147,7 @@ void UpdateDrawFrame(void)
bool IsAnyKeyPressed()
{
bool keyPressed = false;
- int key = GetCharPressed();
+ int key = GetKeyPressed();
if ((key >= 32) && (key <= 126)) keyPressed = true;