[英]Graphic problems in swt
我想構建一個小部件,它將能夠垂直(向上和向下)和水平(左側和右側)滑動。 當然,用戶將設置此小部件的樣式。 問題是,當我以向右水平滑動的方式測試小部件時,文本后面留下了一些繪制的軌跡。 通過這種方法,我可以繪制文本:
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!" );
}
有人可以告訴我跟蹤標記有什么問題嗎?
這是我解決問題的方法。 很簡單,但是可以正常工作:
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 );
Color color = gc.getForeground ( );
gc.setForeground ( getBackground ( ) );
gc.drawLine ( pX - 1 , pY , pX - 1 , point.y );
gc.setForeground ( color );
}
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!" );
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.