From 4f0a47b7f4ea2df51c0642bb6be723f576ea1b73 Mon Sep 17 00:00:00 2001 From: Ocraftyone Date: Wed, 20 Dec 2023 00:29:06 -0500 Subject: [PATCH 01/39] add UndoValueUIManager from PS from prusa3d/PrusaSlicer@32ff20d Co-authored-by: YuSanka --- src/slic3r/GUI/Field.cpp | 2 +- src/slic3r/GUI/Field.hpp | 176 ++++++++++++++++++++----------- src/slic3r/GUI/OG_CustomCtrl.cpp | 4 +- src/slic3r/GUI/OptionsGroup.cpp | 5 +- src/slic3r/GUI/OptionsGroup.hpp | 17 ++- src/slic3r/GUI/Tab.cpp | 45 +++++--- src/slic3r/GUI/Tab.hpp | 1 + 7 files changed, 162 insertions(+), 88 deletions(-) diff --git a/src/slic3r/GUI/Field.cpp b/src/slic3r/GUI/Field.cpp index 7939bb9acde..c9b8d5368ab 100644 --- a/src/slic3r/GUI/Field.cpp +++ b/src/slic3r/GUI/Field.cpp @@ -206,7 +206,7 @@ wxString Field::get_tooltip_text(const wxString &default_string) wxString tooltip_text(""); #ifdef NDEBUG wxString tooltip = _(m_opt.tooltip); - edit_tooltip(tooltip); + ::edit_tooltip(tooltip); std::string opt_id = m_opt_id; auto hash_pos = opt_id.find("#"); diff --git a/src/slic3r/GUI/Field.hpp b/src/slic3r/GUI/Field.hpp index a951c021321..58b5dd5e2da 100644 --- a/src/slic3r/GUI/Field.hpp +++ b/src/slic3r/GUI/Field.hpp @@ -41,7 +41,120 @@ wxString double_to_string(double const value, const int max_precision = 4); wxString get_thumbnail_string(const Vec2d& value); wxString get_thumbnails_string(const std::vector& values); -class Field { +class UndoValueUIManager +{ + struct UndoValueUI { + // Bitmap and Tooltip text for m_Undo_btn. The wxButton will be updated only if the new wxBitmap pointer differs from the currently rendered one. + const ScalableBitmap* undo_bitmap{ nullptr }; + const wxString* undo_tooltip{ nullptr }; + // Bitmap and Tooltip text for m_Undo_to_sys_btn. The wxButton will be updated only if the new wxBitmap pointer differs from the currently rendered one. + const ScalableBitmap* undo_to_sys_bitmap{ nullptr }; + const wxString* undo_to_sys_tooltip{ nullptr }; + // Color for Label. The wxColour will be updated only if the new wxColour pointer differs from the currently rendered one. + const wxColour* label_color{ nullptr }; + // State of the blinker icon + bool blink{ false }; + + bool set_undo_bitmap(const ScalableBitmap* bmp) { + if (undo_bitmap != bmp) { + undo_bitmap = bmp; + return true; + } + return false; + } + + bool set_undo_to_sys_bitmap(const ScalableBitmap* bmp) { + if (undo_to_sys_bitmap != bmp) { + undo_to_sys_bitmap = bmp; + return true; + } + return false; + } + + bool set_label_colour(const wxColour* clr) { + if (label_color != clr) { + label_color = clr; + } + return false; + } + + bool set_undo_tooltip(const wxString* tip) { + if (undo_tooltip != tip) { + undo_tooltip = tip; + return true; + } + return false; + } + + bool set_undo_to_sys_tooltip(const wxString* tip) { + if (undo_to_sys_tooltip != tip) { + undo_to_sys_tooltip = tip; + return true; + } + return false; + } + }; + + UndoValueUI m_undo_ui; + + struct EditValueUI { + // Bitmap and Tooltip text for m_Edit_btn. The wxButton will be updated only if the new wxBitmap pointer differs from the currently rendered one. + const ScalableBitmap* bitmap{ nullptr }; + wxString tooltip { wxEmptyString }; + + bool set_bitmap(const ScalableBitmap* bmp) { + if (bitmap != bmp) { + bitmap = bmp; + return true; + } + return false; + } + + bool set_tooltip(const wxString& tip) { + if (tooltip != tip) { + tooltip = tip; + return true; + } + return false; + } + }; + + EditValueUI m_edit_ui; + +public: + UndoValueUIManager() {} + ~UndoValueUIManager() {} + + bool set_undo_bitmap(const ScalableBitmap* bmp) { return m_undo_ui.set_undo_bitmap(bmp); } + bool set_undo_to_sys_bitmap(const ScalableBitmap* bmp) { return m_undo_ui.set_undo_to_sys_bitmap(bmp); } + bool set_label_colour(const wxColour* clr) { return m_undo_ui.set_label_colour(clr); } + bool set_undo_tooltip(const wxString* tip) { return m_undo_ui.set_undo_tooltip(tip); } + bool set_undo_to_sys_tooltip(const wxString* tip) { return m_undo_ui.set_undo_to_sys_tooltip(tip); } + + bool set_edit_bitmap(const ScalableBitmap* bmp) { return m_edit_ui.set_bitmap(bmp); } + bool set_edit_tooltip(const wxString& tip) { return m_edit_ui.set_tooltip(tip); } + + // ui items used for revert line value + bool has_undo_ui() const { return m_undo_ui.undo_bitmap != nullptr; } + const ScalableBitmap* undo_bitmap() const { return m_undo_ui.undo_bitmap; } + const wxString* undo_tooltip() const { return m_undo_ui.undo_tooltip; } + const ScalableBitmap* undo_to_sys_bitmap() const { return m_undo_ui.undo_to_sys_bitmap; } + const wxString* undo_to_sys_tooltip() const { return m_undo_ui.undo_to_sys_tooltip; } + const wxColour* label_color() const { return m_undo_ui.label_color; } + + // Extentions + + // Search blinker + const bool blink() const { return m_undo_ui.blink; } + bool* get_blink_ptr() { return &m_undo_ui.blink; } + + // Edit field button + bool has_edit_ui() const { return !m_edit_ui.tooltip.IsEmpty(); } + const wxBitmapBundle* edit_bitmap() const { return &m_edit_ui.bitmap->bmp(); } + const wxString* edit_tooltip() const { return &m_edit_ui.tooltip; } +}; + +class Field : public UndoValueUIManager { protected: // factory function to defer and enforce creation of derived type. virtual void PostInitialize(); @@ -139,49 +252,6 @@ class Field { return std::move(p); //!p; } - bool set_undo_bitmap(const ScalableBitmap *bmp) { - if (m_undo_bitmap != bmp) { - m_undo_bitmap = bmp; - return true; - } - return false; - } - - bool set_undo_to_sys_bitmap(const ScalableBitmap *bmp) { - if (m_undo_to_sys_bitmap != bmp) { - m_undo_to_sys_bitmap = bmp; - return true; - } - return false; - } - - bool set_label_colour(const wxColour *clr) { - if (m_label_color != clr) { - m_label_color = clr; - } - return false; - } - - bool set_undo_tooltip(const wxString *tip) { - if (m_undo_tooltip != tip) { - m_undo_tooltip = tip; - return true; - } - return false; - } - - bool set_undo_to_sys_tooltip(const wxString *tip) { - if (m_undo_to_sys_tooltip != tip) { - m_undo_to_sys_tooltip = tip; - return true; - } - return false; - } - - bool* get_blink_ptr() { - return &m_blink; - } - virtual void msw_rescale(); virtual void sys_color_changed(); @@ -193,27 +263,9 @@ class Field { static int def_width_wider() ; static int def_width_thinner() ; - const ScalableBitmap* undo_bitmap() { return m_undo_bitmap; } - const wxString* undo_tooltip() { return m_undo_tooltip; } - const ScalableBitmap* undo_to_sys_bitmap() { return m_undo_to_sys_bitmap; } - const wxString* undo_to_sys_tooltip() { return m_undo_to_sys_tooltip; } - const wxColour* label_color() { return m_label_color; } - const bool blink() { return m_blink; } const bool combine_side_text() { return m_combine_side_text; } // BBS: new param style protected: - // Bitmap and Tooltip text for m_Undo_btn. The wxButton will be updated only if the new wxBitmap pointer differs from the currently rendered one. - const ScalableBitmap* m_undo_bitmap = nullptr; - const wxString* m_undo_tooltip = nullptr; - // Bitmap and Tooltip text for m_Undo_to_sys_btn. The wxButton will be updated only if the new wxBitmap pointer differs from the currently rendered one. - const ScalableBitmap* m_undo_to_sys_bitmap = nullptr; - const wxString* m_undo_to_sys_tooltip = nullptr; - - bool m_blink{ false }; - - // Color for Label. The wxColour will be updated only if the new wxColour pointer differs from the currently rendered one. - const wxColour* m_label_color = nullptr; - // current value boost::any m_value; // last maeningful value diff --git a/src/slic3r/GUI/OG_CustomCtrl.cpp b/src/slic3r/GUI/OG_CustomCtrl.cpp index 26349192d12..68ffe0de896 100644 --- a/src/slic3r/GUI/OG_CustomCtrl.cpp +++ b/src/slic3r/GUI/OG_CustomCtrl.cpp @@ -195,7 +195,7 @@ wxPoint OG_CustomCtrl::get_pos(const Line& line, Field* field_in/* = nullptr*/) if (line.widget) { #ifndef DISABLE_BLINKING - h_pos += blinking_button_width; + h_pos += (line.has_undo_ui() ? 3 : 1) * blinking_button_width; #endif for (auto child : line.widget_sizer->GetChildren()) @@ -761,7 +761,7 @@ void OG_CustomCtrl::CtrlLine::render(wxDC& dc, wxCoord h_pos, wxCoord v_pos) wxColour blink_color = StateColor::darkModeColorFor("#009688"); bool is_url_string = false; if (ctrl->opt_group->label_width != 0 && !label.IsEmpty()) { - const wxColour* text_clr = field ? field->label_color() : og_line.full_Label_color; + const wxColour* text_clr = field ? field->label_color() : og_line.label_color(); for (const Option& opt : option_set) { Field* field = ctrl->opt_group->get_field(opt.opt_id); if (field && field->blink()) { diff --git a/src/slic3r/GUI/OptionsGroup.cpp b/src/slic3r/GUI/OptionsGroup.cpp index 92dca600031..a0e3fa00a9d 100644 --- a/src/slic3r/GUI/OptionsGroup.cpp +++ b/src/slic3r/GUI/OptionsGroup.cpp @@ -210,7 +210,7 @@ void OptionsGroup::append_line(const Line& line) m_options_mode.push_back(option_set[0].opt.mode); } -//BBS: get line for opt_key +/*//BBS: get line for opt_key Line* OptionsGroup::get_line(const std::string& opt_key) { for (auto& l : m_lines) @@ -222,7 +222,7 @@ Line* OptionsGroup::get_line(const std::string& opt_key) } return nullptr; -} +}*/ void OptionsGroup::append_separator() { @@ -678,6 +678,7 @@ void ConfigOptionsGroup::back_to_config_value(const DynamicPrintConfig& config, opt_key == "thumbnails" || opt_key == "bed_custom_texture" || opt_key == "bed_custom_model") { value = get_config_value(config, opt_key); this->change_opt_value(opt_key, value); + OptionsGroup::on_change_OG(opt_key, value); return; } else { auto opt_id = m_opt_map.find(opt_key)->first; diff --git a/src/slic3r/GUI/OptionsGroup.hpp b/src/slic3r/GUI/OptionsGroup.hpp index a758f1652a6..5b54edb92fd 100644 --- a/src/slic3r/GUI/OptionsGroup.hpp +++ b/src/slic3r/GUI/OptionsGroup.hpp @@ -48,7 +48,8 @@ struct Option { using t_option = std::unique_ptr