我想构建一个能够垂直(上下)和水平(左右)滑动的控件。当然,用户将设置这个小部件的样式。 问题是,当我用正确的方向水平滑动测试小部件时,文本留下了一些绘制的痕迹。用这种方法我画了文字: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!");
}
有人能告诉我跟踪标记有什么问题吗?
这将无法正常工作。我已经试过了。 – 2011-03-12 14:00:09