From d290b058ebf5ee4a9543114f28e55cb2109c2124 Mon Sep 17 00:00:00 2001 From: brunoherbelin Date: Sat, 12 Sep 2020 12:24:25 +0200 Subject: [PATCH] Added overlay of active resize corner in GeometryView, and overlay to show fixe-size rotation. --- CMakeLists.txt | 1 + Decorations.cpp | 33 ++++++++++++++++++++-------- Decorations.h | 3 +++ View.cpp | 58 +++++++++++++++++++++++++++++-------------------- View.h | 1 + 5 files changed, 63 insertions(+), 33 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ebb3d15..fd2b5d4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -295,6 +295,7 @@ set(VMIX_RSC_FILES ./rsc/mesh/border_handles_rotation.ply ./rsc/mesh/border_handles_scale.ply ./rsc/mesh/border_handles_overlay.ply + ./rsc/mesh/border_handles_overlay_filled.ply ./rsc/mesh/border_handles_sharp.ply ./rsc/mesh/border_large_sharp.ply ./rsc/mesh/border_vertical_overlay.ply diff --git a/Decorations.cpp b/Decorations.cpp index 9d4da9d..d062f44 100644 --- a/Decorations.cpp +++ b/Decorations.cpp @@ -170,6 +170,7 @@ Handles::Handles(Type type) : Node(), type_(type) handle_ = handle_corner; } + corner_ = glm::vec2(0.f, 0.f); } Handles::~Handles() @@ -184,6 +185,8 @@ void Handles::update( float dt ) void Handles::draw(glm::mat4 modelview, glm::mat4 projection) { + static Mesh *handle_active = new Mesh("mesh/border_handles_overlay_filled.ply"); + if ( !initialized() ) { if(handle_ && !handle_->initialized()) handle_->init(); @@ -224,6 +227,12 @@ void Handles::draw(glm::mat4 modelview, glm::mat4 projection) vec = modelview * glm::vec4(-1.f, 1.f, 0.f, 1.f); ctm = GlmToolkit::transform(vec, rot, glm::vec3(1.f)); handle_->draw( ctm, projection ); + + if ( glm::length(corner_) > 0.f ) { + vec = modelview * glm::vec4(corner_.x, corner_.y, 0.f, 1.f); + ctm = GlmToolkit::transform(vec, rot, glm::vec3(1.f)); + handle_active->draw( ctm, projection ); + } } else if ( type_ == Handles::RESIZE_H ){ // left and right @@ -234,6 +243,12 @@ void Handles::draw(glm::mat4 modelview, glm::mat4 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 ); + + if ( glm::length(corner_) > 0.f ) { + vec = modelview * glm::vec4(corner_.x, corner_.y, 0.f, 1.f); + ctm = GlmToolkit::transform(vec, rot, glm::vec3(1.f)); + handle_active->draw( ctm, projection ); + } } else if ( type_ == Handles::RESIZE_V ){ // top and bottom @@ -244,6 +259,12 @@ void Handles::draw(glm::mat4 modelview, glm::mat4 projection) vec = modelview * glm::vec4(0.f, -1.f, 0.f, 1.f); ctm = GlmToolkit::transform(vec, rot, glm::vec3(1.f)); handle_->draw( ctm, projection ); + + if ( glm::length(corner_) > 0.f ) { + vec = modelview * glm::vec4(corner_.x, corner_.y, 0.f, 1.f); + ctm = GlmToolkit::transform(vec, rot, glm::vec3(1.f)); + handle_active->draw( ctm, projection ); + } } else if ( type_ == Handles::ROTATE ){ // one icon in top right corner @@ -324,28 +345,22 @@ void Symbol::draw(glm::mat4 modelview, glm::mat4 projection) // set color symbol_->shader()->color = color; -// glm::mat4 ctm = modelview * transform_; -// // correct for aspect ratio -// glm::vec4 vec = ctm * glm::vec4(1.f, 1.0f, 0.f, 0.f); -// ctm *= glm::scale(glm::identity(), glm::vec3( vec.y / vec.x, 1.f, 1.f)); - // rebuild a matrix with rotation (see handles) and translation from modelview + translation_ // and define scale to be 1, 1 - glm::mat4 ctm; glm::vec3 rot(0.f); glm::vec4 vec = modelview * glm::vec4(1.f, 0.f, 0.f, 0.f); rot.z = glm::orientedAngle( glm::vec3(1.f, 0.f, 0.f), glm::normalize(glm::vec3(vec)), glm::vec3(0.f, 0.f, 1.f) ); - // extract scaling ctm = glm::rotate(glm::identity(), -rot.z, glm::vec3(0.f, 0.f, 1.f)) * modelview ; vec = ctm * glm::vec4(1.f, 1.f, 0.f, 0.f); glm::vec3 sca = glm::vec3(vec.y , vec.y, 1.f) * glm::vec3(scale_.y, scale_.y, 1.f); - + // extract translation glm::vec3 tran = glm::vec3(modelview[3][0], modelview[3][1], modelview[3][2]) ; tran += translation_ * glm::vec3(vec); - + // apply local rotation rot.z += rotation_.z; + // generate matrix ctm = GlmToolkit::transform(tran, rot, sca); symbol_->draw( ctm, projection); diff --git a/Decorations.h b/Decorations.h index 2b7d030..bb1708d 100644 --- a/Decorations.h +++ b/Decorations.h @@ -46,10 +46,13 @@ public: Type type() const { return type_; } Primitive *handle() const { return handle_; } + void overlayActiveCorner(glm::vec2 v) {corner_ = v;} + glm::vec4 color; protected: Primitive *handle_; + glm::vec2 corner_; Type type_; }; diff --git a/View.cpp b/View.cpp index 1559d02..28fe937 100644 --- a/View.cpp +++ b/View.cpp @@ -628,7 +628,7 @@ GeometryView::GeometryView() : View(GEOMETRY) // User interface foreground // // 'clock' : tic marks every 10 degrees for ROTATION - // (with opaque background) + // with dark background Group *g = new Group; Symbol *s = new Symbol(Symbol::CLOCK); g->attach(s); @@ -641,12 +641,18 @@ GeometryView::GeometryView() : View(GEOMETRY) overlay_rotation_clock_->scale_ = glm::vec3(0.25f, 0.25f, 1.f); scene.fg()->attach(overlay_rotation_clock_); overlay_rotation_clock_->visible_ = false; + // circle to show fixed-size ROTATION + overlay_rotation_fix_ = new Symbol(Symbol::SQUARE); + overlay_rotation_fix_->scale_ = glm::vec3(0.25f, 0.25f, 1.f); + scene.fg()->attach(overlay_rotation_fix_); + overlay_rotation_fix_->visible_ = false; // circle to show the center of ROTATION overlay_rotation_ = new Symbol(Symbol::CIRCLE); overlay_rotation_->scale_ = glm::vec3(0.25f, 0.25f, 1.f); scene.fg()->attach(overlay_rotation_); overlay_rotation_->visible_ = false; // 'grid' : tic marks every 0.1 step for SCALING + // with dark background g = new Group; s = new Symbol(Symbol::GRID); g->attach(s); @@ -814,12 +820,8 @@ View::Cursor GeometryView::grab (Source *s, glm::vec2 from, glm::vec2 to, std::p // picking on the resizing handles in the corners if ( pick.first == s->handle_[Handles::RESIZE] ) { -// overlay_scaling_->visible_ = true; -// glm::vec4 icon = corner_to_scene_transform * glm::vec4(0.f, 0.f, 0.f, 1.f); -// overlay_scaling_->translation_.x = icon.x; -// overlay_scaling_->translation_.y = icon.y; -// overlay_scaling_->rotation_.z = s->stored_status_->rotation_.z; -// overlay_scaling_->update(0); + // inform on which corner should be overlayed (opposite) + s->handle_[Handles::RESIZE]->overlayActiveCorner(-corner); // RESIZE CORNER // proportional SCALING with SHIFT @@ -865,12 +867,8 @@ View::Cursor GeometryView::grab (Source *s, glm::vec2 from, glm::vec2 to, std::p // picking on the BORDER RESIZING handles left or right else if ( pick.first == s->handle_[Handles::RESIZE_H] ) { -// overlay_scaling_->visible_ = true; -// glm::vec4 icon = corner_to_scene_transform * glm::vec4(0.f, 0.f, 0.f, 1.f); -// overlay_scaling_->translation_.x = icon.x; -// overlay_scaling_->translation_.y = icon.y; -// overlay_scaling_->rotation_.z = s->stored_status_->rotation_.z; -// overlay_scaling_->update(0); + // inform on which corner should be overlayed (opposite) + s->handle_[Handles::RESIZE_H]->overlayActiveCorner(-corner); // SHIFT: HORIZONTAL SCALE to restore source aspect ratio if (UserInterface::manager().shiftModifier()) { @@ -904,12 +902,8 @@ View::Cursor GeometryView::grab (Source *s, glm::vec2 from, glm::vec2 to, std::p // picking on the BORDER RESIZING handles top or bottom else if ( pick.first == s->handle_[Handles::RESIZE_V] ) { -// overlay_scaling_->visible_ = true; -// glm::vec4 icon = corner_to_scene_transform * glm::vec4(0.f, 0.f, 0.f, 1.f); -// overlay_scaling_->translation_.x = icon.x; -// overlay_scaling_->translation_.y = icon.y; -// overlay_scaling_->rotation_.z = s->stored_status_->rotation_.z; -// overlay_scaling_->update(0); + // inform on which corner should be overlayed (opposite) + s->handle_[Handles::RESIZE_V]->overlayActiveCorner(-corner); // SHIFT: VERTICAL SCALE to restore source aspect ratio if (UserInterface::manager().shiftModifier()) { @@ -977,6 +971,7 @@ View::Cursor GeometryView::grab (Source *s, glm::vec2 from, glm::vec2 to, std::p // ROTATION on CENTER overlay_rotation_clock_->visible_ = false; + overlay_rotation_fix_->visible_ = true; overlay_rotation_->visible_ = true; overlay_rotation_->translation_.x = s->stored_status_->translation_.x; overlay_rotation_->translation_.y = s->stored_status_->translation_.y; @@ -1009,7 +1004,9 @@ View::Cursor GeometryView::grab (Source *s, glm::vec2 from, glm::vec2 to, std::p // apply center scaling sourceNode->scale_ = s->stored_status_->scale_ * source_scaling; info << std::endl << " Size " << std::fixed << std::setprecision(3) << sourceNode->scale_.x; - info << " x " << sourceNode->scale_.y ; + info << " x " << sourceNode->scale_.y ; + overlay_rotation_fix_->visible_ = false; + overlay_rotation_fix_->copyTransform(overlay_rotation_); } } // picking anywhere but on a handle: user wants to move the source @@ -1045,11 +1042,24 @@ View::Cursor GeometryView::grab (Source *s, glm::vec2 from, glm::vec2 to, std::p void GeometryView::terminate() { + // hide all overlays overlay_rotation_clock_->visible_ = false; - overlay_rotation_->visible_ = false; - overlay_scaling_grid_->visible_ = false; - overlay_scaling_cross_->visible_ = false; - overlay_scaling_->visible_ = false; + overlay_rotation_fix_->visible_ = false; + overlay_rotation_->visible_ = false; + overlay_scaling_grid_->visible_ = false; + overlay_scaling_cross_->visible_ = false; + overlay_scaling_->visible_ = false; + + // cancel of all handles overlays + glm::vec2 c(0.f, 0.f); + for (auto sit = Mixer::manager().session()->begin(); + sit != Mixer::manager().session()->end(); sit++){ + + (*sit)->handle_[Handles::RESIZE]->overlayActiveCorner(c); + (*sit)->handle_[Handles::RESIZE_H]->overlayActiveCorner(c); + (*sit)->handle_[Handles::RESIZE_V]->overlayActiveCorner(c); + } + } //View::Cursor GeometryView::over (Source*, glm::vec2, std::pair) diff --git a/View.h b/View.h index 3f9d14c..cf06175 100644 --- a/View.h +++ b/View.h @@ -149,6 +149,7 @@ public: private: Node *overlay_rotation_; + Node *overlay_rotation_fix_; Node *overlay_rotation_clock_; Node *overlay_scaling_; Node *overlay_scaling_cross_;