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

Cellophane doesn't work with gradients #2

Open
takikawa opened this issue Jul 7, 2015 · 10 comments
Open

Cellophane doesn't work with gradients #2

takikawa opened this issue Jul 7, 2015 · 10 comments

Comments

@takikawa
Copy link
Contributor

takikawa commented Jul 7, 2015

The cellophane function doesn't appear to work as expected when gradients are used, e.g., in a dc pict.

Example:

#lang racket

(require pict
         racket/draw)

(define (rectangle/2t width height 
                      #:border-width [border-width 1]
                      #:border-color [border-color "black"]
                      #:color-1 [color-1 "white"]
                      #:color-2 [color-2 "black"])
  (dc (λ (dc dx dy)
        (define old-brush (send dc get-brush))
        (define old-pen (send dc get-pen))
        (define gradient
          (make-object linear-gradient%
                       dx dy
                       dx (+ dy height)
                       (list (list 0 (make-object color% color-1))
                             (list 1 (make-object color% color-2)))))
        (send dc set-brush (new brush% [gradient gradient]))
        (send dc set-pen (new pen% [width border-width]
                                   [color border-color]))
        (send dc draw-rectangle dx dy width height)
        (send dc set-brush old-brush)
        (send dc set-pen old-pen))
      width height))

(cc-superimpose (disk 20)
                (cellophane (rectangle/2t 100 100 #:color-1 "green") 0.5))

(cc-superimpose (disk 20)
                (cellophane (colorize (filled-rectangle 100 100) "green") 0.5))

I expected the first image this produces to show a disk under a translucent gradiented rectangle.

@rfindler
Copy link
Member

rfindler commented Jul 7, 2015

Cellophane just sets the alpha (via set-alpha) so presumably this is
actually a racket/gui issue (and can be demonstrated via only the dc
combinator)?

@spdegabrielle
Copy link
Member

is this still an issue? Please consider adding the label good first issue so it is findable:

Issues labeled good first issue in in Racket GitHub repositories

@rfindler
Copy link
Member

I'm not sure if it is a good first issue. It might be for someone that knows a lot about GUI toolkits. Also, it probably is a racket/gui issue, not a pict issue (but someone would need to verify that by making a smaller program).

@soegaard
Copy link
Member

soegaard commented Jun 18, 2020 via email

@rfindler
Copy link
Member

Just to make sure I'm following: you're saying that setting the dc's alpha is not supposed to affect the brush/pen's gradient and so functions like rectangle/2t should be expected to explicitly account for that if they want to respect functions like cellophane?

The alternative would be to have cellophane explicitly adjust the gradient (if it finds one)? It does at least seem like that explicit adjustment is possible, based on the methods. (I have no idea if it is a bad idea, however!)

@soegaard
Copy link
Member

soegaard commented Jun 18, 2020 via email

@soegaard
Copy link
Member

soegaard commented Jun 18, 2020 via email

@soegaard
Copy link
Member

soegaard commented Jun 18, 2020 via email

@mflatt
Copy link
Member

mflatt commented Jun 18, 2020

I think that's almost certainly a good repair.

The only problem I see is that some existing program might rely on the alpha setting not affecting gradients (and maybe including an explicit alpha in the gradient construction to compensate). But I think the risk of breaking old programs in a significant way is small enough that it's worth fixing gradient brushes.

@soegaard
Copy link
Member

This is the result after the [a (* (color-alpha c) (get-alpha))] change.

image

This is the result of the original program:

image

/Jens Axel
(who keeps forgetting that Github can't handle images when sent through gmail)

soegaard added a commit to racket/draw that referenced this issue Jun 18, 2020
mflatt pushed a commit to racket/draw that referenced this issue Jun 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants