First scaling experiments

This commit is contained in:
YuSanka 2019-04-10 09:56:32 +02:00
parent e0340f4f81
commit 82573390c7
11 changed files with 148 additions and 20 deletions

View file

@ -23,6 +23,8 @@ void BitmapCache::clear()
{
for (std::pair<const std::string, wxBitmap*> &bitmap : m_map)
delete bitmap.second;
m_map.clear();
}
static wxBitmap wxImage_to_wxBitmap_with_alpha(wxImage &&image)

View file

@ -58,9 +58,18 @@ public:
: P(parent, id, title, pos, size, style, name)
{
m_scale_factor = (float)get_dpi_for_window(this) / (float)DPI_DEFAULT;
// ->-
m_prev_scale_factor = -1;
// -<-
recalc_font();
this->Bind(EVT_DPI_CHANGED, [this](const DpiChangedEvent &evt) {
// ->-
m_prev_scale_factor = m_scale_factor;
// -<-
m_scale_factor = (float)evt.dpi / (float)DPI_DEFAULT;
on_dpi_changed(evt.rect);
});
@ -69,14 +78,20 @@ public:
virtual ~DPIAware() {}
float scale_factor() const { return m_scale_factor; }
float prev_scale_factor() const { return m_prev_scale_factor; }
int em_unit() const { return m_em_unit; }
int font_size() const { return m_font_size; }
protected:
virtual void on_dpi_changed(const wxRect &suggested_rect) = 0;
// ->-
// virtual void scale(wxWindow *window, const float& scale) = 0;
// -<-
private:
int m_scale_factor;
float m_scale_factor;
float m_prev_scale_factor;
int m_em_unit;
int m_font_size;

View file

@ -256,9 +256,63 @@ bool MainFrame::can_delete_all() const
return (m_plater != nullptr) ? !m_plater->model().objects.empty() : false;
}
static void scale(wxWindow *window, const float scale_f)
{
auto children = window->GetChildren();
for (auto child : children)
{
scale(child, scale_f);
child->SetFont(child->GetFont().Scaled(scale_f));
// const wxSize& sz = child->GetSize();
// if (sz != wxDefaultSize)
// child->SetSize(sz*scale_f);
child->Layout();
}
}
void MainFrame::on_dpi_changed(const wxRect &suggested_rect)
{
// TODO
printf("WM_DPICHANGED: %.2f\n", scale_factor());
// ->-
const float old_sc_factor = prev_scale_factor();
const float new_sc_factor = scale_factor();
if (fabs(old_sc_factor - new_sc_factor) > 0.001)
{
Freeze();
const auto new_em_unit = wxGetApp().em_unit()*new_sc_factor / old_sc_factor;
scale(this, new_sc_factor / old_sc_factor/*, 1/new_em_unit*/);
wxGetApp().set_em_unit(std::max<size_t>(10, new_em_unit));
/* Load default preset bitmaps before a tabpanel initialization,
* but after filling of an em_unit value
*/
wxGetApp().preset_bundle->load_default_preset_bitmaps();
wxGetApp().sidebar().scrolled_panel()->SetSize(40 * wxGetApp().em_unit(), -1);
wxGetApp().sidebar().scrolled_panel()->Layout();
// update preset comboboxes on Tabs
for (auto tab : wxGetApp().tabs_list)
tab->rescale();//update_tab_ui();
// update preset comboboxes on Plater
wxGetApp().sidebar().update_all_preset_comboboxes();
Refresh();
Layout();
Thaw();
}
// -<-
}
void MainFrame::init_menubar()

View file

