Skip to content

Instantly share code, notes, and snippets.

@Metaxal
Last active September 15, 2022 05:20
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Metaxal/cef7a4a2372aa5b19ddc5c9841cfaaff to your computer and use it in GitHub Desktop.
Save Metaxal/cef7a4a2372aa5b19ddc5c9841cfaaff to your computer and use it in GitHub Desktop.
A simple standalone program using overlays with plot-snip in a pasteboard, and switching with the zooming feature
#lang racket/gui
(require plot
pict)
;;; Author: Laurent Orseau
;;; License: [Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0) or
;;; [MIT license](http://opensource.org/licenses/MIT) at your option.
;;; See in particular this blog bost:
;;; https://alex-hhh.github.io/2019/09/map-snip.html#2019-09-08-map-snip-footnote-2-return
(define fr (new frame% [label "fr"] [width 500] [height 500]))
(define hp (new horizontal-panel% [parent fr] [stretchable-height #f]))
(define bt-zoom
(new button% [parent hp] [label "Zoom"]
[callback (λ (bt ev)
(send snip set-mouse-event-callback #f))]))
(define bt-pos
(new button% [parent hp] [label "Position"]
[callback (λ (bt ev)
(send snip set-mouse-event-callback value-renderer))]))
(define pb (new (class pasteboard%
(define/augment (can-interactive-move? ev) #f)
(define/augment (can-interactive-resize? ev) #f)
(super-new)) ))
(define ed (new editor-canvas% [parent fr] [editor pb]))
(define (value-renderer snip event x y)
(define overlays
(and x y (eq? (send event get-event-type) 'motion)
(list (point-pict (vector x y)
(text (format "~a ~a"
(~r (+ 0. x) #:precision '(= 2))
(~r (+ 0. y) #:precision '(= 2))))
#:anchor 'auto))))
(send snip set-overlay-renderers overlays))
(define snip (plot-snip (function (λ (x) (sin x)) -10. 10.)))
(send pb insert snip)
(send fr show #t)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment