DearImGui is back again
This commit is contained in:
102
metaprogram.jai
102
metaprogram.jai
@@ -44,6 +44,10 @@ build :: (build_release: bool, main_path: string, game_name: string, working_dir
|
||||
entity_serialize_proc_string: [..] string;
|
||||
|
||||
should_serialize :: (type: *Type_Info_Struct, member: Type_Info_Struct_Member) -> bool {
|
||||
if type.name == "Color" {
|
||||
return true;
|
||||
}
|
||||
|
||||
if type != null {
|
||||
if type.name == {
|
||||
case "Vector2"; {
|
||||
@@ -62,6 +66,7 @@ should_serialize :: (type: *Type_Info_Struct, member: Type_Info_Struct_Member) -
|
||||
}
|
||||
}
|
||||
case "Vector4"; #through;
|
||||
case "Color"; #through;
|
||||
case "Quaternion"; {
|
||||
if member.name == {
|
||||
case "x"; #through;
|
||||
@@ -91,7 +96,7 @@ should_make_ui :: (type: *Type_Info_Struct, member: Type_Info_Struct_Member) ->
|
||||
if to_lower_copy(it,, allocator = temp) == "hide" return false;
|
||||
}
|
||||
|
||||
if type!= null {
|
||||
if type != null {
|
||||
if type.name == {
|
||||
case "Vector2"; {
|
||||
if member.name == {
|
||||
@@ -118,6 +123,7 @@ should_make_ui :: (type: *Type_Info_Struct, member: Type_Info_Struct_Member) ->
|
||||
case; return false;
|
||||
}
|
||||
}
|
||||
case "Color"; return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -190,6 +196,64 @@ generate_member_ui :: (type: *Type_Info_Struct, builder: *String_Builder, path:
|
||||
}
|
||||
}
|
||||
|
||||
generate_member_ui_imgui :: (type: *Type_Info_Struct, builder: *String_Builder, path: string = "") {
|
||||
for type.members {
|
||||
readonly := is_readonly(type, it);
|
||||
if should_make_ui(type, it) && (should_serialize(type, it) || readonly) {
|
||||
new_path : string;
|
||||
if it.name != "entity" {
|
||||
if path.count == 0 {
|
||||
new_path = it.name;
|
||||
} else {
|
||||
new_path = tprint("%1.%2", path, it.name);
|
||||
}
|
||||
}
|
||||
|
||||
tag : Type_Info_Tag;
|
||||
if it.type.type == .VARIANT {
|
||||
info_variant := cast(*Type_Info_Variant)it.type;
|
||||
tag = info_variant.variant_of.type;
|
||||
} else {
|
||||
tag = it.type.type;
|
||||
}
|
||||
|
||||
if readonly {
|
||||
print_to_builder(builder, "\tImGui.Text(\"%\", e.%);\n", new_path, new_path);
|
||||
} else {
|
||||
if tag == {
|
||||
case .STRUCT; {
|
||||
info_struct := cast(*Type_Info_Struct) it.type;
|
||||
if info_struct.name == "Transform" {
|
||||
print_to_builder(builder, TRANSFORM_UI_IMGUI);
|
||||
} else if info_struct.name == "Vector3" {
|
||||
print_to_builder(builder, "\tImGui.DragFloat3(tprint_c(\"%\"), *e.%.component);\n", new_path, new_path);
|
||||
} else if info_struct.name == "Color" || info_struct.name == "Vector4" {
|
||||
print_to_builder(builder, "\tImGui.ColorEdit4(tprint_c(\"%\"), *e.%.component);\n", new_path, new_path);
|
||||
} else {
|
||||
generate_member_ui_imgui(info_struct, builder, new_path);
|
||||
}
|
||||
}
|
||||
case .BOOL; {
|
||||
print_to_builder(builder, "\tImGui.Checkbox(tprint_c(\"%\"), *e.%);\n", new_path, new_path);
|
||||
}
|
||||
case .STRING; {
|
||||
print_to_builder(builder, "\timgui_input_text(tprint(\"%\"), *e.%);\n", new_path, new_path);
|
||||
//ui_textfield :: (label: string, text: *string, identifier: s64 = 0, loc := #caller_location) {
|
||||
}
|
||||
case .FLOAT; {
|
||||
print_to_builder(builder, "\tImGui.DragFloat(tprint_c(\"%\"), *e.%);\n", new_path, new_path);
|
||||
}
|
||||
//case .ENUM; #through;
|
||||
case .INTEGER; {
|
||||
print_to_builder(builder, "\t{val := cast(int)e.%;\n", new_path);
|
||||
print_to_builder(builder, "\timgui_input_int(tprint(\"%\"), *val);\n", new_path);
|
||||
print_to_builder(builder, "\te.% = xx val;}\n", new_path);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TRANSFORM_UI :: #string DONE
|
||||
updated := ui_vector_field("Position", *e.transform.position);
|
||||
@@ -205,6 +269,20 @@ if updated {
|
||||
}
|
||||
DONE
|
||||
|
||||
TRANSFORM_UI_IMGUI :: #string DONE
|
||||
updated := ImGui.DragFloat3("Position", *e.transform.position.component);
|
||||
euler_rotation := quaternion_to_euler_v3(e.transform.orientation);
|
||||
euler_rotation *= RADIANS_TO_DEGREES;
|
||||
updated |= ImGui.DragFloat3("Rotation", *euler_rotation.component);
|
||||
euler_rotation *= DEGREES_TO_RADIANS;
|
||||
e.transform.orientation = euler_to_quaternion(euler_rotation);
|
||||
updated |= ImGui.DragFloat3("Scale", *e.transform.scale.component);
|
||||
|
||||
if updated {
|
||||
update_matrix(*e.transform);
|
||||
}
|
||||
DONE
|
||||
|
||||
generate_member_serialization :: (struct_type: *Type_Info_Struct, builder: *String_Builder, path: string = "") {
|
||||
for struct_type.members {
|
||||
if should_serialize(struct_type, it) {
|
||||
@@ -335,6 +413,20 @@ generate_ui_procedure_for_entity :: (code_struct: *Code_Struct) {
|
||||
array_add(*entity_serialize_proc_string, builder_to_string(*ui));
|
||||
}
|
||||
|
||||
generate_ui_procedure_for_entity_imgui :: (code_struct: *Code_Struct) {
|
||||
name := code_struct.defined_type.name;
|
||||
|
||||
// Serialize
|
||||
ui : String_Builder;
|
||||
print_to_builder(*ui, "#if EDITOR {");
|
||||
print_to_builder(*ui, "entity_ui_proc_imgui :: (e: *%) {\n", name);
|
||||
generate_member_ui_imgui(code_struct.defined_type, *ui);
|
||||
print_to_builder(*ui, "}\n");
|
||||
print_to_builder(*ui, "}");
|
||||
|
||||
array_add(*entity_serialize_proc_string, builder_to_string(*ui));
|
||||
}
|
||||
|
||||
generate_serialize_procedure_for_entity :: (code_struct: *Code_Struct) {
|
||||
name := code_struct.defined_type.name;
|
||||
|
||||
@@ -389,7 +481,7 @@ note_struct :: (code_struct: *Code_Struct) {
|
||||
print("Detected entity '%'.\n", name);
|
||||
|
||||
generate_serialize_procedure_for_entity(code_struct);
|
||||
generate_ui_procedure_for_entity(code_struct);
|
||||
generate_ui_procedure_for_entity_imgui(code_struct);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -484,11 +576,11 @@ generate_code :: (w: Workspace) {
|
||||
|
||||
for entity_type_names {
|
||||
lower := to_lower_copy (it,, allocator=temp);
|
||||
print_to_builder(*builder, "if ui_clickable_label(\"New %1\") return new_%2();", it, lower);
|
||||
print_to_builder(*builder, "if ImGui.Button(\"New %1\") return new_%2();", it, lower);
|
||||
}
|
||||
|
||||
for new_entity_procs {
|
||||
print_to_builder(*builder, "if ui_clickable_label(\"%1\") return %1();", it);
|
||||
print_to_builder(*builder, "if ImGui.Button(\"%1\") return %1();", it);
|
||||
}
|
||||
|
||||
build_string := sprint(EDITOR_UI_ENTITY_CREATION, builder_to_string(*builder));
|
||||
@@ -543,7 +635,7 @@ generate_code :: (w: Workspace) {
|
||||
builder: String_Builder;
|
||||
|
||||
for entity_type_names {
|
||||
print_to_builder(*builder, "\tcase %1; entity_ui_proc(cast(*%1)e);\n", it);
|
||||
print_to_builder(*builder, "\tcase %1; entity_ui_proc_imgui(cast(*%1)e);\n", it);
|
||||
}
|
||||
|
||||
build_string := sprint(ENTITY_UI, builder_to_string(*builder));
|
||||
|
||||
Reference in New Issue
Block a user