Improv Shader Editor UI and clone create

This commit is contained in:
Bruno Herbelin
2024-05-30 23:12:59 +02:00
parent 81a0a724ab
commit 7092de8809
7 changed files with 40 additions and 19 deletions

Binary file not shown.

View File

@@ -272,7 +272,7 @@ void ImageFilteringShader::setCode(const std::string &code, std::promise<std::st
custom_shading_.setShaders("shaders/image.vs", shader_code_, (int)n, ret);
}
else if (ret != nullptr) {
ret->set_value("No change.");
ret->set_value("No change");
}
}

View File

@@ -465,10 +465,10 @@ Source * Mixer::createSourceGroup()
return s;
}
Source * Mixer::createSourceClone(const std::string &namesource, bool copy_attributes)
CloneSource * Mixer::createSourceClone(const std::string &namesource, bool copy_attributes)
{
// ready to create a source
Source *s = nullptr;
CloneSource *s = nullptr;
// origin to clone is either the given name or the current
SourceList::iterator origin = session_->end();

View File

@@ -50,7 +50,7 @@ public:
// creation of sources
Source * createSourceFile (const std::string &path, bool disable_hw_decoding = false);
Source * createSourceMultifile(const std::list<std::string> &list_files, uint fps);
Source * createSourceClone (const std::string &namesource = "", bool copy_attributes = true);
class CloneSource *createSourceClone(const std::string &namesource = "", bool copy_attributes = true);
Source * createSourceRender ();
Source * createSourceStream (const std::string &gstreamerpipeline);
Source * createSourcePattern(uint pattern, glm::ivec2 res);

View File

@@ -18,6 +18,7 @@ TextEditor _editor;
#include "SystemToolkit.h"
#include "CloneSource.h"
#include "DialogToolkit.h"
#include "UserInterfaceManager.h"
#include "ShaderEditWindow.h"
@@ -141,6 +142,8 @@ void ShaderEditWindow::Render()
return;
}
Source *cs = Mixer::manager().currentSource();
// menu (no title bar)
if (ImGui::BeginMenuBar())
{
@@ -149,6 +152,16 @@ void ShaderEditWindow::Render()
Settings::application.widget.shader_editor = false;
if (ImGui::BeginMenu(IMGUI_TITLE_SHADEREDITOR))
{
// Menu entry to allow creating a custom filter
if (ImGui::MenuItem(ICON_FA_SHARE_SQUARE " Clone source & add filter",
nullptr, nullptr, cs != nullptr)) {
CloneSource *filteredclone = Mixer::manager().createSourceClone();
filteredclone->setFilter(FrameBufferFilter::FILTER_IMAGE);
Mixer::manager().addSource ( filteredclone );
UserInterface::manager().showPannel( Mixer::manager().numSource() );
}
ImGui::Separator();
// reload code from GPU
if (ImGui::MenuItem( ICON_FA_REDO_ALT " Reload", nullptr, nullptr, current_ != nullptr)) {
// force reload
@@ -189,13 +202,6 @@ void ShaderEditWindow::Render()
if (ImGui::MenuItem( ICON_FA_EXTERNAL_LINK_ALT " Browse shadertoy.com"))
SystemToolkit::open("https://www.shadertoy.com/");
// Enable/Disable editor options
ImGui::Separator();
ImGui::MenuItem( ICON_FA_UNDERLINE " Show Shader Inputs", nullptr, &show_shader_inputs_);
bool ws = _editor.IsShowingWhitespaces();
if (ImGui::MenuItem( ICON_FA_ELLIPSIS_H " Show whitespace", nullptr, &ws))
_editor.SetShowWhitespaces(ws);
// output manager menu
ImGui::Separator();
bool pinned = Settings::application.widget.shader_editor_view == Settings::application.current_view;
@@ -231,6 +237,13 @@ void ShaderEditWindow::Render()
if (ImGui::MenuItem( MENU_SELECTALL, SHORTCUT_SELECTALL, nullptr, _editor.GetText().size() > 1 ))
_editor.SetSelection(TextEditor::Coordinates(), TextEditor::Coordinates(_editor.GetTotalLines(), 0));
// Enable/Disable editor options
ImGui::Separator();
ImGui::MenuItem( ICON_FA_UNDERLINE " Show Shader Inputs", nullptr, &show_shader_inputs_);
bool ws = _editor.IsShowingWhitespaces();
if (ImGui::MenuItem( ICON_FA_ELLIPSIS_H " Show whitespace", nullptr, &ws))
_editor.SetShowWhitespaces(ws);
ImGui::EndMenu();
}
@@ -301,11 +314,9 @@ void ShaderEditWindow::Render()
else {
ImageFilter *i = nullptr;
// get current clone source
Source *s = Mixer::manager().currentSource();
// if there is a current source
if (s != nullptr) {
CloneSource *c = dynamic_cast<CloneSource *>(s);
if (cs != nullptr) {
CloneSource *c = dynamic_cast<CloneSource *>(cs);
// if the current source is a clone
if ( c != nullptr ) {
FrameBufferFilter *f = c->filter();
@@ -325,6 +336,7 @@ void ShaderEditWindow::Render()
if (i == nullptr) {
status_ = "-";
_editor.SetText("");
_editor.SetReadOnly(true);
current_ = nullptr;
}
}
@@ -347,10 +359,13 @@ void ShaderEditWindow::Render()
_editor.SetText( filters_[i].code().first );
_editor.SetReadOnly(false);
_editor.SetColorizerEnable(true);
status_ = "Ready.";
status_ = "Ready";
}
// cancel edit clone
else {
// possibility that source was removed
g_printerr("cancel edit clone %ld\n", current_);
// disable editor
_editor.SetReadOnly(true);
_editor.SetColorizerEnable(false);

View File

@@ -1122,6 +1122,9 @@ void UserInterface::showMenuWindows()
if ( ImGui::MenuItem( MENU_INPUTS, SHORTCUT_INPUTS, &Settings::application.widget.inputs) )
UserInterface::manager().inputscontrol.setVisible(Settings::application.widget.inputs);
if ( ImGui::MenuItem( MENU_SHADEREDITOR, SHORTCUT_SHADEREDITOR, &Settings::application.widget.shader_editor) )
UserInterface::manager().shadercontrol.setVisible(Settings::application.widget.shader_editor);
// Show Help
ImGui::MenuItem( MENU_HELP, SHORTCUT_HELP, &Settings::application.widget.help );
// Show Logs
@@ -3558,8 +3561,10 @@ void Navigator::RenderSourcePannel(Source *s, const ImVec2 &iconsize)
if ( s->failed() ) {
ImGuiToolkit::ButtonDisabled( ICON_FA_SHARE_SQUARE " Clone & Filter", ImVec2(ImGui::GetContentRegionAvail().x, 0));
}
else if ( ImGui::Button( ICON_FA_SHARE_SQUARE " Clone & Filter", ImVec2(ImGui::GetContentRegionAvail().x, 0)) )
Mixer::manager().addSource ( Mixer::manager().createSourceClone() );
else if ( ImGui::Button( ICON_FA_SHARE_SQUARE " Clone & Filter", ImVec2(ImGui::GetContentRegionAvail().x, 0)) ) {
Mixer::manager().addSource ( (Source *) Mixer::manager().createSourceClone() );
UserInterface::manager().showPannel( Mixer::manager().numSource() );
}
// replace button
if ( ImGui::Button( ICON_FA_PLUS_SQUARE " Replace", ImVec2(ImGui::GetContentRegionAvail().x, 0)) ) {

View File

@@ -232,9 +232,10 @@
#define MENU_TIMER ICON_FA_CLOCK " Timer "
#define TOOLTIP_TIMER "Timer "
#define SHORTCUT_TIMER CTRL_MOD "T"
#define MENU_INPUTS ICON_FA_HAND_PAPER " Inputs mapping "
#define MENU_INPUTS ICON_FA_HAND_PAPER " Input mapping "
#define TOOLTIP_INPUTS "Inputs mapping "
#define SHORTCUT_INPUTS CTRL_MOD "I"
#define MENU_SHADEREDITOR ICON_FA_CODE " Shader Editor "
#define TOOLTIP_SHADEREDITOR "Shader Editor "
#define SHORTCUT_SHADEREDITOR CTRL_MOD "E"
#define TOOLTIP_FULLSCREEN "Fullscreen "