Added shortcuts for gizmos

This commit is contained in:
Enrico Turri 2018-11-22 10:14:31 +01:00
parent ddf8acb440
commit c60ed7bc07
5 changed files with 96 additions and 8 deletions

View File

@ -31,6 +31,8 @@
#define ENABLE_NEW_MENU_LAYOUT (1 && ENABLE_1_42_0)
// All rotations made using the rotate gizmo are done with respect to the world reference system
#define ENABLE_WORLD_ROTATIONS (1 && ENABLE_1_42_0)
// Enables shortcut keys for gizmos
#define ENABLE_GIZMOS_SHORTCUT (1 && ENABLE_1_42_0)
#endif // _technologies_h_

View File

@ -2659,6 +2659,43 @@ bool GLCanvas3D::Gizmos::is_running() const
return (curr != nullptr) ? (curr->get_state() == GLGizmoBase::On) : false;
}
#if ENABLE_GIZMOS_SHORTCUT
bool GLCanvas3D::Gizmos::handle_shortcut(int key, const Selection& selection)
{
if (!m_enabled)
return false;
bool handled = false;
for (GizmosMap::iterator it = m_gizmos.begin(); it != m_gizmos.end(); ++it)
{
if ((it->second == nullptr) || !it->second->is_selectable())
continue;
int it_key = it->second->get_shortcut_key();
if (it->second->is_activable(selection) && ((it_key == key - 64) || (it_key == key - 96)))
{
if ((it->second->get_state() == GLGizmoBase::On))
{
it->second->set_state(GLGizmoBase::Off);
m_current = Undefined;
handled = true;
}
else if ((it->second->get_state() == GLGizmoBase::Off))
{
it->second->set_state(GLGizmoBase::On);
m_current = it->first;
handled = true;
}
}
else
it->second->set_state(GLGizmoBase::Off);
}
return handled;
}
#endif // ENABLE_GIZMOS_SHORTCUT
bool GLCanvas3D::Gizmos::is_dragging() const
{
if (!m_enabled)
@ -4273,7 +4310,16 @@ void GLCanvas3D::on_char(wxKeyEvent& evt)
#endif // ENABLE_MODIFIED_CAMERA_TARGET
default:
{
evt.Skip();
#if ENABLE_GIZMOS_SHORTCUT
if (evt.ShiftDown() && m_gizmos.handle_shortcut(keyCode, m_selection))
{
_update_gizmos_data();
render();
}
else
#endif // ENABLE_GIZMOS_SHORTCUT
evt.Skip();
break;
}
}
@ -4761,16 +4807,14 @@ void GLCanvas3D::on_key_down(wxKeyEvent& evt)
else
{
int key = evt.GetKeyCode();
#ifdef __WXOSX__
if (key == WXK_BACK)
#else
if (key == WXK_DELETE)
#endif // __WXOSX__
post_event(SimpleEvent(EVT_GLCANVAS_REMOVE_OBJECT));
else
{
#ifdef __WXOSX__
if (key == WXK_BACK)
post_event(SimpleEvent(EVT_GLCANVAS_REMOVE_OBJECT));
#endif
evt.Skip();
}
evt.Skip();
}
}

View File

@ -611,6 +611,9 @@ private:
EType get_current_type() const;
bool is_running() const;
#if ENABLE_GIZMOS_SHORTCUT
bool handle_shortcut(int key, const Selection& selection);
#endif // ENABLE_GIZMOS_SHORTCUT
bool is_dragging() const;
void start_dragging(const Selection& selection);

View File

@ -30,6 +30,10 @@
#include "GUI_Utils.hpp"
#include "GUI_App.hpp"
#if ENABLE_GIZMOS_SHORTCUT
#include <wx/defs.h>
#endif // ENABLE_GIZMOS_SHORTCUT
// TODO: Display tooltips quicker on Linux
static const float DEFAULT_BASE_COLOR[3] = { 0.625f, 0.625f, 0.625f };
@ -161,6 +165,9 @@ GLGizmoBase::GLGizmoBase(GLCanvas3D& parent)
: m_parent(parent)
, m_group_id(-1)
, m_state(Off)
#if ENABLE_GIZMOS_SHORTCUT
, m_shortcut_key(0)
#endif // ENABLE_GIZMOS_SHORTCUT
, m_hover_id(-1)
, m_dragging(false)
{
@ -639,6 +646,10 @@ bool GLGizmoRotate3D::on_init()
if (!m_textures[On].load_from_file(path + "rotate_on.png", false))
return false;
#if ENABLE_GIZMOS_SHORTCUT
m_shortcut_key = WXK_CONTROL_R;
#endif // ENABLE_GIZMOS_SHORTCUT
return true;
}
@ -713,6 +724,10 @@ bool GLGizmoScale3D::on_init()
m_grabbers[2].angles(0) = half_pi;
m_grabbers[3].angles(0) = half_pi;
#if ENABLE_GIZMOS_SHORTCUT
m_shortcut_key = WXK_CONTROL_S;
#endif // ENABLE_GIZMOS_SHORTCUT
return true;
}
@ -1057,6 +1072,10 @@ bool GLGizmoMove3D::on_init()
m_grabbers.push_back(Grabber());
}
#if ENABLE_GIZMOS_SHORTCUT
m_shortcut_key = WXK_CONTROL_M;
#endif // ENABLE_GIZMOS_SHORTCUT
return true;
}
@ -1213,6 +1232,10 @@ bool GLGizmoFlatten::on_init()
if (!m_textures[On].load_from_file(path + "layflat_on.png", false))
return false;
#if ENABLE_GIZMOS_SHORTCUT
m_shortcut_key = WXK_CONTROL_F;
#endif // ENABLE_GIZMOS_SHORTCUT
return true;
}
@ -1542,6 +1565,10 @@ bool GLGizmoSlaSupports::on_init()
if (!m_textures[On].load_from_file(path + "sla_support_points_on.png", false))
return false;
#if ENABLE_GIZMOS_SHORTCUT
m_shortcut_key = WXK_CONTROL_L;
#endif // ENABLE_GIZMOS_SHORTCUT
return true;
}
@ -1893,6 +1920,10 @@ bool GLGizmoCut::on_init()
m_grabbers.emplace_back();
#if ENABLE_GIZMOS_SHORTCUT
m_shortcut_key = WXK_CONTROL_C;
#endif // ENABLE_GIZMOS_SHORTCUT
return true;
}

View File

@ -77,6 +77,9 @@ protected:
int m_group_id;
EState m_state;
#if ENABLE_GIZMOS_SHORTCUT
int m_shortcut_key;
#endif // ENABLE_GIZMOS_SHORTCUT
// textures are assumed to be square and all with the same size in pixels, no internal check is done
GLTexture m_textures[Num_States];
int m_hover_id;
@ -100,6 +103,11 @@ public:
EState get_state() const { return m_state; }
void set_state(EState state) { m_state = state; on_set_state(); }
#if ENABLE_GIZMOS_SHORTCUT
int get_shortcut_key() const { return m_shortcut_key; }
void set_shortcut_key(int key) { m_shortcut_key = key; }
#endif // ENABLE_GIZMOS_SHORTCUT
bool is_activable(const GLCanvas3D::Selection& selection) const { return on_is_activable(selection); }
bool is_selectable() const { return on_is_selectable(); }