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;
}
#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;
{ // 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);
}
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;
}
}
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);
}
}
#local {
editor_font: Font;
+ editor_big_font: Font;
editor_openness := 0.0f;
editor_target_openness := 0.0f;
dragging := false;
sidebar_width := 0.0f;
+ menubar_height := 40.0f;
Tabs :: enum {
None;