On 6/8/2016 10:26 PM, David Christiansen wrote:
What I mean is that I'm using draw-pict to cause the contents of a pict to be drawn on a dc<%> that I get from a bitmap%. The bitmap is initialized empty and transparent, and then the pict is drawn to it. I can tell which pixels are affected by the drawing by seeing if they are still transparent.
I think I'm not being clear. The word "draw" here is overloaded and confusing ... I going to try to avoid it below.
If you are using pen and brush to paint a picture [as opposed to loading a pre-made image file], then pen strokes in your painting can be used to define the user click area(s). I don't have a ready example: as I said previously, I haven't done much GUI/graphics in Racket ... but glancing at the documentation it appears that most of the GDI functions I am familiar with are represented.
The assumption is that the clickable areas are closed figures that COULD BE outlined using a pen. The outline actually does not need to be rendered in the image [or it could be transparent, or the same color as the background] ... you only need to know where the outline should be.
You create the outline for the click area indirectly using a dc-path% object. Paths are off-screen "scripts" that record intended pen strokes without actually drawing anything. The completed path can be rendered using the dc% *draw-path* function.
The dc-path% can be used to create a region% object (using region% *set-path*) which will represent the area enclosed by the outline. The notion of "enclosed" gets a little weird if the outline isn't a simple closed figure, but for most uses it is straightforward. Regions can be composed like sets using union, intersection and difference to define areas having arbitrarily complex shapes.
[Windows GDI has a "fill region" call which paints a region using an arbitrary brush. Racket doesn't appear to implement that, but it can be synthesized using *set-clipping-region* and rendering the region's bounding box with *draw-rectangle* (with suitable pen and brush). You can use this to visualize the area represented by the region.]
Once you have a region% representing the clickable area(s), you can ask it directly whether mouse coordinates are inside it. You can use separate regions to distinguish different click areas, or create a single region that represents a group of areas if you only need to know that some area was clicked and not specifically which one.
Hope this helps. If it isn't viable in your situation, then at least you can say you learned a new trick. :-)
George -- You received this message because you are subscribed to the Google Groups "Racket Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to racket-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.