Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for transparent overlays #175

Open
mikekben opened this issue Sep 12, 2022 · 3 comments
Open

Support for transparent overlays #175

mikekben opened this issue Sep 12, 2022 · 3 comments

Comments

@mikekben
Copy link

mikekben commented Sep 12, 2022

Is it possible to add support for an overlay-like operation of "erasing" by overlaying a transparent image? For example, this would be useful for overlaying a doughnut shape over a colorful background while maintaining the background behind the center of the doughnut:

(overlay
 (circle 30 'solid 'green)
 (circle 50 'solid 'red)
 (above (rectangle 200 100 'solid 'green)
        (rectangle 200 100 'solid 'blue)))

but with a transparent rather than solid green background for the center of the doughnut shape, allowing the green-blue split to be visible. I can think of two ways to expand the API to support this functionality:

  • Add a new erase function
    (erase image scene) where scene is the background, and image is the area to be replaced by transparent pixels. The color of image could be ignored, or perhaps the function could require that the color of image is 'transparent
  • Add an 'overwrite mode for existing functions
    (circle 30 'overwrite 'transparent) This option may introduce lots of corner cases for existing functions, and the 'overwrite mode would be ignored in all cases except during an overlay.

Looking through the existing API, it seems that implementing this functionality could closely follow the existing overlay implementation, but I hope that others can suggest some additional feedback and propose better ways to proceed!

@rfindler
Copy link
Member

rfindler commented Sep 12, 2022

The library is built on top of dc<%>, which is itself built on top of platform-specific drawing code provided by the underlying operating system. So I think that an operation that would require, eg, actually calculating where circles get drawn is probably not on the table. That said, there may be some more clever way to use regions and clipping or just the existing calls somehow to get this effect, I'm not sure.

@sorawee
Copy link
Contributor

sorawee commented Sep 12, 2022

Specifically for donut, you can kinda hack it by using pen.

Screen Shot 2022-09-12 at 11 55 30 AM

(define donut
  (circle 20
          "outline"
          (make-pen "goldenrod" 10 "solid" "round" "round")))

(overlay donut
         (triangle 200 "solid" "red"))

@rfindler
Copy link
Member

Thinking a little bit more about this, it may be possible to leverage the fact that the clipping region in the underlying dc is a region (which supports union operations with anything that can be drawn via a path) that might allow something cool to be done here. I'm probably not going to tackle it soon but just thought I'd mention it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants