Skip to content

Commit 0ad22c2

Browse files
committed
Fixed an issue where NodeFactory::RegisterNodeType did not handle many edge cases; GroupComment::SetPosition now correctly moves attached nodes, previously, only non-programmatic movement worked as expected.
1 parent 4885866 commit 0ad22c2

6 files changed

Lines changed: 42 additions & 10 deletions

File tree

CMakeLists.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,19 @@ option(VISUAL_NODE_SYSTEM_BUILD_SHARED_LIBS "Build VisualNodeSystem as a shared
1212
option(VISUAL_NODE_SYSTEM_USE_STATIC_RUNTIME "Use static runtime (/MT) instead of dynamic (/MD) for VisualNodeSystem" ON)
1313
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
1414

15+
if(MSVC)
16+
if(VISUAL_NODE_SYSTEM_USE_STATIC_RUNTIME)
17+
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MTd")
18+
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT")
19+
else()
20+
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MDd")
21+
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MD")
22+
endif()
23+
24+
# Always add /MP for multi-processor compilation
25+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP")
26+
endif()
27+
1528
# Turn on the ability to create folders to organize projects (.vcproj)
1629
# It creates "CMakePredefinedTargets" folder by default and adds CMake
1730
# defined projects like INSTALL.vcproj and ZERO_CHECK.vcproj

GroupComment.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "GroupComment.h"
2+
#include "SubSystems/VisualNodeArea/VisualNodeArea.h"
23
using namespace VisNodeSys;
34

45
char GroupComment::GroupCommentRename[GROUP_COMMENT_CAPTION_MAX_LENGTH] = "";
@@ -35,7 +36,15 @@ ImVec2 GroupComment::GetPosition() const
3536

3637
void GroupComment::SetPosition(const ImVec2 NewValue)
3738
{
38-
Position = NewValue;
39+
if (ParentArea == nullptr)
40+
{
41+
Position = NewValue;
42+
return;
43+
}
44+
45+
ImVec2 Delta = NewValue - Position;
46+
ParentArea->AttachElementsToGroupComment(this);
47+
ParentArea->MoveGroupComment(this, Delta);
3948
}
4049

4150
ImVec2 GroupComment::GetSize() const

SubSystems/VisualNodeArea/VisualNodeArea.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ namespace VisNodeSys
6666

6767
class VISUAL_NODE_SYSTEM_API NodeArea
6868
{
69+
friend class GroupComment;
6970
friend NodeSystem;
7071
public:
7172
NodeArea();

SubSystems/VisualNodeArea/VisualNodeAreaInput.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -619,7 +619,7 @@ void NodeArea::MouseDraggingGroupCommentUpdate()
619619

620620
void NodeArea::MoveGroupComment(GroupComment* GroupComment, ImVec2 Delta)
621621
{
622-
GroupComment->SetPosition(GroupComment->GetPosition() + Delta);
622+
GroupComment->Position += Delta;
623623

624624
if (!GroupComment->bMoveElementsWithComment)
625625
return;

VisualNodeFactory.cpp

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,28 +11,37 @@ extern "C" __declspec(dllexport) void* GetNodeFactory()
1111
NodeFactory::NodeFactory() {}
1212
NodeFactory::~NodeFactory() {}
1313

14-
void NodeFactory::RegisterNodeType(const std::string& Type,
14+
bool NodeFactory::RegisterNodeType(const std::string& Type,
1515
std::function<Node* ()> Constructor,
1616
std::function<Node* (const Node&)> CopyConstructor)
1717
{
18+
if (Type.empty() || Constructor == nullptr || CopyConstructor == nullptr)
19+
return false;
20+
21+
auto ConstructorIterator = Constructors.find(Type);
22+
if (ConstructorIterator != Constructors.end())
23+
return false;
24+
1825
Constructors[Type] = Constructor;
1926
CopyConstructors[Type] = CopyConstructor;
27+
28+
return true;
2029
}
2130

2231
Node* NodeFactory::CreateNode(const std::string& Type) const
2332
{
24-
auto it = Constructors.find(Type);
25-
if (it == Constructors.end())
33+
auto ConstructorIterator = Constructors.find(Type);
34+
if (ConstructorIterator == Constructors.end())
2635
return nullptr;
2736

28-
return it->second();
37+
return ConstructorIterator->second();
2938
}
3039

3140
Node* NodeFactory::CopyNode(const std::string& Type, const Node& Node) const
3241
{
33-
auto it = CopyConstructors.find(Type);
34-
if (it == CopyConstructors.end())
42+
auto CopyConstructorIterator = CopyConstructors.find(Type);
43+
if (CopyConstructorIterator == CopyConstructors.end())
3544
return nullptr;
3645

37-
return it->second(Node);
46+
return CopyConstructorIterator->second(Node);
3847
}

VisualNodeFactory.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ namespace VisNodeSys
1414
public:
1515
SINGLETON_PUBLIC_PART(NodeFactory)
1616

17-
void RegisterNodeType(const std::string& Type, std::function<Node* ()> Constructor, std::function<Node* (const Node&)> CopyConstructor);
17+
bool RegisterNodeType(const std::string& Type, std::function<Node* ()> Constructor, std::function<Node* (const Node&)> CopyConstructor);
1818
Node* CreateNode(const std::string& Type) const;
1919
Node* CopyNode(const std::string& Type, const Node& Node) const;
2020
};

0 commit comments

Comments
 (0)