mirror of
https://git.mirrors.martin98.com/https://github.com/prusa3d/PrusaSlicer.git
synced 2025-05-07 16:59:10 +08:00
Mac: Retina OpenGL: Fix ImGui font switch, dynamic switching, toolbar fixes
This commit is contained in:
parent
d1c569dd57
commit
3df1ed8f6b
@ -3952,11 +3952,6 @@ GLCanvas3D::GLCanvas3D(wxGLCanvas* canvas)
|
|||||||
|
|
||||||
#if ENABLE_RETINA_GL
|
#if ENABLE_RETINA_GL
|
||||||
m_retina_helper.reset(new RetinaHelper(canvas));
|
m_retina_helper.reset(new RetinaHelper(canvas));
|
||||||
|
|
||||||
const bool use_retina = wxGetApp().app_config->get("use_retina_opengl") == "1";
|
|
||||||
BOOST_LOG_TRIVIAL(debug) << "GLCanvas3D: Use Retina OpenGL: " << use_retina;
|
|
||||||
m_retina_helper->set_use_retina(use_retina);
|
|
||||||
BOOST_LOG_TRIVIAL(debug) << "GLCanvas3D: Scaling factor: " << m_retina_helper->get_scale_factor();
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -5947,6 +5942,26 @@ void GLCanvas3D::handle_sidebar_focus_event(const std::string& opt_key, bool foc
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GLCanvas3D::update_ui_from_settings()
|
||||||
|
{
|
||||||
|
#if ENABLE_RETINA_GL
|
||||||
|
const float orig_scaling = m_retina_helper->get_scale_factor();
|
||||||
|
|
||||||
|
const bool use_retina = wxGetApp().app_config->get("use_retina_opengl") == "1";
|
||||||
|
BOOST_LOG_TRIVIAL(debug) << "GLCanvas3D: Use Retina OpenGL: " << use_retina;
|
||||||
|
m_retina_helper->set_use_retina(use_retina);
|
||||||
|
const float new_scaling = m_retina_helper->get_scale_factor();
|
||||||
|
|
||||||
|
if (new_scaling != orig_scaling) {
|
||||||
|
BOOST_LOG_TRIVIAL(debug) << "GLCanvas3D: Scaling factor: " << new_scaling;
|
||||||
|
|
||||||
|
m_camera.zoom /= orig_scaling;
|
||||||
|
m_camera.zoom *= new_scaling;
|
||||||
|
_refresh_if_shown_on_screen();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
bool GLCanvas3D::_is_shown_on_screen() const
|
bool GLCanvas3D::_is_shown_on_screen() const
|
||||||
{
|
{
|
||||||
return (m_canvas != nullptr) ? m_canvas->IsShownOnScreen() : false;
|
return (m_canvas != nullptr) ? m_canvas->IsShownOnScreen() : false;
|
||||||
|
@ -1070,6 +1070,8 @@ public:
|
|||||||
|
|
||||||
void handle_sidebar_focus_event(const std::string& opt_key, bool focus_on);
|
void handle_sidebar_focus_event(const std::string& opt_key, bool focus_on);
|
||||||
|
|
||||||
|
void update_ui_from_settings();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool _is_shown_on_screen() const;
|
bool _is_shown_on_screen() const;
|
||||||
#if !ENABLE_REWORKED_BED_SHAPE_CHANGE
|
#if !ENABLE_REWORKED_BED_SHAPE_CHANGE
|
||||||
|
@ -468,12 +468,12 @@ float GLToolbar::get_width_horizontal() const
|
|||||||
|
|
||||||
float GLToolbar::get_width_vertical() const
|
float GLToolbar::get_width_vertical() const
|
||||||
{
|
{
|
||||||
return 2.0f * m_layout.border + m_icons_texture.metadata.icon_size * m_layout.icons_scale;
|
return 2.0f * m_layout.border * m_layout.icons_scale + m_icons_texture.metadata.icon_size * m_layout.icons_scale;
|
||||||
}
|
}
|
||||||
|
|
||||||
float GLToolbar::get_height_horizontal() const
|
float GLToolbar::get_height_horizontal() const
|
||||||
{
|
{
|
||||||
return 2.0f * m_layout.border + m_icons_texture.metadata.icon_size * m_layout.icons_scale;
|
return 2.0f * m_layout.border * m_layout.icons_scale + m_icons_texture.metadata.icon_size * m_layout.icons_scale;
|
||||||
}
|
}
|
||||||
|
|
||||||
float GLToolbar::get_height_vertical() const
|
float GLToolbar::get_height_vertical() const
|
||||||
@ -483,23 +483,25 @@ float GLToolbar::get_height_vertical() const
|
|||||||
|
|
||||||
float GLToolbar::get_main_size() const
|
float GLToolbar::get_main_size() const
|
||||||
{
|
{
|
||||||
float size = 2.0f * m_layout.border;
|
float size = 2.0f * m_layout.border * m_layout.icons_scale;
|
||||||
for (unsigned int i = 0; i < (unsigned int)m_items.size(); ++i)
|
for (unsigned int i = 0; i < (unsigned int)m_items.size(); ++i)
|
||||||
{
|
{
|
||||||
if (m_items[i]->is_separator())
|
if (m_items[i]->is_separator())
|
||||||
size += m_layout.separator_size;
|
size += m_layout.separator_size * m_layout.icons_scale;
|
||||||
else
|
else
|
||||||
size += (float)m_icons_texture.metadata.icon_size * m_layout.icons_scale;
|
size += (float)m_icons_texture.metadata.icon_size * m_layout.icons_scale;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_items.size() > 1)
|
if (m_items.size() > 1)
|
||||||
size += ((float)m_items.size() - 1.0f) * m_layout.gap_size;
|
size += ((float)m_items.size() - 1.0f) * m_layout.gap_size * m_layout.icons_scale;
|
||||||
|
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string GLToolbar::update_hover_state_horizontal(const Vec2d& mouse_pos, GLCanvas3D& parent)
|
std::string GLToolbar::update_hover_state_horizontal(const Vec2d& mouse_pos, GLCanvas3D& parent)
|
||||||
{
|
{
|
||||||
|
// Note: m_layout.icons_scale is not applied here because mouse_pos is already in scaled coordinates
|
||||||
|
|
||||||
float zoom = parent.get_camera_zoom();
|
float zoom = parent.get_camera_zoom();
|
||||||
float inv_zoom = (zoom != 0.0f) ? 1.0f / zoom : 0.0f;
|
float inv_zoom = (zoom != 0.0f) ? 1.0f / zoom : 0.0f;
|
||||||
|
|
||||||
@ -591,6 +593,8 @@ std::string GLToolbar::update_hover_state_horizontal(const Vec2d& mouse_pos, GLC
|
|||||||
|
|
||||||
std::string GLToolbar::update_hover_state_vertical(const Vec2d& mouse_pos, GLCanvas3D& parent)
|
std::string GLToolbar::update_hover_state_vertical(const Vec2d& mouse_pos, GLCanvas3D& parent)
|
||||||
{
|
{
|
||||||
|
// Note: m_layout.icons_scale is not applied here because mouse_pos is already in scaled coordinates
|
||||||
|
|
||||||
float zoom = parent.get_camera_zoom();
|
float zoom = parent.get_camera_zoom();
|
||||||
float inv_zoom = (zoom != 0.0f) ? 1.0f / zoom : 0.0f;
|
float inv_zoom = (zoom != 0.0f) ? 1.0f / zoom : 0.0f;
|
||||||
|
|
||||||
@ -774,11 +778,12 @@ void GLToolbar::render_horizontal(const GLCanvas3D& parent) const
|
|||||||
|
|
||||||
float zoom = parent.get_camera_zoom();
|
float zoom = parent.get_camera_zoom();
|
||||||
float inv_zoom = (zoom != 0.0f) ? 1.0f / zoom : 0.0f;
|
float inv_zoom = (zoom != 0.0f) ? 1.0f / zoom : 0.0f;
|
||||||
|
float factor = inv_zoom * m_layout.icons_scale;
|
||||||
|
|
||||||
float scaled_icons_size = (float)m_icons_texture.metadata.icon_size * m_layout.icons_scale * inv_zoom;
|
float scaled_icons_size = (float)m_icons_texture.metadata.icon_size * factor;
|
||||||
float scaled_separator_size = m_layout.separator_size * inv_zoom;
|
float scaled_separator_size = m_layout.separator_size * factor;
|
||||||
float scaled_gap_size = m_layout.gap_size * inv_zoom;
|
float scaled_gap_size = m_layout.gap_size * factor;
|
||||||
float scaled_border = m_layout.border * inv_zoom;
|
float scaled_border = m_layout.border * factor;
|
||||||
float scaled_width = get_width() * inv_zoom;
|
float scaled_width = get_width() * inv_zoom;
|
||||||
float scaled_height = get_height() * inv_zoom;
|
float scaled_height = get_height() * inv_zoom;
|
||||||
|
|
||||||
@ -899,11 +904,12 @@ void GLToolbar::render_vertical(const GLCanvas3D& parent) const
|
|||||||
|
|
||||||
float zoom = parent.get_camera_zoom();
|
float zoom = parent.get_camera_zoom();
|
||||||
float inv_zoom = (zoom != 0.0f) ? 1.0f / zoom : 0.0f;
|
float inv_zoom = (zoom != 0.0f) ? 1.0f / zoom : 0.0f;
|
||||||
|
float factor = inv_zoom * m_layout.icons_scale;
|
||||||
|
|
||||||
float scaled_icons_size = (float)m_icons_texture.metadata.icon_size * m_layout.icons_scale * inv_zoom;
|
float scaled_icons_size = (float)m_icons_texture.metadata.icon_size * m_layout.icons_scale * factor;
|
||||||
float scaled_separator_size = m_layout.separator_size * inv_zoom;
|
float scaled_separator_size = m_layout.separator_size * factor;
|
||||||
float scaled_gap_size = m_layout.gap_size * inv_zoom;
|
float scaled_gap_size = m_layout.gap_size * factor;
|
||||||
float scaled_border = m_layout.border * inv_zoom;
|
float scaled_border = m_layout.border * factor;
|
||||||
float scaled_width = get_width() * inv_zoom;
|
float scaled_width = get_width() * inv_zoom;
|
||||||
float scaled_height = get_height() * inv_zoom;
|
float scaled_height = get_height() * inv_zoom;
|
||||||
|
|
||||||
|
@ -109,6 +109,7 @@ public:
|
|||||||
virtual ~Preview();
|
virtual ~Preview();
|
||||||
|
|
||||||
wxGLCanvas* get_wxglcanvas() { return m_canvas_widget; }
|
wxGLCanvas* get_wxglcanvas() { return m_canvas_widget; }
|
||||||
|
GLCanvas3D* get_canvas3d() { return m_canvas; }
|
||||||
|
|
||||||
void set_view_toolbar(GLToolbar* toolbar);
|
void set_view_toolbar(GLToolbar* toolbar);
|
||||||
|
|
||||||
|
@ -205,6 +205,8 @@ void ImGuiWrapper::init_default_font(float scaling)
|
|||||||
{
|
{
|
||||||
static const float font_size = 18.0f;
|
static const float font_size = 18.0f;
|
||||||
|
|
||||||
|
destroy_fonts_texture();
|
||||||
|
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
io.Fonts->Clear();
|
io.Fonts->Clear();
|
||||||
ImFont* font = io.Fonts->AddFontFromFileTTF((Slic3r::resources_dir() + "/fonts/NotoSans-Regular.ttf").c_str(), font_size * scaling);
|
ImFont* font = io.Fonts->AddFontFromFileTTF((Slic3r::resources_dir() + "/fonts/NotoSans-Regular.ttf").c_str(), font_size * scaling);
|
||||||
|
@ -1266,6 +1266,11 @@ void Plater::priv::update_ui_from_settings()
|
|||||||
// $self->{buttons_sizer}->Show($self->{btn_reslice}, ! wxTheApp->{app_config}->get("background_processing"));
|
// $self->{buttons_sizer}->Show($self->{btn_reslice}, ! wxTheApp->{app_config}->get("background_processing"));
|
||||||
// $self->{buttons_sizer}->Layout;
|
// $self->{buttons_sizer}->Layout;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
#if ENABLE_RETINA_GL
|
||||||
|
view3D->get_canvas3d()->update_ui_from_settings();
|
||||||
|
preview->get_canvas3d()->update_ui_from_settings();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
ProgressStatusBar* Plater::priv::statusbar()
|
ProgressStatusBar* Plater::priv::statusbar()
|
||||||
|
@ -122,8 +122,7 @@ void PreferencesDialog::build()
|
|||||||
void PreferencesDialog::accept()
|
void PreferencesDialog::accept()
|
||||||
{
|
{
|
||||||
if (m_values.find("no_defaults") != m_values.end() ||
|
if (m_values.find("no_defaults") != m_values.end() ||
|
||||||
m_values.find("use_legacy_opengl") != m_values.end() ||
|
m_values.find("use_legacy_opengl") != m_values.end()) {
|
||||||
m_values.find("use_retina_opengl") != m_values.end()) {
|
|
||||||
warning_catcher(this, _(L("You need to restart Slic3r to make the changes effective.")));
|
warning_catcher(this, _(L("You need to restart Slic3r to make the changes effective.")));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user