@ -781,6 +781,31 @@ void Sidebar::remove_unused_filament_combos(const int current_extruder_count)
}
}
void Sidebar::update_all_preset_comboboxes()
{
PresetBundle &preset_bundle = *wxGetApp().preset_bundle;
const auto print_tech = preset_bundle.printers.get_edited_preset().printer_technology();
// wxWindowUpdateLocker noUpdates_scrolled(p->scrolled);
// Update the print choosers to only contain the compatible presets, update the dirty flags.
if (print_tech == ptFFF)
preset_bundle.prints.update_platter_ui(p->combo_print);
else {
preset_bundle.sla_prints.update_platter_ui(p->combo_sla_print);
preset_bundle.sla_materials.update_platter_ui(p->combo_sla_material);
}
// Update the printer choosers, update the dirty flags.
preset_bundle.printers.update_platter_ui(p->combo_printer);
// Update the filament choosers to only contain the compatible presets, update the color preview,
// update the dirty flags.
if (print_tech == ptFFF) {
for (size_t i = 0; i < p->combos_filament.size(); ++i)
preset_bundle.update_platter_filament_ui(i, p->combos_filament[i]);
}
p->show_preset_comboboxes();
}
void Sidebar::update_presets(Preset::Type preset_type)
{
PresetBundle &preset_bundle = *wxGetApp().preset_bundle;
@ -822,22 +847,23 @@ void Sidebar::update_presets(Preset::Type preset_type)
{
// wxWindowUpdateLocker noUpdates_scrolled(p->scrolled);
// Update the print choosers to only contain the compatible presets, update the dirty flags.
if (print_tech == ptFFF)
preset_bundle.prints.update_platter_ui(p->combo_print);
else {
preset_bundle.sla_prints.update_platter_ui(p->combo_sla_print);
preset_bundle.sla_materials.update_platter_ui(p->combo_sla_material);
}
// Update the printer choosers, update the dirty flags.
preset_bundle.printers.update_platter_ui(p->combo_printer);
// Update the filament choosers to only contain the compatible presets, update the color preview,
// update the dirty flags.
if (print_tech == ptFFF) {
for (size_t i = 0; i < p->combos_filament.size(); ++ i)
preset_bundle.update_platter_filament_ui(i, p->combos_filament[i]);
}
p->show_preset_comboboxes();
// // Update the print choosers to only contain the compatible presets, update the dirty flags.
// if (print_tech == ptFFF)
// preset_bundle.prints.update_platter_ui(p->combo_print);
// else {
// preset_bundle.sla_prints.update_platter_ui(p->combo_sla_print);
// preset_bundle.sla_materials.update_platter_ui(p->combo_sla_material);
// }
// // Update the printer choosers, update the dirty flags.
// preset_bundle.printers.update_platter_ui(p->combo_printer);
// // Update the filament choosers to only contain the compatible presets, update the color preview,
// // update the dirty flags.
// if (print_tech == ptFFF) {
// for (size_t i = 0; i < p->combos_filament.size(); ++ i)
// preset_bundle.update_platter_filament_ui(i, p->combos_filament[i]);
// }
// p->show_preset_comboboxes();
update_all_preset_comboboxes();
break;
}

View file

@ -79,6 +79,7 @@ public:
void init_filament_combo(PresetComboBox **combo, const int extr_idx);
void remove_unused_filament_combos(const int current_extruder_count);
void update_all_preset_comboboxes();
void update_presets(Slic3r::Preset::Type preset_type);
void update_mode_sizer() const;
void update_reslice_btn_tooltip() const;

View file

@ -1288,6 +1288,11 @@ std::string PresetCollection::path_from_name(const std::string &new_name) const
return (boost::filesystem::path(m_dir_path) / file_name).make_preferred().string();
}
void PresetCollection::clear_bitmap_cache()
{
m_bitmap_cache->clear();
}
wxString PresetCollection::separator(const std::string &label)
{
return wxString::FromUTF8(PresetCollection::separator_head()) + _(label) + wxString::FromUTF8(PresetCollection::separator_tail());

View file

@ -411,6 +411,8 @@ public:
// Generate a file path from a profile name. Add the ".ini" suffix if it is missing.
std::string path_from_name(const std::string &new_name) const;
void clear_bitmap_cache();
#ifdef __linux__
static const char* separator_head() { return "------- "; }
static const char* separator_tail() { return " -------"; }

View file

@ -1448,6 +1448,14 @@ bool PresetBundle::parse_color(const std::string &scolor, unsigned char *rgb_out
void PresetBundle::load_default_preset_bitmaps()
{
// Clear bitmap cache, before load new scaled default preset bitmaps
m_bitmapCache->clear();
this->prints.clear_bitmap_cache();
this->sla_prints.clear_bitmap_cache();
this->filaments.clear_bitmap_cache();
this->sla_materials.clear_bitmap_cache();
this->printers.clear_bitmap_cache();
this->prints.load_bitmap_default("cog");
this->sla_prints.load_bitmap_default("cog");
this->filaments.load_bitmap_default("spool.png");

View file

@ -726,6 +726,16 @@ void Tab::update_visibility()
update_changed_tree_ui();
}
void Tab::rescale()
{
m_em_unit = wxGetApp().em_unit();
m_presets_choice->SetSize(25 * m_em_unit, -1);
m_treectrl->SetSize(20 * m_em_unit, -1);
update_tab_ui();
}
Field* Tab::get_field(const t_config_option_key& opt_key, int opt_index/* = -1*/) const
{
Field* field = nullptr;

View file

@ -274,6 +274,7 @@ public:
virtual void reload_config();
void update_mode();
void update_visibility();
void rescale();
Field* get_field(const t_config_option_key& opt_key, int opt_index = -1) const;
bool set_value(const t_config_option_key& opt_key, const boost::any& value);
wxSizer* description_line_widget(wxWindow* parent, ogStaticText** StaticText);

View file

@ -2387,7 +2387,7 @@ PrusaModeButton::PrusaModeButton( wxWindow *parent,
const wxBitmap& bmp_on/* = wxNullBitmap*/,
const wxSize& size/* = wxDefaultSize*/,
const wxPoint& pos/* = wxDefaultPosition*/) :
wxButton(parent, id, mode, pos, size, /*wxBU_EXACTFIT | */wxNO_BORDER),
wxButton(parent, id, mode, pos, wxDefaultSize/*size*/, wxBU_EXACTFIT | wxNO_BORDER),
m_bmp_on(bmp_on)
{
#ifdef __WXMSW__
@ -2425,7 +2425,11 @@ void PrusaModeButton::focus_button(const bool focus)
{
// const wxBitmap& bmp = focus ? m_bmp_on : m_bmp_off;
// SetBitmap(bmp);
const wxFont& new_font = focus ? Slic3r::GUI::wxGetApp().bold_font() : Slic3r::GUI::wxGetApp().small_font();
// const wxFont& new_font = focus ? Slic3r::GUI::wxGetApp().bold_font() : Slic3r::GUI::wxGetApp().small_font();
wxFont font = GetFont();
const wxFont& new_font = focus ? font.Bold() : font.GetBaseFont();
SetFont(new_font);
Refresh();