mirror of
				https://github.com/SoftFever/OrcaSlicer.git
				synced 2025-10-30 12:11:15 -06:00 
			
		
		
		
	fix position of window
This commit is contained in:
		
							parent
							
								
									21fd35d243
								
							
						
					
					
						commit
						268b06bdbb
					
				
					 2 changed files with 38 additions and 11 deletions
				
			
		|  | @ -53,10 +53,6 @@ void GLGizmoSimplify::on_render_input_window(float x, float y, float bottom_limi | |||
|     const int max_char_in_name = 25; | ||||
|     create_gui_cfg(); | ||||
| 
 | ||||
|     int flag = ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoResize | | ||||
|                ImGuiWindowFlags_NoCollapse; | ||||
|     m_imgui->begin(on_get_name(), flag); | ||||
| 
 | ||||
|     const Selection &selection = m_parent.get_selection(); | ||||
|     int object_idx = selection.get_object_idx(); | ||||
|     ModelObject *obj = wxGetApp().plater()->model().objects[object_idx]; | ||||
|  | @ -65,6 +61,12 @@ void GLGizmoSimplify::on_render_input_window(float x, float y, float bottom_limi | |||
|     // Check selection of new volume
 | ||||
|     // Do not reselect object when processing 
 | ||||
|     if (act_volume != volume && state == State::settings) { | ||||
|         bool change_window_position = (volume == nullptr); | ||||
|         // select different model
 | ||||
|         if (volume != nullptr && original_its.has_value()) { | ||||
|             set_its(*original_its); | ||||
|         } | ||||
| 
 | ||||
|         obj_index = object_idx; // to remember correct object
 | ||||
|         volume = act_volume; | ||||
|         original_its = {}; | ||||
|  | @ -72,13 +74,30 @@ void GLGizmoSimplify::on_render_input_window(float x, float y, float bottom_limi | |||
|         c.wanted_percent = 50.;  // default value
 | ||||
|         c.update_percent(tm.its.indices.size()); | ||||
|         is_valid_result = false; | ||||
|         // set window position
 | ||||
|         ImVec2 pos = ImGui::GetMousePos(); | ||||
|         pos.x -= gui_cfg->window_offset; | ||||
|         pos.y -= gui_cfg->window_offset; | ||||
|         ImGui::SetWindowPos(pos, ImGuiCond_Always); | ||||
| 
 | ||||
|         if (change_window_position) { | ||||
|             ImVec2 pos = ImGui::GetMousePos(); | ||||
|             pos.x -= gui_cfg->window_offset; | ||||
|             pos.y -= gui_cfg->window_offset; | ||||
|             // minimal top left value
 | ||||
|             ImVec2 tl(gui_cfg->window_padding, gui_cfg->window_padding); | ||||
|             if (pos.x < tl.x) pos.x = tl.x; | ||||
|             if (pos.y < tl.y) pos.y = tl.y; | ||||
|             // maximal bottom right value
 | ||||
|             auto parent_size = m_parent.get_canvas_size(); | ||||
|             ImVec2 br( | ||||
|                 parent_size.get_width() - (2 * gui_cfg->window_offset + gui_cfg->window_padding),  | ||||
|                 parent_size.get_height() - (2 * gui_cfg->window_offset + gui_cfg->window_padding)); | ||||
|             if (pos.x > br.x) pos.x = br.x; | ||||
|             if (pos.y > br.y) pos.y = br.y; | ||||
|             ImGui::SetNextWindowPos(pos, ImGuiCond_Always); | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     int flag = ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoResize | | ||||
|                ImGuiWindowFlags_NoCollapse; | ||||
|     m_imgui->begin(on_get_name(), flag); | ||||
| 
 | ||||
|     size_t triangle_count = volume->mesh().its.indices.size(); | ||||
|     // already reduced mesh
 | ||||
|     if (original_its.has_value()) | ||||
|  | @ -211,8 +230,6 @@ void GLGizmoSimplify::on_render_input_window(float x, float y, float bottom_limi | |||
| } | ||||
| 
 | ||||
| void GLGizmoSimplify::close() { | ||||
|     volume = nullptr; | ||||
|      | ||||
|     // close gizmo == open it again
 | ||||
|     GLGizmosManager &gizmos_mgr = m_parent.get_gizmos_manager(); | ||||
|     gizmos_mgr.open_gizmo(GLGizmosManager::EType::Simplify); | ||||
|  | @ -293,6 +310,14 @@ bool GLGizmoSimplify::on_is_activable() const | |||
|     return !m_parent.get_selection().is_empty(); | ||||
| } | ||||
| 
 | ||||
| void GLGizmoSimplify::on_set_state()  | ||||
| {  | ||||
|     // Closing gizmo. e.g. selecting another one
 | ||||
|     if (m_state == GLGizmoBase::Off) { | ||||
|         volume = nullptr;             | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| void GLGizmoSimplify::create_gui_cfg() {  | ||||
|     if (gui_cfg.has_value()) return; | ||||
| 
 | ||||
|  |  | |||
|  | @ -41,6 +41,7 @@ protected: | |||
|     virtual void on_render_input_window(float x, float y, float bottom_limit) override; | ||||
|     virtual bool on_is_activable() const override; | ||||
|     virtual bool on_is_selectable() const override { return false; } | ||||
|     virtual void on_set_state() override; | ||||
| 
 | ||||
| private: | ||||
|     void close(); | ||||
|  | @ -78,6 +79,7 @@ private: | |||
|         int input_width       = 100; | ||||
|         int input_small_width = 80; | ||||
|         int window_offset     = 100; | ||||
|         int window_padding    = 0; | ||||
|     }; | ||||
|     std::optional<GuiCfg> gui_cfg; | ||||
|     void create_gui_cfg(); | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Filip Sykala
						Filip Sykala