GLCanvas3D -> added support for cursor change and change cursor when using SLA support gizmo rectangle selection

This commit is contained in:
Enrico Turri 2019-04-24 15:43:52 +02:00
parent 9710140948
commit d79a2b8d2d
7 changed files with 79 additions and 13 deletions

View file

@ -1213,6 +1213,7 @@ GLCanvas3D::GLCanvas3D(wxGLCanvas* canvas, Bed3D& bed, Camera& camera, GLToolbar
, m_regenerate_volumes(true)
, m_moving(false)
, m_tab_down(false)
, m_cursor_type(Standard)
, m_color_by("volume")
, m_reload_delayed(false)
, m_render_sla_auxiliaries(true)
@ -2323,9 +2324,25 @@ void GLCanvas3D::on_key(wxKeyEvent& evt)
// m_canvas->HandleAsNavigationKey(evt); // XXX: Doesn't work in some cases / on Linux
post_event(SimpleEvent(EVT_GLCANVAS_TAB));
}
else if (keyCode == WXK_SHIFT)
{
set_cursor(Standard);
}
else if (keyCode == WXK_ALT)
{
set_cursor(Standard);
}
}
else if (evt.GetEventType() == wxEVT_KEY_DOWN) {
m_tab_down = keyCode == WXK_TAB && !evt.HasAnyModifiers();
if (keyCode == WXK_SHIFT)
{
set_cursor(Cross);
}
else if (keyCode == WXK_ALT)
{
set_cursor(Cross);
}
}
}
}
@ -3173,6 +3190,20 @@ double GLCanvas3D::get_size_proportional_to_max_bed_size(double factor) const
return factor * m_bed.get_bounding_box().max_size();
}
void GLCanvas3D::set_cursor(ECursorType type)
{
if ((m_canvas != nullptr) && (m_cursor_type != type))
{
switch (type)
{
case Standard: { m_canvas->SetCursor(*wxSTANDARD_CURSOR); break; }
case Cross: { m_canvas->SetCursor(*wxCROSS_CURSOR); break; }
}
m_cursor_type = type;
}
}
bool GLCanvas3D::_is_shown_on_screen() const
{
return (m_canvas != nullptr) ? m_canvas->IsShownOnScreen() : false;

View file

@ -392,6 +392,14 @@ private:
void render(const GLCanvas3D& canvas) const;
};
public:
enum ECursorType : unsigned char
{
Standard,
Cross
};
private:
wxGLCanvas* m_canvas;
wxGLContext* m_context;
#if ENABLE_RETINA_GL
@ -436,6 +444,7 @@ private:
bool m_regenerate_volumes;
bool m_moving;
bool m_tab_down;
ECursorType m_cursor_type;
// Following variable is obsolete and it should be safe to remove it.
// I just don't want to do it now before a release (Lukas Matena 24.3.2019)
@ -587,6 +596,8 @@ public:
double get_size_proportional_to_max_bed_size(double factor) const;
void set_cursor(ECursorType type);
private:
bool _is_shown_on_screen() const;

View file

@ -9,7 +9,7 @@ namespace GUI {
void GLSelectionRectangle::start_dragging(const Vec2d& mouse_position, float width, float height, EState status)
{
if (is_active() || status==Off)
if (is_dragging() || status == Off)
return;
m_width = width;
@ -23,7 +23,7 @@ void GLSelectionRectangle::start_dragging(const Vec2d& mouse_position, float wid
void GLSelectionRectangle::dragging(const Vec2d& mouse_position)
{
if (is_active())
if (is_dragging())
m_end_corner = mouse_position;
}
@ -31,7 +31,7 @@ void GLSelectionRectangle::dragging(const Vec2d& mouse_position)
std::vector<unsigned int> GLSelectionRectangle::end_dragging(const Camera& camera, const std::vector<Vec3d>& points)
{
if (!is_active())
if (!is_dragging())
return std::vector<unsigned int>();
m_status = Off;

View file

@ -28,7 +28,7 @@ public:
void render() const;
bool is_active() const { return m_status != Off; }
bool is_dragging() const { return m_status != Off; }
EState get_status() const { return m_status; }

View file

@ -485,7 +485,7 @@ bool GLGizmoSlaSupports::gizmo_event(SLAGizmoEventType action, const Vec2d& mous
}
// left down without selection rectangle - place point on the mesh:
if (action == SLAGizmoEventType::LeftDown && !m_selection_rectangle.is_active() && !shift_down) {
if (action == SLAGizmoEventType::LeftDown && !m_selection_rectangle.is_dragging() && !shift_down) {
// If any point is in hover state, this should initiate its move - return control back to GLCanvas:
if (m_hover_id != -1)
return false;
@ -510,7 +510,7 @@ bool GLGizmoSlaSupports::gizmo_event(SLAGizmoEventType action, const Vec2d& mous
}
// left up with selection rectangle - select points inside the rectangle:
if ((action == SLAGizmoEventType::LeftUp || action == SLAGizmoEventType::ShiftUp || action == SLAGizmoEventType::AltUp) && m_selection_rectangle.is_active()) {
if ((action == SLAGizmoEventType::LeftUp || action == SLAGizmoEventType::ShiftUp || action == SLAGizmoEventType::AltUp) && m_selection_rectangle.is_dragging()) {
// Is this a selection or deselection rectangle?
GLSelectionRectangle::EState rectangle_status = m_selection_rectangle.get_status();
@ -601,7 +601,7 @@ bool GLGizmoSlaSupports::gizmo_event(SLAGizmoEventType action, const Vec2d& mous
return true; // point has been placed and the button not released yet
// this prevents GLCanvas from starting scene rotation
if (m_selection_rectangle.is_active()) {
if (m_selection_rectangle.is_dragging()) {
m_selection_rectangle.dragging(mouse_position);
return true;
}

View file

@ -68,6 +68,9 @@ public:
void delete_selected_points(bool force = false);
ClippingPlane get_sla_clipping_plane() const;
bool is_in_editing_mode() const { return m_editing_mode; }
bool is_selection_rectangle_dragging() const { return m_selection_rectangle.is_dragging(); }
private:
bool on_init();
void on_update(const UpdateData& data, const Selection& selection);

View file

@ -843,13 +843,34 @@ bool GLGizmosManager::on_key(wxKeyEvent& evt, GLCanvas3D& canvas)
if (evt.GetEventType() == wxEVT_KEY_UP)
{
if ((m_current == SlaSupports) && (keyCode == WXK_SHIFT) && gizmo_event(SLAGizmoEventType::ShiftUp))
// shift has been just released - SLA gizmo might want to close rectangular selection.
processed = true;
if (m_current == SlaSupports)
{
GLGizmoSlaSupports* gizmo = reinterpret_cast<GLGizmoSlaSupports*>(get_current());
if ((m_current == SlaSupports) && (keyCode == WXK_ALT) && gizmo_event(SLAGizmoEventType::AltUp))
// alt has been just released - SLA gizmo might want to close rectangular selection.
if (keyCode == WXK_SHIFT)
{
// shift has been just released - SLA gizmo might want to close rectangular selection.
if (gizmo_event(SLAGizmoEventType::ShiftUp) || (gizmo->is_in_editing_mode() && gizmo->is_selection_rectangle_dragging()))
processed = true;
}
else if (keyCode == WXK_ALT)
{
// alt has been just released - SLA gizmo might want to close rectangular selection.
if (gizmo_event(SLAGizmoEventType::AltUp) || (gizmo->is_in_editing_mode() && gizmo->is_selection_rectangle_dragging()))
processed = true;
}
}
if (processed)
canvas.set_cursor(GLCanvas3D::Standard);
}
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())
{
canvas.set_cursor(GLCanvas3D::Cross);
processed = true;
}
}
if (processed)