Welcome to mirror list, hosted at ThFree Co, Russian Federation.

GLSelectionRectangle.hpp « GUI « slic3r « src - github.com/prusa3d/PrusaSlicer.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 49b3447ba9c38812c8d833988933a9a4e5fc1b1c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#ifndef slic3r_GLSelectionRectangle_hpp_
#define slic3r_GLSelectionRectangle_hpp_

#include "libslic3r/Point.hpp"
#if ENABLE_LEGACY_OPENGL_REMOVAL
#include "GLModel.hpp"
#endif // ENABLE_LEGACY_OPENGL_REMOVAL

namespace Slic3r {
namespace GUI {
    
struct Camera;
class GLCanvas3D;

class GLSelectionRectangle {
public:
    enum class EState {
            Off,
            Select,
            Deselect
    };

    // Initiates the rectangle. 
    void start_dragging(const Vec2d& mouse_position, EState state);

    // To be called on mouse move.
    void dragging(const Vec2d& mouse_position);

    // Given a vector of points in world coordinates, the function returns indices of those
    // that are in the rectangle. It then disables the rectangle.
    std::vector<unsigned int> stop_dragging(const GLCanvas3D& canvas, const std::vector<Vec3d>& points);

    // Disables the rectangle.
    void stop_dragging();

    void render(const GLCanvas3D& canvas);

    bool is_dragging() const { return m_state != EState::Off; }
#if ENABLE_NEW_RECTANGLE_SELECTION
    bool is_empty() const    { return m_state == EState::Off || m_start_corner.isApprox(m_end_corner); }
#endif // ENABLE_NEW_RECTANGLE_SELECTION

    EState get_state() const { return m_state; }

    float get_width() const  { return std::abs(m_start_corner.x() - m_end_corner.x()); }
    float get_height() const { return std::abs(m_start_corner.y() - m_end_corner.y()); }
    float get_left() const   { return std::min(m_start_corner.x(), m_end_corner.x()); }
    float get_right() const  { return std::max(m_start_corner.x(), m_end_corner.x()); }
    float get_top() const    { return std::max(m_start_corner.y(), m_end_corner.y()); }
    float get_bottom() const { return std::min(m_start_corner.y(), m_end_corner.y()); }

private:
    EState m_state{ EState::Off };
    Vec2d m_start_corner{ Vec2d::Zero() };
    Vec2d m_end_corner{ Vec2d::Zero() };
#if ENABLE_LEGACY_OPENGL_REMOVAL
    GLModel m_rectangle;
    Vec2d m_old_start_corner{ Vec2d::Zero() };
    Vec2d m_old_end_corner{ Vec2d::Zero() };
#endif // ENABLE_LEGACY_OPENGL_REMOVAL
};

    
} // namespace GUI
} // namespace Slic3r


#endif // slic3r_GLGizmoSlaSupports_hpp_