From 18f83e5a1fa5813316e610b4cb20dc5f8ef435b7 Mon Sep 17 00:00:00 2001 From: apistol78 Date: Mon, 27 May 2024 13:52:12 +0200 Subject: [PATCH] Traktor: Able inline edit swizzle and variable nodes. --- .../Shader/Facades/CommentNodeFacade.cpp | 4 +- .../Shader/Facades/SwizzleNodeFacade.cpp | 60 ++++++++++++++++--- .../Editor/Shader/Facades/SwizzleNodeFacade.h | 20 ++++--- .../Shader/Facades/VariableNodeFacade.cpp | 58 +++++++++++++++--- .../Shader/Facades/VariableNodeFacade.h | 19 +++--- code/Ui/Graph/InOutNodeShape.cpp | 2 +- 6 files changed, 128 insertions(+), 35 deletions(-) diff --git a/code/Render/Editor/Shader/Facades/CommentNodeFacade.cpp b/code/Render/Editor/Shader/Facades/CommentNodeFacade.cpp index eca272347d..21a2c8e5b6 100644 --- a/code/Render/Editor/Shader/Facades/CommentNodeFacade.cpp +++ b/code/Render/Editor/Shader/Facades/CommentNodeFacade.cpp @@ -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 { @@ -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(); } diff --git a/code/Render/Editor/Shader/Facades/SwizzleNodeFacade.cpp b/code/Render/Editor/Shader/Facades/SwizzleNodeFacade.cpp index f0dab38290..66debe416d 100644 --- a/code/Render/Editor/Shader/Facades/SwizzleNodeFacade.cpp +++ b/code/Render/Editor/Shader/Facades/SwizzleNodeFacade.cpp @@ -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) @@ -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( @@ -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( @@ -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( @@ -107,5 +152,4 @@ void SwizzleNodeFacade::setValidationIndicator( editorNode->setState(validationSucceeded ? 0 : 1); } - } } diff --git a/code/Render/Editor/Shader/Facades/SwizzleNodeFacade.h b/code/Render/Editor/Shader/Facades/SwizzleNodeFacade.h index 9adcc0dda9..66fa2c035e 100644 --- a/code/Render/Editor/Shader/Facades/SwizzleNodeFacade.h +++ b/code/Render/Editor/Shader/Facades/SwizzleNodeFacade.h @@ -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 @@ -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 { @@ -64,8 +65,9 @@ class SwizzleNodeFacade : public INodeFacade private: Ref m_nodeShape; + Ref< ui::Edit > m_edit; + ui::Node* m_editEditorNode = nullptr; + Swizzle* m_editShaderNode = nullptr; }; - } } - diff --git a/code/Render/Editor/Shader/Facades/VariableNodeFacade.cpp b/code/Render/Editor/Shader/Facades/VariableNodeFacade.cpp index 0b871ef388..adf260a508 100644 --- a/code/Render/Editor/Shader/Facades/VariableNodeFacade.cpp +++ b/code/Render/Editor/Shader/Facades/VariableNodeFacade.cpp @@ -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 @@ -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) @@ -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( @@ -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( @@ -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( @@ -109,5 +154,4 @@ void VariableNodeFacade::setValidationIndicator( editorNode->setState(validationSucceeded ? 0 : 1); } - } } diff --git a/code/Render/Editor/Shader/Facades/VariableNodeFacade.h b/code/Render/Editor/Shader/Facades/VariableNodeFacade.h index 9d19e14b81..ac99cbd6b6 100644 --- a/code/Render/Editor/Shader/Facades/VariableNodeFacade.h +++ b/code/Render/Editor/Shader/Facades/VariableNodeFacade.h @@ -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 @@ -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 { @@ -64,7 +65,9 @@ class VariableNodeFacade : public INodeFacade private: Ref m_nodeShape; + Ref< ui::Edit > m_edit; + ui::Node* m_editEditorNode = nullptr; + Variable* m_editShaderNode = nullptr; }; - } } diff --git a/code/Ui/Graph/InOutNodeShape.cpp b/code/Ui/Graph/InOutNodeShape.cpp index 2ac8187e07..8646aece1f 100644 --- a/code/Ui/Graph/InOutNodeShape.cpp +++ b/code/Ui/Graph/InOutNodeShape.cpp @@ -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