mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-11 16:57:53 -06:00
imgui: More refactoring, cut gizmo window positioning
This commit is contained in:
parent
145b8fd0df
commit
c542413962
4 changed files with 24 additions and 30 deletions
|
@ -4405,12 +4405,12 @@ void GLCanvas3D::_resize(unsigned int w, unsigned int h)
|
||||||
|
|
||||||
auto *imgui = wxGetApp().imgui();
|
auto *imgui = wxGetApp().imgui();
|
||||||
imgui->set_display_size((float)w, (float)h);
|
imgui->set_display_size((float)w, (float)h);
|
||||||
imgui->set_font_size(m_canvas->GetFont().GetPixelSize().y);
|
|
||||||
#if ENABLE_RETINA_GL
|
#if ENABLE_RETINA_GL
|
||||||
imgui->set_style_scaling(m_retina_helper->get_scale_factor());
|
const float scaling = m_retina_helper->get_scale_factor();
|
||||||
#else
|
#else
|
||||||
imgui->set_style_scaling(m_canvas->GetContentScaleFactor());
|
const float scaling = m_canvas->GetContentScaleFactor();
|
||||||
#endif
|
#endif
|
||||||
|
imgui->set_scaling(m_canvas->GetFont().GetPixelSize().y, scaling);
|
||||||
|
|
||||||
// ensures that this canvas is current
|
// ensures that this canvas is current
|
||||||
_set_current();
|
_set_current();
|
||||||
|
|
|
@ -185,7 +185,10 @@ void GLGizmoCut::on_render_for_picking(const Selection& selection) const
|
||||||
|
|
||||||
void GLGizmoCut::on_render_input_window(float x, float y, float bottom_limit, const Selection& selection)
|
void GLGizmoCut::on_render_input_window(float x, float y, float bottom_limit, const Selection& selection)
|
||||||
{
|
{
|
||||||
|
const float approx_height = m_imgui->scaled(11.0f);
|
||||||
|
y = std::min(y, bottom_limit - approx_height);
|
||||||
m_imgui->set_next_window_pos(x, y, ImGuiCond_Always);
|
m_imgui->set_next_window_pos(x, y, ImGuiCond_Always);
|
||||||
|
|
||||||
m_imgui->set_next_window_bg_alpha(0.5f);
|
m_imgui->set_next_window_bg_alpha(0.5f);
|
||||||
m_imgui->begin(_(L("Cut")), ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse);
|
m_imgui->begin(_(L("Cut")), ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse);
|
||||||
|
|
||||||
|
|
|
@ -92,21 +92,18 @@ void ImGuiWrapper::set_display_size(float w, float h)
|
||||||
io.DisplayFramebufferScale = ImVec2(1.0f, 1.0f);
|
io.DisplayFramebufferScale = ImVec2(1.0f, 1.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ImGuiWrapper::set_font_size(float font_size)
|
void ImGuiWrapper::set_scaling(float font_size, float scaling)
|
||||||
{
|
{
|
||||||
if (m_font_size != font_size) {
|
if (m_font_size == font_size && m_style_scaling == scaling) {
|
||||||
m_font_size = font_size;
|
return;
|
||||||
destroy_font();
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
void ImGuiWrapper::set_style_scaling(float scaling)
|
m_font_size = font_size;
|
||||||
{
|
|
||||||
if (!std::isnan(scaling) && !std::isinf(scaling) && scaling != m_style_scaling) {
|
ImGui::GetStyle().ScaleAllSizes(scaling / m_style_scaling);
|
||||||
ImGui::GetStyle().ScaleAllSizes(scaling / m_style_scaling);
|
m_style_scaling = scaling;
|
||||||
m_style_scaling = scaling;
|
|
||||||
destroy_font();
|
destroy_font();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ImGuiWrapper::update_mouse_data(wxMouseEvent& evt)
|
bool ImGuiWrapper::update_mouse_data(wxMouseEvent& evt)
|
||||||
|
@ -163,8 +160,6 @@ bool ImGuiWrapper::update_key_data(wxKeyEvent &evt)
|
||||||
|
|
||||||
void ImGuiWrapper::new_frame()
|
void ImGuiWrapper::new_frame()
|
||||||
{
|
{
|
||||||
printf("ImGuiWrapper: new_frame()\n");
|
|
||||||
|
|
||||||
if (m_new_frame_open) {
|
if (m_new_frame_open) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -184,6 +179,12 @@ void ImGuiWrapper::render()
|
||||||
m_new_frame_open = false;
|
m_new_frame_open = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ImVec2 ImGuiWrapper::calc_text_size(const wxString &text)
|
||||||
|
{
|
||||||
|
auto text_utf8 = into_u8(text);
|
||||||
|
return ImGui::CalcTextSize(text_utf8.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
void ImGuiWrapper::set_next_window_pos(float x, float y, int flag)
|
void ImGuiWrapper::set_next_window_pos(float x, float y, int flag)
|
||||||
{
|
{
|
||||||
ImGui::SetNextWindowPos(ImVec2(x, y), (ImGuiCond)flag);
|
ImGui::SetNextWindowPos(ImVec2(x, y), (ImGuiCond)flag);
|
||||||
|
@ -293,12 +294,6 @@ bool ImGuiWrapper::combo(const wxString& label, const std::vector<std::string>&
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
ImVec2 ImGuiWrapper::calc_text_size(const wxString &text)
|
|
||||||
{
|
|
||||||
auto text_utf8 = into_u8(text);
|
|
||||||
return ImGui::CalcTextSize(text_utf8.c_str());
|
|
||||||
}
|
|
||||||
|
|
||||||
void ImGuiWrapper::disabled_begin(bool disabled)
|
void ImGuiWrapper::disabled_begin(bool disabled)
|
||||||
{
|
{
|
||||||
wxCHECK_RET(!m_disabled, "ImGUI: Unbalanced disabled_begin() call");
|
wxCHECK_RET(!m_disabled, "ImGUI: Unbalanced disabled_begin() call");
|
||||||
|
@ -342,8 +337,6 @@ bool ImGuiWrapper::want_any_input() const
|
||||||
|
|
||||||
void ImGuiWrapper::init_font()
|
void ImGuiWrapper::init_font()
|
||||||
{
|
{
|
||||||
printf("ImGuiWrapper: init_font()\n");
|
|
||||||
|
|
||||||
const float font_size = m_font_size * m_style_scaling;
|
const float font_size = m_font_size * m_style_scaling;
|
||||||
|
|
||||||
destroy_font();
|
destroy_font();
|
||||||
|
|
|
@ -35,8 +35,7 @@ public:
|
||||||
|
|
||||||
void set_language(const std::string &language);
|
void set_language(const std::string &language);
|
||||||
void set_display_size(float w, float h);
|
void set_display_size(float w, float h);
|
||||||
void set_font_size(float font_size);
|
void set_scaling(float font_size, float scaling);
|
||||||
void set_style_scaling(float scaling);
|
|
||||||
bool update_mouse_data(wxMouseEvent &evt);
|
bool update_mouse_data(wxMouseEvent &evt);
|
||||||
bool update_key_data(wxKeyEvent &evt);
|
bool update_key_data(wxKeyEvent &evt);
|
||||||
|
|
||||||
|
@ -47,7 +46,8 @@ public:
|
||||||
void render();
|
void render();
|
||||||
|
|
||||||
float scaled(float x) const { return x * m_font_size * m_style_scaling; }
|
float scaled(float x) const { return x * m_font_size * m_style_scaling; }
|
||||||
ImVec2 scaled_vec(float x, float y) const { return ImVec2(x * m_font_size * m_style_scaling, y * m_font_size * m_style_scaling); }
|
ImVec2 scaled(float x, float y) const { return ImVec2(x * m_font_size * m_style_scaling, y * m_font_size * m_style_scaling); }
|
||||||
|
ImVec2 calc_text_size(const wxString &text);
|
||||||
|
|
||||||
void set_next_window_pos(float x, float y, int flag);
|
void set_next_window_pos(float x, float y, int flag);
|
||||||
void set_next_window_bg_alpha(float alpha);
|
void set_next_window_bg_alpha(float alpha);
|
||||||
|
@ -66,8 +66,6 @@ public:
|
||||||
void text(const wxString &label);
|
void text(const wxString &label);
|
||||||
bool combo(const wxString& label, const std::vector<std::string>& options, int& selection); // Use -1 to not mark any option as selected
|
bool combo(const wxString& label, const std::vector<std::string>& options, int& selection); // Use -1 to not mark any option as selected
|
||||||
|
|
||||||
ImVec2 calc_text_size(const wxString &text);
|
|
||||||
|
|
||||||
void disabled_begin(bool disabled);
|
void disabled_begin(bool disabled);
|
||||||
void disabled_end();
|
void disabled_end();
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue