SDL has a wrapped feature we can use for now, handle RETURN
This commit is contained in:
parent
93ec09351a
commit
396b07b359
16
tide.odin
16
tide.odin
@ -84,15 +84,18 @@ sdl_init :: proc() -> (ok: bool) {
|
|||||||
bt := new(BufferText)
|
bt := new(BufferText)
|
||||||
bt.builder = strings.builder_make(0, 512)
|
bt.builder = strings.builder_make(0, 512)
|
||||||
ctx.buffer_text = bt
|
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
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
process_input :: proc() {
|
process_input :: proc() {
|
||||||
e: sdl.Event
|
e: sdl.Event
|
||||||
|
|
||||||
state.buffer_dirty = false
|
|
||||||
|
|
||||||
for sdl.PollEvent(&e) {
|
for sdl.PollEvent(&e) {
|
||||||
#partial switch(e.type) {
|
#partial switch(e.type) {
|
||||||
case .QUIT:
|
case .QUIT:
|
||||||
@ -105,6 +108,10 @@ process_input :: proc() {
|
|||||||
strings.pop_rune(&ctx.buffer_text.builder)
|
strings.pop_rune(&ctx.buffer_text.builder)
|
||||||
state.buffer_dirty = true
|
state.buffer_dirty = true
|
||||||
fmt.println("Key Pressed: BACKSPACE")
|
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:
|
case .TEXTINPUT:
|
||||||
key := string(cstring(raw_data(e.text.text[:])))
|
key := string(cstring(raw_data(e.text.text[:])))
|
||||||
@ -120,7 +127,7 @@ update :: proc() {
|
|||||||
color := sdl.Color{ 0, 0, 0, 255}
|
color := sdl.Color{ 0, 0, 0, 255}
|
||||||
|
|
||||||
str := strings.to_cstring(&ctx.buffer_text.builder)
|
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) {
|
if (ctx.text_surface == nil) {
|
||||||
log.errorf(sdl.GetErrorString())
|
log.errorf(sdl.GetErrorString())
|
||||||
os.exit(1)
|
os.exit(1)
|
||||||
@ -163,6 +170,7 @@ main :: proc() {
|
|||||||
ctx.frame_end = f64(sdl.GetPerformanceCounter()) / f64(sdl.GetPerformanceFrequency())
|
ctx.frame_end = f64(sdl.GetPerformanceCounter()) / f64(sdl.GetPerformanceFrequency())
|
||||||
ctx.frame_elapsed = ctx.frame_end - ctx.frame_start
|
ctx.frame_elapsed = ctx.frame_end - ctx.frame_start
|
||||||
ctx.frame_start = ctx.frame_end
|
ctx.frame_start = ctx.frame_end
|
||||||
|
state.buffer_dirty = false
|
||||||
}
|
}
|
||||||
|
|
||||||
ttf.CloseFont(ctx.font)
|
ttf.CloseFont(ctx.font)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user