From 2c3d6ff02ed63e67b54731099fc6c4834ef15ca6 Mon Sep 17 00:00:00 2001 From: brunoherbelin Date: Fri, 19 Mar 2021 13:30:58 +0100 Subject: [PATCH] Implement lock source mechanism in TextureView --- Source.cpp | 1 + TextureView.cpp | 31 ++++++++++++++++++++----------- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/Source.cpp b/Source.cpp index e9f55c3..5af3b82 100644 --- a/Source.cpp +++ b/Source.cpp @@ -424,6 +424,7 @@ void Source::attach(FrameBuffer *renderbuffer) groups_[View::LAYER]->attach( locker_ ); groups_[View::MIXING]->attach( locker_ ); groups_[View::GEOMETRY]->attach( locker_ ); + groups_[View::TEXTURE]->attach( locker_ ); // scale all icon nodes to match aspect ratio for (int v = View::MIXING; v < View::INVALID; v++) { diff --git a/TextureView.cpp b/TextureView.cpp index bad49ce..2449dc5 100644 --- a/TextureView.cpp +++ b/TextureView.cpp @@ -346,16 +346,16 @@ std::pair TextureView::pick(glm::vec2 P) if ( !pv.empty()) { // keep edit source active if it is clicked // AND if the cursor is not for drawing - Source *s = edit_source_; - if (s != nullptr) { + Source *current = edit_source_; + if (current != nullptr) { // special case for drawing in the mask - if ( s->maskShader()->mode == MaskShader::PAINT && mask_cursor_paint_ > 0) { + if ( current->maskShader()->mode == MaskShader::PAINT && mask_cursor_paint_ > 0) { pick = { mask_cursor_circle_, P }; return pick; } // special case for cropping the mask shape - else if ( s->maskShader()->mode == MaskShader::SHAPE && mask_cursor_shape_ > 0) { + else if ( current->maskShader()->mode == MaskShader::SHAPE && mask_cursor_shape_ > 0) { pick = { mask_cursor_crop_, P }; return pick; } @@ -365,24 +365,33 @@ std::pair TextureView::pick(glm::vec2 P) for (; itp != pv.rend(); itp++){ // test if source contains this node Source::hasNode is_in_source( (*itp).first ); - if ( is_in_source( s ) ){ + if ( is_in_source( current ) ){ // a node in the current source was clicked ! pick = *itp; break; } } // not found: the edit source was not clicked - if ( itp == pv.rend() ) - s = nullptr; + if ( itp == pv.rend() ) { + current = nullptr; + } // picking on the menu handle - else if ( pick.first == s->handles_[mode_][Handles::MENU] ) { + else if ( pick.first == current->handles_[mode_][Handles::MENU] ) { // show context menu openContextMenu(MENU_SOURCE); } + // pick on the lock icon; unlock source + else if ( pick.first == current->lock_ ) { + lock(current, false); + } + // pick on the open lock icon; lock source and cancel pick + else if ( pick.first == current->unlock_ ) { + lock(current, true); + } } // not the edit source (or no edit source) - if (s == nullptr) { + if (current == nullptr) { // cancel pick pick = { nullptr, glm::vec2(0.f) }; } @@ -526,7 +535,7 @@ void TextureView::draw() if (edit_source_ != nullptr){ // force to redraw the frame of the edit source (even if source is not visible) - DrawVisitor dv(edit_source_->frames_[mode_], Rendering::manager().Projection(), true); + DrawVisitor dv(edit_source_->groups_[mode_], Rendering::manager().Projection(), true); scene.accept(dv); // display interface @@ -887,7 +896,7 @@ View::Cursor TextureView::grab (Source *s, glm::vec2 from, glm::vec2 to, std::pa glm::vec3 scene_translation = scene_to - scene_from; // Not grabbing a source - if (!s) { + if (!s || s->locked()) { // work on the edited source if ( edit_source_ != nullptr ) {