Unified color definition

This commit is contained in:
enricoturri1966 2021-05-25 13:46:25 +02:00 committed by Lukas Matena
parent e648368934
commit 9605d10caa
6 changed files with 59 additions and 79 deletions

View File

@ -85,9 +85,9 @@ GLGizmoBase::GLGizmoBase(GLCanvas3D& parent, const std::string& icon_filename, u
, m_imgui(wxGetApp().imgui())
, m_first_input_window_render(true)
{
::memcpy((void*)m_base_color, (const void*)DEFAULT_BASE_COLOR, 4 * sizeof(float));
::memcpy((void*)m_drag_color, (const void*)DEFAULT_DRAG_COLOR, 4 * sizeof(float));
::memcpy((void*)m_highlight_color, (const void*)DEFAULT_HIGHLIGHT_COLOR, 4 * sizeof(float));
m_base_color = DEFAULT_BASE_COLOR;
m_drag_color = DEFAULT_DRAG_COLOR;
m_highlight_color = DEFAULT_HIGHLIGHT_COLOR;
m_cone.init_from(make_cone(1., 1., 2 * PI / 24));
m_sphere.init_from(make_sphere(1., (2 * M_PI) / 24.));
m_cylinder.init_from(make_cylinder(1., 1., 2 * PI / 24.));
@ -102,10 +102,9 @@ void GLGizmoBase::set_hover_id(int id)
}
}
void GLGizmoBase::set_highlight_color(const float* color)
void GLGizmoBase::set_highlight_color(const std::array<float, 4>& color)
{
if (color != nullptr)
::memcpy((void*)m_highlight_color, (const void*)color, 4 * sizeof(float));
m_highlight_color = color;
}
void GLGizmoBase::enable_grabber(unsigned int id)

View File

