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

GLToolbar.hpp « GUI « slic3r « src « xs - github.com/prusa3d/PrusaSlicer.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 65d6748ffe629f2700bb8db6ca5eb883c611dc3b (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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
#ifndef slic3r_GLToolbar_hpp_
#define slic3r_GLToolbar_hpp_

#include "../../slic3r/GUI/GLTexture.hpp"
#include "../../callback.hpp"

#include <string>
#include <vector>

namespace Slic3r {
namespace GUI {

class GLCanvas3D;

class GLToolbarItem
{
public:
    enum EType : unsigned char
    {
        Action,
        Separator,
        Num_Types
    };

    enum EState : unsigned char
    {
        Normal,
        Pressed,
        Disabled,
        Hover,
        HoverPressed,
        Num_States
    };

    struct Data
    {
        std::string name;
        std::string tooltip;
        unsigned int sprite_id;
        bool is_toggable;
        PerlCallback* action_callback;

        Data();
    };

private:
    EType m_type;
    EState m_state;
    Data m_data;

public:
    GLToolbarItem(EType type, const Data& data);

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

    const std::string& get_name() const;
    const std::string& get_tooltip() const;

    void do_action();

    bool is_enabled() const;
    bool is_hovered() const;
    bool is_pressed() const;

    bool is_toggable() const;
    bool is_separator() const;

    void render(unsigned int tex_id, float left, float right, float bottom, float top, unsigned int texture_size, unsigned int border_size, unsigned int icon_size, unsigned int gap_size) const;

private:
    GLTexture::Quad_UVs get_uvs(unsigned int texture_size, unsigned int border_size, unsigned int icon_size, unsigned int gap_size) const;
};

class GLToolbar
{
public:
    // items icon textures are assumed to be square and all with the same size in pixels, no internal check is done
    // icons are layed-out into the texture starting from the top-left corner in the same order as enum GLToolbarItem::EState
    // from left to right
    struct ItemsIconsTexture
    {
        GLTexture texture;
        // size of the square icons, in pixels
        unsigned int items_icon_size;
        // distance from the border, in pixels
        unsigned int items_icon_border_size;
        // distance between two adjacent icons (to avoid filtering artifacts), in pixels
        unsigned int items_icon_gap_size;

        ItemsIconsTexture();
    };

    struct Layout
    {
        enum Type : unsigned char
        {
            Horizontal,
            Vertical,
            Num_Types
        };

        Type type;
        float top;
        float left;
        float separator_size;
        float gap_size;

        Layout();
    };

private:
    typedef std::vector<GLToolbarItem*> ItemsList;

    GLCanvas3D& m_parent;
    bool m_enabled;
    ItemsIconsTexture m_icons_texture;
    Layout m_layout;

    ItemsList m_items;

public:
    explicit GLToolbar(GLCanvas3D& parent);

    bool init(const std::string& icons_texture_filename, unsigned int items_icon_size, unsigned int items_icon_border_size, unsigned int items_icon_gap_size);
    
    Layout::Type get_layout_type() const;
    void set_layout_type(Layout::Type type);

    void set_position(float top, float left);
    void set_separator_size(float size);
    void set_gap_size(float size);

    bool is_enabled() const;
    void set_enabled(bool enable);

    bool add_item(const GLToolbarItem::Data& data);
    bool add_separator();

    float get_width() const;
    float get_height() const;

    void enable_item(const std::string& name);
    void disable_item(const std::string& name);

    bool is_item_pressed(const std::string& name) const;

    void update_hover_state(const Vec2d& mouse_pos);

    // returns the id of the item under the given mouse position or -1 if none
    int contains_mouse(const Vec2d& mouse_pos) const;

    void do_action(unsigned int item_id);

    void render() const;

private:
    float get_width_horizontal() const;
    float get_width_vertical() const;
    float get_height_horizontal() const;
    float get_height_vertical() const;
    float get_main_size() const;
    void update_hover_state_horizontal(const Vec2d& mouse_pos);
    void update_hover_state_vertical(const Vec2d& mouse_pos);
    int contains_mouse_horizontal(const Vec2d& mouse_pos) const;
    int contains_mouse_vertical(const Vec2d& mouse_pos) const;

    void render_horizontal() const;
    void render_vertical() const;
};

} // namespace GUI
} // namespace Slic3r

#endif // slic3r_GLToolbar_hpp_