mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-11 16:57:53 -06:00
Custom control : fixed re-scaling for MSW
This commit is contained in:
parent
1b3c288b35
commit
e93e80166b
6 changed files with 173 additions and 79 deletions
|
@ -26,14 +26,13 @@ OG_CustomCtrl::OG_CustomCtrl( wxWindow* parent,
|
|||
if (!wxOSX)
|
||||
SetDoubleBuffered(true);// SetDoubleBuffered exists on Win and Linux/GTK, but is missing on OSX
|
||||
|
||||
// init bitmaps
|
||||
m_bmp_mode_simple = ScalableBitmap(this, "mode_simple" , wxOSX ? 10 : 12);
|
||||
m_bmp_mode_advanced = ScalableBitmap(this, "mode_advanced", wxOSX ? 10 : 12);
|
||||
m_bmp_mode_expert = ScalableBitmap(this, "mode_expert" , wxOSX ? 10 : 12);
|
||||
m_bmp_blinking = ScalableBitmap(this, "search_blink");
|
||||
m_font = wxGetApp().normal_font();
|
||||
m_em_unit = em_unit(m_parent);
|
||||
m_v_gap = lround(1.0 * m_em_unit);
|
||||
m_h_gap = lround(0.2 * m_em_unit);
|
||||
|
||||
m_v_gap = lround(1.0 * wxGetApp().em_unit());
|
||||
m_h_gap = lround(0.2 * wxGetApp().em_unit());
|
||||
m_bmp_mode_sz = create_scaled_bitmap("mode_simple", this, wxOSX ? 10 : 12).GetSize();
|
||||
m_bmp_blinking_sz = create_scaled_bitmap("search_blink", this).GetSize();
|
||||
|
||||
init_ctrl_lines();// from og.lines()
|
||||
|
||||
|
@ -41,9 +40,6 @@ OG_CustomCtrl::OG_CustomCtrl( wxWindow* parent,
|
|||
this->Bind(wxEVT_MOTION, &OG_CustomCtrl::OnMotion, this);
|
||||
this->Bind(wxEVT_LEFT_DOWN, &OG_CustomCtrl::OnLeftDown, this);
|
||||
this->Bind(wxEVT_LEFT_UP, &OG_CustomCtrl::OnLeftUp, this);
|
||||
|
||||
const wxFont& font = wxGetApp().normal_font();
|
||||
m_font = wxOSX ? font.Smaller() : font;
|
||||
}
|
||||
|
||||
void OG_CustomCtrl::init_ctrl_lines()
|
||||
|
@ -58,9 +54,8 @@ void OG_CustomCtrl::init_ctrl_lines()
|
|||
)
|
||||
continue;
|
||||
|
||||
auto option_set = line.get_options();
|
||||
|
||||
wxCoord height = 0;
|
||||
const std::vector<Option>& option_set = line.get_options();
|
||||
wxCoord height;
|
||||
|
||||
// if we have a single option with no label, no sidetext just add it directly to sizer
|
||||
if (option_set.size() == 1 && opt_group->label_width == 0 && option_set.front().opt.full_width &&
|
||||
|
@ -68,13 +63,13 @@ void OG_CustomCtrl::init_ctrl_lines()
|
|||
option_set.front().opt.sidetext.size() == 0 && option_set.front().side_widget == nullptr &&
|
||||
line.get_extra_widgets().size() == 0)
|
||||
{
|
||||
height = m_bmp_blinking.bmp().GetHeight() + m_v_gap;
|
||||
height = m_bmp_blinking_sz.GetHeight() + m_v_gap;
|
||||
ctrl_lines.emplace_back(CtrlLine{ height, this, line, true });
|
||||
}
|
||||
else if (opt_group->label_width != 0 && !line.label.IsEmpty())
|
||||
{
|
||||
wxSize label_sz = GetTextExtent(line.label);
|
||||
height = label_sz.y * (label_sz.GetWidth() > (opt_group->label_width*wxGetApp().em_unit()) ? 2 : 1) + m_v_gap;
|
||||
height = label_sz.y * (label_sz.GetWidth() > int(opt_group->label_width * m_em_unit) ? 2 : 1) + m_v_gap;
|
||||
ctrl_lines.emplace_back(CtrlLine{ height, this, line });
|
||||
}
|
||||
else
|
||||
|
@ -98,7 +93,7 @@ wxPoint OG_CustomCtrl::get_pos(const Line& line, Field* field_in/* = nullptr*/)
|
|||
for (auto ctrl_line : ctrl_lines) {
|
||||
if (&ctrl_line.og_line == &line)
|
||||
{
|
||||
h_pos = m_bmp_mode_simple.bmp().GetWidth() + m_h_gap;
|
||||
h_pos = m_bmp_mode_sz.GetWidth() + m_h_gap;
|
||||
if (line.near_label_widget_win) {
|
||||
wxSize near_label_widget_sz = line.near_label_widget_win->GetSize();
|
||||
if (field_in)
|
||||
|
@ -109,18 +104,20 @@ wxPoint OG_CustomCtrl::get_pos(const Line& line, Field* field_in/* = nullptr*/)
|
|||
|
||||
wxString label = line.label;
|
||||
if (opt_group->label_width != 0 && !label.IsEmpty())
|
||||
h_pos += opt_group->label_width * wxGetApp().em_unit() + m_h_gap;
|
||||
h_pos += opt_group->label_width * m_em_unit + m_h_gap;
|
||||
|
||||
if (line.widget)
|
||||
break;
|
||||
|
||||
int action_buttons_width = 3 * (m_bmp_blinking_sz.GetWidth() + m_h_gap);
|
||||
|
||||
// If we have a single option with no sidetext
|
||||
const std::vector<Option>& option_set = line.get_options();
|
||||
if (option_set.size() == 1 && option_set.front().opt.sidetext.size() == 0 &&
|
||||
option_set.front().opt.label.empty() &&
|
||||
option_set.front().side_widget == nullptr && line.get_extra_widgets().size() == 0)
|
||||
{
|
||||
h_pos += 3 * (m_bmp_blinking.bmp().GetWidth() + m_h_gap);
|
||||
h_pos += action_buttons_width;
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -138,7 +135,7 @@ wxPoint OG_CustomCtrl::get_pos(const Line& line, Field* field_in/* = nullptr*/)
|
|||
dc.SetFont(m_font);
|
||||
h_pos += dc.GetMultiLineTextExtent(label).x + m_h_gap;
|
||||
}
|
||||
h_pos += 3 * (m_bmp_blinking.bmp().GetWidth() + m_h_gap);
|
||||
h_pos += action_buttons_width;
|
||||
|
||||
if (field == field_in)
|
||||
break;
|
||||
|
@ -149,10 +146,10 @@ wxPoint OG_CustomCtrl::get_pos(const Line& line, Field* field_in/* = nullptr*/)
|
|||
|
||||
// add sidetext if any
|
||||
if (!option.sidetext.empty() || opt_group->sidetext_width > 0)
|
||||
h_pos += opt_group->sidetext_width * wxGetApp().em_unit() + m_h_gap;
|
||||
h_pos += opt_group->sidetext_width * m_em_unit + m_h_gap;
|
||||
|
||||
if (opt.opt_id != option_set.back().opt_id) //! istead of (opt != option_set.back())
|
||||
h_pos += lround(0.6 * wxGetApp().em_unit());
|
||||
h_pos += lround(0.6 * m_em_unit);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -254,17 +251,72 @@ void OG_CustomCtrl::correct_widgets_position(wxSizer* widget, const Line& line,
|
|||
|
||||
void OG_CustomCtrl::msw_rescale()
|
||||
{
|
||||
const wxFont& font = GUI::wxGetApp().normal_font();
|
||||
m_font = wxOSX ? font.Smaller() : font;
|
||||
m_font = wxGetApp().normal_font();
|
||||
m_em_unit = em_unit(m_parent);
|
||||
m_v_gap = lround(1.0 * m_em_unit);
|
||||
m_h_gap = lround(0.2 * m_em_unit);
|
||||
|
||||
m_bmp_mode_sz = create_scaled_bitmap("mode_simple", this, wxOSX ? 10 : 12).GetSize();
|
||||
m_bmp_blinking_sz = create_scaled_bitmap("search_blink", this).GetSize();
|
||||
|
||||
wxCoord v_pos = 0;
|
||||
for (CtrlLine& line : ctrl_lines) {
|
||||
line.msw_rescale();
|
||||
if (line.is_visible)
|
||||
v_pos += (wxCoord)line.height;
|
||||
}
|
||||
this->SetMinSize(wxSize(wxDefaultCoord, v_pos));
|
||||
|
||||
wxSize new_sz = GUI::wxGetApp().em_unit() * this->GetSize();
|
||||
SetMinSize(new_sz);
|
||||
GetParent()->Layout();
|
||||
}
|
||||
|
||||
void OG_CustomCtrl::sys_color_changed()
|
||||
{
|
||||
msw_rescale();
|
||||
}
|
||||
|
||||
void OG_CustomCtrl::CtrlLine::correct_items_positions()
|
||||
{
|
||||
if (draw_just_act_buttons || !is_visible)
|
||||
return;
|
||||
|
||||
if (og_line.near_label_widget_win)
|
||||
ctrl->correct_window_position(og_line.near_label_widget_win, og_line);
|
||||
if (og_line.widget_sizer)
|
||||
ctrl->correct_widgets_position(og_line.widget_sizer, og_line);
|
||||
if (og_line.extra_widget_sizer)
|
||||
ctrl->correct_widgets_position(og_line.extra_widget_sizer, og_line);
|
||||
|
||||
const std::vector<Option>& option_set = og_line.get_options();
|
||||
for (auto opt : option_set) {
|
||||
Field* field = ctrl->opt_group->get_field(opt.opt_id);
|
||||
if (!field)
|
||||
continue;
|
||||
if (field->getSizer())
|
||||
ctrl->correct_widgets_position(field->getSizer(), og_line, field);
|
||||
else if (field->getWindow())
|
||||
ctrl->correct_window_position(field->getWindow(), og_line, field);
|
||||
}
|
||||
}
|
||||
|
||||
void OG_CustomCtrl::CtrlLine::msw_rescale()
|
||||
{
|
||||
// if we have a single option with no label, no sidetext
|
||||
if (draw_just_act_buttons)
|
||||
height = create_scaled_bitmap("empty").GetHeight();
|
||||
|
||||
if (ctrl->opt_group->label_width != 0 && !og_line.label.IsEmpty()) {
|
||||
wxSize label_sz = ctrl->GetTextExtent(og_line.label);
|
||||
height = label_sz.y * (label_sz.GetWidth() > int(ctrl->opt_group->label_width * ctrl->m_em_unit) ? 2 : 1) + ctrl->m_v_gap;
|
||||
}
|
||||
|
||||
if (og_line.get_options().front().opt.full_width) {
|
||||
Field* field = ctrl->opt_group->get_field(og_line.get_options().front().opt_id);
|
||||
if (field->getWindow())
|
||||
field->getWindow()->SetSize(wxSize(3 * Field::def_width_wider() * ctrl->m_em_unit, -1));
|
||||
}
|
||||
|
||||
correct_items_positions();
|
||||
}
|
||||
|
||||
void OG_CustomCtrl::CtrlLine::update_visibility(ConfigOptionMode mode)
|
||||
|
@ -277,21 +329,12 @@ void OG_CustomCtrl::CtrlLine::update_visibility(ConfigOptionMode mode)
|
|||
if (draw_just_act_buttons)
|
||||
return;
|
||||
|
||||
if (og_line.near_label_widget_win) {
|
||||
if (og_line.near_label_widget_win)
|
||||
og_line.near_label_widget_win->Show(is_visible);
|
||||
if (is_visible)
|
||||
ctrl->correct_window_position(og_line.near_label_widget_win, og_line);
|
||||
}
|
||||
if (og_line.widget_sizer) {
|
||||
if (og_line.widget_sizer)
|
||||
og_line.widget_sizer->ShowItems(is_visible);
|
||||
if (is_visible)
|
||||
ctrl->correct_widgets_position(og_line.widget_sizer, og_line);
|
||||
}
|
||||
if (og_line.extra_widget_sizer) {
|
||||
if (og_line.extra_widget_sizer)
|
||||
og_line.extra_widget_sizer->ShowItems(is_visible);
|
||||
if (is_visible)
|
||||
ctrl->correct_widgets_position(og_line.extra_widget_sizer, og_line);
|
||||
}
|
||||
|
||||
for (auto opt : option_set) {
|
||||
Field* field = ctrl->opt_group->get_field(opt.opt_id);
|
||||
|
@ -299,30 +342,25 @@ void OG_CustomCtrl::CtrlLine::update_visibility(ConfigOptionMode mode)
|
|||
continue;
|
||||
|
||||
if (field->getSizer()) {
|
||||
if (is_visible)
|
||||
ctrl->correct_widgets_position(field->getSizer(), og_line, field);
|
||||
|
||||
auto children = field->getSizer()->GetChildren();
|
||||
for (auto child : children)
|
||||
if (child->IsWindow())
|
||||
child->GetWindow()->Show(is_visible);
|
||||
}
|
||||
else if (field->getWindow()) {
|
||||
if (is_visible)
|
||||
ctrl->correct_window_position(field->getWindow(), og_line, field);
|
||||
else if (field->getWindow())
|
||||
field->getWindow()->Show(is_visible);
|
||||
}
|
||||
}
|
||||
|
||||
correct_items_positions();
|
||||
}
|
||||
|
||||
void OG_CustomCtrl::CtrlLine::render(wxDC& dc, wxCoord v_pos)
|
||||
{
|
||||
Field* field = nullptr;
|
||||
field = ctrl->opt_group->get_field(og_line.get_options().front().opt_id);
|
||||
Field* field = ctrl->opt_group->get_field(og_line.get_options().front().opt_id);
|
||||
|
||||
if (draw_just_act_buttons) {
|
||||
if (field)
|
||||
draw_act_bmps(dc, wxPoint(0, v_pos), ctrl->m_bmp_blinking.bmp(), field->undo_to_sys_bitmap()->bmp(), field->undo_bitmap()->bmp());
|
||||
draw_act_bmps(dc, wxPoint(0, v_pos), field->undo_to_sys_bitmap()->bmp(), field->undo_bitmap()->bmp());
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -336,7 +374,7 @@ void OG_CustomCtrl::CtrlLine::render(wxDC& dc, wxCoord v_pos)
|
|||
wxString label = og_line.label;
|
||||
if (ctrl->opt_group->label_width != 0 && !label.IsEmpty()) {
|
||||
const wxColour* text_clr = (option_set.size() == 1 && field ? field->label_color() : og_line.full_Label_color);
|
||||
h_pos = draw_text(dc, wxPoint(h_pos, v_pos), label + ":", text_clr, ctrl->opt_group->label_width * wxGetApp().em_unit());
|
||||
h_pos = draw_text(dc, wxPoint(h_pos, v_pos), label + ":", text_clr, ctrl->opt_group->label_width * ctrl->m_em_unit);
|
||||
}
|
||||
|
||||
// If there's a widget, build it and add the result to the sizer.
|
||||
|
@ -352,7 +390,7 @@ void OG_CustomCtrl::CtrlLine::render(wxDC& dc, wxCoord v_pos)
|
|||
option_set.front().side_widget == nullptr && og_line.get_extra_widgets().size() == 0)
|
||||
{
|
||||
if (field)
|
||||
draw_act_bmps(dc, wxPoint(h_pos, v_pos), ctrl->m_bmp_blinking.bmp(), field->undo_to_sys_bitmap()->bmp(), field->undo_bitmap()->bmp());
|
||||
draw_act_bmps(dc, wxPoint(h_pos, v_pos), field->undo_to_sys_bitmap()->bmp(), field->undo_bitmap()->bmp());
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -366,11 +404,11 @@ void OG_CustomCtrl::CtrlLine::render(wxDC& dc, wxCoord v_pos)
|
|||
_CTX(option.label, "Layers") : _(option.label);
|
||||
label += ":";
|
||||
|
||||
h_pos = draw_text(dc, wxPoint(h_pos, v_pos), label, field ? field->label_color() : nullptr, ctrl->opt_group->sublabel_width * wxGetApp().em_unit());
|
||||
h_pos = draw_text(dc, wxPoint(h_pos, v_pos), label, field ? field->label_color() : nullptr, ctrl->opt_group->sublabel_width * ctrl->m_em_unit);
|
||||
}
|
||||
|
||||
if (field) {
|
||||
h_pos = draw_act_bmps(dc, wxPoint(h_pos, v_pos), ctrl->m_bmp_blinking.bmp(), field->undo_to_sys_bitmap()->bmp(), field->undo_bitmap()->bmp());
|
||||
h_pos = draw_act_bmps(dc, wxPoint(h_pos, v_pos), field->undo_to_sys_bitmap()->bmp(), field->undo_bitmap()->bmp());
|
||||
if (field->getSizer())
|
||||
{
|
||||
auto children = field->getSizer()->GetChildren();
|
||||
|
@ -388,19 +426,19 @@ void OG_CustomCtrl::CtrlLine::render(wxDC& dc, wxCoord v_pos)
|
|||
|
||||
// add sidetext if any
|
||||
if (!option.sidetext.empty() || ctrl->opt_group->sidetext_width > 0)
|
||||
h_pos = draw_text(dc, wxPoint(h_pos, v_pos), _(option.sidetext), nullptr, ctrl->opt_group->sidetext_width * wxGetApp().em_unit());
|
||||
h_pos = draw_text(dc, wxPoint(h_pos, v_pos), _(option.sidetext), nullptr, ctrl->opt_group->sidetext_width * ctrl->m_em_unit);
|
||||
|
||||
if (opt.opt_id != option_set.back().opt_id) //! istead of (opt != option_set.back())
|
||||
h_pos += lround(0.6 * wxGetApp().em_unit());
|
||||
h_pos += lround(0.6 * ctrl->m_em_unit);
|
||||
}
|
||||
}
|
||||
|
||||
wxCoord OG_CustomCtrl::CtrlLine::draw_mode_bmp(wxDC& dc, wxCoord v_pos)
|
||||
{
|
||||
ConfigOptionMode mode = og_line.get_options()[0].opt.mode;
|
||||
const wxBitmap& bmp = mode == ConfigOptionMode::comSimple ? ctrl->m_bmp_mode_simple.bmp() :
|
||||
mode == ConfigOptionMode::comAdvanced ? ctrl->m_bmp_mode_advanced.bmp() : ctrl->m_bmp_mode_expert.bmp();
|
||||
|
||||
const std::string& bmp_name = mode == ConfigOptionMode::comSimple ? "mode_simple" :
|
||||
mode == ConfigOptionMode::comAdvanced ? "mode_advanced" : "mode_expert";
|
||||
wxBitmap bmp = create_scaled_bitmap(bmp_name, ctrl, wxOSX ? 10 : 12);
|
||||
wxCoord y_draw = v_pos + lround((height - bmp.GetHeight()) / 2);
|
||||
|
||||
dc.DrawBitmap(bmp, 0, y_draw);
|
||||
|
@ -452,8 +490,9 @@ wxCoord OG_CustomCtrl::CtrlLine::draw_text(wxDC& dc, wxPoint pos, const wxStr
|
|||
return pos.x + width + ctrl->m_h_gap;
|
||||
}
|
||||
|
||||
wxCoord OG_CustomCtrl::CtrlLine::draw_act_bmps(wxDC& dc, wxPoint pos, const wxBitmap& bmp_blinking, const wxBitmap& bmp_undo_to_sys, const wxBitmap& bmp_undo)
|
||||
wxCoord OG_CustomCtrl::CtrlLine::draw_act_bmps(wxDC& dc, wxPoint pos, const wxBitmap& bmp_undo_to_sys, const wxBitmap& bmp_undo)
|
||||
{
|
||||
wxBitmap bmp_blinking = create_scaled_bitmap("search_blink", ctrl);
|
||||
wxCoord h_pos = pos.x;
|
||||
wxCoord pos_y = pos.y + lround((height - bmp_blinking.GetHeight()) / 2);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue