Skip to content

Commit

Permalink
added a way to ask for the children of a container to be drawn in rev…
Browse files Browse the repository at this point in the history
…erse order (for clever rendering tricks)
  • Loading branch information
meeloo committed Apr 8, 2014
1 parent 759f8fa commit da4799f
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 24 deletions.
2 changes: 1 addition & 1 deletion include/nuiGrid.h
Expand Up @@ -123,7 +123,7 @@ class nuiGrid : public nuiSimpleContainer
void SetEqualizeRows(bool set);
bool GetEqualizeColumns() const;
bool GetEqualizeRows() const;

protected:

uint32 GetDimensionRange(uint32 dimension) const;
Expand Down
4 changes: 4 additions & 0 deletions include/nuiWidget.h
Expand Up @@ -589,6 +589,8 @@ class nuiWidget : public nuiObject
uint32 GetCSSPass() const;
//@}

NUI_GETSETDO(bool, ReverseRender, Invalidate());

protected:
std::map<nglString, nuiEventSource*, nglString::LessFunctor> mEventMap;
std::vector<nuiEventActionHolder*> mEventActions;
Expand Down Expand Up @@ -706,6 +708,8 @@ class nuiWidget : public nuiObject
bool mAutoClip: 1;
bool mAutoDraw: 1;
bool mFixedAspectRatio: 1;
bool mReverseRender: 1;



bool mClickThru: 1;
Expand Down
Expand Up @@ -24,6 +24,11 @@
<key>orderHint</key>
<integer>11</integer>
</dict>
<key>nuiCocoa.xcscheme</key>
<dict>
<key>orderHint</key>
<integer>10</integer>
</dict>
<key>nuiPhoneD.xcscheme</key>
<dict>
<key>orderHint</key>
Expand Down
20 changes: 12 additions & 8 deletions src/Decorations/nuiColorDecoration.cpp
Expand Up @@ -132,18 +132,22 @@ nuiSize nuiColorDecoration::GetBorder(nuiPosition position, const nuiWidget* pWi
switch (position)
{
case nuiLeft:
case nuiRight:
return mClientRect.Left();
break;
case nuiRight:
return mClientRect.GetWidth();
break;
case nuiTop:
case nuiBottom:
return mClientRect.Top();
break;
case nuiBottom:
return mClientRect.GetHeight();
break;
case nuiFillHorizontal:
return mClientRect.Left()*2;
return mClientRect.Right();
break;
case nuiFillVertical:
return mClientRect.Top()*2;
return mClientRect.Bottom();
break;
case nuiNoPosition: break;
case nuiTopLeft: break;
Expand Down Expand Up @@ -171,11 +175,11 @@ void nuiColorDecoration::GetBorders(const nuiWidget* pWidget, float& rLeft, floa
}

rLeft = mClientRect.Left();
rRight = rLeft;
rRight = mClientRect.GetWidth();
rTop = mClientRect.Top();
rBottom = rTop;
rHorizontal = rLeft * 2;
rVertical = rTop * 2;
rBottom = mClientRect.Bottom();
rHorizontal = rLeft + rRight;
rVertical = rTop + rBottom;
}


Expand Down
39 changes: 30 additions & 9 deletions src/Layout/nuiGrid.cpp
Expand Up @@ -1213,19 +1213,40 @@ bool nuiGrid::Draw(nuiDrawContext *pContext)
}

IteratorPtr pIt;
for (pIt = GetFirstChild(); pIt && pIt->IsValid(); GetNextChild(pIt))
if (mReverseRender)
{
nuiWidgetPtr pItem = pIt->GetWidget();
if (pItem)
for (pIt = GetLastChild(); pIt && pIt->IsValid(); GetPreviousChild(pIt))
{
//#FIXME #TEST
nuiRect r = pItem->GetIdealRect();
if (mDisplayWidgetBoundingRect)
nuiWidgetPtr pItem = pIt->GetWidget();
if (pItem)
{
pContext->DrawRect(pItem->GetRect(), eStrokeShape);
//#FIXME #TEST
nuiRect r = pItem->GetIdealRect();
if (mDisplayWidgetBoundingRect)
{
pContext->DrawRect(pItem->GetRect(), eStrokeShape);
}

DrawChild(pContext, pItem);
}
}
}
else
{
for (pIt = GetFirstChild(); pIt && pIt->IsValid(); GetNextChild(pIt))
{
nuiWidgetPtr pItem = pIt->GetWidget();
if (pItem)
{
//#FIXME #TEST
nuiRect r = pItem->GetIdealRect();
if (mDisplayWidgetBoundingRect)
{
pContext->DrawRect(pItem->GetRect(), eStrokeShape);
}

DrawChild(pContext, pItem);
}

DrawChild(pContext, pItem);
}
}

Expand Down
24 changes: 19 additions & 5 deletions src/WidgetTree/nuiContainer.cpp
Expand Up @@ -368,13 +368,27 @@ bool nuiContainer::DrawChildren(nuiDrawContext* pContext)
{
CheckValid();
IteratorPtr pIt;
for (pIt = GetFirstChild(); pIt && pIt->IsValid(); GetNextChild(pIt))

if (mReverseRender)
{
nuiWidgetPtr pItem = pIt->GetWidget();
if (pItem)
DrawChild(pContext, pItem);
for (pIt = GetLastChild(); pIt && pIt->IsValid(); GetPreviousChild(pIt))
{
nuiWidgetPtr pItem = pIt->GetWidget();
if (pItem)
DrawChild(pContext, pItem);
}
delete pIt;
}
else
{
for (pIt = GetFirstChild(); pIt && pIt->IsValid(); GetNextChild(pIt))
{
nuiWidgetPtr pItem = pIt->GetWidget();
if (pItem)
DrawChild(pContext, pItem);
}
delete pIt;
}
delete pIt;
return true;
}

Expand Down
9 changes: 8 additions & 1 deletion src/WidgetTree/nuiWidget.cpp
Expand Up @@ -139,6 +139,7 @@ void nuiWidget::InitDefaultValues()
mFixedAspectRatio = false;
mAutoClip = true;
mAutoDraw = false;
mReverseRender = false;
}


Expand Down Expand Up @@ -472,7 +473,13 @@ void nuiWidget::InitAttributes()
(nglString(_T("FixedAspectRatio")), nuiUnitOnOff,
nuiMakeDelegate(this, &nuiWidget::GetFixedAspectRatio),
nuiMakeDelegate(this, &nuiWidget::SetFixedAspectRatio)));


AddAttribute(new nuiAttribute<bool>
(nglString(_T("ReverseRender")), nuiUnitSize,
nuiMakeDelegate(this, &nuiWidget::GetReverseRender),
nuiMakeDelegate(this, &nuiWidget::SetReverseRender)));



}

Expand Down

0 comments on commit da4799f

Please sign in to comment.