1 // Copyright 2001-2018 Crytek GmbH / Crytek Group. All rights reserved.
4 #include "NodeGraphViewStyle.h"
6 #include "NodeWidgetStyle.h"
7 #include "GroupWidgetStyle.h"
8 #include "CommentWidgetStyle.h"
9 #include "ConnectionWidgetStyle.h"
10 #include "NodePinWidgetStyle.h"
12 #include "NodeGraphView.h"
14 namespace CryGraphEditor
{
16 CNodeGraphViewStyle::CNodeGraphViewStyle(const char* szStyleId
)
19 setObjectName(szStyleId
);
21 m_selectionColor
= QColor(97, 172, 237);
22 m_highlightColor
= QColor(140, 140, 140);
24 m_gridBackgroundColor
= QColor(0x5F, 0x5F, 0x5F);
25 m_gridSegmentLineColor
= QColor(0x46, 0x46, 0x46);
26 m_gridSegmentLineWidth
= 1.f
;
27 m_gridSegmentSize
= 140.f
;
29 m_gridSubSegmentLineColor
= QColor(0x70, 0x70, 0x70);
30 m_gridSubSegmentCount
= 8;
31 m_gridSubSegmentLineWidth
= 1.f
;
33 CNodeWidgetStyle
* pNodeStyle
= new CNodeWidgetStyle("Node", *this);
34 CConnectionWidgetStyle
* pConnectionStyle
= new CConnectionWidgetStyle("Connection", *this);
35 CNodePinWidgetStyle
* pPinStyle
= new CNodePinWidgetStyle("Pin", *this);
38 void CNodeGraphViewStyle::RegisterNodeWidgetStyle(CNodeWidgetStyle
* pStyle
)
40 CRY_ASSERT_MESSAGE(pStyle
->GetId(), "StyleId must be non-zero!");
43 const uint32 styleIdHash
= pStyle
->GetIdHash();
44 const bool iconExists
= (m_nodeWidgetStylesById
.find(styleIdHash
) != m_nodeWidgetStylesById
.end());
46 if (iconExists
== false)
48 pStyle
->SetParent(this);
49 m_nodeWidgetStylesById
[styleIdHash
] = pStyle
;
53 auto result
= m_nodeWidgetStylesById
.find(styleIdHash
);
54 const stack_string resultStyleId
= result
->second
->GetId();
55 if (pStyle
->GetId() == resultStyleId
)
57 //CRY_ASSERT_MESSAGE(false, "Style id already exists.");
61 CRY_ASSERT_MESSAGE(false, "Hash collison of style id '%s' and '%s'", pStyle
->GetId(), resultStyleId
.c_str());
67 const CNodeWidgetStyle
* CNodeGraphViewStyle::GetNodeWidgetStyle(const char* styleId
) const
70 const StyleIdHash styleIdHash
= CCrc32::Compute(styleId
);
71 auto result
= m_nodeWidgetStylesById
.find(styleIdHash
);
72 if (result
!= m_nodeWidgetStylesById
.end())
74 return result
->second
;
79 void CNodeGraphViewStyle::RegisterGroupWidgetStyle(CGroupWidgetStyle
* pStyle
)
81 CRY_ASSERT_MESSAGE(pStyle
->GetId(), "StyleId must be non-zero!");
84 const uint32 styleIdHash
= pStyle
->GetIdHash();
85 const bool iconExists
= (m_groupWidgetStylesById
.find(styleIdHash
) != m_groupWidgetStylesById
.end());
87 if (iconExists
== false)
89 pStyle
->SetParent(this);
90 m_groupWidgetStylesById
[styleIdHash
] = pStyle
;
94 auto result
= m_groupWidgetStylesById
.find(styleIdHash
);
95 const stack_string resultStyleId
= result
->second
->GetId();
96 if (pStyle
->GetId() == resultStyleId
)
98 CRY_ASSERT_MESSAGE(false, "Style id already exists.");
102 CRY_ASSERT_MESSAGE(false, "Hash collison of style id '%s' and '%s'", pStyle
->GetId(), resultStyleId
.c_str());
108 const CGroupWidgetStyle
* CNodeGraphViewStyle::GetGroupWidgetStyle(const char* styleId
) const
110 CRY_ASSERT_MESSAGE(styleId
, "StyleId must be non-zero!");
111 const StyleIdHash styleIdHash
= CCrc32::Compute(styleId
);
112 auto result
= m_groupWidgetStylesById
.find(styleIdHash
);
113 if (result
!= m_groupWidgetStylesById
.end())
115 return result
->second
;
120 void CNodeGraphViewStyle::RegisterCommentWidgetStyle(CCommentWidgetStyle
* pStyle
)
122 CRY_ASSERT_MESSAGE(pStyle
->GetId(), "StyleId must be non-zero!");
125 const uint32 styleIdHash
= pStyle
->GetIdHash();
126 const bool iconExists
= (m_commentWidgetStylesById
.find(styleIdHash
) != m_commentWidgetStylesById
.end());
128 if (iconExists
== false)
130 pStyle
->SetParent(this);
131 m_commentWidgetStylesById
[styleIdHash
] = pStyle
;
135 auto result
= m_commentWidgetStylesById
.find(styleIdHash
);
136 const stack_string resultStyleId
= result
->second
->GetId();
137 if (pStyle
->GetId() == resultStyleId
)
139 //CRY_ASSERT_MESSAGE(false, "Style id already exists.");
143 CRY_ASSERT_MESSAGE(false, "Hash collison of style id '%s' and '%s'", pStyle
->GetId(), resultStyleId
.c_str());
149 const CCommentWidgetStyle
* CNodeGraphViewStyle::GetCommentWidgetStyle(const char* styleId
) const
151 CRY_ASSERT_MESSAGE(styleId
, "StyleId must be non-zero!");
152 const StyleIdHash styleIdHash
= CCrc32::Compute(styleId
);
153 auto result
= m_commentWidgetStylesById
.find(styleIdHash
);
154 if (result
!= m_commentWidgetStylesById
.end())
156 return result
->second
;
161 void CNodeGraphViewStyle::RegisterConnectionWidgetStyle(CConnectionWidgetStyle
* pStyle
)
163 CRY_ASSERT_MESSAGE(pStyle
->GetId(), "StyleId must be non-zero!");
166 const StyleIdHash styleIdHash
= pStyle
->GetIdHash();
167 const bool iconExists
= (m_connectionWidgetStylesById
.find(styleIdHash
) != m_connectionWidgetStylesById
.end());
169 if (iconExists
== false)
171 pStyle
->SetParent(this);
172 m_connectionWidgetStylesById
[styleIdHash
] = pStyle
;
176 auto result
= m_connectionWidgetStylesById
.find(styleIdHash
);
177 const stack_string resultStyleId
= result
->second
->GetId();
178 if (pStyle
->GetId() == resultStyleId
)
180 CRY_ASSERT_MESSAGE(false, "Style id already exists.");
184 CRY_ASSERT_MESSAGE(false, "Hash collison of style id '%s' and '%s'", pStyle
->GetId(), resultStyleId
.c_str());
190 const CConnectionWidgetStyle
* CNodeGraphViewStyle::GetConnectionWidgetStyle(const char* styleId
) const
193 const StyleIdHash styleIdHash
= CCrc32::Compute(styleId
);
194 auto result
= m_connectionWidgetStylesById
.find(styleIdHash
);
195 if (result
!= m_connectionWidgetStylesById
.end())
197 return result
->second
;
202 void CNodeGraphViewStyle::RegisterPinWidgetStyle(CNodePinWidgetStyle
* pStyle
)
204 CRY_ASSERT_MESSAGE(pStyle
->GetId(), "StyleId must be non-zero!");
207 const StyleIdHash styleIdHash
= pStyle
->GetIdHash();
208 const bool iconExists
= (m_pinWidgetStylesById
.find(styleIdHash
) != m_pinWidgetStylesById
.end());
210 if (iconExists
== false)
212 pStyle
->SetParent(this);
213 m_pinWidgetStylesById
[styleIdHash
] = pStyle
;
217 auto result
= m_pinWidgetStylesById
.find(styleIdHash
);
218 const stack_string resultStyleId
= result
->second
->GetId();
219 if (pStyle
->GetId() == resultStyleId
)
221 CRY_ASSERT_MESSAGE(false, "Style id already exists.");
225 CRY_ASSERT_MESSAGE(false, "Hash collison of style id '%s' and '%s'", pStyle
->GetId(), resultStyleId
.c_str());
231 const CNodePinWidgetStyle
* CNodeGraphViewStyle::GetPinWidgetStyle(const char* styleId
) const
234 const StyleIdHash styleIdHash
= CCrc32::Compute(styleId
);
235 auto result
= m_pinWidgetStylesById
.find(styleIdHash
);
236 if (result
!= m_pinWidgetStylesById
.end())
238 return result
->second
;