Cleanup and unify views interface (combo)

This commit is contained in:
brunoherbelin
2021-02-28 10:18:10 +01:00
parent 7e723f4142
commit f2cd18f754
11 changed files with 126 additions and 43 deletions

View File

@@ -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<int, int> > 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();

View File

@@ -265,7 +265,7 @@ bool ImGuiToolkit::ButtonIconMultistate(std::vector<std::pair<int, int> > icons,
return ret;
}
bool ImGuiToolkit::ComboIcon (std::vector<std::pair<int, int> > icons, int* state)
bool ImGuiToolkit::ComboIcon (std::vector<std::pair<int, int> > icons, std::vector<std::string> 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<std::pair<int, int> > icons, int* stat
ImGui::SetNextItemWidth(w * 2.6f);
if (ImGui::BeginCombo("##ComboIcon", " ") )
{
std::vector<std::pair<int, int> >::iterator it = icons.begin();
for(int i = 0 ; it != icons.end(); i++, it++) {
std::vector<std::pair<int, int> >::iterator it_icon = icons.begin();
std::vector<std::string>::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();

View File

@@ -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<std::pair<int, int> > icons, int* state);
bool ComboIcon (std::vector<std::pair<int, int> > icons, int* state);
bool ComboIcon (std::vector<std::pair<int, int> > icons, std::vector<std::string> 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);

View File

@@ -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()) );

View File

@@ -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" );
}
ImGui::Separator();
// manipulation of sources in Mixing view
if (ImGui::Selectable( ICON_FA_ALIGN_CENTER " Distribute" )){
SourceList::iterator it = Mixer::selection().begin();
SourceList dsl = Mixer::selection().depthSortedList();
SourceList::iterator it = dsl.begin();
float depth = (*it)->depth();
float depth_inc = (Mixer::selection().back()->depth() - depth) / static_cast<float>(Mixer::selection().size()-1);
for (it++; it != Mixer::selection().end(); it++) {
float depth_inc = (dsl.back()->depth() - depth) / static_cast<float>(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<Node *, glm::vec2> 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_;
}
}

View File

@@ -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_;

View File

@@ -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

View File

@@ -36,6 +36,7 @@ private:
// TEST
std::vector<glm::vec2> points_;
class LineStrip *lines_;
void updateSelectionOverlay() override;
};

View File

@@ -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();
}

View File

@@ -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

View File

@@ -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