diff --git a/src/libslic3r/Technologies.hpp b/src/libslic3r/Technologies.hpp index c22e504df..3df9da961 100644 --- a/src/libslic3r/Technologies.hpp +++ b/src/libslic3r/Technologies.hpp @@ -34,17 +34,6 @@ #define ENABLE_HACK_CLOSING_ON_OSX_10_9_5 (1 && ENABLE_2_2_0_RC1) -//================== -// 2.2.0.final techs -//================== -#define ENABLE_2_2_0_FINAL 1 - -// Enable tooltips for GLCanvas3D using ImGUI -#define ENABLE_CANVAS_TOOLTIP_USING_IMGUI (1 && ENABLE_2_2_0_FINAL) -// Enable fix for dragging mouse event handling for gizmobar -#define ENABLE_GIZMO_TOOLBAR_DRAGGING_FIX (1 && ENABLE_2_2_0_FINAL) - - //=================== // 2.3.0.alpha1 techs //=================== diff --git a/src/slic3r/GUI/DoubleSlider.cpp b/src/slic3r/GUI/DoubleSlider.cpp index 597b9ad60..a6c9a5c77 100644 --- a/src/slic3r/GUI/DoubleSlider.cpp +++ b/src/slic3r/GUI/DoubleSlider.cpp @@ -838,8 +838,20 @@ void Control::draw_cog_icon(wxDC& dc) get_size(&width, &height); wxCoord x_draw, y_draw; - is_horizontal() ? x_draw = width-2 : x_draw = width - m_cog_icon_dim - 2; - is_horizontal() ? y_draw = height - m_cog_icon_dim - 2 : y_draw = height-2; +#if ENABLE_GCODE_VIEWER + if (m_draw_mode == dmSequentialGCodeView) + { + is_horizontal() ? x_draw = width - 2 : x_draw = 0.5 * width - 0.5 * m_cog_icon_dim; + is_horizontal() ? y_draw = 0.5 * height - 0.5 * m_cog_icon_dim : y_draw = height - 2; + } + else + { +#endif // ENABLE_GCODE_VIEWER + is_horizontal() ? x_draw = width - 2 : x_draw = width - m_cog_icon_dim - 2; + is_horizontal() ? y_draw = height - m_cog_icon_dim - 2 : y_draw = height - 2; +#if ENABLE_GCODE_VIEWER + } +#endif // ENABLE_GCODE_VIEWER dc.DrawBitmap(m_bmp_cog.bmp(), x_draw, y_draw); @@ -977,10 +989,19 @@ wxString Control::get_tooltip(int tick/*=-1*/) if (m_focus == fiRevertIcon) return _(L("Discard all custom changes")); if (m_focus == fiCogIcon) - return m_mode == t_mode::MultiAsSingle ? - GUI::from_u8((boost::format(_utf8(L("Jump to height %s or " - "Set extruder sequence for the entire print"))) % " (Shift + G)\n").str()) : - _(L("Jump to height")) + " (Shift + G)"; +#if ENABLE_GCODE_VIEWER + { + if (m_draw_mode == dmSequentialGCodeView) + return _L("Jump to move") + " (Shift + G)"; + else +#endif // ENABLE_GCODE_VIEWER + return m_mode == t_mode::MultiAsSingle ? + GUI::from_u8((boost::format(_utf8(L("Jump to height %s or " + "Set extruder sequence for the entire print"))) % " (Shift + G)\n").str()) : + _(L("Jump to height")) + " (Shift + G)"; +#if ENABLE_GCODE_VIEWER + } +#endif // ENABLE_GCODE_VIEWER if (m_focus == fiColorBand) return m_mode != t_mode::SingleExtruder ? "" : _(L("Edit current color - Right click the colored slider segment")); @@ -1230,7 +1251,11 @@ void Control::OnLeftUp(wxMouseEvent& event) if (m_mode == t_mode::MultiAsSingle && m_draw_mode == dmRegular) show_cog_icon_context_menu(); else +#if ENABLE_GCODE_VIEWER + jump_to_value(); +#else jump_to_print_z(); +#endif // ENABLE_GCODE_VIEWER break; case maOneLayerIconClick: switch_one_layer_mode(); @@ -1385,7 +1410,11 @@ void Control::OnChar(wxKeyEvent& event) m_ticks.suppress_minus(false); } if (key == 'G') +#if ENABLE_GCODE_VIEWER + jump_to_value(); +#else jump_to_print_z(); +#endif // ENABLE_GCODE_VIEWER } void Control::OnRightDown(wxMouseEvent& event) @@ -1571,7 +1600,11 @@ void Control::show_cog_icon_context_menu() wxMenu menu; append_menu_item(&menu, wxID_ANY, _(L("Jump to height")) + " (Shift+G)", "", - [this](wxCommandEvent&) { jump_to_print_z(); }, "", &menu); +#if ENABLE_GCODE_VIEWER + [this](wxCommandEvent&) { jump_to_value(); }, "", & menu); +#else + [this](wxCommandEvent&) { jump_to_print_z(); }, "", &menu); +#endif // ENABLE_GCODE_VIEWER append_menu_item(&menu, wxID_ANY, _(L("Set extruder sequence for the entire print")), "", [this](wxCommandEvent&) { edit_extruder_sequence(); }, "", &menu); @@ -1689,11 +1722,21 @@ static std::string get_pause_print_msg(const std::string& msg_in, double height) return into_u8(dlg.GetValue()); } +#if ENABLE_GCODE_VIEWER +static double get_value_to_jump(double active_value, double min_z, double max_z, DrawMode mode) +#else static double get_print_z_to_jump(double active_print_z, double min_z, double max_z) +#endif // ENABLE_GCODE_VIEWER { +#if ENABLE_GCODE_VIEWER + wxString msg_text = (mode == dmSequentialGCodeView) ? _L("Enter the move you want to jump to") + ":" : _L("Enter the height you want to jump to") + ":"; + wxString msg_header = (mode == dmSequentialGCodeView) ? _L("Jump to move") : _L("Jump to height"); + wxString msg_in = GUI::double_to_string(active_value); +#else wxString msg_text = _(L("Enter the height you want to jump to")) + ":"; wxString msg_header = _(L("Jump to height")); wxString msg_in = GUI::double_to_string(active_print_z); +#endif // ENABLE_GCODE_VIEWER // get custom gcode wxTextEntryDialog dlg(nullptr, msg_text, msg_header, msg_in, wxTextEntryDialogStyle); @@ -1902,6 +1945,23 @@ void Control::edit_extruder_sequence() post_ticks_changed_event(ToolChangeCode); } +#if ENABLE_GCODE_VIEWER +void Control::jump_to_value() +{ + double value = get_value_to_jump(m_values[m_selection == ssLower ? m_lower_value : m_higher_value], + m_values[m_min_value], m_values[m_max_value], m_draw_mode); + if (value < 0.0) + return; + + auto it = std::lower_bound(m_values.begin(), m_values.end(), value - epsilon()); + int tick_value = it - m_values.begin(); + + if (m_selection == ssLower) + SetLowerValue(tick_value); + else + SetHigherValue(tick_value); +} +#else void Control::jump_to_print_z() { double print_z = get_print_z_to_jump(m_values[m_selection == ssLower ? m_lower_value : m_higher_value], @@ -1917,6 +1977,7 @@ void Control::jump_to_print_z() else SetHigherValue(tick_value); } +#endif // ENABLE_GCODE_VIEWER void Control::post_ticks_changed_event(const std::string& gcode /*= ""*/) { diff --git a/src/slic3r/GUI/DoubleSlider.hpp b/src/slic3r/GUI/DoubleSlider.hpp index fea1ba172..71949f7f3 100644 --- a/src/slic3r/GUI/DoubleSlider.hpp +++ b/src/slic3r/GUI/DoubleSlider.hpp @@ -253,7 +253,11 @@ public: void discard_all_thicks(); void move_current_thumb_to_pos(wxPoint pos); void edit_extruder_sequence(); +#if ENABLE_GCODE_VIEWER + void jump_to_value(); +#else void jump_to_print_z(); +#endif // ENABLE_GCODE_VIEWER void show_add_context_menu(); void show_edit_context_menu(); void show_cog_icon_context_menu(); diff --git a/src/slic3r/GUI/Field.cpp b/src/slic3r/GUI/Field.cpp index 59ea01314..834613743 100644 --- a/src/slic3r/GUI/Field.cpp +++ b/src/slic3r/GUI/Field.cpp @@ -92,6 +92,12 @@ void Field::PostInitialize() case '2': { tab_id = 1; break; } case '3': { tab_id = 2; break; } case '4': { tab_id = 3; break; } +#ifdef __APPLE__ + case 'f': +#else /* __APPLE__ */ + case WXK_CONTROL_F: +#endif /* __APPLE__ */ + case 'F': { wxGetApp().plater()->search(false); break; } default: break; } if (tab_id >= 0) diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index 7629bc969..82c7576a2 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -63,11 +63,6 @@ #include #include #include "DoubleSlider.hpp" -#if !ENABLE_CANVAS_TOOLTIP_USING_IMGUI -#if ENABLE_RENDER_STATISTICS -#include -#endif // ENABLE_RENDER_STATISTICS -#endif // !ENABLE_CANVAS_TOOLTIP_USING_IMGUI #include @@ -1381,7 +1376,6 @@ void GLCanvas3D::Labels::render(const std::vector& sorted_ } } -#if ENABLE_CANVAS_TOOLTIP_USING_IMGUI void GLCanvas3D::Tooltip::set_text(const std::string& text) { // If the mouse is inside an ImGUI dialog, then the tooltip is suppressed. @@ -1433,7 +1427,6 @@ void GLCanvas3D::Tooltip::render(const Vec2d& mouse_position, GLCanvas3D& canvas imgui.end(); ImGui::PopStyleVar(2); } -#endif // ENABLE_CANVAS_TOOLTIP_USING_IMGUI #if ENABLE_SLOPE_RENDERING void GLCanvas3D::Slope::render() const @@ -2122,7 +2115,6 @@ void GLCanvas3D::render() m_camera.debug_render(); #endif // ENABLE_CAMERA_STATISTICS -#if ENABLE_CANVAS_TOOLTIP_USING_IMGUI std::string tooltip; // Negative coordinate means out of the window, likely because the window was deactivated. @@ -2152,7 +2144,6 @@ void GLCanvas3D::render() if (m_tooltip_enabled) m_tooltip.render(m_mouse.position, *this); -#endif // ENABLE_CANVAS_TOOLTIP_USING_IMGUI wxGetApp().plater()->get_mouse3d_controller().render_settings_dialog(*this); @@ -2164,30 +2155,6 @@ void GLCanvas3D::render() auto end_time = std::chrono::high_resolution_clock::now(); m_render_stats.last_frame = std::chrono::duration_cast(end_time - start_time).count(); #endif // ENABLE_RENDER_STATISTICS - -#if !ENABLE_CANVAS_TOOLTIP_USING_IMGUI - std::string tooltip = ""; - - if (tooltip.empty()) - tooltip = m_layers_editing.get_tooltip(*this); - - if (tooltip.empty()) - tooltip = m_gizmos.get_tooltip(); - - if (tooltip.empty()) - tooltip = m_main_toolbar.get_tooltip(); - - if (tooltip.empty()) - tooltip = m_undoredo_toolbar.get_tooltip(); - - if (tooltip.empty()) - tooltip = m_collapse_toolbar.get_tooltip(); - - if (tooltip.empty()) - tooltip = m_view_toolbar.get_tooltip(); - - set_tooltip(tooltip); -#endif // !ENABLE_CANVAS_TOOLTIP_USING_IMGUI } void GLCanvas3D::render_thumbnail(ThumbnailData& thumbnail_data, unsigned int w, unsigned int h, bool printable_only, bool parts_only, bool show_bed, bool transparent_background) const @@ -2911,9 +2878,7 @@ void GLCanvas3D::bind_event_handlers() m_canvas->Bind(wxEVT_MIDDLE_DCLICK, &GLCanvas3D::on_mouse, this); m_canvas->Bind(wxEVT_RIGHT_DCLICK, &GLCanvas3D::on_mouse, this); m_canvas->Bind(wxEVT_PAINT, &GLCanvas3D::on_paint, this); -#if ENABLE_CANVAS_TOOLTIP_USING_IMGUI m_canvas->Bind(wxEVT_SET_FOCUS, &GLCanvas3D::on_set_focus, this); -#endif // ENABLE_CANVAS_TOOLTIP_USING_IMGUI } } @@ -2941,9 +2906,7 @@ void GLCanvas3D::unbind_event_handlers() m_canvas->Unbind(wxEVT_MIDDLE_DCLICK, &GLCanvas3D::on_mouse, this); m_canvas->Unbind(wxEVT_RIGHT_DCLICK, &GLCanvas3D::on_mouse, this); m_canvas->Unbind(wxEVT_PAINT, &GLCanvas3D::on_paint, this); -#if ENABLE_CANVAS_TOOLTIP_USING_IMGUI m_canvas->Unbind(wxEVT_SET_FOCUS, &GLCanvas3D::on_set_focus, this); -#endif // ENABLE_CANVAS_TOOLTIP_USING_IMGUI } } @@ -3561,29 +3524,20 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt) Point pos(evt.GetX(), evt.GetY()); ImGuiWrapper* imgui = wxGetApp().imgui(); -#if ENABLE_CANVAS_TOOLTIP_USING_IMGUI if (m_tooltip.is_in_imgui() && evt.LeftUp()) // ignore left up events coming from imgui windows and not processed by them m_mouse.ignore_left_up = true; m_tooltip.set_in_imgui(false); -#endif // ENABLE_CANVAS_TOOLTIP_USING_IMGUI if (imgui->update_mouse_data(evt)) { m_mouse.position = evt.Leaving() ? Vec2d(-1.0, -1.0) : pos.cast(); -#if ENABLE_CANVAS_TOOLTIP_USING_IMGUI m_tooltip.set_in_imgui(true); -#endif // ENABLE_CANVAS_TOOLTIP_USING_IMGUI render(); #ifdef SLIC3R_DEBUG_MOUSE_EVENTS printf((format_mouse_event_debug_message(evt) + " - Consumed by ImGUI\n").c_str()); #endif /* SLIC3R_DEBUG_MOUSE_EVENTS */ // do not return if dragging or tooltip not empty to allow for tooltip update -#if ENABLE_CANVAS_TOOLTIP_USING_IMGUI if (!m_mouse.dragging && m_tooltip.is_empty()) return; -#else - if (!m_mouse.dragging && m_canvas->GetToolTipText().empty()) - return; -#endif // ENABLE_CANVAS_TOOLTIP_USING_IMGUI } #ifdef __WXMSW__ @@ -3642,9 +3596,7 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt) mouse_up_cleanup(); m_mouse.set_start_position_3D_as_invalid(); -#if ENABLE_CANVAS_TOOLTIP_USING_IMGUI m_mouse.position = pos.cast(); -#endif /// ENABLE_CANVAS_TOOLTIP_USING_IMGUI return; } @@ -3676,18 +3628,14 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt) if (top_level_wnd && top_level_wnd->IsActive()) m_canvas->SetFocus(); m_mouse.position = pos.cast(); -#if ENABLE_CANVAS_TOOLTIP_USING_IMGUI m_tooltip_enabled = false; -#endif // ENABLE_CANVAS_TOOLTIP_USING_IMGUI // 1) forces a frame render to ensure that m_hover_volume_idxs is updated even when the user right clicks while // the context menu is shown, ensuring it to disappear if the mouse is outside any volume and to // change the volume hover state if any is under the mouse // 2) when switching between 3d view and preview the size of the canvas changes if the side panels are visible, // so forces a resize to avoid multiple renders with different sizes (seen as flickering) _refresh_if_shown_on_screen(); -#if ENABLE_CANVAS_TOOLTIP_USING_IMGUI m_tooltip_enabled = true; -#endif // ENABLE_CANVAS_TOOLTIP_USING_IMGUI } m_mouse.set_start_position_2D_as_invalid(); //#endif @@ -4005,14 +3953,12 @@ void GLCanvas3D::on_paint(wxPaintEvent& evt) this->render(); } -#if ENABLE_CANVAS_TOOLTIP_USING_IMGUI void GLCanvas3D::on_set_focus(wxFocusEvent& evt) { m_tooltip_enabled = false; _refresh_if_shown_on_screen(); m_tooltip_enabled = true; } -#endif // ENABLE_CANVAS_TOOLTIP_USING_IMGUI Size GLCanvas3D::get_canvas_size() const { @@ -4062,26 +4008,7 @@ void GLCanvas3D::reset_legend_texture() void GLCanvas3D::set_tooltip(const std::string& tooltip) const { if (m_canvas != nullptr) - { -#if ENABLE_CANVAS_TOOLTIP_USING_IMGUI m_tooltip.set_text(tooltip); -#else - wxString txt = wxString::FromUTF8(tooltip.data()); - if (m_canvas->GetToolTipText() != txt) - m_canvas->SetToolTip(txt); - -// wxToolTip* t = m_canvas->GetToolTip(); -// if (t != nullptr) -// { -// if (tooltip.empty()) -// m_canvas->UnsetToolTip(); -// else -// t->SetTip(wxString::FromUTF8(tooltip.data())); -// } -// else if (!tooltip.empty()) // Avoid "empty" tooltips => unset of the empty tooltip leads to application crash under OSX -// m_canvas->SetToolTip(wxString::FromUTF8(tooltip.data())); -#endif // ENABLE_CANVAS_TOOLTIP_USING_IMGUI - } } void GLCanvas3D::do_move(const std::string& snapshot_type) diff --git a/src/slic3r/GUI/GLCanvas3D.hpp b/src/slic3r/GUI/GLCanvas3D.hpp index 43d37607c..9d7779061 100644 --- a/src/slic3r/GUI/GLCanvas3D.hpp +++ b/src/slic3r/GUI/GLCanvas3D.hpp @@ -3,9 +3,7 @@ #include #include -#if ENABLE_CANVAS_TOOLTIP_USING_IMGUI #include -#endif // ENABLE_CANVAS_TOOLTIP_USING_IMGUI #include "3DScene.hpp" #include "GLToolbar.hpp" @@ -399,7 +397,6 @@ private: void render(const std::vector& sorted_instances) const; }; -#if ENABLE_CANVAS_TOOLTIP_USING_IMGUI class Tooltip { std::string m_text; @@ -415,7 +412,6 @@ private: void set_in_imgui(bool b) { m_in_imgui = b; } bool is_in_imgui() const { return m_in_imgui; } }; -#endif // ENABLE_CANVAS_TOOLTIP_USING_IMGUI #if ENABLE_SLOPE_RENDERING class Slope @@ -526,10 +522,8 @@ private: int m_selected_extruder; Labels m_labels; -#if ENABLE_CANVAS_TOOLTIP_USING_IMGUI mutable Tooltip m_tooltip; mutable bool m_tooltip_enabled{ true }; -#endif // ENABLE_CANVAS_TOOLTIP_USING_IMGUI #if ENABLE_SLOPE_RENDERING Slope m_slope; #endif // ENABLE_SLOPE_RENDERING @@ -558,7 +552,7 @@ public: #if ENABLE_GCODE_VIEWER void reset_gcode_toolpaths() { m_gcode_viewer.reset(); } const GCodeViewer::SequentialView& get_gcode_sequential_view() const { return m_gcode_viewer.get_sequential_view(); } - void update_gcode_sequential_view_current(unsigned int low, unsigned int high) { m_gcode_viewer.update_sequential_view_current(low, high); } + void update_gcode_sequential_view_current(unsigned int first, unsigned int last) { m_gcode_viewer.update_sequential_view_current(first, last); } #endif // ENABLE_GCODE_VIEWER void toggle_sla_auxiliaries_visibility(bool visible, const ModelObject* mo = nullptr, int instance_idx = -1); @@ -687,9 +681,7 @@ public: void on_timer(wxTimerEvent& evt); void on_mouse(wxMouseEvent& evt); void on_paint(wxPaintEvent& evt); -#if ENABLE_CANVAS_TOOLTIP_USING_IMGUI void on_set_focus(wxFocusEvent& evt); -#endif // ENABLE_CANVAS_TOOLTIP_USING_IMGUI Size get_canvas_size() const; Vec2d get_local_mouse_position() const; diff --git a/src/slic3r/GUI/GLToolbar.cpp b/src/slic3r/GUI/GLToolbar.cpp index c69327cfa..603cfc3ad 100644 --- a/src/slic3r/GUI/GLToolbar.cpp +++ b/src/slic3r/GUI/GLToolbar.cpp @@ -153,9 +153,6 @@ GLToolbar::GLToolbar(GLToolbar::EType type, const std::string& name) , m_name(name) , m_enabled(false) , m_icons_texture_dirty(true) -#if !ENABLE_CANVAS_TOOLTIP_USING_IMGUI - , m_tooltip("") -#endif // !ENABLE_CANVAS_TOOLTIP_USING_IMGUI , m_pressed_toggable_id(-1) { } @@ -359,7 +356,6 @@ int GLToolbar::get_item_id(const std::string& name) const return -1; } -#if ENABLE_CANVAS_TOOLTIP_USING_IMGUI std::string GLToolbar::get_tooltip() const { std::string tooltip; @@ -382,7 +378,6 @@ std::string GLToolbar::get_tooltip() const return tooltip; } -#endif // ENABLE_CANVAS_TOOLTIP_USING_IMGUI void GLToolbar::get_additional_tooltip(int item_id, std::string& text) { @@ -449,17 +444,11 @@ bool GLToolbar::on_mouse(wxMouseEvent& evt, GLCanvas3D& parent) // prevents loosing selection into the scene if mouse down was done inside the toolbar and mouse up was down outside it, // as when switching between views m_mouse_capture.reset(); -#if !ENABLE_CANVAS_TOOLTIP_USING_IMGUI - if (contains_mouse(mouse_pos, parent) == -1) - // mouse is outside the toolbar - m_tooltip.clear(); -#endif // !ENABLE_CANVAS_TOOLTIP_USING_IMGUI return true; } m_mouse_capture.reset(); } -#if ENABLE_CANVAS_TOOLTIP_USING_IMGUI if (evt.Moving()) update_hover_state(mouse_pos, parent); else if (evt.LeftUp()) @@ -500,31 +489,9 @@ bool GLToolbar::on_mouse(wxMouseEvent& evt, GLCanvas3D& parent) else return false; } -#else - if (evt.Moving()) - m_tooltip = update_hover_state(mouse_pos, parent); - else if (evt.LeftUp()) - m_mouse_capture.left = false; - else if (evt.MiddleUp()) - m_mouse_capture.middle = false; - else if (evt.RightUp()) - m_mouse_capture.right = false; - else if (evt.Dragging() && m_mouse_capture.any()) - // if the button down was done on this toolbar, prevent from dragging into the scene - processed = true; -#endif // ENABLE_CANVAS_TOOLTIP_USING_IMGUI int item_id = contains_mouse(mouse_pos, parent); -#if ENABLE_CANVAS_TOOLTIP_USING_IMGUI if (item_id != -1) -#else - if (item_id == -1) - { - // mouse is outside the toolbar - m_tooltip.clear(); - } - else -#endif // ENABLE_CANVAS_TOOLTIP_USING_IMGUI { // mouse inside toolbar if (evt.LeftDown() || evt.LeftDClick()) @@ -532,12 +499,8 @@ bool GLToolbar::on_mouse(wxMouseEvent& evt, GLCanvas3D& parent) m_mouse_capture.left = true; m_mouse_capture.parent = &parent; processed = true; -#if ENABLE_CANVAS_TOOLTIP_USING_IMGUI if ((item_id != -2) && !m_items[item_id]->is_separator() && !m_items[item_id]->is_disabled() && ((m_pressed_toggable_id == -1) || (m_items[item_id]->get_last_action_type() == GLToolbarItem::Left))) -#else - if ((item_id != -2) && !m_items[item_id]->is_separator() && ((m_pressed_toggable_id == -1) || (m_items[item_id]->get_last_action_type() == GLToolbarItem::Left))) -#endif // ENABLE_CANVAS_TOOLTIP_USING_IMGUI { // mouse is inside an icon do_action(GLToolbarItem::Left, item_id, parent, true); @@ -554,22 +517,14 @@ bool GLToolbar::on_mouse(wxMouseEvent& evt, GLCanvas3D& parent) m_mouse_capture.right = true; m_mouse_capture.parent = &parent; processed = true; -#if ENABLE_CANVAS_TOOLTIP_USING_IMGUI if ((item_id != -2) && !m_items[item_id]->is_separator() && !m_items[item_id]->is_disabled() && ((m_pressed_toggable_id == -1) || (m_items[item_id]->get_last_action_type() == GLToolbarItem::Right))) -#else - if ((item_id != -2) && !m_items[item_id]->is_separator() && ((m_pressed_toggable_id == -1) || (m_items[item_id]->get_last_action_type() == GLToolbarItem::Right))) -#endif // ENABLE_CANVAS_TOOLTIP_USING_IMGUI { // mouse is inside an icon do_action(GLToolbarItem::Right, item_id, parent, true); parent.set_as_dirty(); } } -#if !ENABLE_CANVAS_TOOLTIP_USING_IMGUI - else if (evt.LeftUp()) - processed = true; -#endif // !ENABLE_CANVAS_TOOLTIP_USING_IMGUI } return processed; @@ -654,11 +609,7 @@ void GLToolbar::do_action(GLToolbarItem::EActionType type, int item_id, GLCanvas if ((0 <= item_id) && (item_id < (int)m_items.size())) { GLToolbarItem* item = m_items[item_id]; -#if ENABLE_CANVAS_TOOLTIP_USING_IMGUI if ((item != nullptr) && !item->is_separator() && !item->is_disabled() && (!check_hover || item->is_hovered())) -#else - if ((item != nullptr) && !item->is_separator() && (!check_hover || item->is_hovered())) -#endif // ENABLE_CANVAS_TOOLTIP_USING_IMGUI { if (((type == GLToolbarItem::Right) && item->is_right_toggable()) || ((type == GLToolbarItem::Left) && item->is_left_toggable())) @@ -712,7 +663,6 @@ void GLToolbar::do_action(GLToolbarItem::EActionType type, int item_id, GLCanvas } } -#if ENABLE_CANVAS_TOOLTIP_USING_IMGUI void GLToolbar::update_hover_state(const Vec2d& mouse_pos, GLCanvas3D& parent) { if (!m_enabled) @@ -725,26 +675,8 @@ void GLToolbar::update_hover_state(const Vec2d& mouse_pos, GLCanvas3D& parent) case Layout::Vertical: { update_hover_state_vertical(mouse_pos, parent); break; } } } -#else -std::string GLToolbar::update_hover_state(const Vec2d& mouse_pos, GLCanvas3D& parent) -{ - if (!m_enabled) - return ""; - switch (m_layout.type) - { - default: - case Layout::Horizontal: { return update_hover_state_horizontal(mouse_pos, parent); } - case Layout::Vertical: { return update_hover_state_vertical(mouse_pos, parent); } - } -} -#endif // ENABLE_CANVAS_TOOLTIP_USING_IMGUI - -#if ENABLE_CANVAS_TOOLTIP_USING_IMGUI void GLToolbar::update_hover_state_horizontal(const Vec2d& mouse_pos, GLCanvas3D& parent) -#else -std::string GLToolbar::update_hover_state_horizontal(const Vec2d& mouse_pos, GLCanvas3D& parent) -#endif // ENABLE_CANVAS_TOOLTIP_USING_IMGUI { // NB: mouse_pos is already scaled appropriately @@ -765,10 +697,6 @@ std::string GLToolbar::update_hover_state_horizontal(const Vec2d& mouse_pos, GLC float left = m_layout.left + scaled_border; float top = m_layout.top - scaled_border; -#if !ENABLE_CANVAS_TOOLTIP_USING_IMGUI - std::string tooltip; -#endif // !ENABLE_CANVAS_TOOLTIP_USING_IMGUI - for (GLToolbarItem* item : m_items) { if (!item->is_visible()) @@ -783,18 +711,6 @@ std::string GLToolbar::update_hover_state_horizontal(const Vec2d& mouse_pos, GLC GLToolbarItem::EState state = item->get_state(); bool inside = (left <= (float)scaled_mouse_pos(0)) && ((float)scaled_mouse_pos(0) <= right) && (bottom <= (float)scaled_mouse_pos(1)) && ((float)scaled_mouse_pos(1) <= top); -#if !ENABLE_CANVAS_TOOLTIP_USING_IMGUI - if (inside) - { - tooltip = item->get_tooltip(); - if (!item->is_pressed()) - { - const std::string& additional_tooltip = item->get_additional_tooltip(); - if (!additional_tooltip.empty()) - tooltip += "\n" + additional_tooltip; - } - } -#endif // !ENABLE_CANVAS_TOOLTIP_USING_IMGUI switch (state) { @@ -838,7 +754,6 @@ std::string GLToolbar::update_hover_state_horizontal(const Vec2d& mouse_pos, GLC break; } -#if ENABLE_CANVAS_TOOLTIP_USING_IMGUI case GLToolbarItem::Disabled: { if (inside) @@ -863,29 +778,14 @@ std::string GLToolbar::update_hover_state_horizontal(const Vec2d& mouse_pos, GLC { break; } -#else - default: - case GLToolbarItem::Disabled: - { - break; - } -#endif // ENABLE_CANVAS_TOOLTIP_USING_IMGUI } left += icon_stride; } } - -#if !ENABLE_CANVAS_TOOLTIP_USING_IMGUI - return tooltip; -#endif // !ENABLE_CANVAS_TOOLTIP_USING_IMGUI } -#if ENABLE_CANVAS_TOOLTIP_USING_IMGUI void GLToolbar::update_hover_state_vertical(const Vec2d& mouse_pos, GLCanvas3D& parent) -#else -std::string GLToolbar::update_hover_state_vertical(const Vec2d& mouse_pos, GLCanvas3D& parent) -#endif // ENABLE_CANVAS_TOOLTIP_USING_IMGUI { // NB: mouse_pos is already scaled appropriately @@ -905,10 +805,6 @@ std::string GLToolbar::update_hover_state_vertical(const Vec2d& mouse_pos, GLCan float left = m_layout.left + scaled_border; float top = m_layout.top - scaled_border; -#if !ENABLE_CANVAS_TOOLTIP_USING_IMGUI - std::string tooltip; -#endif // !ENABLE_CANVAS_TOOLTIP_USING_IMGUI - for (GLToolbarItem* item : m_items) { if (!item->is_visible()) @@ -923,18 +819,6 @@ std::string GLToolbar::update_hover_state_vertical(const Vec2d& mouse_pos, GLCan GLToolbarItem::EState state = item->get_state(); bool inside = (left <= (float)scaled_mouse_pos(0)) && ((float)scaled_mouse_pos(0) <= right) && (bottom <= (float)scaled_mouse_pos(1)) && ((float)scaled_mouse_pos(1) <= top); -#if !ENABLE_CANVAS_TOOLTIP_USING_IMGUI - if (inside) - { - tooltip = item->get_tooltip(); - if (!item->is_pressed()) - { - const std::string& additional_tooltip = item->get_additional_tooltip(); - if (!additional_tooltip.empty()) - tooltip += "\n" + additional_tooltip; - } - } -#endif // !ENABLE_CANVAS_TOOLTIP_USING_IMGUI switch (state) { @@ -978,7 +862,6 @@ std::string GLToolbar::update_hover_state_vertical(const Vec2d& mouse_pos, GLCan break; } -#if ENABLE_CANVAS_TOOLTIP_USING_IMGUI case GLToolbarItem::Disabled: { if (inside) @@ -1003,22 +886,11 @@ std::string GLToolbar::update_hover_state_vertical(const Vec2d& mouse_pos, GLCan { break; } -#else - default: - case GLToolbarItem::Disabled: - { - break; - } -#endif // ENABLE_CANVAS_TOOLTIP_USING_IMGUI } top -= icon_stride; } } - -#if !ENABLE_CANVAS_TOOLTIP_USING_IMGUI - return tooltip; -#endif // !ENABLE_CANVAS_TOOLTIP_USING_IMGUI } int GLToolbar::contains_mouse(const Vec2d& mouse_pos, const GLCanvas3D& parent) const @@ -1367,37 +1239,21 @@ bool GLToolbar::generate_icons_texture() const std::vector> states; if (m_name == "Top") { -#if ENABLE_CANVAS_TOOLTIP_USING_IMGUI states.push_back({ 1, false }); // Normal states.push_back({ 0, false }); // Pressed states.push_back({ 2, false }); // Disabled states.push_back({ 0, false }); // Hover states.push_back({ 0, false }); // HoverPressed states.push_back({ 2, false }); // HoverDisabled -#else - states.push_back(std::make_pair(1, false)); - states.push_back(std::make_pair(0, false)); - states.push_back(std::make_pair(2, false)); - states.push_back(std::make_pair(0, false)); - states.push_back(std::make_pair(0, false)); -#endif // ENABLE_CANVAS_TOOLTIP_USING_IMGUI } else if (m_name == "View") { -#if ENABLE_CANVAS_TOOLTIP_USING_IMGUI states.push_back({ 1, false }); // Normal states.push_back({ 1, true }); // Pressed states.push_back({ 1, false }); // Disabled states.push_back({ 0, false }); // Hover states.push_back({ 1, true }); // HoverPressed states.push_back({ 1, false }); // HoverDisabled -#else - states.push_back(std::make_pair(1, false)); - states.push_back(std::make_pair(1, true)); - states.push_back(std::make_pair(1, false)); - states.push_back(std::make_pair(0, false)); - states.push_back(std::make_pair(1, true)); -#endif // ENABLE_CANVAS_TOOLTIP_USING_IMGUI } unsigned int sprite_size_px = (unsigned int)(m_layout.icons_size * m_layout.scale); diff --git a/src/slic3r/GUI/GLToolbar.hpp b/src/slic3r/GUI/GLToolbar.hpp index 9911bb34a..41c2735c9 100644 --- a/src/slic3r/GUI/GLToolbar.hpp +++ b/src/slic3r/GUI/GLToolbar.hpp @@ -61,9 +61,7 @@ public: Disabled, Hover, HoverPressed, -#if ENABLE_CANVAS_TOOLTIP_USING_IMGUI HoverDisabled, -#endif // ENABLE_CANVAS_TOOLTIP_USING_IMGUI Num_States }; @@ -123,15 +121,9 @@ public: void do_left_action() { m_last_action_type = Left; m_data.left.action_callback(); } void do_right_action() { m_last_action_type = Right; m_data.right.action_callback(); } -#if ENABLE_CANVAS_TOOLTIP_USING_IMGUI bool is_enabled() const { return (m_state != Disabled) && (m_state != HoverDisabled); } bool is_disabled() const { return (m_state == Disabled) || (m_state == HoverDisabled); } bool is_hovered() const { return (m_state == Hover) || (m_state == HoverPressed) || (m_state == HoverDisabled); } -#else - bool is_enabled() const { return m_state != Disabled; } - bool is_disabled() const { return m_state == Disabled; } - bool is_hovered() const { return (m_state == Hover) || (m_state == HoverPressed); } -#endif // ENABLE_CANVAS_TOOLTIP_USING_IMGUI bool is_pressed() const { return (m_state == Pressed) || (m_state == HoverPressed); } bool is_visible() const { return m_data.visible; } bool is_separator() const { return m_type == Separator; } @@ -262,9 +254,6 @@ private: }; MouseCapture m_mouse_capture; -#if !ENABLE_CANVAS_TOOLTIP_USING_IMGUI - std::string m_tooltip; -#endif // !ENABLE_CANVAS_TOOLTIP_USING_IMGUI int m_pressed_toggable_id; public: @@ -310,11 +299,7 @@ public: void force_left_action(int item_id, GLCanvas3D& parent) { do_action(GLToolbarItem::Left, item_id, parent, false); } void force_right_action(int item_id, GLCanvas3D& parent) { do_action(GLToolbarItem::Right, item_id, parent, false); } -#if ENABLE_CANVAS_TOOLTIP_USING_IMGUI std::string get_tooltip() const; -#else - const std::string& get_tooltip() const { return m_tooltip; } -#endif // ENABLE_CANVAS_TOOLTIP_USING_IMGUI void get_additional_tooltip(int item_id, std::string& text); void set_additional_tooltip(int item_id, const std::string& text); @@ -336,15 +321,9 @@ private: float get_height_vertical() const; float get_main_size() const; void do_action(GLToolbarItem::EActionType type, int item_id, GLCanvas3D& parent, bool check_hover); -#if ENABLE_CANVAS_TOOLTIP_USING_IMGUI void update_hover_state(const Vec2d& mouse_pos, GLCanvas3D& parent); void update_hover_state_horizontal(const Vec2d& mouse_pos, GLCanvas3D& parent); void update_hover_state_vertical(const Vec2d& mouse_pos, GLCanvas3D& parent); -#else - std::string update_hover_state(const Vec2d& mouse_pos, GLCanvas3D& parent); - std::string update_hover_state_horizontal(const Vec2d& mouse_pos, GLCanvas3D& parent); - std::string update_hover_state_vertical(const Vec2d& mouse_pos, GLCanvas3D& parent); -#endif // ENABLE_CANVAS_TOOLTIP_USING_IMGUI // returns the id of the item under the given mouse position or -1 if none int contains_mouse(const Vec2d& mouse_pos, const GLCanvas3D& parent) const; int contains_mouse_horizontal(const Vec2d& mouse_pos, const GLCanvas3D& parent) const; diff --git a/src/slic3r/GUI/Gizmos/GLGizmosManager.cpp b/src/slic3r/GUI/Gizmos/GLGizmosManager.cpp index 8ff6c121f..8f8bebc8e 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmosManager.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmosManager.cpp @@ -479,22 +479,9 @@ bool GLGizmosManager::on_mouse(wxMouseEvent& evt) int selected_object_idx = selection.get_object_idx(); bool processed = false; -#if !ENABLE_CANVAS_TOOLTIP_USING_IMGUI - // mouse anywhere - if (!evt.Dragging() && !evt.Leaving() && !evt.Entering() && (m_mouse_capture.parent != nullptr)) - { - if (m_mouse_capture.any() && (evt.LeftUp() || evt.MiddleUp() || evt.RightUp())) - // prevents loosing selection into the scene if mouse down was done inside the toolbar and mouse up was down outside it - processed = true; - - m_mouse_capture.reset(); - } -#endif // !ENABLE_CANVAS_TOOLTIP_USING_IMGUI - // mouse anywhere if (evt.Moving()) m_tooltip = update_hover_state(mouse_pos); -#if ENABLE_CANVAS_TOOLTIP_USING_IMGUI else if (evt.LeftUp()) { if (m_mouse_capture.left) @@ -551,11 +538,7 @@ bool GLGizmosManager::on_mouse(wxMouseEvent& evt) // else // return false; } -#if ENABLE_GIZMO_TOOLBAR_DRAGGING_FIX else if (evt.Dragging() && !is_dragging()) -#else - else if (evt.Dragging()) -#endif // ENABLE_GIZMO_TOOLBAR_DRAGGING_FIX { if (m_mouse_capture.any()) // if the button down was done on this toolbar, prevent from dragging into the scene @@ -563,25 +546,6 @@ bool GLGizmosManager::on_mouse(wxMouseEvent& evt) // else // return false; } -#else - else if (evt.LeftUp()) - m_mouse_capture.left = false; - else if (evt.MiddleUp()) - m_mouse_capture.middle = false; - else if (evt.RightUp()) - { - m_mouse_capture.right = false; - if (pending_right_up) - { - pending_right_up = false; - processed = true; - } - } - else if (evt.Dragging() && m_mouse_capture.any()) - // if the button down was done on this toolbar, prevent from dragging into the scene - processed = true; -#endif // ENABLE_CANVAS_TOOLTIP_USING_IMGUI -#if ENABLE_GIZMO_TOOLBAR_DRAGGING_FIX else if (evt.Dragging() && is_dragging()) { if (!m_parent.get_wxglcanvas()->HasCapture()) @@ -628,7 +592,6 @@ bool GLGizmosManager::on_mouse(wxMouseEvent& evt) m_parent.set_as_dirty(); processed = true; } -#endif // ENABLE_GIZMO_TOOLBAR_DRAGGING_FIX if (get_gizmo_idx_from_mouse(mouse_pos) == Undefined) { @@ -680,77 +643,6 @@ bool GLGizmosManager::on_mouse(wxMouseEvent& evt) m_parent.set_as_dirty(); processed = true; } -#if !ENABLE_GIZMO_TOOLBAR_DRAGGING_FIX - else if (evt.Dragging() && is_dragging()) - { - if (!m_parent.get_wxglcanvas()->HasCapture()) - m_parent.get_wxglcanvas()->CaptureMouse(); - - m_parent.set_mouse_as_dragging(); - update(m_parent.mouse_ray(pos), pos); - - switch (m_current) - { - case Move: - { - // Apply new temporary offset - selection.translate(get_displacement()); - wxGetApp().obj_manipul()->set_dirty(); - break; - } - case Scale: - { - // Apply new temporary scale factors - TransformationType transformation_type(TransformationType::Local_Absolute_Joint); - if (evt.AltDown()) - transformation_type.set_independent(); - selection.scale(get_scale(), transformation_type); - if (evt.ControlDown()) - selection.translate(get_scale_offset(), true); - wxGetApp().obj_manipul()->set_dirty(); - break; - } - case Rotate: - { - // Apply new temporary rotations - TransformationType transformation_type(TransformationType::World_Relative_Joint); - if (evt.AltDown()) - transformation_type.set_independent(); - selection.rotate(get_rotation(), transformation_type); - wxGetApp().obj_manipul()->set_dirty(); - break; - } - default: - break; - } - - m_parent.set_as_dirty(); - processed = true; - } -#endif // !ENABLE_GIZMO_TOOLBAR_DRAGGING_FIX -#if !ENABLE_CANVAS_TOOLTIP_USING_IMGUI - else if (evt.LeftUp() && is_dragging()) - { - switch (m_current) { - case Move : m_parent.do_move(L("Gizmo-Move")); break; - case Scale : m_parent.do_scale(L("Gizmo-Scale")); break; - case Rotate : m_parent.do_rotate(L("Gizmo-Rotate")); break; - default : break; - } - - stop_dragging(); - update_data(); - - wxGetApp().obj_manipul()->set_dirty(); - // Let the plater know that the dragging finished, so a delayed refresh - // of the scene with the background processing data should be performed. - m_parent.post_event(SimpleEvent(EVT_GLCANVAS_MOUSE_DRAGGING_FINISHED)); - // updates camera target constraints - m_parent.refresh_camera_scene_box(); - - processed = true; - } -#endif // !ENABLE_CANVAS_TOOLTIP_USING_IMGUI else if (evt.LeftUp() && (m_current == SlaSupports || m_current == Hollow || m_current == FdmSupports) && !m_parent.is_mouse_dragging()) { // in case SLA/FDM gizmo is selected, we just pass the LeftUp event and stop processing - neither @@ -794,10 +686,6 @@ bool GLGizmosManager::on_mouse(wxMouseEvent& evt) m_mouse_capture.right = true; m_mouse_capture.parent = &m_parent; } -#if !ENABLE_CANVAS_TOOLTIP_USING_IMGUI - else if (evt.LeftUp()) - processed = true; -#endif // !ENABLE_CANVAS_TOOLTIP_USING_IMGUI } return processed; diff --git a/src/slic3r/GUI/ImGuiWrapper.cpp b/src/slic3r/GUI/ImGuiWrapper.cpp index 755d84180..53c309abd 100644 --- a/src/slic3r/GUI/ImGuiWrapper.cpp +++ b/src/slic3r/GUI/ImGuiWrapper.cpp @@ -747,7 +747,6 @@ void ImGuiWrapper::search_list(const ImVec2& size_, bool (*items_getter)(int, co // add checkboxes for show/hide Categories and Groups text(_L("Use for search")+":"); check_box(_L("Category"), view_params.category); - check_box(_L("Group"), view_params.group); if (is_localized) check_box(_L("Search in English"), view_params.english); } diff --git a/src/slic3r/GUI/MainFrame.cpp b/src/slic3r/GUI/MainFrame.cpp index 8ba53ee64..2b5f8429f 100644 --- a/src/slic3r/GUI/MainFrame.cpp +++ b/src/slic3r/GUI/MainFrame.cpp @@ -1434,6 +1434,12 @@ SettingsDialog::SettingsDialog(MainFrame* mainframe) case '2': { m_main_frame->select_tab(1); break; } case '3': { m_main_frame->select_tab(2); break; } case '4': { m_main_frame->select_tab(3); break; } +#ifdef __APPLE__ + case 'f': +#else /* __APPLE__ */ + case WXK_CONTROL_F: +#endif /* __APPLE__ */ + case 'F': { m_main_frame->plater()->search(false); break; } default:break; } } diff --git a/src/slic3r/GUI/Search.cpp b/src/slic3r/GUI/Search.cpp index b929b37d0..9fcd9ec9f 100644 --- a/src/slic3r/GUI/Search.cpp +++ b/src/slic3r/GUI/Search.cpp @@ -6,6 +6,8 @@ #include #include +#include "wx/dataview.h" + #include "libslic3r/PrintConfig.hpp" #include "GUI_App.hpp" #include "Tab.hpp" @@ -199,10 +201,8 @@ bool OptionsSearcher::search(const std::string& search, bool force/* = false*/) const std::wstring *prev = nullptr; for (const std::wstring * const s : { view_params.category ? &opt.category_local : nullptr, - view_params.group ? &opt.group_local : nullptr, - &opt.label_local }) + &opt.group_local, &opt.label_local }) if (s != nullptr && (prev == nullptr || *prev != *s)) { -// if (! out.empty()) if (out.size()>2) out += sep; out += *s; @@ -218,10 +218,8 @@ bool OptionsSearcher::search(const std::string& search, bool force/* = false*/) const std::wstring*prev = nullptr; for (const std::wstring * const s : { view_params.category ? &opt.category : nullptr, - view_params.group ? &opt.group : nullptr, - &opt.label }) + &opt.group, &opt.label }) if (s != nullptr && (prev == nullptr || *prev != *s)) { -// if (! out.empty()) if (out.size()>2) out += sep; out += *s; @@ -272,9 +270,9 @@ bool OptionsSearcher::search(const std::string& search, bool force/* = false*/) label += L" [" + std::to_wstring(score) + L"]";// add score value std::string label_u8 = into_u8(label); std::string label_plain = label_u8; - boost::erase_all(label_plain, std::string(1, char(ImGui::ColorMarkerStart))); - boost::erase_all(label_plain, std::string(1, char(ImGui::ColorMarkerEnd))); - found.emplace_back(FoundOption{ label_plain, label_u8, boost::nowide::narrow(get_tooltip(opt)), i, score }); + boost::replace_all(label_plain, std::string(1, char(ImGui::ColorMarkerStart)), ""); + boost::replace_all(label_plain, std::string(1, char(ImGui::ColorMarkerEnd)), ""); + found.emplace_back(FoundOption{ label_plain, label_u8, boost::nowide::narrow(get_tooltip(opt)), i, score }); } } @@ -415,6 +413,14 @@ void SearchComboPopup::OnKeyDown(wxKeyEvent& event) // SearchDialog //------------------------------------------ +static const std::map icon_idxs = { + {ImGui::PrintIconMarker , 0}, + {ImGui::PrinterIconMarker , 1}, + {ImGui::PrinterSlaIconMarker, 2}, + {ImGui::FilamentIconMarker , 3}, + {ImGui::MaterialIconMarker , 4}, +}; + SearchDialog::SearchDialog(OptionsSearcher* searcher) : GUI::DPIDialog(NULL, wxID_ANY, _L("Search"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER), searcher(searcher) @@ -425,23 +431,35 @@ SearchDialog::SearchDialog(OptionsSearcher* searcher) default_string = _L("Type here to search"); int border = 10; + int em = em_unit(); - search_line = new wxTextCtrl(this, wxID_ANY, "", wxDefaultPosition, wxDefaultSize); + search_line = new wxTextCtrl(this, wxID_ANY, "", wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_ENTER); - // wxWANTS_CHARS style is neede for process Enter key press - search_list = new wxListBox(this, wxID_ANY, wxDefaultPosition, wxSize(em_unit() * 40, em_unit() * 30), 0, NULL, wxWANTS_CHARS); + search_list = new wxDataViewCtrl(this, wxID_ANY, wxDefaultPosition, wxSize(em * 40, em * 30), wxDV_NO_HEADER | wxDV_SINGLE | wxBORDER_SIMPLE); + search_list_model = new SearchListModel(this); + search_list->AssociateModel(search_list_model); + + search_list->AppendBitmapColumn("", SearchListModel::colIcon); + + wxDataViewTextRenderer* const markupRenderer = new wxDataViewTextRenderer(); +#if wxUSE_MARKUP + markupRenderer->EnableMarkup(); +#endif // wxUSE_MARKUP + search_list->AppendColumn(new wxDataViewColumn("", markupRenderer, SearchListModel::colMarkedText, wxCOL_WIDTH_AUTOSIZE, wxALIGN_LEFT)); + + search_list->GetColumn(SearchListModel::colIcon )->SetWidth(3 * em_unit()); + search_list->GetColumn(SearchListModel::colMarkedText)->SetWidth(40 * em_unit()); wxBoxSizer* check_sizer = new wxBoxSizer(wxHORIZONTAL); check_category = new wxCheckBox(this, wxID_ANY, _L("Category")); - check_group = new wxCheckBox(this, wxID_ANY, _L("Group")); if (GUI::wxGetApp().is_localized()) check_english = new wxCheckBox(this, wxID_ANY, _L("Search in English")); wxStdDialogButtonSizer* cancel_btn = this->CreateStdDialogButtonSizer(wxCANCEL); + check_sizer->Add(new wxStaticText(this, wxID_ANY, _L("Use for search") + ":"), 0, wxALIGN_CENTER_VERTICAL | wxRIGHT, border); check_sizer->Add(check_category, 0, wxALIGN_CENTER_VERTICAL | wxRIGHT, border); - check_sizer->Add(check_group, 0, wxALIGN_CENTER_VERTICAL | wxRIGHT, border); if (GUI::wxGetApp().is_localized()) check_sizer->Add(check_english, 0, wxALIGN_CENTER_VERTICAL | wxRIGHT, border); check_sizer->AddStretchSpacer(border); @@ -458,16 +476,19 @@ SearchDialog::SearchDialog(OptionsSearcher* searcher) // process wxEVT_KEY_DOWN to navigate inside search_list, if ArrowUp/Down was pressed search_line->Bind(wxEVT_KEY_DOWN,&SearchDialog::OnKeyDown, this); - search_list->Bind(wxEVT_MOTION, &SearchDialog::OnMouseMove, this); - search_list->Bind(wxEVT_LEFT_UP, &SearchDialog::OnMouseClick, this); - search_list->Bind(wxEVT_KEY_DOWN,&SearchDialog::OnKeyDown, this); + search_list->Bind(wxEVT_DATAVIEW_SELECTION_CHANGED, &SearchDialog::OnSelect, this); + search_list->Bind(wxEVT_DATAVIEW_ITEM_ACTIVATED, &SearchDialog::OnActivate, this); +#ifdef __WXMSW__ + search_list->GetMainWindow()->Bind(wxEVT_MOTION, &SearchDialog::OnMotion, this); + search_list->GetMainWindow()->Bind(wxEVT_LEFT_DOWN, &SearchDialog::OnLeftDown, this); +#endif //__WXMSW__ + check_category->Bind(wxEVT_CHECKBOX, &SearchDialog::OnCheck, this); if (GUI::wxGetApp().is_localized()) check_english ->Bind(wxEVT_CHECKBOX, &SearchDialog::OnCheck, this); - check_category->Bind(wxEVT_CHECKBOX, &SearchDialog::OnCheck, this); - check_group ->Bind(wxEVT_CHECKBOX, &SearchDialog::OnCheck, this); - this->Bind(wxEVT_LISTBOX, &SearchDialog::OnSelect, this); + Bind(wxEVT_MOTION, &SearchDialog::OnMotion, this); + Bind(wxEVT_LEFT_DOWN, &SearchDialog::OnLeftDown, this); SetSizer(topSizer); topSizer->SetSizeHints(this); @@ -484,19 +505,18 @@ void SearchDialog::Popup(wxPoint position /*= wxDefaultPosition*/) const OptionViewParameters& params = searcher->view_params; check_category->SetValue(params.category); - check_group->SetValue(params.group); check_english->SetValue(params.english); this->SetPosition(position); this->ShowModal(); } -void SearchDialog::ProcessSelection(int selection) +void SearchDialog::ProcessSelection(wxDataViewItem selection) { - if (selection < 0) + if (!selection.IsOk()) return; - GUI::wxGetApp().sidebar().jump_to_option(selection); + GUI::wxGetApp().sidebar().jump_to_option(search_list_model->GetRow(selection)); this->EndModal(wxID_CLOSE); } @@ -521,39 +541,6 @@ void SearchDialog::OnLeftUpInTextCtrl(wxEvent& event) event.Skip(); } -void SearchDialog::OnMouseMove(wxMouseEvent& event) -{ - wxPoint pt = wxGetMousePosition() - search_list->GetScreenPosition(); - int selection = search_list->HitTest(pt); - search_list->Select(selection); -} - -void SearchDialog::OnMouseClick(wxMouseEvent&) -{ - int selection = search_list->GetSelection(); - search_list->SetSelection(wxNOT_FOUND); - - wxCommandEvent event(wxEVT_LISTBOX, search_list->GetId()); - event.SetInt(selection); - event.SetEventObject(search_list); - ProcessEvent(event); -} - -void SearchDialog::OnSelect(wxCommandEvent& event) -{ - int selection = event.GetSelection(); - ProcessSelection(selection); -} - -void SearchDialog::update_list() -{ - search_list->Clear(); - - const std::vector& filters = searcher->found_options(); - for (const FoundOption& item : filters) - search_list->Append(from_u8(item.label).Remove(0, 1)); -} - void SearchDialog::OnKeyDown(wxKeyEvent& event) { int key = event.GetKeyCode(); @@ -561,17 +548,23 @@ void SearchDialog::OnKeyDown(wxKeyEvent& event) // change selected item in the list if (key == WXK_UP || key == WXK_DOWN) { - int selection = search_list->GetSelection(); - - if (key == WXK_UP && selection > 0) - selection--; - if (key == WXK_DOWN && selection < int(search_list->GetCount() - 1)) - selection++; - - search_list->Select(selection); - // This function could be called from search_line, // So, for the next correct navigation, set focus on the search_list search_list->SetFocus(); + + auto item = search_list->GetSelection(); + + if (item.IsOk()) { + unsigned selection = search_list_model->GetRow(item); + + if (key == WXK_UP && selection > 0) + selection--; + if (key == WXK_DOWN && selection < unsigned(search_list_model->GetCount() - 1)) + selection++; + + prevent_list_events = true; + search_list->Select(search_list_model->GetItem(selection)); + prevent_list_events = false; + } } // process "Enter" pressed else if (key == WXK_NUMPAD_ENTER || key == WXK_RETURN) @@ -580,21 +573,76 @@ void SearchDialog::OnKeyDown(wxKeyEvent& event) event.Skip(); // !Needed to have EVT_CHAR generated as well } +void SearchDialog::OnActivate(wxDataViewEvent& event) +{ + ProcessSelection(event.GetItem()); +} + +void SearchDialog::OnSelect(wxDataViewEvent& event) +{ + // To avoid selection update from Select() under osx + if (prevent_list_events) + return; + + // wxEVT_DATAVIEW_SELECTION_CHANGED is processed, when selection is changed after mouse click or press the Up/Down arrows + // But this two cases should be processed in different way: + // Up/Down arrows -> leave it as it is (just a navigation) + // LeftMouseClick -> call the ProcessSelection function + if (wxGetMouseState().LeftIsDown()) + ProcessSelection(search_list->GetSelection()); +} + +void SearchDialog::update_list() +{ + search_list_model->Clear(); + + const std::vector& filters = searcher->found_options(); + for (const FoundOption& item : filters) + search_list_model->Prepend(item.label); + + // select first item + prevent_list_events = true; + search_list->Select(search_list_model->GetItem(0)); + prevent_list_events = false; +} + void SearchDialog::OnCheck(wxCommandEvent& event) { OptionViewParameters& params = searcher->view_params; params.english = check_english->GetValue(); params.category = check_category->GetValue(); - params.group = check_group->GetValue(); searcher->search(); update_list(); } +void SearchDialog::OnMotion(wxMouseEvent& event) +{ + wxDataViewItem item; + wxDataViewColumn* col; + wxWindow* win = this; +#ifdef __WXMSW__ + win = search_list; +#endif + search_list->HitTest(wxGetMousePosition() - win->GetScreenPosition(), item, col); + search_list->Select(item); + + event.Skip(); +} + +void SearchDialog::OnLeftDown(wxMouseEvent& event) +{ + ProcessSelection(search_list->GetSelection()); +} + void SearchDialog::on_dpi_changed(const wxRect& suggested_rect) { const int& em = em_unit(); + search_list_model->msw_rescale(); + search_list->GetColumn(SearchListModel::colIcon )->SetWidth(3 * em); + search_list->GetColumn(SearchListModel::colMarkedText)->SetWidth(45 * em); + msw_buttons_rescale(this, em, { wxID_CANCEL }); const wxSize& size = wxSize(40 * em, 30 * em); @@ -604,6 +652,65 @@ void SearchDialog::on_dpi_changed(const wxRect& suggested_rect) Refresh(); } +// ---------------------------------------------------------------------------- +// SearchListModel +// ---------------------------------------------------------------------------- + +SearchListModel::SearchListModel(wxWindow* parent) : wxDataViewVirtualListModel(0) +{ + int icon_id = 0; + for (const std::string& icon : { "cog", "printer", "sla_printer", "spool", "resin" }) + m_icon[icon_id++] = ScalableBitmap(parent, icon); +} + +void SearchListModel::Clear() +{ + m_values.clear(); + Reset(0); +} + +void SearchListModel::Prepend(const std::string& label) +{ + const char icon_c = label.at(0); + int icon_idx = icon_idxs.at(icon_c); + wxString str = from_u8(label).Remove(0, 1); + + m_values.emplace_back(str, icon_idx); + + RowPrepended(); +} + +void SearchListModel::msw_rescale() +{ + for (ScalableBitmap& bmp : m_icon) + bmp.msw_rescale(); +} + +wxString SearchListModel::GetColumnType(unsigned int col) const +{ + if (col == colIcon) + return "wxBitmap"; + return "string"; +} + +void SearchListModel::GetValueByRow(wxVariant& variant, + unsigned int row, unsigned int col) const +{ + switch (col) + { + case colIcon: + variant << m_icon[m_values[row].second].bmp(); + break; + case colMarkedText: + variant = m_values[row].first; + break; + case colMax: + wxFAIL_MSG("invalid column"); + default: + break; + } +} + } diff --git a/src/slic3r/GUI/Search.hpp b/src/slic3r/GUI/Search.hpp index 291633a2b..533ecf8f3 100644 --- a/src/slic3r/GUI/Search.hpp +++ b/src/slic3r/GUI/Search.hpp @@ -67,7 +67,6 @@ struct FoundOption { struct OptionViewParameters { bool category {false}; - bool group {true }; bool english {false}; int hovered_id {0}; @@ -158,48 +157,86 @@ protected: wxString m_input_string; }; - //------------------------------------------ // SearchDialog //------------------------------------------ - +class SearchListModel; class SearchDialog : public GUI::DPIDialog { wxString search_str; wxString default_string; - wxTextCtrl* search_line { nullptr }; - wxListBox* search_list { nullptr }; - wxCheckBox* check_category { nullptr }; - wxCheckBox* check_group { nullptr }; - wxCheckBox* check_english { nullptr }; + bool prevent_list_events {false}; - OptionsSearcher* searcher; + wxTextCtrl* search_line { nullptr }; + wxDataViewCtrl* search_list { nullptr }; + SearchListModel* search_list_model { nullptr }; + wxCheckBox* check_category { nullptr }; + wxCheckBox* check_english { nullptr }; - void update_list(); + OptionsSearcher* searcher { nullptr }; void OnInputText(wxCommandEvent& event); void OnLeftUpInTextCtrl(wxEvent& event); - - void OnMouseMove(wxMouseEvent& event); - void OnMouseClick(wxMouseEvent& event); - void OnSelect(wxCommandEvent& event); void OnKeyDown(wxKeyEvent& event); + void OnActivate(wxDataViewEvent& event); + void OnSelect(wxDataViewEvent& event); + void OnCheck(wxCommandEvent& event); + void OnMotion(wxMouseEvent& event); + void OnLeftDown(wxMouseEvent& event); + + void update_list(); public: SearchDialog(OptionsSearcher* searcher); ~SearchDialog() {} void Popup(wxPoint position = wxDefaultPosition); - void ProcessSelection(int selection); + void ProcessSelection(wxDataViewItem selection); protected: void on_dpi_changed(const wxRect& suggested_rect) override; }; +// ---------------------------------------------------------------------------- +// SearchListModel +// ---------------------------------------------------------------------------- + +class SearchListModel : public wxDataViewVirtualListModel +{ + std::vector> m_values; + ScalableBitmap m_icon[5]; + +public: + enum { + colIcon, + colMarkedText, + colMax + }; + + SearchListModel(wxWindow* parent); + + // helper methods to change the model + + void Clear(); + void Prepend(const std::string& text); + void msw_rescale(); + + // implementation of base class virtuals to define model + + virtual unsigned int GetColumnCount() const wxOVERRIDE { return colMax; } + virtual wxString GetColumnType(unsigned int col) const wxOVERRIDE; + virtual void GetValueByRow(wxVariant& variant, unsigned int row, unsigned int col) const wxOVERRIDE; + virtual bool GetAttrByRow(unsigned int row, unsigned int col, wxDataViewItemAttr& attr) const wxOVERRIDE { return true; } + virtual bool SetValueByRow(const wxVariant& variant, unsigned int row, unsigned int col) wxOVERRIDE { return false; } +}; + + + + } // Search namespace } diff --git a/src/slic3r/GUI/Tab.cpp b/src/slic3r/GUI/Tab.cpp index a21947b15..ae0877763 100644 --- a/src/slic3r/GUI/Tab.cpp +++ b/src/slic3r/GUI/Tab.cpp @@ -53,7 +53,7 @@ void Tab::Highlighter::init(BlinkingBitmap* bmp) if (!bmp) return; - timer.Start(100, false); + timer.Start(300, false); bbmp = bmp; bbmp->activate(); @@ -74,7 +74,7 @@ void Tab::Highlighter::blink() return; bbmp->blink(); - if ((++blink_counter) == 29) + if ((++blink_counter) == 11) invalidate(); }