Cleanup UI - Filters menu, Save-as property

Cleanup code in ImGuiToolkit::IconButton
This commit is contained in:
Bruno Herbelin
2022-01-08 00:35:02 +01:00
parent fcad6766c3
commit 48df5c0eb1
3 changed files with 87 additions and 83 deletions

View File

@@ -208,14 +208,15 @@ bool ImGuiToolkit::ButtonIconToggle(int i, int j, int i_toggle, int j_toggle, bo
bool ImGuiToolkit::IconButton(int i, int j, const char *tooltip) bool ImGuiToolkit::IconButton(int i, int j, const char *tooltip)
{ {
ImGui::PushID( i * 20 + j );
ImGuiWindow* window = ImGui::GetCurrentWindow(); ImGuiWindow* window = ImGui::GetCurrentWindow();
if (window->SkipItems) if (window->SkipItems)
return false; return false;
ImGui::PushID( i * 20 + j );
// duplicate of ImGui::InvisibleButton to handle ImGuiButtonFlags_Repeat // duplicate of ImGui::InvisibleButton to handle ImGuiButtonFlags_Repeat
const ImGuiID id = window->GetID("##iconijbutton"); const ImGuiID id = window->GetID("##iconijbutton");
float h = ImGui::GetFrameHeight(); float h = ImGui::GetFrameHeight();
ImVec2 size = ImGui::CalcItemSize(ImVec2(h, h), 0.0f, 0.0f); ImVec2 size = ImGui::CalcItemSize(ImVec2(h, h), 0.0f, 0.0f);
ImVec2 draw_pos = window->DC.CursorPos; ImVec2 draw_pos = window->DC.CursorPos;
@@ -233,17 +234,17 @@ bool ImGuiToolkit::IconButton(int i, int j, const char *tooltip)
bool hovered, held; bool hovered, held;
bool pressed = ImGui::ButtonBehavior(bb, id, &hovered, &held, flags); bool pressed = ImGui::ButtonBehavior(bb, id, &hovered, &held, flags);
const ImVec4* colors = ImGui::GetStyle().Colors; if (tooltip != nullptr && hovered)
ImGuiToolkit::ToolTip(tooltip);
// draw with hovered color
ImGui::PushStyleColor( ImGuiCol_Text, hovered ? colors[ImGuiCol_NavWindowingHighlight] : colors[ImGuiCol_Text] );
ImGui::SetCursorScreenPos(draw_pos); ImGui::SetCursorScreenPos(draw_pos);
// draw icon with hovered color
const ImVec4* colors = ImGui::GetStyle().Colors;
ImGui::PushStyleColor( ImGuiCol_Text, hovered ? colors[ImGuiCol_NavWindowingHighlight] : colors[ImGuiCol_Text] );
Icon(i, j, !pressed); Icon(i, j, !pressed);
ImGui::PopStyleColor(); ImGui::PopStyleColor();
if (tooltip != nullptr && ImGui::IsItemHovered())
ImGuiToolkit::ToolTip(tooltip);
ImGui::PopID(); ImGui::PopID();
return pressed; return pressed;
} }
@@ -255,25 +256,23 @@ bool ImGuiToolkit::IconButton(const char* icon, const char *tooltip)
ImGui::PushID( icon ); ImGui::PushID( icon );
float frame_height = ImGui::GetFrameHeight(); float frame_height = ImGui::GetFrameHeight();
float frame_width = frame_height;
ImVec2 draw_pos = ImGui::GetCursorScreenPos(); ImVec2 draw_pos = ImGui::GetCursorScreenPos();
// toggle action : operate on the whole area // toggle action : operate on the whole area
ImGui::InvisibleButton("##iconcharbutton", ImVec2(frame_width, frame_height)); ImGui::InvisibleButton("##iconcharbutton", ImVec2(frame_height, frame_height));
if (ImGui::IsItemClicked()) if (ImGui::IsItemClicked())
ret = true; ret = true;
if (tooltip != nullptr && ImGui::IsItemHovered())
ImGuiToolkit::ToolTip(tooltip);
ImGui::SetCursorScreenPos(draw_pos);
// draw with hovered color // draw with hovered color
const ImVec4* colors = ImGui::GetStyle().Colors; const ImVec4* colors = ImGui::GetStyle().Colors;
ImGui::PushStyleColor( ImGuiCol_Text, ImGui::IsItemHovered() ? colors[ImGuiCol_NavWindowingHighlight] : colors[ImGuiCol_Text] ); ImGui::PushStyleColor( ImGuiCol_Text, ImGui::IsItemHovered() ? colors[ImGuiCol_NavWindowingHighlight] : colors[ImGuiCol_Text] );
ImGui::SetCursorScreenPos(draw_pos);
ImGui::Text(icon); ImGui::Text(icon);
ImGui::PopStyleColor(); ImGui::PopStyleColor();
if (tooltip != nullptr && ImGui::IsItemHovered())
ImGuiToolkit::ToolTip(tooltip);
ImGui::PopID(); ImGui::PopID();
return ret; return ret;
} }

