mirror of
https://git.mirrors.martin98.com/https://github.com/prusa3d/PrusaSlicer.git
synced 2025-07-31 15:52:00 +08:00
ImguiDoubleSlider: WIP: Set scale in respect to Retina displays
+ request one more frame for redraw, if value was changed with mouse wheel + some code cleaning
This commit is contained in:
parent
8e749734ff
commit
d06ef37df9
@ -51,12 +51,9 @@ namespace DoubleSlider {
|
||||
constexpr double min_delta_area = scale_(scale_(25)); // equal to 25 mm2
|
||||
constexpr double miscalculation = scale_(scale_(1)); // equal to 1 mm2
|
||||
|
||||
static const float LEFT_MARGIN = 13.0f + 100.0f; // avoid thumbnail toolbar
|
||||
static const float BTN_SZ = 24.f;
|
||||
|
||||
static const ImVec2 ONE_LAYER_OFFSET = ImVec2(41.0f, /*44*/33.0f);
|
||||
static const ImVec2 HORIZONTAL_SLIDER_SIZE = ImVec2(764.0f, 90.0f);//764 = 680 + handle_dummy_width * 2 + text_right_dummy
|
||||
static const ImVec2 VERTICAL_SLIDER_SIZE = ImVec2(105.0f, 748.0f);//748 = 680 + text_dummy_height * 2
|
||||
static const float LEFT_MARGIN = 13.0f + 100.0f; // avoid thumbnail toolbar
|
||||
static const float HORIZONTAL_SLIDER_WIDTH = 90.0f;
|
||||
static const float VERTICAL_SLIDER_HEIGHT = 105.0f;
|
||||
|
||||
bool equivalent_areas(const double& bottom_area, const double& top_area)
|
||||
{
|
||||
@ -85,7 +82,6 @@ Control::Control( wxWindow *parent,
|
||||
const wxPoint& pos,
|
||||
const wxSize& size,
|
||||
long style,
|
||||
// const wxValidator& val,
|
||||
const wxString& name) :
|
||||
wxControl(parent, id, pos, size, wxWANTS_CHARS | wxBORDER_NONE),
|
||||
m_lower_value(lowerValue),
|
||||
@ -170,12 +166,13 @@ Control::Control( wxWindow *parent,
|
||||
imgui_ctrl = ImGuiControl( lowerValue, higherValue,
|
||||
minValue, maxValue,
|
||||
ImVec2(0.f, 0.f), ImVec2(0.f, 0.f),
|
||||
style, into_u8(name), !is_horizontal());
|
||||
is_horizontal() ? 0 : ImGuiSliderFlags_Vertical,
|
||||
into_u8(name), !is_horizontal());
|
||||
|
||||
imgui_ctrl.set_get_label_cb([this](int pos) {return into_u8(get_label(pos)); });
|
||||
|
||||
if (!is_horizontal()) {
|
||||
imgui_ctrl.set_get_label_on_move_cb([this](int pos) {return into_u8(get_label(pos, ltEstimatedTime)); });
|
||||
imgui_ctrl.set_get_label_on_move_cb([this](int pos) { return m_extra_style & wxSL_VALUE_LABEL ? into_u8(get_label(pos, ltEstimatedTime)) : ""; });
|
||||
imgui_ctrl.set_extra_draw_cb([this](const ImRect& draw_rc) {return draw_ticks(draw_rc); });
|
||||
}
|
||||
|
||||
@ -605,19 +602,6 @@ using namespace ImGui;
|
||||
|
||||
// ImGuiDS
|
||||
|
||||
float Control::get_pos_from_value(int v_min, int v_max, int value, const ImRect& rect) {
|
||||
float pos_ratio = (v_max - v_min) != 0 ? ((float)(value - v_min) / (float)(v_max - v_min)) : 0.0f;
|
||||
float handle_pos;
|
||||
if (is_horizontal()) {
|
||||
handle_pos = rect.Min.x + (rect.Max.x - rect.Min.x) * pos_ratio;
|
||||
}
|
||||
else {
|
||||
pos_ratio = 1.0f - pos_ratio;
|
||||
handle_pos = rect.Min.y + (rect.Max.y - rect.Min.y) * pos_ratio;
|
||||
}
|
||||
return handle_pos;
|
||||
}
|
||||
|
||||
void Control::draw_ticks(const ImRect& slideable_region)
|
||||
{
|
||||
//if(m_draw_mode != dmRegular)
|
||||
@ -639,11 +623,8 @@ void Control::draw_ticks(const ImRect& slideable_region)
|
||||
const ImU32 tick_clr = ImGui::ColorConvertFloat4ToU32(ImGuiPureWrap::COL_ORANGE_DARK);
|
||||
const ImU32 tick_hovered_clr = ImGui::ColorConvertFloat4ToU32(ImGuiPureWrap::COL_WINDOW_BACKGROUND);
|
||||
|
||||
auto get_tick_pos = [this, slideable_region](int tick)
|
||||
{
|
||||
int v_min = GetMinValue();
|
||||
int v_max = GetMaxValue();
|
||||
return get_pos_from_value(v_min, v_max, tick, slideable_region);
|
||||
auto get_tick_pos = [this, slideable_region](int tick) {
|
||||
return imgui_ctrl.GetPositionFromValue(tick, slideable_region);
|
||||
};
|
||||
|
||||
std::set<TickCode>::const_iterator tick_it = m_ticks.ticks.begin();
|
||||
@ -744,15 +725,16 @@ void Control::draw_colored_band(const ImRect& groove, const ImRect& slideable_re
|
||||
ImRect main_band = ImRect(blank_rect);
|
||||
main_band.Expand(blank_padding);
|
||||
|
||||
auto draw_band = [](const ImU32& clr, const ImRect& band_rc)
|
||||
{
|
||||
ImGui::RenderFrame(band_rc.Min, band_rc.Max, clr, false, band_rc.GetWidth() * 0.5);
|
||||
//cover round corner
|
||||
ImGui::RenderFrame(ImVec2(band_rc.Min.x, band_rc.Max.y - band_rc.GetWidth() * 0.5), band_rc.Max, clr, false);
|
||||
};
|
||||
auto draw_band = [](const ImU32& clr, const ImRect& band_rc) {
|
||||
ImGui::RenderFrame(band_rc.Min, band_rc.Max, clr, false, band_rc.GetWidth() * 0.5);
|
||||
//cover round corner
|
||||
ImGui::RenderFrame(ImVec2(band_rc.Min.x, band_rc.Max.y - band_rc.GetWidth() * 0.5), band_rc.Max, clr, false);
|
||||
};
|
||||
|
||||
auto draw_main_band = [&main_band](const ImU32& clr) {
|
||||
ImGui::RenderFrame(main_band.Min, main_band.Max, clr, false, main_band.GetWidth() * 0.5);
|
||||
};
|
||||
};
|
||||
|
||||
//draw main colored band
|
||||
const int default_color_idx = m_mode == MultiAsSingle ? std::max<int>(m_only_extruder - 1, 0) : 0;
|
||||
std::array<float, 4>rgba = decode_color_to_float_array(m_extruder_colors[default_color_idx]);
|
||||
@ -764,28 +746,20 @@ void Control::draw_colored_band(const ImRect& groove, const ImRect& slideable_re
|
||||
while (tick_it != m_ticks.ticks.end())
|
||||
{
|
||||
//get position from tick
|
||||
tick_pos = get_pos_from_value(GetMinValue(), GetMaxValue(), tick_it->tick, slideable_region);
|
||||
tick_pos = imgui_ctrl.GetPositionFromValue(tick_it->tick, slideable_region);
|
||||
|
||||
ImRect band_rect = ImRect(ImVec2(main_band.Min.x, std::min(tick_pos, main_band.Min.y)),
|
||||
ImVec2(main_band.Max.x, std::min(tick_pos, main_band.Max.y)));
|
||||
|
||||
if (main_band.Contains(band_rect)) {
|
||||
//draw colored band
|
||||
if (tick_it->type == ToolChange) {
|
||||
if ((m_mode == SingleExtruder) || (m_mode == MultiAsSingle)) {
|
||||
const std::string clr_str = m_mode == SingleExtruder ? tick_it->color : get_color_for_tool_change_tick(tick_it);
|
||||
if (!clr_str.empty()) {
|
||||
std::array<float, 4>rgba = decode_color_to_float_array(clr_str);
|
||||
ImU32 band_clr = IM_COL32(rgba[0] * 255.0f, rgba[1] * 255.0f, rgba[2] * 255.0f, rgba[3] * 255.0f);
|
||||
if (tick_it->tick == 0)
|
||||
draw_main_band(band_clr);
|
||||
else
|
||||
draw_band(band_clr, band_rect);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (tick_it->type == ColorChange/* && m_mode == SingleExtruder*/) {
|
||||
const std::string clr_str = m_mode == SingleExtruder ? tick_it->color : get_color_for_tool_change_tick(tick_it);
|
||||
if ((m_mode == SingleExtruder && tick_it->type == ColorChange) ||
|
||||
(m_mode == MultiAsSingle && (tick_it->type == ToolChange || tick_it->type == ColorChange)))
|
||||
{
|
||||
const std::string clr_str = m_mode == SingleExtruder ? tick_it->color :
|
||||
tick_it->type == ToolChange ?
|
||||
get_color_for_tool_change_tick(tick_it) :
|
||||
get_color_for_color_change_tick(tick_it);
|
||||
|
||||
if (!clr_str.empty()) {
|
||||
std::array<float, 4>rgba = decode_color_to_float_array(clr_str);
|
||||
ImU32 band_clr = IM_COL32(rgba[0] * 255.0f, rgba[1] * 255.0f, rgba[2] * 255.0f, rgba[3] * 255.0f);
|
||||
@ -900,62 +874,67 @@ bool Control::render_button(const wchar_t btn_icon, const wchar_t btn_icon_hover
|
||||
}
|
||||
|
||||
|
||||
bool Control::imgui_render(GUI::GLCanvas3D& canvas)
|
||||
void Control::imgui_render(GUI::GLCanvas3D& canvas, float extra_scale/* = 0.1f*/)
|
||||
{
|
||||
bool result = false;
|
||||
GUI::Size cnv_size = canvas.get_canvas_size();
|
||||
m_scale = extra_scale * 0.1f * wxGetApp().em_unit();
|
||||
|
||||
int canvas_width = cnv_size.get_width();
|
||||
int canvas_height = cnv_size.get_height();
|
||||
const Size cnv_size = canvas.get_canvas_size();
|
||||
const int canvas_width = cnv_size.get_width();
|
||||
const int canvas_height = cnv_size.get_height();
|
||||
|
||||
float scale = (float)wxGetApp().em_unit() / 10.0f;
|
||||
|
||||
scale *= m_scale;
|
||||
ImVec2 pos;
|
||||
ImVec2 size;
|
||||
|
||||
const float action_btn_sz = wxGetApp().imgui()->GetTextureCustomRect(ImGui::DSRevert)->Height;
|
||||
|
||||
if (is_horizontal()) {
|
||||
pos.x = std::max(LEFT_MARGIN, 0.2f * canvas_width);
|
||||
pos.y = canvas_height - HORIZONTAL_SLIDER_SIZE.y * scale;
|
||||
size = ImVec2(canvas_width - 2 * pos.x, HORIZONTAL_SLIDER_SIZE.y * scale);
|
||||
pos.y = canvas_height - HORIZONTAL_SLIDER_WIDTH * m_scale;
|
||||
size = ImVec2(canvas_width - 2 * pos.x, HORIZONTAL_SLIDER_WIDTH * m_scale);
|
||||
imgui_ctrl.ShowLabelOnMouseMove(false);
|
||||
}
|
||||
else {
|
||||
const float tick_icon_side = wxGetApp().imgui()->GetTextureCustomRect(ImGui::PausePrint)->Height;
|
||||
|
||||
pos.x = canvas_width - VERTICAL_SLIDER_SIZE.x * scale - tick_icon_side;
|
||||
pos.y = ONE_LAYER_OFFSET.y;
|
||||
size = ImVec2(VERTICAL_SLIDER_SIZE.x * scale, canvas_height - 4 * pos.y);
|
||||
pos.x = canvas_width - VERTICAL_SLIDER_HEIGHT * m_scale - tick_icon_side;
|
||||
pos.y = 1.f * action_btn_sz;
|
||||
if (m_allow_editing)
|
||||
pos.y += 2.f;
|
||||
size = ImVec2(VERTICAL_SLIDER_HEIGHT * m_scale, canvas_height - 4.f * action_btn_sz);
|
||||
imgui_ctrl.ShowLabelOnMouseMove(true);
|
||||
}
|
||||
|
||||
imgui_ctrl.SetPos(pos);
|
||||
imgui_ctrl.SetSize(size);
|
||||
imgui_ctrl.SetScale(scale);
|
||||
imgui_ctrl.Init(pos, size, m_scale);
|
||||
|
||||
const float btn_sz = BTN_SZ*scale;
|
||||
ImVec2 btn_pos = ImVec2(pos.x + 2.7 * btn_sz, pos.y - 0.5 * btn_sz);
|
||||
if (imgui_ctrl.render(m_selection)) {
|
||||
// request one more frame if value was changes with mouse wheel
|
||||
if (GImGui->IO.MouseWheel != 0.0f)
|
||||
wxGetApp().imgui()->set_requires_extra_frame();
|
||||
|
||||
if (!is_horizontal() && !m_ticks.empty() && m_allow_editing &&
|
||||
render_button(ImGui::DSRevert, ImGui::DSRevertHovered, "revert", btn_pos, fiRevertIcon))
|
||||
discard_all_thicks();
|
||||
|
||||
if (imgui_ctrl.render(m_selection))
|
||||
SetSelectionSpan(m_is_one_layer ? imgui_ctrl.GetHigherValue() : imgui_ctrl.GetLowerValue(), imgui_ctrl.GetHigherValue());
|
||||
}
|
||||
|
||||
// draw action buttons
|
||||
if (!is_horizontal()) {
|
||||
btn_pos.y += 0.5 * btn_sz + size.y;
|
||||
const float groove_center_x = imgui_ctrl.GetGrooveRect().GetCenter().x;
|
||||
|
||||
ImVec2 btn_pos = ImVec2(groove_center_x - 0.5f * action_btn_sz, pos.y - 0.25f * action_btn_sz);
|
||||
|
||||
if (!m_ticks.empty() && m_allow_editing &&
|
||||
render_button(ImGui::DSRevert, ImGui::DSRevertHovered, "revert", btn_pos, fiRevertIcon))
|
||||
discard_all_thicks();
|
||||
|
||||
btn_pos.y += 0.1f * action_btn_sz + size.y;
|
||||
if (render_button(is_one_layer() ? ImGui::Lock : ImGui::Unlock, is_one_layer() ? ImGui::LockHovered : ImGui::UnlockHovered, "one_layer", btn_pos, fiOneLayerIcon))
|
||||
switch_one_layer_mode();
|
||||
|
||||
btn_pos.y += btn_sz;
|
||||
btn_pos.y += 1.2f * action_btn_sz;
|
||||
if (render_button(ImGui::DSSettings, ImGui::DSSettingsHovered, "settings", btn_pos, fiCogIcon))
|
||||
show_cog_icon_context_menu();
|
||||
|
||||
if (m_allow_editing)
|
||||
render_menu();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
bool Control::is_wipe_tower_layer(int tick) const
|
||||
@ -2504,7 +2483,7 @@ void Control::show_cog_icon_context_menu()
|
||||
|
||||
append_menu_item(&menu, wxID_ANY, _L("Jump to height") + " (Shift+G)", "",
|
||||
[this](wxCommandEvent&) { jump_to_value(); }, "", & menu);
|
||||
|
||||
#if 0 // old code
|
||||
wxMenu* ruler_mode_menu = new wxMenu();
|
||||
if (ruler_mode_menu) {
|
||||
append_menu_check_item(ruler_mode_menu, wxID_ANY, _L("None"), _L("Hide ruler"),
|
||||
@ -2522,7 +2501,11 @@ void Control::show_cog_icon_context_menu()
|
||||
append_submenu(&menu, ruler_mode_menu, wxID_ANY, _L("Ruler mode"), _L("Set ruler mode"), "",
|
||||
[]() { return true; }, this);
|
||||
}
|
||||
|
||||
#else
|
||||
append_menu_check_item(&menu, wxID_ANY, _L("Show estimated print time on mouse moving"), _L("Show estimated print time on the ruler"),
|
||||
[this](wxCommandEvent&) { m_extra_style& wxSL_VALUE_LABEL ? m_extra_style ^= wxSL_VALUE_LABEL : m_extra_style |= wxSL_VALUE_LABEL; }, &menu,
|
||||
[]() { return true; }, [this]() { return m_extra_style & wxSL_VALUE_LABEL; }, GUI::wxGetApp().plater());
|
||||
#endif
|
||||
if (m_mode == MultiAsSingle && m_draw_mode == dmRegular)
|
||||
append_menu_item(&menu, wxID_ANY, _L("Set extruder sequence for the entire print"), "",
|
||||
[this](wxCommandEvent&) { edit_extruder_sequence(); }, "", &menu);
|
||||
|
@ -222,7 +222,6 @@ public:
|
||||
const wxPoint& pos = wxDefaultPosition,
|
||||
const wxSize& size = wxDefaultSize,
|
||||
long style = wxSL_VERTICAL,
|
||||
// const wxValidator& val = wxDefaultValidator,
|
||||
const wxString& name = wxEmptyString);
|
||||
~Control() {}
|
||||
|
||||
@ -307,7 +306,7 @@ public:
|
||||
void show_cog_icon_context_menu();
|
||||
void auto_color_change();
|
||||
|
||||
bool imgui_render(GUI::GLCanvas3D& canvas);
|
||||
void imgui_render(GUI::GLCanvas3D& canvas, float extra_scale = 1.f);
|
||||
|
||||
protected:
|
||||
|
||||
@ -486,7 +485,6 @@ private:
|
||||
float m_scale{ 1.0 };
|
||||
bool m_can_change_color{ true };
|
||||
bool m_show_menu{ false };
|
||||
float get_pos_from_value(int v_min, int v_max, int value, const ImRect& rect);
|
||||
|
||||
void draw_colored_band(const ImRect& groove, const ImRect& slideable_region);
|
||||
void draw_ticks(const ImRect& slideable_region);
|
||||
|
@ -1950,7 +1950,13 @@ void GLCanvas3D::render()
|
||||
|
||||
wxGetApp().plater()->get_notification_manager()->render_notifications(*this, get_overlay_window_width());
|
||||
|
||||
wxGetApp().plater()->render_imgui_double_slider(*this);
|
||||
wxGetApp().plater()->render_sliders(*this,
|
||||
#if ENABLE_RETINA_GL
|
||||
m_retina_helper->get_scale_factor()
|
||||
#else
|
||||
1.f
|
||||
#endif
|
||||
);
|
||||
|
||||
wxGetApp().imgui()->render();
|
||||
|
||||
|
@ -348,12 +348,12 @@ void Preview::sys_color_changed()
|
||||
}
|
||||
|
||||
|
||||
void Preview::render_imgui_double_slider(GLCanvas3D& canvas)
|
||||
void Preview::render_sliders(GLCanvas3D& canvas, float extra_scale/* = 0.1f*/)
|
||||
{
|
||||
if (m_layers_slider && m_layers_slider->IsShown())
|
||||
m_layers_slider->imgui_render(canvas);
|
||||
m_layers_slider->imgui_render(canvas, extra_scale);
|
||||
if (m_moves_slider && m_moves_slider->IsShown() && m_bottom_toolbar_panel->IsShown())
|
||||
m_moves_slider->imgui_render(canvas);
|
||||
m_moves_slider->imgui_render(canvas, extra_scale);
|
||||
}
|
||||
|
||||
void Preview::jump_layers_slider(wxKeyEvent& evt)
|
||||
|
@ -140,7 +140,7 @@ public:
|
||||
void move_layers_slider(wxKeyEvent& evt);
|
||||
void edit_layers_slider(wxKeyEvent& evt);
|
||||
|
||||
void render_imgui_double_slider(GLCanvas3D& canvas);
|
||||
void render_sliders(GLCanvas3D& canvas, float extra_scale = 0.1f);
|
||||
|
||||
bool is_loaded() const { return m_loaded; }
|
||||
|
||||
|
@ -17,9 +17,7 @@ static bool behavior(ImGuiID id, const ImRect& region,
|
||||
const ImS32 v_min, const ImS32 v_max,
|
||||
ImS32* out_value, ImRect* out_thumb,
|
||||
ImGuiSliderFlags flags = 0,
|
||||
bool change_on_mouse_move = false,
|
||||
const int fixed_value = -1,
|
||||
const ImVec4& fixed_rect = ImVec4())
|
||||
bool change_on_mouse_move = false)
|
||||
{
|
||||
ImGuiContext& context = *GImGui;
|
||||
|
||||
@ -63,11 +61,6 @@ static bool behavior(ImGuiID id, const ImRect& region,
|
||||
v_new = v_min + (ImS32)(v_range * mouse_pos_ratio + 0.5f);
|
||||
}
|
||||
}
|
||||
// click in fixed_rect behavior
|
||||
if (ImGui::ItemHoverable(fixed_rect, id) && context.IO.MouseReleased[0])
|
||||
{
|
||||
v_new = fixed_value;
|
||||
}
|
||||
|
||||
// apply result, output value
|
||||
if (*out_value != v_new)
|
||||
@ -88,7 +81,7 @@ static bool behavior(ImGuiID id, const ImRect& region,
|
||||
return value_changed;
|
||||
}
|
||||
|
||||
ImRect ImGuiControl::DrawOptions::groove(const ImVec2& pos, const ImVec2& size, bool is_horizontal)
|
||||
ImRect ImGuiControl::DrawOptions::groove(const ImVec2& pos, const ImVec2& size, bool is_horizontal) const
|
||||
{
|
||||
ImVec2 groove_start = is_horizontal ?
|
||||
ImVec2(pos.x + thumb_dummy_sz().x, pos.y + size.y - groove_sz().y - dummy_sz().y) :
|
||||
@ -100,7 +93,7 @@ ImRect ImGuiControl::DrawOptions::groove(const ImVec2& pos, const ImVec2& size,
|
||||
return ImRect(groove_start, groove_start + groove_size);
|
||||
}
|
||||
|
||||
ImRect ImGuiControl::DrawOptions::draggable_region(const ImRect& groove, bool is_horizontal)
|
||||
ImRect ImGuiControl::DrawOptions::draggable_region(const ImRect& groove, bool is_horizontal) const
|
||||
{
|
||||
ImRect draggable_region = is_horizontal ?
|
||||
ImRect(groove.Min.x, groove.GetCenter().y, groove.Max.x, groove.GetCenter().y) :
|
||||
@ -112,7 +105,7 @@ ImRect ImGuiControl::DrawOptions::draggable_region(const ImRect& groove, bool is
|
||||
return draggable_region;
|
||||
}
|
||||
|
||||
ImRect ImGuiControl::DrawOptions::slider_line(const ImRect& draggable_region, const ImVec2& h_thumb_center, const ImVec2& l_thumb_center, bool is_horizontal)
|
||||
ImRect ImGuiControl::DrawOptions::slider_line(const ImRect& draggable_region, const ImVec2& h_thumb_center, const ImVec2& l_thumb_center, bool is_horizontal) const
|
||||
{
|
||||
ImVec2 mid = draggable_region.GetCenter();
|
||||
|
||||
@ -129,7 +122,7 @@ ImGuiControl::ImGuiControl( int lowerValue,
|
||||
int maxValue,
|
||||
ImVec2 pos,
|
||||
ImVec2 size,
|
||||
long style,
|
||||
ImGuiSliderFlags flags,
|
||||
std::string name,
|
||||
bool use_lower_thumb) :
|
||||
m_selection(ssUndef),
|
||||
@ -140,9 +133,8 @@ ImGuiControl::ImGuiControl( int lowerValue,
|
||||
m_higher_value (higherValue),
|
||||
m_min_value(minValue),
|
||||
m_max_value(maxValue),
|
||||
m_style(style == wxSL_HORIZONTAL || style == wxSL_VERTICAL ? style: wxSL_HORIZONTAL),
|
||||
m_flags(flags),
|
||||
m_draw_lower_thumb(use_lower_thumb)
|
||||
//,m_extra_style(style == wxSL_VERTICAL ? wxSL_AUTOTICKS | wxSL_VALUE_LABEL : 0)
|
||||
{
|
||||
}
|
||||
|
||||
@ -204,8 +196,11 @@ std::string ImGuiControl::get_label(int pos) const
|
||||
to_string_with_precision(m_values[value]);
|
||||
}
|
||||
|
||||
float ImGuiControl::get_pos_from_value(int v_min, int v_max, int value, const ImRect& rect)
|
||||
float ImGuiControl::GetPositionFromValue(int value, const ImRect& rect) const
|
||||
{
|
||||
int v_min = m_min_value;
|
||||
int v_max = m_max_value;
|
||||
|
||||
float pos_ratio = (v_max - v_min) != 0 ? ((float)(value - v_min) / (float)(v_max - v_min)) : 0.0f;
|
||||
float thumb_pos;
|
||||
if (is_horizontal()) {
|
||||
@ -246,6 +241,9 @@ void ImGuiControl::draw_background(const ImRect& slideable_region)
|
||||
|
||||
void ImGuiControl::draw_label(std::string label, const ImRect& thumb)
|
||||
{
|
||||
if (label.empty())
|
||||
return;
|
||||
|
||||
const ImVec2 thumb_center = thumb.GetCenter();
|
||||
ImVec2 text_padding = m_draw_opts.text_padding();
|
||||
float rounding = m_draw_opts.rounding();
|
||||
@ -301,12 +299,12 @@ void ImGuiControl::apply_regions(int higher_value, int lower_value, const ImRect
|
||||
ImRect(draggable_region.Min + ImVec2(0, thumb_radius), draggable_region.Max);
|
||||
|
||||
// initialize the thumbs.
|
||||
float higher_thumb_pos = get_pos_from_value(m_min_value, m_max_value, higher_value, m_regions.higher_slideable_region);
|
||||
float higher_thumb_pos = GetPositionFromValue(higher_value, m_regions.higher_slideable_region);
|
||||
m_regions.higher_thumb = is_horizontal() ?
|
||||
ImRect(higher_thumb_pos - thumb_radius, mid.y - thumb_radius, higher_thumb_pos + thumb_radius, mid.y + thumb_radius) :
|
||||
ImRect(mid.x - thumb_radius, higher_thumb_pos - thumb_radius, mid.x + thumb_radius, higher_thumb_pos + thumb_radius);
|
||||
|
||||
float lower_thumb_pos = get_pos_from_value(m_min_value, m_max_value, lower_value, m_regions.lower_slideable_region);
|
||||
float lower_thumb_pos = GetPositionFromValue(lower_value, m_regions.lower_slideable_region);
|
||||
m_regions.lower_thumb = is_horizontal() ?
|
||||
ImRect(lower_thumb_pos - thumb_radius, mid.y - thumb_radius, lower_thumb_pos + thumb_radius, mid.y + thumb_radius) :
|
||||
ImRect(mid.x - thumb_radius, lower_thumb_pos - thumb_radius, mid.x + thumb_radius, lower_thumb_pos + thumb_radius);
|
||||
@ -400,11 +398,11 @@ bool ImGuiControl::draw_slider( int* higher_value, int* lower_value,
|
||||
bool value_changed = false;
|
||||
if (m_selection == ssHigher) {
|
||||
value_changed = behavior(id, m_regions.higher_slideable_region, m_min_value, m_max_value,
|
||||
higher_value, &m_regions.higher_thumb, is_horizontal() ? 0: ImGuiSliderFlags_Vertical);
|
||||
higher_value, &m_regions.higher_thumb, m_flags);
|
||||
}
|
||||
else if (m_draw_lower_thumb && !m_combine_thumbs) {
|
||||
value_changed = behavior(id, m_regions.lower_slideable_region, m_min_value, m_max_value,
|
||||
lower_value, &m_regions.lower_thumb, is_horizontal() ? 0: ImGuiSliderFlags_Vertical);
|
||||
lower_value, &m_regions.lower_thumb, m_flags);
|
||||
}
|
||||
|
||||
// check thumbs values and correct them if needed
|
||||
@ -417,7 +415,7 @@ bool ImGuiControl::draw_slider( int* higher_value, int* lower_value,
|
||||
ImRect mouse_pos_rc = active_thumb;
|
||||
if (!value_changed && ImGui::ItemHoverable(item_size, id) && !ImGui::IsMouseDragging(0)) {
|
||||
behavior(id, slideable_region, m_min_value, m_max_value,
|
||||
&m_mouse_pos_value, &mouse_pos_rc, is_horizontal() ? 0 : ImGuiSliderFlags_Vertical, true);
|
||||
&m_mouse_pos_value, &mouse_pos_rc, m_flags, true);
|
||||
show_move_label = true;
|
||||
}
|
||||
|
||||
|
@ -48,7 +48,7 @@ public:
|
||||
int maxValue,
|
||||
ImVec2 pos,
|
||||
ImVec2 size,
|
||||
long style = wxSL_VERTICAL,
|
||||
ImGuiSliderFlags flags = ImGuiSliderFlags_None,
|
||||
std::string name = "d_slider",
|
||||
bool use_lower_thumb = true);
|
||||
ImGuiControl() {}
|
||||
@ -61,6 +61,7 @@ public:
|
||||
int GetLowerValue() const { return m_lower_value; }
|
||||
int GetHigherValue() const { return m_higher_value; }
|
||||
int GetActiveValue() const;
|
||||
float GetPositionFromValue(int value, const ImRect& rect) const;
|
||||
|
||||
// Set low and high slider position. If the span is non-empty, disable the "one layer" mode.
|
||||
void SetLowerValue (const int lower_val);
|
||||
@ -74,9 +75,15 @@ public:
|
||||
void SetPos(ImVec2 pos) { m_pos = pos; }
|
||||
void SetSize(ImVec2 size) { m_size = size; }
|
||||
void SetScale(float scale) { m_draw_opts.scale = scale; }
|
||||
void Init(const ImVec2& pos, const ImVec2& size, float scale) {
|
||||
m_pos = pos;
|
||||
m_size = size;
|
||||
m_draw_opts.scale = scale;
|
||||
}
|
||||
void ShowLabelOnMouseMove(bool show = true) { m_show_move_label = show; }
|
||||
ImRect GetGrooveRect() const { return m_draw_opts.groove(m_pos, m_size, is_horizontal()); }
|
||||
|
||||
bool is_horizontal() const { return m_style == wxSL_HORIZONTAL; }
|
||||
bool is_horizontal() const { return !(m_flags & ImGuiSliderFlags_Vertical); }
|
||||
bool is_lower_at_min() const { return m_lower_value == m_min_value; }
|
||||
bool is_higher_at_max() const { return m_higher_value == m_max_value; }
|
||||
bool is_full_span() const { return this->is_lower_at_min() && this->is_higher_at_max(); }
|
||||
@ -86,7 +93,6 @@ public:
|
||||
void draw_scroll_line(const ImRect& scroll_line, const ImRect& slideable_region);
|
||||
|
||||
std::string get_label(int pos) const;
|
||||
std::string get_label_on_move(int pos) const { return m_cb_get_label_on_move ? m_cb_get_label_on_move(pos) : get_label(pos); }
|
||||
|
||||
void set_get_label_on_move_cb(std::function<std::string(int)> cb) { m_cb_get_label_on_move = cb; }
|
||||
void set_get_label_cb(std::function<std::string(int)> cb) { m_cb_get_label = cb; }
|
||||
@ -96,20 +102,20 @@ public:
|
||||
struct DrawOptions {
|
||||
float scale { 1.f }; // used for Retina on osx
|
||||
|
||||
ImVec2 dummy_sz() { return ImVec2(24.0f, 44.0f) * scale; }
|
||||
ImVec2 thumb_dummy_sz() { return ImVec2(17.0f, 17.0f) * scale; }
|
||||
ImVec2 groove_sz() { return ImVec2(10.0f, 8.0f) * scale; }
|
||||
ImVec2 draggable_region_sz() { return ImVec2(40.0f, 19.0f) * scale; }
|
||||
ImVec2 text_dummy_sz() { return ImVec2(50.0f, 34.0f) * scale; }
|
||||
ImVec2 text_padding() { return ImVec2( 5.0f, 2.0f) * scale; }
|
||||
ImVec2 dummy_sz() const { return ImVec2(24.0f, 44.0f) * scale; }
|
||||
ImVec2 thumb_dummy_sz() const { return ImVec2(17.0f, 17.0f) * scale; }
|
||||
ImVec2 groove_sz() const { return ImVec2(10.0f, 8.0f) * scale; }
|
||||
ImVec2 draggable_region_sz()const { return ImVec2(40.0f, 19.0f) * scale; }
|
||||
ImVec2 text_dummy_sz() const { return ImVec2(50.0f, 34.0f) * scale; }
|
||||
ImVec2 text_padding() const { return ImVec2( 5.0f, 2.0f) * scale; }
|
||||
|
||||
float thumb_radius() { return 14.0f * scale; }
|
||||
float thumb_border() { return 2.0f * scale; }
|
||||
float rounding() { return 2.0f * scale; }
|
||||
float thumb_radius() const { return 14.0f * scale; }
|
||||
float thumb_border() const { return 2.0f * scale; }
|
||||
float rounding() const { return 2.0f * scale; }
|
||||
|
||||
ImRect groove(const ImVec2& pos, const ImVec2& size, bool is_horizontal);
|
||||
ImRect draggable_region(const ImRect& groove, bool is_horizontal);
|
||||
ImRect slider_line(const ImRect& draggable_region, const ImVec2& h_thumb_center, const ImVec2& l_thumb_center, bool is_horizontal);
|
||||
ImRect groove(const ImVec2& pos, const ImVec2& size, bool is_horizontal) const;
|
||||
ImRect draggable_region(const ImRect& groove, bool is_horizontal) const;
|
||||
ImRect slider_line(const ImRect& draggable_region, const ImVec2& h_thumb_center, const ImVec2& l_thumb_center, bool is_horizontal) const;
|
||||
};
|
||||
|
||||
struct Regions {
|
||||
@ -125,6 +131,7 @@ private:
|
||||
ImVec2 m_pos;
|
||||
ImVec2 m_size;
|
||||
std::string m_name;
|
||||
ImGuiSliderFlags m_flags{ ImGuiSliderFlags_None };
|
||||
|
||||
int m_min_value;
|
||||
int m_max_value;
|
||||
@ -132,7 +139,6 @@ private:
|
||||
int m_higher_value;
|
||||
int m_mouse_pos_value;
|
||||
|
||||
long m_style;
|
||||
double m_label_koef{ 1. };
|
||||
|
||||
bool m_rclick_on_selected_thumb{ false };
|
||||
@ -147,8 +153,8 @@ private:
|
||||
std::function<void(const ImRect&)> m_cb_extra_draw { nullptr };
|
||||
|
||||
void apply_regions(int higher_value, int lower_value, const ImRect& draggable_region);
|
||||
std::string get_label_on_move(int pos) const { return m_cb_get_label_on_move ? m_cb_get_label_on_move(pos) : get_label(pos); }
|
||||
|
||||
float get_pos_from_value(int v_min, int v_max, int value, const ImRect& rect);
|
||||
void check_and_correct_thumbs(int* higher_value, int* lower_value);
|
||||
|
||||
void draw_background(const ImRect& slideable_region);
|
||||
|
@ -1145,9 +1145,10 @@ void ImGuiWrapper::init_font(bool compress)
|
||||
m_custom_glyph_rects_ids[icon.first] =
|
||||
io.Fonts->AddCustomRectFontGlyph(font, icon.first, icon_sz, icon_sz, 3.0 * font_scale + icon_sz);
|
||||
}
|
||||
const int icon_sz_m = int(1.25 * icon_sz); // default size of medium icon is 20 px
|
||||
for (auto& icon : font_icons_medium) {
|
||||
m_custom_glyph_rects_ids[icon.first] =
|
||||
io.Fonts->AddCustomRectFontGlyph(font, icon.first, 1.5 * icon_sz, 1.5 * icon_sz, 3.0 * font_scale + 1.5 * icon_sz);
|
||||
io.Fonts->AddCustomRectFontGlyph(font, icon.first, icon_sz_m, icon_sz_m, 3.0 * font_scale + icon_sz_m);
|
||||
}
|
||||
for (auto& icon : font_icons_large) {
|
||||
m_custom_glyph_rects_ids[icon.first] =
|
||||
@ -1185,7 +1186,6 @@ void ImGuiWrapper::init_font(bool compress)
|
||||
load_icon_from_svg(icon, icon_sz);
|
||||
}
|
||||
|
||||
const int icon_sz_m = int(1.5 * icon_sz); // default size of medium icon is 24 px
|
||||
for (auto icon : font_icons_medium) {
|
||||
load_icon_from_svg(icon, icon_sz_m);
|
||||
}
|
||||
|
@ -385,7 +385,7 @@ struct Plater::priv
|
||||
|
||||
void set_current_canvas_as_dirty();
|
||||
GLCanvas3D* get_current_canvas3D();
|
||||
void render_imgui_double_slider(GLCanvas3D& canvas);
|
||||
void render_sliders(GLCanvas3D& canvas, float extra_scale = 0.1f);
|
||||
void unbind_canvas_event_handlers();
|
||||
void reset_canvas_volumes();
|
||||
|
||||
@ -3190,10 +3190,10 @@ GLCanvas3D* Plater::priv::get_current_canvas3D()
|
||||
return (current_panel == view3D) ? view3D->get_canvas3d() : ((current_panel == preview) ? preview->get_canvas3d() : nullptr);
|
||||
}
|
||||
|
||||
void Plater::priv::render_imgui_double_slider(GLCanvas3D& canvas)
|
||||
void Plater::priv::render_sliders(GLCanvas3D& canvas, float extra_scale /*= 0.1f*/)
|
||||
{
|
||||
if (current_panel == preview)
|
||||
preview->render_imgui_double_slider(canvas);
|
||||
preview->render_sliders(canvas, extra_scale);
|
||||
}
|
||||
|
||||
void Plater::priv::unbind_canvas_event_handlers()
|
||||
@ -6409,9 +6409,9 @@ GLCanvas3D* Plater::get_current_canvas3D()
|
||||
return p->get_current_canvas3D();
|
||||
}
|
||||
|
||||
void Plater::render_imgui_double_slider(GLCanvas3D& canvas)
|
||||
void Plater::render_sliders(GLCanvas3D& canvas, float extra_scale)
|
||||
{
|
||||
p->render_imgui_double_slider(canvas);
|
||||
p->render_sliders(canvas, extra_scale);
|
||||
}
|
||||
|
||||
static std::string concat_strings(const std::set<std::string> &strings,
|
||||
|
@ -272,7 +272,7 @@ public:
|
||||
const GLCanvas3D * canvas3D() const;
|
||||
GLCanvas3D* get_current_canvas3D();
|
||||
|
||||
void render_imgui_double_slider(GLCanvas3D& canvas);
|
||||
void render_sliders(GLCanvas3D& canvas, float extra_scale = 0.1f);
|
||||
|
||||
void arrange();
|
||||
void arrange(Worker &w, bool selected);
|
||||
|
Loading…
x
Reference in New Issue
Block a user