Big Refactoring: - deleted/renamed all _Prusa_ prefixes,

- cleaned code from commented parts
 - rescale() -> msw_rescale()
This commit is contained in:
YuSanka 2019-04-25 01:45:00 +02:00
parent be60f0a53c
commit 065448e9e5
32 changed files with 726 additions and 1139 deletions

View file

@ -117,61 +117,34 @@ void Tab::create_preset_tab()
//buttons
m_scaled_buttons.reserve(6);
m_scaled_buttons.reserve(2);
// wxBitmap bmpMenu;
// bmpMenu = create_scaled_bitmap(this, "save");
// m_btn_save_preset = new wxBitmapButton(panel, wxID_ANY, bmpMenu, wxDefaultPosition, wxDefaultSize, wxBORDER_NONE);
// if (wxMSW) m_btn_save_preset->SetBackgroundColour(color);
// bmpMenu = create_scaled_bitmap(this, "cross"/*"delete.png"*/);
// m_btn_delete_preset = new wxBitmapButton(panel, wxID_ANY, bmpMenu, wxDefaultPosition, wxDefaultSize, wxBORDER_NONE);
// if (wxMSW) m_btn_delete_preset->SetBackgroundColour(color);
add_scaled_button(panel, &m_btn_save_preset, "save");
add_scaled_button(panel, &m_btn_delete_preset, "cross");
m_show_incompatible_presets = false;
// m_bmp_show_incompatible_presets = create_scaled_bitmap(this, "flag_red");
// m_bmp_hide_incompatible_presets = create_scaled_bitmap(this, "flag_green");
add_scaled_bitmap(this, m_bmp_show_incompatible_presets, "flag_red");
add_scaled_bitmap(this, m_bmp_hide_incompatible_presets, "flag_green");
// m_btn_hide_incompatible_presets = new wxBitmapButton(panel, wxID_ANY, m_bmp_hide_incompatible_presets, wxDefaultPosition, wxDefaultSize, wxBORDER_NONE);
// if (wxMSW) m_btn_hide_incompatible_presets->SetBackgroundColour(color);
add_scaled_button(panel, &m_btn_hide_incompatible_presets, m_bmp_hide_incompatible_presets.name());
m_btn_save_preset->SetToolTip(_(L("Save current ")) + m_title);
m_btn_delete_preset->SetToolTip(_(L("Delete this preset")));
m_btn_delete_preset->Disable();
// m_undo_btn = new wxButton(panel, wxID_ANY, "", wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT | wxNO_BORDER);
// m_undo_to_sys_btn = new wxButton(panel, wxID_ANY, "", wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT | wxNO_BORDER);
// m_question_btn = new wxButton(panel, wxID_ANY, "", wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT | wxNO_BORDER);
add_scaled_button(panel, &m_question_btn, "question");
// if (wxMSW) {
// m_undo_btn->SetBackgroundColour(color);
// m_undo_to_sys_btn->SetBackgroundColour(color);
// m_question_btn->SetBackgroundColour(color);
// }
m_question_btn->SetToolTip(_(L("Hover the cursor over buttons to find more information \n"
"or click this button.")));
// Determine the theme color of OS (dark or light)
auto luma = wxGetApp().get_colour_approx_luma(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW));
// Bitmaps to be shown on the "Revert to system" aka "Lock to system" button next to each input field.
// m_bmp_value_lock = create_scaled_bitmap(this, luma >= 128 ? "lock_closed" : "lock_closed_white");
// m_bmp_value_unlock = create_scaled_bitmap(this, "lock_open");
add_scaled_bitmap(this, m_bmp_value_lock , luma >= 128 ? "lock_closed" : "lock_closed_white");
add_scaled_bitmap(this, m_bmp_value_unlock, "lock_open");
m_bmp_non_system = &m_bmp_white_bullet;
// Bitmaps to be shown on the "Undo user changes" button next to each input field.
// m_bmp_value_revert = create_scaled_bitmap(this, "undo");
// m_bmp_white_bullet = create_scaled_bitmap(this, luma >= 128 ? "dot" : "dot_white"/*"bullet_white.png"*/);
// m_bmp_question = create_scaled_bitmap(this, "question");
// m_bmp_value_revert = create_scaled_bitmap(this, "undo");
// m_bmp_white_bullet = create_scaled_bitmap(this, "bullet_white.png");
add_scaled_bitmap(this, m_bmp_value_revert, "undo");
add_scaled_bitmap(this, m_bmp_white_bullet, luma >= 128 ? "dot" : "dot_white"/*"bullet_white.png"*/);
add_scaled_bitmap(this, m_bmp_white_bullet, luma >= 128 ? "dot" : "dot_white");
fill_icon_descriptions();
set_tooltips_text();
@ -179,11 +152,8 @@ void Tab::create_preset_tab()
add_scaled_button(panel, &m_undo_btn, m_bmp_white_bullet.name());
add_scaled_button(panel, &m_undo_to_sys_btn, m_bmp_white_bullet.name());
// m_undo_btn->SetBitmap(m_bmp_white_bullet);
m_undo_btn->Bind(wxEVT_BUTTON, ([this](wxCommandEvent) { on_roll_back_value(); }));
// m_undo_to_sys_btn->SetBitmap(m_bmp_white_bullet);
m_undo_to_sys_btn->Bind(wxEVT_BUTTON, ([this](wxCommandEvent) { on_roll_back_value(true); }));
// m_question_btn->SetBitmap(m_bmp_question);
m_question_btn->Bind(wxEVT_BUTTON, ([this](wxCommandEvent)
{
auto dlg = new ButtonsDescription(this, &m_icon_descriptions);
@ -203,7 +173,7 @@ void Tab::create_preset_tab()
m_default_text_clr = wxGetApp().get_label_clr_default();
// Sizer with buttons for mode changing
m_mode_sizer = new PrusaModeSizer(panel);
m_mode_sizer = new ModeSizer(panel);
const float scale_factor = wxGetApp().em_unit()*0.1;// GetContentScaleFactor();
m_hsizer = new wxBoxSizer(wxHORIZONTAL);
@ -281,9 +251,9 @@ void Tab::create_preset_tab()
// Fill cache for mode bitmaps
m_mode_bitmap_cache.reserve(3);
m_mode_bitmap_cache.push_back(PrusaBitmap(this, "mode_simple_.png"));
m_mode_bitmap_cache.push_back(PrusaBitmap(this, "mode_middle_.png"));
m_mode_bitmap_cache.push_back(PrusaBitmap(this, "mode_expert_.png"));
m_mode_bitmap_cache.push_back(ScalableBitmap(this, "mode_simple_.png"));
m_mode_bitmap_cache.push_back(ScalableBitmap(this, "mode_middle_.png"));
m_mode_bitmap_cache.push_back(ScalableBitmap(this, "mode_expert_.png"));
// Initialize the DynamicPrintConfig by default keys/values.
build();
@ -291,17 +261,21 @@ void Tab::create_preset_tab()
m_complited = true;
}
void Tab::add_scaled_button(wxWindow* parent, PrusaButton** btn, const std::string& icon_name,
void Tab::add_scaled_button(wxWindow* parent,
ScalableButton** btn,
const std::string& icon_name,
const wxString& label/* = wxEmptyString*/,
long style /*= wxBU_EXACTFIT | wxNO_BORDER*/)
{
*btn = new PrusaButton(parent, wxID_ANY, icon_name, label, wxDefaultSize, wxDefaultPosition, style);
*btn = new ScalableButton(parent, wxID_ANY, icon_name, label, wxDefaultSize, wxDefaultPosition, style);
m_scaled_buttons.push_back(*btn);
}
void Tab::add_scaled_bitmap(wxWindow* parent, PrusaBitmap& bmp, const std::string& icon_name)
void Tab::add_scaled_bitmap(wxWindow* parent,
ScalableBitmap& bmp,
const std::string& icon_name)
{
bmp = PrusaBitmap(parent, icon_name);
bmp = ScalableBitmap(parent, icon_name);
m_scaled_bitmaps.push_back(&bmp);
}
@ -321,8 +295,7 @@ Slic3r::GUI::PageShp Tab::add_options_page(const wxString& title, const std::str
icon_idx = (m_icon_index.find(icon) == m_icon_index.end()) ? -1 : m_icon_index.at(icon);
if (icon_idx == -1) {
// Add a new icon to the icon list.
// m_icons->Add(create_scaled_bitmap(this, icon));
m_scaled_icons_list.push_back(PrusaBitmap(this, icon));
m_scaled_icons_list.push_back(ScalableBitmap(this, icon));
m_icons->Add(m_scaled_icons_list.back().bmp());
icon_idx = ++m_icon_count;
m_icon_index[icon] = icon_idx;
@ -442,8 +415,8 @@ void Tab::update_changed_ui()
{
bool is_nonsys_value = false;
bool is_modified_value = true;
const /*wxBitmap*/PrusaBitmap *sys_icon = &m_bmp_value_lock;
const /*wxBitmap*/PrusaBitmap *icon = &m_bmp_value_revert;
const ScalableBitmap *sys_icon = &m_bmp_value_lock;
const ScalableBitmap *icon = &m_bmp_value_revert;
const wxColour *color = &m_sys_label_clr;
@ -766,11 +739,11 @@ void Tab::update_visibility()
update_changed_tree_ui();
}
void Tab::rescale()
void Tab::msw_rescale()
{
m_em_unit = wxGetApp().em_unit();
m_mode_sizer->rescale();
m_mode_sizer->msw_rescale();
m_presets_choice->SetSize(35 * m_em_unit, -1);
m_treectrl->SetMinSize(wxSize(20 * m_em_unit, -1));
@ -779,25 +752,25 @@ void Tab::rescale()
// rescale buttons and cached bitmaps
for (const auto btn : m_scaled_buttons)
btn->rescale();
btn->msw_rescale();
for (const auto bmp : m_scaled_bitmaps)
bmp->rescale();
for (PrusaBitmap& bmp : m_mode_bitmap_cache)
bmp.rescale();
bmp->msw_rescale();
for (ScalableBitmap& bmp : m_mode_bitmap_cache)
bmp.msw_rescale();
// rescale icons for tree_ctrl
for (PrusaBitmap& bmp : m_scaled_icons_list)
bmp.rescale();
for (ScalableBitmap& bmp : m_scaled_icons_list)
bmp.msw_rescale();
// recreate and set new ImageList for tree_ctrl
m_icons->RemoveAll();
m_icons = new wxImageList(m_scaled_icons_list.front().bmp().GetWidth(), m_scaled_icons_list.front().bmp().GetHeight());
for (PrusaBitmap& bmp : m_scaled_icons_list)
for (ScalableBitmap& bmp : m_scaled_icons_list)
m_icons->Add(bmp.bmp());
m_treectrl->AssignImageList(m_icons);
// rescale options_groups
for (auto page : m_pages)
page->rescale();
page->msw_rescale();
Layout();
}
@ -1705,12 +1678,8 @@ void TabPrinter::build_printhost(ConfigOptionsGroup *optgroup)
}
auto printhost_browse = [=](wxWindow* parent) {
// auto btn = m_printhost_browse_btn = new wxButton(parent, wxID_ANY, _(L(" Browse ")) + dots,
// wxDefaultPosition, wxDefaultSize, wxBU_LEFT | wxBU_EXACTFIT);
// btn->SetFont(Slic3r::GUI::wxGetApp().normal_font());
// btn->SetBitmap(create_scaled_bitmap(this, "browse"));
add_scaled_button(parent, &m_printhost_browse_btn, "browse", _(L(" Browse ")) + dots, wxBU_LEFT | wxBU_EXACTFIT);
PrusaButton* btn = m_printhost_browse_btn;
ScalableButton* btn = m_printhost_browse_btn;
btn->SetFont(Slic3r::GUI::wxGetApp().normal_font());
auto sizer = new wxBoxSizer(wxHORIZONTAL);
@ -1728,12 +1697,8 @@ void TabPrinter::build_printhost(ConfigOptionsGroup *optgroup)
};
auto print_host_test = [this](wxWindow* parent) {
// auto btn = m_print_host_test_btn = new wxButton(parent, wxID_ANY, _(L("Test")),
// wxDefaultPosition, wxDefaultSize, wxBU_LEFT | wxBU_EXACTFIT);
// btn->SetFont(Slic3r::GUI::wxGetApp().normal_font());
// btn->SetBitmap(create_scaled_bitmap(this, "test"));
add_scaled_button(parent, &m_print_host_test_btn, "test", _(L("Test")), wxBU_LEFT | wxBU_EXACTFIT);
PrusaButton* btn = m_print_host_test_btn;
ScalableButton* btn = m_print_host_test_btn;
btn->SetFont(Slic3r::GUI::wxGetApp().normal_font());
auto sizer = new wxBoxSizer(wxHORIZONTAL);
sizer->Add(btn);
@ -1849,11 +1814,7 @@ void TabPrinter::build_fff()
Line line = optgroup->create_single_option_line("bed_shape");//{ _(L("Bed shape")), "" };
line.widget = [this](wxWindow* parent) {
// auto btn = new wxButton(parent, wxID_ANY, _(L(" Set "))+dots, wxDefaultPosition, wxDefaultSize, wxBU_LEFT | wxBU_EXACTFIT);
// btn->SetFont(wxGetApp().small_font());
// btn->SetBitmap(create_scaled_bitmap(this, "printer"));
PrusaButton* btn;
ScalableButton* btn;
add_scaled_button(parent, &btn, "printer_white", _(L(" Set ")) + dots, wxBU_LEFT | wxBU_EXACTFIT);
btn->SetFont(wxGetApp().normal_font());
@ -2054,11 +2015,7 @@ void TabPrinter::build_sla()
Line line = optgroup->create_single_option_line("bed_shape");//{ _(L("Bed shape")), "" };
line.widget = [this](wxWindow* parent) {
// auto btn = new wxButton(parent, wxID_ANY, _(L(" Set ")) + dots, wxDefaultPosition, wxDefaultSize, wxBU_LEFT | wxBU_EXACTFIT);
// btn->SetFont(wxGetApp().small_font());
// btn->SetBitmap(create_scaled_bitmap(this, "printer"));
PrusaButton* btn;
ScalableButton* btn;
add_scaled_button(parent, &btn, "printer_white", _(L(" Set ")) + dots, wxBU_LEFT | wxBU_EXACTFIT);
btn->SetFont(wxGetApp().normal_font());
@ -2157,7 +2114,6 @@ void TabPrinter::extruders_count_changed(size_t extruders_count)
* of unregular pages of a Printer Settings
*/
build_unregular_pages();
// reload_config(); // #ys_FIXME_delete_after_testing : This function is called from build_extruder_pages() now
if (is_count_changed) {
on_value_change("extruders_count", extruders_count);
@ -3029,12 +2985,9 @@ wxSizer* Tab::compatible_widget_create(wxWindow* parent, PresetDependencies &dep
{
deps.checkbox = new wxCheckBox(parent, wxID_ANY, _(L("All")));
deps.checkbox->SetFont(Slic3r::GUI::wxGetApp().normal_font());
// deps.btn = new wxButton(parent, wxID_ANY, _(L(" Set "))+dots, wxDefaultPosition, wxDefaultSize, wxBU_LEFT | wxBU_EXACTFIT);
add_scaled_button(parent, &deps.btn, "printer_white", _(L(" Set ")) + dots, wxBU_LEFT | wxBU_EXACTFIT);
deps.btn->SetFont(Slic3r::GUI::wxGetApp().normal_font());
// deps.btn->SetBitmap(create_scaled_bitmap(this, "printer"));
auto sizer = new wxBoxSizer(wxHORIZONTAL);
sizer->Add((deps.checkbox), 0, wxALIGN_CENTER_VERTICAL);
sizer->Add((deps.btn), 0, wxALIGN_CENTER_VERTICAL);
@ -3190,10 +3143,10 @@ void Page::update_visibility(ConfigOptionMode mode)
m_show = ret_val;
}
void Page::rescale()
void Page::msw_rescale()
{
for (auto group : m_optgroups)
group->rescale();
group->msw_rescale();
}
Field* Page::get_field(const t_config_option_key& opt_key, int opt_index /*= -1*/) const
@ -3223,14 +3176,6 @@ ConfigOptionsGroupShp Page::new_optgroup(const wxString& title, int noncommon_la
{
std::string bmp_name;
const std::vector<Option>& options = line.get_options();
// if (options.size() == 0 || options[0].opt.gui_type == "legend")
// bmp_name = "";
// else {
// auto mode = options[0].opt.mode; //we assume that we have one option per line
// bmp_name = mode == comExpert ? "mode_expert_.png" :
// mode == comAdvanced ? "mode_middle_.png" : "mode_simple_.png";
// }
// auto bmp = new wxStaticBitmap(parent, wxID_ANY, bmp_name.empty() ? wxNullBitmap : create_scaled_bitmap(parent, bmp_name));
int mode_id = int(options[0].opt.mode);
const wxBitmap& bitmap = options.size() == 0 || options[0].opt.gui_type == "legend" ? wxNullBitmap :
m_mode_bitmap_cache[mode_id].bmp();
@ -3280,7 +3225,7 @@ ConfigOptionsGroupShp Page::new_optgroup(const wxString& title, int noncommon_la
if (ctrl == nullptr)
return;
ctrl->SetBitmap(reinterpret_cast<PrusaBitmap*>(ctrl->GetClientData())->bmp());
ctrl->SetBitmap(reinterpret_cast<ScalableBitmap*>(ctrl->GetClientData())->bmp());
};
vsizer()->Add(optgroup->sizer, 0, wxEXPAND | wxALL, 10);