From f2cd18f754fa8acb2ef7c6109d6a97c692eff610 Mon Sep 17 00:00:00 2001 From: brunoherbelin Date: Sun, 28 Feb 2021 10:18:10 +0100 Subject: [PATCH] Cleanup and unify views interface (combo) --- GeometryView.cpp | 19 ++++++----------- ImGuiToolkit.cpp | 12 ++++++----- ImGuiToolkit.h | 6 +++--- ImGuiVisitor.cpp | 6 +++--- LayerView.cpp | 54 +++++++++++++++++++++++++++++++++++++++++------ LayerView.h | 2 ++ MixingView.cpp | 55 ++++++++++++++++++++++++++++++++++++++++++------ MixingView.h | 1 + TextureView.cpp | 7 +++--- View.cpp | 4 ++-- defines.h | 3 ++- 11 files changed, 126 insertions(+), 43 deletions(-) diff --git a/GeometryView.cpp b/GeometryView.cpp index 46af77b..6299c7d 100644 --- a/GeometryView.cpp +++ b/GeometryView.cpp @@ -236,25 +236,20 @@ void GeometryView::draw() // style grey ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(COLOR_FRAME_LIGHT, 1.f)); // 1 ImGui::PushStyleColor(ImGuiCol_PopupBg, ImVec4(0.14f, 0.14f, 0.14f, 0.9f)); + ImGui::PushStyleColor(ImGuiCol_Header, ImVec4(0.36f, 0.36f, 0.36f, 0.9f)); + ImGui::PushStyleColor(ImGuiCol_HeaderHovered, ImVec4(0.36f, 0.36f, 0.36f, 0.5f)); ImGui::PushStyleColor(ImGuiCol_FrameBg, ImVec4(0.14f, 0.14f, 0.14f, 0.00f)); ImGui::PushStyleColor(ImGuiCol_FrameBgHovered, ImVec4(0.14f, 0.14f, 0.14f, 0.46f)); - ImGui::PushStyleColor(ImGuiCol_SliderGrab, ImVec4(0.85f, 0.85f, 0.85f, 0.86f)); - ImGui::PushStyleColor(ImGuiCol_SliderGrabActive, ImVec4(0.95f, 0.95f, 0.95f, 1.00f)); - ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0.00f, 0.00f, 0.00f, 0.00f)); - ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4(0.14f, 0.14f, 0.14f, 0.46f)); - ImGui::PushStyleColor(ImGuiCol_Header, ImVec4(0.67f, 0.67f, 0.67f, 0.79f)); - ImGui::PushStyleColor(ImGuiCol_HeaderHovered, ImVec4(0.36f, 0.36f, 0.36f, 0.44f)); - ImGui::PushStyleColor(ImGuiCol_HeaderActive, ImVec4(0.88f, 0.88f, 0.88f, 0.73f)); - ImGui::PushStyleColor(ImGuiCol_Tab, ImVec4(0.83f, 0.83f, 0.84f, 0.78f)); - ImGui::PushStyleColor(ImGuiCol_TabHovered, ImVec4(0.53f, 0.53f, 0.53f, 0.60f)); - ImGui::PushStyleColor(ImGuiCol_TabActive, ImVec4(0.40f, 0.40f, 0.40f, 1.00f)); // 14 colors + ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0.14f, 0.14f, 0.14f, 0.00f)); + ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4(0.14f, 0.14f, 0.14f, 0.46f)); // 8 static std::vector< std::pair > icons_ws = { {10,16}, {11,16}, {12,16} }; - if ( ImGuiToolkit::ComboIcon (icons_ws, &Settings::application.current_workspace) ){ + static std::vector< std::string > labels_ws = { "Background", "Workspace", "Foreground" }; + if ( ImGuiToolkit::ComboIcon (icons_ws, labels_ws, &Settings::application.current_workspace) ){ View::need_deep_update_++; } - ImGui::PopStyleColor(14); // 14 colors + ImGui::PopStyleColor(8); // 14 colors ImGui::End(); } ImGui::PopFont(); diff --git a/ImGuiToolkit.cpp b/ImGuiToolkit.cpp index c38b3b1..e4e9fcb 100644 --- a/ImGuiToolkit.cpp +++ b/ImGuiToolkit.cpp @@ -265,7 +265,7 @@ bool ImGuiToolkit::ButtonIconMultistate(std::vector > icons, return ret; } -bool ImGuiToolkit::ComboIcon (std::vector > icons, int* state) +bool ImGuiToolkit::ComboIcon (std::vector > icons, std::vector labels, int* state) { bool ret = false; Sum id = std::for_each(icons.begin(), icons.end(), Sum()); @@ -276,18 +276,20 @@ bool ImGuiToolkit::ComboIcon (std::vector > icons, int* stat ImGui::SetNextItemWidth(w * 2.6f); if (ImGui::BeginCombo("##ComboIcon", " ") ) { - std::vector >::iterator it = icons.begin(); - for(int i = 0 ; it != icons.end(); i++, it++) { + std::vector >::iterator it_icon = icons.begin(); + std::vector::iterator it_label = labels.begin(); + for(int i = 0 ; it_icon != icons.end(); i++, it_icon++, it_label++) { ImGui::PushID( id.sum + i + 1); ImVec2 pos = ImGui::GetCursorScreenPos(); // combo selectable item - if ( ImGui::Selectable(" ", i == *state )){ + std::string label = " " + (*it_label); + if ( ImGui::Selectable(label.c_str(), i == *state )){ *state = i; ret = true; } // draw item icon ImGui::SetCursorScreenPos( pos + ImVec2(w/6.f,0) ); - Icon( (*it).first, (*it).second ); + Icon( (*it_icon).first, (*it_icon).second ); ImGui::PopID(); } ImGui::EndCombo(); diff --git a/ImGuiToolkit.h b/ImGuiToolkit.h index bf6159e..26ecf20 100644 --- a/ImGuiToolkit.h +++ b/ImGuiToolkit.h @@ -20,16 +20,16 @@ namespace ImGuiToolkit bool ButtonIcon (int i, int j, const char* tooltip = nullptr); bool ButtonIconToggle (int i, int j, int i_toggle, int j_toggle, bool* toggle); bool ButtonIconMultistate (std::vector > icons, int* state); - bool ComboIcon (std::vector > icons, int* state); + bool ComboIcon (std::vector > icons, std::vector labels, int* state); // utility buttons bool ButtonToggle (const char* label, bool* toggle); void ButtonSwitch (const char* label, bool* toggle , const char *help = nullptr); void ButtonOpenUrl (const char* url, const ImVec2& size_arg = ImVec2(0,0)); - void ToolTip (const char* desc, const char* shortcut = ""); + void ToolTip (const char* desc, const char* shortcut = nullptr); void HelpMarker (const char* desc, const char* icon = ICON_FA_QUESTION_CIRCLE, const char* shortcut = nullptr); - void HelpIcon (const char* desc, int i = 19, int j = 5, const char* shortcut = ""); + void HelpIcon (const char* desc, int i = 19, int j = 5, const char* shortcut = nullptr); // utility sliders bool TimelineSlider (const char* label, guint64 *time, guint64 start, guint64 end, guint64 step, const float width); diff --git a/ImGuiVisitor.cpp b/ImGuiVisitor.cpp index 173c045..72b7f7f 100644 --- a/ImGuiVisitor.cpp +++ b/ImGuiVisitor.cpp @@ -431,11 +431,11 @@ void ImGuiVisitor::visit (Source& s) // Inform on workspace ImGui::SetCursorPos( ImVec2(preview_width + 20, pos.y + ImGui::GetFrameHeightWithSpacing()) ); if (s.workspace() == Source::BACKGROUND) - ImGuiToolkit::HelpIcon("Background",10, 16); + ImGuiToolkit::HelpIcon("in Background",10, 16); else if (s.workspace() == Source::FOREGROUND) - ImGuiToolkit::HelpIcon("Foreground",12, 16); + ImGuiToolkit::HelpIcon("in Foreground",12, 16); else - ImGuiToolkit::HelpIcon("Stage",11, 16); + ImGuiToolkit::HelpIcon("in Workspace",11, 16); // locking ImGui::SetCursorPos( ImVec2(preview_width + 20, pos.y + 2.f * ImGui::GetFrameHeightWithSpacing()) ); diff --git a/LayerView.cpp b/LayerView.cpp index 330b1a0..7800ef0 100644 --- a/LayerView.cpp +++ b/LayerView.cpp @@ -92,26 +92,53 @@ void LayerView::draw() } if (ImGui::BeginPopup("LayerSelectionContextMenu")) { + // colored context menu ImGui::PushStyleColor(ImGuiCol_Text, ImGuiToolkit::HighlightColor()); + ImGui::PushStyleColor(ImGuiCol_HeaderHovered, ImVec4(0.36f, 0.36f, 0.36f, 0.44f)); + + // special action of Mixing view if (candidate_flatten_group){ - if (ImGui::Selectable( ICON_FA_DOWNLOAD " Flatten" )){ + if (ImGui::Selectable( ICON_FA_DOWNLOAD " Flatten" )) Mixer::manager().groupSelection(); - } } else { ImGui::TextDisabled( ICON_FA_DOWNLOAD " Flatten" ); } - if (ImGui::Selectable( ICON_FA_ALIGN_CENTER " Distribute" )){ - SourceList::iterator it = Mixer::selection().begin(); + ImGui::Separator(); + + // manipulation of sources in Mixing view + if (ImGui::Selectable( ICON_FA_ALIGN_CENTER " Distribute" )){ + SourceList dsl = Mixer::selection().depthSortedList(); + SourceList::iterator it = dsl.begin(); float depth = (*it)->depth(); - float depth_inc = (Mixer::selection().back()->depth() - depth) / static_cast(Mixer::selection().size()-1); - for (it++; it != Mixer::selection().end(); it++) { + float depth_inc = (dsl.back()->depth() - depth) / static_cast(Mixer::selection().size()-1); + for (it++; it != dsl.end(); it++) { depth += depth_inc; (*it)->setDepth(depth); } View::need_deep_update_++; } - ImGui::PopStyleColor(); + if (ImGui::Selectable( ICON_FA_RULER_HORIZONTAL " Fix spacing" )){ + SourceList dsl = Mixer::selection().depthSortedList(); + SourceList::iterator it = dsl.begin(); + float depth = (*it)->depth(); + for (it++; it != dsl.end(); it++) { + depth += 2.f * LAYER_STEP; + (*it)->setDepth(depth); + } + View::need_deep_update_++; + } + if (ImGui::Selectable( ICON_FA_EXCHANGE_ALT " Inverse order" )){ + SourceList dsl = Mixer::selection().depthSortedList(); + SourceList::iterator it = dsl.begin(); + SourceList::reverse_iterator rit = dsl.rbegin(); + for (; it != dsl.end(); it++, rit++) { + (*it)->setDepth((*rit)->depth()); + } + View::need_deep_update_++; + } + + ImGui::PopStyleColor(2); ImGui::EndPopup(); } } @@ -198,6 +225,8 @@ std::pair LayerView::pick(glm::vec2 P) else if ( s->locked() && !UserInterface::manager().ctrlModifier() ) pick = { nullptr, glm::vec2(0.f) }; } + else + pick = { nullptr, glm::vec2(0.f) }; } return pick; @@ -293,3 +322,14 @@ void LayerView::arrow (glm::vec2 movement) } } + + +void LayerView::updateSelectionOverlay() +{ + View::updateSelectionOverlay(); + + if (overlay_selection_->visible_) { + // slightly extend the boundary of the selection + overlay_selection_frame_->scale_ = glm::vec3(1.f) + glm::vec3(0.07f, 0.07f, 1.f) / overlay_selection_->scale_; + } +} diff --git a/LayerView.h b/LayerView.h index 78572ec..74ebc59 100644 --- a/LayerView.h +++ b/LayerView.h @@ -21,6 +21,8 @@ public: float setDepth (Source *, float d = -1.f); private: + void updateSelectionOverlay() override; + float aspect_ratio; Mesh *persp_layer_; Mesh *persp_left_, *persp_right_; diff --git a/MixingView.cpp b/MixingView.cpp index 8afa105..525f8be 100644 --- a/MixingView.cpp +++ b/MixingView.cpp @@ -47,7 +47,7 @@ MixingView::MixingView() : View(MIXING), limbo_scale_(MIXING_LIMBO_SCALE) scene.bg()->attach(mixingCircle_); circle_ = new Mesh("mesh/circle.ply"); - circle_->shader()->color = glm::vec4( COLOR_CIRCLE, 0.9f ); + circle_->shader()->color = glm::vec4( COLOR_CIRCLE, 1.0f ); scene.bg()->attach(circle_); // Mixing scene foreground @@ -100,10 +100,10 @@ MixingView::MixingView() : View(MIXING), limbo_scale_(MIXING_LIMBO_SCALE) // points_.push_back(glm::vec2(0.f, 1.f)); // points_.push_back(glm::vec2(1.f, 1.f)); // points_.push_back(glm::vec2(1.f, 0.f)); -//// lines_ = new LineStrip(points_, 1.f); -// lines_ = new LineCircle(); +// lines_ = new LineStrip(points_, 1.f); // scene.fg()->attach(lines_); + lines_ = nullptr; } @@ -123,13 +123,31 @@ void MixingView::draw() } if (ImGui::BeginPopup("MixingSelectionContextMenu")) { + // colored context menu ImGui::PushStyleColor(ImGuiCol_Text, ImGuiToolkit::HighlightColor()); + ImGui::PushStyleColor(ImGuiCol_HeaderHovered, ImVec4(0.36f, 0.36f, 0.36f, 0.44f)); + // special action of Mixing view if (ImGui::Selectable( ICON_FA_DRAW_POLYGON " Link" )){ } + ImGui::Separator(); - ImGui::PopStyleColor(); + // manipulation of sources in Mixing view + if (ImGui::Selectable( ICON_FA_CROSSHAIRS " Center" )){ + SourceList::iterator it = Mixer::selection().begin(); + for (; it != Mixer::selection().end(); it++) { + (*it)->group(View::MIXING)->translation_ -= overlay_selection_->translation_; + (*it)->touch(); + } + } + if (ImGui::Selectable( ICON_FA_EXPAND_ARROWS_ALT " Expand to borders" )){ + SourceList::iterator it = Mixer::selection().begin(); + for (; it != Mixer::selection().end(); it++) { + (*it)->setAlpha(0.f); + } + } + ImGui::PopStyleColor(2); ImGui::EndPopup(); } } @@ -381,9 +399,9 @@ void MixingView::setAlpha(Source *s) glm::vec2 mix_pos = glm::vec2(DEFAULT_MIXING_TRANSLATION); for(NodeSet::iterator it = scene.ws()->begin(); it != scene.ws()->end(); it++) { - - if ( glm::distance(glm::vec2((*it)->translation_), mix_pos) < 0.001) { - mix_pos += glm::vec2(-0.03, 0.03); + // avoid superposing icons: distribute equally + if ( glm::distance(glm::vec2((*it)->translation_), mix_pos) < DELTA_ALPHA) { + mix_pos += glm::vec2(-0.03f, 0.03f); } } @@ -394,6 +412,29 @@ void MixingView::setAlpha(Source *s) s->touch(); } + +void MixingView::updateSelectionOverlay() +{ + View::updateSelectionOverlay(); + + if (overlay_selection_->visible_) { + // slightly extend the boundary of the selection + overlay_selection_frame_->scale_ = glm::vec3(1.f) + glm::vec3(0.01f, 0.01f, 1.f) / overlay_selection_->scale_; + +// if (lines_) { +// scene.fg()->detach(lines_); +// delete lines_; +// } + +// points_.push_back(glm::vec2(0.f, 0.f)); +// points_.push_back(glm::vec2(0.f, 1.f)); +// points_.push_back(glm::vec2(1.f, 1.f)); +// points_.push_back(glm::vec2(1.f, 0.f)); +// lines_ = new LineStrip(points_, 1.f); +// scene.fg()->attach(lines_); + } +} + #define CIRCLE_PIXELS 64 #define CIRCLE_PIXEL_RADIUS 1024.0 //#define CIRCLE_PIXELS 256 diff --git a/MixingView.h b/MixingView.h index fc1c44c..cceb545 100644 --- a/MixingView.h +++ b/MixingView.h @@ -36,6 +36,7 @@ private: // TEST std::vector points_; class LineStrip *lines_; + void updateSelectionOverlay() override; }; diff --git a/TextureView.cpp b/TextureView.cpp index 85a063e..cfd4bce 100644 --- a/TextureView.cpp +++ b/TextureView.cpp @@ -549,8 +549,8 @@ void TextureView::draw() ImGui::PushStyleColor(ImGuiCol_SliderGrabActive, ImVec4(0.95f, 0.95f, 0.95f, 1.00f)); ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0.00f, 0.00f, 0.00f, 0.00f)); ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4(0.24f, 0.24f, 0.24f, 0.46f)); - ImGui::PushStyleColor(ImGuiCol_Header, ImVec4(0.67f, 0.67f, 0.67f, 0.79f)); - ImGui::PushStyleColor(ImGuiCol_HeaderHovered, ImVec4(0.36f, 0.36f, 0.36f, 0.44f)); + ImGui::PushStyleColor(ImGuiCol_Header, ImVec4(0.36f, 0.36f, 0.36f, 0.9f)); + ImGui::PushStyleColor(ImGuiCol_HeaderHovered, ImVec4(0.36f, 0.36f, 0.36f, 0.5f)); ImGui::PushStyleColor(ImGuiCol_HeaderActive, ImVec4(0.88f, 0.88f, 0.88f, 0.73f)); ImGui::PushStyleColor(ImGuiCol_Tab, ImVec4(0.83f, 0.83f, 0.84f, 0.78f)); ImGui::PushStyleColor(ImGuiCol_TabHovered, ImVec4(0.53f, 0.53f, 0.53f, 0.60f)); @@ -824,6 +824,7 @@ void TextureView::draw() } if (ImGui::BeginPopup("AppearanceSourceContextMenu")) { ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(COLOR_APPEARANCE_SOURCE, 1.f)); + ImGui::PushStyleColor(ImGuiCol_HeaderHovered, ImVec4(0.36f, 0.36f, 0.36f, 0.44f)); Source *s = Mixer::manager().currentSource(); if (s != nullptr) { if (ImGui::Selectable( ICON_FA_VECTOR_SQUARE " Reset" )){ @@ -843,7 +844,7 @@ void TextureView::draw() s->touch(); } } - ImGui::PopStyleColor(); + ImGui::PopStyleColor(2); ImGui::EndPopup(); } diff --git a/View.cpp b/View.cpp index 0e1dfc5..fd0c7d8 100644 --- a/View.cpp +++ b/View.cpp @@ -252,7 +252,7 @@ void View::updateSelectionOverlay() overlay_selection_icon_ = new Handles(Handles::MENU); overlay_selection_->attach(overlay_selection_icon_); overlay_selection_frame_ = new Frame(Frame::SHARP, Frame::LARGE, Frame::NONE); - overlay_selection_frame_->scale_ = glm::vec3(1.05f, 1.05f, 1.f); +// overlay_selection_frame_->scale_ = glm::vec3(1.05f, 1.05f, 1.f); overlay_selection_->attach(overlay_selection_frame_); scene.fg()->attach(overlay_selection_); } @@ -277,7 +277,7 @@ void View::updateSelectionOverlay() // show group overlay overlay_selection_->visible_ = true; ImVec4 c = ImGuiToolkit::HighlightColor(); - overlay_selection_frame_->color = glm::vec4(c.x, c.y, c.z, c.w); + overlay_selection_frame_->color = glm::vec4(c.x, c.y, c.z, c.w * 0.8f); overlay_selection_icon_->color = glm::vec4(c.x, c.y, c.z, c.w); } // no selection: reset drawing selection overlay diff --git a/defines.h b/defines.h index 0afc909..b778d82 100644 --- a/defines.h +++ b/defines.h @@ -30,6 +30,7 @@ #define MIN_DEPTH 0.f #define MAX_DEPTH 12.f #define DELTA_DEPTH 0.05f +#define DELTA_ALPHA 0.0005f #define MIXING_DEFAULT_SCALE 2.4f #define MIXING_MIN_SCALE 0.8f #define MIXING_MAX_SCALE 7.0f @@ -90,7 +91,7 @@ #define COLOR_APPEARANCE_MASK_DISABLE 0.6f, 0.6f, 0.6f #define COLOR_FRAME 0.75f, 0.2f, 0.75f #define COLOR_FRAME_LIGHT 0.9f, 0.6f, 0.9f -#define COLOR_CIRCLE 0.25f, 0.65f, 0.7f +#define COLOR_CIRCLE 0.2f, 0.65f, 0.7f #define COLOR_CIRCLE_LIGHT 0.6f, 0.95f, 1.f #define COLOR_LIMBO_CIRCLE 0.16f, 0.16f, 0.16f #define COLOR_SLIDER_CIRCLE 0.11f, 0.11f, 0.11f