From 4630d39663297cd0fdc6d653faf3f3016a727cb0 Mon Sep 17 00:00:00 2001 From: brunoherbelin Date: Tue, 17 Nov 2020 23:28:11 +0100 Subject: [PATCH] New context menu in Geometry and Appearance Views: special handle (upper left corner) with new icon and view-specific context menu on current source. --- CMakeLists.txt | 2 + Decorations.cpp | 15 +++ Decorations.h | 2 +- PickingVisitor.cpp | 6 + Source.cpp | 10 +- Source.h | 2 +- UserInterfaceManager.cpp | 1 + View.cpp | 87 +++++++++++---- View.h | 5 +- rsc/images/checker.dds | Bin 0 -> 384 bytes rsc/mesh/border_handles_menu.ply | 186 +++++++++++++++++++++++++++++++ rsc/mesh/icon_rightarrow.ply | 47 ++++++++ 12 files changed, 339 insertions(+), 24 deletions(-) create mode 100644 rsc/images/checker.dds create mode 100644 rsc/mesh/border_handles_menu.ply create mode 100644 rsc/mesh/icon_rightarrow.ply diff --git a/CMakeLists.txt b/CMakeLists.txt index badf0c1..38eb71d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -332,6 +332,7 @@ set(VMIX_RSC_FILES ./rsc/mesh/border_handles_overlay.ply ./rsc/mesh/border_handles_overlay_filled.ply ./rsc/mesh/border_handles_sharp.ply + ./rsc/mesh/border_handles_menu.ply ./rsc/mesh/border_large_sharp.ply ./rsc/mesh/border_vertical_overlay.ply ./rsc/mesh/perspective_layer.ply @@ -357,6 +358,7 @@ set(VMIX_RSC_FILES ./rsc/mesh/icon_clock.ply ./rsc/mesh/icon_clock_hand.ply ./rsc/mesh/icon_grid.ply + ./rsc/mesh/icon_rightarrow.ply ./rsc/mesh/h_line.ply ./rsc/mesh/h_mark.ply ) diff --git a/Decorations.cpp b/Decorations.cpp index 270f803..2fe8c28 100644 --- a/Decorations.cpp +++ b/Decorations.cpp @@ -158,6 +158,7 @@ Handles::Handles(Type type) : Node(), type_(type) static Mesh *handle_rotation = new Mesh("mesh/border_handles_rotation.ply"); static Mesh *handle_corner = new Mesh("mesh/border_handles_overlay.ply"); static Mesh *handle_scale = new Mesh("mesh/border_handles_scale.ply"); + static Mesh *handle_restore = new Mesh("mesh/border_handles_menu.ply"); color = glm::vec4( 1.f, 1.f, 0.f, 1.f); if ( type_ == Handles::ROTATE ) { @@ -166,6 +167,9 @@ Handles::Handles(Type type) : Node(), type_(type) else if ( type_ == Handles::SCALE ) { handle_ = handle_scale; } + else if ( type_ == Handles::MENU ) { + handle_ = handle_restore; + } else { handle_ = handle_corner; } @@ -288,6 +292,17 @@ void Handles::draw(glm::mat4 modelview, glm::mat4 projection) // 3. draw handle_->draw( ctm, projection ); } + else if ( type_ == Handles::MENU ){ + // one icon in top left corner + // 1. Fixed displacement by (-0.12,0.12) along the rotation.. + ctm = GlmToolkit::transform(glm::vec4(0.f), rot, mirror); + glm::vec4 pos = ctm * glm::vec4( -0.12f, 0.12f, 0.f, 1.f); + // 2. ..from the top right corner (1,1) + vec = ( modelview * glm::vec4(-1.f, 1.f, 0.f, 1.f) ) + pos; + ctm = GlmToolkit::transform(vec, rot, glm::vec3(1.f)); + // 3. draw + handle_->draw( ctm, projection ); + } } } diff --git a/Decorations.h b/Decorations.h index b20ebac..775dea8 100644 --- a/Decorations.h +++ b/Decorations.h @@ -36,7 +36,7 @@ protected: class Handles : public Node { public: - typedef enum { RESIZE = 0, RESIZE_H, RESIZE_V, ROTATE, SCALE } Type; + typedef enum { RESIZE = 0, RESIZE_H, RESIZE_V, ROTATE, SCALE, MENU } Type; Handles(Type type); ~Handles(); diff --git a/PickingVisitor.cpp b/PickingVisitor.cpp index 94b03c0..9b35e6b 100644 --- a/PickingVisitor.cpp +++ b/PickingVisitor.cpp @@ -156,6 +156,12 @@ void PickingVisitor::visit(Handles &n) float l = glm::length( glm::vec2(vec) ); picked = glm::length( glm::vec2( 1.f + l, -1.f - l) - glm::vec2(P) ) < 1.5f * scale; } + else if ( n.type() == Handles::MENU ){ + // the icon for restore is on the left top corner at (-0.12, 0.12) in scene coordinates + glm::vec4 vec = glm::inverse(modelview_) * glm::vec4( 0.1f, 0.1f, 0.f, 0.f ); + float l = glm::length( glm::vec2(vec) ); + picked = glm::length( glm::vec2( -1.f - l, 1.f + l) - glm::vec2(P) ) < 1.5f * scale; + } if ( picked ) // add this to the nodes picked diff --git a/Source.cpp b/Source.cpp index 102a539..f21a390 100644 --- a/Source.cpp +++ b/Source.cpp @@ -91,7 +91,11 @@ Source::Source() : initialized_(false), active_(true), need_update_(true), symbo handles_[View::GEOMETRY][Handles::SCALE] = new Handles(Handles::SCALE); handles_[View::GEOMETRY][Handles::SCALE]->color = glm::vec4( COLOR_HIGHLIGHT_SOURCE, 1.f); handles_[View::GEOMETRY][Handles::SCALE]->translation_.z = 0.1; - overlays_[View::GEOMETRY]->attach(handles_[View::GEOMETRY][Handles::SCALE]); + overlays_[View::GEOMETRY]->attach(handles_[View::GEOMETRY][Handles::SCALE]); + handles_[View::GEOMETRY][Handles::MENU] = new Handles(Handles::MENU); + handles_[View::GEOMETRY][Handles::MENU]->color = glm::vec4( COLOR_HIGHLIGHT_SOURCE, 1.f); + handles_[View::GEOMETRY][Handles::MENU]->translation_.z = 0.1; + overlays_[View::GEOMETRY]->attach(handles_[View::GEOMETRY][Handles::MENU]); frame = new Frame(Frame::SHARP, Frame::THIN, Frame::NONE); frame->translation_.z = 0.1; @@ -154,6 +158,10 @@ Source::Source() : initialized_(false), active_(true), need_update_(true), symbo handles_[View::APPEARANCE][Handles::SCALE]->color = glm::vec4( COLOR_APPEARANCE_SOURCE, 1.f); handles_[View::APPEARANCE][Handles::SCALE]->translation_.z = 0.1; overlays_[View::APPEARANCE]->attach(handles_[View::APPEARANCE][Handles::SCALE]); + handles_[View::APPEARANCE][Handles::MENU] = new Handles(Handles::MENU); + handles_[View::APPEARANCE][Handles::MENU]->color = glm::vec4( COLOR_APPEARANCE_SOURCE, 1.f); + handles_[View::APPEARANCE][Handles::MENU]->translation_.z = 0.1; + overlays_[View::APPEARANCE]->attach(handles_[View::APPEARANCE][Handles::MENU]); groups_[View::APPEARANCE]->attach(overlays_[View::APPEARANCE]); // empty transition node diff --git a/Source.h b/Source.h index 1f458bd..578e660 100644 --- a/Source.h +++ b/Source.h @@ -178,7 +178,7 @@ protected: // overlays and frames to be displayed on top of source std::map overlays_; std::map frames_; - std::map handles_; + std::map handles_; Symbol *symbol_; // update diff --git a/UserInterfaceManager.cpp b/UserInterfaceManager.cpp index aaa4412..b92f94c 100644 --- a/UserInterfaceManager.cpp +++ b/UserInterfaceManager.cpp @@ -219,6 +219,7 @@ bool UserInterface::Init() style.WindowRounding = base_font_size / 2.5f; style.ChildRounding = style.WindowRounding / 2.f; style.FrameRounding = style.WindowRounding / 2.f; + style.PopupRounding = style.WindowRounding / 2.f; style.GrabRounding = style.FrameRounding / 2.f; style.GrabMinSize = base_font_size / 1.5f; style.Alpha = 0.92f; diff --git a/View.cpp b/View.cpp index 57296b1..af666cc 100644 --- a/View.cpp +++ b/View.cpp @@ -762,6 +762,7 @@ GeometryView::GeometryView() : View(GEOMETRY) scene.fg()->attach(overlay_scaling_); overlay_scaling_->visible_ = false; + show_context_menu_ = false; } void GeometryView::update(float dt) @@ -839,6 +840,33 @@ void GeometryView::draw() scene.accept(dv); } + // display popup menu + if (show_context_menu_) + ImGui::OpenPopup( "GeometryContextMenu" ); + if (ImGui::BeginPopup( "GeometryContextMenu" )) { + Source *s = Mixer::manager().currentSource(); + if (s != nullptr) { + if (ImGui::Selectable( "Recenter" )){ + s->group(mode_)->translation_ = glm::vec3(0,0,0); + } + else if (ImGui::Selectable( "Reset Geometry " )){ + s->group(mode_)->scale_ = glm::vec3(1,1,1); + s->group(mode_)->rotation_.z = 0; + } + else if (ImGui::Selectable( "Restore original aspect ratio" )){ + s->group(mode_)->scale_.x = s->group(mode_)->scale_.y; + } + // TODO other actions +// else if (ImGui::Selectable( "Bring to front" )){ + +// } +// else if (ImGui::Selectable( "Send to back" )){ + +// } + } + show_context_menu_ = false; + ImGui::EndPopup(); + } } @@ -874,6 +902,11 @@ std::pair GeometryView::pick(glm::vec2 P) // not found: the current source was not clicked if (itp == pv.rend()) s = nullptr; + // picking on the menu handle + else if ( pick.first == s->handles_[mode_][Handles::MENU] ) { + // show context menu + show_context_menu_ = true; + } } // the clicked source changed (not the current source) if (s == nullptr) { @@ -1823,26 +1856,22 @@ int AppearanceView::size () //} -//std::pair AppearanceView::pick(glm::vec2 P) -//{ -// // get picking from generic View -// std::pair pick = View::pick(P); - -//// // picking visitor found nothing? -//// if ( pick.first == nullptr) { +std::pair AppearanceView::pick(glm::vec2 P) +{ + // get picking from generic View + std::pair pick = View::pick(P); -//// Source *s = Mixer::manager().currentSource(); -//// if (s != nullptr) { + Source *s = Mixer::manager().currentSource(); + if (s != nullptr) { + if ( pick.first == s->handles_[mode_][Handles::MENU] ) { + // show context menu + show_context_menu_ = true; + } + } -//// pick = std::pair(s->rendersurface_, glm::vec2(0.f)); -//// } - - -//// } - -// return pick; -//} + return pick; +} void AppearanceView::draw() { @@ -1896,12 +1925,32 @@ void AppearanceView::draw() } } - - Shader::force_blending_opacity = true; View::draw(); Shader::force_blending_opacity = false; + + // display popup menu + if (show_context_menu_) + ImGui::OpenPopup( "AppearanceContextMenu" ); + if (ImGui::BeginPopup( "AppearanceContextMenu" )) { + Source *s = Mixer::manager().currentSource(); + if (s != nullptr) { + if (ImGui::Selectable( "Recenter" )){ + s->group(mode_)->translation_ = glm::vec3(0,0,0); + } + else if (ImGui::Selectable( "Reset UV " )){ + s->group(mode_)->scale_ = glm::vec3(1,1,1); + s->group(mode_)->rotation_.z = 0; + } + else if (ImGui::Selectable( "Restore original aspect ratio" )){ + s->group(mode_)->scale_.x = s->group(mode_)->scale_.y; + } + } + show_context_menu_ = false; + ImGui::EndPopup(); + } + } View::Cursor AppearanceView::grab (Source *s, glm::vec2 from, glm::vec2 to, std::pair pick) diff --git a/View.h b/View.h index a852796..aa095a9 100644 --- a/View.h +++ b/View.h @@ -171,6 +171,7 @@ private: Node *overlay_scaling_; Node *overlay_scaling_cross_; Node *overlay_scaling_grid_; + bool show_context_menu_; }; class LayerView : public View @@ -223,7 +224,6 @@ class AppearanceView : public View public: AppearanceView(); - // select sources provided a start and end selection points in screen coordinates // void select(glm::vec2, glm::vec2) override; // void selectAll() override; @@ -234,7 +234,7 @@ public: void resize (int) override; int size () override; -// std::pair pick(glm::vec2 P) override; + std::pair pick(glm::vec2 P) override; Cursor grab (Source *s, glm::vec2 from, glm::vec2 to, std::pair pick) override; Cursor drag (glm::vec2, glm::vec2) override; void terminate() override; @@ -250,6 +250,7 @@ private: Symbol *overlay_scaling_; Symbol *overlay_scaling_cross_; Node *overlay_scaling_grid_; + bool show_context_menu_; }; diff --git a/rsc/images/checker.dds b/rsc/images/checker.dds new file mode 100644 index 0000000000000000000000000000000000000000..142558403a542c4d342f49b71502646d04afe3a2 GIT binary patch literal 384 zcmZ>930A0KU|?Vu;9w8{(jd&h2qGYqyQgn}u8T`>6elx85D%#Ulw$#6mxvH!tjfTK nqssh;g3EI@O<4s5xcI)=I>|6O5RJ~KR6n|T=zL1e$E6