Question about modifying the code for the curve tool
Greets! I'm new here. :)
Earlier today I had an idea for an improvement to the curve drawing tool that would speed up my drawing workflow considerably and make it a lot more practical to draw things quickly and precisely with a mouse. Here's what I was thinking:
When you're editing a curve, there's a button on the toolbar that sets the nodes along the curve to "auto-smooth". I discovered this a couple of days ago and instantly fell in love with it. At any rate, I was thinking it would be really nice to be able to draw auto-smoothed points with the curve drawing tool, perhaps by holding shift when you click the button, or holding shift, then clicking, dragging, and releasing. Non-auto-smoothed points are great if you want fine control, but if you're trying to lay down some clean-looking curves quickly, auto-smoothing seems to be the way to go. It would be really nice if I could draw them as I go, rather than just clicking the mouse and crating line segments, then going back and converting all of them. Hopefully I'm making sense so far. :)
At any rate, I thought I'd poke around the 0.48 code and see if I could implement this feature myself, but I ran into an issue. Specifically, it appears that the code for drawing a curve initially adds points directly into the underlying curve data structure, whereas the code that distinguishes between normal curve points and auto-smoothed points is actually part of the user interface, and not part of the curve itself. Thus, when you add a point onto a curve, there doesn't appear (at least not at first glance) to be a way to easily get hold of the Node object and set it to auto-smooth mode.
Here's what I've gleaned from looking at the code thus far:
When you add a point by clicking the mouse button, it happens around pen-context.cpp:1272, where it calls pc->red_curve->curveto(...). The node type, however, is actually set from the MultiPathManipulator class, which I don't appear to have access to in pen-context.cpp. Is there a simple way of doing this?
Also, kudos for writing code that's clear enough that I have some idea of what's going on after looking at it for half an hour. :)
Peace, Bart K. http://opengameart.org
2011/3/4 Bart Kelsey <elbarto@...400...>:
At any rate, I thought I'd poke around the 0.48 code and see if I could implement this feature myself, but I ran into an issue. Specifically, it appears that the code for drawing a curve initially adds points directly into the underlying curve data structure, whereas the code that distinguishes between normal curve points and auto-smoothed points is actually part of the user interface, and not part of the curve itself. Thus, when you add a point onto a curve, there doesn't appear (at least not at first glance) to be a way to easily get hold of the Node object and set it to auto-smooth mode.
That's correct. Nodes only exist in the node tool. The node type information is stored in the XML attribute sodipodi:nodetypes. See PathManipulator::_createControlPointsFromGeometry() to see its format. You would have to store information in this attribute when drawing with the node tool. But that's not all; the code that determines the positions of handles of an auto node is also present only in the node tool. You would have to move it to a common location and use it in the Bezier tool to set handle positions, so that they match the node type information.
A better possible implementation involves improving SPPath, more specifically adding a method for setting node types that would fix the handles automatically. Currently we directly put values in the XML, which is not good.
Regards, Krzysztof
participants (2)
-
Bart Kelsey
-
Krzysztof Kosiński