From 53bd7d6ae289f16ad13918fee2fcac007890d7f1 Mon Sep 17 00:00:00 2001 From: Bruno Herbelin Date: Sat, 16 Dec 2023 20:52:36 +0100 Subject: [PATCH] DRAFT Source geometry 4 sides crop --- CMakeLists.txt | 1 + rsc/mesh/border_handles_arrows.ply | 315 +++++++++++++++++++++++++++++ src/Decorations.cpp | 30 +++ src/Decorations.h | 2 + src/GeometryView.cpp | 182 ++++++++++++++++- src/PickingVisitor.cpp | 4 +- src/Source.cpp | 8 + src/Source.h | 2 +- src/TextureView.cpp | 78 +++++++ 9 files changed, 616 insertions(+), 6 deletions(-) create mode 100644 rsc/mesh/border_handles_arrows.ply diff --git a/CMakeLists.txt b/CMakeLists.txt index 446933a..6ed8def 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -547,6 +547,7 @@ set(VMIX_RSC_FILES ./rsc/mesh/border_handles_lock.ply ./rsc/mesh/border_handles_lock_open.ply ./rsc/mesh/border_handles_shadow.ply + ./rsc/mesh/border_handles_arrows.ply ./rsc/mesh/border_large_sharp.ply ./rsc/mesh/border_vertical_overlay.ply ./rsc/mesh/perspective_layer.ply diff --git a/rsc/mesh/border_handles_arrows.ply b/rsc/mesh/border_handles_arrows.ply new file mode 100644 index 0000000..415918f --- /dev/null +++ b/rsc/mesh/border_handles_arrows.ply @@ -0,0 +1,315 @@ +ply +format ascii 1.0 +comment Created by Blender 3.6.2 - www.blender.org +element vertex 152 +property float x +property float y +property float z +property float nx +property float ny +property float nz +element face 150 +property list uchar uint vertex_indices +end_header +-0.054269 0.035526 0.000000 0.000000 0.000000 1.000000 +-0.051133 0.035460 0.000000 0.000000 0.000000 1.000000 +-0.052691 0.035643 0.000000 0.000000 0.000000 1.000000 +0.051265 0.035437 0.000000 0.000000 0.000000 1.000000 +0.054401 0.035503 0.000000 0.000000 0.000000 1.000000 +0.052822 0.035620 0.000000 0.000000 0.000000 1.000000 +-0.055825 0.035091 0.000000 0.000000 0.000000 1.000000 +0.055957 0.035068 0.000000 0.000000 0.000000 1.000000 +-0.049640 0.034996 0.000000 0.000000 0.000000 1.000000 +0.049772 0.034973 0.000000 0.000000 0.000000 1.000000 +-0.057314 0.034321 0.000000 0.000000 0.000000 1.000000 +0.057446 0.034298 0.000000 0.000000 0.000000 1.000000 +-0.048257 0.034269 0.000000 0.000000 0.000000 1.000000 +0.048388 0.034246 0.000000 0.000000 0.000000 1.000000 +-0.058692 0.033196 0.000000 0.000000 0.000000 1.000000 +0.058824 0.033173 0.000000 0.000000 0.000000 1.000000 +-0.047026 0.033297 0.000000 0.000000 0.000000 1.000000 +0.047158 0.033274 0.000000 0.000000 0.000000 1.000000 +-0.045992 0.032098 0.000000 0.000000 0.000000 1.000000 +0.046124 0.032075 0.000000 0.000000 0.000000 1.000000 +-0.059232 0.032657 0.000000 0.000000 0.000000 1.000000 +0.059363 0.032634 0.000000 0.000000 0.000000 1.000000 +-0.060723 0.031166 0.000000 0.000000 0.000000 1.000000 +0.060854 0.031143 0.000000 0.000000 0.000000 1.000000 +-0.045199 0.030691 0.000000 0.000000 0.000000 1.000000 +0.045331 0.030668 0.000000 0.000000 0.000000 1.000000 +-0.062975 0.028914 0.000000 0.000000 0.000000 1.000000 +0.063107 0.028891 0.000000 0.000000 0.000000 1.000000 +-0.044692 0.029093 0.000000 0.000000 0.000000 1.000000 +0.044824 0.029070 0.000000 0.000000 0.000000 1.000000 +-0.044512 0.027324 0.000000 0.000000 0.000000 1.000000 +0.044645 0.027300 0.000000 0.000000 0.000000 1.000000 +-0.065799 0.026091 0.000000 0.000000 0.000000 1.000000 +0.065930 0.026068 0.000000 0.000000 0.000000 1.000000 +-0.044512 0.026975 0.000000 0.000000 0.000000 1.000000 +0.044645 0.009597 0.000000 0.000000 0.000000 1.000000 +-0.044512 0.026011 0.000000 0.000000 0.000000 1.000000 +-0.069003 0.022888 0.000000 0.000000 0.000000 1.000000 +0.069134 0.022865 0.000000 0.000000 0.000000 1.000000 +-0.044512 0.024554 0.000000 0.000000 0.000000 1.000000 +-0.044512 0.022728 0.000000 0.000000 0.000000 1.000000 +-0.072397 0.019494 0.000000 0.000000 0.000000 1.000000 +0.072529 0.019471 0.000000 0.000000 0.000000 1.000000 +-0.044512 0.020656 0.000000 0.000000 0.000000 1.000000 +-0.044512 0.018460 0.000000 0.000000 0.000000 1.000000 +-0.075792 0.016100 0.000000 0.000000 0.000000 1.000000 +0.075923 0.016077 0.000000 0.000000 0.000000 1.000000 +-0.044512 0.016265 0.000000 0.000000 0.000000 1.000000 +-0.044512 0.014193 0.000000 0.000000 0.000000 1.000000 +-0.078996 0.012897 0.000000 0.000000 0.000000 1.000000 +0.079127 0.012874 0.000000 0.000000 0.000000 1.000000 +-0.044512 0.012367 0.000000 0.000000 0.000000 1.000000 +-0.081819 0.010074 0.000000 0.000000 0.000000 1.000000 +0.081951 0.010051 0.000000 0.000000 0.000000 1.000000 +-0.044512 0.010910 0.000000 0.000000 0.000000 1.000000 +-0.044512 0.009946 0.000000 0.000000 0.000000 1.000000 +-0.084072 0.007822 0.000000 0.000000 0.000000 1.000000 +0.084203 0.007799 0.000000 0.000000 0.000000 1.000000 +-0.044512 0.009597 0.000000 0.000000 0.000000 1.000000 +-0.009625 0.009597 0.000000 0.000000 0.000000 1.000000 +0.009757 0.009597 0.000000 0.000000 0.000000 1.000000 +-0.085563 0.006331 0.000000 0.000000 0.000000 1.000000 +0.085694 0.006308 0.000000 0.000000 0.000000 1.000000 +-0.086102 0.005792 0.000000 0.000000 0.000000 1.000000 +0.086234 0.005769 0.000000 0.000000 0.000000 1.000000 +-0.086845 0.004942 0.000000 0.000000 0.000000 1.000000 +0.086977 0.004919 0.000000 0.000000 0.000000 1.000000 +-0.087454 0.004021 0.000000 0.000000 0.000000 1.000000 +0.087585 0.003998 0.000000 0.000000 0.000000 1.000000 +-0.087927 0.003045 0.000000 0.000000 0.000000 1.000000 +0.088058 0.003022 0.000000 0.000000 0.000000 1.000000 +-0.088265 0.002027 0.000000 0.000000 0.000000 1.000000 +0.088396 0.002003 0.000000 0.000000 0.000000 1.000000 +-0.088467 0.000980 0.000000 0.000000 0.000000 1.000000 +0.088599 0.000957 0.000000 0.000000 0.000000 1.000000 +-0.088535 -0.000080 0.000000 0.000000 0.000000 1.000000 +0.088667 -0.000103 0.000000 0.000000 0.000000 1.000000 +-0.088467 -0.001140 0.000000 0.000000 0.000000 1.000000 +0.088599 -0.001164 0.000000 0.000000 0.000000 1.000000 +-0.088265 -0.002187 0.000000 0.000000 0.000000 1.000000 +0.088396 -0.002210 0.000000 0.000000 0.000000 1.000000 +-0.087927 -0.003205 0.000000 0.000000 0.000000 1.000000 +0.088058 -0.003228 0.000000 0.000000 0.000000 1.000000 +-0.087454 -0.004181 0.000000 0.000000 0.000000 1.000000 +0.087585 -0.004205 0.000000 0.000000 0.000000 1.000000 +-0.086845 -0.005102 0.000000 0.000000 0.000000 1.000000 +0.086977 -0.005125 0.000000 0.000000 0.000000 1.000000 +-0.086102 -0.005952 0.000000 0.000000 0.000000 1.000000 +0.086234 -0.005975 0.000000 0.000000 0.000000 1.000000 +-0.085563 -0.006491 0.000000 0.000000 0.000000 1.000000 +0.085694 -0.006515 0.000000 0.000000 0.000000 1.000000 +-0.084072 -0.007982 0.000000 0.000000 0.000000 1.000000 +0.084203 -0.008005 0.000000 0.000000 0.000000 1.000000 +-0.081819 -0.010234 0.000000 0.000000 0.000000 1.000000 +-0.044512 -0.009780 0.000000 0.000000 0.000000 1.000000 +-0.009625 -0.009780 0.000000 0.000000 0.000000 1.000000 +0.009757 -0.009780 0.000000 0.000000 0.000000 1.000000 +0.044645 -0.009780 0.000000 0.000000 0.000000 1.000000 +0.081951 -0.010257 0.000000 0.000000 0.000000 1.000000 +-0.044512 -0.027483 0.000000 0.000000 0.000000 1.000000 +0.044645 -0.010129 0.000000 0.000000 0.000000 1.000000 +0.044645 -0.011093 0.000000 0.000000 0.000000 1.000000 +-0.078996 -0.013057 0.000000 0.000000 0.000000 1.000000 +0.079127 -0.013080 0.000000 0.000000 0.000000 1.000000 +0.044645 -0.012550 0.000000 0.000000 0.000000 1.000000 +0.044645 -0.014376 0.000000 0.000000 0.000000 1.000000 +-0.075792 -0.016260 0.000000 0.000000 0.000000 1.000000 +0.075923 -0.016283 0.000000 0.000000 0.000000 1.000000 +0.044645 -0.016448 0.000000 0.000000 0.000000 1.000000 +-0.072397 -0.019654 0.000000 0.000000 0.000000 1.000000 +0.072529 -0.019677 0.000000 0.000000 0.000000 1.000000 +0.044645 -0.018643 0.000000 0.000000 0.000000 1.000000 +0.044645 -0.020839 0.000000 0.000000 0.000000 1.000000 +-0.069003 -0.023048 0.000000 0.000000 0.000000 1.000000 +0.069134 -0.023071 0.000000 0.000000 0.000000 1.000000 +0.044645 -0.022911 0.000000 0.000000 0.000000 1.000000 +0.044645 -0.024737 0.000000 0.000000 0.000000 1.000000 +-0.065799 -0.026251 0.000000 0.000000 0.000000 1.000000 +0.065930 -0.026274 0.000000 0.000000 0.000000 1.000000 +0.044645 -0.026194 0.000000 0.000000 0.000000 1.000000 +0.044645 -0.027158 0.000000 0.000000 0.000000 1.000000 +-0.062975 -0.029074 0.000000 0.000000 0.000000 1.000000 +0.063107 -0.029097 0.000000 0.000000 0.000000 1.000000 +0.044645 -0.027507 0.000000 0.000000 0.000000 1.000000 +-0.044692 -0.029253 0.000000 0.000000 0.000000 1.000000 +0.044823 -0.029276 0.000000 0.000000 0.000000 1.000000 +-0.060723 -0.031326 0.000000 0.000000 0.000000 1.000000 +0.060854 -0.031349 0.000000 0.000000 0.000000 1.000000 +-0.045199 -0.030851 0.000000 0.000000 0.000000 1.000000 +0.045331 -0.030874 0.000000 0.000000 0.000000 1.000000 +-0.045992 -0.032258 0.000000 0.000000 0.000000 1.000000 +0.046124 -0.032281 0.000000 0.000000 0.000000 1.000000 +-0.059232 -0.032817 0.000000 0.000000 0.000000 1.000000 +0.059363 -0.032840 0.000000 0.000000 0.000000 1.000000 +-0.047026 -0.033457 0.000000 0.000000 0.000000 1.000000 +0.047158 -0.033480 0.000000 0.000000 0.000000 1.000000 +-0.058692 -0.033356 0.000000 0.000000 0.000000 1.000000 +0.058824 -0.033379 0.000000 0.000000 0.000000 1.000000 +-0.057314 -0.034481 0.000000 0.000000 0.000000 1.000000 +0.057446 -0.034504 0.000000 0.000000 0.000000 1.000000 +-0.048257 -0.034429 0.000000 0.000000 0.000000 1.000000 +0.048388 -0.034452 0.000000 0.000000 0.000000 1.000000 +-0.049640 -0.035156 0.000000 0.000000 0.000000 1.000000 +0.049772 -0.035179 0.000000 0.000000 0.000000 1.000000 +-0.055825 -0.035251 0.000000 0.000000 0.000000 1.000000 +0.055957 -0.035274 0.000000 0.000000 0.000000 1.000000 +-0.051133 -0.035620 0.000000 0.000000 0.000000 1.000000 +0.051265 -0.035643 0.000000 0.000000 0.000000 1.000000 +-0.054269 -0.035686 0.000000 0.000000 0.000000 1.000000 +0.054401 -0.035709 0.000000 0.000000 0.000000 1.000000 +-0.052690 -0.035803 0.000000 0.000000 0.000000 1.000000 +0.052822 -0.035826 0.000000 0.000000 0.000000 1.000000 +3 0 1 2 +3 3 4 5 +3 6 1 0 +3 3 7 4 +3 6 8 1 +3 9 7 3 +3 10 8 6 +3 9 11 7 +3 10 12 8 +3 13 11 9 +3 14 12 10 +3 13 15 11 +3 14 16 12 +3 17 15 13 +3 14 18 16 +3 19 15 17 +3 20 18 14 +3 19 21 15 +3 22 18 20 +3 19 23 21 +3 22 24 18 +3 25 23 19 +3 26 24 22 +3 25 27 23 +3 26 28 24 +3 29 27 25 +3 26 30 28 +3 31 27 29 +3 32 30 26 +3 31 33 27 +3 32 34 30 +3 35 33 31 +3 32 36 34 +3 37 36 32 +3 35 38 33 +3 37 39 36 +3 37 40 39 +3 41 40 37 +3 35 42 38 +3 41 43 40 +3 41 44 43 +3 45 44 41 +3 35 46 42 +3 45 47 44 +3 45 48 47 +3 49 48 45 +3 35 50 46 +3 49 51 48 +3 52 51 49 +3 35 53 50 +3 52 54 51 +3 52 55 54 +3 56 55 52 +3 35 57 53 +3 56 58 55 +3 56 59 58 +3 56 60 59 +3 56 35 60 +3 56 57 35 +3 61 57 56 +3 61 62 57 +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 77 78 76 +3 79 78 77 +3 79 80 78 +3 81 80 79 +3 81 82 80 +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 +3 91 92 90 +3 93 92 91 +3 93 94 92 +3 94 95 92 +3 95 96 92 +3 96 97 92 +3 97 98 92 +3 93 99 94 +3 100 98 97 +3 101 98 100 +3 102 99 93 +3 101 103 98 +3 104 103 101 +3 105 103 104 +3 106 99 102 +3 105 107 103 +3 108 107 105 +3 109 99 106 +3 108 110 107 +3 111 110 108 +3 112 110 111 +3 113 99 109 +3 112 114 110 +3 115 114 112 +3 116 114 115 +3 117 99 113 +3 116 118 114 +3 119 118 116 +3 120 118 119 +3 121 99 117 +3 120 122 118 +3 123 122 120 +3 121 124 99 +3 125 122 123 +3 126 124 121 +3 125 127 122 +3 126 128 124 +3 129 127 125 +3 126 130 128 +3 131 127 129 +3 132 130 126 +3 131 133 127 +3 132 134 130 +3 135 133 131 +3 136 134 132 +3 135 137 133 +3 138 134 136 +3 135 139 137 +3 138 140 134 +3 141 139 135 +3 138 142 140 +3 143 139 141 +3 144 142 138 +3 143 145 139 +3 144 146 142 +3 147 145 143 +3 148 146 144 +3 147 149 145 +3 148 150 146 +3 151 149 147 diff --git a/src/Decorations.cpp b/src/Decorations.cpp index dc6fd57..ef91fa7 100644 --- a/src/Decorations.cpp +++ b/src/Decorations.cpp @@ -219,6 +219,7 @@ Handles::Handles(Type type) : Node(), type_(type) static Mesh *handle_eyeslash = new Mesh("mesh/icon_eye_slash.ply"); static Mesh *handle_shadow = new Mesh("mesh/border_handles_shadow.ply", "images/soft_shadow.dds"); static Mesh *handle_node = new Mesh("mesh/border_handles_sharp.ply"); + static Mesh *handle_crop_h = new Mesh("mesh/border_handles_arrows.ply"); color = glm::vec4( 1.f, 1.f, 1.f, 1.f); corner_ = glm::vec2(0.f, 0.f); @@ -251,6 +252,12 @@ Handles::Handles(Type type) : Node(), type_(type) else if ( type_ >= Handles::NODE_LOWER_LEFT && type_ <= Handles::NODE_UPPER_RIGHT ) { handle_ = handle_node; } + else if ( type_ == Handles::CROP_H ) { + handle_ = handle_crop_h; + } + else if ( type_ == Handles::CROP_V ) { + handle_ = handle_crop_h; + } else { handle_ = handle_corner; } @@ -450,6 +457,29 @@ void Handles::draw(glm::mat4 modelview, glm::mat4 projection) // 2. draw handle_->draw( ctm, projection ); } + else if ( type_ == Handles::CROP_H ){ + // left and right + vec = modelview * glm::vec4(1.f, 0.f, 0.f, 1.f); + ctm = GlmToolkit::transform(vec, rot, glm::vec3(1.f)); + handle_->draw( ctm, projection ); + + vec = modelview * glm::vec4(-1.f, 0.f, 0.f, 1.f); + ctm = GlmToolkit::transform(vec, rot, glm::vec3(1.f)); + handle_->draw( ctm, projection ); + + } + else if ( type_ == Handles::CROP_V ){ + // top and bottom + vec = modelview * glm::vec4(0.f, 1.f, 0.f, 1.f); + ctm = GlmToolkit::transform(vec, rot, glm::vec3(1.f)); + ctm = glm::rotate(ctm, M_PI_2f, glm::vec3(0.f, 0.f, 1.f)); + handle_->draw( ctm, projection ); + + vec = modelview * glm::vec4(0.f, -1.f, 0.f, 1.f); + ctm = GlmToolkit::transform(vec, rot, glm::vec3(1.f)); + ctm = glm::rotate(ctm, M_PI_2f, glm::vec3(0.f, 0.f, 1.f)); + handle_->draw( ctm, projection ); + } } } diff --git a/src/Decorations.h b/src/Decorations.h index 2721b16..643182c 100644 --- a/src/Decorations.h +++ b/src/Decorations.h @@ -46,6 +46,8 @@ public: NODE_UPPER_LEFT, NODE_LOWER_RIGHT, NODE_UPPER_RIGHT, + CROP_H, + CROP_V, EDIT_CROP, EDIT_SHAPE, MENU, diff --git a/src/GeometryView.cpp b/src/GeometryView.cpp index 6b4729c..4db1663 100644 --- a/src/GeometryView.cpp +++ b/src/GeometryView.cpp @@ -331,6 +331,7 @@ void GeometryView::draw() } if (ImGui::BeginPopup("GeometrySourceContextMenu")) { if (s != nullptr) { + if (ImGui::MenuItem( ICON_FA_EXPAND " Fit" )){ s->group(mode_)->scale_ = glm::vec3(output_surface_->scale_.x/ s->frame()->aspectRatio(), 1.f, 1.f); s->group(mode_)->rotation_.z = 0; @@ -488,9 +489,11 @@ void GeometryView::adaptGridToSource(Source *s, Node *picked) } else if ( picked == s->handles_[mode_][Handles::SCALE] || picked == s->handles_[mode_][Handles::NODE_LOWER_LEFT] || - picked == s->handles_[mode_][Handles::NODE_UPPER_LEFT] || - picked == s->handles_[mode_][Handles::NODE_LOWER_RIGHT] || - picked == s->handles_[mode_][Handles::NODE_UPPER_RIGHT] ){ + picked == s->handles_[mode_][Handles::NODE_UPPER_LEFT] || + picked == s->handles_[mode_][Handles::NODE_LOWER_RIGHT] || + picked == s->handles_[mode_][Handles::NODE_UPPER_RIGHT] || + picked == s->handles_[mode_][Handles::CROP_V] || + picked == s->handles_[mode_][Handles::CROP_H] ){ translation_grid_->root()->translation_ = s->group(mode_)->translation_; translation_grid_->root()->rotation_.z = s->group(mode_)->rotation_.z; // Swap grid to translation grid @@ -908,6 +911,7 @@ View::Cursor GeometryView::grab (Source *s, glm::vec2 from, glm::vec2 to, std::p // hide other grips s->handles_[mode_][Handles::MENU]->visible_ = false; s->handles_[mode_][Handles::EDIT_CROP]->visible_ = false; + // get stored status glm::vec3 node_pos = glm::vec3(s->stored_status_->data_[3].x, s->stored_status_->data_[3].y, @@ -926,6 +930,178 @@ View::Cursor GeometryView::grab (Source *s, glm::vec2 from, glm::vec2 to, std::p sourceNode->data_[3].x = CLAMP( node_pos.x, -0.99f, 0.f ); sourceNode->data_[3].y = CLAMP( node_pos.y, -0.99f, 0.f ); } + else if (pick.first == s->handles_[mode_][Handles::CROP_H]) { + // hide all other grips + s->handles_[mode_][Handles::MENU]->visible_ = false; + s->handles_[mode_][Handles::EDIT_CROP]->visible_ = false; + + // prepare overlay + glm::vec3 _prev_crop_scale = 0.5f + * glm::vec3(s->stored_status_->crop_[0] + - s->stored_status_->crop_[1], + s->stored_status_->crop_[3] + - s->stored_status_->crop_[2], + 2.f); + overlay_crop_->scale_ = s->stored_status_->scale_ / _prev_crop_scale; + overlay_crop_->scale_.x *= s->frame()->aspectRatio(); + + overlay_crop_->translation_.x = s->stored_status_->translation_.x; + overlay_crop_->translation_.x + += (s->stored_status_->crop_[1] + _prev_crop_scale.x) * overlay_crop_->scale_.x; + + overlay_crop_->translation_.y = s->stored_status_->translation_.y; + overlay_crop_->translation_.y + += -s->stored_status_->crop_[3] + _prev_crop_scale.y; + + overlay_crop_->rotation_.z = s->stored_status_->rotation_.z; + overlay_crop_->update(0); + overlay_crop_->visible_ = true; + + // + // Manipulate the handle in the SCENE coordinates to apply grid snap + // + glm::vec4 handle = corner_to_scene_transform * glm::vec4(corner * 2.f, 0.f, 1.f ); + // move the corner we hold by the mouse translation (in scene reference frame) + handle = glm::translate(glm::identity(), scene_to - scene_from) * handle; + // snap handle coordinates to grid (if active) + if ( grid->active() ) + handle = grid->snap(handle); + + // Compute coordinates coordinates back in CORNER reference frame + handle = scene_to_corner_transform * handle; + // The scaling factor is computed by dividing new handle coordinates with the ones before transform + glm::vec2 handle_scaling = glm::vec2(handle.x, 1.f) / glm::vec2(corner.x * 2.f, 1.f); + + // Apply transform to the CROP + if (corner.x > 0.f) { + // RIGHT SIDE ; clamp between 0.1 and 1 + sourceNode->crop_[1] = CLAMP(s->stored_status_->crop_[0] + + (s->stored_status_->crop_[1] + - s->stored_status_->crop_[0]) + * handle_scaling.x, + 0.1f, + 1.f); + } else { + // LEFT SIDE : clamp between -1 and -0.1 + sourceNode->crop_[0] = CLAMP(s->stored_status_->crop_[1] + - (s->stored_status_->crop_[1] + - s->stored_status_->crop_[0]) + * handle_scaling.x, + -1.f, + -0.1f); + } + + // get back the horizontal scaling after clamping of cropped coordinates + handle_scaling.x = (sourceNode->crop_[1] - sourceNode->crop_[0]) + / (s->stored_status_->crop_[1] - s->stored_status_->crop_[0]); + + // + // Adjust scale and translation + // + // The center of the source in CORNER reference frame + glm::vec4 corner_center = glm::vec4(corner, 0.f, 1.f); + // scale center of source in CORNER reference frame + corner_center = glm::scale(glm::identity(), glm::vec3(handle_scaling, 1.f)) + * corner_center; + // convert center back into scene reference frame + corner_center = corner_to_scene_transform * corner_center; + + // Apply translation to the source + sourceNode->translation_ = glm::vec3(corner_center); + sourceNode->scale_ = s->stored_status_->scale_ * glm::vec3(handle_scaling, 1.f); + + // show cursor depending on angle + float c = tan(sourceNode->rotation_.z); + ret.type = ABS(c) > 1.f ? Cursor_ResizeNS : Cursor_ResizeEW; + info << "Crop H " << std::fixed << std::setprecision(3) << sourceNode->crop_[0]; + info << " x " << sourceNode->crop_[1]; + } + else if (pick.first == s->handles_[mode_][Handles::CROP_V]) { + // hide all other grips + s->handles_[mode_][Handles::MENU]->visible_ = false; + s->handles_[mode_][Handles::EDIT_CROP]->visible_ = false; + + // prepare overlay + glm::vec3 _prev_crop_scale = 0.5f + * glm::vec3(s->stored_status_->crop_[0] + - s->stored_status_->crop_[1], + s->stored_status_->crop_[3] + - s->stored_status_->crop_[2], + 2.f); + overlay_crop_->scale_ = s->stored_status_->scale_ / _prev_crop_scale; + overlay_crop_->scale_.x *= s->frame()->aspectRatio(); + + overlay_crop_->translation_.x = s->stored_status_->translation_.x; + overlay_crop_->translation_.x + += (s->stored_status_->crop_[1] + _prev_crop_scale.x) * overlay_crop_->scale_.x; + + overlay_crop_->translation_.y = s->stored_status_->translation_.y; + overlay_crop_->translation_.y + += -s->stored_status_->crop_[3] + _prev_crop_scale.y; + + overlay_crop_->rotation_.z = s->stored_status_->rotation_.z; + overlay_crop_->update(0); + overlay_crop_->visible_ = true; + + // + // Manipulate the handle in the SCENE coordinates to apply grid snap + // + glm::vec4 handle = corner_to_scene_transform * glm::vec4(corner * 2.f, 0.f, 1.f ); + // move the corner we hold by the mouse translation (in scene reference frame) + handle = glm::translate(glm::identity(), scene_to - scene_from) * handle; + // snap handle coordinates to grid (if active) + if ( grid->active() ) + handle = grid->snap(handle); + + // Compute coordinates coordinates back in CORNER reference frame + handle = scene_to_corner_transform * handle; + // The scaling factor is computed by dividing new handle coordinates with the ones before transform + glm::vec2 handle_scaling = glm::vec2(1.f, handle.y) / glm::vec2(1.f, corner.y * 2.f); + + // Apply transform to the CROP + if (corner.y > 0.f) { + // TOP SIDE ; clamp between 0.1 and 1 + sourceNode->crop_[2] = CLAMP(s->stored_status_->crop_[3] + + (s->stored_status_->crop_[2] + - s->stored_status_->crop_[3]) + * handle_scaling.y, + 0.1f, + 1.f); + } else { + // BOTTON SIDE : clamp between -1 and -0.1 + sourceNode->crop_[3] = CLAMP(s->stored_status_->crop_[2] + - (s->stored_status_->crop_[2] + - s->stored_status_->crop_[3]) + * handle_scaling.y, + -1.f, + -0.1f); + } + + // get back the horizontal scaling after clamping of cropped coordinates + handle_scaling.y = (sourceNode->crop_[2] - sourceNode->crop_[3]) + / (s->stored_status_->crop_[2] - s->stored_status_->crop_[3]); + + // + // Adjust scale and translation + // + // The center of the source in CORNER reference frame + glm::vec4 corner_center = glm::vec4(corner, 0.f, 1.f); + // scale center of source in CORNER reference frame + corner_center = glm::scale(glm::identity(), glm::vec3(handle_scaling, 1.f)) + * corner_center; + // convert center back into scene reference frame + corner_center = corner_to_scene_transform * corner_center; + + // Apply translation to the source + sourceNode->translation_ = glm::vec3(corner_center); + sourceNode->scale_ = s->stored_status_->scale_ * glm::vec3(handle_scaling, 1.f); + + // show cursor depending on angle + float c = tan(sourceNode->rotation_.z); + ret.type = ABS(c) > 1.f ? Cursor_ResizeEW : Cursor_ResizeNS; + info << "Crop V " << std::fixed << std::setprecision(3) << sourceNode->crop_[2]; + info << " x " << sourceNode->crop_[3]; + } // picking on the resizing handles in the corners RESIZE CORNER else if ( pick.first == s->handles_[mode_][Handles::RESIZE] ) { // hide other grips diff --git a/src/PickingVisitor.cpp b/src/PickingVisitor.cpp index 194e17b..d7c684e 100644 --- a/src/PickingVisitor.cpp +++ b/src/PickingVisitor.cpp @@ -160,12 +160,12 @@ void PickingVisitor::visit(Handles &n) glm::length(glm::vec2(-1.f, +1.f)- glm::vec2(P)) < scale || glm::length(glm::vec2(-1.f, -1.f)- glm::vec2(P)) < scale ); } - else if ( n.type() == Handles::RESIZE_H ){ + else if ( n.type() == Handles::RESIZE_H || n.type() == Handles::CROP_H ){ // left & right picked = ( glm::length(glm::vec2(+1.f, 0.f)- glm::vec2(P)) < scale || glm::length(glm::vec2(-1.f, 0.f)- glm::vec2(P)) < scale ); } - else if ( n.type() == Handles::RESIZE_V ){ + else if ( n.type() == Handles::RESIZE_V || n.type() == Handles::CROP_V ){ // top & bottom picked = ( glm::length(glm::vec2(0.f, +1.f)- glm::vec2(P)) < scale || glm::length(glm::vec2(0.f, -1.f)- glm::vec2(P)) < scale ); diff --git a/src/Source.cpp b/src/Source.cpp index ceddb2f..8c30e9a 100644 --- a/src/Source.cpp +++ b/src/Source.cpp @@ -249,6 +249,14 @@ Source::Source(uint64_t id) : SourceCore(), id_(id), ready_(false), symbol_(null handles_[View::GEOMETRY][Handles::NODE_UPPER_RIGHT]->color = glm::vec4(COLOR_HIGHLIGHT_SOURCE, 1.f); handles_[View::GEOMETRY][Handles::NODE_UPPER_RIGHT]->translation_.z = 0.1; node_manipulator->attach(handles_[View::GEOMETRY][Handles::NODE_UPPER_RIGHT]); + handles_[View::GEOMETRY][Handles::CROP_H] = new Handles(Handles::CROP_H); + handles_[View::GEOMETRY][Handles::CROP_H]->color = glm::vec4(COLOR_HIGHLIGHT_SOURCE, 1.f); + handles_[View::GEOMETRY][Handles::CROP_H]->translation_.z = 0.1; + node_manipulator->attach(handles_[View::GEOMETRY][Handles::CROP_H]); + handles_[View::GEOMETRY][Handles::CROP_V] = new Handles(Handles::CROP_V); + handles_[View::GEOMETRY][Handles::CROP_V]->color = glm::vec4(COLOR_HIGHLIGHT_SOURCE, 1.f); + handles_[View::GEOMETRY][Handles::CROP_V]->translation_.z = 0.1; + node_manipulator->attach(handles_[View::GEOMETRY][Handles::CROP_V]); handles_[View::GEOMETRY][Handles::EDIT_CROP] = new Handles(Handles::EDIT_CROP); handles_[View::GEOMETRY][Handles::EDIT_CROP]->color = glm::vec4(COLOR_HIGHLIGHT_SOURCE, 1.f); handles_[View::GEOMETRY][Handles::EDIT_CROP]->translation_.z = 0.1; diff --git a/src/Source.h b/src/Source.h index 9cba753..2f8e0cb 100644 --- a/src/Source.h +++ b/src/Source.h @@ -332,7 +332,7 @@ protected: // overlays and frames to be displayed on top of source std::map overlays_; std::map frames_; - std::map handles_; + std::map handles_; Handles *lock_, *unlock_; Switch *locker_, *manipulator_; Symbol *symbol_; diff --git a/src/TextureView.cpp b/src/TextureView.cpp index 339791b..832a850 100644 --- a/src/TextureView.cpp +++ b/src/TextureView.cpp @@ -561,6 +561,84 @@ void TextureView::adjustBackground() } +/* + * +void TextureView::adjustBackground() +{ + // by default consider edit source is null + mask_node_->visible_ = false; + float image_original_width = 1.f; + glm::vec2 edit_source_size = glm::vec2(1.f, 1.f); + + glm::vec3 scale = glm::vec3(1.f); + glm::vec3 shift = glm::vec3(0.f); + + preview_surface_->setTextureIndex( Resource::getTextureTransparent() ); + + // if its a valid index + if (edit_source_ != nullptr && edit_source_->ready()) { + // update rendering frame to match edit source AR + image_original_width = edit_source_->frame()->aspectRatio(); + edit_source_size.y = edit_source_->groups_[View::GEOMETRY]->crop_[2] - edit_source_->groups_[View::GEOMETRY]->crop_[3]; + edit_source_size.y *= 0.5f; + edit_source_size.x = edit_source_->groups_[View::GEOMETRY]->crop_[1] - edit_source_->groups_[View::GEOMETRY]->crop_[0]; + edit_source_size.x *= 0.5f * edit_source_->frame()->aspectRatio(); + +// scale = edit_source_->mixingsurface_->scale_; + scale = glm::vec3(edit_source_size, 1.f); + preview_surface_->setTextureIndex( edit_source_->frame()->texture() ); + preview_shader_->mask_texture = edit_source_->blendingShader()->mask_texture; + preview_surface_->scale_ = scale; + +// preview_surface_->scale_ = glm::vec3(edit_source_size, 1.f); + preview_surface_->translation_ = glm::vec3((1.f + edit_source_->groups_[View::GEOMETRY]->crop_[0]) * image_original_width * 0.5f, + (1.f - edit_source_->groups_[View::GEOMETRY]->crop_[2]) * -0.5f, + 1.f); + + // mask appearance + mask_node_->visible_ = edit_source_->maskShader()->mode == MaskShader::SHAPE && mask_cursor_shape_ > 0; + + int shape = edit_source_->maskShader()->shape; + mask_circle_->visible_ = shape == MaskShader::ELLIPSE; + mask_square_->visible_ = shape == MaskShader::OBLONG || shape == MaskShader::RECTANGLE; + mask_horizontal_->visible_ = shape == MaskShader::HORIZONTAL; + mask_vertical_->visible_ = shape == MaskShader::VERTICAL; + + // symetrical shapes + if ( shape < MaskShader::HORIZONTAL){ + mask_node_->scale_ = scale * glm::vec3(edit_source_->maskShader()->size, 1.f); + mask_node_->translation_ = glm::vec3(0.f); + } + // vertical + else if ( shape > MaskShader::HORIZONTAL ) { + mask_node_->scale_ = glm::vec3(1.f, scale.y, 1.f); + mask_node_->translation_ = glm::vec3(edit_source_->maskShader()->size.x * scale.x, 0.f, 0.f); + } + // horizontal + else { + mask_node_->scale_ = glm::vec3(scale.x, 1.f, 1.f); + mask_node_->translation_ = glm::vec3(0.f, edit_source_->maskShader()->size.y * scale.y, 0.f); + } + + } + + // background scene + background_surface_->scale_.x = image_original_width; + background_surface_->scale_.y = 1.f; + background_frame_->scale_.x = image_original_width; + vertical_mark_->translation_.x = -image_original_width; + + preview_frame_->translation_ = preview_surface_->translation_; + preview_checker_->translation_ = preview_surface_->translation_; + preview_frame_->scale_ = preview_surface_->scale_; + preview_checker_->scale_ = preview_surface_->scale_; + glm::mat4 Ar = glm::scale(glm::identity(), scale ); + static glm::mat4 Tra = glm::scale(glm::translate(glm::identity(), glm::vec3( -32.f, -32.f, 0.f)), glm::vec3( 64.f, 64.f, 1.f)); + preview_checker_->shader()->iTransform = Ar * Tra; + +} +*/ + Source *TextureView::getEditOrCurrentSource() { // get current source