1 // Copyright 2001-2018 Crytek GmbH / Crytek Group. All rights reserved.
4 #include "HyperNodePainter_QuickSearch.h"
6 #include "HyperGraph/Nodes/QuickSearchNode.h"
7 #include "HyperGraph/HyperGraph.h"
8 #include "HyperGraph/FlowGraphPreferences.h"
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
);
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
));
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;
48 pAssets
= new SQuickSearchAssets();
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
)
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
);
82 rect
.X
= rect
.Y
= 0.0f
;
83 pBackground
->SetRect(rect
);
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
);
109 pList
->AddLine(start
, end
, &pAssets
->penBorder
);