Commit d8676389 authored by cutealien's avatar cutealien

Fixed several selection, highlighting and clipping bugs in CGUITreeview (thx @...

Fixed several selection, highlighting and clipping bugs in CGUITreeview (thx @ AReichl for the patch + test)


git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@4910 dfc29bdd-3216-0410-991c-e03cc46cb475
parent aa082cbb
-------------------------- --------------------------
Changes in 1.9 (not yet released) Changes in 1.9 (not yet released)
- Fixed several selection, highlighting and clipping bugs in CGUITreeview (thx @ AReichl for the patch + test)
- Removed DllMain from the static windows build (thx @ AReichl for reporting) - Removed DllMain from the static windows build (thx @ AReichl for reporting)
- Fixed maximize/minimize under Linux by supporting NETWM hints. Patch provided by hendu. - Fixed maximize/minimize under Linux by supporting NETWM hints. Patch provided by hendu.
- ISceneNode::deserializeAttributes uses now old values for parameters which are not in the attributes (thx @entity for noticing). - ISceneNode::deserializeAttributes uses now old values for parameters which are not in the attributes (thx @entity for noticing).
......
// This file is part of the "Irrlicht Engine". // This file is part of the "Irrlicht Engine".
// written by Reinhard Ostermeier, reinhard@nospam.r-ostermeier.de // Written by Reinhard Ostermeier, reinhard@nospam.r-ostermeier.de
// expaned by burningwater // Expanded by burningwater
// Bugfixes by Michael Zeilfelder
// Bugfixes by Andreas Reichl
#include "CGUITreeView.h" #include "CGUITreeView.h"
...@@ -455,9 +457,8 @@ CGUITreeView::CGUITreeView(IGUIEnvironment* environment, IGUIElement* parent, ...@@ -455,9 +457,8 @@ CGUITreeView::CGUITreeView(IGUIEnvironment* environment, IGUIElement* parent,
core::rect<s32>( RelativeRect.getWidth() - s, core::rect<s32>( RelativeRect.getWidth() - s,
0, 0,
RelativeRect.getWidth(), RelativeRect.getWidth(),
RelativeRect.getHeight() - (scrollBarHorizontal ? s : 0 ) RelativeRect.getHeight() - s
), ), !clip );
!clip );
ScrollBarV->drop(); ScrollBarV->drop();
ScrollBarV->setSubElement(true); ScrollBarV->setSubElement(true);
...@@ -468,8 +469,11 @@ CGUITreeView::CGUITreeView(IGUIEnvironment* environment, IGUIElement* parent, ...@@ -468,8 +469,11 @@ CGUITreeView::CGUITreeView(IGUIEnvironment* environment, IGUIElement* parent,
if ( scrollBarHorizontal ) if ( scrollBarHorizontal )
{ {
ScrollBarH = new CGUIScrollBar( true, Environment, this, -1, ScrollBarH = new CGUIScrollBar( true, Environment, this, -1,
core::rect<s32>( 0, RelativeRect.getHeight() - s, RelativeRect.getWidth() - s, RelativeRect.getHeight() ), core::rect<s32>( 0,
!clip ); RelativeRect.getHeight() - s,
RelativeRect.getWidth() - s,
RelativeRect.getHeight()
), !clip );
ScrollBarH->drop(); ScrollBarH->drop();
ScrollBarH->setSubElement(true); ScrollBarH->setSubElement(true);
...@@ -583,10 +587,24 @@ void CGUITreeView::recalculateItemHeight() ...@@ -583,10 +587,24 @@ void CGUITreeView::recalculateItemHeight()
} }
if ( ScrollBarV ) if ( ScrollBarV )
ScrollBarV->setMax( core::max_(0,TotalItemHeight - AbsoluteRect.getHeight()) ); {
s32 diffHor = TotalItemHeight - AbsoluteRect.getHeight();
if ( ScrollBarH )
{
diffHor += ScrollBarH->getAbsolutePosition().getHeight();
}
ScrollBarV->setMax( core::max_( 0, diffHor) );
}
if ( ScrollBarH ) if ( ScrollBarH )
ScrollBarH->setMax( core::max_(0, TotalItemWidth - AbsoluteRect.getWidth()) ); {
s32 diffVert = TotalItemWidth - AbsoluteRect.getWidth();
if ( ScrollBarV )
{
// TODO: not sure yet if it needs handling
}
ScrollBarH->setMax( core::max_( 0, diffVert ) );
}
} }
...@@ -630,7 +648,6 @@ bool CGUITreeView::OnEvent( const SEvent &event ) ...@@ -630,7 +648,6 @@ bool CGUITreeView::OnEvent( const SEvent &event )
break; break;
case EMIE_LMOUSE_PRESSED_DOWN: case EMIE_LMOUSE_PRESSED_DOWN:
if( ( ScrollBarV && ScrollBarV->getAbsolutePosition().isPointInside( p ) && ScrollBarV->OnEvent( event ) ) || if( ( ScrollBarV && ScrollBarV->getAbsolutePosition().isPointInside( p ) && ScrollBarV->OnEvent( event ) ) ||
( ScrollBarH && ScrollBarH->getAbsolutePosition().isPointInside( p ) && ScrollBarH->OnEvent( event ) ) ( ScrollBarH && ScrollBarH->getAbsolutePosition().isPointInside( p ) && ScrollBarH->OnEvent( event ) )
) )
...@@ -665,6 +682,7 @@ bool CGUITreeView::OnEvent( const SEvent &event ) ...@@ -665,6 +682,7 @@ bool CGUITreeView::OnEvent( const SEvent &event )
} }
} }
break; break;
default: default:
break; break;
} }
...@@ -697,9 +715,10 @@ void CGUITreeView::mouseAction( s32 xpos, s32 ypos, bool onlyHover /*= false*/ ) ...@@ -697,9 +715,10 @@ void CGUITreeView::mouseAction( s32 xpos, s32 ypos, bool onlyHover /*= false*/ )
ypos -= AbsoluteRect.UpperLeftCorner.Y; ypos -= AbsoluteRect.UpperLeftCorner.Y;
// find new selected item. // find new selected item.
if( ItemHeight != 0 && ScrollBarV ) s32 scrollBarVPos = ScrollBarV ? ScrollBarV->getPos() : 0;
if( ItemHeight != 0 )
{ {
selIdx = ( ( ypos - 1 ) + ScrollBarV->getPos() ) / ItemHeight; selIdx = ( ( ypos - 1 ) + scrollBarVPos ) / ItemHeight;
} }
hitNode = 0; hitNode = 0;
...@@ -716,6 +735,8 @@ void CGUITreeView::mouseAction( s32 xpos, s32 ypos, bool onlyHover /*= false*/ ) ...@@ -716,6 +735,8 @@ void CGUITreeView::mouseAction( s32 xpos, s32 ypos, bool onlyHover /*= false*/ )
++n; ++n;
} }
s32 scrollBarHPos = ScrollBarH ? ScrollBarH->getPos() : 0;
xpos += scrollBarHPos; // correction for shift
if( hitNode && xpos > hitNode->getLevel() * IndentWidth ) if( hitNode && xpos > hitNode->getLevel() * IndentWidth )
{ {
Selected = hitNode; Selected = hitNode;
...@@ -768,7 +789,6 @@ void CGUITreeView::mouseAction( s32 xpos, s32 ypos, bool onlyHover /*= false*/ ) ...@@ -768,7 +789,6 @@ void CGUITreeView::mouseAction( s32 xpos, s32 ypos, bool onlyHover /*= false*/ )
} }
} }
//! draws the element and its children //! draws the element and its children
void CGUITreeView::draw() void CGUITreeView::draw()
{ {
...@@ -789,41 +809,37 @@ void CGUITreeView::draw() ...@@ -789,41 +809,37 @@ void CGUITreeView::draw()
} }
// draw background // draw background
core::rect<s32> frameRect( AbsoluteRect ); core::rect<s32> frameRect( AbsoluteRect );
if( DrawBack ) if( DrawBack )
{ {
driver->draw2DRectangle( skin->getColor( EGDC_3D_HIGH_LIGHT ), frameRect, driver->draw2DRectangle( skin->getColor( EGDC_3D_HIGH_LIGHT ), frameRect, clipRect );
clipRect );
} }
// draw the border // draw the border
frameRect.LowerRightCorner.Y = frameRect.UpperLeftCorner.Y + 1; frameRect.LowerRightCorner.Y = frameRect.UpperLeftCorner.Y + 1;
driver->draw2DRectangle( skin->getColor( EGDC_3D_SHADOW ), frameRect, driver->draw2DRectangle( skin->getColor( EGDC_3D_SHADOW ), frameRect, clipRect );
clipRect );
frameRect.LowerRightCorner.Y = AbsoluteRect.LowerRightCorner.Y; frameRect.LowerRightCorner.Y = AbsoluteRect.LowerRightCorner.Y;
frameRect.LowerRightCorner.X = frameRect.UpperLeftCorner.X + 1; frameRect.LowerRightCorner.X = frameRect.UpperLeftCorner.X + 1;
driver->draw2DRectangle( skin->getColor( EGDC_3D_SHADOW ), frameRect, driver->draw2DRectangle( skin->getColor( EGDC_3D_SHADOW ), frameRect, clipRect );
clipRect );
frameRect = AbsoluteRect; frameRect = AbsoluteRect;
frameRect.UpperLeftCorner.X = frameRect.LowerRightCorner.X - 1; frameRect.UpperLeftCorner.X = frameRect.LowerRightCorner.X - 1;
driver->draw2DRectangle( skin->getColor( EGDC_3D_HIGH_LIGHT ), frameRect, driver->draw2DRectangle( skin->getColor( EGDC_3D_HIGH_LIGHT ), frameRect, clipRect );
clipRect );
frameRect = AbsoluteRect; frameRect = AbsoluteRect;
frameRect.UpperLeftCorner.Y = AbsoluteRect.LowerRightCorner.Y - 1; frameRect.UpperLeftCorner.Y = AbsoluteRect.LowerRightCorner.Y - 1;
frameRect.LowerRightCorner.Y = AbsoluteRect.LowerRightCorner.Y; frameRect.LowerRightCorner.Y = AbsoluteRect.LowerRightCorner.Y;
driver->draw2DRectangle( skin->getColor( EGDC_3D_HIGH_LIGHT ), frameRect, driver->draw2DRectangle( skin->getColor( EGDC_3D_HIGH_LIGHT ), frameRect, clipRect );
clipRect );
// draw items // draw items
core::rect<s32> clientClip( AbsoluteRect ); core::rect<s32> clientClip( AbsoluteRect );
clientClip.UpperLeftCorner.Y += 1;
clientClip.UpperLeftCorner.X += 1; clientClip.UpperLeftCorner.X += 1;
clientClip.UpperLeftCorner.Y += 1;
clientClip.LowerRightCorner.X = AbsoluteRect.LowerRightCorner.X; clientClip.LowerRightCorner.X = AbsoluteRect.LowerRightCorner.X;
clientClip.LowerRightCorner.Y -= 1; clientClip.LowerRightCorner.Y -= 1;
...@@ -854,7 +870,6 @@ void CGUITreeView::draw() ...@@ -854,7 +870,6 @@ void CGUITreeView::draw()
if ( ScrollBarH ) if ( ScrollBarH )
{ {
frameRect.UpperLeftCorner.X -= ScrollBarH->getPos(); frameRect.UpperLeftCorner.X -= ScrollBarH->getPos();
frameRect.LowerRightCorner.X -= ScrollBarH->getPos();
} }
if( frameRect.LowerRightCorner.Y >= AbsoluteRect.UpperLeftCorner.Y if( frameRect.LowerRightCorner.Y >= AbsoluteRect.UpperLeftCorner.Y
...@@ -862,7 +877,10 @@ void CGUITreeView::draw() ...@@ -862,7 +877,10 @@ void CGUITreeView::draw()
{ {
if( node == Selected ) if( node == Selected )
{ {
driver->draw2DRectangle( skin->getColor( EGDC_HIGH_LIGHT ), frameRect, &clientClip ); // selection box beginning from far left
core::rect<s32> copyFrameRect( frameRect ); // local copy to keep original untouched
copyFrameRect.UpperLeftCorner.X = AbsoluteRect.UpperLeftCorner.X + 1;
driver->draw2DRectangle( skin->getColor( EGDC_HIGH_LIGHT ), copyFrameRect, &clientClip );
} }
if( node->hasChildren() ) if( node->hasChildren() )
...@@ -880,40 +898,35 @@ void CGUITreeView::draw() ...@@ -880,40 +898,35 @@ void CGUITreeView::draw()
rc.UpperLeftCorner.Y = expanderRect.UpperLeftCorner.Y; rc.UpperLeftCorner.Y = expanderRect.UpperLeftCorner.Y;
rc.LowerRightCorner.X = expanderRect.LowerRightCorner.X; rc.LowerRightCorner.X = expanderRect.LowerRightCorner.X;
rc.LowerRightCorner.Y = rc.UpperLeftCorner.Y + 1; rc.LowerRightCorner.Y = rc.UpperLeftCorner.Y + 1;
driver->draw2DRectangle( skin->getColor( EGDC_3D_SHADOW ), rc, driver->draw2DRectangle( skin->getColor( EGDC_3D_DARK_SHADOW ), rc, clipRect );
clipRect );
// box left line // box left line
rc.UpperLeftCorner.X = expanderRect.UpperLeftCorner.X; rc.UpperLeftCorner.X = expanderRect.UpperLeftCorner.X;
rc.UpperLeftCorner.Y = expanderRect.UpperLeftCorner.Y; rc.UpperLeftCorner.Y = expanderRect.UpperLeftCorner.Y;
rc.LowerRightCorner.X = rc.UpperLeftCorner.X + 1; rc.LowerRightCorner.X = rc.UpperLeftCorner.X + 1;
rc.LowerRightCorner.Y = expanderRect.LowerRightCorner.Y; rc.LowerRightCorner.Y = expanderRect.LowerRightCorner.Y;
driver->draw2DRectangle( skin->getColor( EGDC_3D_SHADOW ), rc, driver->draw2DRectangle( skin->getColor( EGDC_3D_DARK_SHADOW ), rc, clipRect );
clipRect );
// box right line // box right line
rc.UpperLeftCorner.X = expanderRect.LowerRightCorner.X - 1; rc.UpperLeftCorner.X = expanderRect.LowerRightCorner.X - 1;
rc.UpperLeftCorner.Y = expanderRect.UpperLeftCorner.Y; rc.UpperLeftCorner.Y = expanderRect.UpperLeftCorner.Y;
rc.LowerRightCorner.X = rc.UpperLeftCorner.X + 1; rc.LowerRightCorner.X = rc.UpperLeftCorner.X + 1;
rc.LowerRightCorner.Y = expanderRect.LowerRightCorner.Y; rc.LowerRightCorner.Y = expanderRect.LowerRightCorner.Y;
driver->draw2DRectangle( skin->getColor( EGDC_3D_SHADOW ), rc, driver->draw2DRectangle( skin->getColor( EGDC_3D_DARK_SHADOW ), rc, clipRect );
clipRect );
// box bottom line // box bottom line
rc.UpperLeftCorner.X = expanderRect.UpperLeftCorner.X; rc.UpperLeftCorner.X = expanderRect.UpperLeftCorner.X;
rc.UpperLeftCorner.Y = expanderRect.LowerRightCorner.Y - 1; rc.UpperLeftCorner.Y = expanderRect.LowerRightCorner.Y - 1;
rc.LowerRightCorner.X = expanderRect.LowerRightCorner.X; rc.LowerRightCorner.X = expanderRect.LowerRightCorner.X;
rc.LowerRightCorner.Y = rc.UpperLeftCorner.Y + 1; rc.LowerRightCorner.Y = rc.UpperLeftCorner.Y + 1;
driver->draw2DRectangle( skin->getColor( EGDC_3D_SHADOW ), rc, driver->draw2DRectangle( skin->getColor( EGDC_3D_DARK_SHADOW ), rc, clipRect );
clipRect );
// horizontal '-' line // horizontal '-' line
rc.UpperLeftCorner.X = expanderRect.UpperLeftCorner.X + 2; rc.UpperLeftCorner.X = expanderRect.UpperLeftCorner.X + 2;
rc.UpperLeftCorner.Y = expanderRect.UpperLeftCorner.Y + ( expanderRect.getHeight() >> 1 ); rc.UpperLeftCorner.Y = expanderRect.UpperLeftCorner.Y + ( expanderRect.getHeight() >> 1 );
rc.LowerRightCorner.X = rc.UpperLeftCorner.X + expanderRect.getWidth() - 4; rc.LowerRightCorner.X = rc.UpperLeftCorner.X + expanderRect.getWidth() - 4;
rc.LowerRightCorner.Y = rc.UpperLeftCorner.Y + 1; rc.LowerRightCorner.Y = rc.UpperLeftCorner.Y + 1;
driver->draw2DRectangle( skin->getColor( EGDC_BUTTON_TEXT ), rc, driver->draw2DRectangle( skin->getColor( EGDC_BUTTON_TEXT ), rc, clipRect );
clipRect );
if( !node->getExpanded() ) if( !node->getExpanded() )
{ {
...@@ -922,8 +935,7 @@ void CGUITreeView::draw() ...@@ -922,8 +935,7 @@ void CGUITreeView::draw()
rc.UpperLeftCorner.Y = expanderRect.UpperLeftCorner.Y + 2; rc.UpperLeftCorner.Y = expanderRect.UpperLeftCorner.Y + 2;
rc.LowerRightCorner.X = rc.UpperLeftCorner.X + 1; rc.LowerRightCorner.X = rc.UpperLeftCorner.X + 1;
rc.LowerRightCorner.Y = rc.UpperLeftCorner.Y + expanderRect.getHeight() - 4; rc.LowerRightCorner.Y = rc.UpperLeftCorner.Y + expanderRect.getHeight() - 4;
driver->draw2DRectangle( skin->getColor( EGDC_BUTTON_TEXT ), rc, driver->draw2DRectangle( skin->getColor( EGDC_BUTTON_TEXT ), rc, clipRect );
clipRect );
} }
} }
...@@ -989,8 +1001,7 @@ void CGUITreeView::draw() ...@@ -989,8 +1001,7 @@ void CGUITreeView::draw()
rc.LowerRightCorner.X = frameRect.UpperLeftCorner.X - 2; rc.LowerRightCorner.X = frameRect.UpperLeftCorner.X - 2;
} }
rc.LowerRightCorner.Y = rc.UpperLeftCorner.Y + 1; rc.LowerRightCorner.Y = rc.UpperLeftCorner.Y + 1;
driver->draw2DRectangle( skin->getColor( EGDC_3D_SHADOW ), rc, driver->draw2DRectangle( skin->getColor( EGDC_3D_SHADOW ), rc, clipRect );
clipRect );
if( node->getParent() != Root ) if( node->getParent() != Root )
{ {
...@@ -1004,8 +1015,7 @@ void CGUITreeView::draw() ...@@ -1004,8 +1015,7 @@ void CGUITreeView::draw()
rc.UpperLeftCorner.Y = frameRect.UpperLeftCorner.Y - ( frameRect.getHeight() >> 1 ); rc.UpperLeftCorner.Y = frameRect.UpperLeftCorner.Y - ( frameRect.getHeight() >> 1 );
} }
rc.LowerRightCorner.X = rc.UpperLeftCorner.X + 1; rc.LowerRightCorner.X = rc.UpperLeftCorner.X + 1;
driver->draw2DRectangle( skin->getColor( EGDC_3D_SHADOW ), rc, driver->draw2DRectangle( skin->getColor( EGDC_3D_SHADOW ), rc, clipRect );
clipRect );
// the vertical lines of all parents // the vertical lines of all parents
IGUITreeViewNode* nodeTmp = node->getParent(); IGUITreeViewNode* nodeTmp = node->getParent();
...@@ -1016,8 +1026,7 @@ void CGUITreeView::draw() ...@@ -1016,8 +1026,7 @@ void CGUITreeView::draw()
rc.LowerRightCorner.X -= IndentWidth; rc.LowerRightCorner.X -= IndentWidth;
if( nodeTmp != nodeTmp->getParent()->getLastChild() ) if( nodeTmp != nodeTmp->getParent()->getLastChild() )
{ {
driver->draw2DRectangle( skin->getColor( EGDC_3D_SHADOW ), rc, driver->draw2DRectangle( skin->getColor( EGDC_3D_SHADOW ), rc, clipRect );
clipRect );
} }
nodeTmp = nodeTmp->getParent(); nodeTmp = nodeTmp->getParent();
} }
......
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