mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-12-05 11:17:58 -05:00
Assembly View fixes & improvements (#14431)
* init * Update GLCanvas3D.cpp * Update GLCanvas3D.cpp * Update GLCanvas3D.cpp * update * update * simplify solution * fix hit test * correct variable name * simplify arrow implementation * Update GLCanvas3D.cpp
This commit is contained in:
3 files changed
+69
-52
No files matched your search
@@ -3077,6 +3077,12 @@ void GLCanvas3D::update_volumes_colors_by_extruder()
|
||||
m_volumes.update_colors_by_extruder(m_config);
|
||||
}
|
||||
|
||||
float GLCanvas3D::get_assemble_view_gizmos_left() const
|
||||
{
|
||||
const float right_inset = get_assemble_view_toolbar_margin() + (is_collapse_toolbar_on_left() ? 0.f : get_collapse_toolbar_width());
|
||||
return (float)get_canvas_size().get_width() - right_inset - m_gizmos.get_scaled_total_width();
|
||||
}
|
||||
|
||||
bool GLCanvas3D::is_collapse_toolbar_on_left() const
|
||||
{
|
||||
return collapse_side() == CollapseSide::Left;
|
||||
@@ -12087,8 +12093,8 @@ void GLCanvas3D::_render_return_toolbar() const
|
||||
auto canvas_h = float(cnv_size.get_height());
|
||||
float window_width = real_size.x + button_icon_size.x + imgui.scaled(2.0f);
|
||||
float window_height = button_icon_size.y + imgui.scaled(2.0f);
|
||||
float window_pos_x = 30.0f + (is_collapse_toolbar_on_left() ? (get_collapse_toolbar_width() + 5.f) : 0);
|
||||
float window_pos_y = 14.0f;
|
||||
float window_pos_x = get_assemble_view_toolbar_margin() + (is_collapse_toolbar_on_left() ? get_collapse_toolbar_width() : 0.f); // ORCA place return button closer to corner
|
||||
float window_pos_y = 0.0f; // ORCA
|
||||
|
||||
imgui.set_next_window_pos(window_pos_x, window_pos_y, ImGuiCond_Always, 0, 0);
|
||||
#ifdef __WINDOWS__
|
||||
@@ -12117,7 +12123,7 @@ void GLCanvas3D::_render_return_toolbar() const
|
||||
|
||||
ImVec4 bg_col = ImVec4(0.0f, 0.0f, 0.0f, 0.0f);
|
||||
ImVec4 tint_col = fg_color; // icon color
|
||||
ImVec2 margin = ImVec2(10.0f, 5.0f);
|
||||
ImVec2 margin = ImVec2(10.0f, 0.0f);
|
||||
|
||||
if (ImGui::ImageTextButton(real_size,_utf8(L("Return")).c_str(), m_return_toolbar.get_return_texture_id(), button_icon_size, uv0, uv1, -1, bg_col, tint_col, margin)) {
|
||||
const_cast<GLGizmosManager*>(&m_gizmos)->reset_all_states();
|
||||
@@ -12145,6 +12151,7 @@ void GLCanvas3D::_render_return_toolbar() const
|
||||
ImGui::PopStyleColor(5);
|
||||
ImGui::PopStyleVar(1);
|
||||
|
||||
m_return_toolbar_right = ImGui::GetWindowWidth() + window_pos_x;
|
||||
imgui.end();
|
||||
}
|
||||
|
||||
@@ -12563,8 +12570,7 @@ bool GLCanvas3D::_is_mouse_over_top_toolbar(const Vec2d& mouse_pos) const
|
||||
if (m_canvas_type == ECanvasType::CanvasAssembleView) {
|
||||
if (!m_gizmos.is_enabled() || m_gizmos.get_selectable_icons_cnt() == 0)
|
||||
return false;
|
||||
// same as GLGizmosManager::do_render_overlay()
|
||||
left = 0.5f * (float)get_canvas_size().get_width() + 0.5f * m_paint_toolbar_width;
|
||||
left = get_assemble_view_gizmos_left();
|
||||
width = m_gizmos.get_scaled_total_width();
|
||||
height = m_gizmos.get_scaled_total_height();
|
||||
} else {
|
||||
@@ -12612,7 +12618,9 @@ void GLCanvas3D::_render_paint_toolbar() const
|
||||
#else
|
||||
float f_scale = 1.0f;
|
||||
#endif
|
||||
int em_unit = wxGetApp().em_unit() / 10;
|
||||
#ifdef WIN32
|
||||
f_scale *= (float) get_dpi_for_window(wxGetApp().GetTopWindow()) / (float) DPI_DEFAULT; // ORCA scale with the screen
|
||||
#endif
|
||||
|
||||
std::vector<std::string> colors = wxGetApp().plater()->get_extruder_colors_from_plater_config();
|
||||
int extruder_num = colors.size();
|
||||
@@ -12626,6 +12634,8 @@ void GLCanvas3D::_render_paint_toolbar() const
|
||||
std::string display_filament_type;
|
||||
iter->config.get_filament_type(display_filament_type);
|
||||
auto pos = display_filament_type.find(' ');
|
||||
if (pos == std::string::npos)
|
||||
pos = display_filament_type.find('-'); // ORCA also try to split with "-". it saves space for -AERO, -CF
|
||||
if (pos != std::string::npos) {
|
||||
filament_text_first_line.push_back(display_filament_type.substr(0, pos));
|
||||
filament_text_second_line.push_back(display_filament_type.substr(pos + 1));
|
||||
@@ -12647,28 +12657,36 @@ void GLCanvas3D::_render_paint_toolbar() const
|
||||
}
|
||||
|
||||
ImGuiWrapper& imgui = *wxGetApp().imgui();
|
||||
const float canvas_w = float(get_canvas_size().get_width());
|
||||
const ImVec2 button_size = ImVec2(64.0f, 48.0f) * f_scale * em_unit;
|
||||
const float spacing = 4.0f * em_unit * f_scale;
|
||||
const float return_button_margin = 130.0f * em_unit * f_scale;
|
||||
const float assembly_icon_h = m_assemble_view_toolbar.get_scaled_icon_size();
|
||||
const ImVec2 button_size = ImVec2(assembly_icon_h * 1.2f, assembly_icon_h); // ORCA match button size with toolbar height
|
||||
const float spacing = 4.f * f_scale;
|
||||
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(spacing, spacing));
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0);
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(spacing, 0));
|
||||
ImGui::PushStyleColor(ImGuiCol_WindowBg, m_is_dark ? ImGuiWrapper::COL_TOOLBAR_BG_DARK : ImGuiWrapper::COL_TOOLBAR_BG); // ORCA Toolbar color
|
||||
|
||||
imgui.set_next_window_pos(0.5f * canvas_w, 0, ImGuiCond_Always, 0.5f, 0.0f);
|
||||
float constraint_window_width = canvas_w - 2 * return_button_margin;
|
||||
ImGui::SetNextWindowSizeConstraints({ 0, 0 }, { constraint_window_width, FLT_MAX });
|
||||
// ORCA center it between the return button and the gizmo bar
|
||||
const float max_pos_x = get_assemble_view_gizmos_left() - get_assemble_view_toolbar_margin();
|
||||
imgui.set_next_window_pos(0.5f * (m_return_toolbar_right + max_pos_x), 0, ImGuiCond_Always, 0.5f, 0.0f);
|
||||
// Keep room for one button on a canvas too narrow for the bar: ImGui reads a negative limit as "keep the current size".
|
||||
float constraint_window_width = std::max(max_pos_x - m_return_toolbar_right, button_size.x + spacing * 2.f);
|
||||
ImGui::SetNextWindowSizeConstraints({ 0, 0 }, { constraint_window_width, assembly_icon_h + spacing * 2.f });
|
||||
imgui.begin(_L("Paint Toolbar"), ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse);
|
||||
|
||||
const float cursor_y = ImGui::GetCursorPosY();
|
||||
const ImVec2 arrow_button_size = ImVec2(0.375f * button_size.x, ImGui::GetWindowHeight());
|
||||
const ImRect left_arrow_button = ImRect(ImGui::GetCurrentWindow()->Pos, ImGui::GetCurrentWindow()->Pos + arrow_button_size);
|
||||
const ImRect right_arrow_button = ImRect(ImGui::GetCurrentWindow()->Pos + ImGui::GetWindowSize() - arrow_button_size, ImGui::GetCurrentWindow()->Pos + ImGui::GetWindowSize());
|
||||
ImU32 left_arrow_button_color = IM_COL32(0, 0, 0, 0.4f * 255);
|
||||
ImU32 right_arrow_button_color = IM_COL32(0, 0, 0, 0.4f * 255);
|
||||
ImU32 arrow_color = IM_COL32(255, 255, 255, 255);
|
||||
// ORCA an arrow shows only when the bar can scroll that way. It covers the button under it while it shows, and after
|
||||
// it hides until the cursor leaves its place: spamming an arrow to reach the end must not change a color
|
||||
const bool show_left_arrow = ImGui::GetScrollX() > 0.0f;
|
||||
const bool show_right_arrow = ImGui::GetScrollX() < ImGui::GetScrollMaxX();
|
||||
bool& left_arrow_held = m_paint_toolbar_arrow_held[0];
|
||||
bool& right_arrow_held = m_paint_toolbar_arrow_held[1];
|
||||
left_arrow_held = ImGui::IsMouseHoveringRect(left_arrow_button.Min, left_arrow_button.Max) && (show_left_arrow || left_arrow_held);
|
||||
right_arrow_held = ImGui::IsMouseHoveringRect(right_arrow_button.Min, right_arrow_button.Max) && (show_right_arrow || right_arrow_held);
|
||||
ImU32 arrow_color = ImGui::GetColorU32(m_is_dark ? ImGuiWrapper::COL_TOOLBAR_BG : ImGuiWrapper::COL_TOOLBAR_BG_DARK); // ORCA
|
||||
ImDrawList* draw_list = ImGui::GetWindowDrawList();
|
||||
ImGuiContext& context = *GImGui;
|
||||
bool disabled = !wxGetApp().plater()->can_fillcolor();
|
||||
@@ -12688,13 +12706,13 @@ void GLCanvas3D::_render_paint_toolbar() const
|
||||
if (disabled)
|
||||
ImGui::PushItemFlag(ImGuiItemFlags_Disabled, true);
|
||||
if (ImGui::Button(("##filament_button" + std::to_string(i)).c_str(), button_size)) {
|
||||
if (!ImGui::IsMouseHoveringRect(left_arrow_button.Min, left_arrow_button.Max) && !ImGui::IsMouseHoveringRect(right_arrow_button.Min, right_arrow_button.Max))
|
||||
if (!left_arrow_held && !right_arrow_held)
|
||||
wxPostEvent(m_canvas, IntEvent(EVT_GLTOOLBAR_FILLCOLOR, i + 1));
|
||||
}
|
||||
if (i < (int) gradient_ramps.size() && !gradient_ramps[i].empty())
|
||||
ImGuiWrapper::draw_gradient_ramp(draw_list, ImGui::GetItemRectMin(), ImGui::GetItemRectMax(), gradient_ramps[i]);
|
||||
if (ImGui::IsItemHovered() && i < 9) {
|
||||
if (!ImGui::IsMouseHoveringRect(left_arrow_button.Min, left_arrow_button.Max) && !ImGui::IsMouseHoveringRect(right_arrow_button.Min, right_arrow_button.Max)) {
|
||||
if (!left_arrow_held && !right_arrow_held) {
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, { 20.0f * f_scale, 10.0f * f_scale });
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 3.0f * f_scale);
|
||||
imgui.tooltip(wxString::Format(_L("Shortcut Key %d"), i + 1), ImGui::GetFontSize() * 20.0f);
|
||||
@@ -12706,7 +12724,7 @@ void GLCanvas3D::_render_paint_toolbar() const
|
||||
ImGui::PopItemFlag();
|
||||
}
|
||||
|
||||
const float text_offset_y = 4.0f * em_unit * f_scale;
|
||||
const float text_offset_y = 2.f * f_scale;
|
||||
for (int i = 0; i < extruder_num; i++) {
|
||||
// A gradient slot's swatch shows its fade instead of the blended colour in `colors`, so the
|
||||
// labels take their contrast from the colour printed at the middle of the fade they sit on.
|
||||
@@ -12726,39 +12744,34 @@ void GLCanvas3D::_render_paint_toolbar() const
|
||||
imgui.pop_bold_font();
|
||||
|
||||
ImVec2 filament_first_line_label_size = ImGui::CalcTextSize(filament_text_first_line[i].c_str());
|
||||
ImGui::SetCursorPosY(cursor_y + text_offset_y + number_label_size.y);
|
||||
ImGui::SetCursorPosY(cursor_y + text_offset_y + number_label_size.y * .8f * (filament_text_second_line[i].empty() ? 1.5f : 1.f)); // ORCA center a single line
|
||||
ImGui::SetCursorPosX(spacing + i * (spacing + button_size.x) + (button_size.x - filament_first_line_label_size.x) / 2);
|
||||
ImGui::TextColored(text_color, "%s", filament_text_first_line[i].c_str());
|
||||
|
||||
ImVec2 filament_second_line_label_size = ImGui::CalcTextSize(filament_text_second_line[i].c_str());
|
||||
ImGui::SetCursorPosY(cursor_y + text_offset_y + number_label_size.y + filament_first_line_label_size.y);
|
||||
ImGui::SetCursorPosY(cursor_y + text_offset_y + number_label_size.y * .6f + filament_first_line_label_size.y);
|
||||
ImGui::SetCursorPosX(spacing + i * (spacing + button_size.x) + (button_size.x - filament_second_line_label_size.x) / 2);
|
||||
ImGui::TextColored(text_color, "%s", filament_text_second_line[i].c_str());
|
||||
}
|
||||
|
||||
if (ImGui::GetWindowWidth() == constraint_window_width) {
|
||||
if (ImGui::IsMouseHoveringRect(left_arrow_button.Min, left_arrow_button.Max)) {
|
||||
left_arrow_button_color = IM_COL32(0, 0, 0, 0.64f * 255);
|
||||
if (context.IO.MouseClicked[ImGuiMouseButton_Left]) {
|
||||
ImGui::SetScrollX(ImGui::GetScrollX() - button_size.x);
|
||||
imgui.set_requires_extra_frame();
|
||||
}
|
||||
// ORCA an arrow scrolls further the more buttons are in view, in whole buttons so they keep their place under the arrows
|
||||
const float button_stride = button_size.x + spacing;
|
||||
const int visible_buttons = int((ImGui::GetWindowWidth() - spacing) / button_stride);
|
||||
const float scroll_step = (visible_buttons > 8 ? 4 : visible_buttons > 4 ? 2 : 1) * button_stride;
|
||||
auto render_arrow_button = [&](const ImRect& rect, ImGuiDir dir) {
|
||||
const bool hovered = ImGui::IsMouseHoveringRect(rect.Min, rect.Max);
|
||||
if (hovered && context.IO.MouseClicked[ImGuiMouseButton_Left]) {
|
||||
ImGui::SetScrollX(ImGui::GetScrollX() + (dir == ImGuiDir_Left ? -1.f : 1.f) * scroll_step);
|
||||
imgui.set_requires_extra_frame();
|
||||
}
|
||||
draw_list->AddRectFilled(left_arrow_button.Min, left_arrow_button.Max, left_arrow_button_color);
|
||||
ImGui::BBLRenderArrow(draw_list, left_arrow_button.GetCenter() - ImVec2(draw_list->_Data->FontSize, draw_list->_Data->FontSize) * 0.5f, arrow_color, ImGuiDir_Left, 2.0f);
|
||||
draw_list->AddRectFilled(rect.Min, rect.Max, ImGui::GetColorU32(ImGuiCol_WindowBg, hovered ? .9f : .7f)); // ORCA the toolbar's color, see through
|
||||
ImGui::BBLRenderArrow(draw_list, rect.GetCenter() - ImVec2(draw_list->_Data->FontSize, draw_list->_Data->FontSize) * 0.5f, arrow_color, dir, 2.f * f_scale);
|
||||
};
|
||||
if (show_left_arrow)
|
||||
render_arrow_button(left_arrow_button, ImGuiDir_Left);
|
||||
if (show_right_arrow)
|
||||
render_arrow_button(right_arrow_button, ImGuiDir_Right);
|
||||
|
||||
if (ImGui::IsMouseHoveringRect(right_arrow_button.Min, right_arrow_button.Max)) {
|
||||
right_arrow_button_color = IM_COL32(0, 0, 0, 0.64f * 255);
|
||||
if (context.IO.MouseClicked[ImGuiMouseButton_Left]) {
|
||||
ImGui::SetScrollX(ImGui::GetScrollX() + button_size.x);
|
||||
imgui.set_requires_extra_frame();
|
||||
}
|
||||
}
|
||||
draw_list->AddRectFilled(right_arrow_button.Min, right_arrow_button.Max, right_arrow_button_color);
|
||||
ImGui::BBLRenderArrow(draw_list, right_arrow_button.GetCenter() - ImVec2(draw_list->_Data->FontSize, draw_list->_Data->FontSize) * 0.5f, arrow_color, ImGuiDir_Right, 2.0f);
|
||||
}
|
||||
|
||||
m_paint_toolbar_width = (ImGui::GetWindowWidth() + 50.0f * em_unit * f_scale);
|
||||
imgui.end();
|
||||
ImGui::PopStyleVar(3);
|
||||
ImGui::PopStyleColor();
|
||||
@@ -12904,8 +12917,6 @@ void GLCanvas3D::_render_assemble_info() const
|
||||
ImGuiWrapper* imgui = wxGetApp().imgui();
|
||||
auto canvas_w = float(get_canvas_size().get_width());
|
||||
auto canvas_h = float(get_canvas_size().get_height());
|
||||
float space_size = imgui->get_style_scaling() * 8.0f;
|
||||
float caption_max = imgui->calc_text_size(_L("Total Volume:")).x + 3 * space_size;
|
||||
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
ImFont* font = io.Fonts->Fonts[0];
|
||||
@@ -12916,6 +12927,8 @@ void GLCanvas3D::_render_assemble_info() const
|
||||
float margin = 10.0f * get_scale();
|
||||
imgui->set_next_window_pos(canvas_w - margin, canvas_h - margin, ImGuiCond_Always, 1.0f, 1.0f);
|
||||
ImGuiWrapper::push_common_window_style(get_scale()); // ORCA use window style for popups with title
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding , ImVec2(margin, margin)); // Use less horizontal padding
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowTitleAlign, ImVec2(.5f, .5f)); // Use centered title
|
||||
imgui->begin(_L("Assembly Info"), ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoCollapse);
|
||||
font->Scale = origScale;
|
||||
ImGui::PushFont(font);
|
||||
@@ -12925,12 +12938,13 @@ void GLCanvas3D::_render_assemble_info() const
|
||||
double size1 = m_selection.get_bounding_box().size()(1);
|
||||
double size2 = m_selection.get_bounding_box().size()(2);
|
||||
if (!m_selection.is_empty()) {
|
||||
ImGui::Text("%s", _L("Volume:").ToUTF8().data()); ImGui::SameLine(caption_max);
|
||||
imgui->bold_text(_L("Volume:").utf8_string()); // ORCA draw on new line to make modal smaller
|
||||
ImGui::Text("%.2f", size0 * size1 * size2);
|
||||
ImGui::Text("%s", _L("Size:").ToUTF8().data()); ImGui::SameLine(caption_max);
|
||||
imgui->bold_text(_L("Size:").utf8_string()); // ORCA draw on new line to make modal smaller
|
||||
ImGui::Text("%.2f x %.2f x %.2f", size0, size1, size2);
|
||||
}
|
||||
imgui->end();
|
||||
ImGui::PopStyleVar(2);
|
||||
ImGuiWrapper::pop_common_window_style();
|
||||
}
|
||||
|
||||
|
||||
@@ -790,7 +790,9 @@ private:
|
||||
mutable IMReturnToolbar m_return_toolbar;
|
||||
mutable Vec2i32 m_canvas_toolbar_pos = {140, 5};
|
||||
mutable float m_sc{1};
|
||||
mutable float m_paint_toolbar_width;
|
||||
mutable float m_return_toolbar_right{0.f};
|
||||
// Filament bar: the cursor is still where a scroll arrow was when it hid, {left, right}.
|
||||
mutable std::array<bool, 2> m_paint_toolbar_arrow_held{false, false};
|
||||
bool m_collapse_toolbar_enabled{true};
|
||||
// The collapse button of a sidebar other than Prepare's, from set_collapse_toolbar().
|
||||
GLToolbar* m_collapse_toolbar{nullptr};
|
||||
@@ -1291,7 +1293,9 @@ public:
|
||||
int get_main_toolbar_width() const { return m_main_toolbar.get_width(); }
|
||||
float get_assemble_view_toolbar_width() const { return m_assemble_view_toolbar.get_width(); }
|
||||
float get_assemble_view_toolbar_height() const { return m_assemble_view_toolbar.get_height(); }
|
||||
float get_assembly_paint_toolbar_width() const { return m_paint_toolbar_width; }
|
||||
float get_assemble_view_toolbar_margin() const { return m_assemble_view_toolbar.get_scaled_icon_size() * .2f; }
|
||||
// Left edge, in pixels, of the gizmo bar in the assemble view: right aligned, inside the collapse button.
|
||||
float get_assemble_view_gizmos_left() const;
|
||||
// Half the separator toolbar follows each bar that shows icons: left the main toolbar, right the gizmo bar.
|
||||
float get_separator_toolbar_width(bool left) const;
|
||||
float get_separator_toolbar_height() const { return m_separator_toolbar.get_height(); }
|
||||
|
||||
@@ -217,9 +217,7 @@ GLGizmosManager::EType GLGizmosManager::get_gizmo_from_mouse(const Vec2d &mouse_
|
||||
//float space_width = GLGizmosManager::Default_Icons_Size * wxGetApp().toolbar_icon_scale();;
|
||||
float top_x;
|
||||
if (m_parent.get_canvas_type() == GLCanvas3D::CanvasAssembleView) {
|
||||
const float cnv_w = (float)m_parent.get_canvas_size().get_width();
|
||||
|
||||
top_x = 0.5f * cnv_w + 0.5f * (m_parent.get_assembly_paint_toolbar_width());
|
||||
top_x = m_parent.get_assemble_view_gizmos_left() + border; // the icons start after the border, as in do_render_overlay()
|
||||
} else {
|
||||
top_x = m_parent.get_main_toolbar_offset();
|
||||
top_x += m_parent.get_main_toolbar_width() + m_parent.get_separator_toolbar_width(true) + border;
|
||||
@@ -1487,7 +1485,8 @@ void GLGizmosManager::do_render_overlay(bool draw_icons) const
|
||||
|
||||
float top_x;
|
||||
if (m_parent.get_canvas_type() == GLCanvas3D::CanvasAssembleView) {
|
||||
top_x = m_parent.get_assembly_paint_toolbar_width() * inv_cnv_w;
|
||||
// from pixels to {-1, 1}
|
||||
top_x = 2.0f * m_parent.get_assemble_view_gizmos_left() * inv_cnv_w - 1.0f;
|
||||
}
|
||||
else {
|
||||
//BBS: GUI refactor: GLToolbar&&Gizmo adjust
|
||||
|
||||
Reference in new issue
Block a user