draw2d库中的三角形

时间:2010-10-24 07:27:54

标签: java user-interface geometry swt draw2d

我无法理解org.eclipse.draw2d.Triangle的api。有一些操作领域:

protected int direction
    The direction this triangle will face. Possible values are PositionConstants.NORTH, PositionConstants.SOUTH, PositionConstants.EAST and PositionConstants.WEST.

protected int orientation
    The orientation of this triangle. Possible values are Orientable.VERTICAL and Orientable.HORIZONTAL. 

还有“三角形的点”。但是没有api可以直接操纵它们。 所以我可能需要一些例子来理解..(通过点或smt创建三角形)

感谢。

1 个答案:

答案 0 :(得分:1)

我不太了解API,但是从查看源代码来看,这个类看起来对生成“箭头”类型的三角形很有用,这些三角形指向上,下,左或右,具体取决于你是否指定北方,南,西或东分别为方向。

方向取决于方向,反之亦然。为了说明我的意思,这里是setDirection()的代码:

    public void setDirection(int value) {
            if ((value & (NORTH | SOUTH)) != 0)
                    orientation = VERTICAL;
            else
                    orientation = HORIZONTAL;
            direction = value;
            revalidate();
            repaint();
    }

如果您指定VERTICALNORTH方向,则方向设置为SOUTH,否则设置为HORIZONTAL

我认为你不能用这个类绘制任意三角形。