Skip to content

Commit

Permalink
Traktor: Able inline edit swizzle and variable nodes.
Browse files Browse the repository at this point in the history
  • Loading branch information
apistol78 committed May 27, 2024
1 parent 430678c commit 18f83e5
Show file tree
Hide file tree
Showing 6 changed files with 128 additions and 35 deletions.
4 changes: 2 additions & 2 deletions code/Render/Editor/Shader/Facades/CommentNodeFacade.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,11 @@
#include "Render/Editor/Node.h"
#include "Render/Editor/Shader/Facades/CommentNodeFacade.h"
#include "Ui/Application.h"
#include "Ui/Edit.h"
#include "Ui/Graph/GraphControl.h"
#include "Ui/Graph/Node.h"
#include "Ui/Graph/CommentNodeShape.h"

#include "Ui/Edit.h"

namespace traktor::render
{

Expand Down Expand Up @@ -105,6 +104,7 @@ void CommentNodeFacade::editShaderNode(
m_edit->setText(shaderNode->getComment());
m_edit->setRect(rcEdit);
m_edit->setVisible(true);
m_edit->selectAll();
m_edit->setFocus();
}

Expand Down
60 changes: 52 additions & 8 deletions code/Render/Editor/Shader/Facades/SwizzleNodeFacade.cpp
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
/*
* TRAKTOR
* Copyright (c) 2022 Anders Pistol.
* Copyright (c) 2022-2024 Anders Pistol.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
#include "Render/Editor/InputPin.h"
#include "Render/Editor/Node.h"
#include "Render/Editor/OutputPin.h"
#include "Render/Editor/Shader/Nodes.h"
#include "Render/Editor/Shader/Facades/SwizzleNodeFacade.h"
#include "Ui/Application.h"
#include "Ui/Edit.h"
#include "Ui/Graph/GraphControl.h"
#include "Ui/Graph/Node.h"
#include "Ui/Graph/InOutNodeShape.h"

namespace traktor
namespace traktor::render
{
namespace render
{

T_IMPLEMENT_RTTI_CLASS(L"traktor.render.SwizzleNodeFacade", SwizzleNodeFacade, INodeFacade)

Expand Down Expand Up @@ -52,7 +51,7 @@ Ref< ui::Node > SwizzleNodeFacade::createEditorNode(
m_nodeShape
);

for (int j = 0; j < shaderNode->getInputPinCount(); ++j)
for (int32_t j = 0; j < shaderNode->getInputPinCount(); ++j)
{
const InputPin* inputPin = shaderNode->getInputPin(j);
editorNode->createInputPin(
Expand All @@ -63,7 +62,7 @@ Ref< ui::Node > SwizzleNodeFacade::createEditorNode(
);
}

for (int j = 0; j < shaderNode->getOutputPinCount(); ++j)
for (int32_t j = 0; j < shaderNode->getOutputPinCount(); ++j)
{
const OutputPin* outputPin = shaderNode->getOutputPin(j);
editorNode->createOutputPin(
Expand All @@ -85,6 +84,52 @@ void SwizzleNodeFacade::editShaderNode(
Node* shaderNode
)
{
const ui::Rect rcEditVirtual = graphControl->pixel(editorNode->calculateRect());
const ui::Rect rcEdit(
graphControl->virtualToClient(rcEditVirtual.getTopLeft()),
graphControl->virtualToClient(rcEditVirtual.getBottomRight())
);

m_editEditorNode = editorNode;
m_editShaderNode = mandatory_non_null_type_cast< Swizzle* >(shaderNode);

if (m_edit == nullptr)
{
m_edit = new ui::Edit();
m_edit->create(graphControl);
m_edit->addEventHandler< ui::FocusEvent >(
[this](ui::FocusEvent* event)
{
if (m_edit->isVisible(false) && event->lostFocus())
{
m_editEditorNode->setInfo(m_edit->getText());
m_editShaderNode->set(m_edit->getText());
m_edit->setVisible(false);
}
}
);
m_edit->addEventHandler< ui::KeyDownEvent >(
[this](ui::KeyDownEvent* event)
{
if (event->getVirtualKey() == ui::VkReturn)
{
m_editEditorNode->setInfo(m_edit->getText());
m_editShaderNode->set(m_edit->getText());
m_edit->setVisible(false);
}
else if (event->getVirtualKey() == ui::VkEscape)
{
m_edit->setVisible(false);
}
}
);
}

m_edit->setText(m_editShaderNode->get());
m_edit->setRect(rcEdit);
m_edit->setVisible(true);
m_edit->selectAll();
m_edit->setFocus();
}

void SwizzleNodeFacade::refreshEditorNode(
Expand All @@ -107,5 +152,4 @@ void SwizzleNodeFacade::setValidationIndicator(
editorNode->setState(validationSucceeded ? 0 : 1);
}

}
}
20 changes: 11 additions & 9 deletions code/Render/Editor/Shader/Facades/SwizzleNodeFacade.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* TRAKTOR
* Copyright (c) 2022 Anders Pistol.
* Copyright (c) 2022-2024 Anders Pistol.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
Expand All @@ -10,17 +10,18 @@

#include "Render/Editor/Shader/INodeFacade.h"

namespace traktor
namespace traktor::ui
{
namespace ui
{

class Edit;
class INodeShape;

}
}

namespace traktor::render
{

namespace render
{
class Swizzle;

class SwizzleNodeFacade : public INodeFacade
{
Expand Down Expand Up @@ -64,8 +65,9 @@ class SwizzleNodeFacade : public INodeFacade

private:
Ref<ui::INodeShape > m_nodeShape;
Ref< ui::Edit > m_edit;
ui::Node* m_editEditorNode = nullptr;
Swizzle* m_editShaderNode = nullptr;
};

}
}

58 changes: 51 additions & 7 deletions code/Render/Editor/Shader/Facades/VariableNodeFacade.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* TRAKTOR
* Copyright (c) 2022 Anders Pistol.
* Copyright (c) 2022-2024 Anders Pistol.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
Expand All @@ -11,14 +11,13 @@
#include "Render/Editor/Shader/Nodes.h"
#include "Render/Editor/Shader/Facades/VariableNodeFacade.h"
#include "Ui/Application.h"
#include "Ui/Edit.h"
#include "Ui/Graph/GraphControl.h"
#include "Ui/Graph/Node.h"
#include "Ui/Graph/InOutNodeShape.h"

namespace traktor
namespace traktor::render
{
namespace render
{

T_IMPLEMENT_RTTI_CLASS(L"traktor.render.VariableNodeFacade", VariableNodeFacade, INodeFacade)

Expand Down Expand Up @@ -54,7 +53,7 @@ Ref< ui::Node > VariableNodeFacade::createEditorNode(
m_nodeShape
);

for (int j = 0; j < shaderNode->getInputPinCount(); ++j)
for (int32_t j = 0; j < shaderNode->getInputPinCount(); ++j)
{
const InputPin* inputPin = shaderNode->getInputPin(j);
editorNode->createInputPin(
Expand All @@ -65,7 +64,7 @@ Ref< ui::Node > VariableNodeFacade::createEditorNode(
);
}

for (int j = 0; j < shaderNode->getOutputPinCount(); ++j)
for (int32_t j = 0; j < shaderNode->getOutputPinCount(); ++j)
{
const OutputPin* outputPin = shaderNode->getOutputPin(j);
editorNode->createOutputPin(
Expand All @@ -87,6 +86,52 @@ void VariableNodeFacade::editShaderNode(
Node* shaderNode
)
{
const ui::Rect rcEditVirtual = graphControl->pixel(editorNode->calculateRect());
const ui::Rect rcEdit(
graphControl->virtualToClient(rcEditVirtual.getTopLeft()),
graphControl->virtualToClient(rcEditVirtual.getBottomRight())
);

m_editEditorNode = editorNode;
m_editShaderNode = mandatory_non_null_type_cast< Variable* >(shaderNode);

if (m_edit == nullptr)
{
m_edit = new ui::Edit();
m_edit->create(graphControl);
m_edit->addEventHandler< ui::FocusEvent >(
[this](ui::FocusEvent* event)
{
if (m_edit->isVisible(false) && event->lostFocus())
{
m_editEditorNode->setInfo(m_edit->getText());
m_editShaderNode->setName(m_edit->getText());
m_edit->setVisible(false);
}
}
);
m_edit->addEventHandler< ui::KeyDownEvent >(
[this](ui::KeyDownEvent* event)
{
if (event->getVirtualKey() == ui::VkReturn)
{
m_editEditorNode->setInfo(m_edit->getText());
m_editShaderNode->setName(m_edit->getText());
m_edit->setVisible(false);
}
else if (event->getVirtualKey() == ui::VkEscape)
{
m_edit->setVisible(false);
}
}
);
}

m_edit->setText(m_editShaderNode->getName());
m_edit->setRect(rcEdit);
m_edit->setVisible(true);
m_edit->selectAll();
m_edit->setFocus();
}

void VariableNodeFacade::refreshEditorNode(
Expand All @@ -109,5 +154,4 @@ void VariableNodeFacade::setValidationIndicator(
editorNode->setState(validationSucceeded ? 0 : 1);
}

}
}
19 changes: 11 additions & 8 deletions code/Render/Editor/Shader/Facades/VariableNodeFacade.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* TRAKTOR
* Copyright (c) 2022 Anders Pistol.
* Copyright (c) 2022-2024 Anders Pistol.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
Expand All @@ -10,17 +10,18 @@

#include "Render/Editor/Shader/INodeFacade.h"

namespace traktor
namespace traktor::ui
{
namespace ui
{

class Edit;
class INodeShape;

}
}

namespace traktor::render
{

namespace render
{
class Variable;

class VariableNodeFacade : public INodeFacade
{
Expand Down Expand Up @@ -64,7 +65,9 @@ class VariableNodeFacade : public INodeFacade

private:
Ref<ui::INodeShape > m_nodeShape;
Ref< ui::Edit > m_edit;
ui::Node* m_editEditorNode = nullptr;
Variable* m_editShaderNode = nullptr;
};

}
}
2 changes: 1 addition & 1 deletion code/Ui/Graph/InOutNodeShape.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ namespace traktor::ui
const Unit c_marginWidth = 3_ut; /*< Distance from image edge to "visual" edge. */
const Unit c_textMargin = 16_ut;
const Unit c_textHeight = 16_ut;
const Unit c_minExtent = 40_ut;
const Unit c_minExtent = 80_ut;
const Unit c_pinHitWidth = 14_ut; /*< Width of pin hit area from visual edge. */

struct Dim
Expand Down

0 comments on commit 18f83e5

Please sign in to comment.