Custom control : Implemented blinking icon

This commit is contained in:
YuSanka 2020-10-27 22:19:12 +01:00 committed by Oleksandra Yushchenko
parent 4f5efc99fb
commit 1c22d788aa
7 changed files with 98 additions and 29 deletions

View file

@ -227,6 +227,10 @@ public:
m_side_text = side_text; m_side_text = side_text;
} }
bool* get_blink_ptr() {
return &m_blink;
}
virtual void msw_rescale(bool rescale_sidetext = false); virtual void msw_rescale(bool rescale_sidetext = false);
void sys_color_changed(); void sys_color_changed();
@ -245,6 +249,7 @@ public:
const ScalableBitmap* undo_to_sys_bitmap() { return m_undo_to_sys_bitmap; } 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 wxString* undo_to_sys_tooltip() { return m_undo_to_sys_tooltip; }
const wxColour* label_color() { return m_label_color; } const wxColour* label_color() { return m_label_color; }
const bool blink() { return m_blink; }
protected: protected:
RevertButton* m_Undo_btn = nullptr; RevertButton* m_Undo_btn = nullptr;
@ -256,6 +261,8 @@ protected:
const ScalableBitmap* m_undo_to_sys_bitmap = nullptr; const ScalableBitmap* m_undo_to_sys_bitmap = nullptr;
const wxString* m_undo_to_sys_tooltip = nullptr; const wxString* m_undo_to_sys_tooltip = nullptr;
bool m_blink{ false };
BlinkingBitmap* m_blinking_bmp{ nullptr }; BlinkingBitmap* m_blinking_bmp{ nullptr };
wxStaticText* m_Label = nullptr; wxStaticText* m_Label = nullptr;

View file

