Forked from Metaxal/plot-snip-pasteboard-overlay.rkt
Created
September 15, 2022 05:20
-
-
Save shhyou/b658e239856f85cbc136dc1f951efcd2 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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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