diff options
author | San Jacobs | 2025-09-26 13:41:05 +0200 |
---|---|---|
committer | San Jacobs | 2025-09-26 13:41:05 +0200 |
commit | 58bb80100d3d74aeaf13a89360caddbc1e84fd97 (patch) | |
tree | b824beac050b9da94d4caf9874fe22a69113fd0d | |
parent | 88020820193ef01e0ee7e6e15efe55901250c911 (diff) | |
download | tafl-58bb80100d3d74aeaf13a89360caddbc1e84fd97.tar.gz tafl-58bb80100d3d74aeaf13a89360caddbc1e84fd97.tar.bz2 tafl-58bb80100d3d74aeaf13a89360caddbc1e84fd97.zip |
Press and release on the same button for it to count
-rw-r--r-- | src/tafl/tafl.odin | 43 |
1 files changed, 34 insertions, 9 deletions
diff --git a/src/tafl/tafl.odin b/src/tafl/tafl.odin index 8fb9902..b92651d 100644 --- a/src/tafl/tafl.odin +++ b/src/tafl/tafl.odin @@ -28,7 +28,8 @@ mouse_left_pressed := false mouse_left_is_down := false mouse_left_released := false -clicked_id : string +clicked_pressed_id : string +clicked_release_id : string DEFAULT_FONT : rl.Font FONT_SIZE : int : 24 @@ -158,10 +159,14 @@ tafl_open :: proc( output_com.__tafl_index = this_tafl.own_index if .CLICKABLE in flags { - if clicked_id != "" && clicked_id == this_tafl.id { - output_com.clicked = true - delete(clicked_id) - clicked_id = "" + if clicked_pressed_id != "" && clicked_release_id != "" { + if clicked_pressed_id == this_tafl.id && clicked_release_id == this_tafl.id { + output_com.clicked = true + delete(clicked_pressed_id) + delete(clicked_release_id) + clicked_pressed_id = "" + clicked_release_id = "" + } } } @@ -467,14 +472,32 @@ get_window_size :: proc() -> (i32, i32) { } process_features :: proc() { + + if clicked_pressed_id != "" && clicked_release_id != "" && clicked_pressed_id != clicked_release_id { + delete(clicked_pressed_id) + delete(clicked_release_id) + clicked_pressed_id = "" + clicked_release_id = "" + } + for tafl in tafl_elements { if .CLICKABLE in tafl.flags { + if mouse_left_pressed { + // Collision check + if (tafl.x <= mouse_position.x && mouse_position.x <= (tafl.x+tafl.width) && + tafl.y <= mouse_position.y && mouse_position.y <= (tafl.y+tafl.height)) { + if clicked_pressed_id != "" do delete(clicked_pressed_id) + clicked_pressed_id = strings.clone(tafl.id) + fmt.printfln("Pressed! {}", tafl.id) + } + } if mouse_left_released { + // Collision check if (tafl.x <= mouse_position.x && mouse_position.x <= (tafl.x+tafl.width) && tafl.y <= mouse_position.y && mouse_position.y <= (tafl.y+tafl.height)) { - if clicked_id != "" do delete(clicked_id) - clicked_id = strings.clone(tafl.id) - fmt.printfln("Clicked! {}", tafl.id) + if clicked_release_id != "" do delete(clicked_release_id) + clicked_release_id = strings.clone(tafl.id) + fmt.printfln("Released! {}", tafl.id) } } } @@ -544,6 +567,7 @@ Tafl :: struct { Feature_Flag :: enum { CLICKABLE, + HOVERABLE, } Feature_Flags :: bit_set[Feature_Flag] @@ -596,7 +620,8 @@ FIXED :: proc(x: int) -> Sizing_Dimension { }*/ BUTTON : Feature_Flags : { - .CLICKABLE + .CLICKABLE, + .HOVERABLE } u8_clamp :: proc(input: f32) -> u8 { |