FIX: Preview page : change menu window to modal window

1.by right-click on slider, multiple menu-windows can be opened at the same time
solution: change opened window to modal window.
2.close opened menu window after reslice

Change-Id: I4973e1cf4c2ecce83602417be051d249f1aae6a4
(cherry picked from commit 8890f1b3bdf8f1374136ec40e3f44de583c71e7f)
This commit is contained in:
liz.li 2023-01-03 17:37:44 +08:00 committed by Lane.Wei
parent d38fd70c2e
commit bae334a77e
1 changed files with 129 additions and 113 deletions

View File

@ -603,6 +603,11 @@ void IMSlider::SetModeAndOnlyExtruder(const bool is_one_extruder_printed_model,
else else
m_is_wipe_tower = m_mode != SingleExtruder; m_is_wipe_tower = m_mode != SingleExtruder;
m_can_change_color = can_change_color; m_can_change_color = can_change_color;
// close opened menu window after reslice
m_show_menu = false;
m_show_custom_gcode_window = false;
m_show_go_to_layer_dialog = false;
} }
void IMSlider::SetExtruderColors( const std::vector<std::string>& extruder_colors) void IMSlider::SetExtruderColors( const std::vector<std::string>& extruder_colors)
@ -1214,10 +1219,6 @@ bool IMSlider::render(int canvas_width, int canvas_height)
float scale = (float) wxGetApp().em_unit() / 10.0f; float scale = (float) wxGetApp().em_unit() / 10.0f;
render_input_custom_gcode();
render_go_to_layer_dialog();
if (is_horizontal()) { if (is_horizontal()) {
float pos_x = std::max(LEFT_MARGIN, 0.2f * canvas_width); float pos_x = std::max(LEFT_MARGIN, 0.2f * canvas_width);
float pos_y = (canvas_height - HORIZONTAL_SLIDER_SIZE.y * m_scale); float pos_y = (canvas_height - HORIZONTAL_SLIDER_SIZE.y * m_scale);
@ -1277,67 +1278,76 @@ bool IMSlider::render(int canvas_width, int canvas_height)
void IMSlider::render_input_custom_gcode() void IMSlider::render_input_custom_gcode()
{ {
if (!m_show_custom_gcode_window) if (m_show_custom_gcode_window)
return; ImGui::OpenPopup((_u8L("Custom G-code")).c_str());
ImGuiWrapper& imgui = *wxGetApp().imgui();
static bool move_to_center = true;
static bool set_focus = true;
if (move_to_center) {
auto pos_x = wxGetApp().plater()->get_current_canvas3D()->get_canvas_size().get_width() / 2;
auto pos_y = wxGetApp().plater()->get_current_canvas3D()->get_canvas_size().get_height() / 2;
imgui.set_next_window_pos(pos_x, pos_y, ImGuiCond_Always, 0.5f, 0.5f);
move_to_center = false;
}
imgui.push_common_window_style(m_scale); ImGuiWrapper& imgui = *wxGetApp().imgui();
ImVec2 center = ImGui::GetMainViewport()->GetCenter();
static bool set_focus = true;
ImGui::SetNextWindowPos(center, ImGuiCond_Appearing, ImVec2(0.5f, 0.5f));
imgui.push_menu_style(m_scale);
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(20, 10) * m_scale);
ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 12.f * m_scale); ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 12.f * m_scale);
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(10, 3) * m_scale); ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(10, 3) * m_scale);
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(10, 7) * m_scale); ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(10, 7) * m_scale);
int windows_flag = ImGui::PushStyleColor(ImGuiCol_TitleBgActive, m_is_dark ? ImVec4(54 / 255.0f, 54 / 255.0f, 60 / 255.0f, 1.00f) : ImVec4(245 / 255.0f, 245 / 255.0f, 245 / 255.0f, 1.00f));
ImGui::GetCurrentContext()->DimBgRatio = 1.0f;
int windows_flag =
ImGuiWindowFlags_NoCollapse ImGuiWindowFlags_NoCollapse
| ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_AlwaysAutoResize
| ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoResize
| ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollbar
| ImGuiWindowFlags_NoScrollWithMouse; | ImGuiWindowFlags_NoScrollWithMouse;
imgui.begin(_u8L("Custom G-code"), windows_flag); if (ImGui::BeginPopupModal((_u8L("Custom G-code")).c_str(), NULL, windows_flag))
imgui.text(_u8L("Enter Custom G-code used on current layer:")); {
if (ImGui::IsMouseClicked(0)) { imgui.text(_u8L("Enter Custom G-code used on current layer:"));
set_focus = false; if (ImGui::IsMouseClicked(0)) {
} set_focus = false;
if (set_focus && !ImGui::IsAnyItemActive() && !ImGui::IsMouseClicked(0)) { }
ImGui::SetKeyboardFocusHere(0); if (set_focus && !ImGui::IsAnyItemActive() && !ImGui::IsMouseClicked(0)) {
} ImGui::SetKeyboardFocusHere(0);
int text_height = 6; }
ImGui::InputTextMultiline("##text", m_custom_gcode, sizeof(m_custom_gcode), ImVec2(-1, ImGui::GetTextLineHeight() * text_height)); const int text_height = 6;
//text_height = 5; ImGui::InputTextMultiline("##text", m_custom_gcode, sizeof(m_custom_gcode), ImVec2(-1, ImGui::GetTextLineHeight() * text_height));
//for (int i = 0; m_custom_gcode[i] != '\0'; ++i){
// if ('\n' == m_custom_gcode[i] && text_height < 12)
// ++text_height;
//}
ImGui::NewLine(); ImGui::NewLine();
ImGui::SameLine(ImGui::GetStyle().WindowPadding.x * 14); ImGui::SameLine(ImGui::GetStyle().WindowPadding.x * 14);
imgui.push_confirm_button_style(); imgui.push_confirm_button_style();
if (imgui.bbl_button(_L("OK")) || ImGui::IsKeyDown(ImGui::GetKeyIndex(ImGuiKey_Enter))) {
m_show_custom_gcode_window = false;
add_custom_gcode(m_custom_gcode);
move_to_center = true;
set_focus = true;
}
imgui.pop_confirm_button_style();
ImGui::SameLine(); bool disable_button = false;
imgui.push_cancel_button_style(); if (strlen(m_custom_gcode) == 0)
if (imgui.bbl_button(_L("Cancel")) || ImGui::IsKeyDown(ImGui::GetKeyIndex(ImGuiKey_Escape))) { disable_button = true;
m_show_custom_gcode_window = false; if (disable_button) {
move_to_center = true; ImGui::PushItemFlag(ImGuiItemFlags_Disabled, true);
set_focus = true; imgui.push_button_disable_style();
} }
imgui.pop_cancel_button_style(); if (imgui.bbl_button(_L("OK"))) {
add_custom_gcode(m_custom_gcode);
m_show_custom_gcode_window = false;
ImGui::CloseCurrentPopup();
set_focus = true;
}
if (disable_button) {
ImGui::PopItemFlag();
imgui.pop_button_disable_style();
}
imgui.pop_confirm_button_style();
imgui.end(); ImGui::SameLine();
ImGui::PopStyleVar(3); imgui.push_cancel_button_style();
imgui.pop_common_window_style(); if (imgui.bbl_button(_L("Cancel")) || ImGui::IsKeyDown(ImGui::GetKeyIndex(ImGuiKey_Escape))) {
m_show_custom_gcode_window = false;
ImGui::CloseCurrentPopup();
set_focus = true;
}
imgui.pop_cancel_button_style();
ImGui::EndPopup();
}
ImGui::PopStyleVar(4);
ImGui::PopStyleColor();
imgui.pop_menu_style();
} }
void IMSlider::do_go_to_layer(size_t layer_number) { void IMSlider::do_go_to_layer(size_t layer_number) {
@ -1345,80 +1355,83 @@ void IMSlider::do_go_to_layer(size_t layer_number) {
GetSelection() == ssLower ? SetLowerValue(layer_number) : SetHigherValue(layer_number); GetSelection() == ssLower ? SetLowerValue(layer_number) : SetHigherValue(layer_number);
} }
void IMSlider::render_go_to_layer_dialog(){ void IMSlider::render_go_to_layer_dialog()
if (!m_show_go_to_layer_dialog) {
return; if (m_show_go_to_layer_dialog)
ImGuiWrapper& imgui = *wxGetApp().imgui(); ImGui::OpenPopup((_u8L("Jump to layer")).c_str());
static bool move_to_center = true;
static bool set_focus = true;
if (move_to_center) {
auto pos_x = wxGetApp().plater()->get_current_canvas3D()->get_canvas_size().get_width() / 2;
auto pos_y = wxGetApp().plater()->get_current_canvas3D()->get_canvas_size().get_height() / 2;
imgui.set_next_window_pos(pos_x, pos_y, ImGuiCond_Always, 0.5f, 0.5f);
move_to_center = false;
}
imgui.push_common_window_style(m_scale); ImGuiWrapper& imgui = *wxGetApp().imgui();
ImVec2 center = ImGui::GetMainViewport()->GetCenter();
ImGui::SetNextWindowPos(center, ImGuiCond_Appearing, ImVec2(0.5f, 0.5f));
static bool set_focus = true;
imgui.push_menu_style(m_scale);
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(20, 10) * m_scale);
ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 12.f * m_scale); ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 12.f * m_scale);
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(10, 3) * m_scale); ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(10, 3) * m_scale);
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(10, 7) * m_scale); ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(10, 7) * m_scale);
ImGui::PushStyleColor(ImGuiCol_TitleBgActive, m_is_dark ? ImVec4(54 / 255.0f, 54 / 255.0f, 60 / 255.0f, 1.00f) : ImVec4(245 / 255.0f, 245 / 255.0f, 245 / 255.0f, 1.00f));
ImGui::GetCurrentContext()->DimBgRatio = 1.0f;
int windows_flag = int windows_flag =
ImGuiWindowFlags_NoCollapse ImGuiWindowFlags_NoCollapse
| ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_AlwaysAutoResize
| ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoResize
| ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollbar
| ImGuiWindowFlags_NoScrollWithMouse; | ImGuiWindowFlags_NoScrollWithMouse;
imgui.begin(_u8L("Jump to layer"), windows_flag); if (ImGui::BeginPopupModal((_u8L("Jump to layer")).c_str(), NULL, windows_flag))
imgui.text(_u8L("Please enter the layer number") + " (" + std::to_string(m_min_value + 1) + " - " + std::to_string(m_max_value + 1) + "):"); {
if (ImGui::IsMouseClicked(0)) { imgui.text(_u8L("Please enter the layer number") + " (" + std::to_string(m_min_value + 1) + " - " + std::to_string(m_max_value + 1) + "):");
set_focus = false; if (ImGui::IsMouseClicked(0)) {
} set_focus = false;
if (set_focus && !ImGui::IsAnyItemActive() && !ImGui::IsMouseClicked(0)) { }
ImGui::SetKeyboardFocusHere(0); if (set_focus && !ImGui::IsAnyItemActive() && !ImGui::IsMouseClicked(0)) {
} ImGui::SetKeyboardFocusHere(0);
ImGui::InputText("##input_layer_number", m_layer_number, sizeof(m_layer_number)); }
ImGui::InputText("##input_layer_number", m_layer_number, sizeof(m_layer_number));
ImGui::NewLine(); ImGui::NewLine();
ImGui::SameLine(GImGui->Style.WindowPadding.x * 8); ImGui::SameLine(GImGui->Style.WindowPadding.x * 8);
imgui.push_confirm_button_style(); imgui.push_confirm_button_style();
bool disable_button = false; bool disable_button = false;
if (strlen(m_layer_number) == 0) if (strlen(m_layer_number) == 0)
disable_button = true;
else {
for (size_t i = 0; i< strlen(m_layer_number); i++)
if (!isdigit(m_layer_number[i]))
disable_button = true;
if (!disable_button && (m_min_value > atoi(m_layer_number) - 1 || atoi(m_layer_number) - 1 > m_max_value))
disable_button = true; disable_button = true;
} else {
if (disable_button) { for (size_t i = 0; i < strlen(m_layer_number); i++)
ImGui::PushItemFlag(ImGuiItemFlags_Disabled, true); if (!isdigit(m_layer_number[i]))
imgui.push_button_disable_style(); disable_button = true;
} if (!disable_button && (m_min_value > atoi(m_layer_number) - 1 || atoi(m_layer_number) - 1 > m_max_value))
if (imgui.bbl_button(_L("OK")) || (!disable_button && ImGui::IsKeyDown(ImGui::GetKeyIndex(ImGuiKey_Enter)))) { disable_button = true;
do_go_to_layer(atoi(m_layer_number) - 1); }
m_show_go_to_layer_dialog = false; if (disable_button) {
move_to_center = true; ImGui::PushItemFlag(ImGuiItemFlags_Disabled, true);
set_focus = true; imgui.push_button_disable_style();
} }
if (disable_button) { if (imgui.bbl_button(_L("OK")) || (!disable_button && ImGui::IsKeyDown(ImGui::GetKeyIndex(ImGuiKey_Enter)))) {
ImGui::PopItemFlag(); do_go_to_layer(atoi(m_layer_number) - 1);
imgui.pop_button_disable_style(); m_show_go_to_layer_dialog = false;
} ImGui::CloseCurrentPopup();
imgui.pop_confirm_button_style(); set_focus = true;
}
if (disable_button) {
ImGui::PopItemFlag();
imgui.pop_button_disable_style();
}
imgui.pop_confirm_button_style();
ImGui::SameLine(); ImGui::SameLine();
imgui.push_cancel_button_style(); imgui.push_cancel_button_style();
if (imgui.bbl_button(_L("Cancel")) || ImGui::IsKeyDown(ImGui::GetKeyIndex(ImGuiKey_Escape))) { if (imgui.bbl_button(_L("Cancel")) || ImGui::IsKeyDown(ImGui::GetKeyIndex(ImGuiKey_Escape))) {
m_show_go_to_layer_dialog = false; m_show_go_to_layer_dialog = false;
move_to_center = true; ImGui::CloseCurrentPopup();
set_focus = true; set_focus = true;
} }
imgui.pop_cancel_button_style(); imgui.pop_cancel_button_style();
imgui.end(); ImGui::EndPopup();
ImGui::PopStyleVar(3); }
imgui.pop_common_window_style(); ImGui::PopStyleVar(4);
ImGui::PopStyleColor();
imgui.pop_menu_style();
} }
void IMSlider::render_menu() void IMSlider::render_menu()
@ -1477,6 +1490,9 @@ void IMSlider::render_menu()
ImGui::PopStyleVar(1); ImGui::PopStyleVar(1);
ImGuiWrapper::pop_menu_style(); ImGuiWrapper::pop_menu_style();
render_input_custom_gcode();
render_go_to_layer_dialog();
} }
void IMSlider::on_change_color_mode(bool is_dark) { void IMSlider::on_change_color_mode(bool is_dark) {