mirror of
				https://github.com/SoftFever/OrcaSlicer.git
				synced 2025-10-31 04:31:15 -06:00 
			
		
		
		
	Nearly finished refactoring of GLGizmoManager
This commit is contained in:
		
							parent
							
								
									409a7c7734
								
							
						
					
					
						commit
						d8a274c5ab
					
				
					 6 changed files with 142 additions and 291 deletions
				
			
		|  | @ -44,12 +44,12 @@ public: | |||
|     Vec3d get_flattening_normal() const; | ||||
| 
 | ||||
| protected: | ||||
|     virtual bool on_init(); | ||||
|     virtual std::string on_get_name() const; | ||||
|     virtual bool on_is_activable() const; | ||||
|     virtual void on_start_dragging(); | ||||
|     virtual void on_render() const; | ||||
|     virtual void on_render_for_picking() const; | ||||
|     virtual bool on_init() override; | ||||
|     virtual std::string on_get_name() const override; | ||||
|     virtual bool on_is_activable() const override; | ||||
|     virtual void on_start_dragging() override; | ||||
|     virtual void on_render() const override; | ||||
|     virtual void on_render_for_picking() const override; | ||||
|     virtual void on_set_state() override; | ||||
| }; | ||||
| 
 | ||||
|  |  | |||
|  | @ -87,16 +87,12 @@ protected: | |||
|     virtual void on_set_state() | ||||
|     { | ||||
|         for (GLGizmoRotate& g : m_gizmos) | ||||
|         { | ||||
|             g.set_state(m_state); | ||||
|         } | ||||
|     } | ||||
|     virtual void on_set_hover_id() | ||||
|     { | ||||
|         for (int i = 0; i < 3; ++i) | ||||
|         { | ||||
|             m_gizmos[i].set_hover_id((m_hover_id == i) ? 0 : -1); | ||||
|         } | ||||
|     } | ||||
|     virtual void on_enable_grabber(unsigned int id) | ||||
|     { | ||||
|  |  | |||
|  | @ -1099,9 +1099,6 @@ std::string GLGizmoSlaSupports::on_get_name() const | |||
| 
 | ||||
| void GLGizmoSlaSupports::on_set_state() | ||||
| { | ||||
|     if (m_state == Hover) | ||||
|         return; | ||||
| 
 | ||||
|     // m_model_object pointer can be invalid (for instance because of undo/redo action),
 | ||||
|     // we should recover it from the object id
 | ||||
|     m_model_object = nullptr; | ||||
|  |  | |||
|  | @ -78,7 +78,7 @@ private: | |||
| 
 | ||||
| public: | ||||
|     GLGizmoSlaSupports(GLCanvas3D& parent, const std::string& icon_filename, unsigned int sprite_id); | ||||
|     virtual ~GLGizmoSlaSupports(); | ||||
|     ~GLGizmoSlaSupports() override; | ||||
|     void set_sla_support_data(ModelObject* model_object, const Selection& selection); | ||||
|     bool gizmo_event(SLAGizmoEventType action, const Vec2d& mouse_position, bool shift_down, bool alt_down, bool control_down); | ||||
|     void delete_selected_points(bool force = false); | ||||
|  | @ -90,10 +90,10 @@ public: | |||
|     void reslice_SLA_supports(bool postpone_error_messages = false) const; | ||||
| 
 | ||||
| private: | ||||
|     bool on_init(); | ||||
|     void on_update(const UpdateData& data); | ||||
|     virtual void on_render() const; | ||||
|     virtual void on_render_for_picking() const; | ||||
|     bool on_init() override; | ||||
|     void on_update(const UpdateData& data) override; | ||||
|     virtual void on_render() const override; | ||||
|     virtual void on_render_for_picking() const override; | ||||
| 
 | ||||
|     //void render_selection_rectangle() const;
 | ||||
|     void render_points(const Selection& selection, bool picking = false) const; | ||||
|  | @ -157,7 +157,7 @@ private: | |||
| 
 | ||||
| protected: | ||||
|     void on_set_state() override; | ||||
|     virtual void on_set_hover_id() | ||||
|     virtual void on_set_hover_id() override | ||||
|     { | ||||
|         if (! m_editing_mode || (int)m_editing_cache.size() <= m_hover_id) | ||||
|             m_hover_id = -1; | ||||
|  | @ -166,9 +166,9 @@ protected: | |||
|     void on_stop_dragging() override; | ||||
|     virtual void on_render_input_window(float x, float y, float bottom_limit) override; | ||||
| 
 | ||||
|     virtual std::string on_get_name() const; | ||||
|     virtual bool on_is_activable() const; | ||||
|     virtual bool on_is_selectable() const; | ||||
|     virtual std::string on_get_name() const override; | ||||
|     virtual bool on_is_activable() const override; | ||||
|     virtual bool on_is_selectable() const override; | ||||
|     virtual void on_load(cereal::BinaryInputArchive& ar) override; | ||||
|     virtual void on_save(cereal::BinaryOutputArchive& ar) const override; | ||||
| }; | ||||
|  |  | |||
|  | @ -29,9 +29,49 @@ GLGizmosManager::GLGizmosManager(GLCanvas3D& parent) | |||
| { | ||||
| } | ||||
| 
 | ||||
| GLGizmosManager::~GLGizmosManager() | ||||
| std::vector<size_t> GLGizmosManager::get_selectable_idxs() const | ||||
| { | ||||
|     reset(); | ||||
|     std::vector<size_t> out; | ||||
|     for (size_t i=0; i<m_gizmos.size(); ++i) | ||||
|         if (m_gizmos[i]->is_selectable()) | ||||
|             out.push_back(i); | ||||
|     return out; | ||||
| } | ||||
| 
 | ||||
| std::vector<size_t> GLGizmosManager::get_activable_idxs() const | ||||
| { | ||||
|     std::vector<size_t> out; | ||||
|     for (size_t i=0; i<m_gizmos.size(); ++i) | ||||
|         if (m_gizmos[i]->is_activable()) | ||||
|             out.push_back(i); | ||||
|     return out; | ||||
| } | ||||
| 
 | ||||
| size_t GLGizmosManager::get_gizmo_idx_from_mouse(const Vec2d& mouse_pos) const | ||||
| { | ||||
|     if (! m_enabled) | ||||
|         return Undefined; | ||||
| 
 | ||||
|     float cnv_h = (float)m_parent.get_canvas_size().get_height(); | ||||
|     float height = get_total_overlay_height(); | ||||
|     float scaled_icons_size = m_overlay_icons_size * m_overlay_scale; | ||||
|     float scaled_border = m_overlay_border * m_overlay_scale; | ||||
|     float scaled_gap_y = m_overlay_gap_y * m_overlay_scale; | ||||
|     float scaled_stride_y = scaled_icons_size + scaled_gap_y; | ||||
|     float top_y = 0.5f * (cnv_h - height) + scaled_border; | ||||
| 
 | ||||
|     // is mouse horizontally in the area?
 | ||||
|     if ((scaled_border <= (float)mouse_pos(0) && ((float)mouse_pos(0) <= scaled_border + scaled_icons_size))) { | ||||
|         // which icon is it on?
 | ||||
|         size_t from_top = (size_t)((float)mouse_pos(1) - top_y)/scaled_stride_y; | ||||
|         // is it really on the icon or already past the border?
 | ||||
|         if ((float)mouse_pos(1) <= top_y + from_top*scaled_stride_y + scaled_icons_size) { | ||||
|             std::vector<size_t> selectable = get_selectable_idxs(); | ||||
|             if (from_top < selectable.size()) | ||||
|                 return selectable[from_top]; | ||||
|         } | ||||
|     } | ||||
|     return Undefined; | ||||
| } | ||||
| 
 | ||||
| bool GLGizmosManager::init() | ||||
|  | @ -45,78 +85,23 @@ bool GLGizmosManager::init() | |||
|     if (!m_background_texture.metadata.filename.empty()) | ||||
|     { | ||||
|         if (!m_background_texture.texture.load_from_file(resources_dir() + "/icons/" + m_background_texture.metadata.filename, false, GLTexture::SingleThreaded, false)) | ||||
|         { | ||||
|             reset(); | ||||
|             return false; | ||||
|     } | ||||
| 
 | ||||
|     m_gizmos.emplace_back(new GLGizmoMove3D(m_parent, "move.svg", 0)); | ||||
|     m_gizmos.emplace_back(new GLGizmoScale3D(m_parent, "scale.svg", 1)); | ||||
|     m_gizmos.emplace_back(new GLGizmoRotate3D(m_parent, "rotate.svg", 2)); | ||||
|     m_gizmos.emplace_back(new GLGizmoFlatten(m_parent, "place.svg", 3)); | ||||
|     m_gizmos.emplace_back(new GLGizmoCut(m_parent, "cut.svg", 4)); | ||||
|     m_gizmos.emplace_back(new GLGizmoSlaSupports(m_parent, "sla_supports.svg", 5)); | ||||
| 
 | ||||
|     for (auto& gizmo : m_gizmos) { | ||||
|         if (! gizmo->init()) { | ||||
|             m_gizmos.clear(); | ||||
|             return false; | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     GLGizmoBase* gizmo = new GLGizmoMove3D(m_parent, "move.svg", 0); | ||||
|     if (gizmo == nullptr) | ||||
|         return false; | ||||
| 
 | ||||
|     if (!gizmo->init()) | ||||
|         return false; | ||||
| 
 | ||||
|     m_gizmos.push_back(gizmo); | ||||
| 
 | ||||
|     gizmo = new GLGizmoScale3D(m_parent, "scale.svg", 1); | ||||
|     if (gizmo == nullptr) | ||||
|         return false; | ||||
| 
 | ||||
|     if (!gizmo->init()) | ||||
|         return false; | ||||
| 
 | ||||
|     m_gizmos.push_back(gizmo); | ||||
| 
 | ||||
|     gizmo = new GLGizmoRotate3D(m_parent, "rotate.svg", 2); | ||||
|     if (gizmo == nullptr) | ||||
|     { | ||||
|         reset(); | ||||
|         return false; | ||||
|     } | ||||
| 
 | ||||
|     if (!gizmo->init()) | ||||
|     { | ||||
|         reset(); | ||||
|         return false; | ||||
|     } | ||||
| 
 | ||||
|     m_gizmos.push_back(gizmo); | ||||
| 
 | ||||
|     gizmo = new GLGizmoFlatten(m_parent, "place.svg", 3); | ||||
|     if (gizmo == nullptr) | ||||
|         return false; | ||||
| 
 | ||||
|     if (!gizmo->init()) { | ||||
|         reset(); | ||||
|         return false; | ||||
|     } | ||||
| 
 | ||||
|     m_gizmos.push_back(gizmo); | ||||
| 
 | ||||
|     gizmo = new GLGizmoCut(m_parent, "cut.svg", 4); | ||||
|     if (gizmo == nullptr) | ||||
|         return false; | ||||
| 
 | ||||
|     if (!gizmo->init()) { | ||||
|         reset(); | ||||
|         return false; | ||||
|     } | ||||
| 
 | ||||
|     m_gizmos.push_back(gizmo); | ||||
| 
 | ||||
|     gizmo = new GLGizmoSlaSupports(m_parent, "sla_supports.svg", 5); | ||||
|     if (gizmo == nullptr) | ||||
|         return false; | ||||
| 
 | ||||
|     if (!gizmo->init()) { | ||||
|         reset(); | ||||
|         return false; | ||||
|     } | ||||
| 
 | ||||
|     m_gizmos.push_back(gizmo); | ||||
| 
 | ||||
|     m_current = Undefined; | ||||
|     m_hover = Undefined; | ||||
| 
 | ||||
|  | @ -146,22 +131,13 @@ void GLGizmosManager::refresh_on_off_state() | |||
|     if (m_serializing || m_current == Undefined || m_gizmos.empty()) | ||||
|         return; | ||||
| 
 | ||||
|     GLGizmoBase* gizmo = m_gizmos[m_current]; | ||||
|     if (gizmo != nullptr) | ||||
|     { | ||||
|         if (!gizmo->is_activable()) | ||||
|         { | ||||
|             activate_gizmo(Undefined); | ||||
|         } | ||||
|     } | ||||
|     if (m_current != Undefined && ! m_gizmos[m_current]->is_activable()) | ||||
|         activate_gizmo(Undefined); | ||||
| } | ||||
| 
 | ||||
| void GLGizmosManager::reset_all_states() | ||||
| { | ||||
|     if (!m_enabled) | ||||
|         return; | ||||
| 
 | ||||
|     if (m_serializing) | ||||
|     if (! m_enabled || m_serializing) | ||||
|         return; | ||||
| 
 | ||||
|     activate_gizmo(Undefined); | ||||
|  | @ -270,23 +246,12 @@ bool GLGizmosManager::handle_shortcut(int key) | |||
| 
 | ||||
|     bool handled = false; | ||||
| 
 | ||||
|     for (size_t idx=0; idx<Undefined; ++idx) { | ||||
|         GLGizmoBase* gizmo = m_gizmos[idx]; | ||||
|         if ((gizmo == nullptr) || !gizmo->is_selectable()) | ||||
|             continue; | ||||
|     for (size_t idx : get_selectable_idxs()) { | ||||
|         int it_key = m_gizmos[idx]->get_shortcut_key(); | ||||
| 
 | ||||
|         int it_key = gizmo->get_shortcut_key(); | ||||
| 
 | ||||
|         if (gizmo->is_activable() && ((it_key == key - 64) || (it_key == key - 96))) | ||||
|         { | ||||
|             if (m_current == idx) { | ||||
|                 activate_gizmo(Undefined); | ||||
|         if (m_gizmos[idx]->is_activable() && ((it_key == key - 64) || (it_key == key - 96))) { | ||||
|                 activate_gizmo(m_current == idx ? Undefined : (EType)idx); | ||||
|                 handled = true; | ||||
|             } | ||||
|             else if (m_current != idx) { | ||||
|                 activate_gizmo((EType)idx); | ||||
|                 handled = true; | ||||
|             } | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|  | @ -295,31 +260,25 @@ bool GLGizmosManager::handle_shortcut(int key) | |||
| 
 | ||||
| bool GLGizmosManager::is_dragging() const | ||||
| { | ||||
|     if (!m_enabled) | ||||
|     if (! m_enabled || m_current == Undefined) | ||||
|         return false; | ||||
| 
 | ||||
|     GLGizmoBase* curr = get_current(); | ||||
|     return (curr != nullptr) ? curr->is_dragging() : false; | ||||
|     return m_gizmos[m_current]->is_dragging(); | ||||
| } | ||||
| 
 | ||||
| void GLGizmosManager::start_dragging() | ||||
| { | ||||
|     if (!m_enabled) | ||||
|     if (! m_enabled || m_current == Undefined) | ||||
|         return; | ||||
| 
 | ||||
|     GLGizmoBase* curr = get_current(); | ||||
|     if (curr != nullptr) | ||||
|         curr->start_dragging(); | ||||
|     m_gizmos[m_current]->start_dragging(); | ||||
| } | ||||
| 
 | ||||
| void GLGizmosManager::stop_dragging() | ||||
| { | ||||
|     if (!m_enabled) | ||||
|     if (! m_enabled || m_current == Undefined) | ||||
|         return; | ||||
| 
 | ||||
|     GLGizmoBase* curr = get_current(); | ||||
|     if (curr != nullptr) | ||||
|         curr->stop_dragging(); | ||||
|     m_gizmos[m_current]->stop_dragging(); | ||||
| } | ||||
| 
 | ||||
| Vec3d GLGizmosManager::get_displacement() const | ||||
|  | @ -327,7 +286,7 @@ Vec3d GLGizmosManager::get_displacement() const | |||
|     if (!m_enabled) | ||||
|         return Vec3d::Zero(); | ||||
| 
 | ||||
|     return reinterpret_cast<GLGizmoMove3D*>(m_gizmos[Move])->get_displacement(); | ||||
|     return dynamic_cast<GLGizmoMove3D*>(m_gizmos[Move].get())->get_displacement(); | ||||
| } | ||||
| 
 | ||||
| Vec3d GLGizmosManager::get_scale() const | ||||
|  | @ -335,7 +294,7 @@ Vec3d GLGizmosManager::get_scale() const | |||
|     if (!m_enabled) | ||||
|         return Vec3d::Ones(); | ||||
| 
 | ||||
|     return reinterpret_cast<GLGizmoScale3D*>(m_gizmos[Scale])->get_scale(); | ||||
|     return dynamic_cast<GLGizmoScale3D*>(m_gizmos[Scale].get())->get_scale(); | ||||
| } | ||||
| 
 | ||||
| void GLGizmosManager::set_scale(const Vec3d& scale) | ||||
|  | @ -343,7 +302,7 @@ void GLGizmosManager::set_scale(const Vec3d& scale) | |||
|     if (!m_enabled || m_gizmos.empty()) | ||||
|         return; | ||||
| 
 | ||||
|     reinterpret_cast<GLGizmoScale3D*>(m_gizmos[Scale])->set_scale(scale); | ||||
|     dynamic_cast<GLGizmoScale3D*>(m_gizmos[Scale].get())->set_scale(scale); | ||||
| } | ||||
| 
 | ||||
| Vec3d GLGizmosManager::get_scale_offset() const | ||||
|  | @ -351,7 +310,7 @@ Vec3d GLGizmosManager::get_scale_offset() const | |||
|     if (!m_enabled || m_gizmos.empty()) | ||||
|         return Vec3d::Zero(); | ||||
| 
 | ||||
|     return reinterpret_cast<GLGizmoScale3D*>(m_gizmos[Scale])->get_offset(); | ||||
|     return dynamic_cast<GLGizmoScale3D*>(m_gizmos[Scale].get())->get_offset(); | ||||
| } | ||||
| 
 | ||||
| Vec3d GLGizmosManager::get_rotation() const | ||||
|  | @ -359,14 +318,14 @@ Vec3d GLGizmosManager::get_rotation() const | |||
|     if (!m_enabled || m_gizmos.empty()) | ||||
|         return Vec3d::Zero(); | ||||
| 
 | ||||
|     return reinterpret_cast<GLGizmoRotate3D*>(m_gizmos[Rotate])->get_rotation(); | ||||
|     return dynamic_cast<GLGizmoRotate3D*>(m_gizmos[Rotate].get())->get_rotation(); | ||||
| } | ||||
| 
 | ||||
| void GLGizmosManager::set_rotation(const Vec3d& rotation) | ||||
| { | ||||
|     if (!m_enabled || m_gizmos.empty()) | ||||
|         return; | ||||
|     reinterpret_cast<GLGizmoRotate3D*>(m_gizmos[Rotate])->set_rotation(rotation); | ||||
|     dynamic_cast<GLGizmoRotate3D*>(m_gizmos[Rotate].get())->set_rotation(rotation); | ||||
| } | ||||
| 
 | ||||
| Vec3d GLGizmosManager::get_flattening_normal() const | ||||
|  | @ -374,7 +333,7 @@ Vec3d GLGizmosManager::get_flattening_normal() const | |||
|     if (!m_enabled || m_gizmos.empty()) | ||||
|         return Vec3d::Zero(); | ||||
| 
 | ||||
|     return reinterpret_cast<GLGizmoFlatten*>(m_gizmos[Flatten])->get_flattening_normal(); | ||||
|     return dynamic_cast<GLGizmoFlatten*>(m_gizmos[Flatten].get())->get_flattening_normal(); | ||||
| } | ||||
| 
 | ||||
| void GLGizmosManager::set_flattening_data(const ModelObject* model_object) | ||||
|  | @ -382,7 +341,7 @@ void GLGizmosManager::set_flattening_data(const ModelObject* model_object) | |||
|     if (!m_enabled || m_gizmos.empty()) | ||||
|         return; | ||||
| 
 | ||||
|     reinterpret_cast<GLGizmoFlatten*>(m_gizmos[Flatten])->set_flattening_data(model_object); | ||||
|     dynamic_cast<GLGizmoFlatten*>(m_gizmos[Flatten].get())->set_flattening_data(model_object); | ||||
| } | ||||
| 
 | ||||
| void GLGizmosManager::set_sla_support_data(ModelObject* model_object) | ||||
|  | @ -390,7 +349,7 @@ void GLGizmosManager::set_sla_support_data(ModelObject* model_object) | |||
|     if (!m_enabled || m_gizmos.empty()) | ||||
|         return; | ||||
| 
 | ||||
|     reinterpret_cast<GLGizmoSlaSupports*>(m_gizmos[SlaSupports])->set_sla_support_data(model_object, m_parent.get_selection()); | ||||
|     dynamic_cast<GLGizmoSlaSupports*>(m_gizmos[SlaSupports].get())->set_sla_support_data(model_object, m_parent.get_selection()); | ||||
| } | ||||
| 
 | ||||
| // Returns true if the gizmo used the event to do something, false otherwise.
 | ||||
|  | @ -399,7 +358,7 @@ bool GLGizmosManager::gizmo_event(SLAGizmoEventType action, const Vec2d& mouse_p | |||
|     if (!m_enabled || m_gizmos.empty()) | ||||
|         return false; | ||||
| 
 | ||||
|     return reinterpret_cast<GLGizmoSlaSupports*>(m_gizmos[SlaSupports])->gizmo_event(action, mouse_position, shift_down, alt_down, control_down); | ||||
|     return dynamic_cast<GLGizmoSlaSupports*>(m_gizmos[SlaSupports].get())->gizmo_event(action, mouse_position, shift_down, alt_down, control_down); | ||||
| } | ||||
| 
 | ||||
| ClippingPlane GLGizmosManager::get_sla_clipping_plane() const | ||||
|  | @ -407,33 +366,29 @@ ClippingPlane GLGizmosManager::get_sla_clipping_plane() const | |||
|     if (!m_enabled || m_current != SlaSupports || m_gizmos.empty()) | ||||
|         return ClippingPlane::ClipsNothing(); | ||||
| 
 | ||||
|     return reinterpret_cast<GLGizmoSlaSupports*>(m_gizmos[SlaSupports])->get_sla_clipping_plane(); | ||||
|     return dynamic_cast<GLGizmoSlaSupports*>(m_gizmos[SlaSupports].get())->get_sla_clipping_plane(); | ||||
| } | ||||
| 
 | ||||