@ -426,7 +426,7 @@ void OG_CustomCtrl::CtrlLine::render(wxDC& dc, wxCoord v_pos)
if (draw_just_act_buttons) { if (draw_just_act_buttons) {
if (field) if (field)
draw_act_bmps(dc, wxPoint(0, v_pos), field->undo_to_sys_bitmap()->bmp(), field->undo_bitmap()->bmp()); draw_act_bmps(dc, wxPoint(0, v_pos), field->undo_to_sys_bitmap()->bmp(), field->undo_bitmap()->bmp(), field->blink());
return; return;
} }
@ -445,7 +445,7 @@ void OG_CustomCtrl::CtrlLine::render(wxDC& dc, wxCoord v_pos)
// If there's a widget, build it and set result to the correct position. // If there's a widget, build it and set result to the correct position.
if (og_line.widget != nullptr) { if (og_line.widget != nullptr) {
draw_blinking_bmp(dc, wxPoint(h_pos, v_pos)); draw_blinking_bmp(dc, wxPoint(h_pos, v_pos), og_line.blink);
return; return;
} }
@ -458,7 +458,7 @@ void OG_CustomCtrl::CtrlLine::render(wxDC& dc, wxCoord v_pos)
option_set.front().side_widget == nullptr && og_line.get_extra_widgets().size() == 0) option_set.front().side_widget == nullptr && og_line.get_extra_widgets().size() == 0)
{ {
if (field && field->undo_to_sys_bitmap()) if (field && field->undo_to_sys_bitmap())
draw_act_bmps(dc, wxPoint(h_pos, v_pos), field->undo_to_sys_bitmap()->bmp(), field->undo_bitmap()->bmp()); draw_act_bmps(dc, wxPoint(h_pos, v_pos), field->undo_to_sys_bitmap()->bmp(), field->undo_bitmap()->bmp(), field->blink());
return; return;
} }
@ -477,7 +477,7 @@ void OG_CustomCtrl::CtrlLine::render(wxDC& dc, wxCoord v_pos)
} }
if (field && field->undo_to_sys_bitmap()) { 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(), bmp_rect_id++); h_pos = draw_act_bmps(dc, wxPoint(h_pos, v_pos), field->undo_to_sys_bitmap()->bmp(), field->undo_bitmap()->bmp(), field->blink(), bmp_rect_id++);
if (field->getSizer()) if (field->getSizer())
{ {
auto children = field->getSizer()->GetChildren(); auto children = field->getSizer()->GetChildren();
@ -559,10 +559,9 @@ wxCoord OG_CustomCtrl::CtrlLine::draw_text(wxDC& dc, wxPoint pos, const wxStr
return pos.x + width + ctrl->m_h_gap; return pos.x + width + ctrl->m_h_gap;
} }
wxPoint OG_CustomCtrl::CtrlLine::draw_blinking_bmp(wxDC& dc, wxPoint pos, size_t rect_id) wxPoint OG_CustomCtrl::CtrlLine::draw_blinking_bmp(wxDC& dc, wxPoint pos, bool is_blinking, size_t rect_id)
{ {
// wxBitmap bmp_blinking = create_scaled_bitmap("search_blink", ctrl); wxBitmap bmp_blinking = create_scaled_bitmap(is_blinking ? "search_blink" : "empty", ctrl);
wxBitmap bmp_blinking = create_scaled_bitmap("empty", ctrl);
wxCoord h_pos = pos.x; wxCoord h_pos = pos.x;
wxCoord v_pos = pos.y + lround((height - bmp_blinking.GetHeight()) / 2); wxCoord v_pos = pos.y + lround((height - bmp_blinking.GetHeight()) / 2);
@ -575,9 +574,9 @@ wxPoint OG_CustomCtrl::CtrlLine::draw_blinking_bmp(wxDC& dc, wxPoint pos, size_t
return wxPoint(h_pos, v_pos); return wxPoint(h_pos, v_pos);
} }
wxCoord OG_CustomCtrl::CtrlLine::draw_act_bmps(wxDC& dc, wxPoint pos, const wxBitmap& bmp_undo_to_sys, const wxBitmap& bmp_undo, size_t rect_id) wxCoord OG_CustomCtrl::CtrlLine::draw_act_bmps(wxDC& dc, wxPoint pos, const wxBitmap& bmp_undo_to_sys, const wxBitmap& bmp_undo, bool is_blinking, size_t rect_id)
{ {
pos = draw_blinking_bmp(dc, pos, rect_id); pos = draw_blinking_bmp(dc, pos, is_blinking, rect_id);
wxCoord h_pos = pos.x; wxCoord h_pos = pos.x;
wxCoord v_pos = pos.y; wxCoord v_pos = pos.y;

View file

@ -56,8 +56,8 @@ class OG_CustomCtrl :public wxControl
void render(wxDC& dc, wxCoord v_pos); void render(wxDC& dc, wxCoord v_pos);
wxCoord draw_mode_bmp(wxDC& dc, wxCoord v_pos); wxCoord draw_mode_bmp(wxDC& dc, wxCoord v_pos);
wxCoord draw_text (wxDC& dc, wxPoint pos, const wxString& text, const wxColour* color, int width); wxCoord draw_text (wxDC& dc, wxPoint pos, const wxString& text, const wxColour* color, int width);
wxPoint draw_blinking_bmp(wxDC& dc, wxPoint pos, size_t rect_id = 0); wxPoint draw_blinking_bmp(wxDC& dc, wxPoint pos, bool is_blinking, size_t rect_id = 0);
wxCoord draw_act_bmps(wxDC& dc, wxPoint pos, const wxBitmap& bmp_undo_to_sys, const wxBitmap& bmp_undo, size_t rect_id = 0); wxCoord draw_act_bmps(wxDC& dc, wxPoint pos, const wxBitmap& bmp_undo_to_sys, const wxBitmap& bmp_undo, bool is_blinking, size_t rect_id = 0);
std::vector<wxRect> rects_blinking; std::vector<wxRect> rects_blinking;
std::vector<wxRect> rects_undo_icon; std::vector<wxRect> rects_undo_icon;

View file

@ -923,6 +923,21 @@ Field* ConfigOptionsGroup::get_fieldc(const t_config_option_key& opt_key, int op
return opt_id.empty() ? nullptr : get_field(opt_id); return opt_id.empty() ? nullptr : get_field(opt_id);
} }
std::pair<OG_CustomCtrl*, bool*> ConfigOptionsGroup::get_custom_ctrl_with_blinking_ptr(const t_config_option_key& opt_key, int opt_index/* = -1*/)
{
Field* field = get_fieldc(opt_key, opt_index);
if (field)
return {custom_ctrl, field->get_blink_ptr()};
for (Line& line : m_lines)
for (const Option& opt : line.get_options())
if (opt.opt_id == opt_key && line.widget)
return { custom_ctrl, line.get_blink_ptr() };
return { nullptr, nullptr };
}
// Change an option on m_config, possibly call ModelConfig::touch(). // Change an option on m_config, possibly call ModelConfig::touch().
void ConfigOptionsGroup::change_opt_value(const t_config_option_key& opt_key, const boost::any& value, int opt_index /*= 0*/) void ConfigOptionsGroup::change_opt_value(const t_config_option_key& opt_key, const boost::any& value, int opt_index /*= 0*/)

View file

@ -54,6 +54,7 @@ public:
size_t full_width {0}; size_t full_width {0};
wxStaticText** full_Label {nullptr}; wxStaticText** full_Label {nullptr};
wxColour* full_Label_color {nullptr}; wxColour* full_Label_color {nullptr};
bool blink {false};
widget_t widget {nullptr}; widget_t widget {nullptr};
std::function<wxWindow*(wxWindow*)> near_label_widget{ nullptr }; std::function<wxWindow*(wxWindow*)> near_label_widget{ nullptr };
wxWindow* near_label_widget_win {nullptr}; wxWindow* near_label_widget_win {nullptr};
@ -71,6 +72,7 @@ public:
const std::vector<widget_t>& get_extra_widgets() const {return m_extra_widgets;} const std::vector<widget_t>& get_extra_widgets() const {return m_extra_widgets;}
const std::vector<Option>& get_options() const { return m_options; } const std::vector<Option>& get_options() const { return m_options; }
bool* get_blink_ptr() { return &blink; }
private: private:
std::vector<Option> m_options;//! {std::vector<Option>()}; std::vector<Option> m_options;//! {std::vector<Option>()};
@ -290,6 +292,7 @@ public:
// return option value from config // return option value from config
boost::any get_config_value(const DynamicPrintConfig& config, const std::string& opt_key, int opt_index = -1); boost::any get_config_value(const DynamicPrintConfig& config, const std::string& opt_key, int opt_index = -1);
Field* get_fieldc(const t_config_option_key& opt_key, int opt_index); Field* get_fieldc(const t_config_option_key& opt_key, int opt_index);
std::pair<OG_CustomCtrl*, bool*> get_custom_ctrl_with_blinking_ptr(const t_config_option_key& opt_key, int opt_index/* = -1*/);
private: private:
// Reference to libslic3r config or ModelConfig::get(), non-owning pointer. // Reference to libslic3r config or ModelConfig::get(), non-owning pointer.

View file

@ -12,6 +12,7 @@
#include "WipeTowerDialog.hpp" #include "WipeTowerDialog.hpp"
#include "ButtonsDescription.hpp" #include "ButtonsDescription.hpp"
#include "Search.hpp" #include "Search.hpp"
#include "OG_CustomCtrl.hpp"
#include <wx/app.h> #include <wx/app.h>
#include <wx/button.h> #include <wx/button.h>
@ -54,7 +55,7 @@ void Tab::Highlighter::set_timer_owner(wxEvtHandler* owner, int timerid/* = wxID
{ {
timer.SetOwner(owner, timerid); timer.SetOwner(owner, timerid);
} }
/*
void Tab::Highlighter::init(BlinkingBitmap* bmp) void Tab::Highlighter::init(BlinkingBitmap* bmp)
{ {
if (timer.IsRunning()) if (timer.IsRunning())
@ -67,24 +68,53 @@ void Tab::Highlighter::init(BlinkingBitmap* bmp)
bbmp = bmp; bbmp = bmp;
bbmp->activate(); bbmp->activate();
} }
*/
void Tab::Highlighter::init(std::pair<OG_CustomCtrl*, bool*> params)
{
if (timer.IsRunning())
invalidate();
if (!params.first || !params.second)
return;
timer.Start(300, false);
custom_ctrl = params.first;
blink_ptr = params.second;
*blink_ptr = true;
custom_ctrl->Refresh();
}
void Tab::Highlighter::invalidate() void Tab::Highlighter::invalidate()
{ {
timer.Stop(); timer.Stop();
if (bbmp) { //if (bbmp) {
bbmp->invalidate(); // bbmp->invalidate();
bbmp = nullptr; // bbmp = nullptr;
//}
if (custom_ctrl && blink_ptr) {
*blink_ptr = false;
custom_ctrl->Refresh();
blink_ptr = nullptr;
custom_ctrl = nullptr;
} }
blink_counter = 0; blink_counter = 0;
} }
void Tab::Highlighter::blink() void Tab::Highlighter::blink()
{ {
if (!bbmp) //if (!bbmp)
if (custom_ctrl && blink_ptr) {
*blink_ptr = !*blink_ptr;
custom_ctrl->Refresh();
}
else
return; return;
bbmp->blink(); // bbmp->blink();
if ((++blink_counter) == 11) if ((++blink_counter) == 11)
invalidate(); invalidate();
} }
@ -1014,14 +1044,21 @@ void Tab::sys_color_changed()
Field* Tab::get_field(const t_config_option_key& opt_key, int opt_index/* = -1*/) const Field* Tab::get_field(const t_config_option_key& opt_key, int opt_index/* = -1*/) const
{ {
return m_active_page ? m_active_page->get_field(opt_key, opt_index) : nullptr; return m_active_page ? m_active_page->get_field(opt_key, opt_index) : nullptr;
Field* field = nullptr;
for (auto page : m_pages) {
field = page->get_field(opt_key, opt_index);
if (field != nullptr)
return field;
} }
return field;
std::pair<OG_CustomCtrl*, bool*> Tab::get_custom_ctrl_with_blinking_ptr(const t_config_option_key& opt_key, int opt_index/* = -1*/)
{
if (!m_active_page)
return {nullptr, nullptr};
std::pair<OG_CustomCtrl*, bool*> ret = {nullptr, nullptr};
for (auto opt_group : m_active_page->m_optgroups) {
ret = opt_group->get_custom_ctrl_with_blinking_ptr(opt_key, opt_index);
if (ret.first && ret.second)
break;
}
return ret;
} }
Field* Tab::get_field(const t_config_option_key& opt_key, Page** selected_page, int opt_index/* = -1*/) Field* Tab::get_field(const t_config_option_key& opt_key, Page** selected_page, int opt_index/* = -1*/)
@ -1165,7 +1202,8 @@ void Tab::activate_option(const std::string& opt_key, const wxString& category)
// focused selected field // focused selected field
if (field) { if (field) {
field->getWindow()->SetFocus(); field->getWindow()->SetFocus();
m_highlighter.init(field->blinking_bitmap()); // m_highlighter.init()
// m_highlighter.init(field->blinking_bitmap());
} }
else if (category == "Single extruder MM setup") else if (category == "Single extruder MM setup")
{ {
@ -1176,12 +1214,13 @@ void Tab::activate_option(const std::string& opt_key, const wxString& category)
field = get_field("single_extruder_multi_material"); field = get_field("single_extruder_multi_material");
if (field) { if (field) {
field->getWindow()->SetFocus(); field->getWindow()->SetFocus();
m_highlighter.init(field->blinking_bitmap()); // m_highlighter.init(field->blinking_bitmap());
} }
} }
else //else
m_highlighter.init(m_blinking_ikons[opt_key]); // m_highlighter.init(m_blinking_ikons[opt_key]);
m_highlighter.init(get_custom_ctrl_with_blinking_ptr(opt_key));
} }
void Tab::apply_searcher() void Tab::apply_searcher()

View file

@ -40,6 +40,7 @@ namespace Slic3r {
namespace GUI { namespace GUI {
class TabPresetComboBox; class TabPresetComboBox;
class OG_CustomCtrl;
// Single Tab page containing a{ vsizer } of{ optgroups } // Single Tab page containing a{ vsizer } of{ optgroups }
// package Slic3r::GUI::Tab::Page; // package Slic3r::GUI::Tab::Page;
@ -226,13 +227,16 @@ protected:
struct Highlighter struct Highlighter
{ {
void set_timer_owner(wxEvtHandler* owner, int timerid = wxID_ANY); void set_timer_owner(wxEvtHandler* owner, int timerid = wxID_ANY);
void init(BlinkingBitmap* bmp); // void init(BlinkingBitmap* bmp);
void init(std::pair<OG_CustomCtrl*, bool*>);
void blink(); void blink();
void invalidate(); void invalidate();
private: private:
BlinkingBitmap* bbmp {nullptr}; OG_CustomCtrl* custom_ctrl {nullptr};
bool* blink_ptr {nullptr};
// BlinkingBitmap* bbmp {nullptr};
int blink_counter {0}; int blink_counter {0};
wxTimer timer; wxTimer timer;
} }
@ -338,6 +342,8 @@ public:
virtual void msw_rescale(); virtual void msw_rescale();
virtual void sys_color_changed(); virtual void sys_color_changed();
Field* get_field(const t_config_option_key& opt_key, int opt_index = -1) const; Field* get_field(const t_config_option_key& opt_key, int opt_index = -1) const;
std::pair<OG_CustomCtrl*, bool*> get_custom_ctrl_with_blinking_ptr(const t_config_option_key& opt_key, int opt_index = -1);
Field* get_field(const t_config_option_key &opt_key, Page** selected_page, int opt_index = -1); Field* get_field(const t_config_option_key &opt_key, Page** selected_page, int opt_index = -1);
void toggle_option(const std::string& opt_key, bool toggle, int opt_index = -1); void toggle_option(const std::string& opt_key, bool toggle, int opt_index = -1);
wxSizer* description_line_widget(wxWindow* parent, ogStaticText** StaticText, wxString text = wxEmptyString); wxSizer* description_line_widget(wxWindow* parent, ogStaticText** StaticText, wxString text = wxEmptyString);