开发者

What language would you choose to create a vector drawing interface?

开发者 https://www.devze.com 2023-04-12 22:20 出处:网络
I have a desktop application project which involves a drawing component. Base language isn\'t choosed yet.

I have a desktop application project which involves a drawing component. Base language isn't choosed yet.

Actions required for the drawing are the following :

  • Point & click to draw sticks and curves.
  • Gallery of shapes to add.
  • Select components and edit their properties (thickness, length, metadata)

All I can think of is SVG+Javascript, since I used to work for the web until now. And I would like a broader point of view, more choice.

Please do not argue on which language is theorically best. Instead, tell a story : which one did you used, for what kind of project, and what seemed easy or difficult to you.

Thanks for sharing your exper开发者_如何学Goience :)


Given the requirement there is only one language I'd use: Tcl. The Tk widget library has an excellent canvas widget which is vector based and is very easy to use. It is event based so feels very similar to javascript in terms of UI programming.

Here's code for point-and-click line drawing:

First, creating the canvas is simply:

canvas .c
pack .c

Now code for point and click line drawing:

set currentObject ""

set line {
  set ::currentObject [.c create line %x %y %x %y]

  bind . <Motion> {
    .c coords $currentObject [list %x %y %%x %%y]
  }
}

Now bind the line drawing code to mousedown event:

bind . <ButtonPress-1> $line

Just don't forget to handle the mouseup event as well:

bind . <ButtonRelease-1> {
  bind . <Motion> {}
}

That's just about a dozen lines of code. Which is another reason I usually turn to Tcl for this kind of thing: it lets you do a lot with very little code.


WPF is all about graphical stuff, including vectors.


There is of course the Logo programming language. It sounds like a joke, and in fact, I thought of it as a joke first, but you may find some use for it.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号