Preferences Highlighter

This commit is contained in:
David Kocik 2021-10-13 16:45:05 +02:00
parent aecd7e2b93
commit ffc29a2536
6 changed files with 92 additions and 6 deletions

View File

@ -2020,14 +2020,14 @@ void GUI_App::add_config_menu(wxMenuBar *menu)
menu->Append(local_menu, _L("&Configuration"));
}
void GUI_App::open_preferences(size_t open_on_tab)
void GUI_App::open_preferences(size_t open_on_tab, const std::string& highlight_option)
{
bool app_layout_changed = false;
{
// the dialog needs to be destroyed before the call to recreate_GUI()
// or sometimes the application crashes into wxDialogBase() destructor
// so we put it into an inner scope
PreferencesDialog dlg(mainframe, open_on_tab);
PreferencesDialog dlg(mainframe, open_on_tab, highlight_option);
dlg.ShowModal();
app_layout_changed = dlg.settings_layout_changed();
#if ENABLE_GCODE_LINES_ID_IN_H_SLIDER

View File

@ -259,7 +259,7 @@ public:
wxString current_language_code_safe() const;
bool is_localized() const { return m_wxLocale->GetLocale() != "English"; }
void open_preferences(size_t open_on_tab = 0);
void open_preferences(size_t open_on_tab = 0, const std::string& highlight_option = std::string());
virtual bool OnExceptionInMainLoop() override;
// Calls wxLaunchDefaultBrowser if user confirms in dialog.

View File

@ -919,7 +919,7 @@ void NotificationManager::HintNotification::render_preferences_button(ImGuiWrapp
}
if (imgui.button(button_text.c_str(), button_size.x, button_size.y))
{
wxGetApp().open_preferences(2);
wxGetApp().open_preferences(2, "show_hints");
}
ImGui::PopStyleColor(5);

View File

@ -597,6 +597,8 @@ void OG_CustomCtrl::CtrlLine::render(wxDC& dc, wxCoord v_pos)
{
if (field && field->undo_to_sys_bitmap())
h_pos = draw_act_bmps(dc, wxPoint(h_pos, v_pos), field->undo_to_sys_bitmap()->bmp(), field->undo_bitmap()->bmp(), field->blink()) + ctrl->m_h_gap;
else if (field && !field->undo_to_sys_bitmap() && field->blink())
draw_blinking_bmp(dc, wxPoint(h_pos, v_pos), field->blink());
// update width for full_width fields
if (option_set.front().opt.full_width && field->getWindow())
field->getWindow()->SetSize(ctrl->GetSize().x - h_pos, -1);

View File

@ -43,7 +43,7 @@ namespace Slic3r {
namespace GUI {
PreferencesDialog::PreferencesDialog(wxWindow* parent, int selected_tab) :
PreferencesDialog::PreferencesDialog(wxWindow* parent, int selected_tab, const std::string& highlight_opt_key) :
DPIDialog(parent, wxID_ANY, _L("Preferences"), wxDefaultPosition,
wxDefaultSize, wxDEFAULT_DIALOG_STYLE)
{
@ -51,6 +51,8 @@ PreferencesDialog::PreferencesDialog(wxWindow* parent, int selected_tab) :
isOSX = true;
#endif
build(selected_tab);
if (!highlight_opt_key.empty())
init_highlighter(highlight_opt_key);
}
static std::shared_ptr<ConfigOptionsGroup>create_options_tab(const wxString& title, wxBookCtrlBase* tabs)
@ -755,6 +757,71 @@ void PreferencesDialog::create_settings_text_color_widget()
m_optgroup_gui->sizer->Add(sizer, 0, wxEXPAND | wxTOP, em_unit());
}
void PreferencesDialog::init_highlighter(const t_config_option_key& opt_key)
{
m_highlighter.set_timer_owner(this, 0);
this->Bind(wxEVT_TIMER, [this](wxTimerEvent&)
{
m_highlighter.blink();
});
std::pair<OG_CustomCtrl*, bool*> ctrl = { nullptr, nullptr };
for (auto opt_group : { m_optgroup_general, m_optgroup_camera, m_optgroup_gui }) {
ctrl = opt_group->get_custom_ctrl_with_blinking_ptr(opt_key, -1);
if (ctrl.first && ctrl.second) {
m_highlighter.init(ctrl);
break;
}
}
}
void PreferencesDialog::PreferencesHighlighter::set_timer_owner(wxEvtHandler* owner, int timerid/* = wxID_ANY*/)
{
m_timer.SetOwner(owner, timerid);
}
void PreferencesDialog::PreferencesHighlighter::init(std::pair<OG_CustomCtrl*, bool*> params)
{
if (m_timer.IsRunning())
invalidate();
if (!params.first || !params.second)
return;
m_timer.Start(300, false);
m_custom_ctrl = params.first;
m_show_blink_ptr = params.second;
*m_show_blink_ptr = true;
m_custom_ctrl->Refresh();
}
void PreferencesDialog::PreferencesHighlighter::invalidate()
{
m_timer.Stop();
if (m_custom_ctrl && m_show_blink_ptr) {
*m_show_blink_ptr = false;
m_custom_ctrl->Refresh();
m_show_blink_ptr = nullptr;
m_custom_ctrl = nullptr;
}
m_blink_counter = 0;
}
void PreferencesDialog::PreferencesHighlighter::blink()
{
if (m_custom_ctrl && m_show_blink_ptr) {
*m_show_blink_ptr = !*m_show_blink_ptr;
m_custom_ctrl->Refresh();
}
else
return;
if ((++m_blink_counter) == 11)
invalidate();
}
} // GUI
} // Slic3r

View File

@ -20,6 +20,7 @@ namespace Slic3r {
namespace GUI {
class ConfigOptionsGroup;
class OG_CustomCtrl;
class PreferencesDialog : public DPIDialog
{
@ -39,7 +40,7 @@ class PreferencesDialog : public DPIDialog
bool m_recreate_GUI{false};
public:
explicit PreferencesDialog(wxWindow* parent, int selected_tab = 0);
explicit PreferencesDialog(wxWindow* parent, int selected_tab = 0, const std::string& highlight_opt_key = std::string());
~PreferencesDialog() = default;
bool settings_layout_changed() const { return m_settings_layout_changed; }
@ -55,6 +56,22 @@ protected:
void create_icon_size_slider();
void create_settings_mode_widget();
void create_settings_text_color_widget();
void init_highlighter(const t_config_option_key& opt_key);
struct PreferencesHighlighter
{
void set_timer_owner(wxEvtHandler* owner, int timerid = wxID_ANY);
void init(std::pair<OG_CustomCtrl*, bool*>);
void blink();
void invalidate();
private:
OG_CustomCtrl* m_custom_ctrl{ nullptr };
bool* m_show_blink_ptr{ nullptr };
int m_blink_counter{ 0 };
wxTimer m_timer;
}
m_highlighter;
};
} // GUI