Skip to content

Commit 231a78a

Browse files
committed
Drawing context to return if it can draw icons or not.
1 parent 01bd9ea commit 231a78a

11 files changed

+39
-2
lines changed

Sources/BuiltInNodes/BI_UINodeLayouts.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ void HeaderBasedLayout::AddPanels ( const BasicUINode& uiNode,
1919
nodeStatus = NodeUIHeaderPanel::NodeStatus::HasValue;
2020
}
2121
std::wstring nodeName = uiNode.GetNodeName ().GetLocalized ();
22-
if (uiNode.HasIconId ()) {
22+
if (uiNode.HasIconId () && env.GetDrawingContext ().CanDrawIcon ()) {
2323
drawer.AddPanel (NUIE::NodeUIPanelPtr (new NodeUIIconHeaderPanel (nodeName, nodeStatus, uiNode.GetIconId (), env)));
2424
} else {
2525
drawer.AddPanel (NUIE::NodeUIPanelPtr (new NodeUIHeaderPanel (nodeName, nodeStatus)));

Sources/NodeUIEngine/NUIE_DrawingContext.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,11 @@ Size DrawingContextDecorator::MeasureText (const Font& font, const std::wstring&
9494
return decorated.MeasureText (font, text);
9595
}
9696

97+
bool DrawingContextDecorator::CanDrawIcon ()
98+
{
99+
return decorated.CanDrawIcon ();
100+
}
101+
97102
void DrawingContextDecorator::DrawIcon (const Rect& rect, const IconId& iconId)
98103
{
99104
decorated.DrawIcon (rect, iconId);
@@ -169,6 +174,11 @@ Size NullDrawingContext::MeasureText (const Font&, const std::wstring&)
169174
return Size ();
170175
}
171176

177+
bool NullDrawingContext::CanDrawIcon ()
178+
{
179+
return false;
180+
}
181+
172182
void NullDrawingContext::DrawIcon (const Rect&, const IconId&)
173183
{
174184

Sources/NodeUIEngine/NUIE_DrawingContext.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ class DrawingContext
4444
virtual void DrawFormattedText (const Rect& rect, const Font& font, const std::wstring& text, HorizontalAnchor hAnchor, VerticalAnchor vAnchor, const Color& textColor) = 0;
4545
virtual Size MeasureText (const Font& font, const std::wstring& text) = 0;
4646

47+
virtual bool CanDrawIcon () = 0;
4748
virtual void DrawIcon (const Rect& rect, const IconId& iconId) = 0;
4849
};
4950

@@ -75,6 +76,7 @@ class DrawingContextDecorator : public DrawingContext
7576
virtual void DrawFormattedText (const Rect& rect, const Font& font, const std::wstring& text, HorizontalAnchor hAnchor, VerticalAnchor vAnchor, const Color& textColor) override;
7677
virtual Size MeasureText (const Font& font, const std::wstring& text) override;
7778

79+
virtual bool CanDrawIcon () override;
7880
virtual void DrawIcon (const Rect& rect, const IconId& iconId) override;
7981

8082
protected:
@@ -106,6 +108,7 @@ class NullDrawingContext : public DrawingContext
106108
virtual void DrawFormattedText (const Rect& rect, const Font& font, const std::wstring& text, HorizontalAnchor hAnchor, VerticalAnchor vAnchor, const Color& textColor) override;
107109
virtual Size MeasureText (const Font& font, const std::wstring& text) override;
108110

111+
virtual bool CanDrawIcon () override;
109112
virtual void DrawIcon (const Rect& rect, const IconId& iconId) override;
110113
};
111114

Sources/NodeUIEngine/NUIE_SvgDrawingContext.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,9 +261,14 @@ Size SvgDrawingContext::MeasureText (const Font& font, const std::wstring& text)
261261
return Size (text.length () * font.GetSize (), font.GetSize () * 1.5);
262262
}
263263

264-
void SvgDrawingContext::DrawIcon (const Rect&, const IconId&)
264+
bool SvgDrawingContext::CanDrawIcon ()
265265
{
266+
return false;
267+
}
266268

