Follow-up of 005fef7bf6 - Fixed highlight arrows for gizmos bar and toolbars

This commit is contained in:
enricoturri1966 2022-03-07 15:06:45 +01:00
parent 568f42660a
commit f4726f738c
6 changed files with 215 additions and 33 deletions

View File

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Generator: Adobe Illustrator 25.2.1, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
viewBox="50 0 228 330" style="enable-background:new 50 0 228 330;" xml:space="preserve">
<style type="text/css">
.st0{display:none;}
.st1{fill:none;stroke:#ED6B21;stroke-width:17.0079;stroke-linecap:round;stroke-miterlimit:10;}
</style>
<path id="XMLID_28_" class="st0" d="M180,315V51.2l49.4,49.4c5.9,5.9,15.4,5.9,21.2,0c5.9-5.9,5.9-15.4,0-21.2l-75-75
c-5.9-5.9-15.4-5.9-21.2,0l-75,75C76.5,82.3,75,86.2,75,90s1.5,7.7,4.4,10.6c5.9,5.9,15.4,5.9,21.2,0L150,51.2V315
c0,8.3,6.7,15,15,15S180,323.3,180,315z"
style="fill:#ed6b21;"/>
<g id="XMLID_1_">
<g>
</g>
<g>
<polyline class="st1" points="113.3,84.5 164,18.3 164,18.3 "/>
<polyline class="st1" points="216.1,84.5 164,18.3 164,18.3 "/>
</g>
</g>
<line class="st1" x1="164" y1="263.3" x2="164" y2="18.3"/>
</svg>

After

Width:  |  Height:  |  Size: 1.0 KiB

View File

@ -4759,21 +4759,28 @@ bool GLCanvas3D::_init_main_toolbar()
return true;
}
// init arrow
#if !ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
BackgroundTexture::Metadata arrow_data;
arrow_data.filename = "toolbar_arrow.svg";
arrow_data.left = 0;
arrow_data.top = 0;
arrow_data.right = 0;
arrow_data.bottom = 0;
#endif // !ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
#if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
if (!m_main_toolbar.init_arrow("toolbar_arrow_2.svg"))
#else
if (!m_main_toolbar.init_arrow(arrow_data))
{
#endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
BOOST_LOG_TRIVIAL(error) << "Main toolbar failed to load arrow texture.";
}
// m_gizmos is created at constructor, thus we can init arrow here.
#if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
if (!m_gizmos.init_arrow("toolbar_arrow_2.svg"))
#else
if (!m_gizmos.init_arrow(arrow_data))
{
#endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
BOOST_LOG_TRIVIAL(error) << "Gizmos manager failed to load arrow texture.";
}
// m_main_toolbar.set_layout_type(GLToolbar::Layout::Vertical);
m_main_toolbar.set_layout_type(GLToolbar::Layout::Horizontal);
@ -4973,24 +4980,27 @@ bool GLCanvas3D::_init_undoredo_toolbar()
background_data.right = 16;
background_data.bottom = 16;
if (!m_undoredo_toolbar.init(background_data))
{
if (!m_undoredo_toolbar.init(background_data)) {
// unable to init the toolbar texture, disable it
m_undoredo_toolbar.set_enabled(false);
return true;
}
// init arrow
#if !ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
BackgroundTexture::Metadata arrow_data;
arrow_data.filename = "toolbar_arrow.svg";
arrow_data.left = 0;
arrow_data.top = 0;
arrow_data.right = 0;
arrow_data.bottom = 0;
#endif // !ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
#if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
if (!m_undoredo_toolbar.init_arrow("toolbar_arrow_2.svg"))
#else
if (!m_undoredo_toolbar.init_arrow(arrow_data))
{
#endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
BOOST_LOG_TRIVIAL(error) << "Undo/Redo toolbar failed to load arrow texture.";
}
// m_undoredo_toolbar.set_layout_type(GLToolbar::Layout::Vertical);
m_undoredo_toolbar.set_layout_type(GLToolbar::Layout::Horizontal);
@ -5010,8 +5020,7 @@ bool GLCanvas3D::_init_undoredo_toolbar()
item.right.toggable = true;
item.right.action_callback = [this]() { m_imgui_undo_redo_hovered_pos = -1; };
item.right.render_callback = [this](float left, float right, float, float) {
if (m_canvas != nullptr)
{
if (m_canvas != nullptr) {
if (_render_undo_redo_stack(true, 0.5f * (left + right)))
_deactivate_undo_redo_toolbar_items();
}
@ -5030,8 +5039,7 @@ bool GLCanvas3D::_init_undoredo_toolbar()
new_additional_tooltip = (boost::format(_utf8(L("Next Undo action: %1%"))) % action).str();
}
if (new_additional_tooltip != curr_additional_tooltip)
{
if (new_additional_tooltip != curr_additional_tooltip) {
m_undoredo_toolbar.set_additional_tooltip(id, new_additional_tooltip);
set_tooltip("");
}
@ -5048,8 +5056,7 @@ bool GLCanvas3D::_init_undoredo_toolbar()
item.left.action_callback = [this]() { post_event(SimpleEvent(EVT_GLCANVAS_REDO)); };
item.right.action_callback = [this]() { m_imgui_undo_redo_hovered_pos = -1; };
item.right.render_callback = [this](float left, float right, float, float) {
if (m_canvas != nullptr)
{
if (m_canvas != nullptr) {
if (_render_undo_redo_stack(false, 0.5f * (left + right)))
_deactivate_undo_redo_toolbar_items();
}
@ -5068,8 +5075,7 @@ bool GLCanvas3D::_init_undoredo_toolbar()
new_additional_tooltip = (boost::format(_utf8(L("Next Redo action: %1%"))) % action).str();
}
if (new_additional_tooltip != curr_additional_tooltip)
{
if (new_additional_tooltip != curr_additional_tooltip) {
m_undoredo_toolbar.set_additional_tooltip(id, new_additional_tooltip);
set_tooltip("");
}
@ -5811,10 +5817,8 @@ void GLCanvas3D::_render_gizmos_overlay()
m_gizmos.render_overlay();
if (m_gizmo_highlighter.m_render_arrow)
{
m_gizmos.render_arrow(*this, m_gizmo_highlighter.m_gizmo_type);
}
}
void GLCanvas3D::_render_main_toolbar()
{

View File

@ -185,6 +185,16 @@ bool GLToolbar::init(const BackgroundTexture::Metadata& background_texture)
return res;
}
#if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
bool GLToolbar::init_arrow(const std::string& filename)
{
if (m_arrow_texture.get_id() != 0)
return true;
const std::string path = resources_dir() + "/icons/";
return (!filename.empty()) ? m_arrow_texture.load_from_svg_file(path + filename, false, false, false, 512) : false;
}
#else
bool GLToolbar::init_arrow(const BackgroundTexture::Metadata& arrow_texture)
{
if (m_arrow_texture.texture.get_id() != 0)
@ -201,6 +211,7 @@ bool GLToolbar::init_arrow(const BackgroundTexture::Metadata& arrow_texture)
return res;
}
#endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
GLToolbar::Layout::EType GLToolbar::get_layout_type() const
{
@ -1408,9 +1419,9 @@ void GLToolbar::render_background(float left, float top, float right, float bott
const unsigned int tex_id = m_background_texture.texture.get_id();
const float tex_width = (float)m_background_texture.texture.get_width();
const float tex_height = (float)m_background_texture.texture.get_height();
if (tex_id != 0 && tex_width > 0 && tex_height > 0) {
const float inv_tex_width = (tex_width != 0.0f) ? 1.0f / tex_width : 0.0f;
const float inv_tex_height = (tex_height != 0.0f) ? 1.0f / tex_height : 0.0f;
if (tex_id != 0 && tex_width > 0.0f && tex_height > 0.0f) {
const float inv_tex_width = 1.0f / tex_width;
const float inv_tex_height = 1.0f / tex_height;
const float internal_left = left + border_w;
const float internal_right = right - border_w;
@ -1558,6 +1569,76 @@ void GLToolbar::render_background(float left, float top, float right, float bott
}
#endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
#if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
void GLToolbar::render_arrow(const GLCanvas3D& parent, GLToolbarItem* highlighted_item)
{
// arrow texture not initialized
if (m_arrow_texture.get_id() == 0)
return;
const Size cnv_size = parent.get_canvas_size();
const float cnv_w = (float)cnv_size.get_width();
const float cnv_h = (float)cnv_size.get_height();
if (cnv_w == 0 || cnv_h == 0)
return;
const float inv_cnv_w = 1.0f / cnv_w;
const float inv_cnv_h = 1.0f / cnv_h;
const float icons_size_x = 2.0f * m_layout.icons_size * m_layout.scale * inv_cnv_w;
const float icons_size_y = 2.0f * m_layout.icons_size * m_layout.scale * inv_cnv_h;
const float separator_size = 2.0f * m_layout.separator_size * m_layout.scale * inv_cnv_w;
const float gap_size = 2.0f * m_layout.gap_size * m_layout.scale * inv_cnv_w;
const float border_x = 2.0f * m_layout.border * m_layout.scale * inv_cnv_w;
const float border_y = 2.0f * m_layout.border * m_layout.scale * inv_cnv_h;
const float separator_stride = separator_size + gap_size;
const float icon_stride = icons_size_x + gap_size;
float left = 2.0f * m_layout.left * inv_cnv_w + border_x;
float top = 2.0f * m_layout.top * inv_cnv_h - 2.0f * border_y - icons_size_y;
bool found = false;
for (const GLToolbarItem* item : m_items) {
if (!item->is_visible())
continue;
if (item->is_separator())
left += separator_stride;
else {
if (item->get_name() == highlighted_item->get_name()) {
found = true;
break;
}
left += icon_stride;
}
}
if (!found)
return;
const float right = left + icons_size_x;
const unsigned int tex_id = m_arrow_texture.get_id();
// arrow width and height
const float arr_tex_width = (float)m_arrow_texture.get_width();
const float arr_tex_height = (float)m_arrow_texture.get_height();
if (tex_id != 0 && arr_tex_width > 0.0f && arr_tex_height > 0.0f) {
const float arrow_size_x = 2.0f * m_layout.scale * arr_tex_width * inv_cnv_w;
const float arrow_size_y = 2.0f * m_layout.scale * arr_tex_height * inv_cnv_h;
const float left_uv = 0.0f;
const float right_uv = 1.0f;
const float top_uv = 1.0f;
const float bottom_uv = 0.0f;
top -= border_y;
const float bottom = top - arrow_size_y * icons_size_x / arrow_size_x;
GLTexture::render_sub_texture(tex_id, left, right, bottom, top, { { left_uv, top_uv }, { right_uv, top_uv }, { right_uv, bottom_uv }, { left_uv, bottom_uv } });
}
}
#else
void GLToolbar::render_arrow(const GLCanvas3D& parent, GLToolbarItem* highlighted_item)
{
// arrow texture not initialized
@ -1623,6 +1704,7 @@ void GLToolbar::render_arrow(const GLCanvas3D& parent, GLToolbarItem* highlighte
GLTexture::render_sub_texture(tex_id, internal_left, internal_right, internal_bottom, internal_top, { { internal_left_uv, internal_top_uv }, { internal_right_uv, internal_top_uv }, { internal_right_uv, internal_bottom_uv }, { internal_left_uv, internal_bottom_uv } });
}
}
#endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
#if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
void GLToolbar::render_horizontal(const GLCanvas3D& parent)

View File

@ -246,7 +246,11 @@ private:
GLTexture m_icons_texture;
bool m_icons_texture_dirty;
BackgroundTexture m_background_texture;
#if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
GLTexture m_arrow_texture;
#else
BackgroundTexture m_arrow_texture;
#endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
Layout m_layout;
ItemsList m_items;
@ -273,7 +277,11 @@ public:
bool init(const BackgroundTexture::Metadata& background_texture);
#if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
bool init_arrow(const std::string& filename);
#else
bool init_arrow(const BackgroundTexture::Metadata& arrow_texture);
#endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
Layout::EType get_layout_type() const;
void set_layout_type(Layout::EType type);

View File

@ -124,6 +124,16 @@ bool GLGizmosManager::init()
return true;
}
#if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
bool GLGizmosManager::init_arrow(const std::string& filename)
{
if (m_arrow_texture.get_id() != 0)
return true;
const std::string path = resources_dir() + "/icons/";
return (!filename.empty()) ? m_arrow_texture.load_from_svg_file(path + filename, false, false, false, 512) : false;
}
#else
bool GLGizmosManager::init_arrow(const BackgroundTexture::Metadata & arrow_texture)
{
if (m_arrow_texture.texture.get_id() != 0)
@ -139,6 +149,7 @@ bool GLGizmosManager::init_arrow(const BackgroundTexture::Metadata& arrow_textur
return res;
}
#endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
void GLGizmosManager::set_overlay_icon_size(float size)
{
@ -329,7 +340,7 @@ void GLGizmosManager::render_current_gizmo_for_picking_pass() const
m_gizmos[m_current]->render_for_picking();
}
void GLGizmosManager::render_overlay() const
void GLGizmosManager::render_overlay()
{
if (!m_enabled)
return;
@ -773,6 +784,54 @@ void GLGizmosManager::render_background(float left, float top, float right, floa
}
#endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
#if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
void GLGizmosManager::render_arrow(const GLCanvas3D& parent, EType highlighted_type) const
{
const std::vector<size_t> selectable_idxs = get_selectable_idxs();
if (selectable_idxs.empty())
return;
const Size cnv_size = m_parent.get_canvas_size();
const float cnv_w = (float)cnv_size.get_width();
const float cnv_h = (float)cnv_size.get_height();
if (cnv_w == 0 || cnv_h == 0)
return;
const float inv_cnv_w = 1.0f / cnv_w;
const float inv_cnv_h = 1.0f / cnv_h;
const float top_x = -1.0f;
float top_y = 0.5f * 2.0f * get_scaled_total_height() * inv_cnv_h;
const float icons_size_x = 2.0f * m_layout.scaled_icons_size() * inv_cnv_w;
const float icons_size_y = 2.0f * m_layout.scaled_icons_size() * inv_cnv_h;
const float stride_y = 2.0f * m_layout.scaled_stride_y() * inv_cnv_h;
for (size_t idx : selectable_idxs) {
if (idx == highlighted_type) {
const int tex_width = m_arrow_texture.get_width();
const int tex_height = m_arrow_texture.get_height();
const unsigned int tex_id = m_arrow_texture.get_id();
const float arrow_size_x = 2.0f * m_layout.scale * float(tex_height) * inv_cnv_w;
const float arrow_size_y = 2.0f * m_layout.scale * float(tex_width) * inv_cnv_h;
const float left_uv = 0.0f;
const float right_uv = 1.0f;
const float top_uv = 1.0f;
const float bottom_uv = 0.0f;
const float left = top_x + icons_size_x + 6.0f * m_layout.scaled_border() * inv_cnv_w;
const float right = left + arrow_size_x * icons_size_y / arrow_size_y;
GLTexture::render_sub_texture(tex_id, left, right, top_y, top_y + icons_size_y, { { left_uv, bottom_uv }, { left_uv, top_uv }, { right_uv, top_uv }, { right_uv, bottom_uv } });
break;
}
top_y -= stride_y;
}
}
#else
void GLGizmosManager::render_arrow(const GLCanvas3D& parent, EType highlighted_type) const
{
std::vector<size_t> selectable_idxs = get_selectable_idxs();
@ -811,11 +870,12 @@ void GLGizmosManager::render_arrow(const GLCanvas3D& parent, EType highlighted_t
zoomed_top_y -= zoomed_stride_y;
}
}
#endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
#if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
void GLGizmosManager::do_render_overlay() const
{
std::vector<size_t> selectable_idxs = get_selectable_idxs();
const std::vector<size_t> selectable_idxs = get_selectable_idxs();
if (selectable_idxs.empty())
return;
@ -989,14 +1049,12 @@ GLGizmosManager::EType GLGizmosManager::get_gizmo_from_name(const std::string& g
return GLGizmosManager::EType::Undefined;
}
bool GLGizmosManager::generate_icons_texture() const
bool GLGizmosManager::generate_icons_texture()
{
std::string path = resources_dir() + "/icons/";
std::vector<std::string> filenames;
for (size_t idx=0; idx<m_gizmos.size(); ++idx)
{
if (m_gizmos[idx] != nullptr)
{
for (size_t idx = 0; idx<m_gizmos.size(); ++idx) {
if (m_gizmos[idx] != nullptr) {
const std::string& icon_filename = m_gizmos[idx]->get_icon_filename();
if (!icon_filename.empty())
filenames.push_back(path + icon_filename);

View File

@ -102,10 +102,14 @@ private:
GLCanvas3D& m_parent;
bool m_enabled;
std::vector<std::unique_ptr<GLGizmoBase>> m_gizmos;
mutable GLTexture m_icons_texture;
mutable bool m_icons_texture_dirty;
GLTexture m_icons_texture;
bool m_icons_texture_dirty;
BackgroundTexture m_background_texture;
#if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
GLTexture m_arrow_texture;
#else
BackgroundTexture m_arrow_texture;
#endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
Layout m_layout;
EType m_current;
EType m_hover;
@ -133,7 +137,11 @@ public:
bool init();
#if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
bool init_arrow(const std::string& filename);
#else
bool init_arrow(const BackgroundTexture::Metadata& arrow_texture);
#endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
template<class Archive>
void load(Archive& ar)
@ -208,7 +216,7 @@ public:
void render_current_gizmo_for_picking_pass() const;
void render_painter_gizmo();
void render_overlay() const;
void render_overlay();
void render_arrow(const GLCanvas3D& parent, EType highlighted_type) const;
@ -245,7 +253,7 @@ private:
float get_scaled_total_height() const;
float get_scaled_total_width() const;
bool generate_icons_texture() const;
bool generate_icons_texture();
void update_hover_state(const EType &type);
bool grabber_contains_mouse() const;