mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-01-19 20:24:49 +00:00
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:
parent
6e85b43088
commit
daa0cfef3a
|
|
@ -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));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -54,7 +54,6 @@ protected:
|
|||
|
||||
// Undo
|
||||
SimGroup* mTrash;
|
||||
SimSet* mSelectedSet;
|
||||
|
||||
// view controls
|
||||
Point2I mViewOffset;
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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_
|
||||
|
|
|
|||
|
|
@ -943,6 +943,16 @@ singleton GuiControlProfile( GuiBackFillProfile )
|
|||
category = "Editor";
|
||||
};
|
||||
|
||||
singleton GuiControlProfile(GuiShaderEditorProfile : ToolsGuiDefaultProfile)
|
||||
{
|
||||
opaque = true;
|
||||
};
|
||||
|
||||
singleton GuiControlProfile(ShaderNodeProfile : ToolsGuiDefaultProfile)
|
||||
{
|
||||
opaque = true;
|
||||
};
|
||||
|
||||
singleton GuiControlProfile( GuiControlListPopupProfile )
|
||||
{
|
||||
opaque = true;
|
||||
|
|
|
|||
|
|
@ -1,24 +1,24 @@
|
|||
//--- OBJECT WRITE BEGIN ---
|
||||
$guiContent = new GuiControl(ShaderEditorGui) {
|
||||
extent = "800 600";
|
||||
extent = "1280 720";
|
||||
profile = "GuiDefaultProfile";
|
||||
tooltipProfile = "ToolsGuiToolTipProfile";
|
||||
isContainer = "1";
|
||||
canSaveDynamicFields = "1";
|
||||
|
||||
new GuiFrameSetCtrl() {
|
||||
columns = "0 200 625";
|
||||
columns = "0 320 1000";
|
||||
borderWidth = "2";
|
||||
borderColor = "10 10 10 0";
|
||||
autoBalance = "1";
|
||||
extent = "800 600";
|
||||
extent = "1280 720";
|
||||
horizSizing = "width";
|
||||
vertSizing = "height";
|
||||
profile = "ToolsGuiFrameSetProfile";
|
||||
tooltipProfile = "ToolsGuiToolTipProfile";
|
||||
|
||||
new GuiControl() {
|
||||
extent = "198 600";
|
||||
extent = "318 720";
|
||||
horizSizing = "width";
|
||||
vertSizing = "height";
|
||||
profile = "ToolsGuiDefaultProfile";
|
||||
|
|
@ -28,7 +28,7 @@ $guiContent = new GuiControl(ShaderEditorGui) {
|
|||
new GuiSplitContainer() {
|
||||
orientation = "Horizontal";
|
||||
splitPoint = "0 200";
|
||||
extent = "197 600";
|
||||
extent = "317 720";
|
||||
horizSizing = "width";
|
||||
vertSizing = "height";
|
||||
profile = "ToolsGuiDefaultProfile";
|
||||
|
|
@ -36,7 +36,7 @@ $guiContent = new GuiControl(ShaderEditorGui) {
|
|||
|
||||
new GuiPanel(ShaderEditorPreview) {
|
||||
docking = "Client";
|
||||
extent = "197 198";
|
||||
extent = "317 198";
|
||||
profile = "ToolsGuiButtonProfile";
|
||||
tooltipProfile = "ToolsGuiToolTipProfile";
|
||||
internalName = "Panel1";
|
||||
|
|
@ -44,7 +44,7 @@ $guiContent = new GuiControl(ShaderEditorGui) {
|
|||
new GuiPanel(ShaderEditorInspector) {
|
||||
docking = "Client";
|
||||
position = "0 202";
|
||||
extent = "197 398";
|
||||
extent = "317 518";
|
||||
profile = "ToolsGuiButtonProfile";
|
||||
tooltipProfile = "ToolsGuiToolTipProfile";
|
||||
internalName = "panel2";
|
||||
|
|
@ -52,17 +52,25 @@ $guiContent = new GuiControl(ShaderEditorGui) {
|
|||
};
|
||||
};
|
||||
new GuiControl() {
|
||||
position = "200 0";
|
||||
extent = "423 600";
|
||||
position = "320 0";
|
||||
extent = "678 720";
|
||||
horizSizing = "width";
|
||||
vertSizing = "height";
|
||||
profile = "ToolsGuiButtonProfile";
|
||||
tooltipProfile = "ToolsGuiToolTipProfile";
|
||||
isContainer = "1";
|
||||
|
||||
new GuiShaderEditor(ShaderNodeGraph) {
|
||||
extent = "678 720";
|
||||
horizSizing = "width";
|
||||
vertSizing = "height";
|
||||
profile = "GuiShaderEditorProfile";
|
||||
tooltipProfile = "GuiToolTipProfile";
|
||||
};
|
||||
};
|
||||
new GuiControl(ShaderEditorSidebar) {
|
||||
position = "625 0";
|
||||
extent = "175 600";
|
||||
position = "1000 0";
|
||||
extent = "280 720";
|
||||
horizSizing = "width";
|
||||
vertSizing = "height";
|
||||
profile = "ToolsGuiDefaultProfile";
|
||||
|
|
@ -74,7 +82,7 @@ $guiContent = new GuiControl(ShaderEditorGui) {
|
|||
allowReorder = "1";
|
||||
selectedPage = "0";
|
||||
position = "3 5";
|
||||
extent = "166 400";
|
||||
extent = "271 520";
|
||||
horizSizing = "width";
|
||||
vertSizing = "height";
|
||||
profile = "ToolsGuiTabBookProfile";
|
||||
|
|
@ -84,7 +92,7 @@ $guiContent = new GuiControl(ShaderEditorGui) {
|
|||
fitBook = "1";
|
||||
text = "Library";
|
||||
position = "0 20";
|
||||
extent = "166 380";
|
||||
extent = "271 500";
|
||||
horizSizing = "width";
|
||||
vertSizing = "height";
|
||||
profile = "ToolsGuiTabPageProfile";
|
||||
|
|
@ -93,14 +101,14 @@ $guiContent = new GuiControl(ShaderEditorGui) {
|
|||
new GuiScrollCtrl() {
|
||||
hScrollBar = "dynamic";
|
||||
childMargin = "0 2";
|
||||
extent = "166 370";
|
||||
extent = "271 490";
|
||||
horizSizing = "width";
|
||||
vertSizing = "height";
|
||||
profile = "ToolsGuiScrollProfile";
|
||||
tooltipProfile = "ToolsGuiToolTipProfile";
|
||||
|
||||
new GuiStackControl(ShaderToolbox) {
|
||||
extent = "486 1000";
|
||||
extent = "591 1000";
|
||||
horizSizing = "width";
|
||||
profile = "ToolsGuiDefaultProfile";
|
||||
tooltipProfile = "ToolsGuiToolTipProfile";
|
||||
|
|
|
|||
Loading…
Reference in a new issue