diff options
author | bubnikv <bubnikv@gmail.com> | 2018-09-19 12:02:24 +0300 |
---|---|---|
committer | bubnikv <bubnikv@gmail.com> | 2018-09-19 12:02:24 +0300 |
commit | 0558b53493a77bae44831cf87bb0f59359828ef5 (patch) | |
tree | c3e8dbdf7d91a051c12d9ebbf7606d41047fea96 /src/slic3r/GUI/ProgressStatusBar.cpp | |
parent | 3ddaccb6410478ad02d8c0e02d6d8e6eb1785b9f (diff) |
WIP: Moved sources int src/, separated most of the source code from Perl.
The XS was left only for the unit / integration tests, and it links
libslic3r only. No wxWidgets are allowed to be used from Perl starting
from now.
Diffstat (limited to 'src/slic3r/GUI/ProgressStatusBar.cpp')
-rw-r--r-- | src/slic3r/GUI/ProgressStatusBar.cpp | 152 |
1 files changed, 152 insertions, 0 deletions
diff --git a/src/slic3r/GUI/ProgressStatusBar.cpp b/src/slic3r/GUI/ProgressStatusBar.cpp new file mode 100644 index 000000000..363e34cb2 --- /dev/null +++ b/src/slic3r/GUI/ProgressStatusBar.cpp @@ -0,0 +1,152 @@ +#include "ProgressStatusBar.hpp" + +#include <wx/timer.h> +#include <wx/gauge.h> +#include <wx/button.h> +#include <wx/statusbr.h> +#include <wx/frame.h> +#include "GUI.hpp" + +#include <iostream> + +namespace Slic3r { + +ProgressStatusBar::ProgressStatusBar(wxWindow *parent, int id): + self(new wxStatusBar(parent ? parent : GUI::get_main_frame(), + id == -1? wxID_ANY : id)), + timer_(new wxTimer(self)), + prog_ (new wxGauge(self, + wxGA_HORIZONTAL, + 100, + wxDefaultPosition, + wxDefaultSize)), + cancelbutton_(new wxButton(self, + -1, + "Cancel", + wxDefaultPosition, + wxDefaultSize)) +{ + prog_->Hide(); + cancelbutton_->Hide(); + + self->SetFieldsCount(3); + int w[] = {-1, 150, 155}; + self->SetStatusWidths(3, w); + + self->Bind(wxEVT_TIMER, [this](const wxTimerEvent&) { + if (prog_->IsShown()) timer_->Stop(); + if(is_busy()) prog_->Pulse(); + }); + + self->Bind(wxEVT_SIZE, [this](wxSizeEvent& event){ + wxRect rect; + self->GetFieldRect(1, rect); + auto offset = 0; + cancelbutton_->Move(rect.GetX() + offset, rect.GetY() + offset); + cancelbutton_->SetSize(rect.GetWidth() - offset, rect.GetHeight()); + + self->GetFieldRect(2, rect); + prog_->Move(rect.GetX() + offset, rect.GetY() + offset); + prog_->SetSize(rect.GetWidth() - offset, rect.GetHeight()); + + event.Skip(); + }); + + cancelbutton_->Bind(wxEVT_BUTTON, [this](const wxCommandEvent&) { + if(cancel_cb_) cancel_cb_(); + m_perl_cancel_callback.call(); + cancelbutton_->Hide(); + }); +} + +ProgressStatusBar::~ProgressStatusBar() { + if(timer_->IsRunning()) timer_->Stop(); +} + +int ProgressStatusBar::get_progress() const +{ + return prog_->GetValue(); +} + +void ProgressStatusBar::set_progress(int val) +{ + if(!prog_->IsShown()) show_progress(true); + + if(val == prog_->GetRange()) { + prog_->SetValue(0); + show_progress(false); + } else { + prog_->SetValue(val); + } +} + +int ProgressStatusBar::get_range() const +{ + return prog_->GetRange(); +} + +void ProgressStatusBar::set_range(int val) +{ + if(val != prog_->GetRange()) { + prog_->SetRange(val); + } +} + +void ProgressStatusBar::show_progress(bool show) +{ + prog_->Show(show); + prog_->Pulse(); +} + +void ProgressStatusBar::start_busy(int rate) +{ + busy_ = true; + show_progress(true); + if (!timer_->IsRunning()) { + timer_->Start(rate); + } +} + +void ProgressStatusBar::stop_busy() +{ + timer_->Stop(); + show_progress(false); + prog_->SetValue(0); + busy_ = false; +} + +void ProgressStatusBar::set_cancel_callback(ProgressStatusBar::CancelFn ccb) { + cancel_cb_ = ccb; + if(ccb) cancelbutton_->Show(); + else cancelbutton_->Hide(); +} + +void ProgressStatusBar::run(int rate) +{ + if(!timer_->IsRunning()) { + timer_->Start(rate); + } +} + +void ProgressStatusBar::embed(wxFrame *frame) +{ + wxFrame* mf = frame? frame : GUI::get_main_frame(); + mf->SetStatusBar(self); +} + +void ProgressStatusBar::set_status_text(const wxString& txt) +{ + self->SetStatusText(wxString::FromUTF8(txt.c_str())); +} + +void ProgressStatusBar::show_cancel_button() +{ + cancelbutton_->Show(); +} + +void ProgressStatusBar::hide_cancel_button() +{ + cancelbutton_->Hide(); +} + +} |