Commit 7a3b638c authored by cutealien's avatar cutealien

CGUIProfiler can now handle it when a group doesn't fit on a single page.


git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@4815 dfc29bdd-3216-0410-991c-e03cc46cb475
parent bb890274
// This file is part of the "Irrlicht Engine". // This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h // For conditions of distribution and use, see copyright notice in irrlicht.h
// Written by Michael Zeilfelder // Written by Michael Zeilfelder
#include "CGUIProfiler.h" #include "CGUIProfiler.h"
#ifdef _IRR_COMPILE_WITH_GUI_ #ifdef _IRR_COMPILE_WITH_GUI_
#include "IGUITable.h" #include "IGUITable.h"
#include "IGUIScrollBar.h"
#include "IGUIEnvironment.h" #include "IGUIEnvironment.h"
#include "CProfiler.h" #include "CProfiler.h"
...@@ -16,7 +18,7 @@ namespace gui ...@@ -16,7 +18,7 @@ namespace gui
//! constructor //! constructor
CGUIProfiler::CGUIProfiler(IGUIEnvironment* environment, IGUIElement* parent, s32 id, core::rect<s32> rectangle) CGUIProfiler::CGUIProfiler(IGUIEnvironment* environment, IGUIElement* parent, s32 id, core::rect<s32> rectangle)
: IGUIProfiler(environment, parent, id, rectangle) : IGUIProfiler(environment, parent, id, rectangle)
, DisplayTable(0), CurrentGroupIdx(0), IgnoreUncalled(false) , DisplayTable(0), CurrentGroupIdx(0), CurrentGroupPage(0), NumGroupPages(1), IgnoreUncalled(false)
{ {
Profiler = &getProfiler(); Profiler = &getProfiler();
...@@ -113,6 +115,49 @@ void CGUIProfiler::updateDisplay() ...@@ -113,6 +115,49 @@ void CGUIProfiler::updateDisplay()
} }
} }
} }
// IGUITable has no page-wise scrolling yet. The following code can be replaced when we add that at.
// For now we use some CGUITable implementation info to figure this out.
// (If you wonder why I didn't code page-scrolling directly in CGUITable ... because then it needs to be a
// public interface and I don't have enough time currently to design & implement that well)
s32 itemsTotalHeight = DisplayTable->getRowCount() * DisplayTable->getItemHeight();
s32 tableHeight = DisplayTable->getAbsolutePosition().getHeight();
s32 heightTitleRow = DisplayTable->getItemHeight()+1;
if ( itemsTotalHeight+heightTitleRow < tableHeight )
{
NumGroupPages = 1;
}
else
{
s32 heightHScrollBar = DisplayTable->getHorizontalScrollBar() ? DisplayTable->getHorizontalScrollBar()->getAbsolutePosition().getHeight() : 0;
s32 pageHeight = tableHeight - (heightTitleRow+heightHScrollBar);
if ( pageHeight > 0 )
{
NumGroupPages = (itemsTotalHeight/pageHeight);
if ( itemsTotalHeight % pageHeight )
++NumGroupPages;
}
else // won't see anything, but that's up to the user
{
NumGroupPages = DisplayTable->getRowCount();
}
if ( NumGroupPages < 1 )
NumGroupPages = 1;
}
if ( CurrentGroupPage < 0 )
CurrentGroupPage = (s32)NumGroupPages-1;
IGUIScrollBar* vScrollBar = DisplayTable->getVerticalScrollBar();
if ( vScrollBar )
{
if ( NumGroupPages < 2 )
vScrollBar->setPos(0);
else
{
f32 factor = (f32)CurrentGroupPage/(f32)(NumGroupPages-1);
vScrollBar->setPos( s32(factor * (f32)vScrollBar->getMax()) );
}
}
} }
} }
...@@ -128,27 +173,41 @@ void CGUIProfiler::draw() ...@@ -128,27 +173,41 @@ void CGUIProfiler::draw()
void CGUIProfiler::nextPage(bool includeOverview) void CGUIProfiler::nextPage(bool includeOverview)
{ {
if ( ++CurrentGroupIdx >= Profiler->getGroupCount() ) if ( CurrentGroupPage < NumGroupPages-1 )
++CurrentGroupPage;
else
{ {
if ( includeOverview ) CurrentGroupPage = 0;
CurrentGroupIdx = 0; if ( ++CurrentGroupIdx >= Profiler->getGroupCount() )
else {
CurrentGroupIdx = 1; // can be invalid if ( includeOverview )
CurrentGroupIdx = 0;
else
CurrentGroupIdx = 1; // can be invalid
}
} }
} }
void CGUIProfiler::previousPage(bool includeOverview) void CGUIProfiler::previousPage(bool includeOverview)
{ {
if ( CurrentGroupIdx > 0 ) if ( CurrentGroupPage > 0 )
--CurrentGroupIdx; {
--CurrentGroupPage;
}
else else
CurrentGroupIdx = Profiler->getGroupCount()-1;
if ( CurrentGroupIdx == 0 && !includeOverview )
{ {
if ( Profiler->getGroupCount() ) CurrentGroupPage = -1; // unknown because NumGroupPages has to be re-calculated first
if ( CurrentGroupIdx > 0 )
--CurrentGroupIdx;
else
CurrentGroupIdx = Profiler->getGroupCount()-1; CurrentGroupIdx = Profiler->getGroupCount()-1;
if ( CurrentGroupIdx == 0 ) if ( CurrentGroupIdx == 0 && !includeOverview )
CurrentGroupIdx = 1; // invalid to avoid showing the overview {
if ( Profiler->getGroupCount() )
CurrentGroupIdx = Profiler->getGroupCount()-1;
if ( CurrentGroupIdx == 0 )
CurrentGroupIdx = 1; // invalid to avoid showing the overview
}
} }
} }
......
...@@ -69,6 +69,8 @@ namespace gui ...@@ -69,6 +69,8 @@ namespace gui
IProfiler * Profiler; IProfiler * Profiler;
irr::gui::IGUITable* DisplayTable; irr::gui::IGUITable* DisplayTable;
irr::u32 CurrentGroupIdx; irr::u32 CurrentGroupIdx;
irr::s32 CurrentGroupPage;
irr::s32 NumGroupPages;
bool IgnoreUncalled; bool IgnoreUncalled;
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment