From b759bfe01cc0ac065b776231e4ac3210832e6b56 Mon Sep 17 00:00:00 2001 From: quou Date: Tue, 14 Jan 2025 22:20:27 +1100 Subject: clean up editor a bit --- editor.cpp | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) (limited to 'editor.cpp') diff --git a/editor.cpp b/editor.cpp index 05362e5..da83e15 100644 --- a/editor.cpp +++ b/editor.cpp @@ -8,6 +8,7 @@ static struct { UI::Toolbar* toolbar; UI::Button* mat_btn; UI::Modal* mat_win; + UI::Label* mat_name; UI::Slider* metalness_input; Model_Instance* selected_inst; int selected_mesh; @@ -20,6 +21,20 @@ static int mat_win_handler(UI::Element* e, const UI::Message& m) { return 0; } +static void setup_mat_edit() { + if (editor.selected_inst) { + Mesh* meshes = editor.selected_inst->m->get_meshes(); + Mesh& msh = meshes[editor.selected_mesh]; + Material* mat = msh.material; + editor.metalness_input->enable(); + editor.metalness_input->input->set_val(mat->metalness); + editor.mat_name->set_text(mat->name); + } else { + editor.metalness_input->disable(); + editor.mat_name->set_text(""); + } +} + static int mat_btn_handler(UI::Element* e, const UI::Message& m) { (void)e; if (m.type == UI::Message::Type::click) { @@ -32,13 +47,15 @@ static int mat_btn_handler(UI::Element* e, const UI::Message& m) { ); editor.mat_win->handler = mat_win_handler; editor.mat_btn->disable(); + editor.mat_name = editor.ui->create_element( + container, + "" + ); editor.metalness_input = editor.ui->create_element( container, 0.0f, 1.0f ); - if (!editor.selected_inst) - editor.metalness_input->disable(); editor.metalness_input->input->handler = []( UI::Element* e, const UI::Message& m @@ -52,6 +69,7 @@ static int mat_btn_handler(UI::Element* e, const UI::Message& m) { } return 0; }; + setup_mat_edit(); } return 0; } @@ -76,14 +94,7 @@ void editor_on_select(Model_Instance* instance, int mesh) { editor.selected_inst = instance; editor.selected_mesh = mesh; if (editor.mat_win) { - if (instance) { - Mesh* meshes = instance->m->get_meshes(); - Mesh& msh = meshes[mesh]; - Material* mat = msh.material; - editor.metalness_input->enable(); - editor.metalness_input->input->set_val(mat->metalness); - } else - editor.metalness_input->disable(); + setup_mat_edit(); } } } -- cgit v1.2.3-54-g00ecf