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

GLGizmo.cpp « GUI « slic3r « src « xs - github.com/prusa3d/PrusaSlicer.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 75f39aad98fdad50a7c87201ce9e91058b0ce3d2 (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
#include "GLGizmo.hpp"

#include "../../libslic3r/Utils.hpp"
#include "../../libslic3r/BoundingBox.hpp"

#include <GL/glew.h>

#include <iostream>

namespace Slic3r {
namespace GUI {

GLGizmoBase::GLGizmoBase()
    : m_state(Off)
{
}

GLGizmoBase::~GLGizmoBase()
{
}

bool GLGizmoBase::init()
{
    return on_init();
}

GLGizmoBase::EState GLGizmoBase::get_state() const
{
    return m_state;
}

void GLGizmoBase::set_state(GLGizmoBase::EState state)
{
    m_state = state;
}

unsigned int GLGizmoBase::get_textures_id() const
{
    return m_textures[m_state].get_id();
}

int GLGizmoBase::get_textures_size() const
{
    return m_textures[Off].get_width();
}

void GLGizmoBase::render(const BoundingBoxf3& box) const
{
    on_render(box);
}

GLGizmoRotate::GLGizmoRotate()
    : GLGizmoBase()
    , m_angle_x(0.0f)
    , m_angle_y(0.0f)
    , m_angle_z(0.0f)
{
}

bool GLGizmoRotate::on_init()
{
    std::string path = resources_dir() + "/icons/overlay/";

    std::string filename = path + "rotate_off.png";
    if (!m_textures[Off].load_from_file(filename))
        return false;

    filename = path + "rotate_hover.png";
    if (!m_textures[Hover].load_from_file(filename))
        return false;

    filename = path + "rotate_on.png";
    if (!m_textures[On].load_from_file(filename))
        return false;

    return true;
}

void GLGizmoRotate::on_render(const BoundingBoxf3& box) const
{
    std::cout << "GLGizmoRotate::render()" << std::endl;
}

const float GLGizmoScale::Offset = 5.0f;
const float GLGizmoScale::SquareHalfSize = 2.0f;

GLGizmoScale::GLGizmoScale()
    : GLGizmoBase()
    , m_scale_x(1.0f)
    , m_scale_y(1.0f)
    , m_scale_z(1.0f)
{
}

bool GLGizmoScale::on_init()
{
    std::string path = resources_dir() + "/icons/overlay/";

    std::string filename = path + "scale_off.png";
    if (!m_textures[Off].load_from_file(filename))
        return false;

    filename = path + "scale_hover.png";
    if (!m_textures[Hover].load_from_file(filename))
        return false;

    filename = path + "scale_on.png";
    if (!m_textures[On].load_from_file(filename))
        return false;

    return true;
}

void GLGizmoScale::on_render(const BoundingBoxf3& box) const
{
    ::glDisable(GL_LIGHTING);
    ::glDisable(GL_DEPTH_TEST);

    const Pointf3& size = box.size();
    const Pointf3& center = box.center();

    Pointf3 half_scaled_size = 0.5 * Pointf3((coordf_t)m_scale_x * size.x, (coordf_t)m_scale_y * size.y, (coordf_t)m_scale_z * size.z);
    coordf_t min_x = center.x - half_scaled_size.x - (coordf_t)Offset;
    coordf_t max_x = center.x + half_scaled_size.x + (coordf_t)Offset;
    coordf_t min_y = center.y - half_scaled_size.y - (coordf_t)Offset;
    coordf_t max_y = center.y + half_scaled_size.y + (coordf_t)Offset;

    ::glLineWidth(2.0f);
    ::glBegin(GL_LINE_LOOP);
    // draw outline
    ::glColor3f(1.0f, 1.0f, 1.0f);
    ::glVertex3f((GLfloat)min_x, (GLfloat)min_y, 0.0f);
    ::glVertex3f((GLfloat)max_x, (GLfloat)min_y, 0.0f);
    ::glVertex3f((GLfloat)max_x, (GLfloat)max_y, 0.0f);
    ::glVertex3f((GLfloat)min_x, (GLfloat)max_y, 0.0f);
    ::glEnd();

    // draw grabbers
    ::glColor3f(1.0f, 0.38f, 0.0f);
    ::glDisable(GL_CULL_FACE);
    _render_square(Pointf3(min_x, min_y, 0.0));
    _render_square(Pointf3(max_x, min_y, 0.0));
    _render_square(Pointf3(max_x, max_y, 0.0));
    _render_square(Pointf3(min_x, max_y, 0.0));
    ::glEnable(GL_CULL_FACE);
}

void GLGizmoScale::_render_square(const Pointf3& center) const
{
    float min_x = (float)center.x - SquareHalfSize;
    float max_x = (float)center.x + SquareHalfSize;
    float min_y = (float)center.y - SquareHalfSize;
    float max_y = (float)center.y + SquareHalfSize;

    ::glBegin(GL_TRIANGLES);
    ::glVertex3f((GLfloat)min_x, (GLfloat)min_y, 0.0f);
    ::glVertex3f((GLfloat)max_x, (GLfloat)min_y, 0.0f);
    ::glVertex3f((GLfloat)max_x, (GLfloat)max_y, 0.0f);
    ::glVertex3f((GLfloat)max_x, (GLfloat)max_y, 0.0f);
    ::glVertex3f((GLfloat)min_x, (GLfloat)max_y, 0.0f);
    ::glVertex3f((GLfloat)min_x, (GLfloat)min_y, 0.0f);
    ::glEnd();
}

} // namespace GUI
} // namespace Slic3r