From: Brendan Hansen Date: Mon, 31 Jan 2022 03:45:29 +0000 (-0600) Subject: improving editor feel X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=f1044854434cfd5dea8f4180cf262d35dd3b6f57;p=bar-game.git improving editor feel --- diff --git a/src/entity/editor.onyx b/src/entity/editor.onyx index f9a7a4f..8044048 100644 --- a/src/entity/editor.onyx +++ b/src/entity/editor.onyx @@ -13,6 +13,7 @@ use package glfw3 editor_init :: () { editor_font = font_lookup(.{"./assets/fonts/calibri.ttf", 18}); + editor_big_font = font_lookup(.{"./assets/fonts/calibri.ttf", 24}); selected_entity_id = Entity_Nothing; } @@ -41,7 +42,7 @@ editor_update :: (dt: f32) { #local handle_entity_selction_and_dragging :: (dt: f32) { mouse_pos := mouse_get_position_vector(); - if is_button_just_down(GLFW_MOUSE_BUTTON_LEFT) && mouse_pos.x < ~~window_width - sidebar_width { + if is_button_just_down(GLFW_MOUSE_BUTTON_LEFT) && mouse_pos.x < ~~window_width - sidebar_width && mouse_pos.y > menubar_height { selected_entity_id = Entity_Nothing; for entity_manager.entities { get_rect := entity_manager.entity_types[it.type].get_rect; @@ -93,7 +94,7 @@ editor_draw :: () { { // Draw menu bar x := 0.0f; w := cast(f32) window_width; - h := 40.0f; + h := menubar_height; y := h * (editor_openness - 1); immediate_set_color(background_color); @@ -126,9 +127,9 @@ editor_draw :: () { } immediate_rectangle(x, y, w, h); - text_width := font_get_width(editor_font, it.name); - font_draw(editor_font, x + (w - text_width) / 2, y + h / 2 + 18 / 4, it.name); - x += w; + text_width := font_get_width(editor_big_font, it.name); + font_draw(editor_big_font, x + (w - text_width) / 2, y + h / 2 + 24 / 4, it.name); + x += w + 2; } } @@ -161,39 +162,51 @@ editor_draw :: () { assert(type_info.struct_inherits(entity.type, Entity), "entity is not an entity"); info := cast(^type_info.Type_Info_Struct) type_info.get_type_info(entity.type); - font_print(editor_font, x + 2, y + 20, info.name); + font_print(editor_big_font, x + 2, y + 24, info.name); - render_struct_fields(any.{~~entity, entity.type}, 0, x, y, w, h); + render_struct_fields(any.{~~entity, entity.type}, 1, x, y + 4, w, h); } -#local render_struct_fields :: (v: any, i: i32, x, y, w, h: f32) -> (new_y: f32, new_i: i32) { +#local render_struct_fields :: (v: any, i: i32, x, y, w, h: f32, depth := 0) -> (new_y: f32, new_i: i32) { + Field_Height :: 22.0f + info := cast(^type_info.Type_Info_Struct) type_info.get_type_info(v.type); for info.members { i += 1; - y += 20; + y += Field_Height; if i % 2 == 0 { immediate_set_color(.{.3,.3,.3}); - immediate_rectangle(x, y + 2, w, 22); + immediate_rectangle(x, y + 2, w, Field_Height + 2); } - font_print(editor_font, x + 22, y + 20, it.name); + font_print(editor_font, x + 2, y + Field_Height, it.name); member_any := any.{cast(^u8) v.data + it.offset, it.type}; + #persist depth_colors := Color.[ + Color.{0.4, 0.2, 0.2}, + Color.{0.2, 0.4, 0.2}, + Color.{0.2, 0.2, 0.4}, + Color.{0.4, 0.4, 0.2} + ]; + if type_info.get_type_info(it.type).kind == .Struct { - y, i = render_struct_fields(member_any, i, x + 20, y, w - 20, h); + new_y, new_i := render_struct_fields(member_any, i, x + Field_Height, y, w - Field_Height, h, depth + 1); + immediate_set_color(depth_colors[depth % 4]); + immediate_rectangle(x, y + Field_Height + 4, Field_Height / 2, new_y - y); + y, i = new_y, new_i; } elseif it.type == Entity_ID { value_buf: [1024] u8; entity_type := (entity_manager->get(*cast(^Entity_ID) member_any.data)).type; // Dereferencing null here value_str := conv.format_va(value_buf, "{} ({})", .[member_any, .{^entity_type, type_expr}]); - font_print(editor_font, x + w - font_get_width(editor_font, value_str) - 2, y + 20, value_str); + font_print(editor_font, x + w - font_get_width(editor_font, value_str) - 2, y + Field_Height, value_str); } else { value_buf: [1024] u8; value_str := conv.format_va(value_buf, "{}", .[member_any]); - font_print(editor_font, x + w - font_get_width(editor_font, value_str) - 2, y + 20, value_str); + font_print(editor_font, x + w - font_get_width(editor_font, value_str) - 2, y + Field_Height, value_str); } } @@ -202,6 +215,7 @@ editor_draw :: () { #local { editor_font: Font; + editor_big_font: Font; editor_openness := 0.0f; editor_target_openness := 0.0f; @@ -210,6 +224,7 @@ editor_draw :: () { dragging := false; sidebar_width := 0.0f; + menubar_height := 40.0f; Tabs :: enum { None;