Commit dcdd7919 authored by Max Kobelt's avatar Max Kobelt
Browse files

Draw name input

parent 27d1d22c
......@@ -3,11 +3,12 @@
#include <stddef.h>
#define MAX_INPUT_CHARS 10
#define PLAY_FONT_SIZE 50
#define NAME_FONT_SIZE 30
#define TEXT_SIDE_MARGIN (NAME_FONT_SIZE / 3)
extern const int GAME_SCREEN_WIDTH, GAME_SCREEN_HEIGHT, FRAME_RATE;
const size_t PLAY_FONT_SIZE = 50, NAME_FONT_SIZE = 30;
char name[MAX_INPUT_CHARS + 1] = "\0";
size_t letterCount, framesCount;
Rectangle inputBox;
......@@ -25,12 +26,9 @@ void calcMenu() {
int key = GetKeyPressed();
while (key > 0) {
// 0-9 and A-Z
if (((key >= KEY_ZERO && key <= KEY_NINE) || (key >= KEY_A && key <= KEY_Z)) && letterCount < MAX_INPUT_CHARS) {
if (!IsKeyPressed(KEY_LEFT_SHIFT) && !IsKeyPressed(KEY_RIGHT_SHIFT)) {
key += 32; // Uncapitalize
}
name[letterCount++] = (char) key;
// 0-9, A-Z and a-z
if (((key >= KEY_ZERO && key <= KEY_NINE) || (key >= KEY_A && key <= KEY_Z) || (key >= 97 && key <= 122)) && letterCount < MAX_INPUT_CHARS) {
name[letterCount++] = key;
} else if (IsKeyPressed(KEY_BACKSPACE) && letterCount > 0) {
name[--letterCount] = '\0';
}
......@@ -43,7 +41,19 @@ void drawMenu() {
DrawText("PLAY", playBtnPos.x, playBtnPos.y, PLAY_FONT_SIZE, RED);
DrawRectangleRec(inputBox, LIGHTGRAY);
DrawRectangleLines(inputBox.x, inputBox.y, inputBox.width, inputBox.height, RED);
DrawText(name,
inputBox.x + TEXT_SIDE_MARGIN,
inputBox.y + inputBox.height - NAME_FONT_SIZE,
NAME_FONT_SIZE,
RED
);
if ((++framesCount / (FRAME_RATE / 2)) % 2) {
DrawText("_", inputBox.x + 8 + MeasureText(name, NAME_FONT_SIZE), inputBox.y + inputBox.height - NAME_FONT_SIZE, NAME_FONT_SIZE, RED);
DrawText("_",
inputBox.x + TEXT_SIDE_MARGIN + MeasureText(name, NAME_FONT_SIZE),
inputBox.y + inputBox.height - NAME_FONT_SIZE,
NAME_FONT_SIZE,
RED
);
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment