mirror of
https://git.mirrors.martin98.com/https://github.com/prusa3d/PrusaSlicer.git
synced 2025-08-15 16:25:54 +08:00
Enable rotation by propagation on_mouse event into gizmo
This commit is contained in:
parent
b22fcdc174
commit
2435b7af07
@ -167,7 +167,15 @@ public:
|
|||||||
|
|
||||||
virtual std::string get_tooltip() const { return ""; }
|
virtual std::string get_tooltip() const { return ""; }
|
||||||
|
|
||||||
protected:
|
/// <summary>
|
||||||
|
/// Implement when you want process mouse events in gizmo
|
||||||
|
/// Click, Right click, move, drag, ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="mouse_event">Keep information about mouse + some action key like alt, shift, ...</param>
|
||||||
|
/// <returns>Return True when Gizmo use the information and don't want to propagate it. Otherwise False.</returns>
|
||||||
|
virtual bool on_mouse(const wxMouseEvent &mouse_event) { return false; }
|
||||||
|
|
||||||
|
protected:
|
||||||
virtual bool on_init() = 0;
|
virtual bool on_init() = 0;
|
||||||
virtual void on_load(cereal::BinaryInputArchive& ar) {}
|
virtual void on_load(cereal::BinaryInputArchive& ar) {}
|
||||||
virtual void on_save(cereal::BinaryOutputArchive& ar) const {}
|
virtual void on_save(cereal::BinaryOutputArchive& ar) const {}
|
||||||
|
@ -201,7 +201,13 @@ GLGizmoEmboss::GLGizmoEmboss(GLCanvas3D &parent)
|
|||||||
, m_volume(nullptr)
|
, m_volume(nullptr)
|
||||||
, m_exist_notification(false)
|
, m_exist_notification(false)
|
||||||
, m_is_initialized(false) // initialize on first opening gizmo
|
, m_is_initialized(false) // initialize on first opening gizmo
|
||||||
, m_rotate_gizmo(parent, GLGizmoRotate::Axis::Z)
|
, m_rotate_gizmo(parent, GLGizmoRotate::Axis::Z) // grab id = 2 (Z axis)
|
||||||
|
, m_move_grabber(
|
||||||
|
GLModel(),
|
||||||
|
0, // grab id
|
||||||
|
DEFAULT_BASE_COLOR,
|
||||||
|
DEFAULT_DRAG_COLOR
|
||||||
|
)
|
||||||
{
|
{
|
||||||
m_rotate_gizmo.set_group_id(0);
|
m_rotate_gizmo.set_group_id(0);
|
||||||
// TODO: add suggestion to use https://fontawesome.com/
|
// TODO: add suggestion to use https://fontawesome.com/
|
||||||
@ -280,33 +286,43 @@ void GLGizmoEmboss::create_volume(ModelVolumeType volume_type, const Vec2d& mous
|
|||||||
selection.get_object_idx());
|
selection.get_object_idx());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool GLGizmoEmboss::on_mouse(const wxMouseEvent &evt)
|
||||||
|
{
|
||||||
|
if (m_dragging) {
|
||||||
|
// temporary rotation
|
||||||
|
TransformationType transformation_type(TransformationType::Local_Relative_Independent);
|
||||||
|
Vec3d rotation(0., 0., m_rotate_gizmo.get_angle());
|
||||||
|
m_parent.get_selection().rotate(rotation, transformation_type);
|
||||||
|
}
|
||||||
|
if (evt.LeftUp() && m_dragging) {
|
||||||
|
// apply rotation
|
||||||
|
m_parent.do_rotate(L("Text-Rotate"));
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
bool GLGizmoEmboss::on_init()
|
bool GLGizmoEmboss::on_init()
|
||||||
{
|
{
|
||||||
m_rotate_gizmo.init();
|
m_rotate_gizmo.init();
|
||||||
std::array<float, 4> gray_color = {.6f, .6f, .6f, .3f};
|
std::array<float, 4> gray_color = {.6f, .6f, .6f, .3f};
|
||||||
m_rotate_gizmo.set_highlight_color(gray_color);
|
m_rotate_gizmo.set_highlight_color(gray_color);
|
||||||
// m_grabbers.emplace_back();
|
|
||||||
|
m_move_grabber.shape.init_from(its_make_cube(1., 1., 1.));
|
||||||
|
|
||||||
m_shortcut_key = WXK_CONTROL_T;
|
m_shortcut_key = WXK_CONTROL_T;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string GLGizmoEmboss::on_get_name() const { return _u8L("Emboss"); }
|
std::string GLGizmoEmboss::on_get_name() const { return _u8L("Emboss"); }
|
||||||
|
|
||||||
template<typename Tfnc> static void render_rotate_gizmo(Tfnc fnc) {
|
|
||||||
//ObjectManipulation *manipul = wxGetApp().obj_manipul();
|
|
||||||
//auto tmp = manipul->get_coordinates_type();
|
|
||||||
//manipul->set_coordinates_type(ECoordinatesType::Local);
|
|
||||||
fnc();
|
|
||||||
//manipul->set_coordinates_type(tmp);
|
|
||||||
}
|
|
||||||
|
|
||||||
void GLGizmoEmboss::on_render() {
|
void GLGizmoEmboss::on_render() {
|
||||||
// no volume selected
|
// no volume selected
|
||||||
if (m_volume == nullptr) return;
|
if (m_volume == nullptr) return;
|
||||||
|
|
||||||
glsafe(::glClear(GL_DEPTH_BUFFER_BIT));
|
glsafe(::glClear(GL_DEPTH_BUFFER_BIT));
|
||||||
|
|
||||||
render_rotate_gizmo([&gizmo = m_rotate_gizmo]() { gizmo.render(); });
|
m_rotate_gizmo.render();
|
||||||
|
m_move_grabber.shape.render();
|
||||||
|
|
||||||
if (!m_preview.is_initialized()) return;
|
if (!m_preview.is_initialized()) return;
|
||||||
|
|
||||||
@ -323,7 +339,7 @@ void GLGizmoEmboss::on_render() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void GLGizmoEmboss::on_render_for_picking() {
|
void GLGizmoEmboss::on_render_for_picking() {
|
||||||
render_rotate_gizmo([&gizmo = m_rotate_gizmo]() { gizmo.render_for_picking(); });
|
m_rotate_gizmo.render_for_picking();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GLGizmoEmboss::on_render_input_window(float x, float y, float bottom_limit)
|
void GLGizmoEmboss::on_render_input_window(float x, float y, float bottom_limit)
|
||||||
@ -424,7 +440,15 @@ CommonGizmosDataID GLGizmoEmboss::on_get_requirements() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
void GLGizmoEmboss::on_start_dragging() { m_rotate_gizmo.start_dragging(); }
|
void GLGizmoEmboss::on_start_dragging() { m_rotate_gizmo.start_dragging(); }
|
||||||
void GLGizmoEmboss::on_stop_dragging() { m_rotate_gizmo.start_dragging(); }
|
void GLGizmoEmboss::on_stop_dragging()
|
||||||
|
{
|
||||||
|
m_rotate_gizmo.stop_dragging();
|
||||||
|
|
||||||
|
// TODO: when start second rotatiton previous rotation rotate draggers
|
||||||
|
// This is fast fix for second try to rotate
|
||||||
|
// When fixing, move grabber above text (not on side)
|
||||||
|
m_rotate_gizmo.set_angle(0);
|
||||||
|
}
|
||||||
|
|
||||||
void GLGizmoEmboss::initialize()
|
void GLGizmoEmboss::initialize()
|
||||||
{
|
{
|
||||||
@ -709,7 +733,7 @@ std::optional<Transform3d> GLGizmoEmboss::transform_on_surface(
|
|||||||
Selection &selection = m_parent.get_selection();
|
Selection &selection = m_parent.get_selection();
|
||||||
// check selection has volume
|
// check selection has volume
|
||||||
if (selection.volumes_count() < 0) return {};
|
if (selection.volumes_count() < 0) return {};
|
||||||
assert(selection.volumes_count() == (int)raycasters.size());
|
assert(selection.volumes_count() == (unsigned int)raycasters.size());
|
||||||
|
|
||||||
const Camera &camera = wxGetApp().plater()->get_camera();
|
const Camera &camera = wxGetApp().plater()->get_camera();
|
||||||
|
|
||||||
@ -890,7 +914,7 @@ void GLGizmoEmboss::draw_font_list()
|
|||||||
store_font_list();
|
store_font_list();
|
||||||
ImGui::CloseCurrentPopup();
|
ImGui::CloseCurrentPopup();
|
||||||
} else if (ImGui::IsItemHovered())
|
} else if (ImGui::IsItemHovered())
|
||||||
ImGui::SetTooltip(
|
ImGui::SetTooltip("%s",
|
||||||
_u8L("Choose from installed font inside dialog.").c_str());
|
_u8L("Choose from installed font inside dialog.").c_str());
|
||||||
|
|
||||||
#ifdef ALLOW_DEBUG_MODE
|
#ifdef ALLOW_DEBUG_MODE
|
||||||
@ -900,7 +924,8 @@ void GLGizmoEmboss::draw_font_list()
|
|||||||
choose_true_type_file();
|
choose_true_type_file();
|
||||||
store_font_list();
|
store_font_list();
|
||||||
ImGui::CloseCurrentPopup();
|
ImGui::CloseCurrentPopup();
|
||||||
} else if (ImGui::IsItemHovered()) ImGui::SetTooltip(_u8L("add file with font(.ttf, .ttc)").c_str());
|
} else if (ImGui::IsItemHovered())
|
||||||
|
ImGui::SetTooltip("%s",_u8L("add file with font(.ttf, .ttc)").c_str());
|
||||||
#endif // ALLOW_DEBUG_MODE
|
#endif // ALLOW_DEBUG_MODE
|
||||||
|
|
||||||
ImGui::Separator();
|
ImGui::Separator();
|
||||||
@ -921,7 +946,7 @@ void GLGizmoEmboss::draw_font_list()
|
|||||||
process();
|
process();
|
||||||
}
|
}
|
||||||
} else if (ImGui::IsItemHovered())
|
} else if (ImGui::IsItemHovered())
|
||||||
ImGui::SetTooltip(f.name.c_str());
|
ImGui::SetTooltip("%s", f.name.c_str());
|
||||||
|
|
||||||
// draw buttons rename and delete
|
// draw buttons rename and delete
|
||||||
ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
@ -1029,7 +1054,7 @@ void GLGizmoEmboss::draw_advanced()
|
|||||||
if (ImGui::BeginCombo(_u8L("Font collection").c_str(),
|
if (ImGui::BeginCombo(_u8L("Font collection").c_str(),
|
||||||
std::to_string(m_font->index).c_str())) {
|
std::to_string(m_font->index).c_str())) {
|
||||||
for (unsigned int i = 0; i < m_font->count; ++i) {
|
for (unsigned int i = 0; i < m_font->count; ++i) {
|
||||||
ImGui::PushID(1 << 10 + i);
|
ImGui::PushID(1 << (10 + i));
|
||||||
if (ImGui::Selectable(std::to_string(i).c_str(),
|
if (ImGui::Selectable(std::to_string(i).c_str(),
|
||||||
i == m_font->index)) {
|
i == m_font->index)) {
|
||||||
m_font->index = i;
|
m_font->index = i;
|
||||||
@ -1477,7 +1502,7 @@ bool GLGizmoEmboss::draw_button(IconType icon, bool disable)
|
|||||||
if (disable) {
|
if (disable) {
|
||||||
draw_icon(icon, IconState::disabled);
|
draw_icon(icon, IconState::disabled);
|
||||||
if (ImGui::IsItemHovered() && icon == IconType::erase)
|
if (ImGui::IsItemHovered() && icon == IconType::erase)
|
||||||
ImGui::SetTooltip(_u8L("Active font can't be removed").c_str());
|
ImGui::SetTooltip("%s",_u8L("Active font can't be removed").c_str());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1488,10 +1513,10 @@ bool GLGizmoEmboss::draw_button(IconType icon, bool disable)
|
|||||||
if (ImGui::IsItemHovered()) {
|
if (ImGui::IsItemHovered()) {
|
||||||
switch (icon) {
|
switch (icon) {
|
||||||
case IconType::rename:
|
case IconType::rename:
|
||||||
ImGui::SetTooltip(_u8L("rename").c_str());
|
ImGui::SetTooltip("%s", _u8L("rename").c_str());
|
||||||
break;
|
break;
|
||||||
case IconType::erase:
|
case IconType::erase:
|
||||||
ImGui::SetTooltip(_u8L("delete").c_str());
|
ImGui::SetTooltip("%s", _u8L("delete").c_str());
|
||||||
break;
|
break;
|
||||||
default: break;
|
default: break;
|
||||||
}
|
}
|
||||||
|
@ -32,6 +32,13 @@ public:
|
|||||||
|
|
||||||
void create_volume(ModelVolumeType volume_type, const Vec2d &mouse_pos = Vec2d(-1,-1));
|
void create_volume(ModelVolumeType volume_type, const Vec2d &mouse_pos = Vec2d(-1,-1));
|
||||||
void set_fine_position();
|
void set_fine_position();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Rotate by text on dragging rotate grabers
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="mouse_event">Information about mouse</param>
|
||||||
|
/// <returns>Propagete normaly return false.</returns>
|
||||||
|
bool on_mouse(const wxMouseEvent &mouse_event) override;
|
||||||
protected:
|
protected:
|
||||||
bool on_init() override;
|
bool on_init() override;
|
||||||
std::string on_get_name() const override;
|
std::string on_get_name() const override;
|
||||||
@ -138,6 +145,30 @@ private:
|
|||||||
// Rotation gizmo
|
// Rotation gizmo
|
||||||
GLGizmoRotate m_rotate_gizmo;
|
GLGizmoRotate m_rotate_gizmo;
|
||||||
|
|
||||||
|
struct MyGrabber
|
||||||
|
{
|
||||||
|
GLModel shape;
|
||||||
|
int grab_id;
|
||||||
|
std::array<float, 4> color;
|
||||||
|
std::array<float, 4> hovered_color;
|
||||||
|
|
||||||
|
MyGrabber(GLModel shape,
|
||||||
|
int grab_id,
|
||||||
|
std::array<float, 4> color,
|
||||||
|
std::array<float, 4> hovered_color)
|
||||||
|
: shape(shape)
|
||||||
|
, grab_id(grab_id)
|
||||||
|
, color(color)
|
||||||
|
, hovered_color(hovered_color)
|
||||||
|
{}
|
||||||
|
|
||||||
|
void render() {
|
||||||
|
|
||||||
|
}
|
||||||
|
};
|
||||||
|
// Translate on surface of model
|
||||||
|
MyGrabber m_move_grabber;
|
||||||
|
|
||||||
// preview position
|
// preview position
|
||||||
GLModel m_preview;
|
GLModel m_preview;
|
||||||
Transform3d m_preview_trmat;
|
Transform3d m_preview_trmat;
|
||||||
|
@ -537,6 +537,9 @@ bool GLGizmosManager::on_mouse_wheel(wxMouseEvent& evt)
|
|||||||
|
|
||||||
bool GLGizmosManager::on_mouse(wxMouseEvent& evt)
|
bool GLGizmosManager::on_mouse(wxMouseEvent& evt)
|
||||||
{
|
{
|
||||||
|
if (m_current != Undefined && m_gizmos[m_current]->on_mouse(evt))
|
||||||
|
return true;
|
||||||
|
|
||||||
// used to set a right up event as processed when needed
|
// used to set a right up event as processed when needed
|
||||||
static bool pending_right_up = false;
|
static bool pending_right_up = false;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user