GCode Preview - New Layout

This commit is contained in:
Enrico Turri 2018-02-02 12:38:35 +01:00
parent c550ad2268
commit 787a5f1715
7 changed files with 202 additions and 31 deletions

View file

@ -5,6 +5,9 @@
#include <boost/algorithm/string/predicate.hpp>
#include <boost/filesystem.hpp>
#include <boost/algorithm/string/split.hpp>
#include <boost/algorithm/string/classification.hpp>
#if __APPLE__
#import <IOKit/pwr_mgt/IOPMLib.h>
#elif _WIN32
@ -20,6 +23,9 @@
#include <wx/notebook.h>
#include <wx/panel.h>
#include <wx/sizer.h>
#include <wx/combo.h>
#include "slic3r/gui/wxextensions.hpp"
namespace Slic3r { namespace GUI {
@ -183,4 +189,46 @@ void create_preset_tab(const char *name)
g_wxTabPanel->AddPage(panel, name);
}
void create_combochecklist(wxComboCtrl* comboCtrl, std::string text, std::string items, bool initial_value)
{
wxCheckListBoxComboPopup* popup = new wxCheckListBoxComboPopup(-1);
if (popup != nullptr)
{
comboCtrl->SetPopupControl(popup);
popup->SetStringValue(text);
popup->Connect(-1, wxEVT_CHECKLISTBOX, wxCommandEventHandler(wxCheckListBoxComboPopup::OnCheckListBox), nullptr, popup);
popup->Connect(-1, wxEVT_LISTBOX, wxCommandEventHandler(wxCheckListBoxComboPopup::OnListBoxSelection), nullptr, popup);
std::vector<std::string> items_str;
boost::split(items_str, items, boost::is_any_of("|"), boost::token_compress_off);
for (const std::string& item : items_str)
{
popup->Append(item);
}
for (unsigned int i = 0; i < popup->GetCount(); ++i)
{
popup->Check(i, initial_value);
}
}
}
int combochecklist_get_flags(wxComboCtrl* comboCtrl)
{
int flags = 0;
wxCheckListBoxComboPopup* popup = wxDynamicCast(comboCtrl->GetPopupControl(), wxCheckListBoxComboPopup);
if (popup != nullptr)
{
for (unsigned int i = 0; i < popup->GetCount(); ++i)
{
if (popup->IsChecked(i))
flags += (int)std::pow(2.0f, (float)i);
}
}
return flags;
}
} }

View file

@ -8,6 +8,7 @@ class wxApp;
class wxFrame;
class wxMenuBar;
class wxNotebook;
class wxComboCtrl;
namespace Slic3r { namespace GUI {
@ -27,6 +28,16 @@ void add_debug_menu(wxMenuBar *menu);
// add it at the end of the tab panel.
void create_preset_tab(const char *name);
} }
// Creates a wxCheckListBoxComboPopup inside the given wxComboCtrl, filled with the given text and items.
// Items are all initialized to the given value.
// Items must be separated by '|', for example "Item1|Item2|Item3", and so on.
void create_combochecklist(wxComboCtrl* comboCtrl, std::string text, std::string items, bool initial_value);
// Returns the current state of the items listed in the wxCheckListBoxComboPopup contained in the given wxComboCtrl,
// encoded inside an int.
int combochecklist_get_flags(wxComboCtrl* comboCtrl);
}
}
#endif

View file

@ -0,0 +1,74 @@
#include "wxExtensions.hpp"
const unsigned int wxCheckListBoxComboPopup::Height = 200;
wxCheckListBoxComboPopup::wxCheckListBoxComboPopup(wxWindowID id)
: m_id(id)
, m_text(wxEmptyString)
{
}
bool wxCheckListBoxComboPopup::Create(wxWindow* parent)
{
return wxCheckListBox::Create(parent, m_id, wxPoint(0, 0));
}
wxWindow* wxCheckListBoxComboPopup::GetControl()
{
return this;
}
void wxCheckListBoxComboPopup::SetStringValue(const wxString& value)
{
m_text = value;
}
wxString wxCheckListBoxComboPopup::GetStringValue() const
{
return m_text;
}
wxSize wxCheckListBoxComboPopup::GetAdjustedSize(int minWidth, int prefHeight, int maxHeight)
{
// matches owner wxComboCtrl's width
wxComboCtrl* cmb = GetComboCtrl();
if (cmb != nullptr)
{
wxSize size = GetComboCtrl()->GetSize();
size.SetHeight(Height);
return size;
}
else
return wxSize(200, Height);
}
void wxCheckListBoxComboPopup::OnCheckListBox(wxCommandEvent& evt)
{
// forwards the checklistbox event to the owner wxComboCtrl
wxComboCtrl* cmb = GetComboCtrl();
if (cmb != nullptr)
{
wxCommandEvent event(wxEVT_CHECKLISTBOX, cmb->GetId());
cmb->ProcessWindowEvent(event);
}
}
void wxCheckListBoxComboPopup::OnListBoxSelection(wxCommandEvent& evt)
{
// transforms list box item selection event into checklistbox item toggle event
int selId = GetSelection();
if (selId != wxNOT_FOUND)
{
Toggle((unsigned int)selId);
SetSelection(wxNOT_FOUND);
wxCommandEvent event(wxEVT_CHECKLISTBOX, GetId());
event.SetInt(selId);
event.SetEventObject(this);
event.SetString(GetString(selId));
ProcessEvent(event);
}
}

View file

@ -0,0 +1,27 @@
#ifndef slic3r_GUI_wxExtensions_hpp_
#define slic3r_GUI_wxExtensions_hpp_
#include <wx/checklst.h>
#include <wx/combo.h>
class wxCheckListBoxComboPopup : public wxCheckListBox, public wxComboPopup
{
static const unsigned int Height;
wxWindowID m_id;
wxString m_text;
public:
explicit wxCheckListBoxComboPopup(wxWindowID id);
virtual bool Create(wxWindow* parent);
virtual wxWindow* GetControl();
virtual void SetStringValue(const wxString& value);
virtual wxString GetStringValue() const;
virtual wxSize GetAdjustedSize(int minWidth, int prefHeight, int maxHeight);
void OnCheckListBox(wxCommandEvent& evt);
void OnListBoxSelection(wxCommandEvent& evt);
};
#endif // slic3r_GUI_wxExtensions_hpp_