From 752083cbe68c053d88b90981d79050eae27818f7 Mon Sep 17 00:00:00 2001 From: YuSanka Date: Tue, 7 Apr 2020 12:09:58 +0200 Subject: [PATCH] Implemented blinking icon to highlight a searched field --- src/slic3r/GUI/Field.cpp | 3 +++ src/slic3r/GUI/Field.hpp | 16 ++++++++++++++++ src/slic3r/GUI/OptionsGroup.cpp | 1 + src/slic3r/GUI/OptionsGroup.hpp | 17 ----------------- src/slic3r/GUI/Tab.cpp | 12 +++++++++++- src/slic3r/GUI/Tab.hpp | 28 ++++++++++++++++++++++++++++ 6 files changed, 59 insertions(+), 18 deletions(-) diff --git a/src/slic3r/GUI/Field.cpp b/src/slic3r/GUI/Field.cpp index a1a6583bc..d69fd6c06 100644 --- a/src/slic3r/GUI/Field.cpp +++ b/src/slic3r/GUI/Field.cpp @@ -57,6 +57,9 @@ void Field::PostInitialize() m_Undo_btn->Bind(wxEVT_BUTTON, ([this](wxCommandEvent) { on_back_to_initial_value(); })); m_Undo_to_sys_btn->Bind(wxEVT_BUTTON, ([this](wxCommandEvent) { on_back_to_sys_value(); })); + m_attention_bmp = ScalableBitmap(m_parent, "error_tick_f"); + m_find_image = new wxStaticBitmap(m_parent, wxID_ANY, wxNullBitmap, wxDefaultPosition, m_attention_bmp.bmp().GetSize()); + switch (m_opt.type) { case coPercents: diff --git a/src/slic3r/GUI/Field.hpp b/src/slic3r/GUI/Field.hpp index 7f7ee8ed8..73529cf31 100644 --- a/src/slic3r/GUI/Field.hpp +++ b/src/slic3r/GUI/Field.hpp @@ -191,6 +191,19 @@ public: return false; } + void invalidate_attention_bmp() const { + m_find_image->SetBitmap(wxNullBitmap); + } + + void activate_attention_bmp() const { + m_find_image->SetBitmap(m_attention_bmp.bmp()); + } + + void blink_attention_bmp() const { + bool is_shown = m_find_image->IsShown(); + m_find_image->Show(!is_shown); + } + bool set_label_colour_force(const wxColour *clr) { if (m_Label == nullptr) return false; m_Label->SetForegroundColour(*clr); @@ -240,6 +253,9 @@ protected: const ScalableBitmap* m_undo_to_sys_bitmap = nullptr; const wxString* m_undo_to_sys_tooltip = nullptr; + ScalableBitmap m_attention_bmp; + wxStaticBitmap* m_find_image{ nullptr }; + wxStaticText* m_Label = nullptr; // 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; diff --git a/src/slic3r/GUI/OptionsGroup.cpp b/src/slic3r/GUI/OptionsGroup.cpp index 207d42b5b..ca26dfe80 100644 --- a/src/slic3r/GUI/OptionsGroup.cpp +++ b/src/slic3r/GUI/OptionsGroup.cpp @@ -110,6 +110,7 @@ void OptionsGroup::add_undo_buttuns_to_sizer(wxSizer* sizer, const t_field& fiel sizer->Add(field->m_Undo_to_sys_btn, 0, wxALIGN_CENTER_VERTICAL); sizer->Add(field->m_Undo_btn, 0, wxALIGN_CENTER_VERTICAL); + sizer->Add(field->m_find_image, 0, wxALIGN_CENTER_VERTICAL | wxRIGHT, 2); } void OptionsGroup::append_line(const Line& line, wxStaticText** full_Label/* = nullptr*/) { diff --git a/src/slic3r/GUI/OptionsGroup.hpp b/src/slic3r/GUI/OptionsGroup.hpp index f5b181f60..6c7c8c10d 100644 --- a/src/slic3r/GUI/OptionsGroup.hpp +++ b/src/slic3r/GUI/OptionsGroup.hpp @@ -195,23 +195,6 @@ public: sizer->Add(m_grid_sizer, 0, wxEXPAND | wxALL, wxOSX||!staticbox ? 0: 5); #endif /* __WXGTK__ */ - - - if (stb) - stb->Bind(wxEVT_PAINT, [this](wxPaintEvent& evt) { - evt.Skip(); - const wxSize sz = stb->GetSize(); - wxPaintDC dc(stb); - const wxPen pen = wxPen(wxColour(250, 10, 10), 2, wxPENSTYLE_SOLID); - dc.SetPen(pen); - dc.SetBrush(wxBrush(wxColour(250, 0, 0), wxBRUSHSTYLE_SOLID)); - dc.DrawRectangle(25, 25, sz.x - 25, sz.y - 25); -/* - HDC hdc = GetHdcOf(dc); - RECT dim = { 5, 5, sz.x - 5, sz.y - 5 }; - ::FillRect(hdc, &dim, GetHbrushOf(wxBrush(wxColour( 0, 250,0), wxBRUSHSTYLE_SOLID))); -*/ - }); } wxGridSizer* get_grid_sizer() { return m_grid_sizer; } diff --git a/src/slic3r/GUI/Tab.cpp b/src/slic3r/GUI/Tab.cpp index 17bb68d02..333840986 100644 --- a/src/slic3r/GUI/Tab.cpp +++ b/src/slic3r/GUI/Tab.cpp @@ -69,6 +69,13 @@ Tab::Tab(wxNotebook* parent, const wxString& title, Preset::Type type) : page->layout_valid = false; evt.Skip(); })); + + this->m_highlighting_timer.SetOwner(this, 0); + this->Bind(wxEVT_TIMER, [this](wxTimerEvent&) + { + if (!m_highlighter.blink()) + m_highlighting_timer.Stop(); + }); } void Tab::set_type() @@ -992,8 +999,11 @@ void Tab::activate_option(const std::string& opt_key, const wxString& category) tap_panel->SetSelection(page_id); // focused selected field - if (field) + if (field) { field->getWindow()->SetFocus(); + m_highlighting_timer.Start(500, false); + m_highlighter.init(field); + } } diff --git a/src/slic3r/GUI/Tab.hpp b/src/slic3r/GUI/Tab.hpp index fe683b49f..4a6ab7c19 100644 --- a/src/slic3r/GUI/Tab.hpp +++ b/src/slic3r/GUI/Tab.hpp @@ -224,6 +224,34 @@ protected: bool m_completed { false }; ConfigOptionMode m_mode = comExpert; // to correct first Tab update_visibility() set mode to Expert + wxTimer m_highlighting_timer; + struct { + Field* field {nullptr}; + int blink_counter {0}; + + void init(Field* f) + { + field = f; + field->activate_attention_bmp(); + } + + void invalidate() + { + field->invalidate_attention_bmp(); + field = nullptr; + blink_counter = 0; + } + + bool blink() + { + field->blink_attention_bmp(); + if ((++blink_counter) == 5) + invalidate(); + + return blink_counter != 0; + } + } m_highlighter; + public: PresetBundle* m_preset_bundle; bool m_show_btn_incompatible_presets = false;