| bool GLGizmosManager::wants_reslice_supports_on_undo() const | ||||
| { | ||||
|     return (m_current == SlaSupports | ||||
|         && dynamic_cast<const GLGizmoSlaSupports*>(m_gizmos.at(SlaSupports))->has_backend_supports()); | ||||
|         && dynamic_cast<const GLGizmoSlaSupports*>(m_gizmos.at(SlaSupports).get())->has_backend_supports()); | ||||
| } | ||||
| 
 | ||||
| void GLGizmosManager::render_current_gizmo() const | ||||
| { | ||||
|     if (!m_enabled) | ||||
|     if (!m_enabled || m_current == Undefined) | ||||
|         return; | ||||
| 
 | ||||
|     GLGizmoBase* curr = get_current(); | ||||
|     if (curr != nullptr) | ||||
|         curr->render(); | ||||
|     m_gizmos[m_current]->render(); | ||||
| } | ||||
| 
 | ||||
| void GLGizmosManager::render_current_gizmo_for_picking_pass() const | ||||
| { | ||||
|     if (!m_enabled) | ||||
|     if (! m_enabled || m_current == Undefined) | ||||
|         return; | ||||
| 
 | ||||
|     GLGizmoBase* curr = get_current(); | ||||
|     if (curr != nullptr) | ||||
|         curr->render_for_picking(); | ||||
|     m_gizmos[m_current]->render_for_picking(); | ||||
| } | ||||
| 
 | ||||
