From 396b07b359a0f392e4aed459c78f0c7b4ef53924 Mon Sep 17 00:00:00 2001 From: Joseph Ferano Date: Fri, 6 Sep 2024 11:11:41 +0700 Subject: [PATCH] SDL has a wrapped feature we can use for now, handle RETURN --- tide.odin | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/tide.odin b/tide.odin index 11cd227..b0fc3ca 100644 --- a/tide.odin +++ b/tide.odin @@ -84,15 +84,18 @@ sdl_init :: proc() -> (ok: bool) { bt := new(BufferText) bt.builder = strings.builder_make(0, 512) ctx.buffer_text = bt - append(&bt.builder.buf, "// Code goes here...") + append(&bt.builder.buf, "// Code goes here...\ntest more stuff ok") + str := strings.to_cstring(&ctx.buffer_text.builder) + color := sdl.Color{ 0, 0, 0, 255} + ctx.text_surface = ttf.RenderUTF8_Blended_Wrapped(ctx.font, str, color, 900); + ctx.ftex = sdl.CreateTextureFromSurface(ctx.renderer, ctx.text_surface); + state.buffer_dirty = true return true } process_input :: proc() { e: sdl.Event - state.buffer_dirty = false - for sdl.PollEvent(&e) { #partial switch(e.type) { case .QUIT: @@ -105,6 +108,10 @@ process_input :: proc() { strings.pop_rune(&ctx.buffer_text.builder) state.buffer_dirty = true fmt.println("Key Pressed: BACKSPACE") + case .RETURN: + strings.write_rune(&ctx.buffer_text.builder, '\n') + state.buffer_dirty = true + fmt.println("Key Pressed: RETURN") } case .TEXTINPUT: key := string(cstring(raw_data(e.text.text[:]))) @@ -120,7 +127,7 @@ update :: proc() { color := sdl.Color{ 0, 0, 0, 255} str := strings.to_cstring(&ctx.buffer_text.builder) - ctx.text_surface = ttf.RenderUTF8_Blended(ctx.font, str, color); + ctx.text_surface = ttf.RenderUTF8_Blended_Wrapped(ctx.font, str, color, 900); if (ctx.text_surface == nil) { log.errorf(sdl.GetErrorString()) os.exit(1) @@ -163,6 +170,7 @@ main :: proc() { ctx.frame_end = f64(sdl.GetPerformanceCounter()) / f64(sdl.GetPerformanceFrequency()) ctx.frame_elapsed = ctx.frame_end - ctx.frame_start ctx.frame_start = ctx.frame_end + state.buffer_dirty = false } ttf.CloseFont(ctx.font)