!XT (BREAK-16) (Sandbox) Remove double-newlines at the end of files.
[CRYENGINE.git] / Code / Sandbox / Plugins / EditorCommon / NodeGraph / NodeGraphViewStyle.cpp
blob2f07e46efb1f43fc1bd7d51e5c48383de1731e49
1 // Copyright 2001-2018 Crytek GmbH / Crytek Group. All rights reserved.
3 #include "stdafx.h"
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)
17 : QWidget()
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!");
41 if (pStyle->GetId())
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;
51 else
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.");
59 else
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
69 CRY_ASSERT(styleId);
70 const StyleIdHash styleIdHash = CCrc32::Compute(styleId);
71 auto result = m_nodeWidgetStylesById.find(styleIdHash);
72 if (result != m_nodeWidgetStylesById.end())
74 return result->second;
76 return nullptr;
79 void CNodeGraphViewStyle::RegisterGroupWidgetStyle(CGroupWidgetStyle* pStyle)
81 CRY_ASSERT_MESSAGE(pStyle->GetId(), "StyleId must be non-zero!");
82 if (pStyle->GetId())
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;
92 else
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.");
100 else
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;
117 return nullptr;
120 void CNodeGraphViewStyle::RegisterCommentWidgetStyle(CCommentWidgetStyle* pStyle)
122 CRY_ASSERT_MESSAGE(pStyle->GetId(), "StyleId must be non-zero!");
123 if (pStyle->GetId())
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;
133 else
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.");
141 else
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;
158 return nullptr;
161 void CNodeGraphViewStyle::RegisterConnectionWidgetStyle(CConnectionWidgetStyle* pStyle)
163 CRY_ASSERT_MESSAGE(pStyle->GetId(), "StyleId must be non-zero!");
164 if (pStyle->GetId())
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;
174 else
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.");
182 else
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
192 CRY_ASSERT(styleId);
193 const StyleIdHash styleIdHash = CCrc32::Compute(styleId);
194 auto result = m_connectionWidgetStylesById.find(styleIdHash);
195 if (result != m_connectionWidgetStylesById.end())
197 return result->second;
199 return nullptr;
202 void CNodeGraphViewStyle::RegisterPinWidgetStyle(CNodePinWidgetStyle* pStyle)
204 CRY_ASSERT_MESSAGE(pStyle->GetId(), "StyleId must be non-zero!");
205 if (pStyle->GetId())
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;
215 else
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.");
223 else
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
233 CRY_ASSERT(styleId);
234 const StyleIdHash styleIdHash = CCrc32::Compute(styleId);
235 auto result = m_pinWidgetStylesById.find(styleIdHash);
236 if (result != m_pinWidgetStylesById.end())
238 return result->second;
240 return nullptr;