| void GLGizmosManager::render_overlay() const | ||||
|  | @ -492,7 +447,7 @@ bool GLGizmosManager::on_mouse(wxMouseEvent& evt) | |||
|         // if the button down was done on this toolbar, prevent from dragging into the scene
 | ||||
|         processed = true; | ||||
| 
 | ||||
|     if (!overlay_contains_mouse(mouse_pos)) | ||||
|     if (get_gizmo_idx_from_mouse(mouse_pos) == Undefined) | ||||
|     { | ||||
|         // mouse is outside the toolbar
 | ||||
|         m_tooltip = ""; | ||||
|  | @ -502,14 +457,12 @@ bool GLGizmosManager::on_mouse(wxMouseEvent& evt) | |||
|             if ((m_current == SlaSupports) && gizmo_event(SLAGizmoEventType::LeftDown, mouse_pos, evt.ShiftDown(), evt.AltDown(), evt.ControlDown())) | ||||
|                 // the gizmo got the event and took some action, there is no need to do anything more
 | ||||
|                 processed = true; | ||||
|             else if (!selection.is_empty() && grabber_contains_mouse()) | ||||
|             { | ||||
|             else if (!selection.is_empty() && grabber_contains_mouse()) { | ||||
|                 update_data(); | ||||
|                 selection.start_dragging(); | ||||
|                 start_dragging(); | ||||
| 
 | ||||
|                 if (m_current == Flatten) | ||||
|                 { | ||||
|                 if (m_current == Flatten) { | ||||
|                     // Rotate the object so the normal points downward:
 | ||||
|                     m_parent.do_flatten(get_flattening_normal(), L("Gizmo-Place on Face")); | ||||
|                     wxGetApp().obj_manipul()->set_dirty(); | ||||
|  | @ -579,25 +532,14 @@ bool GLGizmosManager::on_mouse(wxMouseEvent& evt) | |||
|         } | ||||
|         else if (evt.LeftUp() && is_dragging()) | ||||
|         { | ||||
|             switch (m_current) | ||||
|             { | ||||
|             case Move: | ||||
|             { | ||||
|                 m_parent.do_move(L("Gizmo-Move")); | ||||
|                 break; | ||||
|             } | ||||
|             case Scale: | ||||
|             { | ||||
|                 m_parent.do_scale(L("Gizmo-Scale")); | ||||
|                 break; | ||||
|             } | ||||
|             case Rotate: | ||||
|             { | ||||
|                 m_parent.do_rotate(L("Gizmo-Rotate")); | ||||
|                 break; | ||||
|             } | ||||
|             default: | ||||
|                 break; | ||||
|             switch (m_current) { | ||||
|             case Move : m_parent.do_move(L("Gizmo-Move")); | ||||
|                         break; | ||||
|             case Scale : m_parent.do_scale(L("Gizmo-Scale")); | ||||
|                          break; | ||||
|             case Rotate : m_parent.do_rotate(L("Gizmo-Rotate")); | ||||
|                           break; | ||||
|             default : break; | ||||
|             } | ||||
| 
 | ||||
|             stop_dragging(); | ||||
|  | @ -787,7 +729,7 @@ bool GLGizmosManager::on_key(wxKeyEvent& evt) | |||
|     { | ||||
|         if (m_current == SlaSupports) | ||||
|         { | ||||
|             GLGizmoSlaSupports* gizmo = reinterpret_cast<GLGizmoSlaSupports*>(get_current()); | ||||
|             GLGizmoSlaSupports* gizmo = dynamic_cast<GLGizmoSlaSupports*>(get_current()); | ||||
| 
 | ||||
|             if (keyCode == WXK_SHIFT) | ||||
|             { | ||||
|  | @ -808,7 +750,8 @@ bool GLGizmosManager::on_key(wxKeyEvent& evt) | |||
|     } | ||||
|     else if (evt.GetEventType() == wxEVT_KEY_DOWN) | ||||
|     { | ||||
|         if ((m_current == SlaSupports) && ((keyCode == WXK_SHIFT) || (keyCode == WXK_ALT)) && reinterpret_cast<GLGizmoSlaSupports*>(get_current())->is_in_editing_mode()) | ||||
|         if ((m_current == SlaSupports) && ((keyCode == WXK_SHIFT) || (keyCode == WXK_ALT)) | ||||
|           && dynamic_cast<GLGizmoSlaSupports*>(get_current())->is_in_editing_mode()) | ||||
|         { | ||||
| //            m_parent.set_cursor(GLCanvas3D::Cross);
 | ||||
|             processed = true; | ||||
|  | @ -827,18 +770,7 @@ void GLGizmosManager::update_after_undo_redo(const UndoRedo::Snapshot& snapshot) | |||
|     m_serializing = false; | ||||
|     if (m_current == SlaSupports | ||||
|      && snapshot.snapshot_data.flags & UndoRedo::SnapshotData::RECALCULATE_SLA_SUPPORTS) | ||||
|         dynamic_cast<GLGizmoSlaSupports*>(m_gizmos[SlaSupports])->reslice_SLA_supports(true); | ||||
| } | ||||
| 
 | ||||
| void GLGizmosManager::reset() | ||||
| { | ||||
|     for (GLGizmoBase* gizmo : m_gizmos) | ||||
|     { | ||||
|         delete gizmo; | ||||
|         gizmo = nullptr; | ||||
|     } | ||||
| 
 | ||||
|     m_gizmos.clear(); | ||||
|         dynamic_cast<GLGizmoSlaSupports*>(m_gizmos[SlaSupports].get())->reslice_SLA_supports(true); | ||||
| } | ||||
| 
 | ||||
| void GLGizmosManager::render_background(float left, float top, float right, float bottom, float border) const | ||||
|  | @ -856,7 +788,7 @@ void GLGizmosManager::render_background(float left, float top, float right, floa | |||
|         float internal_top = top - border; | ||||
|         float internal_bottom = bottom + border; | ||||
| 
 | ||||
|         float left_uv = 0.0f; | ||||
|         // float left_uv = 0.0f;
 | ||||
|         float right_uv = 1.0f; | ||||
|         float top_uv = 1.0f; | ||||
|         float bottom_uv = 0.0f; | ||||
|  | @ -926,19 +858,17 @@ void GLGizmosManager::do_render_overlay() const | |||
|     float scaled_icons_size = m_overlay_icons_size * m_overlay_scale * inv_zoom; | ||||
|     float scaled_stride_y = scaled_icons_size + scaled_gap_y; | ||||
|     unsigned int icons_texture_id = m_icons_texture.get_id(); | ||||
|     unsigned int tex_width = m_icons_texture.get_width(); | ||||
|     unsigned int tex_height = m_icons_texture.get_height(); | ||||
|     float inv_tex_width = (tex_width != 0) ? 1.0f / (float)tex_width : 0.0f; | ||||
|     float inv_tex_height = (tex_height != 0) ? 1.0f / (float)tex_height : 0.0f; | ||||
|     int tex_width = m_icons_texture.get_width(); | ||||
|     int tex_height = m_icons_texture.get_height(); | ||||
|     float inv_tex_width = (tex_width != 0) ? 1.0f / tex_width : 0.0f; | ||||
|     float inv_tex_height = (tex_height != 0) ? 1.0f / tex_height : 0.0f; | ||||
| 
 | ||||
|     if ((icons_texture_id == 0) || (tex_width <= 0) || (tex_height <= 0)) | ||||
|         return; | ||||
| 
 | ||||
|     for (size_t idx=0; idx<m_gizmos.size(); ++idx) | ||||
|     for (size_t idx : get_selectable_idxs()) | ||||
|     { | ||||
|         GLGizmoBase* gizmo = m_gizmos[idx]; | ||||
|         if ((gizmo == nullptr) || !gizmo->is_selectable()) | ||||
|             continue; | ||||
|         GLGizmoBase* gizmo = m_gizmos[idx].get(); | ||||
| 
 | ||||
|         unsigned int sprite_id = gizmo->get_sprite_id(); | ||||
|         int icon_idx = m_current == idx ? 2 : (m_hover == idx ? 1 : 0); | ||||
|  | @ -952,7 +882,7 @@ void GLGizmosManager::do_render_overlay() const | |||
| 
 | ||||
|         GLTexture::render_sub_texture(icons_texture_id, top_x, top_x + scaled_icons_size, top_y - scaled_icons_size, top_y, { { u_left, v_bottom }, { u_right, v_bottom }, { u_right, v_top }, { u_left, v_top } }); | ||||
|         if (idx == m_current) { | ||||
|             float toolbar_top = (float)cnv_h - m_parent.get_view_toolbar_height(); | ||||
|             float toolbar_top = cnv_h - m_parent.get_view_toolbar_height(); | ||||
|             gizmo->render_input_window(width, 0.5f * cnv_h - top_y * zoom, toolbar_top); | ||||
|         } | ||||
|         top_y -= scaled_stride_y; | ||||
|  | @ -967,13 +897,14 @@ float GLGizmosManager::get_total_overlay_height() const | |||
|     float scaled_stride_y = scaled_icons_size + scaled_gap_y; | ||||
|     float height = 2.0f * scaled_border; | ||||
| 
 | ||||
|     for (size_t idx=0; idx<m_gizmos.size(); ++idx) | ||||
|     /*for (size_t idx=0; idx<m_gizmos.size(); ++idx)
 | ||||
|     { | ||||
|         if ((m_gizmos[idx] == nullptr) || !m_gizmos[idx]->is_selectable()) | ||||
|             continue; | ||||
| 
 | ||||
|         height += scaled_stride_y; | ||||
|     } | ||||
|     }*/ | ||||
|     height += get_selectable_idxs().size() * scaled_stride_y; | ||||
| 
 | ||||
|     return height - scaled_gap_y; | ||||
| } | ||||
|  | @ -988,7 +919,7 @@ GLGizmoBase* GLGizmosManager::get_current() const | |||
|     if (m_current==Undefined || m_gizmos.empty()) | ||||
|         return nullptr; | ||||
|     else | ||||
|         return m_gizmos[m_current]; | ||||
|         return m_gizmos[m_current].get(); | ||||
| } | ||||
| 
 | ||||
| bool GLGizmosManager::generate_icons_texture() const | ||||
|  | @ -1022,34 +953,9 @@ void GLGizmosManager::update_on_off_state(const Vec2d& mouse_pos) | |||
|     if (!m_enabled) | ||||
|         return; | ||||
| 
 | ||||
|     float cnv_h = (float)m_parent.get_canvas_size().get_height(); | ||||
|     float height = get_total_overlay_height(); | ||||
| 
 | ||||
|     float scaled_icons_size = m_overlay_icons_size * m_overlay_scale; | ||||
|     float scaled_border = m_overlay_border * m_overlay_scale; | ||||
|     float scaled_gap_y = m_overlay_gap_y * m_overlay_scale; | ||||
|     float scaled_stride_y = scaled_icons_size + scaled_gap_y; | ||||
|     float top_y = 0.5f * (cnv_h - height) + scaled_border; | ||||
| 
 | ||||
|     for (size_t idx = Move; idx<Undefined; ++idx) { | ||||
|         GLGizmoBase* gizmo = m_gizmos[idx]; | ||||
|         if ((gizmo == nullptr) || !gizmo->is_selectable()) | ||||
|             continue; | ||||
| 
 | ||||
|         bool inside = (scaled_border <= (float)mouse_pos(0)) && ((float)mouse_pos(0) <= scaled_border + scaled_icons_size) && (top_y <= (float)mouse_pos(1)) && ((float)mouse_pos(1) <= top_y + scaled_icons_size); | ||||
|         if (gizmo->is_activable() && inside) | ||||
|         { | ||||
|             if (m_hover == idx) { | ||||
|                 if (m_current == idx) | ||||
|                     activate_gizmo(Undefined); | ||||
|                 else | ||||
|                     activate_gizmo((EType)idx); | ||||
|                 //gizmo->set_state(m_current == idx ? GLGizmoBase::Off : GLGizmoBase::On);
 | ||||
|                 //m_current = (EType)(m_current == idx ? Undefined : idx);
 | ||||
|             } | ||||
|         } | ||||
|         top_y += scaled_stride_y; | ||||
|     } | ||||
|     size_t idx = get_gizmo_idx_from_mouse(mouse_pos); | ||||
|     if (idx != Undefined && m_gizmos[idx]->is_activable() && m_hover == idx) | ||||
|         activate_gizmo(m_current == idx ? Undefined : (EType)idx); | ||||
| } | ||||
| 
 | ||||
| std::string GLGizmosManager::update_hover_state(const Vec2d& mouse_pos) | ||||
|  | @ -1059,30 +965,14 @@ std::string GLGizmosManager::update_hover_state(const Vec2d& mouse_pos) | |||
|     if (!m_enabled) | ||||
|         return name; | ||||
| 
 | ||||
|     float cnv_h = (float)m_parent.get_canvas_size().get_height(); | ||||
|     float height = get_total_overlay_height(); | ||||
|     float scaled_icons_size = m_overlay_icons_size * m_overlay_scale; | ||||
|     float scaled_border = m_overlay_border * m_overlay_scale; | ||||
|     float scaled_gap_y = m_overlay_gap_y * m_overlay_scale; | ||||
|     float scaled_stride_y = scaled_icons_size + scaled_gap_y; | ||||
|     float top_y = 0.5f * (cnv_h - height) + scaled_border; | ||||
| 
 | ||||
|     m_hover = Undefined; | ||||
| 
 | ||||
|     for (size_t idx=0; idx<Undefined; ++idx) | ||||
|     { | ||||
|         GLGizmoBase* gizmo = m_gizmos[idx]; | ||||
|         if ((gizmo == nullptr) || !gizmo->is_selectable()) | ||||
|             continue; | ||||
|     size_t idx = get_gizmo_idx_from_mouse(mouse_pos); | ||||
|     if (idx != Undefined) { | ||||
|         name = m_gizmos[idx]->get_name(); | ||||
| 
 | ||||
|         bool inside = (scaled_border <= (float)mouse_pos(0)) && ((float)mouse_pos(0) <= scaled_border + scaled_icons_size) && (top_y <= (float)mouse_pos(1)) && ((float)mouse_pos(1) <= top_y + scaled_icons_size); | ||||
|         if (inside) | ||||
|             name = gizmo->get_name(); | ||||
| 
 | ||||
|         if (gizmo->is_activable() && inside) | ||||
|         if (m_gizmos[idx]->is_activable()) | ||||
|             m_hover = (EType)idx; | ||||
| 
 | ||||
|         top_y += scaled_stride_y; | ||||
|     } | ||||
| 
 | ||||
|     return name; | ||||
|  | @ -1093,44 +983,18 @@ void GLGizmosManager::activate_gizmo(EType type) | |||
|     if (m_gizmos.empty() || m_current == type) | ||||
|         return; | ||||
| 
 | ||||
|     if (m_current != Undefined) | ||||
|     if (m_current != Undefined) { | ||||
|         m_gizmos[m_current]->set_state(GLGizmoBase::Off); | ||||
|         if (m_gizmos[m_current]->get_state() != GLGizmoBase::Off) | ||||
|             return; // gizmo refused to be turned off, do nothing.
 | ||||
|     } | ||||
| 
 | ||||
|     if (type != Undefined) | ||||
|         m_gizmos[type]->set_state(GLGizmoBase::On); | ||||
| 
 | ||||
|     m_current = type; | ||||
| 
 | ||||
| } | ||||
| 
 | ||||
| bool GLGizmosManager::overlay_contains_mouse(const Vec2d& mouse_pos) const | ||||
| { | ||||
|     if (!m_enabled) | ||||
|         return false; | ||||
| 
 | ||||
|     float cnv_h = (float)m_parent.get_canvas_size().get_height(); | ||||
|     float height = get_total_overlay_height(); | ||||
| 
 | ||||
|     float scaled_icons_size = m_overlay_icons_size * m_overlay_scale; | ||||
|     float scaled_border = m_overlay_border * m_overlay_scale; | ||||
|     float scaled_gap_y = m_overlay_gap_y * m_overlay_scale; | ||||
|     float scaled_stride_y = scaled_icons_size + scaled_gap_y; | ||||
|     float top_y = 0.5f * (cnv_h - height) + scaled_border; | ||||
| 
 | ||||
|     for (size_t idx=0; idx<Undefined; ++idx) | ||||
|     { | ||||
|         GLGizmoBase* gizmo = m_gizmos[idx]; | ||||
|         if ((gizmo == nullptr) || !gizmo->is_selectable()) | ||||
|             continue; | ||||
| 
 | ||||
|         if ((scaled_border <= (float)mouse_pos(0)) && ((float)mouse_pos(0) <= scaled_border + scaled_icons_size) && (top_y <= (float)mouse_pos(1)) && ((float)mouse_pos(1) <= top_y + scaled_icons_size)) | ||||
|             return true; | ||||
| 
 | ||||
|         top_y += scaled_stride_y; | ||||
|     } | ||||
| 
 | ||||
|     return false; | ||||
| } | ||||
| 
 | ||||
| bool GLGizmosManager::grabber_contains_mouse() const | ||||
| { | ||||
|  |  | |||
|  | @ -66,16 +66,17 @@ public: | |||
| private: | ||||
|     GLCanvas3D& m_parent; | ||||
|     bool m_enabled; | ||||
|     typedef std::map<EType, GLGizmoBase*> GizmosMap; | ||||
| //    GizmosMap m_gizmos;
 | ||||
|     typedef std::vector<GLGizmoBase*> Gizmos; | ||||
|     Gizmos m_gizmos; | ||||
|     std::vector<std::unique_ptr<GLGizmoBase>> m_gizmos; | ||||
|     mutable GLTexture m_icons_texture; | ||||
|     mutable bool m_icons_texture_dirty; | ||||
|     BackgroundTexture m_background_texture; | ||||
|     EType m_current; | ||||
|     EType m_hover; | ||||
| 
 | ||||
|     std::vector<size_t> get_selectable_idxs() const; | ||||
|     std::vector<size_t> get_activable_idxs() const; | ||||
|     size_t get_gizmo_idx_from_mouse(const Vec2d& mouse_pos) const; | ||||
| 
 | ||||
|     void activate_gizmo(EType type); | ||||
| 
 | ||||
|     float m_overlay_icons_size; | ||||
|  | @ -102,7 +103,6 @@ private: | |||
| 
 | ||||
| public: | ||||
|     explicit GLGizmosManager(GLCanvas3D& parent); | ||||
|     ~GLGizmosManager(); | ||||
| 
 | ||||
|     bool init(); | ||||
| 
 | ||||
|  | @ -114,10 +114,7 @@ public: | |||
| 
 | ||||
|         m_serializing = true; | ||||
| 
 | ||||
|         EType current = m_current; | ||||
|         ar(m_current); | ||||
|         //std::swap(current, m_current); // undo the deserialization, let activate_gizmo do the change
 | ||||
|         //activate_gizmo(current);
 | ||||
| 
 | ||||
|         if (m_current != Undefined) | ||||
|             m_gizmos[m_current]->load(ar); | ||||
|  | @ -193,8 +190,6 @@ public: | |||
|     void update_after_undo_redo(const UndoRedo::Snapshot& snapshot); | ||||
| 
 | ||||
| private: | ||||
|     void reset(); | ||||
| 
 | ||||
|     void render_background(float left, float top, float right, float bottom, float border) const; | ||||
|     void do_render_overlay() const; | ||||
| 
 | ||||
|  | @ -207,7 +202,6 @@ private: | |||
| 
 | ||||
|     void update_on_off_state(const Vec2d& mouse_pos); | ||||
|     std::string update_hover_state(const Vec2d& mouse_pos); | ||||
|     bool overlay_contains_mouse(const Vec2d& mouse_pos) const; | ||||
|     bool grabber_contains_mouse() const; | ||||
| }; | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Lukas Matena
						Lukas Matena