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

GLGizmo.hpp « GUI « slic3r « src « xs - github.com/prusa3d/PrusaSlicer.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 506b3972e702815832c926ca694e20d80bf98419 (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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#ifndef slic3r_GLGizmo_hpp_
#define slic3r_GLGizmo_hpp_

#include "../../slic3r/GUI/GLTexture.hpp"
#include "../../libslic3r/Point.hpp"

#include <vector>

namespace Slic3r {

class BoundingBoxf3;
class Pointf3;

namespace GUI {

class GLGizmoBase
{
protected:
    static const float BaseColor[3];
    static const float HighlightColor[3];

    struct Grabber
    {
        static const float HalfSize;
        static const float HoverOffset;

        Pointf center;
        float angle_z;
        float color[3];

        Grabber();
        void render(bool hover) const;
    };

public:
    enum EState
    {
        Off,
        Hover,
        On,
        Num_States
    };

protected:
    EState m_state;
    // 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;
    mutable std::vector<Grabber> m_grabbers;

public:
    GLGizmoBase();
    virtual ~GLGizmoBase();

    bool init();

    EState get_state() const;
    void set_state(EState state);

    unsigned int get_texture_id() const;
    int get_textures_size() const;

    int get_hover_id() const;
    void set_hover_id(int id);

    void start_dragging();
    void stop_dragging();
    void update(const Pointf& mouse_pos);
    void refresh();

    void render(const BoundingBoxf3& box) const;
    void render_for_picking(const BoundingBoxf3& box) const;

protected:
    virtual bool on_init() = 0;
    virtual void on_set_state();
    virtual void on_start_dragging();
    virtual void on_stop_dragging();
    virtual void on_update(const Pointf& mouse_pos) = 0;
    virtual void on_refresh();
    virtual void on_render(const BoundingBoxf3& box) const = 0;
    virtual void on_render_for_picking(const BoundingBoxf3& box) const = 0;

    void render_grabbers() const;
};

class GLGizmoRotate : public GLGizmoBase
{
    static const float Offset;
    static const unsigned int CircleResolution;
    static const unsigned int AngleResolution;
    static const unsigned int ScaleStepsCount;
    static const float ScaleStepRad;
    static const unsigned int ScaleLongEvery;
    static const float ScaleLongTooth;
    static const float ScaleShortTooth;
    static const unsigned int SnapRegionsCount;
    static const float GrabberOffset;

    float m_angle_z;

    mutable Pointf m_center;
    mutable float m_radius;
    mutable bool m_keep_radius;

public:
    GLGizmoRotate();

    float get_angle_z() const;
    void set_angle_z(float angle_z);

protected:
    virtual bool on_init();
    virtual void on_set_state();
    virtual void on_update(const Pointf& mouse_pos);
    virtual void on_refresh();
    virtual void on_render(const BoundingBoxf3& box) const;
    virtual void on_render_for_picking(const BoundingBoxf3& box) const;

private:
    void _render_circle() const;
    void _render_scale() const;
    void _render_snap_radii() const;
    void _render_reference_radius() const;
    void _render_angle_z() const;
    void _render_grabber() const;
};

class GLGizmoScale : public GLGizmoBase
{
    static const float Offset;

    float m_scale;
    float m_starting_scale;

    Pointf m_starting_drag_position;

public:
    GLGizmoScale();

    float get_scale() const;
    void set_scale(float scale);

protected:
    virtual bool on_init();
    virtual void on_start_dragging();
    virtual void on_update(const Pointf& mouse_pos);
    virtual void on_render(const BoundingBoxf3& box) const;
    virtual void on_render_for_picking(const BoundingBoxf3& box) const;
};

} // namespace GUI
} // namespace Slic3r

#endif // slic3r_GLGizmo_hpp_