Factor out load_scaled_bitmap

This commit is contained in:
Vojtech Kral 2019-04-09 14:18:03 +02:00
parent 64ce604ff4
commit c17e8602ed
6 changed files with 43 additions and 72 deletions

View file

@ -799,16 +799,16 @@ bool PresetCollection::delete_current_preset()
return true;
}
bool PresetCollection::load_bitmap_default(const std::string &file_name)
void PresetCollection::load_bitmap_default(const std::string &file_name)
{
// return m_bitmap_main_frame->LoadFile(wxString::FromUTF8(Slic3r::var(file_name).c_str()), wxBITMAP_TYPE_PNG);
return load_scaled_bitmap(nullptr, &m_bitmap_main_frame, file_name); // FIXME: pass window ptr for proper scaling
// FIXME: pass window ptr for proper scaling
*m_bitmap_main_frame = create_scaled_bitmap(nullptr, file_name);
}
bool PresetCollection::load_bitmap_add(const std::string &file_name)
void PresetCollection::load_bitmap_add(const std::string &file_name)
{
// return m_bitmap_add->LoadFile(wxString::FromUTF8(Slic3r::var(file_name).c_str()), wxBITMAP_TYPE_PNG);
return load_scaled_bitmap(nullptr, &m_bitmap_add, file_name); // FIXME: pass window ptr for proper scaling
// FIXME: pass window ptr for proper scaling
*m_bitmap_add = create_scaled_bitmap(nullptr, file_name);
}
const Preset* PresetCollection::get_selected_preset_parent() const

View file

@ -276,10 +276,10 @@ public:
bool delete_current_preset();
// Load default bitmap to be placed at the wxBitmapComboBox of a MainFrame.
bool load_bitmap_default(const std::string &file_name);
void load_bitmap_default(const std::string &file_name);
// Load "add new printer" bitmap to be placed at the wxBitmapComboBox of a MainFrame.
bool load_bitmap_add(const std::string &file_name);
void load_bitmap_add(const std::string &file_name);
// Compatible & incompatible marks, to be placed at the wxBitmapComboBox items.
void set_bitmap_compatible (const wxBitmap *bmp) { m_bitmap_compatible = bmp; }

View file

@ -396,56 +396,37 @@ void PresetBundle::export_selections(AppConfig &config)
config.set("presets", "printer", printers.get_selected_preset_name());
}
bool PresetBundle::load_compatible_bitmaps()
void PresetBundle::load_compatible_bitmaps()
{
const std::string path_bitmap_compatible = "flag-green-icon.png";
const std::string path_bitmap_incompatible = "flag-red-icon.png";
const std::string path_bitmap_lock = "sys_lock.png";//"lock.png";
const std::string path_bitmap_lock_open = "sys_unlock.png";//"lock_open.png";
// bool loaded_compatible = m_bitmapCompatible ->LoadFile(
// wxString::FromUTF8(Slic3r::var(path_bitmap_compatible).c_str()), wxBITMAP_TYPE_PNG);
// bool loaded_incompatible = m_bitmapIncompatible->LoadFile(
// wxString::FromUTF8(Slic3r::var(path_bitmap_incompatible).c_str()), wxBITMAP_TYPE_PNG);
// bool loaded_lock = m_bitmapLock->LoadFile(
// wxString::FromUTF8(Slic3r::var(path_bitmap_lock).c_str()), wxBITMAP_TYPE_PNG);
// bool loaded_lock_open = m_bitmapLockOpen->LoadFile(
// wxString::FromUTF8(Slic3r::var(path_bitmap_lock_open).c_str()), wxBITMAP_TYPE_PNG);
// FIXME: pass window ptr for proper scaling
bool loaded_compatible = load_scaled_bitmap(nullptr, &m_bitmapCompatible, path_bitmap_compatible);
bool loaded_incompatible = load_scaled_bitmap(nullptr, &m_bitmapIncompatible,path_bitmap_incompatible);
bool loaded_lock = load_scaled_bitmap(nullptr, &m_bitmapLock, path_bitmap_lock);
bool loaded_lock_open = load_scaled_bitmap(nullptr, &m_bitmapLockOpen, path_bitmap_lock_open);
*m_bitmapCompatible = create_scaled_bitmap(nullptr, "flag-green-icon.png");
*m_bitmapIncompatible = create_scaled_bitmap(nullptr, "flag-red-icon.png");
*m_bitmapLock = create_scaled_bitmap(nullptr, "sys_lock.png");
*m_bitmapLockOpen = create_scaled_bitmap(nullptr, "sys_unlock.png");
if (loaded_compatible) {
prints .set_bitmap_compatible(m_bitmapCompatible);
filaments .set_bitmap_compatible(m_bitmapCompatible);
sla_prints .set_bitmap_compatible(m_bitmapCompatible);
sla_materials.set_bitmap_compatible(m_bitmapCompatible);
// printers .set_bitmap_compatible(m_bitmapCompatible);
}
if (loaded_incompatible) {
prints .set_bitmap_incompatible(m_bitmapIncompatible);
filaments .set_bitmap_incompatible(m_bitmapIncompatible);
sla_prints .set_bitmap_incompatible(m_bitmapIncompatible);
sla_materials.set_bitmap_incompatible(m_bitmapIncompatible);
// printers .set_bitmap_incompatible(m_bitmapIncompatible);
}
if (loaded_lock) {
prints .set_bitmap_lock(m_bitmapLock);
filaments .set_bitmap_lock(m_bitmapLock);
sla_prints .set_bitmap_lock(m_bitmapLock);
sla_materials.set_bitmap_lock(m_bitmapLock);
printers .set_bitmap_lock(m_bitmapLock);
}
if (loaded_lock_open) {
prints .set_bitmap_lock_open(m_bitmapLock);
filaments .set_bitmap_lock_open(m_bitmapLock);
sla_prints .set_bitmap_lock_open(m_bitmapLock);
sla_materials.set_bitmap_lock_open(m_bitmapLock);
printers .set_bitmap_lock_open(m_bitmapLock);
}
return loaded_compatible && loaded_incompatible && loaded_lock && loaded_lock_open;
prints .set_bitmap_compatible(m_bitmapCompatible);
filaments .set_bitmap_compatible(m_bitmapCompatible);
sla_prints .set_bitmap_compatible(m_bitmapCompatible);
sla_materials.set_bitmap_compatible(m_bitmapCompatible);
printers .set_bitmap_compatible(m_bitmapCompatible);
prints .set_bitmap_incompatible(m_bitmapIncompatible);
filaments .set_bitmap_incompatible(m_bitmapIncompatible);
sla_prints .set_bitmap_incompatible(m_bitmapIncompatible);
sla_materials.set_bitmap_incompatible(m_bitmapIncompatible);
printers .set_bitmap_incompatible(m_bitmapIncompatible);
prints .set_bitmap_lock(m_bitmapLock);
filaments .set_bitmap_lock(m_bitmapLock);
sla_prints .set_bitmap_lock(m_bitmapLock);
sla_materials.set_bitmap_lock(m_bitmapLock);
printers .set_bitmap_lock(m_bitmapLock);
prints .set_bitmap_lock_open(m_bitmapLock);
filaments .set_bitmap_lock_open(m_bitmapLock);
sla_prints .set_bitmap_lock_open(m_bitmapLock);
sla_materials.set_bitmap_lock_open(m_bitmapLock);
printers .set_bitmap_lock_open(m_bitmapLock);
}
DynamicPrintConfig PresetBundle::full_config() const

