Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/prusa3d/PrusaSlicer.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYuSanka <yusanka@gmail.com>2021-12-22 14:30:19 +0300
committerYuSanka <yusanka@gmail.com>2021-12-22 16:38:50 +0300
commitc76778182724dd6f0171cabc115f2c9939860cc4 (patch)
treec972b60c30d914e2dc500d42832922f00efe16d7 /src/slic3r/GUI
parentf2aeca3a716d8d3d4233be321cddcf463c1bf21f (diff)
Code refactoring for Highlighter class
Diffstat (limited to 'src/slic3r/GUI')
-rw-r--r--src/slic3r/GUI/Preferences.cpp3
-rw-r--r--src/slic3r/GUI/Preferences.hpp5
-rw-r--r--src/slic3r/GUI/Tab.cpp4
-rw-r--r--src/slic3r/GUI/Tab.hpp2
-rw-r--r--src/slic3r/GUI/wxExtensions.cpp60
-rw-r--r--src/slic3r/GUI/wxExtensions.hpp51
6 files changed, 87 insertions, 38 deletions
diff --git a/src/slic3r/GUI/Preferences.cpp b/src/slic3r/GUI/Preferences.cpp
index 9e4753e12..fa1e84ea6 100644
--- a/src/slic3r/GUI/Preferences.cpp
+++ b/src/slic3r/GUI/Preferences.cpp
@@ -52,9 +52,6 @@ PreferencesDialog::PreferencesDialog(wxWindow* parent) :
build();
m_highlighter.set_timer_owner(this, 0);
- this->Bind(wxEVT_TIMER, [this](wxTimerEvent&) {
- m_highlighter.blink();
- });
}
void PreferencesDialog::show(const std::string& highlight_opt_key /*= std::string()*/, const std::string& tab_name/*= std::string()*/)
diff --git a/src/slic3r/GUI/Preferences.hpp b/src/slic3r/GUI/Preferences.hpp
index ef13ee599..f8b1d1237 100644
--- a/src/slic3r/GUI/Preferences.hpp
+++ b/src/slic3r/GUI/Preferences.hpp
@@ -71,9 +71,8 @@ protected:
void init_highlighter(const t_config_option_key& opt_key);
std::vector<ConfigOptionsGroup*> optgroups();
- Highlighter m_highlighter;
-
- std::map<std::string, BlinkingBitmap*> m_blinkers;
+ HighlighterForWx m_highlighter;
+ std::map<std::string, BlinkingBitmap*> m_blinkers;
};
} // GUI
diff --git a/src/slic3r/GUI/Tab.cpp b/src/slic3r/GUI/Tab.cpp
index 9fecd8bbb..ea12ababb 100644
--- a/src/slic3r/GUI/Tab.cpp
+++ b/src/slic3r/GUI/Tab.cpp
@@ -85,10 +85,6 @@ Tab::Tab(wxBookCtrlBase* parent, const wxString& title, Preset::Type type) :
}));
m_highlighter.set_timer_owner(this, 0);
- this->Bind(wxEVT_TIMER, [this](wxTimerEvent&)
- {
- m_highlighter.blink();
- });
}
void Tab::set_type()
diff --git a/src/slic3r/GUI/Tab.hpp b/src/slic3r/GUI/Tab.hpp
index fe2abb9d5..45da27bf6 100644
--- a/src/slic3r/GUI/Tab.hpp
+++ b/src/slic3r/GUI/Tab.hpp
@@ -218,7 +218,7 @@ protected:
bool m_completed { false };
ConfigOptionMode m_mode = comExpert; // to correct first Tab update_visibility() set mode to Expert
- Highlighter m_highlighter;
+ HighlighterForWx m_highlighter;
DynamicPrintConfig m_cache_config;
diff --git a/src/slic3r/GUI/wxExtensions.cpp b/src/slic3r/GUI/wxExtensions.cpp
index 93745b11e..9b70657e1 100644
--- a/src/slic3r/GUI/wxExtensions.cpp
+++ b/src/slic3r/GUI/wxExtensions.cpp
@@ -983,19 +983,48 @@ void BlinkingBitmap::blink()
namespace Slic3r {
namespace GUI {
-void Highlighter::set_timer_owner(wxEvtHandler* owner, int timerid/* = wxID_ANY*/)
+void Highlighter::set_timer_owner(wxWindow* owner, int timerid/* = wxID_ANY*/)
{
m_timer.SetOwner(owner, timerid);
+ bind_timer(owner);
}
-void Highlighter::init(std::pair<OG_CustomCtrl*, bool*> params)
+bool Highlighter::init(bool input_failed)
+{
+ if (input_failed)
+ return false;
+
+ m_timer.Start(300, false);
+ return true;
+}
+void Highlighter::invalidate()
{
if (m_timer.IsRunning())
+ m_timer.Stop();
+ m_blink_counter = 0;
+}
+
+void Highlighter::blink()
+{
+ if ((++m_blink_counter) == 11)
invalidate();
- if (!params.first || !params.second)
- return;
+}
- m_timer.Start(300, false);
+// HighlighterForWx
+
+void HighlighterForWx::bind_timer(wxWindow* owner)
+{
+ owner->Bind(wxEVT_TIMER, [this](wxTimerEvent&) {
+ blink();
+ });
+}
+
+// using OG_CustomCtrl where arrow will be rendered and flag indicated "show/hide" state of this arrow
+void HighlighterForWx::init(std::pair<OG_CustomCtrl*, bool*> params)
+{
+ invalidate();
+ if (!Highlighter::init(!params.first && !params.second))
+ return;
m_custom_ctrl = params.first;
m_show_blink_ptr = params.second;
@@ -1004,22 +1033,20 @@ void Highlighter::init(std::pair<OG_CustomCtrl*, bool*> params)
m_custom_ctrl->Refresh();
}
-void Highlighter::init(BlinkingBitmap* blinking_bmp)
+// - using a BlinkingBitmap. Change state of this bitmap
+void HighlighterForWx::init(BlinkingBitmap* blinking_bmp)
{
- if (m_timer.IsRunning())
- invalidate();
- if (!blinking_bmp)
+ invalidate();
+ if (!Highlighter::init(!blinking_bmp))
return;
- m_timer.Start(300, false);
-
m_blinking_bitmap = blinking_bmp;
m_blinking_bitmap->activate();
}
-void Highlighter::invalidate()
+void HighlighterForWx::invalidate()
{
- m_timer.Stop();
+ Highlighter::invalidate();
if (m_custom_ctrl && m_show_blink_ptr) {
*m_show_blink_ptr = false;
@@ -1031,11 +1058,9 @@ void Highlighter::invalidate()
m_blinking_bitmap->invalidate();
m_blinking_bitmap = nullptr;
}
-
- m_blink_counter = 0;
}
-void Highlighter::blink()
+void HighlighterForWx::blink()
{
if (m_custom_ctrl && m_show_blink_ptr) {
*m_show_blink_ptr = !*m_show_blink_ptr;
@@ -1046,8 +1071,7 @@ void Highlighter::blink()
else
return;
- if ((++m_blink_counter) == 11)
- invalidate();
+ Highlighter::blink();
}
}// GUI
diff --git a/src/slic3r/GUI/wxExtensions.hpp b/src/slic3r/GUI/wxExtensions.hpp
index 5478c244e..7e613cff9 100644
--- a/src/slic3r/GUI/wxExtensions.hpp
+++ b/src/slic3r/GUI/wxExtensions.hpp
@@ -382,26 +382,59 @@ namespace Slic3r {
namespace GUI {
class OG_CustomCtrl;
+
+// Highlighter is used as an instrument to put attention to some UI control
+
class Highlighter
{
- OG_CustomCtrl* m_custom_ctrl{ nullptr };
- bool* m_show_blink_ptr{ nullptr };
- BlinkingBitmap* m_blinking_bitmap{ nullptr };
-
- int m_blink_counter{ 0 };
+ int m_blink_counter { 0 };
wxTimer m_timer;
public:
- void set_timer_owner(wxEvtHandler* owner, int timerid = wxID_ANY);
- void init(std::pair<OG_CustomCtrl*, bool*>);
+ Highlighter() {}
+ ~Highlighter() {}
+
+ void set_timer_owner(wxWindow* owner, int timerid = wxID_ANY);
+ virtual void bind_timer(wxWindow* owner) = 0;
+
+ bool init(bool input_failed);
+ void blink();
+ void invalidate();
+};
+
+class HighlighterForWx : public Highlighter
+{
+// There are 2 possible cases to use HighlighterForWx:
+// - using a BlinkingBitmap. Change state of this bitmap
+ BlinkingBitmap* m_blinking_bitmap { nullptr };
+// - using OG_CustomCtrl where arrow will be rendered and flag indicated "show/hide" state of this arrow
+ OG_CustomCtrl* m_custom_ctrl { nullptr };
+ bool* m_show_blink_ptr { nullptr };
+
+public:
+ HighlighterForWx() {}
+ ~HighlighterForWx() {}
+
+ void bind_timer(wxWindow* owner) override;
void init(BlinkingBitmap* blinking_bitmap);
+ void init(std::pair<OG_CustomCtrl*, bool*>);
void blink();
void invalidate();
};
+/*
+class HighlighterForImGUI : public Highlighter
+{
+
+public:
+ HighlighterForImGUI() {}
+ ~HighlighterForImGUI() {}
+ void init();
+ void blink();
+ void invalidate();
+};
+*/
} // GUI
} // Slic3r
-
-
#endif // slic3r_GUI_wxExtensions_hpp_