Skip to content

Commit

Permalink
Drawing context to return if it can draw icons or not.
Browse files Browse the repository at this point in the history
  • Loading branch information
kovacsv committed Jun 15, 2020
1 parent 01bd9ea commit 231a78a
Show file tree
Hide file tree
Showing 11 changed files with 39 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Sources/BuiltInNodes/BI_UINodeLayouts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ void HeaderBasedLayout::AddPanels ( const BasicUINode& uiNode,
nodeStatus = NodeUIHeaderPanel::NodeStatus::HasValue;
}
std::wstring nodeName = uiNode.GetNodeName ().GetLocalized ();
if (uiNode.HasIconId ()) {
if (uiNode.HasIconId () && env.GetDrawingContext ().CanDrawIcon ()) {
drawer.AddPanel (NUIE::NodeUIPanelPtr (new NodeUIIconHeaderPanel (nodeName, nodeStatus, uiNode.GetIconId (), env)));
} else {
drawer.AddPanel (NUIE::NodeUIPanelPtr (new NodeUIHeaderPanel (nodeName, nodeStatus)));
Expand Down
10 changes: 10 additions & 0 deletions Sources/NodeUIEngine/NUIE_DrawingContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ Size DrawingContextDecorator::MeasureText (const Font& font, const std::wstring&
return decorated.MeasureText (font, text);
}

bool DrawingContextDecorator::CanDrawIcon ()
{
return decorated.CanDrawIcon ();
}

void DrawingContextDecorator::DrawIcon (const Rect& rect, const IconId& iconId)
{
decorated.DrawIcon (rect, iconId);
Expand Down Expand Up @@ -169,6 +174,11 @@ Size NullDrawingContext::MeasureText (const Font&, const std::wstring&)
return Size ();
}

bool NullDrawingContext::CanDrawIcon ()
{
return false;
}

void NullDrawingContext::DrawIcon (const Rect&, const IconId&)
{

Expand Down
3 changes: 3 additions & 0 deletions Sources/NodeUIEngine/NUIE_DrawingContext.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class DrawingContext
virtual void DrawFormattedText (const Rect& rect, const Font& font, const std::wstring& text, HorizontalAnchor hAnchor, VerticalAnchor vAnchor, const Color& textColor) = 0;
virtual Size MeasureText (const Font& font, const std::wstring& text) = 0;

virtual bool CanDrawIcon () = 0;
virtual void DrawIcon (const Rect& rect, const IconId& iconId) = 0;
};

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

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

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

virtual bool CanDrawIcon () override;
virtual void DrawIcon (const Rect& rect, const IconId& iconId) override;
};

Expand Down
7 changes: 6 additions & 1 deletion Sources/NodeUIEngine/NUIE_SvgDrawingContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,9 +261,14 @@ Size SvgDrawingContext::MeasureText (const Font& font, const std::wstring& text)
return Size (text.length () * font.GetSize (), font.GetSize () * 1.5);
}

void SvgDrawingContext::DrawIcon (const Rect&, const IconId&)
bool SvgDrawingContext::CanDrawIcon ()
{
return false;
}

void SvgDrawingContext::DrawIcon (const Rect&, const IconId&)
{
DBGBREAK ();
}

std::wstring ReplaceAll (const std::wstring& string, const std::wstring& from, const std::wstring& to)
Expand Down
1 change: 1 addition & 0 deletions Sources/NodeUIEngine/NUIE_SvgDrawingContext.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class SvgDrawingContext : public DrawingContext
virtual void FillEllipse (const Rect& rect, const Color& color) override;
virtual void DrawFormattedText (const Rect& rect, const Font& font, const std::wstring& text, HorizontalAnchor hAnchor, VerticalAnchor vAnchor, const NUIE::Color& textColor) override;
virtual Size MeasureText (const Font& font, const std::wstring& text) override;
virtual bool CanDrawIcon () override;
virtual void DrawIcon (const Rect& rect, const IconId& iconId) override;

private:
Expand Down
5 changes: 5 additions & 0 deletions Sources/WindowsAppSupport/WAS_BitmapContextGdi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,11 @@ NUIE::Size BitmapContextGdi::MeasureText (const NUIE::Font& font, const std::wst
return NUIE::Size (gdiRect.right - gdiRect.left + 5, gdiRect.bottom - gdiRect.top);
}

bool BitmapContextGdi::CanDrawIcon ()
{
return false;
}

void BitmapContextGdi::DrawIcon (const NUIE::Rect&, const NUIE::IconId&)
{
DBGBREAK ();
Expand Down
1 change: 1 addition & 0 deletions Sources/WindowsAppSupport/WAS_BitmapContextGdi.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ class BitmapContextGdi : public NUIE::NativeDrawingContext
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;
virtual NUIE::Size MeasureText (const NUIE::Font& font, const std::wstring& text) override;

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

private:
Expand Down
5 changes: 5 additions & 0 deletions Sources/WindowsAppSupport/WAS_BitmapContextGdiplus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,11 @@ NUIE::Size BitmapContextGdiplus::MeasureText (const NUIE::Font& font, const std:
return NUIE::Size (textRect.Width, textRect.Height);
}

bool BitmapContextGdiplus::CanDrawIcon ()
{
return false;
}

void BitmapContextGdiplus::DrawIcon (const NUIE::Rect&, const NUIE::IconId&)
{
DBGBREAK ();
Expand Down
1 change: 1 addition & 0 deletions Sources/WindowsAppSupport/WAS_BitmapContextGdiplus.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class BitmapContextGdiplus : public NUIE::NativeDrawingContext
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;
virtual NUIE::Size MeasureText (const NUIE::Font& font, const std::wstring& text) override;

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

private:
Expand Down
5 changes: 5 additions & 0 deletions Sources/WindowsAppSupport/WAS_Direct2DContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,11 @@ NUIE::Size Direct2DContext::MeasureText (const NUIE::Font& font, const std::wstr
return NUIE::Size (metrics.width * SafetyTextRatio, metrics.height * SafetyTextRatio);
}

bool Direct2DContext::CanDrawIcon ()
{
return true;
}

void Direct2DContext::DrawIcon (const NUIE::Rect& rect, const NUIE::IconId& iconId)
{
if (imageLoader == nullptr) {
Expand Down
1 change: 1 addition & 0 deletions Sources/WindowsAppSupport/WAS_Direct2DContext.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class Direct2DContext : public NUIE::NativeDrawingContext
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;
virtual NUIE::Size MeasureText (const NUIE::Font& font, const std::wstring& text) override;

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

private:
Expand Down

0 comments on commit 231a78a

Please sign in to comment.