DearImGui is back again

This commit is contained in:
2025-03-22 17:33:10 +01:00
parent 9a8ab7853a
commit 2208a7200f
6 changed files with 172 additions and 49 deletions

View File

@@ -33,7 +33,8 @@ pick_scene_view_at :: (camera: Camera, coordinates: Vector2) {
editor_ui :: () {
// Scene picking
if !ui_mouse_over_window() {
blocking_input := ImGui.GetIO().WantCaptureMouse || ImGui.GetIO().WantCaptureKeyboard;
if !blocking_input {
if key_down(.MOUSE_LEFT) {
if engine.current_scene != null {
coords := engine.input.normalized_viewport_mouse_position;
@@ -43,7 +44,8 @@ editor_ui :: () {
}
{
ui_window_begin("Create", cast(s32)engine.renderer.render_target_width - 200, 5, 200, 200);
ImGui.Begin("Create", flags=ImGui.WindowFlags.NoResize);
new_entity := editor_ui_entity_creation();
if new_entity != null {
set_position(*new_entity.transform, engine.editor.camera.position + engine.editor.camera.forward * 20.0);
@@ -51,23 +53,30 @@ editor_ui :: () {
array_add(*engine.editor.selected_entities, new_entity);
}
ui_window_end();
ImGui.End();
}
ui_window_begin("Entities", 1, 5, 200, 600);
ImGui.Begin("Entities");
if engine.current_scene != null {
for engine.current_scene.entities {
if it.flags & .DELETED continue;
ui_set_next_padding(20);
clicked := false;
selected := array_find(engine.editor.selected_entities, it);
label : *u8;
if it.name.count == 0 {
clicked = ui_clickable_label(tprint("%", it.type), selected, it.id);
label = tprint_c("%", it.type);
} else {
clicked = ui_clickable_label(it.name, selected, it.id);
label = to_temp_c_string(it.name);
//clicked = ui_clickable_label(it.name, selected, it.id);
}
ImGui.PushID(tprint("%", it_index));
clicked = ImGui.Selectable(label, selected);
ImGui.PopID();
if clicked {
if !key_pressed(.CTRL) {
engine.editor.selected_entities.count = 0;
@@ -80,59 +89,44 @@ editor_ui :: () {
}
}
}
//ui_space(0, 5);
}
}
ui_window_end();
ImGui.End();
ui_window_begin("Settings", 0, cast(s32)engine.renderer.render_target_height-80, 300, 80);
ImGui.Begin("Settings");
{
if engine.editor.transform_gizmo.snap_to_grid {
if ui_toolbar_button("Snap to grid enabled", .{0.0, 0.4, 0.0, 1.0}) {
if ImGui.Button("Snap to grid enabled") {
engine.editor.transform_gizmo.snap_to_grid = false;
}
} else {
if ui_toolbar_button("Snap to grid disabled", .{0.4, 0.0, 0.0, 1.0}) {
if ImGui.Button("Snap to grid disabled") {
engine.editor.transform_gizmo.snap_to_grid = true;
}
}
if engine.editor.transform_gizmo.space == .LOCAL {
if ui_toolbar_button("LOCAL", .{0.0, 0.3, 0.0, 1.0}) {
if ImGui.Button("LOCAL") {
engine.editor.transform_gizmo.space = .WORLD;
}
} else {
if ui_toolbar_button("WORLD", .{0.0, 0.0, 0.3, 1.0}) {
if ImGui.Button("WORLD") {
engine.editor.transform_gizmo.space = .LOCAL;
}
}
//ui_space(15, 10)
ui_space(20, 0);
}
ui_window_end();
ImGui.End();
// Properties
{
if engine.editor.selected_entities.count == 1 {
ui_window_begin("Properties", 200, 200, 400, 500);
ImGui.Begin("Properties");
if engine.editor.selected_entities.count == 1 {
entity := engine.editor.selected_entities[0];
//updated := ui_vector_field("Position", *entity.transform.position);
//euler_rotation := quaternion_to_euler_v3(entity.transform.orientation);
//euler_rotation *= RADIANS_TO_DEGREES;
//updated |= ui_vector_field("Rotation", *euler_rotation);
//euler_rotation *= DEGREES_TO_RADIANS;
//entity.transform.orientation = euler_to_quaternion(euler_rotation);
//updated |= ui_vector_field("Scale", *entity.transform.scale);
//if updated {
// update_matrix(*entity.transform);
//}
entity_ui(entity);
}
ui_window_end();
ImGui.End();
}
}
}
@@ -146,6 +140,7 @@ base_editor_update :: () {
}
camera := *engine.editor.camera;
blocking_input := ImGui.GetIO().WantCaptureMouse || ImGui.GetIO().WantCaptureKeyboard;
if engine.editor.focused_widget == null && engine.mode == .EDITING {
engine.editor.should_check_entities = true;
@@ -162,14 +157,14 @@ base_editor_update :: () {
//coordinates := Vector2.{engine.editor.mouse_viewport_state.normalized_local_mouse_coordinates.x, 1.0 - engine.editor.mouse_viewport_state.normalized_local_mouse_coordinates.y};
ray := normalized_screen_to_ray_v2(engine.editor.camera, coordinates);
if !ui_mouse_over_window() {
if !blocking_input {
if update_transform_gizmo(ray, coordinates) {
engine.editor.should_check_entities = false;
}
}
}
if !engine.editor.focused_widget {
if !blocking_input {
if key_pressed(.CTRL) && key_down(.Z) {
undo();
}