summaryrefslogtreecommitdiffhomepage
path: root/examples/web/text/text_input_box.c
diff options
context:
space:
mode:
Diffstat (limited to 'examples/web/text/text_input_box.c')
-rw-r--r--examples/web/text/text_input_box.c155
1 files changed, 0 insertions, 155 deletions
diff --git a/examples/web/text/text_input_box.c b/examples/web/text/text_input_box.c
deleted file mode 100644
index 7a9537e..0000000
--- a/examples/web/text/text_input_box.c
+++ /dev/null
@@ -1,155 +0,0 @@
-/*******************************************************************************************
-*
-* raylib [text] example - Input Box
-*
-* This example has been created using raylib 1.7 (www.raylib.com)
-* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
-*
-* Copyright (c) 2017 Ramon Santamaria (@raysan5)
-*
-********************************************************************************************/
-
-#include "raylib.h"
-
-#define MAX_INPUT_CHARS 9
-
-#if defined(PLATFORM_WEB)
- #include <emscripten/emscripten.h>
-#endif
-
-//----------------------------------------------------------------------------------
-// Global Variables Definition
-//----------------------------------------------------------------------------------
-const int screenWidth = 800;
-const int screenHeight = 450;
-
-char name[MAX_INPUT_CHARS + 1] = "\0"; // NOTE: One extra space required for line ending char '\0'
-int letterCount = 0;
-
-Rectangle textBox = { 0 };
-bool mouseOnText = false;
-
-int framesCounter = 0;
-
-//----------------------------------------------------------------------------------
-// Module Functions Declaration
-//----------------------------------------------------------------------------------
-void UpdateDrawFrame(void); // Update and Draw one frame
-
-//----------------------------------------------------------------------------------
-// Program Main Entry Point
-//----------------------------------------------------------------------------------
-int main(void)
-{
- // Initialization
- //--------------------------------------------------------------------------------------
- InitWindow(screenWidth, screenHeight, "raylib [text] example - input box");
-
- textBox = (Rectangle){ screenWidth/2 - 100, 180, 225, 50 };
-
-#if defined(PLATFORM_WEB)
- emscripten_set_main_loop(UpdateDrawFrame, 60, 1);
-#else
- SetTargetFPS(60); // Set our game to run at 60 frames-per-second
- //--------------------------------------------------------------------------------------
-
- // Main game loop
- while (!WindowShouldClose()) // Detect window close button or ESC key
- {
- UpdateDrawFrame();
- }
-#endif
-
- // De-Initialization
- //--------------------------------------------------------------------------------------
- CloseWindow(); // Close window and OpenGL context
- //--------------------------------------------------------------------------------------
-
- return 0;
-}
-
-//----------------------------------------------------------------------------------
-// Module Functions Definition
-//----------------------------------------------------------------------------------
-void UpdateDrawFrame(void)
-{
- // Update
- //----------------------------------------------------------------------------------
- if (CheckCollisionPointRec(GetMousePosition(), textBox)) mouseOnText = true;
- else mouseOnText = false;
-
- 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();
-
- // Check if more characters have been pressed on the same frame
- while (key > 0)
- {
- // 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--;
- if (letterCount < 0) letterCount = 0;
- name[letterCount] = '\0';
- }
- }
- else SetMouseCursor(MOUSE_CURSOR_DEFAULT);
-
- if (mouseOnText) framesCounter++;
- else framesCounter = 0;
- //----------------------------------------------------------------------------------
-
- // Draw
- //----------------------------------------------------------------------------------
- BeginDrawing();
-
- ClearBackground(RAYWHITE);
-
- DrawText("PLACE MOUSE OVER INPUT BOX!", 240, 140, 20, GRAY);
-
- DrawRectangleRec(textBox, LIGHTGRAY);
- if (mouseOnText) DrawRectangleLines(textBox.x, textBox.y, textBox.width, textBox.height, RED);
- else DrawRectangleLines(textBox.x, textBox.y, textBox.width, textBox.height, DARKGRAY);
-
- DrawText(name, textBox.x + 5, textBox.y + 8, 40, MAROON);
-
- DrawText(TextFormat("INPUT CHARS: %i/%i", letterCount, MAX_INPUT_CHARS), 315, 250, 20, DARKGRAY);
-
- if (mouseOnText)
- {
- if (letterCount < MAX_INPUT_CHARS)
- {
- // Draw blinking underscore char
- if (((framesCounter/20)%2) == 0) DrawText("_", textBox.x + 8 + MeasureText(name, 40), textBox.y + 12, 40, MAROON);
- }
- else DrawText("Press BACKSPACE to delete chars...", 230, 300, 20, GRAY);
- }
-
- EndDrawing();
- //----------------------------------------------------------------------------------
-}
-
-// Check if any key is pressed
-// NOTE: We limit keys check to keys between 32 (KEY_SPACE) and 126
-bool IsAnyKeyPressed()
-{
- bool keyPressed = false;
- int key = GetKeyPressed();
-
- if ((key >= 32) && (key <= 126)) keyPressed = true;
-
- return keyPressed;
-} \ No newline at end of file