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

View file

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

View file

@ -21,9 +21,10 @@
//-----------------------------------------------------------------------------
#include "platform/platform.h"
#include "gui/shaderEditor/nodes/shaderNode.h"
#include "gui/core/guiCanvas.h"
IMPLEMENT_CONOBJECT(ShaderNode);
ConsoleDocClass(ShaderNode,
@ -35,6 +36,14 @@ ConsoleDocClass(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()
@ -66,6 +75,39 @@ bool ShaderNode::onAdd()
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)

View file

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