mirror of
				https://github.com/SoftFever/OrcaSlicer.git
				synced 2025-10-30 20:21:12 -06:00 
			
		
		
		
	ENH:adjust preview slider UI
Change-Id: Idc5ba3ed44d04cdcd0d7d124d57b689e1af2a8b1
This commit is contained in:
		
							parent
							
								
									bb5c614b71
								
							
						
					
					
						commit
						8c923804fc
					
				
					 4 changed files with 151 additions and 156 deletions
				
			
		|  | @ -1276,7 +1276,7 @@ void GCodeViewer::render(int canvas_width, int canvas_height, int right_margin) | |||
|         m_sequential_view.marker.set_world_position(m_sequential_view.current_position); | ||||
|         m_sequential_view.marker.set_world_offset(m_sequential_view.current_offset); | ||||
|         //BBS fixed buttom margin. m_moves_slider.pos_y
 | ||||
|         m_sequential_view.render(legend_height, canvas_width - right_margin * m_scale, canvas_height - bottom_margin * m_scale, m_view_type); | ||||
|         m_sequential_view.render(legend_height, canvas_width, canvas_height - bottom_margin * m_scale, m_view_type); | ||||
|     } | ||||
| #if ENABLE_GCODE_VIEWER_STATISTICS | ||||
|     render_statistics(); | ||||
|  |  | |||
|  | @ -74,8 +74,8 @@ static constexpr const float TRACKBALLSIZE = 0.8f; | |||
| 
 | ||||
| static const float SLIDER_DEFAULT_RIGHT_MARGIN  = 10.0f; | ||||
| static const float SLIDER_DEFAULT_BOTTOM_MARGIN = 10.0f; | ||||
| static const float SLIDER_RIGHT_MARGIN          = 115.0f; | ||||
| static const float SLIDER_BOTTOM_MARGIN         = 90.0f; | ||||
| static const float SLIDER_RIGHT_MARGIN          = 124.0f; | ||||
| static const float SLIDER_BOTTOM_MARGIN         = 64.0f; | ||||
| 
 | ||||
