绘制曲线以在代号One GlassPane中制作箭头

时间:2019-04-04 22:38:08

标签: codenameone

在CodenameOne应用中,我需要在GlassPane中绘制弯曲的箭头。 GlassPane的使用不是强制性的,但是我已经在ContentPane中使用了某些图层,在LayeredPane中使用了某些图层,因此我认为GlassPane是确保箭头“位于”应用程序上方的最佳选择。

箭头应类似于以下箭头:

Arrow

Arrow

我想我可以创建一个算法来确定“开始”和“结束”点的绝对X和Y坐标,以及其他一些描述曲线的点(P0,P1,P2等)。例如:

Points of lines

Points of lines

我的问题是我不知道该怎么做。通常,在这种情况下,我不需要Codename One应用程序中的低级绘图。您能给我展示一个正确而完整的代码来绘制此图(假设知道起点,终点,P0,P1等的坐标)吗?谢谢。

1 个答案:

答案 0 :(得分:1)

手工很难做到这一点。我建议使用SVG通过诸如Sketch之类的工具或类似的矢量图形工具绘制这样的箭头。然后使用火烈鸟将其转换为图像:https://www.codenameone.com/blog/flamingo-svg-transcoder.html

或者,您也可以使用GeneralPath对其进行手动编码,例如:

GeneralPath gp = new GeneralPath();

// move to start of path
gp.move(x, y);

// draw the curve of the arrow, we use a control point around which
// the curve is drawn and curve to the destination of the line
gp.curveTo(contolX, controlY, destX, destY);

// Stroke defines how the shape is drawn it accepts the line width
// cap style, join style and miter limit
Stroke st = new Stroke(2, Stroke.CAP_SQUARE, Stroke.JOIN_MITER, 1);

// red
graphics.setColor(0xff00000);

// now we can draw the shape
graphics.drawShape(gp, st);