On Sat, Mar 23, 2013 at 1:18 AM, Ralf Werner <[email protected]> wrote:

> i would like to add Transparent Layers to FloatCanvas.

Is a "Layer" in this context a DrawObject that is semi-transparent?
i.e. uses the alpha channel?

Or something higher level -- an offscreen bitmap that is transparent
with some non-transparent things drawn on it, that can be layered.

>From the rest of your message, I think you mean Draw Objects that can
use alpha, but I want to be sure.

Note that you can already do this, but making custom DrawObjects:

http://trac.paulmcnett.com/floatcanvas/wiki/SmoothLines

and creating a GraphicsContext inside the _Draw method.

However, It looks like you are proposing updating the existing
DrawObjects to support Alpha, which I think is a good idea, and a long
time coming!

> For this to achieve at first step i would touch the current classes and add
> a Alpha value
> for the Color creation. For example something like this:
>
> def SetBrush(self, FillColor, FillStyle, Alpha = 255):
>
> def SetPen(self,LineColor,LineStyle,LineWidth, Alpha = 255):

This may be a good time to re-factor the DrawObject base class brush
and pen caching system -- by removing it -- I don't think it buys us
anything these days...

> class RectEllipse(XYObjectMixin, LineAndFillMixin, DrawObject):
>     def __init__(self, XY, WH,
>                  LineColor = "Black",
>                  LineStyle = "Solid",
>                  LineWidth    = 1,
>                  FillColor    = None,
>                  FillStyle    = "Solid",
>                  InForeground = False,
>                  LineAlpha = 255
>                  FillAlpha = 255):

> So the current API stays the same and will not broken.

Sounds good -- I love Python's names arguments -- it makes this kind
of extending so easy!

> My question is, to support the alpha drawing we must use the new
> GraphicsContext.
> Should i use the new GraphicsContext routines directly or can i use the GCDC
> Wrapper?
> The latter saves some amount of work.

Using a GCDC will not give us access to the full flexibility of the
GCs, but you are right, it will be a lot easier. So I suggest we go
that route..perhaps updating to full GraphicsContext support later.

Note: it may be worth doing some performance testing for how long it
takes to create a GC from a DC. In the example in the wiki I referred
to, the GC is created in the _draw method, so ti will get re-created
with every object draw -- but that may be very fast. In which case, it
would be pretty easy to simple add GC functionality to each DrawObject
as needed.

Another option is to pass in both a DC and GC to the _draw methods --
then they could use or not use them as needed. Or, have the _draw
method access the GC from the Canvas itself. When I first started all
this, I was trying to keep the code decoupled, so DrawObjects didn't
need to know much about the FloatCanvas, but as you would never need a
DRawObject without a FloatCanvas, maybe there is no point -- we could
simply pass the FloatCanvas instance in to the _draw methods, and the
code could use:

Canvas.mainDC
Canvas.HitTestDC
Canvas.GC

as is required for that DrawObject.

> My second question is, should i split the drawing routines in one for normal
> drawing
> and one for drawing in the hittest bitmap.

yes, that is probably required -- the HitTest bitmap requires that
each object be entirely drawn in one color. alpha has no use there,
and anti-aliasing can defeat the approach -- as the pixels along the
edges are a blend of the color with the background. So we'll need to
keep the hit-test drawing with regular DCs -- unless you can turn off
anti-aliasing with GCs -- not sure about that.

> An of topic question is, when objects in the drawing overlapps or objects
> are completly covered
> by other objects. What gives the hittest back? The last drawn object?

only the last drawn object -- there is a single hit-test buffer. each
object is drawn in a unique color, and the hit test is done by
checking the color of the pixel. So any given pixel can have only one
color, thus only one object.

There are times when it would be good to be able to know all of the
objects that may underly a pixel, but we'd need a different way to do
that. This way is very fast for doing the hit test though -- a real
advantage for capturing hits when moving the mouse.

And in most cases, what it does is reflect what the user sees -- they
are going to see only the top-drawn object, so it's clear what they
are clicking on. And if you don't want some objects to be clickable,
they can be turned off, so that the don't get drawn on the HitTest
buffer.

Great to have you on board enhancing FloatCanvas!

-Chris



-- 

Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R            (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

[email protected]
_______________________________________________
FloatCanvas mailing list
[email protected]
http://paulmcnett.com/cgi-bin/mailman/listinfo/floatcanvas

Reply via email to