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 0000000..1425584 Binary files /dev/null and b/rsc/images/checker.dds differ diff --git a/rsc/mesh/border_handles_menu.ply b/rsc/mesh/border_handles_menu.ply new file mode 100644 index 0000000..2e07d6a --- /dev/null +++ b/rsc/mesh/border_handles_menu.ply @@ -0,0 +1,186 @@ +ply +format ascii 1.0 +comment Created by Blender 2.90.1 - www.blender.org +element vertex 92 +property float x +property float y +property float z +element face 84 +property list uchar uint vertex_indices +end_header +-0.072407 -0.033213 0.000000 +-0.000033 -0.032785 0.000000 +-0.070745 -0.032785 0.000000 +0.001629 -0.033213 0.000000 +-0.073767 -0.034396 0.000000 +0.002988 -0.034396 0.000000 +-0.074824 -0.036184 0.000000 +0.004046 -0.036184 0.000000 +-0.075579 -0.038425 0.000000 +0.004801 -0.038425 0.000000 +-0.076032 -0.040968 0.000000 +0.005254 -0.040968 0.000000 +-0.076184 -0.043661 0.000000 +0.005405 -0.043661 0.000000 +-0.076032 -0.046355 0.000000 +0.005254 -0.046355 0.000000 +-0.075579 -0.048898 0.000000 +0.004801 -0.048898 0.000000 +-0.074824 -0.051139 0.000000 +0.004046 -0.051139 0.000000 +-0.073767 -0.052927 0.000000 +0.002988 -0.052927 0.000000 +-0.072407 -0.054110 0.000000 +0.001629 -0.054110 0.000000 +-0.070745 -0.054538 0.000000 +-0.000033 -0.054538 0.000000 +-0.072407 0.010293 0.000000 +-0.000033 0.010721 0.000000 +-0.070745 0.010721 0.000000 +0.001504 0.010332 0.000000 +0.002748 0.009178 0.000000 +-0.073767 0.009110 0.000000 +0.003703 0.007412 0.000000 +-0.074824 0.007322 0.000000 +0.004373 0.005184 0.000000 +-0.075579 0.005081 0.000000 +0.004762 0.002647 0.000000 +-0.076032 0.002538 0.000000 +0.004874 -0.000048 0.000000 +-0.076184 -0.000155 0.000000 +0.004713 -0.002748 0.000000 +-0.076032 -0.002849 0.000000 +0.004284 -0.005304 0.000000 +-0.075579 -0.005392 0.000000 +0.003591 -0.007561 0.000000 +-0.074824 -0.007633 0.000000 +0.002638 -0.009370 0.000000 +-0.073767 -0.009421 0.000000 +0.001428 -0.010577 0.000000 +-0.072407 -0.010604 0.000000 +-0.000033 -0.011032 0.000000 +-0.070745 -0.011032 0.000000 +-0.072407 0.053799 0.000000 +-0.000033 0.054227 0.000000 +-0.070745 0.054227 0.000000 +0.001629 0.053801 0.000000 +0.002988 0.052623 0.000000 +-0.073767 0.052616 0.000000 +0.004046 0.050842 0.000000 +-0.074824 0.050828 0.000000 +0.004801 0.048610 0.000000 +-0.075579 0.048587 0.000000 +0.005254 0.046075 0.000000 +-0.076032 0.046044 0.000000 +0.005405 0.043388 0.000000 +-0.076184 0.043351 0.000000 +0.005254 0.040699 0.000000 +-0.076032 0.040657 0.000000 +0.004801 0.038158 0.000000 +-0.075579 0.038114 0.000000 +0.004045 0.035915 0.000000 +-0.074824 0.035873 0.000000 +0.002988 0.034120 0.000000 +-0.073767 0.034085 0.000000 +0.001628 0.032923 0.000000 +-0.072407 0.032902 0.000000 +-0.000033 0.032474 0.000000 +-0.070745 0.032474 0.000000 +0.031984 0.014465 0.000000 +0.043833 0.014410 0.000000 +0.037905 0.014543 0.000000 +0.026465 0.014169 0.000000 +0.049375 0.014068 0.000000 +0.021742 0.013652 0.000000 +0.054137 0.013524 0.000000 +0.018208 0.012908 0.000000 +0.057724 0.012781 0.000000 +0.016258 0.011932 0.000000 +0.059743 0.011845 0.000000 +0.016285 0.010721 0.000000 +0.059800 0.010721 0.000000 +0.038043 -0.016878 0.000000 +3 0 1 2 +3 0 3 1 +3 4 3 0 +3 4 5 3 +3 6 5 4 +3 6 7 5 +3 8 7 6 +3 8 9 7 +3 10 9 8 +3 10 11 9 +3 12 11 10 +3 12 13 11 +3 14 13 12 +3 14 15 13 +3 16 15 14 +3 16 17 15 +3 18 17 16 +3 18 19 17 +3 20 19 18 +3 20 21 19 +3 22 21 20 +3 22 23 21 +3 24 23 22 +3 24 25 23 +3 26 27 28 +3 26 29 27 +3 26 30 29 +3 31 30 26 +3 31 32 30 +3 33 32 31 +3 33 34 32 +3 35 34 33 +3 35 36 34 +3 37 36 35 +3 37 38 36 +3 39 38 37 +3 39 40 38 +3 41 40 39 +3 41 42 40 +3 43 42 41 +3 43 44 42 +3 45 44 43 +3 45 46 44 +3 47 46 45 +3 47 48 46 +3 49 48 47 +3 49 50 48 +3 51 50 49 +3 52 53 54 +3 52 55 53 +3 52 56 55 +3 57 56 52 +3 57 58 56 +3 59 58 57 +3 59 60 58 +3 61 60 59 +3 61 62 60 +3 63 62 61 +3 63 64 62 +3 65 64 63 +3 65 66 64 +3 67 66 65 +3 67 68 66 +3 69 68 67 +3 69 70 68 +3 71 70 69 +3 71 72 70 +3 73 72 71 +3 73 74 72 +3 75 74 73 +3 75 76 74 +3 77 76 75 +3 78 79 80 +3 81 79 78 +3 81 82 79 +3 83 82 81 +3 83 84 82 +3 85 84 83 +3 85 86 84 +3 87 86 85 +3 87 88 86 +3 89 88 87 +3 89 90 88 +3 91 90 89 diff --git a/rsc/mesh/icon_rightarrow.ply b/rsc/mesh/icon_rightarrow.ply new file mode 100644 index 0000000..d55af9d --- /dev/null +++ b/rsc/mesh/icon_rightarrow.ply @@ -0,0 +1,47 @@ +ply +format ascii 1.0 +comment Created by Blender 2.90.1 - www.blender.org +element vertex 18 +property float x +property float y +property float z +property uchar red +property uchar green +property uchar blue +property uchar alpha +element face 15 +property list uchar uint vertex_indices +end_header +-0.098559 0.044351 0.000000 255 255 255 255 +-0.080774 0.054762 0.000000 255 255 255 255 +-0.098559 0.097694 0.000000 255 255 255 255 +-0.000743 -0.000102 0.000000 255 255 255 255 +-0.080774 0.026570 0.000000 255 255 255 255 +-0.025899 -0.000102 0.000000 255 255 255 255 +-0.214161 -0.044555 0.000000 255 255 255 255 +-0.196376 0.026570 0.000000 255 255 255 255 +-0.214161 0.044351 0.000000 255 255 255 255 +-0.196376 -0.026773 0.000000 255 255 255 255 +-0.080774 -0.054965 0.000000 255 255 255 255 +-0.098559 -0.097898 0.000000 255 255 255 255 +-0.080774 -0.026773 0.000000 255 255 255 255 +-0.098559 -0.044555 0.000000 255 255 255 255 +0.000234 -0.099325 -0.001878 255 255 255 255 +0.020009 -0.099325 -0.001878 255 255 255 255 +0.020009 0.097955 -0.001878 255 255 255 255 +0.000234 0.097955 -0.001878 255 255 255 255 +3 0 1 2 +3 1 3 2 +3 0 4 1 +3 5 3 1 +3 6 7 8 +3 7 0 8 +3 7 4 0 +3 6 9 7 +3 10 3 5 +3 10 11 3 +3 6 12 9 +3 6 13 12 +3 13 10 12 +3 11 10 13 +4 14 15 16 17