!XT (BREAK-16) (Sandbox) Remove double-newlines at the end of files.
[CRYENGINE.git] / Code / Sandbox / EditorQt / HyperGraph / NodePainter / HyperNodePainter_QuickSearch.cpp
blobcd56bd3d73e3f87ce51424583336ead75e4961e6
1 // Copyright 2001-2018 Crytek GmbH / Crytek Group. All rights reserved.
3 #include "StdAfx.h"
4 #include "HyperNodePainter_QuickSearch.h"
6 #include "HyperGraph/Nodes/QuickSearchNode.h"
7 #include "HyperGraph/HyperGraph.h"
8 #include "HyperGraph/FlowGraphPreferences.h"
10 namespace
12 struct SQuickSearchAssets
14 SQuickSearchAssets() :
15 font(L"Tahoma", 10.0f, Gdiplus::FontStyleBold),
16 brushBackground(GET_GDI_COLOR(gFlowGraphColorPreferences.colorQuickSearchBackground)),
17 brushTextCount(GET_GDI_COLOR(gFlowGraphColorPreferences.colorQuickSearchCountText)),
18 brushTextResult(GET_GDI_COLOR(gFlowGraphColorPreferences.colorQuickSearchResultText)),
19 penBorder(GET_GDI_COLOR(gFlowGraphColorPreferences.colorQuickSearchBorder))
21 sf.SetAlignment(Gdiplus::StringAlignmentCenter);
22 sf.SetFormatFlags(Gdiplus::StringFormatFlagsNoWrap);
23 sf.SetTrimming(Gdiplus::StringTrimmingEllipsisPath);
26 void Update()
28 brushBackground.SetColor(GET_GDI_COLOR(gFlowGraphColorPreferences.colorQuickSearchBackground));
29 brushTextCount.SetColor(GET_GDI_COLOR(gFlowGraphColorPreferences.colorQuickSearchCountText));
30 brushTextResult.SetColor(GET_GDI_COLOR(gFlowGraphColorPreferences.colorQuickSearchResultText));
31 penBorder.SetColor(GET_GDI_COLOR(gFlowGraphColorPreferences.colorQuickSearchBorder));
34 Gdiplus::Font font;
35 Gdiplus::SolidBrush brushBackground;
36 Gdiplus::SolidBrush brushTextCount;
37 Gdiplus::SolidBrush brushTextResult;
38 Gdiplus::StringFormat sf;
39 Gdiplus::Pen penBorder;
44 void CHyperNodePainter_QuickSearch::Paint(CHyperNode* pNode, CDisplayList* pList)
46 static SQuickSearchAssets* pAssets = 0;
47 if (!pAssets)
48 pAssets = new SQuickSearchAssets();
50 pAssets->Update();
52 CDisplayRectangle* pBackground = pList->Add<CDisplayRectangle>()
53 ->SetHitEvent(eSOID_ShiftFirstOutputPort)
54 ->SetStroked(&pAssets->penBorder);
56 CString text = pNode->GetName();
57 text.Replace('_', ' ');
58 text.Replace("\\n", "\r\n");
60 CDisplayString* pString = pList->Add<CDisplayString>()
61 ->SetHitEvent(eSOID_ShiftFirstOutputPort)
62 ->SetText(text)
63 ->SetBrush(&pAssets->brushTextResult)
64 ->SetFont(&pAssets->font)
65 ->SetStringFormat(&pAssets->sf);
67 pBackground->SetFilled(&pAssets->brushBackground);
69 CQuickSearchNode* pQuickSearchNode = static_cast<CQuickSearchNode*>(pNode);
70 CString resultCount = "";
71 resultCount.Format("%d / %d", pQuickSearchNode->GetIndex(), pQuickSearchNode->GetSearchResultCount());
72 CDisplayString* pSearchCountString = pList->Add<CDisplayString>()
73 ->SetHitEvent(eSOID_ShiftFirstOutputPort)
74 ->SetText(resultCount)
75 ->SetBrush(&pAssets->brushTextCount)
76 ->SetFont(&pAssets->font)
77 ->SetStringFormat(&pAssets->sf);
79 Gdiplus::RectF rect;
80 rect.Width = 300.0f;
81 rect.Height = 50.0f;
82 rect.X = rect.Y = 0.0f;
83 pBackground->SetRect(rect);
84 rect.Y = 13.0f;
86 Gdiplus::RectF rectString = pString->GetBounds(pList->GetGraphics());
88 if (rectString.Width > rect.Width)
90 text.Delete(0, text.ReverseFind(':'));
91 CString trimmedText = "...";
92 trimmedText.Append(text);
93 pString->SetText(trimmedText);
96 pString->SetRect(rect);
97 pString->SetLocation(Gdiplus::PointF(150.0f, 32.0f));
98 pSearchCountString->SetLocation(Gdiplus::PointF(150.0f, 32.0f));
99 pBackground->SetHitEvent(eSOID_Title);
100 pNode->SetRect(rect);
102 Gdiplus::PointF start(0.0f, 32.0f);
103 Gdiplus::PointF end(300.0f, 32.0f);
105 pList->AddLine(start, end, &pAssets->penBorder);
107 start.Y = 14.0f;
108 end.Y = 14.0f;
109 pList->AddLine(start, end, &pAssets->penBorder);