View file

@ -148,7 +148,7 @@ private:
// If it is not an external config, then the config will be stored into the user profile directory.
void load_config_file_config(const std::string &name_or_path, bool is_external, DynamicPrintConfig &&config);
void load_config_file_config_bundle(const std::string &path, const boost::property_tree::ptree &tree);
bool load_compatible_bitmaps();
void load_compatible_bitmaps();
DynamicPrintConfig full_fff_config() const;
DynamicPrintConfig full_sla_config() const;

View file

@ -422,7 +422,7 @@ void PrusaCollapsiblePaneMSW::Collapse(bool collapse)
// If an icon has horizontal orientation (width > height) call this function with is_horizontal = true
bool load_scaled_bitmap(wxWindow *win, wxBitmap** bmp, const std::string& bmp_name_in, const int px_cnt/* = 16*/, const bool is_horizontal /*= false*/)
wxBitmap create_scaled_bitmap(wxWindow *win, const std::string& bmp_name_in, const int px_cnt/* = 16*/, const bool is_horizontal /* = false*/)
{
static Slic3r::GUI::BitmapCache cache;
@ -434,28 +434,19 @@ bool load_scaled_bitmap(wxWindow *win, wxBitmap** bmp, const std::string& bmp_na
scale_base = (unsigned int)(Slic3r::GUI::wxGetApp().em_unit() * px_cnt * 0.1f + 0.5f);
std::string bmp_name = bmp_name_in;
boost::replace_last(bmp_name, ".png", "");
boost::replace_last(bmp_name, ".png", "");
// Try loading an SVG first, then PNG if SVG is not found:
*bmp = cache.load_svg(bmp_name, width, height, scale_factor);
if (*bmp == nullptr) {
*bmp = cache.load_png(bmp_name, width, height);
wxBitmap *bmp = cache.load_svg(bmp_name, width, height, scale_factor);
if (bmp == nullptr) {
bmp = cache.load_png(bmp_name, width, height);
}
if (*bmp == nullptr) {
if (bmp == nullptr) {
// Neither SVG nor PNG has been found, raise error
throw std::runtime_error("Could not load bitmap: " + bmp_name);
}
// XXX: useless
return *bmp != nullptr;
}
// If an icon has horizontal orientation (width > height) call this function with is_horizontal = true
wxBitmap create_scaled_bitmap(wxWindow *win, const std::string& bmp_name_in, const int px_cnt/* = 16*/, const bool is_horizontal /* = false*/)
{
wxBitmap *bmp {nullptr};
load_scaled_bitmap(win, &bmp, bmp_name_in, px_cnt, is_horizontal);
return *bmp;
}

View file

@ -31,7 +31,6 @@ wxMenuItem* append_submenu(wxMenu* menu, wxMenu* sub_menu, int id, const wxStrin
wxMenuItem* append_menu_radio_item(wxMenu* menu, int id, const wxString& string, const wxString& description,
std::function<void(wxCommandEvent& event)> cb, wxEvtHandler* event_handler);
bool load_scaled_bitmap(wxWindow *win, wxBitmap** bmp, const std::string& bmp_name, const int px_cnt=16, const bool is_horizontal = false);
wxBitmap create_scaled_bitmap(wxWindow *win, const std::string& bmp_name, const int px_cnt=16, const bool is_horizontal = false);
class wxCheckListBoxComboPopup : public wxCheckListBox, public wxComboPopup