NEW:add "Fade out" effect for BaseTransparentDPIFrame
jira: none Change-Id: Ied2fd3a07c213c3518183865169728a87a7d5b1a
This commit is contained in:
parent
dd15d0772f
commit
c5406570bc
|
@ -21,14 +21,14 @@ using namespace Slic3r;
|
|||
using namespace Slic3r::GUI;
|
||||
|
||||
namespace Slic3r { namespace GUI {
|
||||
#define ANIMATION_REFRESH_INTERVAL 15
|
||||
#define ANIMATION_REFRESH_INTERVAL 20
|
||||
BaseTransparentDPIFrame::BaseTransparentDPIFrame(
|
||||
wxWindow *parent, int win_width, wxPoint dialog_pos, int ok_button_width, wxString win_text, wxString ok_text, wxString cancel_text, DisappearanceMode disappearance_mode)
|
||||
: DPIFrame(static_cast<wxWindow *>(wxGetApp().mainframe), wxID_ANY, "", wxDefaultPosition, wxDefaultSize, !wxCAPTION | !wxCLOSE_BOX | wxBORDER_NONE)
|
||||
, m_timed_disappearance_mode(disappearance_mode)
|
||||
{
|
||||
// SetBackgroundStyle(wxBackgroundStyle::wxBG_STYLE_TRANSPARENT);
|
||||
SetTransparent(220);
|
||||
SetTransparent(m_init_transparent);
|
||||
SetBackgroundColour(wxColour(23, 25, 22, 128));
|
||||
SetMinSize(wxSize(FromDIP(win_width), -1));
|
||||
SetMaxSize(wxSize(FromDIP(win_width), -1));
|
||||
|
@ -87,7 +87,9 @@ BaseTransparentDPIFrame::BaseTransparentDPIFrame(
|
|||
|
||||
m_sizer_main->Add(bSizer_button, 1, wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM, FromDIP(20));
|
||||
|
||||
Bind(wxEVT_CLOSE_WINDOW, [this](auto &e) { this->on_hide(); });
|
||||
Bind(wxEVT_CLOSE_WINDOW, [this](auto &e) {
|
||||
on_hide();
|
||||
});
|
||||
SetSizer(m_sizer_main);
|
||||
Layout();
|
||||
Fit();
|
||||
|
@ -96,11 +98,17 @@ BaseTransparentDPIFrame::BaseTransparentDPIFrame(
|
|||
init_timer();
|
||||
Bind(wxEVT_TIMER, &BaseTransparentDPIFrame::on_timer, this);
|
||||
Bind(wxEVT_ENTER_WINDOW, [this](auto &e) {
|
||||
clear_timer_count();
|
||||
m_refresh_timer->Stop();
|
||||
if (m_enter_window_valid) {
|
||||
clear_timer_count();
|
||||
m_display_stage = 0;
|
||||
m_refresh_timer->Stop();
|
||||
SetTransparent(m_init_transparent);
|
||||
}
|
||||
});
|
||||
Bind(wxEVT_LEAVE_WINDOW, [this](auto &e) {
|
||||
m_refresh_timer->Start(ANIMATION_REFRESH_INTERVAL);
|
||||
if (m_enter_window_valid) {
|
||||
m_refresh_timer->Start(ANIMATION_REFRESH_INTERVAL);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -137,13 +145,17 @@ void BaseTransparentDPIFrame::on_show() {
|
|||
|
||||
void BaseTransparentDPIFrame::on_hide()
|
||||
{
|
||||
this->Hide();
|
||||
if (m_refresh_timer) {
|
||||
m_refresh_timer->Stop();
|
||||
}
|
||||
Hide();
|
||||
if (wxGetApp().mainframe != nullptr) {
|
||||
wxGetApp().mainframe->Show();
|
||||
wxGetApp().mainframe->Raise();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void BaseTransparentDPIFrame::clear_timer_count() {
|
||||
m_timer_count = 0;
|
||||
}
|
||||
|
@ -154,17 +166,115 @@ void BaseTransparentDPIFrame::init_timer()
|
|||
m_refresh_timer->SetOwner(this);
|
||||
}
|
||||
|
||||
void BaseTransparentDPIFrame::on_timer(wxTimerEvent &event) {
|
||||
m_timer_count++;
|
||||
if (m_timed_disappearance_mode == DisappearanceMode::TimedDisappearance) {
|
||||
void BaseTransparentDPIFrame::calc_step_transparent() {
|
||||
m_max_size = GetSize();
|
||||
m_step_size.x = GetSize().x / m_time_gradual_and_scale;
|
||||
m_step_size.y = GetSize().y / m_time_gradual_and_scale;
|
||||
m_step_transparent = m_init_transparent / m_time_gradual_and_scale;
|
||||
}
|
||||
|
||||
void BaseTransparentDPIFrame::on_close() {
|
||||
Destroy();
|
||||
}
|
||||
|
||||
void BaseTransparentDPIFrame::on_timer(wxTimerEvent &event)
|
||||
{
|
||||
if (m_timed_disappearance_mode == DisappearanceMode::TimedDisappearance && m_display_stage == 0) {
|
||||
auto cur_time = ANIMATION_REFRESH_INTERVAL * m_timer_count;
|
||||
if (cur_time > m_disappearance_second) {
|
||||
start_gradual_disappearance();
|
||||
m_display_stage++;
|
||||
}
|
||||
}
|
||||
if (m_display_stage == 1) {
|
||||
if (m_move_to_target_gradual_disappearance) {
|
||||
begin_move_to_target_and_gradual_disappearance();
|
||||
}
|
||||
else {
|
||||
begin_gradual_disappearance();
|
||||
}
|
||||
}
|
||||
m_timer_count++;
|
||||
}
|
||||
|
||||
void BaseTransparentDPIFrame::call_start_gradual_disappearance()//for ok or cancel button
|
||||
{
|
||||
m_enter_window_valid = false;
|
||||
m_display_stage = 1;
|
||||
m_refresh_timer->Start(ANIMATION_REFRESH_INTERVAL);
|
||||
start_gradual_disappearance();
|
||||
}
|
||||
|
||||
void BaseTransparentDPIFrame::start_gradual_disappearance()
|
||||
{
|
||||
clear_timer_count();
|
||||
//hide_all();
|
||||
calc_step_transparent();
|
||||
}
|
||||
void BaseTransparentDPIFrame::set_target_pos_and_gradual_disappearance(wxPoint pos)
|
||||
{
|
||||
m_move_to_target_gradual_disappearance = true;
|
||||
m_target_pos = pos;
|
||||
m_start_pos = GetScreenPosition();
|
||||
m_step_pos.x = (m_target_pos.x - m_start_pos.x) / m_time_move;
|
||||
m_step_pos.y = (m_target_pos.y - m_start_pos.y) / m_time_move;
|
||||
}
|
||||
|
||||
void BaseTransparentDPIFrame::begin_gradual_disappearance()
|
||||
{
|
||||
if (m_timer_count <= m_time_gradual_and_scale - 1) {
|
||||
auto transparent = m_init_transparent - m_timer_count * m_step_transparent;
|
||||
SetTransparent(transparent < 0 ? 0 : transparent);
|
||||
} else {
|
||||
on_hide();
|
||||
return;
|
||||
}
|
||||
m_timer_count++;
|
||||
}
|
||||
|
||||
void BaseTransparentDPIFrame::begin_move_to_target_and_gradual_disappearance()
|
||||
{
|
||||
if (m_timer_count <= m_time_move) {
|
||||
if (m_timer_count <= m_time_move - 1) {
|
||||
auto pos = wxPoint(m_start_pos.x + m_timer_count * m_step_pos.x, m_start_pos.y + m_timer_count * m_step_pos.y);
|
||||
SetPosition(pos);
|
||||
} else {
|
||||
SetPosition(m_target_pos);
|
||||
}
|
||||
Refresh();
|
||||
} else {
|
||||
SetPosition(m_target_pos);
|
||||
if (m_timer_count <= m_time_move + m_time_gradual_and_scale - 1) {
|
||||
auto size = wxSize(m_max_size.x - m_timer_count * m_step_size.x, m_max_size.y - m_timer_count * m_step_size.y);
|
||||
SetSize(size);
|
||||
SetTransparent(m_init_transparent - m_timer_count * m_step_transparent);
|
||||
} else {
|
||||
on_hide();
|
||||
return;
|
||||
}
|
||||
}
|
||||
m_timer_count++;
|
||||
}
|
||||
|
||||
void BaseTransparentDPIFrame::show_sizer(wxSizer *sizer, bool show)
|
||||
{
|
||||
wxSizerItemList items = sizer->GetChildren();
|
||||
for (wxSizerItemList::iterator it = items.begin(); it != items.end(); ++it) {
|
||||
wxSizerItem *item = *it;
|
||||
if (wxWindow *window = item->GetWindow()) {
|
||||
window->Show(show);
|
||||
}
|
||||
if (wxSizer *son_sizer = item->GetSizer()) {
|
||||
show_sizer(son_sizer, show);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void BaseTransparentDPIFrame::deal_ok(){}
|
||||
void BaseTransparentDPIFrame::hide_all() {
|
||||
show_sizer(m_sizer_main, false);
|
||||
}
|
||||
|
||||
void BaseTransparentDPIFrame::deal_ok() {}
|
||||
|
||||
void BaseTransparentDPIFrame::deal_cancel(){}
|
||||
|
||||
|
|
|
@ -16,8 +16,7 @@ class BaseTransparentDPIFrame : public Slic3r::GUI::DPIFrame
|
|||
public:
|
||||
enum DisappearanceMode {
|
||||
None,
|
||||
TimedDisappearance,//defalut 7 second
|
||||
QuickDisappearance
|
||||
TimedDisappearance // unit: second
|
||||
};
|
||||
|
||||
BaseTransparentDPIFrame(wxWindow * parent,
|
||||
|
@ -26,33 +25,54 @@ public:
|
|||
int ok_button_width,
|
||||
wxString win_text,
|
||||
wxString ok_text,
|
||||
wxString cancel_text = "",
|
||||
wxString cancel_text = "",
|
||||
DisappearanceMode disappearance_mode = DisappearanceMode::None);
|
||||
~BaseTransparentDPIFrame() override;
|
||||
void on_dpi_changed(const wxRect &suggested_rect) override;
|
||||
void on_show();
|
||||
void on_hide();
|
||||
void clear_timer_count();
|
||||
bool Show(bool show =true) override;
|
||||
bool Show(bool show = true) override;
|
||||
|
||||
virtual void deal_ok();
|
||||
virtual void deal_cancel();
|
||||
virtual void on_timer(wxTimerEvent &event);
|
||||
virtual void deal_ok();
|
||||
virtual void deal_cancel();
|
||||
virtual void on_timer(wxTimerEvent &event);
|
||||
void set_target_pos_and_gradual_disappearance(wxPoint pos);
|
||||
void call_start_gradual_disappearance();
|
||||
|
||||
protected:
|
||||
Button * m_button_ok = nullptr;
|
||||
Button * m_button_cancel = nullptr;
|
||||
Button *m_button_ok = nullptr;
|
||||
Button *m_button_cancel = nullptr;
|
||||
|
||||
DisappearanceMode m_timed_disappearance_mode;
|
||||
float m_timer_count = 0;
|
||||
wxTimer *m_refresh_timer{nullptr};
|
||||
int m_disappearance_second = 2500;//unit ms: mean 5s
|
||||
float m_timer_count = 0;
|
||||
wxTimer * m_refresh_timer{nullptr};
|
||||
int m_disappearance_second = 1500; // unit ms: mean 5s
|
||||
bool m_move_to_target_gradual_disappearance = false;
|
||||
wxPoint m_target_pos;
|
||||
|
||||
private:
|
||||
wxBoxSizer *m_sizer_main{nullptr};
|
||||
wxSize m_max_size;
|
||||
wxSize m_step_size;
|
||||
wxPoint m_step_pos;
|
||||
wxPoint m_start_pos;
|
||||
float m_time_move{6.0f};
|
||||
float m_time_gradual_and_scale{100.0f};
|
||||
int m_init_transparent{220};
|
||||
int m_step_transparent;
|
||||
int m_display_stage = 0;//0 normal //1 gradual
|
||||
bool m_enter_window_valid{true};
|
||||
|
||||
private:
|
||||
void init_timer();
|
||||
void start_gradual_disappearance();
|
||||
void init_timer();
|
||||
void calc_step_transparent();
|
||||
void on_close();
|
||||
void show_sizer(wxSizer *sizer, bool show);
|
||||
void hide_all();
|
||||
void begin_gradual_disappearance();
|
||||
void begin_move_to_target_and_gradual_disappearance();
|
||||
};
|
||||
}} // namespace Slic3r::GUI
|
||||
#endif // _STEP_MESH_DIALOG_H_
|
||||
|
|
|
@ -3028,6 +3028,7 @@ void Sidebar::sync_ams_list(bool is_from_big_sync_btn)
|
|||
auto same_dialog_pos_x = get_sidebar_pos_right_x() + FromDIP(5);
|
||||
temp_fsa_info.dialog_pos.x = same_dialog_pos_x;
|
||||
temp_fsa_info.dialog_pos.y = small_btn_pt.y;
|
||||
temp_fsa_info.ams_btn_pos = small_btn_pt + wxPoint(small_btn_size.x / 2, small_btn_size.y/2);
|
||||
if (m_fna_dialog) {
|
||||
if (m_sna_dialog) {
|
||||
m_sna_dialog->on_hide();
|
||||
|
@ -3035,8 +3036,7 @@ void Sidebar::sync_ams_list(bool is_from_big_sync_btn)
|
|||
m_fna_dialog.reset();
|
||||
}
|
||||
m_fna_dialog = std::make_shared<FinishSyncAmsDialog>(temp_fsa_info);
|
||||
m_fna_dialog->Show();
|
||||
m_fna_dialog->Raise();
|
||||
m_fna_dialog->on_show();
|
||||
}
|
||||
|
||||
PlaterPresetComboBox* Sidebar::printer_combox()
|
||||
|
@ -3134,6 +3134,12 @@ void Sidebar::pop_sync_nozzle_and_ams_ialog() {
|
|||
int same_dialog_pos_x = get_sidebar_pos_right_x() + FromDIP(5);
|
||||
temp_na_info.dialog_pos.x = same_dialog_pos_x;
|
||||
temp_na_info.dialog_pos.y += FromDIP(2);
|
||||
|
||||
wxPoint small_btn_pt;
|
||||
wxSize small_btn_size;
|
||||
get_small_btn_sync_pos_size(small_btn_pt, small_btn_size);
|
||||
temp_na_info.ams_btn_pos = small_btn_pt + wxPoint(small_btn_size.x / 2, small_btn_size.y / 2);
|
||||
|
||||
if (m_sna_dialog) {
|
||||
if (m_fna_dialog) {
|
||||
m_fna_dialog->on_hide();
|
||||
|
@ -3141,8 +3147,7 @@ void Sidebar::pop_sync_nozzle_and_ams_ialog() {
|
|||
m_sna_dialog.reset();
|
||||
}
|
||||
m_sna_dialog = std::make_shared<SyncNozzleAndAmsDialog>(temp_na_info);
|
||||
m_sna_dialog->Show();
|
||||
m_sna_dialog->Raise();
|
||||
m_sna_dialog->on_show();
|
||||
}
|
||||
|
||||
static std::vector<Search::InputInfo> get_search_inputs(ConfigOptionMode mode)
|
||||
|
|
|
@ -4379,6 +4379,8 @@ SyncNozzleAndAmsDialog::SyncNozzleAndAmsDialog(InputInfo &input_info)
|
|||
DisappearanceMode::TimedDisappearance)
|
||||
, m_input_info(input_info)
|
||||
{
|
||||
/* set_target_pos_and_gradual_disappearance(input_info.ams_btn_pos);
|
||||
m_move_to_target_gradual_disappearance = false;*/
|
||||
}
|
||||
|
||||
SyncNozzleAndAmsDialog::~SyncNozzleAndAmsDialog() {}
|
||||
|
@ -4388,8 +4390,10 @@ void SyncNozzleAndAmsDialog::deal_ok() {
|
|||
wxGetApp().plater()->sidebar().sync_ams_list(true);
|
||||
}
|
||||
|
||||
void SyncNozzleAndAmsDialog::deal_cancel() {
|
||||
on_hide();
|
||||
void SyncNozzleAndAmsDialog::deal_cancel()
|
||||
{
|
||||
//m_move_to_target_gradual_disappearance = true;
|
||||
call_start_gradual_disappearance();
|
||||
}
|
||||
|
||||
FinishSyncAmsDialog::FinishSyncAmsDialog(InputInfo &input_info)
|
||||
|
@ -4404,10 +4408,13 @@ FinishSyncAmsDialog::FinishSyncAmsDialog(InputInfo &input_info)
|
|||
, m_input_info(input_info)
|
||||
{
|
||||
m_button_cancel->Hide();
|
||||
//set_target_pos_and_gradual_disappearance(input_info.ams_btn_pos);
|
||||
}
|
||||
|
||||
FinishSyncAmsDialog::~FinishSyncAmsDialog() {}
|
||||
|
||||
void FinishSyncAmsDialog::deal_ok() { on_hide(); }
|
||||
void FinishSyncAmsDialog::deal_ok() {
|
||||
call_start_gradual_disappearance();
|
||||
}
|
||||
|
||||
}} // namespace Slic3r
|
|
@ -362,6 +362,7 @@ public:
|
|||
struct InputInfo
|
||||
{
|
||||
wxPoint dialog_pos{wxPoint(400, 200)};
|
||||
wxPoint ams_btn_pos{wxPoint(400, 200)};
|
||||
};
|
||||
SyncNozzleAndAmsDialog(InputInfo &input_info);
|
||||
~SyncNozzleAndAmsDialog() override;
|
||||
|
@ -377,6 +378,7 @@ public:
|
|||
struct InputInfo
|
||||
{
|
||||
wxPoint dialog_pos{wxPoint(400, 200)};
|
||||
wxPoint ams_btn_pos{wxPoint(400, 200)};
|
||||
};
|
||||
FinishSyncAmsDialog(InputInfo &input_info);
|
||||
~FinishSyncAmsDialog() override;
|
||||
|
|
Loading…
Reference in New Issue