diff --git a/docs/HLSD/keyboard-shortcuts.md b/docs/HLSD/keyboard-shortcuts.md index cf48a13c8d..18b8cf8578 100644 --- a/docs/HLSD/keyboard-shortcuts.md +++ b/docs/HLSD/keyboard-shortcuts.md @@ -56,9 +56,34 @@ combo boxes), so it opens the dial from the canvases and the tab strip only. `MainFrame::handle_global_shortcut` skips a chord that `KeyChord::edits_text()` reports while a text field has the focus (a wx text entry, spin control, web view or ImGui InputText), and skips every chord while an ImGui modal is open, as a wx modal dialog -would. `ImGuiWrapper::owns_key()` reads the active InputText and the popup stack -directly, since `WantCaptureKeyboard` lags a frame, and is called only when the focus is on -a visible canvas from `OpenGLManager::create_wxglcanvas()`. +would. `ImGuiWrapper::owns_key()` reads the text input request and the popup stack of the +last drawn frame, since `WantCaptureKeyboard` and `WantTextInput` only catch up when the +next frame starts, and is called only when the focus is on a visible canvas from +`OpenGLManager::create_wxglcanvas()`. + +The `Plater`, `Preview` and `Painting` shortcuts act on the 3D view, so they run only while +the 3D view has the keyboard. `GLCanvas3D` feeds every key event to ImGui and asks +`ImGuiWrapper::claim_key_event()` whether to act on it as well. While an ImGui popup (a +dropdown, a menu or a modal) is open or an ImGui InputText is active, ImGui claims every key, +as a focused sidebar text field or an open native dropdown keeps every key from the canvas. +Esc then closes the topmost dropdown or menu, since this ImGui closes popups on Esc only +through keyboard navigation, which is off; a modal handles Esc itself. A second Esc reaches +the canvas once nothing claims it. A slider or button held with the mouse also claims every +key until it is released, since a shortcut that switches the view or closes the tool would +leave the drag behind. One side handles a key from its key-down to its release. Its +repeats, its char event and its release follow the key-down's decision even when a field or +modal opens or closes in between, so a key never both runs a shortcut and types, and a +keyboard move of the selection always sees the release of the key that started it. + +Key-ups go to whatever window has the focus, so a shortcut that opens a dialog, such as +Ctrl+P, takes the release of its modifier with it. When the canvas loses the focus it sends +itself a key-up for each Shift, Ctrl or Alt still held, which ends a gizmo's Shift mode and +clears ImGui's own copy of the modifier, and then drops its record of held keys. +`ImGuiWrapper::update_mouse_data()` also takes ImGui's modifiers from each mouse event, which +carries the real state, since a stale Ctrl would turn every slider click into a Ctrl+click +and open the slider's text box. The macOS +Edit menu, whose key equivalents run before the canvas sees the key, follows the same rule +as the canvas. ## Which event a chord matches diff --git a/src/libslic3r/GCode.cpp b/src/libslic3r/GCode.cpp index 91f8535dfd..18cfe2488e 100644 --- a/src/libslic3r/GCode.cpp +++ b/src/libslic3r/GCode.cpp @@ -9900,7 +9900,7 @@ std::string GCode::_extrude(const ExtrusionPath &path, const std::string &path_d } // BBS: use G1 if not enable arc fitting or has no arc fitting result or in spiral_mode mode or we are doing sloped extrusion // Attention: G2 and G3 is not supported in spiral_mode mode - if (!m_config.enable_arc_fitting || path.polyline.fitting_result.empty() || m_config.spiral_mode || sloped != nullptr || path.z_contoured || this->should_disable_arc_fitting()) { + if (m_config.enable_arc_fitting.value == ArcFittingMode::Disabled || path.polyline.fitting_result.empty() || m_config.spiral_mode || sloped != nullptr || path.z_contoured || this->should_disable_arc_fitting()) { double path_length = 0.; double total_length = sloped == nullptr ? 0. : path.polyline.length() * SCALING_FACTOR; double saved_z = m_writer.get_position().z(); diff --git a/src/libslic3r/GCode/WipeTower.cpp b/src/libslic3r/GCode/WipeTower.cpp index b72e924da4..0e57c41804 100644 --- a/src/libslic3r/GCode/WipeTower.cpp +++ b/src/libslic3r/GCode/WipeTower.cpp @@ -2003,7 +2003,7 @@ WipeTower::WipeTower(const PrintConfig& config, int plate_idx, Vec3d plate_origi m_flat_ironing(config.prime_tower_flat_ironing.value), m_enable_tower_interface_features(config.enable_tower_interface_features.value), m_physical_extruder_map(config.physical_extruder_map.values), - m_enable_arc_fitting(config.enable_arc_fitting.value) + m_enable_arc_fitting(config.enable_arc_fitting.value == ArcFittingMode::Enabled) // Orca: has_filament_switcher is a device-set dynamic key, not a PrintConfig member; // it is pushed in from Print via set_has_filament_switcher() instead of read here. { diff --git a/src/libslic3r/GCode/WipeTower2.cpp b/src/libslic3r/GCode/WipeTower2.cpp index 21556e65ba..83729a72a1 100644 --- a/src/libslic3r/GCode/WipeTower2.cpp +++ b/src/libslic3r/GCode/WipeTower2.cpp @@ -1062,7 +1062,7 @@ WipeTower2::WipeTower2(const PrintConfig& config, const PrintRegionConfig& defau m_perimeter_speed(default_region_config.inner_wall_speed.get_at(get_extruder_index(config, (unsigned int)initial_tool))), m_current_tool(initial_tool), wipe_volumes(wiping_matrix), m_wipe_tower_max_purge_speed(float(config.wipe_tower_max_purge_speed)), - m_enable_arc_fitting(config.enable_arc_fitting), + m_enable_arc_fitting(config.enable_arc_fitting.value == ArcFittingMode::Enabled), m_used_fillet(config.wipe_tower_fillet_wall), m_rib_width(config.wipe_tower_rib_width), m_extra_rib_length(config.wipe_tower_extra_rib_length), diff --git a/src/libslic3r/GCodeWriter.cpp b/src/libslic3r/GCodeWriter.cpp index 617fc2ce54..4eed23d7d8 100644 --- a/src/libslic3r/GCodeWriter.cpp +++ b/src/libslic3r/GCodeWriter.cpp @@ -1215,7 +1215,7 @@ std::string GCodeWriter::_spiral_travel_to_z(double z, const Vec2d &ij_offset, c : this->config.travel_speed.get_at(m_cached_extruder_idx); } - if (!this->config.enable_arc_fitting) { // Orca: if arc fitting is disabled, approximate the arc with small linear segments + if (this->config.enable_arc_fitting.value == ArcFittingMode::Disabled) { // Orca: if arc fitting is disabled, approximate the arc with small linear segments const double z_start = m_pos(2); // starting Z height const double px = m_pos(0) - m_x_offset; // take plate offset into consideration diff --git a/src/libslic3r/Layer.cpp b/src/libslic3r/Layer.cpp index 8e58a5e671..849b57e4b3 100644 --- a/src/libslic3r/Layer.cpp +++ b/src/libslic3r/Layer.cpp @@ -380,7 +380,7 @@ void Layer::simplify_support_path(ExtrusionPath * path) { const auto &print_config = this->object()->print()->config(); const bool spiral_mode = print_config.spiral_mode; - const bool enable_arc_fitting = print_config.enable_arc_fitting; + const bool enable_arc_fitting = print_config.enable_arc_fitting.value == ArcFittingMode::Enabled; const auto scaled_resolution = scaled(print_config.resolution.value); if (enable_arc_fitting && @@ -395,7 +395,7 @@ void Layer::simplify_support_multi_path(ExtrusionMultiPath* multipath) { const auto &print_config = this->object()->print()->config(); const bool spiral_mode = print_config.spiral_mode; - const bool enable_arc_fitting = print_config.enable_arc_fitting; + const bool enable_arc_fitting = print_config.enable_arc_fitting.value == ArcFittingMode::Enabled; const auto scaled_resolution = scaled(print_config.resolution.value); for (size_t i = 0; i < multipath->paths.size(); ++i) { @@ -412,7 +412,7 @@ void Layer::simplify_support_loop(ExtrusionLoop* loop) { const auto &print_config = this->object()->print()->config(); const bool spiral_mode = print_config.spiral_mode; - const bool enable_arc_fitting = print_config.enable_arc_fitting; + const bool enable_arc_fitting = print_config.enable_arc_fitting.value == ArcFittingMode::Enabled; const auto scaled_resolution = scaled(print_config.resolution.value); for (size_t i = 0; i < loop->paths.size(); ++i) { diff --git a/src/libslic3r/LayerRegion.cpp b/src/libslic3r/LayerRegion.cpp index eef3f90c87..74ef2b7494 100644 --- a/src/libslic3r/LayerRegion.cpp +++ b/src/libslic3r/LayerRegion.cpp @@ -1101,16 +1101,13 @@ void LayerRegion::simplify_entity_collection(ExtrusionEntityCollection* entity_c void LayerRegion::simplify_path(ExtrusionPath* path) { const auto &print_config = this->layer()->object()->print()->config(); - const bool spiral_mode = print_config.spiral_mode; - const bool enable_arc_fitting = print_config.enable_arc_fitting; + const ArcFittingMode arc_fitting = print_config.enable_arc_fitting.value; + const bool is_sparse_infill = path->role() == erInternalInfill; const auto scaled_resolution = scaled(print_config.resolution.value); - if (enable_arc_fitting && - !spiral_mode) { - if (path->role() == erInternalInfill) - path->simplify_by_fitting_arc(SCALED_SPARSE_INFILL_RESOLUTION); - else - path->simplify_by_fitting_arc(scaled_resolution); + if (!print_config.spiral_mode && + (arc_fitting == ArcFittingMode::Enabled || (arc_fitting == ArcFittingMode::SparseInfill && is_sparse_infill))) { + path->simplify_by_fitting_arc(is_sparse_infill ? SCALED_SPARSE_INFILL_RESOLUTION : scaled_resolution); } else { path->simplify(scaled_resolution); } @@ -1118,42 +1115,14 @@ void LayerRegion::simplify_path(ExtrusionPath* path) void LayerRegion::simplify_multi_path(ExtrusionMultiPath* multipath) { - const auto &print_config = this->layer()->object()->print()->config(); - const bool spiral_mode = print_config.spiral_mode; - const bool enable_arc_fitting = print_config.enable_arc_fitting; - const auto scaled_resolution = scaled(print_config.resolution.value); - - for (size_t i = 0; i < multipath->paths.size(); ++i) { - if (enable_arc_fitting && - !spiral_mode) { - if (multipath->paths[i].role() == erInternalInfill) - multipath->paths[i].simplify_by_fitting_arc(SCALED_SPARSE_INFILL_RESOLUTION); - else - multipath->paths[i].simplify_by_fitting_arc(scaled_resolution); - } else { - multipath->paths[i].simplify(scaled_resolution); - } - } + for (ExtrusionPath &path : multipath->paths) + this->simplify_path(&path); } void LayerRegion::simplify_loop(ExtrusionLoop* loop) { - const auto &print_config = this->layer()->object()->print()->config(); - const bool spiral_mode = print_config.spiral_mode; - const bool enable_arc_fitting = print_config.enable_arc_fitting; - const auto scaled_resolution = scaled(print_config.resolution.value); - - for (size_t i = 0; i < loop->paths.size(); ++i) { - if (enable_arc_fitting && - !spiral_mode) { - if (loop->paths[i].role() == erInternalInfill) - loop->paths[i].simplify_by_fitting_arc(SCALED_SPARSE_INFILL_RESOLUTION); - else - loop->paths[i].simplify_by_fitting_arc(scaled_resolution); - } else { - loop->paths[i].simplify(scaled_resolution); - } - } + for (ExtrusionPath &path : loop->paths) + this->simplify_path(&path); } } diff --git a/src/libslic3r/MultiMaterialSegmentation.cpp b/src/libslic3r/MultiMaterialSegmentation.cpp index 507d997f1d..4c32c7380a 100644 --- a/src/libslic3r/MultiMaterialSegmentation.cpp +++ b/src/libslic3r/MultiMaterialSegmentation.cpp @@ -1928,6 +1928,7 @@ static void remove_multiple_edges_in_vertices(MMU_Graph &graph, const std::vecto } +namespace { // Finds the islands (layer ExPolygons) a region piece overlaps. A top or bottom region is projected from the neighbouring // layers and may reach past the island it belongs to, or over several islands. class IslandLocator @@ -1987,6 +1988,7 @@ private: coord_t m_cell_w = 1, m_cell_h = 1; std::vector> m_grid; }; +} // namespace static std::vector> merge_segmented_layers(const std::vector &input_expolygons, const std::vector> &segmented_regions, diff --git a/src/libslic3r/PerimeterGenerator.cpp b/src/libslic3r/PerimeterGenerator.cpp index 219b6b2551..42963a4575 100644 --- a/src/libslic3r/PerimeterGenerator.cpp +++ b/src/libslic3r/PerimeterGenerator.cpp @@ -1527,7 +1527,7 @@ void PerimeterGenerator::process_classic() process_no_bridge(all_surfaces, perimeter_spacing, ext_perimeter_width); // BBS: don't simplify too much which influence arc fitting when export gcode if arc_fitting is enabled - double surface_simplify_resolution = (print_config->enable_arc_fitting && !this->has_fuzzy_skin) ? 0.2 * m_scaled_resolution : m_scaled_resolution; + double surface_simplify_resolution = (print_config->enable_arc_fitting.value == ArcFittingMode::Enabled && !this->has_fuzzy_skin) ? 0.2 * m_scaled_resolution : m_scaled_resolution; //BBS: reorder the surface to reduce the travel time ExPolygons surface_exp; for (const Surface &surface : all_surfaces) @@ -2577,7 +2577,7 @@ void PerimeterGenerator::process_arachne() process_no_bridge(all_surfaces, perimeter_spacing, ext_perimeter_width); // BBS: don't simplify too much which influence arc fitting when export gcode if arc_fitting is enabled - double surface_simplify_resolution = (print_config->enable_arc_fitting && !this->has_fuzzy_skin) ? 0.2 * m_scaled_resolution : m_scaled_resolution; + double surface_simplify_resolution = (print_config->enable_arc_fitting.value == ArcFittingMode::Enabled && !this->has_fuzzy_skin) ? 0.2 * m_scaled_resolution : m_scaled_resolution; // ORCA: neither one-wall option has a surface to act on without the shell behind it, see // has_top_shell_layers() / has_bottom_shell_layers(). Gated here so every use below - including the // topmost and first layers - sees the same answer. diff --git a/src/libslic3r/PrintConfig.cpp b/src/libslic3r/PrintConfig.cpp index 8e1b2b028e..164bdece3b 100644 --- a/src/libslic3r/PrintConfig.cpp +++ b/src/libslic3r/PrintConfig.cpp @@ -252,6 +252,14 @@ static t_config_enum_values s_keys_map_PowerLossRecoveryMode { }; CONFIG_OPTION_ENUM_DEFINE_STATIC_MAPS(PowerLossRecoveryMode) +// Orca +static t_config_enum_values s_keys_map_ArcFittingMode { + { "disabled", int(ArcFittingMode::Disabled) }, + { "enabled", int(ArcFittingMode::Enabled) }, + { "sparse_infill", int(ArcFittingMode::SparseInfill) } +}; +CONFIG_OPTION_ENUM_DEFINE_STATIC_MAPS(ArcFittingMode) + static t_config_enum_values s_keys_map_CenterOfSurfacePattern{ {"each_surface", int(CenterOfSurfacePattern::Each_Surface)}, {"each_model", int(CenterOfSurfacePattern::Each_Model)}, @@ -4401,16 +4409,25 @@ void PrintConfigDef::init_fff_params() def->set_default_value(new ConfigOptionBool(0)); // BBS - def = this->add("enable_arc_fitting", coBool); + def = this->add("enable_arc_fitting", coEnum); def->label = L("Arc fitting"); - def->tooltip = L("Enable this to get a G-code file which has G2 and G3 moves. " - "The fitting tolerance is same as the resolution.\n\n" - "Note: For Klipper machines, this option is recommended to be disabled. Klipper does not benefit from " - "arc commands as these are split again into line segments by the firmware. This results in a reduction " - "in surface quality as line segments are converted to arcs by the slicer and then back to line segments " - "by the firmware."); + def->tooltip = L("Fit G2 and G3 arc moves to the toolpaths. Walls and surfaces are fitted within the resolution, while " + "sparse infill, supports and the wipe tower use fixed tolerances.\n" + " - Disabled: only straight G1 moves are used.\n" + " - Enabled: arcs are fitted to all toolpaths.\n" + " - Sparse infill only: arcs are fitted to the sparse infill only, which shortens the G-code of " + "curved infill patterns without affecting the walls and surfaces.\n\n" + "Note: For Klipper machines, Disabled is recommended. Klipper splits arcs back into line segments, " + "which lowers the surface quality and can increase the print time."); + def->enum_keys_map = &ConfigOptionEnum::get_enum_values(); + def->enum_values.push_back("disabled"); + def->enum_values.push_back("enabled"); + def->enum_values.push_back("sparse_infill"); + def->enum_labels.push_back(L("Disabled")); + def->enum_labels.push_back(L("Enabled")); + def->enum_labels.push_back(L("Sparse infill only")); def->mode = comAdvanced; - def->set_default_value(new ConfigOptionBool(0)); + def->set_default_value(new ConfigOptionEnum(ArcFittingMode::Disabled)); // BBS def = this->add("gcode_add_line_number", coBool); def->label = L("Add line number"); @@ -9833,6 +9850,13 @@ void PrintConfigDef::handle_legacy(t_config_option_key &opt_key, std::string &va value = "disable"; } } + else if (opt_key == "enable_arc_fitting") { + if (value == "1" || boost::iequals(value, "true")) { + value = "enabled"; + } else if (value == "0" || boost::iequals(value, "false")) { + value = "disabled"; + } + } else if(opt_key == "ensure_vertical_shell_thickness") { if(value == "1") { value = "ensure_all"; diff --git a/src/libslic3r/PrintConfig.hpp b/src/libslic3r/PrintConfig.hpp index 0ebeabb3eb..e712c4565f 100644 --- a/src/libslic3r/PrintConfig.hpp +++ b/src/libslic3r/PrintConfig.hpp @@ -234,6 +234,13 @@ enum class PowerLossRecoveryMode { Disable, }; +// Orca +enum class ArcFittingMode { + Disabled, + Enabled, + SparseInfill, +}; + // BBS enum class WallSequence { InnerOuter, @@ -823,6 +830,7 @@ CONFIG_OPTION_ENUM_DECLARE_STATIC_MAPS(WipeTowerWallType) CONFIG_OPTION_ENUM_DECLARE_STATIC_MAPS(PerimeterGeneratorType) CONFIG_OPTION_ENUM_DECLARE_STATIC_MAPS(ToolChangeOrderingType) CONFIG_OPTION_ENUM_DECLARE_STATIC_MAPS(PowerLossRecoveryMode) +CONFIG_OPTION_ENUM_DECLARE_STATIC_MAPS(ArcFittingMode) CONFIG_OPTION_ENUM_DECLARE_STATIC_MAPS(SurfaceFillOrder) CONFIG_OPTION_ENUM_DECLARE_STATIC_MAPS(AdaptiveInfillMode) CONFIG_OPTION_ENUM_DECLARE_STATIC_MAPS(AdaptiveInfillGradient) @@ -1693,7 +1701,7 @@ PRINT_CONFIG_CLASS_DEFINE( ((ConfigOptionString, printing_by_object_gcode)) ((ConfigOptionFloats, deretraction_speed)) //BBS - ((ConfigOptionBool, enable_arc_fitting)) + ((ConfigOptionEnum, enable_arc_fitting)) ((ConfigOptionString, machine_end_gcode)) ((ConfigOptionStrings, filament_end_gcode)) ((ConfigOptionFloatsNullable, filament_flow_ratio)) diff --git a/src/slic3r/GUI/CAD/SketchInlineEditor.hpp b/src/slic3r/GUI/CAD/SketchInlineEditor.hpp index 677e74b3a0..1721066cd8 100644 --- a/src/slic3r/GUI/CAD/SketchInlineEditor.hpp +++ b/src/slic3r/GUI/CAD/SketchInlineEditor.hpp @@ -68,8 +68,8 @@ public: // (nothing further) <- the canvas has nothing to redraw, so it stops // // This canvas repaints ON DEMAND. ImGui decides whether it wants the keyboard at the END of a - // frame, from the active item, and GLCanvas3D::on_char only calls render() when - // update_key_data() says ImGui wants it. No frames -> WantTextInput never turns on -> no + // frame, from the active item, and GLCanvas3D::on_char only calls render() when ImGui + // wants or claims the key. No frames -> WantTextInput never turns on -> no // render on a keystroke -> still no frames. The characters sit in ImGui's queue and the field // looks exactly as deaf as the window it replaced. One repaint per frame while it is open // breaks the circle. diff --git a/src/slic3r/GUI/ConfigManipulation.cpp b/src/slic3r/GUI/ConfigManipulation.cpp index 6e393b0b9c..5f0998e7fd 100644 --- a/src/slic3r/GUI/ConfigManipulation.cpp +++ b/src/slic3r/GUI/ConfigManipulation.cpp @@ -808,7 +808,7 @@ void ConfigManipulation::toggle_print_fff_options(DynamicPrintConfig *config, in toggle_field("enable_arc_fitting", !have_volumetric_extrusion_rate_slope && !is_belt_printer, -1, _L("Arc fitting is unavailable for belt printers and when extrusion rate smoothing is enabled.")); toggle_line("max_volumetric_extrusion_rate_slope_segment_length", have_volumetric_extrusion_rate_slope, -1, extrusion_smoothing_reason); toggle_line("extrusion_rate_smoothing_external_perimeter_only", have_volumetric_extrusion_rate_slope, -1, extrusion_smoothing_reason); - if(have_volumetric_extrusion_rate_slope) config->set_key_value("enable_arc_fitting", new ConfigOptionBool(false)); + if(have_volumetric_extrusion_rate_slope) config->set_key_value("enable_arc_fitting", new ConfigOptionEnum(ArcFittingMode::Disabled)); if(have_volumetric_extrusion_rate_slope_segment_length < 0.5) { DynamicPrintConfig new_conf = *config; new_conf.set_key_value("max_volumetric_extrusion_rate_slope_segment_length", new ConfigOptionFloat(1)); diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index 12e05605fc..2f72a8e976 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -3899,6 +3899,8 @@ void GLCanvas3D::bind_event_handlers() // The key-up that would commit a keyboard edit goes to whatever took the focus. if (m_selection_edit.kind != SelectionEdit::None) finish_selection_edit(); + release_held_modifiers(); + wxGetApp().imgui()->forget_key_claims(); ImGui::SetWindowFocus(nullptr); render(); evt.Skip(); @@ -4032,11 +4034,12 @@ void GLCanvas3D::on_char(wxKeyEvent& evt) // see include/wx/defs.h enum wxKeyCode int keyCode = evt.GetKeyCode(); - auto imgui = wxGetApp().imgui(); - if (imgui->update_key_data(evt)) { + auto imgui = wxGetApp().imgui(); + const bool imgui_claimed = imgui->claim_key_event(evt); + if (imgui->update_key_data(evt) || imgui_claimed) render(); + if (imgui_claimed) return; - } // Design tab: Delete, Esc, Ctrl+Z/Y and F are NOT handled here. DesignPanel's CHAR_HOOK owns // them (one route per key, whatever holds focus) and only lets a key through to this canvas @@ -4327,20 +4330,35 @@ static bool key_repeats(int key) static void key_released(int key) { s_keys_down.erase(key); } +void GLCanvas3D::release_held_modifiers() +{ + for (const int key : { WXK_SHIFT, WXK_CONTROL, WXK_ALT }) { + if (s_keys_down.count(key) == 0) + continue; + wxKeyEvent release(wxEVT_KEY_UP); + release.m_keyCode = key; + on_key(release); + } +} + void GLCanvas3D::on_key(wxKeyEvent& evt) { - const int keyCode = evt.GetKeyCode(); + auto imgui = wxGetApp().imgui(); + const int keyCode = evt.GetKeyCode(); + const bool imgui_claimed = imgui->claim_key_event(evt); if (evt.GetEventType() == wxEVT_KEY_DOWN) m_key_down = { keyCode, key_repeats(keyCode) }; else if (evt.GetEventType() == wxEVT_KEY_UP) key_released(keyCode); const bool alt_wheel_released = evt.GetEventType() == wxEVT_KEY_UP && keyCode == WXK_ALT && std::exchange(m_alt_wheel_used, false); - auto imgui = wxGetApp().imgui(); - if (imgui->update_key_data(evt)) + // ImGui closes a popup on Esc only through keyboard navigation, which is off. + if (imgui_claimed && evt.GetEventType() == wxEVT_KEY_DOWN && keyCode == WXK_ESCAPE) + imgui->close_top_popup(); + if (imgui->update_key_data(evt) || imgui_claimed) render(); - else + if (!imgui_claimed) { // Before the gizmos and the selection, which Esc also closes. if (evt.GetEventType() == wxEVT_KEY_DOWN && keyCode == WXK_ESCAPE && std::exchange(m_section_view->panel_open, false)) { diff --git a/src/slic3r/GUI/GLCanvas3D.hpp b/src/slic3r/GUI/GLCanvas3D.hpp index 5acbba39a1..ce537643bd 100644 --- a/src/slic3r/GUI/GLCanvas3D.hpp +++ b/src/slic3r/GUI/GLCanvas3D.hpp @@ -1275,6 +1275,8 @@ public: void on_idle(wxIdleEvent& evt); void on_char(wxKeyEvent& evt); void on_key(wxKeyEvent& evt); + // Sends a key-up for each modifier still held, whose own key-up is sent to the window that takes the focus. + void release_held_modifiers(); // Runs the Plater/Preview shortcut bound to chord, swallowing auto-repeats of one-shot // shortcuts; false when nothing is bound. bool handle_shortcut(const KeyChord& chord); diff --git a/src/slic3r/GUI/ImGuiWrapper.cpp b/src/slic3r/GUI/ImGuiWrapper.cpp index 080e85ad4e..b37b99f783 100644 --- a/src/slic3r/GUI/ImGuiWrapper.cpp +++ b/src/slic3r/GUI/ImGuiWrapper.cpp @@ -2,7 +2,6 @@ #include #include -#include #include #include #include "libslic3r/Technologies.hpp" @@ -506,6 +505,11 @@ bool ImGuiWrapper::update_mouse_data(wxMouseEvent& evt) io.MouseDown[0] = evt.LeftIsDown(); io.MouseDown[1] = evt.RightIsDown(); io.MouseDown[2] = evt.MiddleIsDown(); + // Replaces a modifier left held when its key-up was sent to another window. + io.KeyCtrl = evt.ControlDown(); + io.KeyShift = evt.ShiftDown(); + io.KeyAlt = evt.AltDown(); + io.KeySuper = evt.MetaDown(); // Only a vertical wheel event with a direction is a wheel step. A macOS trackpad reports sideways motion // as separate horizontal events, and its wheel events often carry a rotation of 0: wx truncates the // sub-pixel deltas to whole ones and passes on events with no delta at all. Read as vertical steps, @@ -588,16 +592,6 @@ void ImGuiWrapper::new_frame() // synchronize key states // when the application loses the focus it may happen that the key up event is not processed - // synchronize modifier keys - constexpr std::array, 3> imgui_mod_keys{ - std::make_pair(ImGuiKeyModFlags_Ctrl, WXK_CONTROL), - std::make_pair(ImGuiKeyModFlags_Shift, WXK_SHIFT), - std::make_pair(ImGuiKeyModFlags_Alt, WXK_ALT) }; - for (const std::pair& key : imgui_mod_keys) { - if ((io.KeyMods & key.first) != 0 && !wxGetKeyState(key.second)) - io.KeyMods &= ~key.first; - } - // Not sure if it is neccessary // values from 33 to 126 are reserved for the standard ASCII characters for (size_t i = 33; i <= 126; ++i) { @@ -2137,18 +2131,41 @@ bool ImGuiWrapper::want_any_input() const bool ImGuiWrapper::text_input_active() const { - const ImGuiID id = ImGui::GetActiveID(); - return id != 0 && ImGui::GetInputTextState(id) != nullptr; + // An active InputText requests text input in each frame that draws it, and NewFrame() moves the + // request into io.WantTextInput. + const ImGuiContext& g = *ImGui::GetCurrentContext(); + return g.WithinFrameScope ? g.IO.WantTextInput : g.WantTextInputNextFrame == 1; +} + +// A popup stays on the popup stack while its canvas is hidden, so it counts only if the last finished frame +// drew it, which NewFrame() moves from Active to WasActive. +static bool drawn_last_frame(const ImGuiWindow* popup) +{ + return popup != nullptr && (ImGui::GetCurrentContext()->WithinFrameScope ? popup->WasActive : popup->Active); } bool ImGuiWrapper::modal_popup_open() const { - // A modal stays on the popup stack while its canvas is hidden, so it counts only if the last finished - // frame drew it, which NewFrame() moves from Active to WasActive. - const ImGuiWindow* modal = ImGui::GetTopMostPopupModal(); - if (modal == nullptr) - return false; - return ImGui::GetCurrentContext()->WithinFrameScope ? modal->WasActive : modal->Active; + return drawn_last_frame(ImGui::GetTopMostPopupModal()); +} + +bool ImGuiWrapper::popup_open() const +{ + const ImVector& stack = ImGui::GetCurrentContext()->OpenPopupStack; + return std::any_of(stack.begin(), stack.end(), [](const ImGuiPopupData& popup) { return drawn_last_frame(popup.Window); }); +} + +void ImGuiWrapper::close_top_popup() +{ + const ImVector& stack = ImGui::GetCurrentContext()->OpenPopupStack; + for (int level = stack.Size - 1; level >= 0; --level) { + const ImGuiWindow* popup = stack[level].Window; + if (!drawn_last_frame(popup)) + continue; + if ((popup->Flags & ImGuiWindowFlags_Modal) == 0) + ImGui::ClosePopupToLevel(level, true); + return; + } } bool ImGuiWrapper::owns_key(const KeyChord& chord) const @@ -2156,6 +2173,39 @@ bool ImGuiWrapper::owns_key(const KeyChord& chord) const return modal_popup_open() || (chord.edits_text() && text_input_active()); } +bool ImGuiWrapper::item_held() const +{ + return ImGui::GetIO().MouseDown[0] && ImGui::GetActiveID() != 0; +} + +bool ImGuiWrapper::owns_keyboard() const +{ + return popup_open() || item_held() || text_input_active(); +} + +bool ImGuiWrapper::claim_key_event(const wxKeyEvent& evt) +{ + const bool claimed = owns_keyboard(); + const int key = evt.GetKeyCode(); + if (evt.GetEventType() == wxEVT_KEY_DOWN) { + m_char_claim = m_key_claims.try_emplace(key, claimed).first->second; + return *m_char_claim; + } + if (evt.GetEventType() == wxEVT_KEY_UP) { + m_char_claim.reset(); + if (const auto press = m_key_claims.extract(key)) + return press.mapped(); + return claimed; + } + return std::exchange(m_char_claim, std::nullopt).value_or(claimed); +} + +void ImGuiWrapper::forget_key_claims() +{ + m_key_claims.clear(); + m_char_claim.reset(); +} + ImFontAtlasCustomRect* ImGuiWrapper::GetTextureCustomRect(const wchar_t& tex_id) { auto item = m_custom_glyph_rects_ids.find(tex_id); diff --git a/src/slic3r/GUI/ImGuiWrapper.hpp b/src/slic3r/GUI/ImGuiWrapper.hpp index 6b5487bb5f..e4b8dabd77 100644 --- a/src/slic3r/GUI/ImGuiWrapper.hpp +++ b/src/slic3r/GUI/ImGuiWrapper.hpp @@ -73,6 +73,10 @@ class ImGuiWrapper #endif // ENABLE_ENHANCED_IMGUI_SLIDER_FLOAT std::map m_custom_glyph_rects_ids; std::string m_clipboard_text; + // Keys held down, each with whether ImGui claimed its press. + std::map m_key_claims; + // Whether ImGui claimed the last key-down, for the char event that follows it. + std::optional m_char_claim; public: struct LastSliderStatus { @@ -224,8 +228,21 @@ public: bool text_input_active() const; // True while an ImGui modal popup is on screen. bool modal_popup_open() const; + // True while any ImGui popup is on screen, modal or not. + bool popup_open() const; + // Closes the topmost popup on screen unless it is a modal, which handles Esc itself. + void close_top_popup(); // True for every key while a modal is open, and for text-editing keys while an InputText is active. bool owns_key(const KeyChord& chord) const; + // True while the left mouse button holds an ImGui item, such as a slider being dragged. + bool item_held() const; + // True while a popup is open, an item is held or an InputText is active. + bool owns_keyboard() const; + // Returns owns_keyboard() as of the key's key-down, so its repeats, char event and release get the + // same answer. Call it once per event. + bool claim_key_event(const wxKeyEvent& evt); + // Drops the record of held keys, whose key-ups are sent to the window that takes the focus. + void forget_key_claims(); // Optional inputs are used for set up value inside of an optional, with default value // diff --git a/src/slic3r/GUI/MainFrame.cpp b/src/slic3r/GUI/MainFrame.cpp index e729e33ad7..f9baeb2a12 100644 --- a/src/slic3r/GUI/MainFrame.cpp +++ b/src/slic3r/GUI/MainFrame.cpp @@ -3136,12 +3136,15 @@ void MainFrame::init_menubar_as_editor() { editMenu = new wxMenu(); + // Feeds the key to ImGui instead when ImGui has the focused canvas's keyboard, since the menu + // handles its key equivalents before the canvas receives the key. auto handle_key_event = [](wxKeyEvent& evt) { - if (wxGetApp().imgui()->update_key_data(evt)) { - wxGetApp().plater()->get_current_canvas3D()->render(); - return true; - } - return false; + const ImGuiWrapper* imgui = focused_canvas_imgui(wxWindow::FindFocus()); + if (imgui == nullptr || !imgui->owns_keyboard()) + return false; + wxGetApp().imgui()->update_key_data(evt); + wxGetApp().plater()->get_current_canvas3D()->render(); + return true; }; #ifndef __APPLE__ // BBS undo diff --git a/src/slic3r/GUI/TextureImportDialog.cpp b/src/slic3r/GUI/TextureImportDialog.cpp index 8e83f0302a..cee0b5fe5b 100644 --- a/src/slic3r/GUI/TextureImportDialog.cpp +++ b/src/slic3r/GUI/TextureImportDialog.cpp @@ -32,6 +32,8 @@ #include "slic3r/GUI/GUI_Utils.hpp" #include "libslic3r/TexturePainting.hpp" #include "slic3r/GUI/Widgets/SpinInput.hpp" +#include +#include #include "libslic3r/TriangleMesh.hpp" #include #include @@ -101,34 +103,6 @@ static wxColour texture_import_separator_colour() return StateColor::darkModeColorFor(wxColour(SEPARATOR_COLOUR_KEY)); } -// Orca's confirm palette, applied here rather than through Button::SetStyle because these buttons -// keep custom pill geometry that SetStyle resets. The Disabled entries are load-bearing: without -// one, StateColor::colorForStates falls through to the Normal entry and a disabled button paints -// as a live accent button. -static void apply_accent_button_colours(Button* btn) -{ - btn->SetBackgroundColor(StateColor( - std::pair(wxColour("#CECECE"), StateColor::Disabled), - std::pair(wxColour(0, 137, 123), StateColor::Pressed), - std::pair(wxColour(38, 166, 154), StateColor::Hovered), - std::pair(wxColour(0, 150, 136), StateColor::Normal))); - btn->SetBorderColor(StateColor( - std::pair(wxColour("#CECECE"), StateColor::Disabled), - std::pair(wxColour(0, 150, 136), StateColor::Normal))); - btn->SetTextColor(StateColor( - std::pair(wxColour("#6B6B6A"), StateColor::Disabled), - std::pair(wxColour("#FFFFFE"), StateColor::Normal))); -} - -// The same button while the parameters behind it are dirty: still clickable, but reading as -// "what you see is not what this button would apply". -static void apply_muted_button_colours(Button* btn) -{ - btn->SetBackgroundColor(wxColour("#CECECE")); - btn->SetBorderColor(wxColour("#CECECE")); - btn->SetTextColor(wxColour("#6B6B6A")); -} - static wxFont texture_import_section_title_font(wxWindow* win) { wxFont font = win ? win->GetFont() : wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT); @@ -327,7 +301,7 @@ void AccentSlider::OnPaint(wxPaintEvent&) int ts = FromDIP(8); int pen_w = FromDIP(2); - wxColour accent_clr = StateColor::darkModeColorFor(IsEnabled() ? wxColour("#009688") : wxColour("#ACACAC")); + wxColour accent_clr = IsEnabled() ? wxColour("#009688") : StateColor::darkModeColorFor(wxColour("#ACACAC")); // use original accent color here to make it more readable wxColour track_clr = StateColor::darkModeColorFor(IsEnabled() ? wxColour("#CECECE") : wxColour("#DFDFDF")); int tx = xFromValue(); @@ -547,6 +521,14 @@ public: wxColour pop_bg = StateColor::darkModeColorFor(*wxWHITE); SetBackgroundColour(pop_bg); + // ORCA add border for popups. it required to add this controls because it covers all background + Bind(wxEVT_PAINT, [this](wxPaintEvent& evt) { + wxPaintDC dc(this); + dc.SetPen(wxPen(StateColor::darkModeColorFor(wxColour("#DBDBDB")), FromDIP(1))); + dc.SetBrush(*wxTRANSPARENT_BRUSH); + dc.DrawRoundedRectangle(0, 0, GetSize().x, GetSize().y, 0); + }); + m_content = new wxScrolledWindow(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxVSCROLL); m_content->SetBackgroundColour(pop_bg); m_content->SetScrollRate(0, FromDIP(20)); @@ -556,7 +538,7 @@ public: const int row_h = FromDIP(32); const int pad = FromDIP(8); const int max_visible_rows = 10; - const wxColour header_clr = StateColor::darkModeColorFor(wxColour("#ACACAC")); + const wxColour header_clr = StateColor::darkModeColorFor(wxColour("#363636")); auto add_section_header = [&](const wxString& label) { auto* hdr = new wxStaticText(m_content, wxID_ANY, label); @@ -567,7 +549,7 @@ public: outer->Add(hdr, 0, wxLEFT | wxRIGHT | wxTOP, pad); auto* line = new StaticLine(m_content); line->SetLineColour(wxColour(SEPARATOR_COLOUR_KEY)); - outer->Add(line, 0, wxEXPAND | wxLEFT | wxRIGHT | wxTOP | wxBOTTOM, pad); + outer->Add(line, 0, wxEXPAND | wxLEFT | wxRIGHT | wxTOP, pad); }; auto add_section = [&](const wxString& label, TextureFilamentKind kind) { @@ -605,7 +587,7 @@ public: add_label->SetFont(af); decompose_label->SetFont(af); const bool add_enabled = !m_can_add_filament || m_can_add_filament(); - const wxColour action_clr = StateColor::darkModeColorFor(wxColour("#009688")); + const wxColour action_clr = wxColour("#009688"); add_label->SetForegroundColour(add_enabled ? action_clr : header_clr); decompose_label->SetForegroundColour(add_enabled ? action_clr : header_clr); add_label->SetCursor(wxCursor(add_enabled ? wxCURSOR_HAND : wxCURSOR_ARROW)); @@ -659,7 +641,7 @@ public: list_h -= ((int)m_colors_rgba.size() - max_visible_rows) * row_h; m_content->SetMinSize(wxSize(pop_w, list_h)); m_content->SetMaxSize(wxSize(pop_w, list_h)); - top_sizer->Add(m_content, 0, wxEXPAND); + top_sizer->Add(m_content, 0, wxEXPAND | wxALL, FromDIP(1)); top_sizer->AddSpacer(FromDIP(4)); auto* sep_line = new StaticLine(this); @@ -714,8 +696,8 @@ private: row->SetBackgroundStyle(wxBG_STYLE_PAINT); row->SetCursor(wxCursor(wxCURSOR_HAND)); - const int sq = row->FromDIP(24); - const int sq_r = row->FromDIP(2); + const int sq = row->FromDIP(20); // ORCA match color swatch sizes + const int sq_r = row->FromDIP(0); const int sq_x = row->FromDIP(4); const int gap1 = row->FromDIP(8); @@ -754,7 +736,7 @@ private: wxFont nf = p->GetFont(); nf.SetPointSize(9); dc.SetFont(nf); - dc.SetTextForeground(paint_clr.GetLuminance() < 0.6 ? *wxWHITE : texture_import_gray9000()); + dc.SetTextForeground(paint_clr.GetLuminance() < 0.51 ? *wxWHITE : *wxBLACK); // ORCA match used foreground color with other swatches wxString ns = wxString::Format("%d", display_number((int)idx)); wxSize tsz = dc.GetTextExtent(ns); dc.DrawText(ns, sq_x + (sq - tsz.x) / 2, sq_y + (sq - tsz.y) / 2); @@ -823,9 +805,9 @@ private: wxFont font = p->GetFont(); font.SetPointSize(9); dc.SetFont(font); - int x = p->FromDIP(2); - const int sw = p->FromDIP(22); - const int sw_r = p->FromDIP(2); + int x = p->FromDIP(6); // ORCA Match left margins + const int sw = p->FromDIP(20); // ORCA Match color swatch sizes + const int sw_r = 0; //p->FromDIP(2); const int y = (sz.y - sw) / 2; for (size_t ci = 0; ci < entry.mixed_components.size() && ci < entry.mixed_ratios.size(); ++ci) { @@ -936,12 +918,20 @@ public: wxColour pop_bg = StateColor::darkModeColorFor(*wxWHITE); SetBackgroundColour(pop_bg); + // ORCA add border for popups. it required to add this controls because it covers all background + Bind(wxEVT_PAINT, [this](wxPaintEvent& evt) { + wxPaintDC dc(this); + dc.SetPen(wxPen(StateColor::darkModeColorFor(wxColour("#DBDBDB")), FromDIP(1))); + dc.SetBrush(*wxTRANSPARENT_BRUSH); + dc.DrawRoundedRectangle(0, 0, GetSize().x, GetSize().y, 0); + }); + auto* content = new wxPanel(this, wxID_ANY); content->SetBackgroundColour(pop_bg); content->SetBackgroundStyle(wxBG_STYLE_PAINT); auto* sizer = new wxBoxSizer(wxVERTICAL); - const int row_h = FromDIP(36); + const int row_h = FromDIP(32); const int pop_w = std::max(FromDIP(216), popup_width); sizer->Add(create_item_row(content, TextureAutoMixMode::CMYW, row_h), 0, wxEXPAND); sizer->Add(create_item_row(content, TextureAutoMixMode::RYBW, row_h), 0, wxEXPAND); @@ -966,7 +956,7 @@ private: wxPanel* create_item_row(wxWindow* parent, TextureAutoMixMode mode, int row_h) { wxColour row_bg = StateColor::darkModeColorFor(*wxWHITE); - wxColour hover_bg = StateColor::darkModeColorFor(wxColour("#F4F4F4")); + wxColour checked_bg = StateColor::darkModeColorFor(wxColour("#BFE1DE")); wxColour text_fg = texture_import_text_colour(); wxColour accent = StateColor::darkModeColorFor(wxColour("#009688")); @@ -977,15 +967,16 @@ private: row->SetCursor(wxCursor(wxCURSOR_HAND)); const int row_idx = mode == TextureAutoMixMode::CMYW ? 0 : 1; - row->Bind(wxEVT_PAINT, [this, row_bg, hover_bg, text_fg, accent, mode, row_idx](wxPaintEvent& e) { + row->Bind(wxEVT_PAINT, [this, row_bg, checked_bg, text_fg, accent, mode, row_idx](wxPaintEvent& e) { auto* p = static_cast(e.GetEventObject()); wxAutoBufferedPaintDC dc(p); wxSize sz = p->GetClientSize(); const bool hovered = (m_hover_idx == row_idx); const bool selected = (m_current_mode == mode); - dc.SetBrush(wxBrush(hovered ? hover_bg : row_bg)); - dc.SetPen(*wxTRANSPARENT_PEN); + // ORCA Match look with combo box dropdown + dc.SetBrush(wxBrush(selected ? checked_bg : row_bg)); + dc.SetPen(hovered ? wxPen(accent) : *wxTRANSPARENT_PEN); dc.DrawRectangle(0, 0, sz.x, sz.y); wxFont font = p->GetFont(); @@ -996,6 +987,7 @@ private: wxSize tsz = dc.GetTextExtent(label); dc.DrawText(label, p->FromDIP(12), (sz.y - tsz.y) / 2); + /* if (selected) { wxFont check_font = p->GetFont(); check_font.SetPointSize(12); @@ -1006,6 +998,7 @@ private: wxSize csz = dc.GetTextExtent(check); dc.DrawText(check, sz.x - p->FromDIP(16) - csz.x, (sz.y - csz.y) / 2); } + */ }); row->Bind(wxEVT_MOTION, [this, row, row_idx](wxMouseEvent& evt) { @@ -1913,7 +1906,7 @@ void TextureImportDialog::build_ui() { const wxColour dialog_bg = StateColor::darkModeColorFor(*wxWHITE); SetBackgroundColour(dialog_bg); - SetForegroundColour(StateColor::darkModeColorFor(wxColour("#323A3D"))); + SetForegroundColour(StateColor::darkModeColorFor(wxColour("#363636"))); wxBoxSizer* root_sizer = new wxBoxSizer(wxVERTICAL); @@ -1993,18 +1986,14 @@ void TextureImportDialog::build_preview_panel(wxWindow* parent, wxSizer* sizer) m_tab_panel->SetBackgroundColour(preview_bg); m_btn_view_original = new Button(m_tab_panel, _L("Original")); + m_btn_view_original->SetStyle(ButtonStyle::Regular, ButtonType::Parameter); m_btn_view_original->SetId(ID_VIEW_ORIGINAL); m_btn_view_multicolor = new Button(m_tab_panel, _L("Multi-Color")); + m_btn_view_multicolor->SetStyle(ButtonStyle::Regular, ButtonType::Parameter); m_btn_view_multicolor->SetId(ID_VIEW_MULTICOLOR); const int view_button_height = FromDIP(27); - m_btn_view_original->SetCornerRadius(view_button_height / 2); - m_btn_view_original->SetMinSize(wxSize(FromDIP(57), view_button_height)); - m_btn_view_original->SetFont(m_btn_view_original->GetFont().Bold()); m_btn_view_original->SetToolTip(_L("Your input texture model")); - m_btn_view_multicolor->SetCornerRadius(view_button_height / 2); - m_btn_view_multicolor->SetMinSize(wxSize(FromDIP(57), view_button_height)); - m_btn_view_multicolor->SetFont(m_btn_view_multicolor->GetFont().Bold()); m_btn_view_multicolor->SetToolTip(_L("Processed multi-color model")); wxBoxSizer* tab_sizer = new wxBoxSizer(wxHORIZONTAL); @@ -2014,7 +2003,6 @@ void TextureImportDialog::build_preview_panel(wxWindow* parent, wxSizer* sizer) m_tab_panel->Fit(); m_btn_view_multicolor->Hide(); - auto preview_original = [this](wxMouseEvent& e) { if (m_preview_canvas) { m_preview_canvas->set_render_mode(TexturePreviewCanvas::RenderMode::Original); @@ -2069,12 +2057,12 @@ void TextureImportDialog::build_preview_panel(wxWindow* parent, wxSizer* sizer) void TextureImportDialog::build_params_panel(wxWindow* parent, wxSizer* sizer) { - wxColour label_fg = StateColor::darkModeColorFor(wxColour("#323A3D")); + wxColour label_fg = StateColor::darkModeColorFor(wxColour("#363636")); wxBoxSizer* color_header_sizer = new wxBoxSizer(wxHORIZONTAL); wxStaticText* lbl_colors = new wxStaticText(parent, wxID_ANY, _L("Color Count")); lbl_colors->SetForegroundColour(label_fg); - lbl_colors->SetFont(lbl_colors->GetFont().Bold()); + lbl_colors->SetFont(Label::Head_14); color_header_sizer->Add(lbl_colors, 0, wxALIGN_CENTER_VERTICAL | wxRIGHT, FromDIP(8)); m_btn_color_4 = new Button(parent, "4"); @@ -2085,33 +2073,11 @@ void TextureImportDialog::build_params_panel(wxWindow* parent, wxSizer* sizer) m_btn_color_16->SetId(ID_COLOR_16); m_btn_color_auto = new Button(parent, _L("Auto")); m_btn_color_auto->SetId(ID_COLOR_AUTO); - - { - StateColor preset_bg( - std::pair(wxColour(0, 137, 123), StateColor::Pressed | StateColor::Checked), - std::pair(wxColour(38, 166, 154), StateColor::Hovered | StateColor::Checked), - std::pair(wxColour(0, 150, 136), StateColor::Checked), - std::pair(wxColour("#CECECE"), StateColor::Pressed), - std::pair(wxColour("#EEEEEE"), StateColor::Hovered), - std::pair(*wxWHITE, StateColor::Normal)); - StateColor preset_bd( - std::pair(wxColour(0, 150, 136), StateColor::Checked), - std::pair(wxColour("#CECECE"), StateColor::Normal)); - StateColor preset_text( - std::pair(wxColour("#FFFFFE"), StateColor::Checked), - std::pair(wxColour("#323A3D"), StateColor::Normal)); - - for (auto* btn : {m_btn_color_4, m_btn_color_8, m_btn_color_16}) { - btn->SetCornerRadius(FromDIP(12)); - btn->SetMinSize(wxSize(FromDIP(28), FromDIP(28))); - btn->SetBackgroundColor(preset_bg); - btn->SetBorderColor(preset_bd); - btn->SetTextColor(preset_text); - } - } + m_btn_color_auto->SetStyle(ButtonStyle::Regular, ButtonType::Window); update_color_count_preset_buttons(); + color_header_sizer->AddStretchSpacer(); color_header_sizer->Add(m_btn_color_4, 0, wxALIGN_CENTER_VERTICAL | wxRIGHT, FromDIP(2)); color_header_sizer->Add(m_btn_color_8, 0, wxALIGN_CENTER_VERTICAL | wxRIGHT, FromDIP(2)); color_header_sizer->Add(m_btn_color_16, 0, wxALIGN_CENTER_VERTICAL); @@ -2134,7 +2100,7 @@ void TextureImportDialog::build_params_panel(wxWindow* parent, wxSizer* sizer) wxStaticText* lbl_smooth = new wxStaticText(parent, wxID_ANY, _L("Smooth Level")); lbl_smooth->SetForegroundColour(label_fg); - lbl_smooth->SetFont(lbl_smooth->GetFont().Bold()); + lbl_smooth->SetFont(Label::Head_14); sizer->Add(lbl_smooth, 0, wxBOTTOM, FromDIP(4)); wxBoxSizer* smooth_sizer = new wxBoxSizer(wxHORIZONTAL); @@ -2154,27 +2120,7 @@ void TextureImportDialog::build_params_panel(wxWindow* parent, wxSizer* sizer) m_btn_apply = new Button(parent, _L("Apply")); m_btn_apply->SetId(ID_BTN_APPLY); - - { - StateColor btn_bg_white( - std::pair(wxColour("#CECECE"), StateColor::Pressed), - std::pair(wxColour("#EEEEEE"), StateColor::Hovered), - std::pair(*wxWHITE, StateColor::Normal)); - const wxColour btn_bd_accent = wxColour(0, 150, 136); - const wxColour btn_text_accent = wxColour(0, 150, 136); - - m_btn_color_auto->SetCornerRadius(FromDIP(12)); - m_btn_color_auto->SetMinSize(wxSize(FromDIP(60), FromDIP(28))); - m_btn_color_auto->SetBackgroundColor(btn_bg_white); - m_btn_color_auto->SetBorderColor(btn_bd_accent); - m_btn_color_auto->SetTextColor(btn_text_accent); - - m_btn_apply->SetCornerRadius(FromDIP(12)); - m_btn_apply->SetMinSize(wxSize(FromDIP(60), FromDIP(28))); - m_btn_apply->SetBackgroundColor(btn_bg_white); - m_btn_apply->SetBorderColor(btn_bd_accent); - m_btn_apply->SetTextColor(btn_text_accent); - } + m_btn_apply->SetStyle(ButtonStyle::Regular, ButtonType::Window); // Defer attaching the Auto/Apply tooltips until the dialog has actually // been shown. On macOS, AppKit creates NSTrackingArea and dispatches a @@ -2198,7 +2144,7 @@ void TextureImportDialog::build_params_panel(wxWindow* parent, wxSizer* sizer) wxBoxSizer* apply_sizer = new wxBoxSizer(wxHORIZONTAL); apply_sizer->Add(m_btn_color_auto, 0, wxRIGHT, FromDIP(4)); apply_sizer->Add(m_btn_apply, 0); - sizer->Add(apply_sizer, 0, wxALIGN_RIGHT | wxBOTTOM, FromDIP(8)); + sizer->Add(apply_sizer, 0, wxALIGN_RIGHT | wxBOTTOM | wxTOP, FromDIP(8)); m_hint_label = new wxStaticText(parent, wxID_ANY, _L("Reminder: parameters changed, click Apply to take effect")); @@ -2214,27 +2160,19 @@ void TextureImportDialog::build_params_panel(wxWindow* parent, wxSizer* sizer) void TextureImportDialog::build_mapping_panel(wxWindow* parent, wxSizer* sizer) { - wxColour secondary_fg = StateColor::darkModeColorFor(wxColour("#6B6B6B")); + wxColour secondary_fg = StateColor::darkModeColorFor(wxColour("#363636")); wxBoxSizer* header_sizer = new wxBoxSizer(wxHORIZONTAL); wxStaticText* lbl_mapping = new wxStaticText(parent, wxID_ANY, _L("Filament Mapping")); lbl_mapping->SetForegroundColour(secondary_fg); - lbl_mapping->SetFont(texture_import_section_title_font(parent)); + lbl_mapping->SetFont(Label::Head_14); m_auto_mix_font_point_size = lbl_mapping->GetFont().GetPointSize(); header_sizer->Add(lbl_mapping, 0, wxALIGN_CENTER_VERTICAL); m_btn_mix_reset = new Button(parent, "", "revert_btn", wxBORDER_NONE, 16); m_btn_mix_reset->SetCanFocus(false); - m_btn_mix_reset->SetPaddingSize(wxSize(FromDIP(2), FromDIP(2))); - { - StateColor reset_bg( - std::pair(wxColour("#F4F4F4"), StateColor::Pressed), - std::pair(wxColour("#F8F8F8"), StateColor::Hovered), - std::pair(*wxWHITE, StateColor::Normal)); - m_btn_mix_reset->SetBackgroundColor(reset_bg); - m_btn_mix_reset->SetBorderColor(StateColor()); - } + m_btn_mix_reset->SetStyle(ButtonStyle::Regular, ButtonType::Icon); m_btn_mix_reset->SetToolTip(_L("Reset filament mapping to the state before one-click mixing")); m_btn_mix_reset->Bind(wxEVT_BUTTON, [this](wxCommandEvent& evt) { reset_auto_mix(); @@ -2245,31 +2183,10 @@ void TextureImportDialog::build_mapping_panel(wxWindow* parent, wxSizer* sizer) header_sizer->AddStretchSpacer(); - m_btn_auto_mix = new Button(parent, auto_mix_mode_label(m_auto_mix_mode)); - { - wxFont btn_font = m_btn_auto_mix->GetFont(); - btn_font.SetPointSize(m_auto_mix_font_point_size); - m_btn_auto_mix->SetFont(btn_font); - } - m_btn_auto_mix->SetCornerRadius(FromDIP(14)); - m_btn_auto_mix->SetMinSize(wxSize(FromDIP(178), FromDIP(28))); - { - StateColor btn_bg( - std::pair(wxColour("#F4F4F4"), StateColor::Pressed), - std::pair(wxColour("#F8F8F8"), StateColor::Hovered), - std::pair(*wxWHITE, StateColor::Normal)); - const wxColour btn_bd = wxColour("#CECECE"); - const wxColour btn_text = texture_import_gray9000(); - m_btn_auto_mix->SetBackgroundColor(btn_bg); - m_btn_auto_mix->SetBorderColor(btn_bd); - m_btn_auto_mix->SetTextColor(btn_text); - } + m_btn_auto_mix = new Button(parent, auto_mix_mode_label(m_auto_mix_mode), "drop_down", 0, 16); + m_btn_auto_mix->SetStyle(ButtonStyle::Regular, ButtonType::Parameter); m_btn_auto_mix->SetToolTip(_L("Choose the one-click auto-mix mode for texture color import")); - m_btn_auto_mix->Bind(wxEVT_ENTER_WINDOW, [this](wxMouseEvent& evt) { - show_auto_mix_popup(); - evt.Skip(); - }); - m_btn_auto_mix->Bind(wxEVT_LEFT_DOWN, [this](wxMouseEvent& evt) { + m_btn_auto_mix->Bind(wxEVT_BUTTON, [this](wxCommandEvent& evt) { // ORCA show popup on click instead show_auto_mix_popup(); evt.Skip(); }); @@ -2279,11 +2196,12 @@ void TextureImportDialog::build_mapping_panel(wxWindow* parent, wxSizer* sizer) wxBoxSizer* merge_sizer = new wxBoxSizer(wxHORIZONTAL); m_auto_merge_cb = new wxCheckBox(parent, wxID_ANY, _L("Auto-merge same filament")); + m_auto_merge_cb->SetFont(Label::Body_14); m_auto_merge_cb->SetToolTip(_L("Automatically merge identical filaments into existing filaments in the project")); m_auto_merge_cb->SetForegroundColour(secondary_fg); m_auto_merge_cb->SetValue(true); m_auto_merge_cb->Bind(wxEVT_CHECKBOX, &TextureImportDialog::on_auto_merge_toggled, this); - merge_sizer->Add(m_auto_merge_cb, 0, wxALIGN_CENTER_VERTICAL); + merge_sizer->Add(m_auto_merge_cb, 0, wxALIGN_CENTER_VERTICAL | wxTOP | wxBOTTOM, FromDIP(5)); sizer->Add(merge_sizer, 0, wxEXPAND | wxBOTTOM, FromDIP(8)); @@ -2316,29 +2234,16 @@ void TextureImportDialog::build_bottom_buttons(wxSizer* sizer) m_btn_skip = new Button(this, _L("Skip Matching")); m_btn_skip->SetId(ID_BTN_SKIP); m_btn_skip->SetToolTip(_L("Skip filament mapping and import as a single-color model")); - m_btn_skip->SetCornerRadius(FromDIP(20)); - m_btn_skip->SetMinSize(wxSize(FromDIP(136), FromDIP(40))); - { - StateColor skip_bg( - std::pair(wxColour("#CECECE"), StateColor::Pressed), - std::pair(wxColour("#EEEEEE"), StateColor::Hovered), - std::pair(*wxWHITE, StateColor::Normal)); - const wxColour skip_bd = wxColour("#CECECE"); - const wxColour skip_text = wxColour("#6B6B6A"); - m_btn_skip->SetBackgroundColor(skip_bg); - m_btn_skip->SetBorderColor(skip_bd); - m_btn_skip->SetTextColor(skip_text); - } + m_btn_skip->SetStyle(ButtonStyle::Regular, ButtonType::Choice); m_btn_ok = new Button(this, _L("Confirm")); m_btn_ok->SetId(wxID_OK); - m_btn_ok->SetCornerRadius(FromDIP(20)); - m_btn_ok->SetMinSize(wxSize(FromDIP(156), FromDIP(40))); - apply_accent_button_colours(m_btn_ok); - + m_btn_ok->SetStyle(ButtonStyle::Confirm, ButtonType::Choice); + m_btn_ok->EnableTooltipEvenDisabled(); + btn_sizer->AddStretchSpacer(); - btn_sizer->Add(m_btn_skip, 0, wxRIGHT, FromDIP(16)); - btn_sizer->Add(m_btn_ok, 0); + btn_sizer->Add(m_btn_ok, 0, wxRIGHT, FromDIP(16)); // Match ordering of choice buttons on whole UI + btn_sizer->Add(m_btn_skip, 0); sizer->Add(btn_sizer, 0, wxEXPAND | wxTOP, FromDIP(8)); } @@ -2675,11 +2580,11 @@ void TextureImportDialog::on_mesh_repair_decision_required(wxCommandEvent&) // with the same type swaps only the palette and leaves the geometry alone. if (auto* yes_btn = dynamic_cast(dlg.FindWindow(wxID_YES))) { yes_btn->SetStyle(ButtonStyle::Regular, ButtonType::Choice); - yes_btn->SetMinSize(wxSize(FromDIP(180), FromDIP(24))); + //yes_btn->SetMinSize(wxSize(FromDIP(180), FromDIP(32))); // Height not matches and will cause issues on longer translations. let dialog manages it } if (auto* no_btn = dynamic_cast(dlg.FindWindow(wxID_NO))) { no_btn->SetStyle(ButtonStyle::Confirm, ButtonType::Choice); - no_btn->SetMinSize(wxSize(FromDIP(160), FromDIP(24))); + //no_btn->SetMinSize(wxSize(FromDIP(160), FromDIP(32))); // Height not matches and will cause issues on longer translations. let dialog manages it } dlg.Layout(); dlg.Fit(); @@ -3739,7 +3644,7 @@ void TextureImportDialog::rebuild_mapping_rows() const wxColour dash_clr = StateColor::darkModeColorFor(wxColour("#ACACAC")); const wxColour hex_fg = texture_import_text_colour(); - const wxColour card_bg = StateColor::darkModeColorFor(wxColour("#E8E8E8")); + const wxColour card_bg = StateColor::darkModeColorFor(wxColour("#FFFFFF")); const wxColour card_bd = StateColor::darkModeColorFor(wxColour("#DBDBDB")); const wxColour name_fg = texture_import_text_colour(); const wxColour chev_clr = StateColor::darkModeColorFor(wxColour("#6B6B6A")); @@ -3766,7 +3671,7 @@ void TextureImportDialog::rebuild_mapping_rows() // --- Source card (dashed border, circle + hex) --- const int src_w = FromDIP(138); const int target_min_w = FromDIP(239); - const int row_h = FromDIP(44); + const int row_h = FromDIP(32); // ORCA compact row height row.source_panel = new wxPanel(row_panel, wxID_ANY, wxDefaultPosition, wxSize(src_w, row_h), wxTAB_TRAVERSAL | wxFULL_REPAINT_ON_RESIZE); row.source_panel->SetMinSize(wxSize(src_w, row_h)); @@ -3785,12 +3690,12 @@ void TextureImportDialog::rebuild_mapping_rows() wxPen dash_pen(dash_clr, 1, wxPENSTYLE_SHORT_DASH); dc.SetPen(dash_pen); dc.SetBrush(wxBrush(p->GetParent()->GetBackgroundColour())); - int r = p->FromDIP(8); + int r = 0; //p->FromDIP(8); dc.DrawRoundedRectangle(0, 0, sz.x, sz.y, r); - // Color circle 24px - int cd = p->FromDIP(24); - int cx = p->FromDIP(10); + // Color circle 20px + int cd = p->FromDIP(20); // ORCA match size of swatches + int cx = p->FromDIP(6); // ORCA match margins int cy = (sz.y - cd) / 2; dc.SetPen(*wxTRANSPARENT_PEN); dc.SetBrush(wxBrush(src_wx_color)); @@ -3874,7 +3779,7 @@ void TextureImportDialog::rebuild_mapping_rows() if (ci >= m_mapping_rows.size()) return; int fil_idx = m_mapping_rows[ci].target_filament_idx; - int r = p->FromDIP(8); + int r = 0; //p->FromDIP(8); dc.SetBrush(wxBrush(card_bg)); dc.SetPen(wxPen(card_bd, 1)); dc.DrawRoundedRectangle(0, 0, sz.x, sz.y, r); @@ -3886,9 +3791,9 @@ void TextureImportDialog::rebuild_mapping_rows() mixed_font.SetPointSize(10); dc.SetFont(mixed_font); - int x = p->FromDIP(10); - const int sw = p->FromDIP(28); - const int sw_r = p->FromDIP(6); + int x = p->FromDIP(6);// ORCA Match left margins + const int sw = p->FromDIP(20); // ORCA match size of swatches + const int sw_r = 0; //p->FromDIP(6); const int sw_y = (sz.y - sw) / 2; for (size_t mi = 0; mi < entry.mixed_components.size() && mi < entry.mixed_ratios.size(); ++mi) { if (mi > 0) { @@ -3916,7 +3821,7 @@ void TextureImportDialog::rebuild_mapping_rows() wxString num_str = wxString::Format("%d", display_number(comp_idx)); wxSize nsz = dc.GetTextExtent(num_str); - dc.SetTextForeground(comp_clr.GetLuminance() < 0.6 ? *wxWHITE : texture_import_gray9000()); + dc.SetTextForeground(comp_clr.GetLuminance() < 0.51 ? *wxWHITE : *wxBLACK); // ORCA match used foreground color with other swatches dc.DrawText(num_str, x + (sw - nsz.x) / 2, sw_y + (sw - nsz.y) / 2); x += sw + p->FromDIP(5); @@ -3940,10 +3845,10 @@ void TextureImportDialog::rebuild_mapping_rows() } // Numbered color square 32x32, rounded 6px - int sq = p->FromDIP(32); - int sq_x = p->FromDIP(6); + int sq = p->FromDIP(20); // ORCA match size of swatches + int sq_x = p->FromDIP(6);// ORCA Match left margins int sq_y = (sz.y - sq) / 2; - int sq_r = p->FromDIP(6); + int sq_r = 0; //p->FromDIP(6); wxColour fil_clr = get_target_wxcolor(fil_idx); dc.SetPen(*wxTRANSPARENT_PEN); dc.SetBrush(wxBrush(fil_clr)); @@ -3954,7 +3859,7 @@ void TextureImportDialog::rebuild_mapping_rows() wxFont num_font = p->GetFont(); num_font.SetPointSize(10); dc.SetFont(num_font); - dc.SetTextForeground(fil_clr.GetLuminance() < 0.6 ? *wxWHITE : texture_import_gray9000()); + dc.SetTextForeground(fil_clr.GetLuminance() < 0.51 ? *wxWHITE : *wxBLACK); // ORCA match used foreground color with other swatches wxString num_str = wxString::Format("%d", display_number(fil_idx)); wxSize nsz = dc.GetTextExtent(num_str); dc.DrawText(num_str, sq_x + (sq - nsz.x) / 2, sq_y + (sq - nsz.y) / 2); @@ -4030,9 +3935,12 @@ std::vector TextureImportDialog::build_matches_from_rows( void TextureImportDialog::update_color_count_preset_buttons() { - if (m_btn_color_4) m_btn_color_4->SetValue(m_param_color_count == 4); - if (m_btn_color_8) m_btn_color_8->SetValue(m_param_color_count == 8); - if (m_btn_color_16) m_btn_color_16->SetValue(m_param_color_count == 16); + auto update = [this](auto* btn, int count) { + if (btn) btn->SetStyle(m_param_color_count == count ? ButtonStyle::Confirm : ButtonStyle::Regular, ButtonType::Window); + }; + update(m_btn_color_4 , 4); + update(m_btn_color_8 , 8); + update(m_btn_color_16, 16); } void TextureImportDialog::set_color_count_value(int value, bool update_spin) @@ -4161,27 +4069,9 @@ void TextureImportDialog::highlight_view_button(int view_index) { Button* btns[] = { m_btn_view_original, m_btn_view_multicolor }; - // The inactive pill lies on m_tab_panel, which is preview_bg (#EEEEEE -> #4C4C55), and has to - // read as raised above that strip in both themes — so its fill steps away from the strip in - // opposite directions. gDarkColors pairs one light tone with one dark tone and cannot express - // an inversion, so the two are picked here the way filament_swatch_border_colour() does. - const bool dark_pill = is_dark(); - StateColor inactive_bg( - std::pair(dark_pill ? wxColour(0x5C, 0x5C, 0x64) : wxColour("#F4F4F4"), StateColor::Pressed), - std::pair(dark_pill ? wxColour(0x66, 0x66, 0x6E) : wxColour("#F8F8F8"), StateColor::Hovered), - std::pair(dark_pill ? wxColour(0x54, 0x54, 0x5B) : *wxWHITE, StateColor::Normal)); - const wxColour inactive_bd = dark_pill ? wxColour(0x54, 0x54, 0x5B) : *wxWHITE; - const wxColour inactive_text = wxColour("#6B6B6A"); - for (int i = 0; i < 2; ++i) { if (!btns[i]) continue; - if (i == view_index) { - apply_accent_button_colours(btns[i]); - } else { - btns[i]->SetBackgroundColor(inactive_bg); - btns[i]->SetBorderColor(inactive_bd); - btns[i]->SetTextColor(inactive_text); - } + btns[i]->SetStyle(i == view_index ? ButtonStyle::Confirm : ButtonStyle::Regular, ButtonType::Parameter); btns[i]->Refresh(); } } @@ -4259,10 +4149,8 @@ void TextureImportDialog::update_confirm_button_state() void TextureImportDialog::style_confirm_button(bool dirty) { if (dirty) { - apply_muted_button_colours(m_btn_ok); m_btn_ok->SetToolTip(_L("Reminder: parameters changed, click Apply to take effect")); } else { - apply_accent_button_colours(m_btn_ok); m_btn_ok->UnsetToolTip(); } if (m_hint_label) @@ -4308,33 +4196,10 @@ void TextureImportDialog::on_dpi_changed(const wxRect&) const int view_button_height = FromDIP(27); for (Button* btn : {m_btn_view_original, m_btn_view_multicolor}) { - if (btn) { - btn->SetCornerRadius(view_button_height / 2); - btn->SetMinSize(wxSize(FromDIP(57), view_button_height)); - } + if (btn) btn->Rescale(); // ORCA Rescale applies all style automatically when combined with SetStyle } - for (Button* btn : {m_btn_color_4, m_btn_color_8, m_btn_color_16}) { - if (btn) { - btn->SetCornerRadius(FromDIP(12)); - btn->SetMinSize(wxSize(FromDIP(28), FromDIP(28))); - } - } - - if (m_btn_color_auto) { - m_btn_color_auto->SetCornerRadius(FromDIP(12)); - m_btn_color_auto->SetMinSize(wxSize(FromDIP(60), FromDIP(28))); - } - if (m_btn_apply) { - m_btn_apply->SetCornerRadius(FromDIP(12)); - m_btn_apply->SetMinSize(wxSize(FromDIP(60), FromDIP(28))); - } - if (m_btn_auto_mix) { - m_btn_auto_mix->SetCornerRadius(FromDIP(14)); - m_btn_auto_mix->SetMinSize(wxSize(FromDIP(178), FromDIP(28))); - } - if (m_btn_mix_reset) - m_btn_mix_reset->SetPaddingSize(wxSize(FromDIP(2), FromDIP(2))); + update_color_count_preset_buttons(); // ORCA Rescale applies all style automatically when combined with SetStyle if (m_color_spin) m_color_spin->SetMinSize(wxSize(FromDIP(60), FromDIP(28))); @@ -4346,14 +4211,13 @@ void TextureImportDialog::on_dpi_changed(const wxRect&) m_mapping_scroll->SetScrollRate(0, FromDIP(20)); } - if (m_btn_skip) { - m_btn_skip->SetCornerRadius(FromDIP(20)); - m_btn_skip->SetMinSize(wxSize(FromDIP(136), FromDIP(40))); - } - if (m_btn_ok) { - m_btn_ok->SetCornerRadius(FromDIP(20)); - m_btn_ok->SetMinSize(wxSize(FromDIP(156), FromDIP(40))); - } + // ORCA Rescale applies all style automatically when combined with SetStyle + if (m_btn_skip) m_btn_skip->Rescale(); + if (m_btn_ok) m_btn_ok->Rescale(); + if (m_btn_color_auto) m_btn_color_auto->Rescale(); + if (m_btn_apply) m_btn_apply->Rescale(); + if (m_btn_auto_mix) m_btn_auto_mix->Rescale(); + if (m_btn_mix_reset) m_btn_mix_reset->Rescale(); // Mapping rows store their panel sizes (source/target/arrow/row height) // as fixed FromDIP min/max sizes, so rebuild them to pick up the new DPI. diff --git a/tests/fff_print/test_cooling.cpp b/tests/fff_print/test_cooling.cpp index 1645d99a75..a1a840c745 100644 --- a/tests/fff_print/test_cooling.cpp +++ b/tests/fff_print/test_cooling.cpp @@ -40,7 +40,7 @@ TEST_CASE("Arc fitting remains active with overhang fan control", "[Cooling][Reg { DynamicPrintConfig config = DynamicPrintConfig::full_print_config(); config.set_deserialize_strict({ - { "enable_arc_fitting", true }, + { "enable_arc_fitting", "enabled" }, { "enable_overhang_bridge_fan", true }, { "enable_overhang_speed", true }, { "initial_layer_print_height", 0.2 }, @@ -99,7 +99,7 @@ TEST_CASE("Overhang fan transitions do not depend on overhang speed", "[Cooling] DynamicPrintConfig config = DynamicPrintConfig::full_print_config(); config.set_deserialize_strict({ { "bridge_speed", 2.0 }, - { "enable_arc_fitting", false }, + { "enable_arc_fitting", "disabled" }, { "enable_overhang_bridge_fan", true }, { "enable_overhang_speed", false }, { "initial_layer_print_height", 0.3 }, diff --git a/tests/fff_print/test_gcode.cpp b/tests/fff_print/test_gcode.cpp index cb707ae3d4..1fbb84d08c 100644 --- a/tests/fff_print/test_gcode.cpp +++ b/tests/fff_print/test_gcode.cpp @@ -16,9 +16,12 @@ #include "libslic3r/TriangleMesh.hpp" #include "libslic3r/Point.hpp" +#include "libslic3r/libslic3r.h" #include #include #include +#include +#include #include #include #include @@ -213,6 +216,40 @@ TEST_CASE("Object label comments number each object and copy with or without exc } } +TEST_CASE("Sparse infill only arc fitting emits arcs in the sparse infill alone", "[GCode]") +{ + const auto arcs_per_type = [](const char *arc_fitting) { + // 360 facets keep the walls and the concentric infill within the resolution of a circle, so both fit arcs. + const std::string gcode = Test::slice({ make_cylinder(25.0, 10.0, 2.0 * PI / 360.0) }, { + { "enable_arc_fitting", arc_fitting }, + { "sparse_infill_pattern", "concentric" }, + { "sparse_infill_density", "20%" }, + { "z_hop", "0" }, + }); + std::map arcs; + std::istringstream input(gcode); + std::string line, type; + while (std::getline(input, line)) { + if (line.rfind(";TYPE:", 0) == 0) + type = line.substr(6); + else if (line.rfind("G2 ", 0) == 0 || line.rfind("G3 ", 0) == 0) + ++arcs[type]; + } + return arcs; + }; + + CHECK(arcs_per_type("enabled").count("Outer wall") == 1); + + const std::map sparse_only = arcs_per_type("sparse_infill"); + CHECK(sparse_only.count("Sparse infill") == 1); + for (const auto &[type, count] : sparse_only) { + INFO(type << ": " << count << " arcs"); + CHECK(type == "Sparse infill"); + } + + CHECK(arcs_per_type("disabled").empty()); +} + TEST_CASE("An exported G-code's settings load back as the settings it was sliced with", "[GCode]") { // Two filaments, so the config block carries the flush matrix already multiplied by flush_multiplier. diff --git a/tests/libslic3r/test_config.cpp b/tests/libslic3r/test_config.cpp index b1add2b3c5..705da9d36a 100644 --- a/tests/libslic3r/test_config.cpp +++ b/tests/libslic3r/test_config.cpp @@ -1507,6 +1507,21 @@ TEST_CASE("min_object_distance yields no floor when an FFF config lacks the opti } } +TEST_CASE("handle_legacy maps the boolean arc fitting values to modes", "[Config]") { + const auto [value, mode] = GENERATE(table({ + { "0", ArcFittingMode::Disabled }, + { "false", ArcFittingMode::Disabled }, + { "1", ArcFittingMode::Enabled }, + { "true", ArcFittingMode::Enabled }, + { "sparse_infill", ArcFittingMode::SparseInfill }, + })); + INFO(value); + ConfigSubstitutionContext ctxt(ForwardCompatibilitySubstitutionRule::Disable); + DynamicPrintConfig config; + config.set_deserialize("enable_arc_fitting", value, ctxt); + CHECK(config.opt_enum("enable_arc_fitting") == mode); +} + TEST_CASE("handle_legacy migrates the adaptive TPMS keys", "[Config]") { ConfigSubstitutionContext ctxt(ForwardCompatibilitySubstitutionRule::Enable); DynamicPrintConfig config; diff --git a/tests/slic3rutils/test_imgui_wrapper.cpp b/tests/slic3rutils/test_imgui_wrapper.cpp index 544a3832f5..bdb6f24966 100644 --- a/tests/slic3rutils/test_imgui_wrapper.cpp +++ b/tests/slic3rutils/test_imgui_wrapper.cpp @@ -75,7 +75,27 @@ struct ImGuiFrames ImGui::End(); } - char text[16] = ""; + void draw_slider() + { + ImGui::Begin("window"); + ImGui::SliderFloat("##slider", &value, 0.f, 1.f); + const ImVec2 min = ImGui::GetItemRectMin(), max = ImGui::GetItemRectMax(); + slider_center = ImVec2((min.x + max.x) / 2, (min.y + max.y) / 2); + ImGui::End(); + } + + // Presses the left button at pos, or releases it, and draws the slider in two frames. + void mouse(const ImVec2& pos, bool down) + { + ImGui::GetIO().MousePos = pos; + ImGui::GetIO().MouseDown[0] = down; + frame([this] { draw_slider(); }); + frame([this] { draw_slider(); }); + } + + char text[16] = ""; + float value = 0.f; + ImVec2 slider_center; }; void draw_modal() @@ -84,6 +104,28 @@ void draw_modal() ImGui::EndPopup(); } +void draw_dropdown(bool open) +{ + ImGui::Begin("window"); + if (open) + ImGui::OpenPopup("dropdown"); + if (ImGui::BeginPopup("dropdown")) { + ImGui::Text("item"); + ImGui::EndPopup(); + } + ImGui::End(); +} + +wxKeyEvent key_event(wxEventType type, int key_code, int modifiers = wxMOD_NONE) +{ + wxKeyEvent evt(type); + evt.m_keyCode = key_code; + evt.SetControlDown(modifiers & wxMOD_CONTROL); + evt.SetShiftDown(modifiers & wxMOD_SHIFT); + evt.SetAltDown(modifiers & wxMOD_ALT); + return evt; +} + } // namespace TEST_CASE("a vertical wheel event steps ImGui's wheel in its own direction", "[ImGuiWrapper]") @@ -103,6 +145,21 @@ TEST_CASE("a wheel event with no rotation or on the horizontal axis does not ste CHECK_THAT(wheel_after(rotation, axis), WithinAbs(0.0, 0.0)); } +TEST_CASE("a mouse event replaces a modifier whose key-up went to another window", "[ImGuiWrapper][Regression]") +{ + ImGuiWrapper imgui; + imgui.set_display_size(800.f, 600.f); + ImGui::GetIO().KeyCtrl = true; + + wxMouseEvent move(wxEVT_MOTION); + imgui.update_mouse_data(move); + CHECK_FALSE(ImGui::GetIO().KeyCtrl); + + move.SetControlDown(true); + imgui.update_mouse_data(move); + CHECK(ImGui::GetIO().KeyCtrl); +} + TEST_CASE("an InputText counts as active only while it holds the keyboard", "[ImGuiWrapper]") { ImGuiFrames f; @@ -161,3 +218,137 @@ TEST_CASE("ImGui owns every key under a modal and text-editing keys in an active }); CHECK(f.imgui.owns_key(save)); } + +TEST_CASE("ImGui owns the whole keyboard under a modal or in an active InputText", "[ImGuiWrapper]") +{ + ImGuiFrames f; + CHECK_FALSE(f.imgui.owns_keyboard()); + + f.frame([&] { f.draw_input(true); }); + f.frame([&] { f.draw_input(false); }); + CHECK(f.imgui.owns_keyboard()); + + f.frame([] {}); + CHECK_FALSE(f.imgui.owns_keyboard()); + f.frame([] { + ImGui::OpenPopup("modal"); + draw_modal(); + }); + CHECK(f.imgui.owns_keyboard()); +} + +TEST_CASE("an open dropdown owns the whole keyboard until it is closed", "[ImGuiWrapper]") +{ + ImGuiFrames f; + f.frame([] { draw_dropdown(true); }); + CHECK(f.imgui.popup_open()); + CHECK(f.imgui.owns_keyboard()); + + f.imgui.close_top_popup(); + f.frame([] { draw_dropdown(false); }); + CHECK_FALSE(f.imgui.popup_open()); + CHECK_FALSE(f.imgui.owns_keyboard()); +} + +TEST_CASE("closing the top popup leaves a modal open", "[ImGuiWrapper]") +{ + ImGuiFrames f; + f.frame([] { + ImGui::OpenPopup("modal"); + draw_modal(); + }); + f.imgui.close_top_popup(); + f.frame([] { draw_modal(); }); + CHECK(f.imgui.modal_popup_open()); +} + +TEST_CASE("a held slider owns the keyboard but not the keys Global shortcuts use", "[ImGuiWrapper]") +{ + ImGuiFrames f; + f.mouse(ImVec2(0, 0), false); + CHECK_FALSE(f.imgui.item_held()); + f.mouse(f.slider_center, true); + CHECK(f.imgui.item_held()); + CHECK(f.imgui.owns_keyboard()); + CHECK_FALSE(f.imgui.owns_key(KeyChord{ 'M' })); + CHECK_FALSE(f.imgui.owns_key(KeyChord{ WXK_LEFT })); + + f.mouse(f.slider_center, false); + CHECK_FALSE(f.imgui.owns_keyboard()); +} + +TEST_CASE("a slider typed into once is not a text field when dragged", "[ImGuiWrapper][Regression]") +{ + ImGuiFrames f; + f.mouse(ImVec2(0, 0), false); + ImGui::GetIO().KeyCtrl = true; // Ctrl+click types a value + f.mouse(f.slider_center, true); + ImGui::GetIO().KeyCtrl = false; + f.mouse(f.slider_center, false); + REQUIRE(f.imgui.text_input_active()); + + f.mouse(ImVec2(0, 0), true); // a click elsewhere closes the field + f.mouse(ImVec2(0, 0), false); + f.mouse(f.slider_center, true); + REQUIRE(ImGui::GetInputTextState(ImGui::GetActiveID()) != nullptr); + CHECK_FALSE(f.imgui.text_input_active()); + CHECK_FALSE(f.imgui.owns_key(KeyChord{ 'M' })); +} + +TEST_CASE("a key's char event gets its key-down's answer", "[ImGuiWrapper]") +{ + ImGuiFrames f; + f.frame([&] { f.draw_input(true); }); + f.frame([&] { f.draw_input(false); }); + CHECK(f.imgui.claim_key_event(key_event(wxEVT_KEY_DOWN, 'A'))); + f.frame([] {}); // the field closes before the char arrives + REQUIRE_FALSE(f.imgui.text_input_active()); + CHECK(f.imgui.claim_key_event(key_event(wxEVT_CHAR, 'a'))); + + CHECK_FALSE(f.imgui.claim_key_event(key_event(wxEVT_KEY_DOWN, 'B'))); + f.frame([&] { f.draw_input(true); }); // the field opens before the char arrives + f.frame([&] { f.draw_input(false); }); + CHECK_FALSE(f.imgui.claim_key_event(key_event(wxEVT_CHAR, 'b'))); + // A char with no key-down before it is decided on its own. + CHECK(f.imgui.claim_key_event(key_event(wxEVT_CHAR, 'c'))); +} + +TEST_CASE("a held key's repeats and release get its press's answer", "[ImGuiWrapper]") +{ + ImGuiFrames f; + CHECK_FALSE(f.imgui.claim_key_event(key_event(wxEVT_KEY_DOWN, WXK_RIGHT))); + f.frame([&] { f.draw_input(true); }); + f.frame([&] { f.draw_input(false); }); + CHECK_FALSE(f.imgui.claim_key_event(key_event(wxEVT_KEY_DOWN, WXK_RIGHT))); + CHECK_FALSE(f.imgui.claim_key_event(key_event(wxEVT_KEY_UP, WXK_RIGHT))); + + CHECK(f.imgui.claim_key_event(key_event(wxEVT_KEY_DOWN, WXK_RIGHT))); + CHECK(f.imgui.claim_key_event(key_event(wxEVT_KEY_UP, WXK_RIGHT))); + // The release also clears the press's answer for a later char with no key-down. + f.frame([] {}); + CHECK_FALSE(f.imgui.claim_key_event(key_event(wxEVT_CHAR, 'a'))); +} + +TEST_CASE("a key pressed again after the canvas lost the focus is decided afresh", "[ImGuiWrapper]") +{ + ImGuiFrames f; + CHECK_FALSE(f.imgui.claim_key_event(key_event(wxEVT_KEY_DOWN, 'M'))); + f.imgui.forget_key_claims(); // the key-up went to the window that took the focus + + f.frame([&] { f.draw_input(true); }); + f.frame([&] { f.draw_input(false); }); + CHECK(f.imgui.claim_key_event(key_event(wxEVT_KEY_DOWN, 'M'))); +} + +TEST_CASE("an active ImGui field claims every key, whether it edits text or not", "[ImGuiWrapper]") +{ + const int key = GENERATE(int('A'), int('D'), int(WXK_SHIFT)); + ImGuiFrames f; + CHECK_FALSE(f.imgui.claim_key_event(key_event(wxEVT_KEY_DOWN, key, wxMOD_CONTROL))); + CHECK_FALSE(f.imgui.claim_key_event(key_event(wxEVT_KEY_UP, key, wxMOD_CONTROL))); + + f.frame([&] { f.draw_input(true); }); + f.frame([&] { f.draw_input(false); }); + CHECK(f.imgui.claim_key_event(key_event(wxEVT_KEY_DOWN, key, wxMOD_CONTROL))); + CHECK(f.imgui.claim_key_event(key_event(wxEVT_KEY_UP, key, wxMOD_CONTROL))); +}