-----Original Message----- From: Maximilian Albert [mailto:Anhalter42@...173...] Sent: woensdag 18 juni 2008 12:45 To: Engelen, J.B.C. (Johan) Cc: inkscape-devel@lists.sourceforge.net Subject: Re: Temporary canvas items
J.B.C.Engelen@...1578... schrieb:
Hi Max,
- How can I create a temporary canvas item to display a helper path having a given shape?
For this, you should have a look at the path flash code in
function > "sp_node_context_flash_path".
Thanks. I had seen this function, but it simply takes an *existing* item and converts it to a temporary path. This is not so difficult since in this case we can extract the existing SPCurve information from the item. So my question should have been more precise: What's the recommended way to create temporary path "from scratch" (i.e., without necessarily an item existing that has the required path information)?
Can I easily construct the required SPCurve directly? Or should I create a BPath first which is converted to a curve (if so, how would I do this)? Or must I create a separate SPItem from the desired path data and pass this on to sp_nodepath_generate_helperpath()? I gues my question boils down to this: Which of these things is lowest in the hierarchy and still has convenient creation functions?
Go with sp_canvas_bpath_new (look up sp_nodepath_generate_helperpath). Generating an SPCurve is/should be easy; there are two ways: 1. create Geom::PathVector and then construct SPCurve with it. (I'd take this route, but it might not be so obvious to do for the first time, have a look at display/curve.cpp's moveto, lineto, curveto, closepath. Ignore all code about NArtBpath, so only look at _pathv) 2. construct empty SPCurve and then create the path using curve->moveto, lineto and/or curveto. Have a look at display/curve.h ; documentation per function can be found in curve.cpp.
BTW, how is SPCanvasItem related to SPCurve/SPItem etc.? How do I "correctly" create an SPCanvasItem from given path data? In particular, what do I specify as the parent SPCanvasGroup?
For bpaths on canvas: SPCanvasItem is created from SPCurve and keeps a reference to the SPCurve after that. When sp_canvas_item_request_update is called on the canvasitem, it re-reads the SPCurve data and puts that on screen. SPDesktop has a number of SPCanvasGroups, pick one :P For temp items, I take sp_desktop_tempgroup(desktop). I think there is also a group for "scratchpad" things that you might want to use.
- How can I display text using this mechanism?
Don't know if this is easy to do. The temp canvas item
machinery only > works with SPCanvasItem. Perhaps it is good to create an SPCanvasItem > that renders text, because it can be used for many other things.
Yes. My question is how the "... that renders text" part would work.
Maybe Cairo can help you out there... (such for outline rendering code, that uses cairo for rendering shapes)
-johan