@ -18,13 +18,15 @@ class ModelObject;
namespace GUI {
static const float DEFAULT_BASE_COLOR[4] = { 0.625f, 0.625f, 0.625f, 1.0f };
static const float DEFAULT_DRAG_COLOR[4] = { 1.0f, 1.0f, 1.0f, 1.0f };
static const float DEFAULT_HIGHLIGHT_COLOR[4] = { 1.0f, 0.38f, 0.0f, 1.0f };
static const float AXES_COLOR[][4] = { { 0.75f, 0.0f, 0.0f, 1.0f }, { 0.0f, 0.75f, 0.0f, 1.0f }, { 0.0f, 0.0f, 0.75f, 1.0f } };
static const float CONSTRAINED_COLOR[4] = { 0.5f, 0.5f, 0.5f, 1.0f };
static const std::array<float, 4> DEFAULT_BASE_COLOR = { 0.625f, 0.625f, 0.625f, 1.0f };
static const std::array<float, 4> DEFAULT_DRAG_COLOR = { 1.0f, 1.0f, 1.0f, 1.0f };
static const std::array<float, 4> DEFAULT_HIGHLIGHT_COLOR = { 1.0f, 0.38f, 0.0f, 1.0f };
static const std::array<std::array<float, 4>, 3> AXES_COLOR = {{
{ 0.75f, 0.0f, 0.0f, 1.0f },
{ 0.0f, 0.75f, 0.0f, 1.0f },
{ 0.0f, 0.0f, 0.75f, 1.0f }
}};
static const std::array<float, 4> CONSTRAINED_COLOR = { 0.5f, 0.5f, 0.5f, 1.0f };
class ImGuiWrapper;
class GLCanvas3D;
@ -93,9 +95,9 @@ protected:
unsigned int m_sprite_id;
int m_hover_id;
bool m_dragging;
float m_base_color[4];
float m_drag_color[4];
float m_highlight_color[4];
std::array<float, 4> m_base_color;
std::array<float, 4> m_drag_color;
std::array<float, 4> m_highlight_color;
mutable std::vector<Grabber> m_grabbers;
ImGuiWrapper* m_imgui;
bool m_first_input_window_render;
@ -138,7 +140,7 @@ public:
int get_hover_id() const { return m_hover_id; }
void set_hover_id(int id);
void set_highlight_color(const float* color);
void set_highlight_color(const std::array<float, 4>& color);
void enable_grabber(unsigned int id);
void disable_grabber(unsigned int id);

View File

@ -112,14 +112,11 @@ void GLGizmoMove3D::on_render() const
glsafe(::glLineWidth((m_hover_id != -1) ? 2.0f : 1.5f));
if (m_hover_id == -1)
{
if (m_hover_id == -1) {
// draw axes
for (unsigned int i = 0; i < 3; ++i)
{
if (m_grabbers[i].enabled)
{
glsafe(::glColor4fv(AXES_COLOR[i]));
for (unsigned int i = 0; i < 3; ++i) {
if (m_grabbers[i].enabled) {
glsafe(::glColor4fv(AXES_COLOR[i].data()));
::glBegin(GL_LINES);
::glVertex3dv(center.data());
::glVertex3dv(m_grabbers[i].center.data());
@ -129,16 +126,14 @@ void GLGizmoMove3D::on_render() const
// draw grabbers
render_grabbers(box);
for (unsigned int i = 0; i < 3; ++i)
{
for (unsigned int i = 0; i < 3; ++i) {
if (m_grabbers[i].enabled)
render_grabber_extension((Axis)i, box, false);
}
}
else
{
else {
// draw axis
glsafe(::glColor4fv(AXES_COLOR[m_hover_id]));
glsafe(::glColor4fv(AXES_COLOR[m_hover_id].data()));
::glBegin(GL_LINES);
::glVertex3dv(center.data());
::glVertex3dv(m_grabbers[m_hover_id].center.data());

View File

@ -133,8 +133,7 @@ void GLGizmoRotate::on_render() const
const Selection& selection = m_parent.get_selection();
const BoundingBoxf3& box = selection.get_bounding_box();
if (m_hover_id != 0 && !m_grabbers[0].dragging)
{
if (m_hover_id != 0 && !m_grabbers[0].dragging) {
m_center = box.center();
m_radius = Offset + box.radius();
m_snap_coarse_in_radius = m_radius / 3.0f;
@ -149,18 +148,17 @@ void GLGizmoRotate::on_render() const
transform_to_local(selection);
glsafe(::glLineWidth((m_hover_id != -1) ? 2.0f : 1.5f));
glsafe(::glColor4fv((m_hover_id != -1) ? m_drag_color : m_highlight_color));
glsafe(::glColor4fv((m_hover_id != -1) ? m_drag_color.data() : m_highlight_color.data()));
render_circle();
if (m_hover_id != -1)
{
if (m_hover_id != -1) {
render_scale();
render_snap_radii();
render_reference_radius();
}
glsafe(::glColor4fv(m_highlight_color));
glsafe(::glColor4fv(m_highlight_color.data()));
if (m_hover_id != -1)
render_angle();
@ -311,14 +309,14 @@ void GLGizmoRotate::render_grabber(const BoundingBoxf3& box) const
m_grabbers[0].center = Vec3d(::cos(m_angle) * grabber_radius, ::sin(m_angle) * grabber_radius, 0.0);
m_grabbers[0].angles(2) = m_angle;
glsafe(::glColor4fv((m_hover_id != -1) ? m_drag_color : m_highlight_color));
glsafe(::glColor4fv((m_hover_id != -1) ? m_drag_color.data() : m_highlight_color.data()));
::glBegin(GL_LINES);
::glVertex3f(0.0f, 0.0f, 0.0f);
::glVertex3dv(m_grabbers[0].center.data());
glsafe(::glEnd());
::memcpy((void*)m_grabbers[0].color.data(), (const void*)m_highlight_color, 4 * sizeof(float));
m_grabbers[0].color = m_highlight_color;
render_grabbers(box);
}
@ -430,8 +428,7 @@ GLGizmoRotate3D::GLGizmoRotate3D(GLCanvas3D& parent, const std::string& icon_fil
m_gizmos.emplace_back(parent, GLGizmoRotate::Y);
m_gizmos.emplace_back(parent, GLGizmoRotate::Z);
for (unsigned int i = 0; i < 3; ++i)
{
for (unsigned int i = 0; i < 3; ++i) {
m_gizmos[i].set_group_id(i);
}
@ -440,14 +437,12 @@ GLGizmoRotate3D::GLGizmoRotate3D(GLCanvas3D& parent, const std::string& icon_fil
bool GLGizmoRotate3D::on_init()
{
for (GLGizmoRotate& g : m_gizmos)
{
for (GLGizmoRotate& g : m_gizmos) {
if (!g.init())
return false;
}
for (unsigned int i = 0; i < 3; ++i)
{
for (unsigned int i = 0; i < 3; ++i) {
m_gizmos[i].set_highlight_color(AXES_COLOR[i]);
}
@ -458,7 +453,7 @@ bool GLGizmoRotate3D::on_init()
std::string GLGizmoRotate3D::on_get_name() const
{
return (_(L("Rotate")) + " [R]").ToUTF8().data();
return (_L("Rotate") + " [R]").ToUTF8().data();
}
bool GLGizmoRotate3D::on_is_activable() const

View File

@ -173,34 +173,32 @@ void GLGizmoScale3D::on_render() const
// x axis
m_grabbers[0].center = m_transform * Vec3d(m_box.min(0), center(1), center(2)) - offset_x;
m_grabbers[1].center = m_transform * Vec3d(m_box.max(0), center(1), center(2)) + offset_x;
::memcpy((void*)m_grabbers[0].color.data(), (ctrl_down && (m_hover_id == 1)) ? (const void*)CONSTRAINED_COLOR : (const void*)&AXES_COLOR[0], 4 * sizeof(float));
::memcpy((void*)m_grabbers[1].color.data(), (ctrl_down && (m_hover_id == 0)) ? (const void*)CONSTRAINED_COLOR : (const void*)&AXES_COLOR[0], 4 * sizeof(float));
m_grabbers[0].color = (ctrl_down && (m_hover_id == 1)) ? CONSTRAINED_COLOR : AXES_COLOR[0];
m_grabbers[1].color = (ctrl_down && (m_hover_id == 0)) ? CONSTRAINED_COLOR : AXES_COLOR[0];
// y axis
m_grabbers[2].center = m_transform * Vec3d(center(0), m_box.min(1), center(2)) - offset_y;
m_grabbers[3].center = m_transform * Vec3d(center(0), m_box.max(1), center(2)) + offset_y;
::memcpy((void*)m_grabbers[2].color.data(), (ctrl_down && (m_hover_id == 3)) ? (const void*)CONSTRAINED_COLOR : (const void*)&AXES_COLOR[1], 4 * sizeof(float));
::memcpy((void*)m_grabbers[3].color.data(), (ctrl_down && (m_hover_id == 2)) ? (const void*)CONSTRAINED_COLOR : (const void*)&AXES_COLOR[1], 4 * sizeof(float));
m_grabbers[2].color = (ctrl_down && (m_hover_id == 3)) ? CONSTRAINED_COLOR : AXES_COLOR[1];
m_grabbers[3].color = (ctrl_down && (m_hover_id == 2)) ? CONSTRAINED_COLOR : AXES_COLOR[1];
// z axis
m_grabbers[4].center = m_transform * Vec3d(center(0), center(1), m_box.min(2)) - offset_z;
m_grabbers[5].center = m_transform * Vec3d(center(0), center(1), m_box.max(2)) + offset_z;
::memcpy((void*)m_grabbers[4].color.data(), (ctrl_down && (m_hover_id == 5)) ? (const void*)CONSTRAINED_COLOR : (const void*)&AXES_COLOR[2], 4 * sizeof(float));
::memcpy((void*)m_grabbers[5].color.data(), (ctrl_down && (m_hover_id == 4)) ? (const void*)CONSTRAINED_COLOR : (const void*)&AXES_COLOR[2], 4 * sizeof(float));
m_grabbers[4].color = (ctrl_down && (m_hover_id == 5)) ? CONSTRAINED_COLOR : AXES_COLOR[2];
m_grabbers[5].color = (ctrl_down && (m_hover_id == 4)) ? CONSTRAINED_COLOR : AXES_COLOR[2];
// uniform
m_grabbers[6].center = m_transform * Vec3d(m_box.min(0), m_box.min(1), center(2)) - offset_x - offset_y;
m_grabbers[7].center = m_transform * Vec3d(m_box.max(0), m_box.min(1), center(2)) + offset_x - offset_y;
m_grabbers[8].center = m_transform * Vec3d(m_box.max(0), m_box.max(1), center(2)) + offset_x + offset_y;
m_grabbers[9].center = m_transform * Vec3d(m_box.min(0), m_box.max(1), center(2)) - offset_x + offset_y;
for (int i = 6; i < 10; ++i)
{
::memcpy((void*)m_grabbers[i].color.data(), (const void*)m_highlight_color, 4 * sizeof(float));
for (int i = 6; i < 10; ++i) {
m_grabbers[i].color = m_highlight_color;
}
// sets grabbers orientation
for (int i = 0; i < 10; ++i)
{
for (int i = 0; i < 10; ++i) {
m_grabbers[i].angles = angles;
}
@ -210,25 +208,21 @@ void GLGizmoScale3D::on_render() const
float grabber_mean_size = (float)((selection_box.size()(0) + selection_box.size()(1) + selection_box.size()(2)) / 3.0);
if (m_hover_id == -1)
{
if (m_hover_id == -1) {
// draw connections
if (m_grabbers[0].enabled && m_grabbers[1].enabled)
{
if (m_grabbers[0].enabled && m_grabbers[1].enabled) {
glsafe(::glColor4fv(m_grabbers[0].color.data()));
render_grabbers_connection(0, 1);
}
if (m_grabbers[2].enabled && m_grabbers[3].enabled)
{
if (m_grabbers[2].enabled && m_grabbers[3].enabled) {
glsafe(::glColor4fv(m_grabbers[2].color.data()));
render_grabbers_connection(2, 3);
}
if (m_grabbers[4].enabled && m_grabbers[5].enabled)
{
if (m_grabbers[4].enabled && m_grabbers[5].enabled) {
glsafe(::glColor4fv(m_grabbers[4].color.data()));
render_grabbers_connection(4, 5);
}
glsafe(::glColor4fv(m_base_color));
glsafe(::glColor4fv(m_base_color.data()));
render_grabbers_connection(6, 7);
render_grabbers_connection(7, 8);
render_grabbers_connection(8, 9);
@ -236,8 +230,7 @@ void GLGizmoScale3D::on_render() const
// draw grabbers
render_grabbers(grabber_mean_size);
}
else if ((m_hover_id == 0) || (m_hover_id == 1))
{
else if (m_hover_id == 0 || m_hover_id == 1) {
// draw connection
glsafe(::glColor4fv(m_grabbers[0].color.data()));
render_grabbers_connection(0, 1);
@ -245,8 +238,7 @@ void GLGizmoScale3D::on_render() const
m_grabbers[0].render(true, grabber_mean_size);
m_grabbers[1].render(true, grabber_mean_size);
}
else if ((m_hover_id == 2) || (m_hover_id == 3))
{
else if (m_hover_id == 2 || m_hover_id == 3) {
// draw connection
glsafe(::glColor4fv(m_grabbers[2].color.data()));
render_grabbers_connection(2, 3);
@ -254,8 +246,7 @@ void GLGizmoScale3D::on_render() const
m_grabbers[2].render(true, grabber_mean_size);
m_grabbers[3].render(true, grabber_mean_size);
}
else if ((m_hover_id == 4) || (m_hover_id == 5))
{
else if (m_hover_id == 4 || m_hover_id == 5) {
// draw connection
glsafe(::glColor4fv(m_grabbers[4].color.data()));
render_grabbers_connection(4, 5);
@ -263,17 +254,15 @@ void GLGizmoScale3D::on_render() const
m_grabbers[4].render(true, grabber_mean_size);
m_grabbers[5].render(true, grabber_mean_size);
}
else if (m_hover_id >= 6)
{
else if (m_hover_id >= 6) {
// draw connection
glsafe(::glColor4fv(m_drag_color));
glsafe(::glColor4fv(m_drag_color.data()));
render_grabbers_connection(6, 7);
render_grabbers_connection(7, 8);
render_grabbers_connection(8, 9);
render_grabbers_connection(9, 6);
// draw grabbers
for (int i = 6; i < 10; ++i)
{
for (int i = 6; i < 10; ++i) {
m_grabbers[i].render(true, grabber_mean_size);
}
}

View File

@ -22,7 +22,7 @@
#include <boost/algorithm/string/predicate.hpp>
#include <boost/log/trivial.hpp>
static const float UNIFORM_SCALE_COLOR[4] = { 0.923f, 0.504f, 0.264f, 1.0f };
static const std::array<float, 4> UNIFORM_SCALE_COLOR = { 0.923f, 0.504f, 0.264f, 1.0f };
namespace Slic3r {
namespace GUI {
@ -1823,7 +1823,7 @@ void Selection::render_sidebar_position_hints(const std::string& sidebar_field)
auto set_color = [](Axis axis) {
GLShaderProgram* shader = wxGetApp().get_current_shader();
if (shader != nullptr)
shader->set_uniform("uniform_color", AXES_COLOR[axis], 4);
shader->set_uniform("uniform_color", AXES_COLOR[axis]);
};
if (boost::ends_with(sidebar_field, "x")) {
@ -1845,7 +1845,7 @@ void Selection::render_sidebar_rotation_hints(const std::string& sidebar_field)
auto set_color = [](Axis axis) {
GLShaderProgram* shader = wxGetApp().get_current_shader();
if (shader != nullptr)
shader->set_uniform("uniform_color", AXES_COLOR[axis], 4);
shader->set_uniform("uniform_color", AXES_COLOR[axis]);
};
auto render_sidebar_rotation_hint = [this]() {
@ -1875,7 +1875,7 @@ void Selection::render_sidebar_scale_hints(const std::string& sidebar_field) con
auto render_sidebar_scale_hint = [this, uniform_scale](Axis axis) {
GLShaderProgram* shader = wxGetApp().get_current_shader();
if (shader != nullptr)
shader->set_uniform("uniform_color", uniform_scale ? UNIFORM_SCALE_COLOR : AXES_COLOR[axis], 4);
shader->set_uniform("uniform_color", uniform_scale ? UNIFORM_SCALE_COLOR : AXES_COLOR[axis]);
glsafe(::glTranslated(0.0, 5.0, 0.0));
m_arrow.render();