shader node editor test

node editor functioning correctly, connections needed next
shader nodes to be added in the next commit also
This commit is contained in:
marauder2k7 2024-03-03 21:13:58 +00:00
parent 6e85b43088
commit daa0cfef3a
6 changed files with 136 additions and 62 deletions

View file

@ -55,7 +55,9 @@ GuiShaderEditor::GuiShaderEditor()
mMouseDownMode = GuiShaderEditor::Selecting; mMouseDownMode = GuiShaderEditor::Selecting;
mTrash = NULL; mTrash = NULL;
mSelectedSet = NULL;
// test
mCurrNodes.push_back(new ShaderNode());
} }
bool GuiShaderEditor::onWake() bool GuiShaderEditor::onWake()
@ -87,23 +89,31 @@ bool GuiShaderEditor::onAdd()
return false; return false;
mTrash = new SimGroup(); mTrash = new SimGroup();
mSelectedSet = new SimSet();
if (!mTrash->registerObject()) if (!mTrash->registerObject())
return false; return false;
if (!mSelectedSet->registerObject())
return false;
return true; return true;
} }
void GuiShaderEditor::onRemove() void GuiShaderEditor::onRemove()
{ {
Parent::onRemove();
mTrash->deleteObject(); mTrash->deleteObject();
mSelectedSet->deleteObject();
mTrash = NULL; mTrash = NULL;
mSelectedSet = NULL;
for (ShaderNode* node : mCurrNodes)
{
SAFE_DELETE(node);
}
for (ShaderNode* node : mSelectedNodes)
{
SAFE_DELETE(node);
}
} }
void GuiShaderEditor::onPreRender() void GuiShaderEditor::onPreRender()
@ -121,8 +131,7 @@ void GuiShaderEditor::renderNodes(Point2I offset, const RectI& updateRect)
// updateRect is the intersection rectangle in screen coords of the control // updateRect is the intersection rectangle in screen coords of the control
// hierarchy. This can be set as the clip rectangle in most cases. // hierarchy. This can be set as the clip rectangle in most cases.
RectI clipRect = updateRect; RectI clipRect = updateRect;
clipRect.inset(2, 2);
GFXDrawUtil* drawer = GFX->getDrawUtil();
for (ShaderNode* node : mCurrNodes) for (ShaderNode* node : mCurrNodes)
{ {
@ -130,20 +139,22 @@ void GuiShaderEditor::renderNodes(Point2I offset, const RectI& updateRect)
if (node->isVisible()) if (node->isVisible())
{ {
Point2I childPos = offset + node->getPosition(); Point2I childPos = offset + node->getPosition();
RectI childClip(childPos, node->getExtent() + Point2I(1, 1)); RectI childClip(childPos, node->getExtent() );
if (selectionContains(node))
{
node->mSelected = true;
}
else
{
node->mSelected = false;
}
if (childClip.intersect(clipRect)) if (childClip.intersect(clipRect))
{ {
GFX->setClipRect(childClip); GFX->setClipRect(childClip);
GFX->setStateBlock(mDefaultGuiSB); GFX->setStateBlock(mDefaultGuiSB);
node->onRender(offset, childClip); node->onRender(childPos, childClip);
}
if (selectionContains(node))
{
GFX->setClipRect(clipRect);
childClip.inset(1, 1);
drawer->drawRect(childClip, ColorI(255, 255, 0, 128));
} }
} }
} }
@ -155,7 +166,7 @@ void GuiShaderEditor::renderNodes(Point2I offset, const RectI& updateRect)
void GuiShaderEditor::onRender(Point2I offset, const RectI& updateRect) void GuiShaderEditor::onRender(Point2I offset, const RectI& updateRect)
{ {
offset += mViewOffset * mZoomScale; offset += mViewOffset;
GFXDrawUtil* drawer = GFX->getDrawUtil(); GFXDrawUtil* drawer = GFX->getDrawUtil();
@ -197,20 +208,20 @@ void GuiShaderEditor::onMouseDown(const GuiEvent& event)
mouseLock(); mouseLock();
// get mouse pos with our view offset and scale. // get mouse pos with our view offset and scale.
mLastMousePos = globalToLocalCoord(event.mousePoint) + mViewOffset * mZoomScale; mLastMousePos = globalToLocalCoord(event.mousePoint) - mViewOffset;
ShaderNode* node = findHitNode(mLastMousePos); ShaderNode* hitNode = findHitNode(mLastMousePos);
if (event.modifier & SI_SHIFT) if (event.modifier & SI_SHIFT)
{ {
startDragRectangle(mLastMousePos); startDragRectangle(mLastMousePos);
mDragAddSelection = true; mDragAddSelection = true;
} }
else if (selectionContains(node)) else if (selectionContains(hitNode))
{ {
if (event.modifier & SI_MULTISELECT) if (event.modifier & SI_MULTISELECT)
{ {
removeSelection(node); removeSelection(hitNode);
setMouseMode(Selecting); setMouseMode(Selecting);
} }
else if (event.modifier & SI_PRIMARY_ALT) else if (event.modifier & SI_PRIMARY_ALT)
@ -224,27 +235,27 @@ void GuiShaderEditor::onMouseDown(const GuiEvent& event)
} }
else else
{ {
if (node == NULL) if (hitNode == NULL)
{ {
startDragRectangle(mLastMousePos); startDragRectangle(mLastMousePos);
mDragAddSelection = false; mDragAddSelection = false;
} }
else if (event.modifier & SI_PRIMARY_ALT && node != NULL) else if (event.modifier & SI_PRIMARY_ALT && hitNode != NULL)
{ {
// Alt is down. Start a drag clone. // Alt is down. Start a drag clone.
clearSelection(); clearSelection();
addSelection(node); addSelection(hitNode);
startDragClone(mLastMousePos); startDragClone(mLastMousePos);
} }
else if (event.modifier & SI_MULTISELECT) else if (event.modifier & SI_MULTISELECT)
{ {
addSelection(node); addSelection(hitNode);
} }
else else
{ {
// Clicked on node. Start move. // Clicked on node. Start move.
clearSelection(); clearSelection();
addSelection(node); addSelection(hitNode);
startDragMove(mLastMousePos); startDragMove(mLastMousePos);
} }
} }
@ -259,8 +270,6 @@ void GuiShaderEditor::onMouseUp(const GuiEvent& event)
return; return;
} }
ShaderNode* node = findHitNode(mLastMousePos);
//unlock the mouse //unlock the mouse
mouseUnlock(); mouseUnlock();
@ -269,7 +278,7 @@ void GuiShaderEditor::onMouseUp(const GuiEvent& event)
mDragBeginPoints.clear(); mDragBeginPoints.clear();
// get mouse pos with our view offset and scale. // get mouse pos with our view offset and scale.
mLastMousePos = globalToLocalCoord(event.mousePoint) + mViewOffset * mZoomScale; mLastMousePos = globalToLocalCoord(event.mousePoint) - mViewOffset;
if (mMouseDownMode == DragSelecting) if (mMouseDownMode == DragSelecting)
{ {
@ -295,11 +304,6 @@ void GuiShaderEditor::onMouseUp(const GuiEvent& event)
} }
} }
if (mMouseDownMode == MovingSelection && mDragMoveUndo)
{
}
//reset the mouse mode //reset the mouse mode
setFirstResponder(); setFirstResponder();
setMouseMode(Selecting); setMouseMode(Selecting);
@ -314,7 +318,7 @@ void GuiShaderEditor::onMouseDragged(const GuiEvent& event)
} }
// get mouse pos with our view offset and scale. // get mouse pos with our view offset and scale.
Point2I mousePoint = globalToLocalCoord(event.mousePoint) + mViewOffset * mZoomScale; Point2I mousePoint = globalToLocalCoord(event.mousePoint) - mViewOffset;
if (mMouseDownMode == DragClone) if (mMouseDownMode == DragClone)
{ {
@ -360,7 +364,7 @@ void GuiShaderEditor::onMiddleMouseDown(const GuiEvent& event)
mouseLock(); mouseLock();
// get mouse pos with our view offset and scale. // get mouse pos with our view offset and scale.
mLastMousePos = globalToLocalCoord(event.mousePoint) + mViewOffset * mZoomScale; mLastMousePos = globalToLocalCoord(event.mousePoint);
setMouseMode(DragPanning); setMouseMode(DragPanning);
@ -382,7 +386,7 @@ void GuiShaderEditor::onMiddleMouseUp(const GuiEvent& event)
mDragBeginPoints.clear(); mDragBeginPoints.clear();
// get mouse pos with our view offset and scale. // get mouse pos with our view offset and scale.
mLastMousePos = globalToLocalCoord(event.mousePoint) + mViewOffset * mZoomScale; mLastMousePos = globalToLocalCoord(event.mousePoint);
setFirstResponder(); setFirstResponder();
setMouseMode(Selecting); setMouseMode(Selecting);
@ -397,13 +401,11 @@ void GuiShaderEditor::onMiddleMouseDragged(const GuiEvent& event)
} }
// get mouse pos with our view offset and scale. // get mouse pos with our view offset and scale.
Point2I mousePoint = globalToLocalCoord(event.mousePoint) + mViewOffset * mZoomScale; Point2I mousePoint = globalToLocalCoord(event.mousePoint);
if (mMouseDownMode == DragPanning) if (mMouseDownMode == DragPanning)
{ {
Point2I delta = mousePoint - mLastMousePos; Point2I delta = mousePoint - mLastMousePos;
RectI selBounds = getSelectionBounds();
// invert it // invert it
if (delta.x || delta.y) if (delta.x || delta.y)
mViewOffset += -delta; mViewOffset += -delta;
@ -439,12 +441,12 @@ RectI GuiShaderEditor::getSelectionBounds()
Vector<ShaderNode*>::const_iterator i = mSelectedNodes.begin(); Vector<ShaderNode*>::const_iterator i = mSelectedNodes.begin();
Point2I minPos = (*i)->localToGlobalCoord(Point2I(0, 0)) + mViewOffset * mZoomScale; Point2I minPos = (*i)->localToGlobalCoord(Point2I(0, 0));
Point2I maxPos = minPos; Point2I maxPos = minPos;
for (; i != mSelectedNodes.end(); i++) for (; i != mSelectedNodes.end(); i++)
{ {
Point2I iPos = (**i).localToGlobalCoord(Point2I(0, 0)) + mViewOffset * mZoomScale; Point2I iPos = (**i).localToGlobalCoord(Point2I(0, 0));
minPos.x = getMin(iPos.x, minPos.x); minPos.x = getMin(iPos.x, minPos.x);
minPos.y = getMin(iPos.y, minPos.y); minPos.y = getMin(iPos.y, minPos.y);
@ -458,8 +460,8 @@ RectI GuiShaderEditor::getSelectionBounds()
maxPos.y = getMax(iPos.y, maxPos.y); maxPos.y = getMax(iPos.y, maxPos.y);
} }
minPos = globalToLocalCoord(minPos) + mViewOffset * mZoomScale; minPos = globalToLocalCoord(minPos);
maxPos = globalToLocalCoord(maxPos) + mViewOffset * mZoomScale; maxPos = globalToLocalCoord(maxPos);
return RectI(minPos.x, minPos.y, (maxPos.x - minPos.x), (maxPos.y - minPos.y)); return RectI(minPos.x, minPos.y, (maxPos.x - minPos.x), (maxPos.y - minPos.y));
} }

