Skip to content

Instantly share code, notes, and snippets.

@spdegabrielle
Created May 13, 2020 07:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save spdegabrielle/1e76357f8ef45a806f02c909758b09d8 to your computer and use it in GitHub Desktop.
Save spdegabrielle/1e76357f8ef45a806f02c909758b09d8 to your computer and use it in GitHub Desktop.
#lang racket/gui
(require ffi/unsafe
ffi/unsafe/objc
pict pict/face)
;; Create the frame:
(define f (new frame%
[label "Example"]
[width 400]
[height 400]))
;; 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)
(draw-pict (face 'happy) dc 10 15))])
;; 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.0))
;(tell h titlebarAppearsTransparent: #:type _BOOL YES)
;var titlebarAppearsTransparent: Bool
(tellv h setOpaque: #:type _BOOL NO)
;; Show the frame:
(send f show #t)
@spdegabrielle
Copy link
Author

found in racket-users archive (2014?)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment