#include "OG_CustomCtrl.hpp" #include "OptionsGroup.hpp" #include "ConfigExceptions.hpp" #include "Plater.hpp" #include "GUI_App.hpp" #include #include #include #include #include "libslic3r/Exception.hpp" #include "libslic3r/Utils.hpp" #include "I18N.hpp" namespace Slic3r { namespace GUI { OG_CustomCtrl::OG_CustomCtrl( wxWindow* parent, OptionsGroup* og, const wxPoint& pos /* = wxDefaultPosition*/, const wxSize& size/* = wxDefaultSize*/, const wxValidator& val /* = wxDefaultValidator*/, const wxString& name/* = wxEmptyString*/) : wxControl(parent, wxID_ANY, pos, size, wxWANTS_CHARS | wxBORDER_NONE), m_og(og) { 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_border = lround(0.2 * wxGetApp().em_unit()); m_v_gap = lround(1.0 * wxGetApp().em_unit()); m_h_gap = lround(0.2 * wxGetApp().em_unit()); init_ctrl_lines();// from og.lines() this->Bind(wxEVT_PAINT, &OG_CustomCtrl::OnPaint, this); 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() { wxCoord v_pos = 0; for (const Line& line : m_og->get_lines()) { if (line.full_width && ( // description line line.widget != nullptr || // description line with widget (button) !line.get_extra_widgets().empty()) ) continue; auto option_set = line.get_options(); wxCoord height = 0; // if we have a single option with no label, no sidetext just add it directly to sizer if (option_set.size() == 1 && m_og->label_width == 0 && option_set.front().opt.full_width && option_set.front().opt.label.empty() && 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; ctrl_lines.emplace_back(CtrlLine{ height, this, line, true }); } else if (m_og->label_width != 0 && !line.label.IsEmpty()) { wxSize label_sz = GetTextExtent(line.label); height = label_sz.y * (label_sz.GetWidth() > (m_og->label_width*wxGetApp().em_unit()) ? 2 : 1) + m_v_gap; ctrl_lines.emplace_back(CtrlLine{ height, this, line }); } else int i = 0; v_pos += height; } this->SetMinSize(wxSize(wxDefaultCoord, v_pos)); } wxPoint OG_CustomCtrl::get_pos(const Line& line, Field* field_in/* = nullptr*/) { wxCoord v_pos = 0; wxCoord h_pos = 0; for (auto ctrl_line : ctrl_lines) { if (&ctrl_line.m_og_line == &line) { h_pos = m_bmp_mode_simple.bmp().GetWidth() + m_h_gap; if (line.near_label_widget) { if (field_in) h_pos += m_bmp_blinking.bmp().GetWidth() + m_h_gap; // ysFIXME else break; } wxString label = line.label; if (m_og->label_width != 0 && !label.IsEmpty()) h_pos += m_og->label_width * wxGetApp().em_unit(); if (line.widget) break; // If we have a single option with no sidetext const std::vector