mirror of
https://git.mirrors.martin98.com/https://github.com/prusa3d/PrusaSlicer.git
synced 2025-07-03 20:35:11 +08:00
Factor out load_scaled_bitmap
This commit is contained in:
parent
64ce604ff4
commit
c17e8602ed
@ -799,16 +799,16 @@ bool PresetCollection::delete_current_preset()
|
|||||||
return true;
|
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);
|
// FIXME: pass window ptr for proper scaling
|
||||||
return load_scaled_bitmap(nullptr, &m_bitmap_main_frame, file_name); // 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);
|
// FIXME: pass window ptr for proper scaling
|
||||||
return load_scaled_bitmap(nullptr, &m_bitmap_add, file_name); // FIXME: pass window ptr for proper scaling
|
*m_bitmap_add = create_scaled_bitmap(nullptr, file_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
const Preset* PresetCollection::get_selected_preset_parent() const
|
const Preset* PresetCollection::get_selected_preset_parent() const
|
||||||
|
@ -276,10 +276,10 @@ public:
|
|||||||
bool delete_current_preset();
|
bool delete_current_preset();
|
||||||
|
|
||||||
// Load default bitmap to be placed at the wxBitmapComboBox of a MainFrame.
|
// 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.
|
// 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.
|
// Compatible & incompatible marks, to be placed at the wxBitmapComboBox items.
|
||||||
void set_bitmap_compatible (const wxBitmap *bmp) { m_bitmap_compatible = bmp; }
|
void set_bitmap_compatible (const wxBitmap *bmp) { m_bitmap_compatible = bmp; }
|
||||||
|
@ -396,57 +396,38 @@ void PresetBundle::export_selections(AppConfig &config)
|
|||||||
config.set("presets", "printer", printers.get_selected_preset_name());
|
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
|
// FIXME: pass window ptr for proper scaling
|
||||||
bool loaded_compatible = load_scaled_bitmap(nullptr, &m_bitmapCompatible, path_bitmap_compatible);
|
*m_bitmapCompatible = create_scaled_bitmap(nullptr, "flag-green-icon.png");
|
||||||
bool loaded_incompatible = load_scaled_bitmap(nullptr, &m_bitmapIncompatible,path_bitmap_incompatible);
|
*m_bitmapIncompatible = create_scaled_bitmap(nullptr, "flag-red-icon.png");
|
||||||
bool loaded_lock = load_scaled_bitmap(nullptr, &m_bitmapLock, path_bitmap_lock);
|
*m_bitmapLock = create_scaled_bitmap(nullptr, "sys_lock.png");
|
||||||
bool loaded_lock_open = load_scaled_bitmap(nullptr, &m_bitmapLockOpen, path_bitmap_lock_open);
|
*m_bitmapLockOpen = create_scaled_bitmap(nullptr, "sys_unlock.png");
|
||||||
|
|
||||||
if (loaded_compatible) {
|
|
||||||
prints .set_bitmap_compatible(m_bitmapCompatible);
|
prints .set_bitmap_compatible(m_bitmapCompatible);
|
||||||
filaments .set_bitmap_compatible(m_bitmapCompatible);
|
filaments .set_bitmap_compatible(m_bitmapCompatible);
|
||||||
sla_prints .set_bitmap_compatible(m_bitmapCompatible);
|
sla_prints .set_bitmap_compatible(m_bitmapCompatible);
|
||||||
sla_materials.set_bitmap_compatible(m_bitmapCompatible);
|
sla_materials.set_bitmap_compatible(m_bitmapCompatible);
|
||||||
// printers .set_bitmap_compatible(m_bitmapCompatible);
|
printers .set_bitmap_compatible(m_bitmapCompatible);
|
||||||
}
|
|
||||||
if (loaded_incompatible) {
|
|
||||||
prints .set_bitmap_incompatible(m_bitmapIncompatible);
|
prints .set_bitmap_incompatible(m_bitmapIncompatible);
|
||||||
filaments .set_bitmap_incompatible(m_bitmapIncompatible);
|
filaments .set_bitmap_incompatible(m_bitmapIncompatible);
|
||||||
sla_prints .set_bitmap_incompatible(m_bitmapIncompatible);
|
sla_prints .set_bitmap_incompatible(m_bitmapIncompatible);
|
||||||
sla_materials.set_bitmap_incompatible(m_bitmapIncompatible);
|
sla_materials.set_bitmap_incompatible(m_bitmapIncompatible);
|
||||||
// printers .set_bitmap_incompatible(m_bitmapIncompatible);
|
printers .set_bitmap_incompatible(m_bitmapIncompatible);
|
||||||
}
|
|
||||||
if (loaded_lock) {
|
|
||||||
prints .set_bitmap_lock(m_bitmapLock);
|
prints .set_bitmap_lock(m_bitmapLock);
|
||||||
filaments .set_bitmap_lock(m_bitmapLock);
|
filaments .set_bitmap_lock(m_bitmapLock);
|
||||||
sla_prints .set_bitmap_lock(m_bitmapLock);
|
sla_prints .set_bitmap_lock(m_bitmapLock);
|
||||||
sla_materials.set_bitmap_lock(m_bitmapLock);
|
sla_materials.set_bitmap_lock(m_bitmapLock);
|
||||||
printers .set_bitmap_lock(m_bitmapLock);
|
printers .set_bitmap_lock(m_bitmapLock);
|
||||||
}
|
|
||||||
if (loaded_lock_open) {
|
|
||||||
prints .set_bitmap_lock_open(m_bitmapLock);
|
prints .set_bitmap_lock_open(m_bitmapLock);
|
||||||
filaments .set_bitmap_lock_open(m_bitmapLock);
|
filaments .set_bitmap_lock_open(m_bitmapLock);
|
||||||
sla_prints .set_bitmap_lock_open(m_bitmapLock);
|
sla_prints .set_bitmap_lock_open(m_bitmapLock);
|
||||||
sla_materials.set_bitmap_lock_open(m_bitmapLock);
|
sla_materials.set_bitmap_lock_open(m_bitmapLock);
|
||||||
printers .set_bitmap_lock_open(m_bitmapLock);
|
printers .set_bitmap_lock_open(m_bitmapLock);
|
||||||
}
|
}
|
||||||
return loaded_compatible && loaded_incompatible && loaded_lock && loaded_lock_open;
|
|
||||||
}
|
|
||||||
|
|
||||||
DynamicPrintConfig PresetBundle::full_config() const
|
DynamicPrintConfig PresetBundle::full_config() const
|
||||||
{
|
{
|
||||||
|
@ -148,7 +148,7 @@ private:
|
|||||||
// If it is not an external config, then the config will be stored into the user profile directory.
|
// 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(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);
|
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_fff_config() const;
|
||||||
DynamicPrintConfig full_sla_config() const;
|
DynamicPrintConfig full_sla_config() const;
|
||||||
|
@ -422,7 +422,7 @@ void PrusaCollapsiblePaneMSW::Collapse(bool collapse)
|
|||||||
|
|
||||||
|
|
||||||
// If an icon has horizontal orientation (width > height) call this function with is_horizontal = true
|
// 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;
|
static Slic3r::GUI::BitmapCache cache;
|
||||||
|
|
||||||
@ -437,25 +437,16 @@ bool load_scaled_bitmap(wxWindow *win, wxBitmap** bmp, const std::string& bmp_na
|
|||||||
boost::replace_last(bmp_name, ".png", "");
|
boost::replace_last(bmp_name, ".png", "");
|
||||||
|
|
||||||
// Try loading an SVG first, then PNG if SVG is not found:
|
// Try loading an SVG first, then PNG if SVG is not found:
|
||||||
*bmp = cache.load_svg(bmp_name, width, height, scale_factor);
|
wxBitmap *bmp = cache.load_svg(bmp_name, width, height, scale_factor);
|
||||||
if (*bmp == nullptr) {
|
if (bmp == nullptr) {
|
||||||
*bmp = cache.load_png(bmp_name, width, height);
|
bmp = cache.load_png(bmp_name, width, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (*bmp == nullptr) {
|
if (bmp == nullptr) {
|
||||||
// Neither SVG nor PNG has been found, raise error
|
// Neither SVG nor PNG has been found, raise error
|
||||||
throw std::runtime_error("Could not load bitmap: " + bmp_name);
|
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;
|
return *bmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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,
|
wxMenuItem* append_menu_radio_item(wxMenu* menu, int id, const wxString& string, const wxString& description,
|
||||||
std::function<void(wxCommandEvent& event)> cb, wxEvtHandler* event_handler);
|
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);
|
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
|
class wxCheckListBoxComboPopup : public wxCheckListBox, public wxComboPopup
|
||||||
|
Loading…
x
Reference in New Issue
Block a user