View File

@@ -260,10 +260,6 @@ void ImGuiVisitor::visit(ImageProcessingShader &n)
{ {
ImGui::PushID(std::to_string(n.id()).c_str()); ImGui::PushID(std::to_string(n.id()).c_str());
// ImGuiToolkit::Icon(6, 2);
// ImGui::SameLine(0, IMGUI_SAME_LINE);
// ImGui::Text("Filters");
if (ImGuiToolkit::IconButton(6, 4)) { if (ImGuiToolkit::IconButton(6, 4)) {
n.gamma = glm::vec4(1.f, 1.f, 1.f, 1.f); n.gamma = glm::vec4(1.f, 1.f, 1.f, 1.f);
Action::manager().store("Gamma & Color"); Action::manager().store("Gamma & Color");
@@ -482,86 +478,89 @@ void ImGuiVisitor::visit (Source& s)
} }
} }
// toggle enable/disable image processing // Filter
bool on = s.imageProcessingEnabled(); bool on = s.imageProcessingEnabled();
ImGui::SetCursorPos( ImVec2( pos.x, pos.y + preview_height)); ImGui::SetCursorPos( ImVec2( pos.x, pos.y + preview_height));
if ( ImGuiToolkit::ButtonIconToggle(6, 2, 6, 2, &on) ){ if (on) {
std::ostringstream oss; ImGuiToolkit::Icon(6, 2); ImGui::SameLine(0, IMGUI_SAME_LINE); ImGui::Text("Filters");
oss << s.name() << ": " << ( on ? "Enable Filter" : "Disable Filter"); }
Action::manager().store(oss.str()); else {
ImGuiToolkit::Indication("Filters disabled", 6, 2);
ImGui::SameLine(0, IMGUI_SAME_LINE);ImGui::TextDisabled("Filters");
} }
s.setImageProcessingEnabled(on);
ImGui::SameLine(0, IMGUI_SAME_LINE);
ImGui::Text("Filters");
pos = ImGui::GetCursorPos(); pos = ImGui::GetCursorPos();
// image processing pannel // menu icon for image processing
if (s.imageProcessingEnabled()) { ImGui::SameLine(preview_width, 2 * IMGUI_SAME_LINE);
if (ImGuiToolkit::IconButton(5, 8))
ImGui::OpenPopup( "MenuImageProcessing" );
// menu icon for image processing if (ImGui::BeginPopup( "MenuImageProcessing" ))
ImGui::SameLine(preview_width, 2 * IMGUI_SAME_LINE); {
if (ImGuiToolkit::IconButton(5, 8)) if (ImGui::MenuItem("Enable", NULL, &on)) {
ImGui::OpenPopup( "MenuImageProcessing" ); std::ostringstream oss;
if (ImGui::BeginPopup( "MenuImageProcessing" )) oss << s.name() << ": " << ( on ? "Enable Filter" : "Disable Filter");
{ Action::manager().store(oss.str());
if (s.processingshader_link_.connected()) { s.setImageProcessingEnabled(on);
if (ImGui::MenuItem( "Unfollow" )){ }
s.processingshader_link_.disconnect();
} if (s.processingshader_link_.connected()) {
if (ImGui::MenuItem( "Unfollow", NULL, false, on)){
s.processingshader_link_.disconnect();
} }
else { }
if (ImGui::MenuItem("Reset" )){ else {
ImageProcessingShader defaultvalues; if (ImGui::MenuItem("Reset", NULL, false, on )){
s.processingShader()->copy(defaultvalues); ImageProcessingShader defaultvalues;
s.processingshader_link_.disconnect(); s.processingShader()->copy(defaultvalues);
std::ostringstream oss; s.processingshader_link_.disconnect();
oss << s.name() << ": " << "Reset Filter"; std::ostringstream oss;
Action::manager().store(oss.str()); oss << s.name() << ": " << "Reset Filter";
} Action::manager().store(oss.str());
if (ImGui::MenuItem("Copy" )){ }
std::string clipboard = SessionVisitor::getClipboard(s.processingShader()); if (ImGui::MenuItem("Copy", NULL, false, on )){
if (!clipboard.empty()) std::string clipboard = SessionVisitor::getClipboard(s.processingShader());
ImGui::SetClipboardText(clipboard.c_str()); if (!clipboard.empty())
} ImGui::SetClipboardText(clipboard.c_str());
const char *clipboard = ImGui::GetClipboardText(); }
const bool can_paste = (clipboard != nullptr && SessionLoader::isClipboard(clipboard)); const char *clipboard = ImGui::GetClipboardText();
if (ImGui::MenuItem("Paste", NULL, false, can_paste)) { const bool can_paste = (clipboard != nullptr && SessionLoader::isClipboard(clipboard));
SessionLoader::applyImageProcessing(s, clipboard); if (ImGui::MenuItem("Paste", NULL, false, can_paste)) {
std::ostringstream oss; SessionLoader::applyImageProcessing(s, clipboard);
oss << s.name() << ": " << "Change Filter"; std::ostringstream oss;
Action::manager().store(oss.str()); oss << s.name() << ": " << "Change Filter";
} Action::manager().store(oss.str());
// ImGui::Separator(); }
// if (ImGui::BeginMenu("Follow")) // // NON-stable style follow mechanism
// ImGui::Separator();
// if (ImGui::BeginMenu("Follow", on))
// {
// for (auto mpit = Mixer::manager().session()->begin();
// mpit != Mixer::manager().session()->end(); mpit++ )
// { // {
// for (auto mpit = Mixer::manager().session()->begin(); // std::string label = (*mpit)->name();
// mpit != Mixer::manager().session()->end(); mpit++ ) // if ( (*mpit)->id() != s.id() &&
// { // (*mpit)->imageProcessingEnabled() &&
// std::string label = (*mpit)->name(); // !(*mpit)->processingshader_link_.connected()) {
// if ( (*mpit)->id() != s.id() && // if (ImGui::MenuItem( label.c_str() )){
// (*mpit)->imageProcessingEnabled() && // s.processingshader_link_.connect(*mpit);
// !(*mpit)->processingshader_link_.connected()) { // s.touch();
// if (ImGui::MenuItem( label.c_str() )){
// s.processingshader_link_.connect(*mpit);
// s.touch();
// }
// } // }
// } // }
// ImGui::EndMenu();
// } // }
} // ImGui::EndMenu();
// }
ImGui::EndPopup();
} }
ImGui::EndPopup();
}
if (s.imageProcessingEnabled()) {
// full panel for image processing // full panel for image processing
ImGui::SetCursorPos( pos ); ImGui::SetCursorPos( pos );
if (s.processingshader_link_.connected()) { if (s.processingshader_link_.connected()) {
ImGuiToolkit::Icon(6, 2);
ImGui::SameLine(0, IMGUI_SAME_LINE);
ImGui::Text("Filters");
Source *target = s.processingshader_link_.source(); Source *target = s.processingshader_link_.source();
ImGui::Text("Following"); ImGui::Text("Following");
if ( target != nullptr && ImGui::Button(target->name().c_str(), ImVec2(IMGUI_RIGHT_ALIGN, 0)) ) if ( target != nullptr && ImGui::Button(target->name().c_str(), ImVec2(IMGUI_RIGHT_ALIGN, 0)) )

View File

@@ -5355,8 +5355,14 @@ void Navigator::RenderMainPannelVimix()
ImGui::InputText("Height", dummy_str, IM_ARRAYSIZE(dummy_str), ImGuiInputTextFlags_ReadOnly); ImGui::InputText("Height", dummy_str, IM_ARRAYSIZE(dummy_str), ImGuiInputTextFlags_ReadOnly);
ImGui::PopStyleColor(1); ImGui::PopStyleColor(1);
} }
// offer to change ratio and resolution // offer to change filename, ratio and resolution
else { else {
ImVec2 draw_pos = ImGui::GetCursorScreenPos();
ImGui::SameLine();
if ( ImGuiToolkit::IconButton(ICON_FA_FILE_DOWNLOAD, "Save as" )) {
UserInterface::manager().selectSaveFilename();
}
ImGui::SetCursorScreenPos(draw_pos);
// combo boxes to select Rario and Height // combo boxes to select Rario and Height
ImGui::SetNextItemWidth(IMGUI_RIGHT_ALIGN); ImGui::SetNextItemWidth(IMGUI_RIGHT_ALIGN);
if (ImGui::Combo("Ratio", &p.x, FrameBuffer::aspect_ratio_name, IM_ARRAYSIZE(FrameBuffer::aspect_ratio_name) ) ) if (ImGui::Combo("Ratio", &p.x, FrameBuffer::aspect_ratio_name, IM_ARRAYSIZE(FrameBuffer::aspect_ratio_name) ) )