From 4ed884de550f682fbb75840fdbc17476e34f8a3a Mon Sep 17 00:00:00 2001 From: Bruno Herbelin Date: Sun, 16 Apr 2023 23:21:08 +0200 Subject: [PATCH] Mouse over icons on source (on Symbol and Characters) Rename class Glyph in Decoration to Character ('Glyph' was used in system X typedef). Added MouseOver in Mixing and Layers view to show highlight color on icons of Symbol and Initials of source. Show left panel on clic on source Initials. --- src/Decorations.cpp | 30 ++++++++++++++++++------------ src/Decorations.h | 7 +++++-- src/DisplaysView.cpp | 2 +- src/LayerView.cpp | 34 ++++++++++++++++++++++++++++++++++ src/LayerView.h | 1 + src/MixingView.cpp | 31 +++++++++++++++++++++++++++++++ src/PickingVisitor.cpp | 17 +++++++++++++++++ src/PickingVisitor.h | 7 ++++++- src/Source.cpp | 4 ++-- src/Source.h | 4 ++-- src/UserInterfaceManager.cpp | 15 ++++++++++++--- src/UserInterfaceManager.h | 1 + src/Visitor.h | 2 ++ 13 files changed, 132 insertions(+), 23 deletions(-) diff --git a/src/Decorations.cpp b/src/Decorations.cpp index eadd8fc..553feae 100644 --- a/src/Decorations.cpp +++ b/src/Decorations.cpp @@ -590,31 +590,31 @@ void Disk::accept(Visitor& v) v.visit(*this); } -Surface *Glyph::font_ = nullptr; +Surface *Character::font_ = nullptr; -Glyph::Glyph(int imgui_font_index) : Node(), character_(' '), font_index_(imgui_font_index), baseline_(0.f), shape_(1.f, 1.f) +Character::Character(int imgui_font_index) : Node(), character_(' '), font_index_(imgui_font_index), baseline_(0.f), shape_(1.f, 1.f) { - if (Glyph::font_ == nullptr) - Glyph::font_ = new Surface; + if (Character::font_ == nullptr) + Character::font_ = new Surface; uvTransform_ = glm::identity(); color = glm::vec4( 1.f, 1.f, 1.f, 1.f); } -void Glyph::draw(glm::mat4 modelview, glm::mat4 projection) +void Character::draw(glm::mat4 modelview, glm::mat4 projection) { if ( !initialized() ) { - if (!Glyph::font_->initialized()) { + if (!Character::font_->initialized()) { uint tex = (uint)(intptr_t)ImGui::GetIO().Fonts->TexID; if ( tex > 0) { - Glyph::font_->init(); + Character::font_->init(); font_->setTextureIndex(tex); } } - if (Glyph::font_->initialized()) { + if (Character::font_->initialized()) { init(); setChar(character_); } @@ -623,10 +623,10 @@ void Glyph::draw(glm::mat4 modelview, glm::mat4 projection) if ( visible_ ) { // set color - Glyph::font_->shader()->color = color; + Character::font_->shader()->color = color; // modify the shader iTransform to select UVs of the desired glyph - Glyph::font_->shader()->iTransform = uvTransform_; + Character::font_->shader()->iTransform = uvTransform_; // rebuild a matrix with rotation (see handles) and translation from modelview + translation_ // and define scale to be 1, 1 @@ -646,11 +646,17 @@ void Glyph::draw(glm::mat4 modelview, glm::mat4 projection) // generate matrix ctm = GlmToolkit::transform(tran, rot, glm::vec3(sca, 1.f)); - Glyph::font_->draw( ctm, projection); + Character::font_->draw( ctm, projection); } } -void Glyph::setChar(char c) +void Character::accept(Visitor& v) +{ + Node::accept(v); + v.visit(*this); +} + +void Character::setChar(char c) { character_ = c; diff --git a/src/Decorations.h b/src/Decorations.h index a8c61bf..f4ec1d8 100644 --- a/src/Decorations.h +++ b/src/Decorations.h @@ -93,13 +93,16 @@ protected: static Mesh *disk_; }; -class Glyph : public Node +class Character : public Node { public: - Glyph(int imgui_font_index = 0); + Character(int imgui_font_index = 0); void setChar(char c); void draw (glm::mat4 modelview, glm::mat4 projection) override; + void accept (Visitor& v) override; + + GlmToolkit::AxisAlignedBoundingBox bbox() const { return font_->bbox(); } glm::vec4 color; diff --git a/src/DisplaysView.cpp b/src/DisplaysView.cpp index 219a2a8..87409a7 100644 --- a/src/DisplaysView.cpp +++ b/src/DisplaysView.cpp @@ -231,7 +231,7 @@ void DisplaysView::recenter () frame->color = glm::vec4( COLOR_MONITOR, 1.f); m->attach(frame); // central label - Glyph *label = new Glyph(4); + Character *label = new Character(4); label->setChar( std::to_string(index).back() ); label->color = glm::vec4( COLOR_MONITOR, 1.f ); label->translation_.y = 0.02f ; diff --git a/src/LayerView.cpp b/src/LayerView.cpp index 1b3fabc..e630465 100644 --- a/src/LayerView.cpp +++ b/src/LayerView.cpp @@ -257,6 +257,10 @@ std::pair LayerView::pick(glm::vec2 P) else if ( pick.first == s->symbol_ ) { UserInterface::manager().showSourceEditor(s); } + // pick the initials: ask to show left panel + else if ( pick.first == s->initial_0_ || pick.first == s->initial_1_ ) { + UserInterface::manager().showSourcePanel(s); + } } else pick = { nullptr, glm::vec2(0.f) }; @@ -336,6 +340,36 @@ View::Cursor LayerView::grab (Source *s, glm::vec2 from, glm::vec2 to, std::pair return Cursor(Cursor_ResizeNESW, info.str() ); } +View::Cursor LayerView::over (glm::vec2 pos) +{ + View::Cursor ret = Cursor(); + std::pair pick = View::pick(pos); + + // + // mouse over source + // + // Source *s = Mixer::manager().findSource(pick.first); + Source *s = Mixer::manager().currentSource(); + if (s != nullptr) { + + s->symbol_->color = glm::vec4( COLOR_HIGHLIGHT_SOURCE, 1.f ); + s->initial_0_->color = glm::vec4( COLOR_HIGHLIGHT_SOURCE, 1.f ); + s->initial_1_->color = glm::vec4( COLOR_HIGHLIGHT_SOURCE, 1.f ); + const ImVec4 h = ImGuiToolkit::HighlightColor(); + + // overlay symbol + if ( pick.first == s->symbol_ ) + s->symbol_->color = glm::vec4( h.x, h.y, h.z, 1.f ); + // overlay initials + if ( pick.first == s->initial_0_ || pick.first == s->initial_1_ ) { + s->initial_0_->color = glm::vec4( h.x, h.y, h.z, 1.f ); + s->initial_1_->color = glm::vec4( h.x, h.y, h.z, 1.f ); + } + } + + return ret; +} + void LayerView::arrow (glm::vec2 movement) { static float accumulator = 0.f; diff --git a/src/LayerView.h b/src/LayerView.h index d21b33c..7d43fb6 100644 --- a/src/LayerView.h +++ b/src/LayerView.h @@ -20,6 +20,7 @@ public: std::pair pick(glm::vec2) override; Cursor grab (Source *s, glm::vec2 from, glm::vec2 to, std::pair pick) override; void arrow (glm::vec2) override; + Cursor over (glm::vec2) override; float setDepth (Source *, float d = -1.f); diff --git a/src/MixingView.cpp b/src/MixingView.cpp index c884be7..13e07b9 100644 --- a/src/MixingView.cpp +++ b/src/MixingView.cpp @@ -448,6 +448,10 @@ std::pair MixingView::pick(glm::vec2 P) else if ( pick.first == s->symbol_ ) { UserInterface::manager().showSourceEditor(s); } + // pick the initials: ask to show left panel + else if ( pick.first == s->initial_0_ || pick.first == s->initial_1_ ) { + UserInterface::manager().showSourcePanel(s); + } // pick on the mixing group rotation icon else if ( pick.first == s->rotation_mixingroup_ ) { if (UserInterface::manager().shiftModifier()) @@ -612,7 +616,10 @@ View::Cursor MixingView::over (glm::vec2 pos) View::Cursor ret = Cursor(); std::pair pick = View::pick(pos); + // // deal with internal interactive objects + // + // mouse over opacity slider if ( pick.first == slider_ ) { slider_->color = glm::vec4( COLOR_CIRCLE_OVER, 0.9f ); slider_arrows_->visible_ = true; @@ -623,6 +630,7 @@ View::Cursor MixingView::over (glm::vec2 pos) slider_->color = glm::vec4( COLOR_CIRCLE, 0.9f ); } + // mouse over limbo scale if ( pick.first == limbo_slider_ ) { limbo_up_->shader()->color = glm::vec4( COLOR_CIRCLE_ARROW, limbo_slider_root_->translation_.y < MIXING_MAX_THRESHOLD ? 0.1f : 0.01f ); limbo_down_->shader()->color = glm::vec4( COLOR_CIRCLE_ARROW, limbo_slider_root_->translation_.y > MIXING_MIN_THRESHOLD ? 0.1f : 0.01f ); @@ -633,6 +641,7 @@ View::Cursor MixingView::over (glm::vec2 pos) limbo_down_->shader()->color = glm::vec4( COLOR_CIRCLE_ARROW, 0.01f ); } + // mouse over white and black buttons if ( pick.first == button_white_ ) button_white_->color = glm::vec4( COLOR_CIRCLE_OVER, 1.f ); else @@ -643,6 +652,28 @@ View::Cursor MixingView::over (glm::vec2 pos) else button_black_->color = glm::vec4( COLOR_CIRCLE, 1.f ); + // + // mouse over source + // + // Source *s = Mixer::manager().findSource(pick.first); + Source *s = Mixer::manager().currentSource(); + if (s != nullptr) { + + s->symbol_->color = glm::vec4( COLOR_HIGHLIGHT_SOURCE, 1.f ); + s->initial_0_->color = glm::vec4( COLOR_HIGHLIGHT_SOURCE, 1.f ); + s->initial_1_->color = glm::vec4( COLOR_HIGHLIGHT_SOURCE, 1.f ); + const ImVec4 h = ImGuiToolkit::HighlightColor(); + + // overlay symbol + if ( pick.first == s->symbol_ ) + s->symbol_->color = glm::vec4( h.x, h.y, h.z, 1.f ); + // overlay initials + if ( pick.first == s->initial_0_ || pick.first == s->initial_1_ ) { + s->initial_0_->color = glm::vec4( h.x, h.y, h.z, 1.f ); + s->initial_1_->color = glm::vec4( h.x, h.y, h.z, 1.f ); + } + } + return ret; } diff --git a/src/PickingVisitor.cpp b/src/PickingVisitor.cpp index 1e05890..0b4f84b 100644 --- a/src/PickingVisitor.cpp +++ b/src/PickingVisitor.cpp @@ -221,6 +221,23 @@ void PickingVisitor::visit(Symbol& n) } +void PickingVisitor::visit(Character& n) +{ + // discard if not visible or if not exactly one point given for picking + if ((!n.visible_ && !force_) || points_.size() != 1) + return; + + // apply inverse transform to the point of interest + glm::vec4 P = glm::inverse(modelview_) * glm::vec4( points_[0], 1.f ); + + // test bounding box for picking from a single point + if ( n.bbox().contains( glm::vec3(P)) ) { + // add this to the nodes picked + nodes_.push_back( std::pair(&n, glm::vec2(P)) ); + } + +} + void PickingVisitor::visit(Scene &n) { n.root()->accept(*this); diff --git a/src/PickingVisitor.h b/src/PickingVisitor.h index 17a1259..945b3b1 100644 --- a/src/PickingVisitor.h +++ b/src/PickingVisitor.h @@ -51,10 +51,15 @@ public: */ void visit(Handles& n) override; /** - * @brief visit Disk : picking grabber for mixing view + * @brief visit Symbol for mixing view * @param n */ void visit(Symbol& n) override; + /** + * @brief visit Glyph for mixing view + * @param n + */ + void visit(Character& n) override; /** * @brief visit Disk : picking grabber for mixing view * @param n diff --git a/src/Source.cpp b/src/Source.cpp index 67b8bc1..e84ec2a 100644 --- a/src/Source.cpp +++ b/src/Source.cpp @@ -144,11 +144,11 @@ Source::Source(uint64_t id) : SourceCore(), id_(id), ready_(false), symbol_(null groups_[View::MIXING]->attach(frames_[View::MIXING]); // Glyphs show letters from the intials, with Font index 4 (LARGE) - initial_0_ = new Glyph(4); + initial_0_ = new Character(4); initial_0_->translation_ = glm::vec3(0.2f, 0.8f, 0.1f); initial_0_->scale_.y = 0.2f; groups_[View::MIXING]->attach(initial_0_); - initial_1_ = new Glyph(4); + initial_1_ = new Character(4); initial_1_->translation_ = glm::vec3(0.4f, 0.8f, 0.1f); initial_1_->scale_.y = 0.2f; groups_[View::MIXING]->attach(initial_1_); diff --git a/src/Source.h b/src/Source.h index a95fc97..016571a 100644 --- a/src/Source.h +++ b/src/Source.h @@ -38,7 +38,7 @@ class FrameBufferSurface; class Frame; class Handles; class Symbol; -class Glyph; +class Character; class CloneSource; class MixingGroup; @@ -316,7 +316,7 @@ protected: Handles *lock_, *unlock_; Switch *locker_; Symbol *symbol_; - Glyph *initial_0_, *initial_1_; + Character *initial_0_, *initial_1_; // update bool active_; diff --git a/src/UserInterfaceManager.cpp b/src/UserInterfaceManager.cpp index 2016dfd..678e92e 100644 --- a/src/UserInterfaceManager.cpp +++ b/src/UserInterfaceManager.cpp @@ -1166,6 +1166,14 @@ int UserInterface::RenderViewNavigator(int *shift) return target_index; } +void UserInterface::showSourcePanel(Source *s) +{ + if (s) { + Mixer::manager().setCurrentSource( s ); + navigator.showPannelSource( Mixer::manager().indexCurrentSource() ); + } +} + void UserInterface::showSourceEditor(Source *s) { Mixer::manager().unsetCurrentSource(); @@ -1178,7 +1186,8 @@ void UserInterface::showSourceEditor(Source *s) sourcecontrol.resetActiveSelection(); return; } - navigator.showPannelSource( Mixer::manager().indexCurrentSource() ); + else + showSourcePanel(s); } } @@ -1729,9 +1738,9 @@ void UserInterface::RenderSourceToolbar(bool *p_open, int* p_border, int *p_mode // NO SOURCE and not auto hide else { - ImGui::TextDisabled(""); + ImGui::TextDisabled(" "); ImGui::TextDisabled("No source selected"); - ImGui::TextDisabled(""); + ImGui::TextDisabled(" "); } } diff --git a/src/UserInterfaceManager.h b/src/UserInterfaceManager.h index 82a53b6..e89f143 100644 --- a/src/UserInterfaceManager.h +++ b/src/UserInterfaceManager.h @@ -481,6 +481,7 @@ public: inline bool shiftModifier() const { return shift_modifier_active; } void showPannel(int id = 0); + void showSourcePanel(Source *s); void showSourceEditor(Source *s); void StartScreenshot(); diff --git a/src/Visitor.h b/src/Visitor.h index 3a6faf5..33ff8d3 100644 --- a/src/Visitor.h +++ b/src/Visitor.h @@ -20,6 +20,7 @@ class Frame; class Handles; class Symbol; class Disk; +class Character; class Stream; class MediaPlayer; class Shader; @@ -88,6 +89,7 @@ public: virtual void visit (Handles&) {} virtual void visit (Symbol&) {} virtual void visit (Disk&) {} + virtual void visit (Character&) {} virtual void visit (Shader&) {} virtual void visit (ImageShader&) {} virtual void visit (MaskShader&) {}