From 66c727820ad2a1158c82aea79a147da01b04e70b Mon Sep 17 00:00:00 2001 From: Brendan Hansen Date: Sun, 13 Jun 2021 14:59:35 -0500 Subject: [PATCH] improvements to textboxes --- src/tower.onyx | 49 +++++++++++++++++++++++++++++++++++-------------- 1 file changed, 35 insertions(+), 14 deletions(-) diff --git a/src/tower.onyx b/src/tower.onyx index cc328d8..34a27fb 100644 --- a/src/tower.onyx +++ b/src/tower.onyx @@ -17,6 +17,16 @@ main :: (args: [] cstr) { gl.enable(gl.BLEND); gl.blendFuncSeparate(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ONE_MINUS_SRC_ALPHA); + + + textbox1_str.buffer = memory.make_slice(u8, 64); + textbox1_str.buffer.count = 0; + textbox1_str.capacity = 64; + + textbox2_str.buffer = memory.make_slice(u8, 64); + textbox2_str.buffer.count = 0; + textbox2_str.capacity = 64; + start_loop :: () -> void #foreign "game" "start_loop" --- start_loop(); } @@ -53,19 +63,23 @@ poll_events :: () { case .MouseMove do ui.update_mouse_position(~~ event.mouse.pos_x, ~~ event.mouse.pos_y); - case .KeyDown { - #if false { - printf("'%s' was down with", event.keyboard->get_name()); - if event.keyboard.modifiers & .CTRL do print(" CTRL"); - if event.keyboard.modifiers & .ALT do print(" ALT"); - if event.keyboard.modifiers & .META do print(" META"); - if event.keyboard.modifiers & .SHIFT do print(" SHIFT"); - print(".\n"); - } + case .KeyDown, .KeyUp { + modifiers : ui.Keyboard_State.Key_State.Modifiers; + if event.keyboard.modifiers & .CTRL do modifiers |= .CTRL; + if event.keyboard.modifiers & .ALT do modifiers |= .ALT; + if event.keyboard.modifiers & .META do modifiers |= .META; + if event.keyboard.modifiers & .SHIFT do modifiers |= .SHIFT; + + if event.kind == .KeyDown { + ui.key_down(event.keyboard.keycode, modifiers); @KeycodeIsWrong // .keycode is apparently not browser independent... - if event.keyboard.keycode == 116 { - refresh :: () -> void #foreign "game" "refresh" --- - refresh(); + if event.keyboard->get_name() == "F5" { + refresh :: () -> void #foreign "game" "refresh" --- + refresh(); + } + + } else { + ui.key_up(event.keyboard.keycode, modifiers); @KeycodeIsWrong // see above } } @@ -113,6 +127,9 @@ radio_options :: enum { } radio_value := radio_options.Apples; +textbox1_str : ui.String_Buffer; +textbox2_str : ui.String_Buffer; + draw :: () { gl.clearColor(0, 0, 0, 1); gl.clear(gl.COLOR_BUFFER_BIT); @@ -142,7 +159,7 @@ draw :: () { i := 1; for ^button_value: check_buttons { checkbox, panel = split_horizontal(panel, top_height=32); - + theme := ui.default_checkbox_theme; if i == 6 { theme.text_color = .{ 0.5, 0.5, 1 }; @@ -198,7 +215,11 @@ draw :: () { textbox: ui.Rectangle; textbox, slider_panel = split_horizontal(slider_panel, top_height=48, padding=8); - ui.textbox(padding(textbox, left=12, right=12), "Test Text"); + ui.textbox(padding(textbox, left=12, right=12), ^textbox1_str); + textbox, slider_panel = split_horizontal(slider_panel, top_height=48, padding=8); + ui.textbox(padding(textbox, left=12, right=12), ^textbox2_str); + + ui.draw_text(slider_panel, conv.str_format("Pos: %i\nHash: %i", ~~str_buffer, ui.textbox_editing_state.cursor_position, ui.textbox_editing_state.hash)); } { -- 2.25.1