diff --git a/edit2d.odin b/edit2d.odin index be00465..998fb47 100644 --- a/edit2d.odin +++ b/edit2d.odin @@ -306,8 +306,6 @@ end_frame :: proc(state: ^engine_state) } - glfw.SwapBuffers(state.window) - __e2d_interal.viewport_changed = false } cleanup :: proc(state: ^engine_state) @@ -356,13 +354,14 @@ is_key_released :: #force_inline proc(state: ^engine_state, key : i32) -> bool{ } -draw_flush :: proc(d: ^e2_draw.Draw) +draw_flush :: proc(state: ^engine_state) { + d := &state.draw if __e2d_interal.viewport_changed { d.glyph.atlas_width = d.cam.width d.glyph.atlas_height = d.cam.height - d.glyph.font_size_pt = 9 + d.glyph.font_size_pt = 12 d.glyph.width = d.cam.width d.glyph.height = d.cam.height @@ -370,5 +369,8 @@ draw_flush :: proc(d: ^e2_draw.Draw) } e2_draw.draw_flush(d, __e2d_interal.viewport_changed) + + glfw.SwapBuffers(state.window) + __e2d_interal.viewport_changed = false } diff --git a/handle_input.odin b/handle_input.odin index 610e671..2d3ae11 100644 --- a/handle_input.odin +++ b/handle_input.odin @@ -2,6 +2,7 @@ package edit2d import b2 "vendor:box2d" //import im "shared:odin-imgui" +import "core:fmt" import "vendor:glfw" import "base:runtime" import draw "./draw" @@ -78,11 +79,17 @@ handle_entity_mode :: proc( } else if is_key_pressed(state, glfw.MOUSE_BUTTON_RIGHT) { + new_def := E { engine = default_engine_entity_def(), type = .NPC } + x_pos, y_pos := glfw.GetCursorPos(state.window) + pos := draw.camera_convert_screen_to_world_32(&state.draw.cam, {f32(x_pos), f32(y_pos)}) + new_def.body_def.position = pos + + interface.selected_entity = i32(len(level.entity_defs)) append(&level.entity_defs, new_def) ret = true @@ -181,17 +188,17 @@ handle_input :: proc( + ret := false #partial switch game.interface.edit_mode { - case .ENTITY : handle_entity_mode(E, state, game_data) + case .ENTITY : ret = handle_entity_mode(E, state, game_data) // case .VERTICES : interface_handle_vertices_mode(state, game_data) // case .OVERVIEW : interface_handle_overview_mode(state, game_data) // case .CHAIN : interface_handle_chain_mode(state, game_data) // case .JOINT : interface_handle_joint_mode(state, game_data) } - return false - + return ret } diff --git a/interface.odin b/interface.odin index 6810896..097f8a0 100644 --- a/interface.odin +++ b/interface.odin @@ -169,7 +169,7 @@ mu_interface_draw_options :: proc(state: ^engine_state) } -interface_all :: proc(interface: ^interface_state) -> bool +interface_all :: proc($E: typeid, interface: ^interface_state, game_data : $G) -> bool { ret := false if interface.selected_entity <0 @@ -177,6 +177,9 @@ interface_all :: proc(interface: ^interface_state) -> bool interface.selected_entity = 0 } + + if handle_input(E, interface.state, game_data) do return true + state := interface.state mu.begin(&state.mu_ctx)