View file

@ -54,7 +54,6 @@ protected:
// Undo // Undo
SimGroup* mTrash; SimGroup* mTrash;
SimSet* mSelectedSet;
// view controls // view controls
Point2I mViewOffset; Point2I mViewOffset;

View file

@ -21,9 +21,10 @@
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
#include "platform/platform.h" #include "platform/platform.h"
#include "gui/shaderEditor/nodes/shaderNode.h" #include "gui/shaderEditor/nodes/shaderNode.h"
#include "gui/core/guiCanvas.h"
IMPLEMENT_CONOBJECT(ShaderNode); IMPLEMENT_CONOBJECT(ShaderNode);
ConsoleDocClass(ShaderNode, ConsoleDocClass(ShaderNode,
@ -35,6 +36,14 @@ ConsoleDocClass(ShaderNode,
ShaderNode::ShaderNode() ShaderNode::ShaderNode()
{ {
mTitle = "Default Node";
mSelected = false;
// fixed extent for all nodes, only height should be changed
setExtent(150, 100);
GuiControlProfile* profile = NULL;
if (Sim::findObject("ToolsGuiDefaultProfile", profile))
setControlProfile(profile);
} }
bool ShaderNode::onWake() bool ShaderNode::onWake()
@ -66,6 +75,39 @@ bool ShaderNode::onAdd()
void ShaderNode::onRemove() void ShaderNode::onRemove()
{ {
Parent::onRemove();
}
void ShaderNode::onRender(Point2I offset, const RectI& updateRect)
{
if (!mProfile)
return Parent::onRender(offset, updateRect);
GFXDrawUtil* drawer = GFX->getDrawUtil();
// Get our rect.
RectI winRect;
winRect.point = offset;
winRect.extent = getExtent();
// draw background.
drawer->drawRectFill(winRect, mProfile->mFillColor);
// draw header text.
U32 strWidth = mProfile->mFont->getStrWidth(mTitle.c_str());
Point2I headerPos = Point2I((getExtent().x / 2) - (strWidth / 2), (30 / 2) - (mProfile->mFont->getFontSize() / 2));
drawer->setBitmapModulation(mProfile->mFontColor);
drawer->drawText(mProfile->mFont, headerPos + offset, mTitle);
drawer->clearBitmapModulation();
ColorI border(128, 128, 128, 128);
if (mSelected)
border = ColorI(128, 0, 128, 128);
winRect.inset(1, 1);
drawer->drawRect(winRect, border);
} }
void ShaderNode::write(Stream& stream, U32 tabStop, U32 flags) void ShaderNode::write(Stream& stream, U32 tabStop, U32 flags)

View file

@ -31,8 +31,14 @@
#include "console/simBase.h" #include "console/simBase.h"
#endif #endif
#ifndef _GFX_GFXDRAWER_H_
#include "gfx/gfxDrawUtil.h"
#endif
enum class NodeTypes enum class NodeTypes
{ {
Default,
Uniform, Uniform,
Input, Input,
Output, Output,
@ -69,6 +75,9 @@ class ShaderNode : public GuiControl
private: private:
typedef GuiControl Parent; typedef GuiControl Parent;
protected:
String mTitle;
public: public:
ShaderNode(); ShaderNode();
@ -78,6 +87,8 @@ public:
virtual bool onAdd() override; virtual bool onAdd() override;
virtual void onRemove() override; virtual void onRemove() override;
virtual void onRender(Point2I offset, const RectI& updateRect) override;
// Serialization functions // Serialization functions
void write(Stream& stream, U32 tabStop = 0, U32 flags = 0); void write(Stream& stream, U32 tabStop = 0, U32 flags = 0);
void read(Stream& stream); void read(Stream& stream);
@ -86,5 +97,7 @@ public:
DECLARE_CONOBJECT(ShaderNode); DECLARE_CONOBJECT(ShaderNode);
DECLARE_CATEGORY("Shader Core"); DECLARE_CATEGORY("Shader Core");
DECLARE_DESCRIPTION("Base class for all shader nodes."); DECLARE_DESCRIPTION("Base class for all shader nodes.");
bool mSelected;
}; };
#endif // !_SHADERNODE_H_ #endif // !_SHADERNODE_H_

View file

@ -943,6 +943,16 @@ singleton GuiControlProfile( GuiBackFillProfile )
category = "Editor"; category = "Editor";
}; };
singleton GuiControlProfile(GuiShaderEditorProfile : ToolsGuiDefaultProfile)
{
opaque = true;
};
singleton GuiControlProfile(ShaderNodeProfile : ToolsGuiDefaultProfile)
{
opaque = true;
};
singleton GuiControlProfile( GuiControlListPopupProfile ) singleton GuiControlProfile( GuiControlListPopupProfile )
{ {
opaque = true; opaque = true;

View file

@ -1,24 +1,24 @@
//--- OBJECT WRITE BEGIN --- //--- OBJECT WRITE BEGIN ---
$guiContent = new GuiControl(ShaderEditorGui) { $guiContent = new GuiControl(ShaderEditorGui) {
extent = "800 600"; extent = "1280 720";
profile = "GuiDefaultProfile"; profile = "GuiDefaultProfile";
tooltipProfile = "ToolsGuiToolTipProfile"; tooltipProfile = "ToolsGuiToolTipProfile";
isContainer = "1"; isContainer = "1";
canSaveDynamicFields = "1"; canSaveDynamicFields = "1";
new GuiFrameSetCtrl() { new GuiFrameSetCtrl() {
columns = "0 200 625"; columns = "0 320 1000";
borderWidth = "2"; borderWidth = "2";
borderColor = "10 10 10 0"; borderColor = "10 10 10 0";
autoBalance = "1"; autoBalance = "1";
extent = "800 600"; extent = "1280 720";
horizSizing = "width"; horizSizing = "width";
vertSizing = "height"; vertSizing = "height";
profile = "ToolsGuiFrameSetProfile"; profile = "ToolsGuiFrameSetProfile";
tooltipProfile = "ToolsGuiToolTipProfile"; tooltipProfile = "ToolsGuiToolTipProfile";
new GuiControl() { new GuiControl() {
extent = "198 600"; extent = "318 720";
horizSizing = "width"; horizSizing = "width";
vertSizing = "height"; vertSizing = "height";
profile = "ToolsGuiDefaultProfile"; profile = "ToolsGuiDefaultProfile";
@ -28,7 +28,7 @@ $guiContent = new GuiControl(ShaderEditorGui) {
new GuiSplitContainer() { new GuiSplitContainer() {
orientation = "Horizontal"; orientation = "Horizontal";
splitPoint = "0 200"; splitPoint = "0 200";
extent = "197 600"; extent = "317 720";
horizSizing = "width"; horizSizing = "width";
vertSizing = "height"; vertSizing = "height";
profile = "ToolsGuiDefaultProfile"; profile = "ToolsGuiDefaultProfile";
@ -36,7 +36,7 @@ $guiContent = new GuiControl(ShaderEditorGui) {
new GuiPanel(ShaderEditorPreview) { new GuiPanel(ShaderEditorPreview) {
docking = "Client"; docking = "Client";
extent = "197 198"; extent = "317 198";
profile = "ToolsGuiButtonProfile"; profile = "ToolsGuiButtonProfile";
tooltipProfile = "ToolsGuiToolTipProfile"; tooltipProfile = "ToolsGuiToolTipProfile";
internalName = "Panel1"; internalName = "Panel1";
@ -44,7 +44,7 @@ $guiContent = new GuiControl(ShaderEditorGui) {
new GuiPanel(ShaderEditorInspector) { new GuiPanel(ShaderEditorInspector) {
docking = "Client"; docking = "Client";
position = "0 202"; position = "0 202";
extent = "197 398"; extent = "317 518";
profile = "ToolsGuiButtonProfile"; profile = "ToolsGuiButtonProfile";
tooltipProfile = "ToolsGuiToolTipProfile"; tooltipProfile = "ToolsGuiToolTipProfile";
internalName = "panel2"; internalName = "panel2";
@ -52,17 +52,25 @@ $guiContent = new GuiControl(ShaderEditorGui) {
}; };
}; };
new GuiControl() { new GuiControl() {
position = "200 0"; position = "320 0";
extent = "423 600"; extent = "678 720";
horizSizing = "width"; horizSizing = "width";
vertSizing = "height"; vertSizing = "height";
profile = "ToolsGuiButtonProfile"; profile = "ToolsGuiButtonProfile";
tooltipProfile = "ToolsGuiToolTipProfile"; tooltipProfile = "ToolsGuiToolTipProfile";
isContainer = "1"; isContainer = "1";
new GuiShaderEditor(ShaderNodeGraph) {
extent = "678 720";
horizSizing = "width";
vertSizing = "height";
profile = "GuiShaderEditorProfile";
tooltipProfile = "GuiToolTipProfile";
};
}; };
new GuiControl(ShaderEditorSidebar) { new GuiControl(ShaderEditorSidebar) {
position = "625 0"; position = "1000 0";
extent = "175 600"; extent = "280 720";
horizSizing = "width"; horizSizing = "width";
vertSizing = "height"; vertSizing = "height";
profile = "ToolsGuiDefaultProfile"; profile = "ToolsGuiDefaultProfile";
@ -74,7 +82,7 @@ $guiContent = new GuiControl(ShaderEditorGui) {
allowReorder = "1"; allowReorder = "1";
selectedPage = "0"; selectedPage = "0";
position = "3 5"; position = "3 5";
extent = "166 400"; extent = "271 520";
horizSizing = "width"; horizSizing = "width";
vertSizing = "height"; vertSizing = "height";
profile = "ToolsGuiTabBookProfile"; profile = "ToolsGuiTabBookProfile";
@ -84,7 +92,7 @@ $guiContent = new GuiControl(ShaderEditorGui) {
fitBook = "1"; fitBook = "1";
text = "Library"; text = "Library";
position = "0 20"; position = "0 20";
extent = "166 380"; extent = "271 500";
horizSizing = "width"; horizSizing = "width";
vertSizing = "height"; vertSizing = "height";
profile = "ToolsGuiTabPageProfile"; profile = "ToolsGuiTabPageProfile";
@ -93,14 +101,14 @@ $guiContent = new GuiControl(ShaderEditorGui) {
new GuiScrollCtrl() { new GuiScrollCtrl() {
hScrollBar = "dynamic"; hScrollBar = "dynamic";
childMargin = "0 2"; childMargin = "0 2";
extent = "166 370"; extent = "271 490";
horizSizing = "width"; horizSizing = "width";
vertSizing = "height"; vertSizing = "height";
profile = "ToolsGuiScrollProfile"; profile = "ToolsGuiScrollProfile";
tooltipProfile = "ToolsGuiToolTipProfile"; tooltipProfile = "ToolsGuiToolTipProfile";
new GuiStackControl(ShaderToolbox) { new GuiStackControl(ShaderToolbox) {
extent = "486 1000"; extent = "591 1000";
horizSizing = "width"; horizSizing = "width";
profile = "ToolsGuiDefaultProfile"; profile = "ToolsGuiDefaultProfile";
tooltipProfile = "ToolsGuiToolTipProfile"; tooltipProfile = "ToolsGuiToolTipProfile";