ShaderNode: Add possibility to set variable name (+ force variables)
This commit is contained in:
@@ -4,5 +4,6 @@ inline FragmentOutput::FragmentOutput(ShaderGraph& graph) :
|
||||
ShaderNode(graph)
|
||||
{
|
||||
SetPreviewSize({ 128, 128 });
|
||||
DisableCustomVariableName();
|
||||
EnablePreview(true);
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ ShaderNode(graph)
|
||||
m_currentInputText = firstInput.name;
|
||||
}
|
||||
|
||||
DisableCustomVariableName();
|
||||
UpdatePreview();
|
||||
}
|
||||
|
||||
|
||||
@@ -3,12 +3,13 @@
|
||||
#include <QtWidgets/QComboBox>
|
||||
#include <QtWidgets/QFormLayout>
|
||||
#include <QtWidgets/QLabel>
|
||||
#include <QtWidgets/QLineEdit>
|
||||
|
||||
ShaderNode::ShaderNode(ShaderGraph& graph) :
|
||||
m_previewSize(64, 64),
|
||||
m_pixmapLabel(nullptr),
|
||||
m_graph(graph),
|
||||
m_forceVariable(false),
|
||||
m_enableCustomVariableName(true),
|
||||
m_isPreviewEnabled(false)
|
||||
{
|
||||
m_pixmapLabel = new QLabel;
|
||||
@@ -51,6 +52,16 @@ void ShaderNode::BuildNodeEdition(QFormLayout* layout)
|
||||
});
|
||||
|
||||
layout->addRow(tr("Preview size"), previewSize);
|
||||
|
||||
if (m_enableCustomVariableName)
|
||||
{
|
||||
QLineEdit* lineEdit = new QLineEdit(QString::fromStdString(m_variableName));
|
||||
connect(lineEdit, &QLineEdit::textChanged, [&](const QString& text)
|
||||
{
|
||||
SetVariableName(text.toStdString());
|
||||
});
|
||||
layout->addRow(tr("Variable name"), lineEdit);
|
||||
}
|
||||
}
|
||||
|
||||
void ShaderNode::EnablePreview(bool enable)
|
||||
|
||||
@@ -27,13 +27,16 @@ class ShaderNode : public QtNodes::NodeDataModel
|
||||
inline const ShaderGraph& GetGraph() const;
|
||||
inline const std::string& GetVariableName() const;
|
||||
|
||||
void SetPreviewSize(const Nz::Vector2i& size);
|
||||
inline void SetPreviewSize(const Nz::Vector2i& size);
|
||||
inline void SetVariableName(std::string variableName);
|
||||
|
||||
QWidget* embeddedWidget() final;
|
||||
|
||||
void setInData(std::shared_ptr<QtNodes::NodeData>, int) override;
|
||||
|
||||
protected:
|
||||
inline void DisableCustomVariableName();
|
||||
inline void EnableCustomVariableName(bool enable = true);
|
||||
void UpdatePreview();
|
||||
|
||||
private:
|
||||
@@ -44,7 +47,7 @@ class ShaderNode : public QtNodes::NodeDataModel
|
||||
std::optional<QPixmap> m_pixmap;
|
||||
std::string m_variableName;
|
||||
ShaderGraph& m_graph;
|
||||
bool m_forceVariable;
|
||||
bool m_enableCustomVariableName;
|
||||
bool m_isPreviewEnabled;
|
||||
};
|
||||
|
||||
|
||||
@@ -24,3 +24,20 @@ inline void ShaderNode::SetPreviewSize(const Nz::Vector2i& size)
|
||||
embeddedWidgetSizeUpdated();
|
||||
}
|
||||
}
|
||||
|
||||
inline void ShaderNode::SetVariableName(std::string variableName)
|
||||
{
|
||||
m_variableName = std::move(variableName);
|
||||
}
|
||||
|
||||
inline void ShaderNode::DisableCustomVariableName()
|
||||
{
|
||||
return EnableCustomVariableName(false);
|
||||
}
|
||||
|
||||
inline void ShaderNode::EnableCustomVariableName(bool enable)
|
||||
{
|
||||
m_enableCustomVariableName = enable;
|
||||
if (!m_enableCustomVariableName)
|
||||
m_variableName.clear();
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ ShaderNode(graph)
|
||||
m_currentTextureText = firstInput.name;
|
||||
}
|
||||
|
||||
DisableCustomVariableName();
|
||||
EnablePreview(true);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user