[cairo] Re: drawlist type functionality?
Mike Emmel
mike.emmel at gmail.com
Mon Apr 4 16:17:47 PDT 2005
I'm getting the cairo list as a digest I changed that so
I can respond correctly qouted..
pete at shinners.org---->
I've got to study up on the Cairo API a bit more, although I see it's
getting some good reorganization at the moment.
I'm curious to see what sort of data is temporarily created as the
drawing calls are made. In the future it could be spectacular to save
these structures and recycle them on repeated calls. Although I'm not
certain this is entirely possible since the Cairo context can be
configured for just about anything before the drawlist is called. These
are also likely backend specific.
<---pete at shinners.org
Your right the reuse code would probably be backend specific but
thats okay it can be handled in the engine.
pete at shinners.org---->
I was thinking the drawlists could be recorded as a custom backend.
Again, I want to get more comfortable with the API before getting into
this. Coming from the python end..
# create a "bowtie" context
ctx = cairo.Context()
drawlist = cairo.Drawlist()
ctx.set_target_drawlist(drawlist)
ctx.move_to(0, 0)
ctx.line_to(1, 1)
ctx.line_to(1, 0)
ctx.line_to(0, 1)
ctx.close_path()
<----pete at shinners.org
I was thinking of a two level system immutable draw objects and
containers for those that can be edited thus you would create a draw
list thats immutable and it would be added to a "container" that
allowed you to add removed drawlists and apply some rules for there
interaction probably for example all members of a container whould
share the same cario context for example. Thats where reinitializing
the context becomes interesting.
So out would havea draw list container that handled "global"
information and you could add remove the drawLists. These lists are
reference counted and can exist in multiple containers.
For example..
# create a "bowtie" context
ctx = cairo.Context()
DrawContainer con = cairo.drawContainer(ctx)
container.setBounds(0,0,5000,5000) //max size
container.setViewport(0,0,500,500) // visible size
container.setClip(0,0,100,100) // current drawing area
drawlist = cairo.Drawlist()
drawlist.move_to(0, 0)
drawlist.line_to(1, 1)
drawlist.line_to(1, 0)
drawlist.line_to(0, 1)
drawlist.close_path()
//add drawlist with x y offset could be a affine transform
id= container.draw(drawlist,20,20)
//reset the container clip
container.setClip( 10,10,10,10)
drawlist2 = cairo.DrawList()
drawList.drawLine(0,0,100,100)
id2= container.add(drawList2)
and you can do a
container.remove(id)
or a
container.move(id,50,50)
container.hide(id)
container.show(id)
container.replace(id,id2)
etc ...
even potentially loops or animation requests.
Containers themselves can be drawlists so they can be nested..
They extend drawlists to allow the addition of child drawlists in
addition they probably should support scrolling in some way or at
least a viewport
So Container would have container methods of
set_bounds
set_clip
set_viewport
So you have attributes at the container level applied to all the
drawlists. The drawlists themselves have attributes container position etc.
You could potentially have ways to override the attributes.
The resemblence to some concepts in SVG is pure coincedence :)
Actually the core of a SVG engine is probably a good starting point.
More information about the cairo
mailing list