remove text input test
This commit is contained in:
parent
62493e8e69
commit
26950f13e3
106
src/user.c
106
src/user.c
@ -15,26 +15,6 @@
|
|||||||
#include "entity.h"
|
#include "entity.h"
|
||||||
#include "mixer.h"
|
#include "mixer.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* FIXME: remove this (testing) */
|
|
||||||
#include "uni.h"
|
|
||||||
GLOBAL u8 test_input_array[256] = { 0 };
|
|
||||||
GLOBAL u32 test_input_array_pos;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
struct bind_state {
|
struct bind_state {
|
||||||
b32 is_held; /* Is this bind held down this frame */
|
b32 is_held; /* Is this bind held down this frame */
|
||||||
u32 num_presses; /* How many times was this bind pressed since last frame */
|
u32 num_presses; /* How many times was this bind pressed since last frame */
|
||||||
@ -509,40 +489,6 @@ INTERNAL void user_update(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* FIXME: Remove this (testing) */
|
|
||||||
/* Test unicode input */
|
|
||||||
if (event->kind == SYS_EVENT_KIND_TEXT) {
|
|
||||||
u32 codepoint = event->text_codepoint;
|
|
||||||
|
|
||||||
struct uni_encode_utf8_result encoded = uni_encode_utf8(codepoint);
|
|
||||||
MEMCPY(&test_input_array[test_input_array_pos], encoded.chars8, encoded.count8);
|
|
||||||
test_input_array_pos += encoded.count8;
|
|
||||||
|
|
||||||
/* Print */
|
|
||||||
if (test_input_array_pos > ARRAY_COUNT(test_input_array) - 4) {
|
|
||||||
struct string str = { .len = test_input_array_pos, .text = test_input_array };
|
|
||||||
sys_message_box(SYS_MESSAGE_BOX_KIND_OK, str);
|
|
||||||
test_input_array_pos = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (event->kind == SYS_EVENT_KIND_BUTTON_DOWN && event->button == SYS_BTN_BACKSPACE) {
|
|
||||||
if (test_input_array_pos > 0) {
|
|
||||||
--test_input_array_pos;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/* Paste test */
|
|
||||||
if (event->kind == SYS_EVENT_KIND_BUTTON_DOWN && event->button == SYS_BTN_V && G.bind_states[USER_BIND_KIND_CTRL_TEST].is_held) {
|
|
||||||
struct string clipboard = sys_get_clipboard_text(scratch.arena);
|
|
||||||
u64 copy_size = min_u64(clipboard.len, ARRAY_COUNT(test_input_array) - test_input_array_pos - 4);
|
|
||||||
MEMCPY(&test_input_array[test_input_array_pos], clipboard.text, copy_size);
|
|
||||||
test_input_array_pos += copy_size;
|
|
||||||
}
|
|
||||||
/* Copy test */
|
|
||||||
if (event->kind == SYS_EVENT_KIND_BUTTON_DOWN && event->button == SYS_BTN_C && G.bind_states[USER_BIND_KIND_CTRL_TEST].is_held) {
|
|
||||||
struct string src = { .text = test_input_array, .len = test_input_array_pos };
|
|
||||||
sys_set_clipboard_text(src);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ========================== *
|
/* ========================== *
|
||||||
@ -1027,58 +973,6 @@ INTERNAL void user_update(void)
|
|||||||
arena_temp_end(temp);
|
arena_temp_end(temp);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* TODO: remove this */
|
|
||||||
/* Draw test input string */
|
|
||||||
{
|
|
||||||
struct font *font = font_load(STR("res/fonts/fixedsys.ttf"), 12.0f);
|
|
||||||
|
|
||||||
#if 0
|
|
||||||
struct rect atlas_rect = {
|
|
||||||
.pos = V2(0, 0),
|
|
||||||
.size = font->texture.size
|
|
||||||
};
|
|
||||||
struct draw_texture_params dparams = DRAW_TEXTURE_PARAMS(.texture = &font->texture);
|
|
||||||
draw_texture_rect(G.viewport_canvas, dparams, atlas_rect);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
struct string src_str = (struct string) { .len = test_input_array_pos, .text = test_input_array };
|
|
||||||
struct string draw_str = string_copy(scratch.arena, src_str);
|
|
||||||
{
|
|
||||||
u64 codepoint_count = 0;
|
|
||||||
u64 pos = 0;
|
|
||||||
while (pos < src_str.len) {
|
|
||||||
struct string remaining = { .len = src_str.len - pos, .text = src_str.text + pos };
|
|
||||||
struct uni_decode_utf8_result decoded = uni_decode_utf8(remaining);
|
|
||||||
|
|
||||||
if (codepoint_count % 10 == 0) {
|
|
||||||
draw_str.len += string_copy(scratch.arena, STR("\n")).len;
|
|
||||||
}
|
|
||||||
|
|
||||||
draw_str.len += string_copy(scratch.arena, STR("[")).len;
|
|
||||||
draw_str.len += string_from_uint(scratch.arena, decoded.codepoint, 16).len;
|
|
||||||
draw_str.len += string_copy(scratch.arena, STR("]: '")).len;
|
|
||||||
|
|
||||||
struct string character = { .len = decoded.advance8, .text = remaining.text };
|
|
||||||
if (string_eq(character, STR("\n"))) {
|
|
||||||
character = STR("\\n");
|
|
||||||
} else if (string_eq(character, STR("\r"))) {
|
|
||||||
character = STR("\\r");
|
|
||||||
}
|
|
||||||
draw_str.len += string_copy(scratch.arena, character).len;
|
|
||||||
|
|
||||||
draw_str.len += string_copy(scratch.arena, STR("' ")).len;
|
|
||||||
|
|
||||||
pos += decoded.advance8;
|
|
||||||
++codepoint_count;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//struct v2 pos = v2_round(V2(0, G.viewport_size.y / 2));
|
|
||||||
struct v2 pos = v2_round(V2(0, 0));
|
|
||||||
draw_text(G.viewport_canvas, font, pos, draw_str);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Push game cmds */
|
/* Push game cmds */
|
||||||
pubilsh_game_cmds(&cmd_list);
|
pubilsh_game_cmds(&cmd_list);
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user