269+
void SvgDrawingContext::DrawIcon (const Rect&, const IconId&)
270+
{
271+
DBGBREAK ();
267272
}
268273

269274
std::wstring ReplaceAll (const std::wstring& string, const std::wstring& from, const std::wstring& to)

Sources/NodeUIEngine/NUIE_SvgDrawingContext.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ class SvgDrawingContext : public DrawingContext
5959
virtual void FillEllipse (const Rect& rect, const Color& color) override;
6060
virtual void DrawFormattedText (const Rect& rect, const Font& font, const std::wstring& text, HorizontalAnchor hAnchor, VerticalAnchor vAnchor, const NUIE::Color& textColor) override;
6161
virtual Size MeasureText (const Font& font, const std::wstring& text) override;
62+
virtual bool CanDrawIcon () override;
6263
virtual void DrawIcon (const Rect& rect, const IconId& iconId) override;
6364

6465
private:

Sources/WindowsAppSupport/WAS_BitmapContextGdi.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,11 @@ NUIE::Size BitmapContextGdi::MeasureText (const NUIE::Font& font, const std::wst
229229
return NUIE::Size (gdiRect.right - gdiRect.left + 5, gdiRect.bottom - gdiRect.top);
230230
}
231231

232+
bool BitmapContextGdi::CanDrawIcon ()
233+
{
234+
return false;
235+
}
236+
232237
void BitmapContextGdi::DrawIcon (const NUIE::Rect&, const NUIE::IconId&)
233238
{
234239
DBGBREAK ();

Sources/WindowsAppSupport/WAS_BitmapContextGdi.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ class BitmapContextGdi : public NUIE::NativeDrawingContext
7979
virtual void DrawFormattedText (const NUIE::Rect& rect, const NUIE::Font& font, const std::wstring& text, NUIE::HorizontalAnchor hAnchor, NUIE::VerticalAnchor vAnchor, const NUIE::Color& textColor) override;
8080
virtual NUIE::Size MeasureText (const NUIE::Font& font, const std::wstring& text) override;
8181

82+
virtual bool CanDrawIcon () override;
8283
virtual void DrawIcon (const NUIE::Rect& rect, const NUIE::IconId& iconId) override;
8384

8485
private:

Sources/WindowsAppSupport/WAS_BitmapContextGdiplus.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,11 @@ NUIE::Size BitmapContextGdiplus::MeasureText (const NUIE::Font& font, const std:
202202
return NUIE::Size (textRect.Width, textRect.Height);
203203
}
204204

205+
bool BitmapContextGdiplus::CanDrawIcon ()
206+
{
207+
return false;
208+
}
209+
205210
void BitmapContextGdiplus::DrawIcon (const NUIE::Rect&, const NUIE::IconId&)
206211
{
207212
DBGBREAK ();

Sources/WindowsAppSupport/WAS_BitmapContextGdiplus.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ class BitmapContextGdiplus : public NUIE::NativeDrawingContext
4141
virtual void DrawFormattedText (const NUIE::Rect& rect, const NUIE::Font& font, const std::wstring& text, NUIE::HorizontalAnchor hAnchor, NUIE::VerticalAnchor vAnchor, const NUIE::Color& textColor) override;
4242
virtual NUIE::Size MeasureText (const NUIE::Font& font, const std::wstring& text) override;
4343

44+
virtual bool CanDrawIcon () override;
4445
virtual void DrawIcon (const NUIE::Rect& rect, const NUIE::IconId& iconId) override;
4546

4647
private:

Sources/WindowsAppSupport/WAS_Direct2DContext.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,11 @@ NUIE::Size Direct2DContext::MeasureText (const NUIE::Font& font, const std::wstr
296296
return NUIE::Size (metrics.width * SafetyTextRatio, metrics.height * SafetyTextRatio);
297297
}
298298

299+
bool Direct2DContext::CanDrawIcon ()
300+
{
301+
return true;
302+
}
303+
299304
void Direct2DContext::DrawIcon (const NUIE::Rect& rect, const NUIE::IconId& iconId)
300305
{
301306
if (imageLoader == nullptr) {

0 commit comments

Comments
 (0)