| float GLCanvas3D::DEFAULT_BG_LIGHT_COLOR[3] = { 0.906f, 0.906f, 0.906f }; | ||||
| float GLCanvas3D::DEFAULT_BG_LIGHT_COLOR_DARK[3] = { 0.329f, 0.329f, 0.353f }; | ||||
|  |  | |||
|  | @ -14,18 +14,22 @@ namespace GUI { | |||
| constexpr double min_delta_area = scale_(scale_(25));  // equal to 25 mm2
 | ||||
| constexpr double miscalculation = scale_(scale_(1));   // equal to 1 mm2
 | ||||
| 
 | ||||
| //static const ImVec2 MIN_RECT_SIZE  = ImVec2(81, 52);
 | ||||
| //static const float TOP_MARGIN     =  3.0f;
 | ||||
| static const float LEFT_MARGIN    = 13.0f + 100.0f;  // avoid thumbnail toolbar
 | ||||
| static const float SLIDER_LENGTH  = 680.0f; | ||||
| static const float  TEXT_WIDTH_DUMMY = 63.0f; | ||||
| static const float  ONE_LAYER_MARGIN = 10.0f; | ||||
| static const ImVec2 ONE_LAYER_OFFSET  = ImVec2(41.0f, 44.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_WINDOW_HEIGHT  = 64.0f; | ||||
| static const float  VERTICAL_SLIDER_WINDOW_WIDTH     = 124.0f; | ||||
| static const float  GROOVE_WIDTH      = 12.0f; | ||||
| static const ImVec2 ONE_LAYER_MARGIN  = ImVec2(20.0f, 20.0f); | ||||
| static const ImVec2 ONE_LAYER_BUTTON_SIZE  = ImVec2(28.0f, 28.0f); | ||||
| 
 | ||||
|     int m_tick_value = -1; | ||||
|     ImVec4 m_tick_rect; | ||||
| static const ImU32 BACKGROUND_COLOR_DARK  = IM_COL32(65, 65, 71, 255); | ||||
| static const ImU32 BACKGROUND_COLOR_LIGHT = IM_COL32(255, 255, 255, 255); | ||||
| static const ImU32 GROOVE_COLOR_DARK      = IM_COL32(45, 45, 49, 255); | ||||
| static const ImU32 GROOVE_COLOR_LIGHT     = IM_COL32(206, 206, 206, 255); | ||||
| static const ImU32 BRAND_COLOR            = IM_COL32(0, 174, 66, 255); | ||||
| 
 | ||||
| 
 | ||||
| static int m_tick_value = -1; | ||||
| static ImVec4 m_tick_rect; | ||||
| 
 | ||||
| bool equivalent_areas(const double& bottom_area, const double& top_area) | ||||
| { | ||||
|  | @ -414,33 +418,17 @@ bool IMSlider::switch_one_layer_mode() | |||
|     return true; | ||||
| } | ||||
| 
 | ||||
| void IMSlider::draw_background(const ImRect& groove) { | ||||
|     const ImU32 bg_rect_col = m_is_dark ? IM_COL32(65, 65, 71, 255) : IM_COL32(255, 255, 255, 255); | ||||
|     const ImU32 groove_col = m_is_dark ? IM_COL32(45, 45, 49, 255) : IM_COL32(206, 206, 206, 255); | ||||
| void IMSlider::draw_background_and_groove(const ImRect& bg_rect, const ImRect& groove) { | ||||
|     const ImU32 bg_rect_col = m_is_dark ? BACKGROUND_COLOR_DARK : BACKGROUND_COLOR_LIGHT; | ||||
|     const ImU32 groove_col = m_is_dark ? GROOVE_COLOR_DARK : GROOVE_COLOR_LIGHT; | ||||
| 
 | ||||
|     if (is_horizontal() || m_ticks.empty()) { | ||||
|         ImVec2 groove_padding = ImVec2(2.0f, 2.0f) * m_scale; | ||||
| 
 | ||||
|         ImRect bg_rect = groove; | ||||
|         bg_rect.Expand(groove_padding); | ||||
| 
 | ||||
|         // draw bg of slider
 | ||||
|         ImGui::RenderFrame(bg_rect.Min, bg_rect.Max, bg_rect_col, false, 0.5 * bg_rect.GetWidth()); | ||||
|         // draw bg of scroll
 | ||||
|         ImGui::RenderFrame(groove.Min, groove.Max, groove_col, false, 0.5 * groove.GetWidth()); | ||||
|     } | ||||
|     else { | ||||
|         ImVec2 groove_padding = ImVec2(5.0f, 7.0f) * m_scale; | ||||
| 
 | ||||
|         ImRect bg_rect = groove; | ||||
|         bg_rect.Expand(groove_padding); | ||||
| 
 | ||||
|         // draw bg of slider
 | ||||
|         ImGui::RenderFrame(bg_rect.Min, bg_rect.Max, bg_rect_col, false, bg_rect.GetWidth() * 0.5); | ||||
|     } | ||||
|     // draw bg of slider
 | ||||
|     ImGui::RenderFrame(bg_rect.Min, bg_rect.Max, bg_rect_col, false, 0.5 * bg_rect.GetWidth()); | ||||
|     // draw groove
 | ||||
|     ImGui::RenderFrame(groove.Min, groove.Max, groove_col, false, 0.5 * groove.GetWidth()); | ||||
| } | ||||
| 
 | ||||
| bool IMSlider::horizontal_slider(const char* str_id, int* value, int v_min, int v_max, const ImVec2& pos, const ImVec2& size, float scale) | ||||
| bool IMSlider::horizontal_slider(const char* str_id, int* value, int v_min, int v_max, const ImVec2& size, float scale) | ||||
| { | ||||
|     ImGuiWindow* window = ImGui::GetCurrentWindow(); | ||||
|     if (window->SkipItems) | ||||
|  | @ -449,36 +437,34 @@ bool IMSlider::horizontal_slider(const char* str_id, int* value, int v_min, int | |||
|     ImGuiContext& context = *GImGui; | ||||
|     const ImGuiID id = window->GetID(str_id); | ||||
| 
 | ||||
|     const ImVec2 pos = window->DC.CursorPos; | ||||
|     const ImRect draw_region(pos, pos + size); | ||||
|     ImGui::ItemSize(draw_region); | ||||
| 
 | ||||
|     float  bottom_dummy        = 44.0f * m_scale; | ||||
|     float  handle_dummy_width  = 17.0f * m_scale; | ||||
|     float  text_right_dummy    = 50.0f * scale * m_scale; | ||||
|     float  groove_y            = 8.0f * m_scale; | ||||
|     float  draggable_region_y  = 19.0f * m_scale; | ||||
|     float  handle_radius       = 14.0f * m_scale; | ||||
|     float  handle_border       = 2.0f * m_scale; | ||||
|     float  rounding            = 2.0f * m_scale; | ||||
|     float  text_start_offset   = 8.0f * m_scale; | ||||
|     ImVec2 text_padding        = ImVec2(5.0f, 2.0f) * m_scale; | ||||
|     float  triangle_offsets[3] = {-3.5f * m_scale, 3.5f * m_scale, -6.06f * m_scale}; | ||||
|     const float  handle_dummy_width  = 10.0f * m_scale; | ||||
|     const float  text_right_dummy    = 50.0f * scale * m_scale; | ||||
| 
 | ||||
|     const float  handle_radius       = 12.0f * m_scale; | ||||
|     const float  handle_border       = 2.0f * m_scale; | ||||
| 
 | ||||
|     const ImU32 white_bg = m_is_dark ? IM_COL32(65, 65, 71, 255) : IM_COL32(255, 255, 255, 255); | ||||
|     const ImU32 handle_clr = IM_COL32(0, 174, 66, 255); | ||||
|     const ImU32 handle_border_clr = m_is_dark ? IM_COL32(65, 65, 71, 255) : IM_COL32(248, 248, 248, 255); | ||||
|     const float  text_frame_rounding = 2.0f * scale * m_scale; | ||||
|     const float  text_start_offset   = 8.0f * m_scale; | ||||
|     const ImVec2 text_padding        = ImVec2(5.0f, 2.0f) * m_scale; | ||||
|     const float  triangle_offsets[3] = {-3.5f * m_scale, 3.5f * m_scale, -6.06f * m_scale}; | ||||
| 
 | ||||
|     // calc groove size
 | ||||
|     ImVec2 groove_start = ImVec2(pos.x + handle_dummy_width, pos.y + size.y - groove_y - bottom_dummy); | ||||
|     ImVec2 groove_size = ImVec2(size.x - 2 * handle_dummy_width - text_right_dummy, groove_y); | ||||
|     ImRect groove = ImRect(groove_start, groove_start + groove_size); | ||||
|     const ImU32 white_bg = m_is_dark ? BACKGROUND_COLOR_DARK : BACKGROUND_COLOR_LIGHT; | ||||
|     const ImU32 handle_clr = BRAND_COLOR; | ||||
|     const ImU32 handle_border_clr = m_is_dark ? BACKGROUND_COLOR_DARK : BACKGROUND_COLOR_LIGHT; | ||||
| 
 | ||||
|     // set active(draggable) region.
 | ||||
|     ImRect draggable_region = ImRect(groove.Min.x, groove.GetCenter().y, groove.Max.x, groove.GetCenter().y); | ||||
|     draggable_region.Expand(ImVec2(handle_radius, draggable_region_y)); | ||||
|     float mid_y   = draggable_region.GetCenter().y; | ||||
|     bool  hovered = ImGui::ItemHoverable(draggable_region, id); | ||||
|     // calculate groove size
 | ||||
|     const ImVec2 groove_start = ImVec2(pos.x + handle_dummy_width, pos.y + size.y - ONE_LAYER_MARGIN.y * m_scale - ONE_LAYER_BUTTON_SIZE.y * m_scale * 0.5f - GROOVE_WIDTH * m_scale * 0.5f); | ||||
|     const ImVec2 groove_size = ImVec2(size.x - 2 * handle_dummy_width - text_right_dummy, GROOVE_WIDTH * m_scale); | ||||
|     const ImRect groove = ImRect(groove_start, groove_start + groove_size); | ||||
|     const ImRect bg_rect = ImRect(groove.Min - ImVec2(6.0f, 6.0f) * m_scale, groove.Max + ImVec2(6.0f, 6.0f) * m_scale); | ||||
|     const float mid_y = groove.GetCenter().y; | ||||
| 
 | ||||
|     // set mouse active region. active region.
 | ||||
|     bool  hovered = ImGui::ItemHoverable(draw_region, id); | ||||
|     if (hovered && context.IO.MouseDown[0]) { | ||||
|         ImGui::SetActiveID(id, window); | ||||
|         ImGui::SetFocusID(id, window); | ||||
|  | @ -486,11 +472,10 @@ bool IMSlider::horizontal_slider(const char* str_id, int* value, int v_min, int | |||
|     } | ||||
| 
 | ||||
|     // draw background
 | ||||
|     draw_background(groove); | ||||
|     draw_background_and_groove(bg_rect, groove); | ||||
| 
 | ||||
|     // set slideable region
 | ||||
|     ImRect slideable_region = draggable_region; | ||||
|     slideable_region.Expand(ImVec2(-handle_radius, 0)); | ||||
|     // set scrollable region
 | ||||
|     const ImRect slideable_region = ImRect(bg_rect.Min + ImVec2(handle_radius, 0.0f), bg_rect.Max - ImVec2(handle_radius, 0.0f)); | ||||
| 
 | ||||
|     // initialize the handle
 | ||||
|     float  handle_pos = get_pos_from_value(v_min, v_max, *value, groove); | ||||
|  | @ -501,8 +486,8 @@ bool IMSlider::horizontal_slider(const char* str_id, int* value, int v_min, int | |||
|     ImVec2 handle_center = handle.GetCenter(); | ||||
| 
 | ||||
|     // draw scroll line
 | ||||
|     ImRect scroll_line = ImRect(ImVec2(groove.Min.x, mid_y - groove_y / 2), ImVec2(handle_center.x, mid_y + groove_y / 2)); | ||||
|     window->DrawList->AddRectFilled(scroll_line.Min, scroll_line.Max, handle_clr, rounding); | ||||
|     ImRect scroll_line = ImRect(groove.Min, ImVec2(handle_center.x, groove.Max.y)); | ||||
|     window->DrawList->AddRectFilled(scroll_line.Min, scroll_line.Max, handle_clr, 0.5f * GROOVE_WIDTH * m_scale); | ||||
| 
 | ||||
|     // draw handle
 | ||||
|     window->DrawList->AddCircleFilled(handle_center, handle_radius, handle_border_clr); | ||||
|  | @ -514,7 +499,7 @@ bool IMSlider::horizontal_slider(const char* str_id, int* value, int v_min, int | |||
|     ImVec2 text_size = text_content_size + text_padding * 2; | ||||
|     ImVec2 text_start = ImVec2(handle_center.x + handle_radius + text_start_offset, handle_center.y - 0.5 * text_size.y); | ||||
|     ImRect text_rect(text_start, text_start + text_size); | ||||
|     ImGui::RenderFrame(text_rect.Min, text_rect.Max, white_bg, false, rounding); | ||||
|     ImGui::RenderFrame(text_rect.Min, text_rect.Max, white_bg, false, text_frame_rounding); | ||||
|     ImVec2 pos_1 = ImVec2(text_rect.Min.x, text_rect.GetCenter().y + triangle_offsets[0]); | ||||
|     ImVec2 pos_2 = ImVec2(text_rect.Min.x, text_rect.GetCenter().y + triangle_offsets[1]); | ||||
|     ImVec2 pos_3 = ImVec2(text_rect.Min.x + triangle_offsets[2], text_rect.GetCenter().y); | ||||
|  | @ -525,27 +510,42 @@ bool IMSlider::horizontal_slider(const char* str_id, int* value, int v_min, int | |||
| } | ||||
| 
 | ||||
| void IMSlider::draw_colored_band(const ImRect& groove, const ImRect& slideable_region) { | ||||
|     if (m_ticks.empty()) | ||||
|     if (!m_ticks.has_tick_with_code(ToolChange)) | ||||
|         return; | ||||
| 
 | ||||
|     const ImU32 blank_col = m_is_dark ? IM_COL32(65, 65, 71, 255) : IM_COL32(255, 255, 255, 255); | ||||
|     ImRect main_band = groove; | ||||
| 
 | ||||
|     ImVec2 blank_padding = ImVec2(6.0f, 5.0f) * m_scale; | ||||
|     float  blank_width   = 1.0f * m_scale; | ||||
| 
 | ||||
|     ImRect blank_rect = ImRect(groove.GetCenter().x - blank_width, groove.Min.y, groove.GetCenter().x + blank_width, groove.Max.y); | ||||
| 
 | ||||
|     ImRect main_band = ImRect(blank_rect); | ||||
|     main_band.Expand(blank_padding); | ||||
| 
 | ||||
|     auto draw_band = [](const ImU32& clr, const ImRect& band_rc) | ||||
|     auto draw_band = [this](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); | ||||
|         if (clr == m_is_dark ? BACKGROUND_COLOR_DARK : BACKGROUND_COLOR_LIGHT) { | ||||
|             ImRect rc = band_rc; | ||||
|             rc.Min += ImVec2(1, 1) * m_scale; | ||||
|             rc.Max -= ImVec2(1, 1) * m_scale; | ||||
|             ImGui::RenderFrame(band_rc.Min, band_rc.Max, m_is_dark ? GROOVE_COLOR_DARK : GROOVE_COLOR_LIGHT, 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, m_is_dark ? GROOVE_COLOR_DARK : GROOVE_COLOR_LIGHT, false); | ||||
| 
 | ||||
|             ImGui::RenderFrame(rc.Min, rc.Max, clr, false, rc.GetWidth() * 0.5); | ||||
|             //cover round corner
 | ||||
|             ImGui::RenderFrame(ImVec2(rc.Min.x, rc.Max.y - rc.GetWidth() * 0.5), rc.Max, clr, false); | ||||
|         } | ||||
|         else { | ||||
|             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, this](const ImU32& clr) { | ||||
|         ImGui::RenderFrame(main_band.Min, main_band.Max, clr, false, main_band.GetWidth() * 0.5); | ||||
|         if (clr == m_is_dark ? BACKGROUND_COLOR_DARK : BACKGROUND_COLOR_LIGHT) { | ||||
|             ImRect rc = main_band; | ||||
|             rc.Min += ImVec2(1, 1) * m_scale; | ||||
|             rc.Max -= ImVec2(1, 1) * m_scale; | ||||
|             ImGui::RenderFrame(main_band.Min, main_band.Max, m_is_dark ? GROOVE_COLOR_DARK : GROOVE_COLOR_LIGHT, false, main_band.GetWidth() * 0.5); | ||||
|             ImGui::RenderFrame(rc.Min, rc.Max, clr, false, rc.GetWidth() * 0.5); | ||||
|         } | ||||
|         else { | ||||
|             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; | ||||
|  | @ -579,9 +579,6 @@ void IMSlider::draw_colored_band(const ImRect& groove, const ImRect& slideable_r | |||
|         } | ||||
|         tick_it++; | ||||
|     } | ||||
| 
 | ||||
|     //draw blank line
 | ||||
|     ImGui::RenderFrame(blank_rect.Min, blank_rect.Max, blank_col, false, blank_rect.GetWidth() * 0.5); | ||||
| } | ||||
| 
 | ||||
| void IMSlider::draw_ticks(const ImRect& slideable_region) { | ||||
|  | @ -594,10 +591,10 @@ void IMSlider::draw_ticks(const ImRect& slideable_region) { | |||
| 
 | ||||
|     ImGuiContext &context       = *GImGui; | ||||
| 
 | ||||
|     ImVec2 tick_box      = ImVec2(46.0f, 16.0f) * m_scale; | ||||
|     ImVec2 tick_offset   = ImVec2(19.0f, 11.0f) * m_scale; | ||||
|     ImVec2 tick_box      = ImVec2(52.0f, 16.0f) * m_scale; | ||||
|     ImVec2 tick_offset   = ImVec2(22.0f, 14.0f) * m_scale; | ||||
|     float  tick_width    = 1.0f * m_scale; | ||||
|     ImVec2 icon_offset   = ImVec2(13.0f, 7.0f) * m_scale; | ||||
|     ImVec2 icon_offset   = ImVec2(16.0f, 7.0f) * m_scale; | ||||
|     ImVec2 icon_size     = ImVec2(14.0f, 14.0f) * m_scale; | ||||
| 
 | ||||
|     const ImU32 tick_clr = IM_COL32(144, 144, 144, 255); | ||||
|  | @ -621,7 +618,10 @@ void IMSlider::draw_ticks(const ImRect& slideable_region) { | |||
| 
 | ||||
|         if (ImGui::IsMouseHoveringRect(tick_hover_box.Min, tick_hover_box.Max)) | ||||
|         { | ||||
|             ImGui::RenderFrame(tick_hover_box.Min, tick_hover_box.Max, tick_hover_box_clr, false); | ||||
|             // render left tick box
 | ||||
|             ImGui::RenderFrame(tick_hover_box.Min, { slideable_region.Min.x, tick_hover_box.Max.y }, tick_hover_box_clr, false); | ||||
|             // render right tick box
 | ||||
|             ImGui::RenderFrame({ slideable_region.Max.x, tick_hover_box.Min.y }, tick_hover_box.Max, tick_hover_box_clr, false); | ||||
|             if (context.IO.MouseClicked[0]) { | ||||
|                 m_tick_value   = tick_it->tick; | ||||
|                 m_tick_rect    = ImVec4(tick_hover_box.Min.x, tick_hover_box.Min.y, tick_hover_box.Max.x, tick_hover_box.Max.y); | ||||
|  | @ -669,7 +669,7 @@ void IMSlider::draw_ticks(const ImRect& slideable_region) { | |||
| 
 | ||||
| } | ||||
| 
 | ||||
| bool IMSlider::vertical_slider(const char* str_id, int* higher_value, int* lower_value, std::string& higher_label, std::string& lower_label,int v_min, int v_max, const ImVec2& pos,const ImVec2& size, SelectedSlider& selection, bool one_layer_flag, float scale) | ||||
| bool IMSlider::vertical_slider(const char* str_id, int* higher_value, int* lower_value, std::string& higher_label, std::string& lower_label,int v_min, int v_max, const ImVec2& size, SelectedSlider& selection, bool one_layer_flag, float scale) | ||||
| { | ||||
|     ImGuiWindow* window = ImGui::GetCurrentWindow(); | ||||
|     if (window->SkipItems) | ||||
|  | @ -678,39 +678,38 @@ bool IMSlider::vertical_slider(const char* str_id, int* higher_value, int* lower | |||
|     ImGuiContext& context = *GImGui; | ||||
|     const ImGuiID id = window->GetID(str_id); | ||||
| 
 | ||||
|     const ImVec2 pos = window->DC.CursorPos; | ||||
|     const ImRect draw_region(pos, pos + size); | ||||
|     ImGui::ItemSize(draw_region); | ||||
| 
 | ||||
|     float  right_dummy         = 24.0f * m_scale; | ||||
|     float  text_dummy_height   = 34.0f * scale * m_scale; | ||||
|     float  groove_x            = 8.0f * m_scale; | ||||
|     float  draggable_region_x  = 40.0f * m_scale; | ||||
|     float  handle_radius       = 14.0f * m_scale; | ||||
|     float  handle_border       = 2.0f * m_scale; | ||||
|     float  rounding            = 2.0f * m_scale; | ||||
|     float  line_width          = 2.0f * m_scale; | ||||
|     float  line_offset         = 9.0f * m_scale; | ||||
|     float  one_handle_offset   = 26.0f * m_scale; | ||||
|     float  bar_width           = 12.0f * m_scale; | ||||
|     ImVec2 text_padding        = ImVec2(5.0f, 2.0f) * m_scale; | ||||
|     ImVec2 triangle_offsets[3] = {ImVec2(2.0f, 0.0f) * m_scale, ImVec2(0.0f, 8.0f) * m_scale, ImVec2(9.0f, 0.0f) * m_scale}; | ||||
|     const float  text_dummy_height   = 30.0f * scale * m_scale; | ||||
| 
 | ||||
|     const float  handle_radius       = 12.0f * m_scale; | ||||
|     const float  handle_border       = 2.0f * m_scale; | ||||
|     const float  line_width          = 1.0f * m_scale; | ||||
|     const float  line_length         = 12.0f * m_scale; | ||||
|     const float  one_handle_offset   = 26.0f * m_scale; | ||||
|     const float  bar_width           = 28.0f * m_scale; | ||||
| 
 | ||||
|     const float  text_frame_rounding = 2.0f * scale * m_scale; | ||||
|     const ImVec2 text_padding        = ImVec2(5.0f, 2.0f) * m_scale; | ||||
|     const ImVec2 triangle_offsets[3] = {ImVec2(2.0f, 0.0f) * m_scale, ImVec2(0.0f, 8.0f) * m_scale, ImVec2(9.0f, 0.0f) * m_scale}; | ||||
|     ImVec2 text_content_size; | ||||
|     ImVec2 text_size; | ||||
| 
 | ||||
|     const ImU32 white_bg = m_is_dark ? IM_COL32(65, 65, 71, 255) : IM_COL32(255, 255, 255, 255); | ||||
|     const ImU32 handle_clr = IM_COL32(0, 174, 66, 255); | ||||
|     const ImU32 handle_border_clr = m_is_dark ? IM_COL32(65, 65, 71, 255) : IM_COL32(248, 248, 248, 255); | ||||
|     const ImU32 white_bg = m_is_dark ? BACKGROUND_COLOR_DARK : BACKGROUND_COLOR_LIGHT; | ||||
|     const ImU32 handle_clr = BRAND_COLOR; | ||||
|     const ImU32 handle_border_clr = m_is_dark ? BACKGROUND_COLOR_DARK : BACKGROUND_COLOR_LIGHT; | ||||
|     // calculate slider groove size
 | ||||
|     const ImVec2 groove_start = ImVec2(pos.x + size.x - ONE_LAYER_MARGIN.x * m_scale - ONE_LAYER_BUTTON_SIZE.x * m_scale * 0.5f - GROOVE_WIDTH * m_scale * 0.5f, pos.y + text_dummy_height); | ||||
|     const ImVec2 groove_size = ImVec2(GROOVE_WIDTH * m_scale, size.y - 2 * text_dummy_height); | ||||
|     const ImRect groove = ImRect(groove_start, groove_start + groove_size); | ||||
|     const ImRect bg_rect = ImRect(groove.Min - ImVec2(6.0f, 6.0f) * m_scale, groove.Max + ImVec2(6.0f, 6.0f) * m_scale); | ||||
|     const float mid_x = groove.GetCenter().x; | ||||
| 
 | ||||
|     // calc slider groove size
 | ||||
|     ImVec2 groove_start = ImVec2(pos.x + size.x - groove_x - right_dummy, pos.y + text_dummy_height); | ||||
|     ImVec2 groove_size = ImVec2(groove_x, size.y - 2 * text_dummy_height); | ||||
|     ImRect groove = ImRect(groove_start, groove_start + groove_size); | ||||
| 
 | ||||
|     // set active(draggable) region.
 | ||||
|     ImRect draggable_region = ImRect(groove.GetCenter().x, groove.Min.y, groove.GetCenter().x, groove.Max.y); | ||||
|     draggable_region.Expand(ImVec2(draggable_region_x, 0)); | ||||
|     float mid_x = draggable_region.GetCenter().x; | ||||
|     bool hovered = ImGui::ItemHoverable(draggable_region, id) && !ImGui::ItemHoverable(m_tick_rect, id); | ||||
|     // set mouse active region.
 | ||||
|     const ImRect active_region = ImRect(ImVec2(draw_region.Min.x + 35.0f * m_scale, draw_region.Min.y), draw_region.Max); | ||||
|     bool hovered = ImGui::ItemHoverable(active_region, id) && !ImGui::ItemHoverable(m_tick_rect, id); | ||||
|     if (hovered && context.IO.MouseDown[0]) { | ||||
|         ImGui::SetActiveID(id, window); | ||||
|         ImGui::SetFocusID(id, window); | ||||
|  | @ -718,14 +717,14 @@ bool IMSlider::vertical_slider(const char* str_id, int* higher_value, int* lower | |||
|     } | ||||
| 
 | ||||
|     // draw background
 | ||||
|     draw_background(groove); | ||||
| 
 | ||||
|     draw_background_and_groove(bg_rect, groove); | ||||
| 
 | ||||
|     // Processing interacting
 | ||||
|     // set slideable region
 | ||||
|     ImRect higher_slideable_region = ImRect(draggable_region.Min, draggable_region.Max - ImVec2(0, handle_radius)); | ||||
|     ImRect lower_slideable_region = ImRect(draggable_region.Min + ImVec2(0, handle_radius), draggable_region.Max); | ||||
|     ImRect one_slideable_region = draggable_region; | ||||
|     // set scrollable region
 | ||||
|     const ImRect region = ImRect(bg_rect.Min + ImVec2(0.0f, handle_radius), bg_rect.Max - ImVec2(0.0f, handle_radius)); | ||||
|     const ImRect higher_slideable_region = ImRect(region.Min, region.Max - ImVec2(0, handle_radius)); | ||||
|     const ImRect lower_slideable_region = ImRect(region.Min + ImVec2(0, handle_radius), region.Max); | ||||
|     const ImRect one_slideable_region = region; | ||||
| 
 | ||||
|     // initialize the handles.
 | ||||
|     float higher_handle_pos = get_pos_from_value(v_min, v_max, *higher_value, higher_slideable_region); | ||||
|  | @ -736,12 +735,11 @@ bool IMSlider::vertical_slider(const char* str_id, int* higher_value, int* lower | |||
| 
 | ||||
|     ImRect one_handle = ImRect(higher_handle.Min - ImVec2(one_handle_offset, 0), higher_handle.Max - ImVec2(one_handle_offset, 0)); | ||||
| 
 | ||||
|     //static bool become_del_handle = false;
 | ||||
|     bool value_changed = false; | ||||
|     if (!one_layer_flag)  | ||||
|     { | ||||
|         // select higher handle by default
 | ||||
|         bool h_selected = (selection == ssHigher); | ||||
|         static bool h_selected = (selection == ssHigher); | ||||
|         if (ImGui::ItemHoverable(higher_handle, id) && context.IO.MouseClicked[0]) { | ||||
|             selection = ssHigher;  | ||||
|             h_selected = true; | ||||
|  | @ -788,17 +786,17 @@ bool IMSlider::vertical_slider(const char* str_id, int* higher_value, int* lower | |||
|             context.IO.MouseClicked[0]) | ||||
|             m_show_menu = false; | ||||
| 
 | ||||
| 
 | ||||
|         if (!m_ticks.empty()) { | ||||
|             // draw ticks
 | ||||
|             draw_ticks(h_selected ? higher_slideable_region : lower_slideable_region); | ||||
|             // draw colored band
 | ||||
|             draw_colored_band(groove, h_selected ? higher_slideable_region : lower_slideable_region); | ||||
|         } | ||||
|         else { | ||||
| 
 | ||||
|         if (!m_ticks.has_tick_with_code(ToolChange)) { | ||||
|             // draw scroll line
 | ||||
|             ImRect scroll_line = ImRect(ImVec2(mid_x - groove_x / 2, higher_handle_center.y), ImVec2(mid_x + groove_x / 2, lower_handle_center.y)); | ||||
|             window->DrawList->AddRectFilled(scroll_line.Min, scroll_line.Max, handle_clr, rounding); | ||||
|             ImRect scroll_line = ImRect(ImVec2(groove.Min.x, higher_handle_center.y), ImVec2(groove.Max.x, lower_handle_center.y)); | ||||
|             window->DrawList->AddRectFilled(scroll_line.Min, scroll_line.Max, handle_clr); | ||||
|         } | ||||
| 
 | ||||
|         // draw handles
 | ||||
|  | @ -809,12 +807,12 @@ bool IMSlider::vertical_slider(const char* str_id, int* higher_value, int* lower | |||
|         if (h_selected) { | ||||
|             window->DrawList->AddCircleFilled(higher_handle_center, handle_radius, handle_border_clr); | ||||
|             window->DrawList->AddCircleFilled(higher_handle_center, handle_radius - handle_border, handle_clr); | ||||
|             window->DrawList->AddLine(higher_handle_center + ImVec2(-line_offset, 0.0f), higher_handle_center + ImVec2(line_offset, 0.0f), white_bg, line_width); | ||||
|             window->DrawList->AddLine(higher_handle_center + ImVec2(0.0f, -line_offset), higher_handle_center + ImVec2(0.0f, line_offset), white_bg, line_width); | ||||
|             window->DrawList->AddLine(higher_handle_center + ImVec2(-0.5f * line_length, 0.0f), higher_handle_center + ImVec2(0.5f * line_length, 0.0f), white_bg, line_width); | ||||
|             window->DrawList->AddLine(higher_handle_center + ImVec2(0.0f, -0.5f * line_length), higher_handle_center + ImVec2(0.0f, 0.5f * line_length), white_bg, line_width); | ||||
|         } | ||||
|         if (!h_selected) { | ||||
|             window->DrawList->AddLine(lower_handle_center + ImVec2(-line_offset, 0.0f), lower_handle_center + ImVec2(line_offset, 0.0f), white_bg, line_width); | ||||
|             window->DrawList->AddLine(lower_handle_center + ImVec2(0.0f, -line_offset), lower_handle_center + ImVec2(0.0f, line_offset), white_bg, line_width); | ||||
|             window->DrawList->AddLine(lower_handle_center + ImVec2(-0.5f * line_length, 0.0f), lower_handle_center + ImVec2(0.5f * line_length, 0.0f), white_bg, line_width); | ||||
|             window->DrawList->AddLine(lower_handle_center + ImVec2(0.0f, -0.5f * line_length), lower_handle_center + ImVec2(0.0f, 0.5f * line_length), white_bg, line_width); | ||||
|         } | ||||
| 
 | ||||
|         // draw higher label
 | ||||
|  | @ -823,7 +821,7 @@ bool IMSlider::vertical_slider(const char* str_id, int* higher_value, int* lower | |||
|         text_size = text_content_size + text_padding * 2; | ||||
|         ImVec2 text_start = ImVec2(higher_handle.Min.x - text_size.x - triangle_offsets[2].x, higher_handle_center.y - text_size.y); | ||||
|         ImRect text_rect(text_start, text_start + text_size); | ||||
|         ImGui::RenderFrame(text_rect.Min, text_rect.Max, white_bg, false, rounding); | ||||
|         ImGui::RenderFrame(text_rect.Min, text_rect.Max, white_bg, false, text_frame_rounding); | ||||
|         ImVec2 pos_1 = text_rect.Max - triangle_offsets[0]; | ||||
|         ImVec2 pos_2 = pos_1 - triangle_offsets[1]; | ||||
|         ImVec2 pos_3 = pos_1 + triangle_offsets[2]; | ||||
|  | @ -835,7 +833,7 @@ bool IMSlider::vertical_slider(const char* str_id, int* higher_value, int* lower | |||
|         text_size = text_content_size + text_padding * 2; | ||||
|         text_start        = ImVec2(lower_handle.Min.x - text_size.x - triangle_offsets[2].x, lower_handle_center.y); | ||||
|         text_rect = ImRect(text_start, text_start + text_size); | ||||
|         ImGui::RenderFrame(text_rect.Min, text_rect.Max, white_bg, false, rounding); | ||||
|         ImGui::RenderFrame(text_rect.Min, text_rect.Max, white_bg, false, text_frame_rounding); | ||||
|         pos_1 = ImVec2(text_rect.Max.x, text_rect.Min.y) - triangle_offsets[0]; | ||||
|         pos_2 = pos_1 + triangle_offsets[1]; | ||||
|         pos_3 = pos_1 + triangle_offsets[2]; | ||||
|  | @ -868,11 +866,11 @@ bool IMSlider::vertical_slider(const char* str_id, int* higher_value, int* lower | |||
|         } | ||||
| 
 | ||||
|         // draw handle
 | ||||
|         window->DrawList->AddLine(ImVec2(mid_x - bar_width, handle_center.y), ImVec2(mid_x + bar_width, handle_center.y), handle_clr, line_width); | ||||
|         window->DrawList->AddLine(ImVec2(mid_x - 0.5 * bar_width, handle_center.y), ImVec2(mid_x + 0.5 * bar_width, handle_center.y), handle_clr, 2 * line_width); | ||||
|         window->DrawList->AddCircleFilled(handle_center, handle_radius, handle_border_clr); | ||||
|         window->DrawList->AddCircleFilled(handle_center, handle_radius - handle_border, handle_clr); | ||||
|         window->DrawList->AddLine(handle_center + ImVec2(-line_offset, 0.0f), handle_center + ImVec2(line_offset, 0.0f), white_bg, line_width); | ||||
|         window->DrawList->AddLine(handle_center + ImVec2(0.0f, -line_offset), handle_center + ImVec2(0.0f, line_offset), white_bg, line_width); | ||||
|         window->DrawList->AddLine(handle_center + ImVec2(-0.5f * line_length, 0.0f), handle_center + ImVec2(0.5f * line_length, 0.0f), white_bg, line_width); | ||||
|         window->DrawList->AddLine(handle_center + ImVec2(0.0f, -0.5f * line_length), handle_center + ImVec2(0.0f, 0.5f * line_length), white_bg, line_width); | ||||
| 
 | ||||
|         // draw label
 | ||||
|         auto text_utf8 = into_u8(higher_label); | ||||
|  | @ -880,7 +878,7 @@ bool IMSlider::vertical_slider(const char* str_id, int* higher_value, int* lower | |||
|         text_size = text_content_size + text_padding * 2; | ||||
|         ImVec2 text_start = ImVec2(one_handle.Min.x - text_size.x, handle_center.y - 0.5 * text_size.y); | ||||
|         ImRect text_rect = ImRect(text_start, text_start + text_size); | ||||
|         ImGui::RenderFrame(text_rect.Min, text_rect.Max, white_bg, false, rounding); | ||||
|         ImGui::RenderFrame(text_rect.Min, text_rect.Max, white_bg, false, text_frame_rounding); | ||||
|         ImGui::RenderText(text_start + text_padding, higher_label.c_str()); | ||||
|     } | ||||
| 
 | ||||
|  | @ -908,22 +906,18 @@ bool IMSlider::render(int canvas_width, int canvas_height) | |||
|     float scale = (float) wxGetApp().em_unit() / 10.0f; | ||||
| 
 | ||||
|     if (is_horizontal()) { | ||||
|         float  pos_x = std::max(LEFT_MARGIN, 0.2f * canvas_width); | ||||
|         float  pos_y = (canvas_height - HORIZONTAL_SLIDER_SIZE.y * m_scale); | ||||
|         ImVec2 size  = ImVec2(canvas_width - 2 * pos_x, HORIZONTAL_SLIDER_SIZE.y * m_scale); | ||||
|         imgui.set_next_window_pos(pos_x, pos_y, ImGuiCond_Always); | ||||
|         ImVec2 size  = ImVec2(canvas_width - 2 * std::max(LEFT_MARGIN * m_scale, 0.2f * canvas_width), HORIZONTAL_SLIDER_WINDOW_HEIGHT * m_scale); | ||||
|         imgui.set_next_window_pos(0.5f * static_cast<float>(canvas_width), canvas_height, ImGuiCond_Always, 0.5f, 1.0f); | ||||
|         imgui.begin(std::string("moves_slider"), windows_flag); | ||||
|         int value = GetHigherValue(); | ||||
|         if (horizontal_slider("moves_slider", &value, GetMinValue(), GetMaxValue(),ImVec2(pos_x, pos_y), size, scale)) { | ||||
|         if (horizontal_slider("moves_slider", &value, GetMinValue(), GetMaxValue(), size, scale)) { | ||||
|             result = true; | ||||
|             SetHigherValue(value); | ||||
|         } | ||||
|         imgui.end(); | ||||
|     } else { | ||||
|         float  pos_x = canvas_width - (VERTICAL_SLIDER_SIZE.x + TEXT_WIDTH_DUMMY * scale - TEXT_WIDTH_DUMMY + ONE_LAYER_MARGIN) * m_scale; | ||||
|         float pos_y = std::max(ONE_LAYER_OFFSET.y, 0.15f * canvas_height - (VERTICAL_SLIDER_SIZE.y - SLIDER_LENGTH) * scale); | ||||
|         ImVec2 size = ImVec2((VERTICAL_SLIDER_SIZE.x + TEXT_WIDTH_DUMMY * scale - TEXT_WIDTH_DUMMY + ONE_LAYER_MARGIN) * m_scale, canvas_height - 2 * pos_y); | ||||
|         imgui.set_next_window_pos(pos_x, pos_y, ImGuiCond_Always); | ||||
|         ImVec2 size = ImVec2(VERTICAL_SLIDER_WINDOW_WIDTH * m_scale, 0.8f * canvas_height); | ||||
|         imgui.set_next_window_pos(canvas_width, 0.5f * static_cast<float>(canvas_height), ImGuiCond_Always, 1.0f, 0.5f); | ||||
|         imgui.begin(std::string("laysers_slider"), windows_flag); | ||||
| 
 | ||||
|         render_menu(); | ||||
|  | @ -935,26 +929,27 @@ bool IMSlider::render(int canvas_width, int canvas_height) | |||
|         int temp_higher_value    = higher_value; | ||||
|         int temp_lower_value     = lower_value; | ||||
|         if (vertical_slider("laysers_slider", &higher_value, &lower_value, higher_label, lower_label, GetMinValue(), GetMaxValue(), | ||||
|                   ImVec2(pos_x, pos_y), size, m_selection, is_one_layer(), scale)) { | ||||
|                   size, m_selection, is_one_layer(), scale)) { | ||||
|             if (temp_higher_value != higher_value) | ||||
|                 SetHigherValue(higher_value); | ||||
|             if (temp_lower_value != lower_value) | ||||
|                 SetLowerValue(lower_value); | ||||
|             result = true; | ||||
|         } | ||||
|         imgui.end(); | ||||
| 
 | ||||
|         ImGui::Spacing(); | ||||
|         ImGui::SameLine((VERTICAL_SLIDER_SIZE.x - ONE_LAYER_OFFSET.x) * scale * m_scale); | ||||
|         imgui.set_next_window_pos(canvas_width, canvas_height, ImGuiCond_Always, 1.0f, 1.0f); | ||||
|         ImGui::SetNextWindowSize((ONE_LAYER_BUTTON_SIZE + ONE_LAYER_MARGIN) * m_scale, 0); | ||||
|         imgui.begin(std::string("one_layer_button"), windows_flag); | ||||
|         ImTextureID normal_id = m_is_dark ? | ||||
|             is_one_layer() ? m_one_layer_on_dark_id : m_one_layer_off_dark_id : | ||||
|             is_one_layer() ? m_one_layer_on_id : m_one_layer_off_id; | ||||
|         ImTextureID hover_id  = m_is_dark ? | ||||
|             is_one_layer() ? m_one_layer_on_hover_dark_id : m_one_layer_off_hover_dark_id : | ||||
|             is_one_layer() ? m_one_layer_on_hover_id : m_one_layer_off_hover_id; | ||||
|         if (ImGui::ImageButton3(normal_id, hover_id, ImVec2(28 * m_scale, 28 * m_scale))) { | ||||
|         if (ImGui::ImageButton3(normal_id, hover_id, ONE_LAYER_BUTTON_SIZE * m_scale)) { | ||||
|             switch_one_layer_mode(); | ||||
|         } | ||||
| 
 | ||||
|         imgui.end(); | ||||
|     } | ||||
| 
 | ||||
|  |  | |||
|  | @ -136,16 +136,16 @@ protected: | |||
|     void do_go_to_layer(size_t layer_number); | ||||
|     void correct_lower_value(); | ||||
|     void correct_higher_value(); | ||||
|     bool horizontal_slider(const char* str_id, int* v, int v_min, int v_max, const ImVec2& pos, const ImVec2& size, float scale = 1.0); | ||||
|     bool horizontal_slider(const char* str_id, int* v, int v_min, int v_max, const ImVec2& size, float scale = 1.0); | ||||
|     void render_go_to_layer_dialog(); | ||||
|     void render_input_custom_gcode(); | ||||
|     void render_menu(); | ||||
|     void draw_background(const ImRect& groove); | ||||
|     void draw_background_and_groove(const ImRect& bg_rect, const ImRect& groove); | ||||
|     void draw_colored_band(const ImRect& groove, const ImRect& slideable_region); | ||||
|     void draw_ticks(const ImRect& slideable_region); | ||||
|     bool vertical_slider(const char* str_id, int* higher_value, int* lower_value, | ||||
|         std::string& higher_label, std::string& lower_label, | ||||
|         int v_min, int v_max, const ImVec2& pos, const ImVec2& size, | ||||
|         int v_min, int v_max, const ImVec2& size, | ||||
|         SelectedSlider& selection, bool one_layer_flag = false, float scale = 1.0f); | ||||
|     bool is_wipe_tower_layer(int tick) const; | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 liz.li
						liz.li