【发布时间】:2016-04-10 18:34:55
【问题描述】:
我想用箭头画一条线。线可以有任何角度。如何在 SWT 中实现?
我在AWT 找到了类似的帖子。我想把它转换成SWT。但是面临将以下方法转换为 SWT 的问题。特别是在以下行中:
at.concatenate(AffineTransform.getRotateInstance(angle));
这是来自this post的方法
void drawArrow(Graphics g1, int x1, int y1, int x2, int y2) {
Graphics2D g = (Graphics2D) g1.create();
double dx = x2 - x1, dy = y2 - y1;
double angle = Math.atan2(dy, dx);
int len = (int) Math.sqrt(dx*dx + dy*dy);
AffineTransform at = AffineTransform.getTranslateInstance(x1, y1);
at.concatenate(AffineTransform.getRotateInstance(angle));
g.transform(at);
// Draw horizontal arrow starting in (0, 0)
g.drawLine(0, 0, len, 0);
g.fillPolygon(new int[] {len, len-ARR_SIZE, len-ARR_SIZE, len}, new int[] {0, -ARR_SIZE, ARR_SIZE, 0}, 4);
}
【问题讨论】:
-
Eclipse GEF 可能有东西