I want to build a widget which will be capable to slide vertical(up and down) and horizontal (left and right). Of course the user will set the styles of this widget.
The problem is that when I test the widget with horizontal sliding in right direction the text left some painted trace behind. With this method I paint the text:
private void paintText ( )
{
if ( getText ( ) != null )
{
Point point = gc.stringExtent ( getText ( ) );
if ( isHorizontalSlide )
{
if ( getMode ( ) == LEFT_MODE )
{
if ( pX + point.x + 1 == rectangle.x )
pX = rectangle.width;
gc.drawText ( getText ( ) , pX -- , pY );
}
else if ( getMode ( ) == RIGHT_MODE )
{
if ( pX == rectangle.width )
pX = rectangle.x - point.x + 1;
gc.drawText ( getText ( ) , pX ++ , pY );
}
else
{
if ( pX + point.x + 1 == rectangle.x )
pX = rectangle.width;
gc.drawText ( getText ( ) , pX -- , pY );
}
}
else if ( isVerticalSlide )
{
if ( getMode ( ) == UP_MODE )
{
if ( pY + point.y + 1 == rectangle.y )
pY = rectangle.height;
gc.drawText ( getText ( ) , pX , pY -- );
}
else if ( getMode ( ) == DOWN_MODE )
{
if ( pY == rectangle.height )
pY = rectangle.y - point.y + 1;
gc.drawText ( getText ( ) , pX , pY ++ );
}
else
{
if ( pY + point.y + 1 == rectangle.y )
pY = rectangle.height;
gc.drawText ( getText ( ) , pX , pY -- );
}
}
}
else
throw new NullPointerException ( "The text cannot be null!" );
}
Could somebody tell me what is the problem with the trace mark?
This is my solution of the problem. It’s simple but it’s work fine: