[racket] Can I make the frame% instances transparent?
Thanks.
This saved lots of time.
On Mon, Jan 20, 2014 at 10:39 AM, Matthew Flatt <mflatt at cs.utah.edu> wrote:
> The `frame%` class does not offer a transparency option, but on Mac OS
> X, you can use the FFI to make a frame transparent at the Cocoa
> NSWindow layer.
>
> Here's an example:
>
> --------------------------------------------------
>
> #lang racket/gui
> (require ffi/unsafe
> ffi/unsafe/objc)
>
> ;; Create the frame:
> (define f (new frame%
> [label "Example"]
> [width 200]
> [height 200]))
>
> ;; Add a transparent canvas that displays "Hello"
> (new canvas%
> [parent f]
> [style '(transparent)]
> [paint-callback (lambda (c dc)
> (send dc draw-text "Hello" 0 0))])
>
> ;; The `CGFloat` type depends on the platform:
> (define 64-bit? (= (ctype-sizeof _long) 8))
> (define _CGFloat (if 64-bit? _double _float))
>
> ;; Get an `NSWindow` from the `frame%` object:
> (define h (send f get-handle))
>
> ;; Set the background's transparency at the `NSWindow` level:
> (import-class NSColor)
> (tellv h setBackgroundColor: (tell NSColor
> colorWithRed: #:type _CGFloat 1.0
> green: #:type _CGFloat 1.0
> blue: #:type _CGFloat 1.0
> alpha: #:type _CGFloat 0.5))
> (tellv h setOpaque: #:type _BOOL NO)
>
> ;; Show the frame:
> (send f show #t)
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20140120/a91e82eb/attachment.html>