Plot snips no longer get focus

Right-click on plot snips now opens editor pop-up menu
This commit is contained in:
Neil Toronto 2011-11-22 14:34:25 -07:00
parent 2f308a5323
commit 9c5d68ead5
4 changed files with 45 additions and 37 deletions

View File

@ -80,4 +80,25 @@
;(send dc draw-bitmap-section bm x y 0 0 width height)
(when message
(parameterize/group ([plot-parameters saved-plot-parameters])
(draw-message dc x y))))))
(draw-message dc x y))))
(send this set-flags (list* 'handles-events 'handles-all-mouse-events (send this get-flags)))
(define/override (on-event dc x y editorx editory evt)
(define editor (send (send this get-admin) get-editor))
(when (member (send evt get-event-type) '(left-down middle-down right-down))
;; The snip has been given caret ownership by now. But we don't want the snip to own the
;; caret because it'll hog all the mouse move events, keeping the other plot snips from
;; showing messages when the mouse hovers over them. Besides, a plot snip has no selectable
;; text or any other reason to own the caret.
;; This gives ownership to the editor:
(send editor set-caret-owner #f))
(when (eq? (send evt get-event-type) 'right-down)
;; The 'handles-events flag keeps the editor from handling the right-click event, meaning the
;; pop-up menu won't pop up. So we call the "local" event handler, which would have been
;; called had this snip not trapped events:
(send editor on-local-event evt)))
(define cross-cursor (make-object cursor% 'cross))
(define/override (adjust-cursor dc x y editorx editory evt) cross-cursor)
))

View File

@ -11,6 +11,7 @@
(provide 2d-plot-snip% make-2d-plot-snip)
(define zoom-delay 16) ; about 60 fps (just over)
(define show-zoom-message? #t)
(define 2d-plot-snip%
(class plot-snip%
@ -42,22 +43,19 @@
(define dragging? #f)
(define left-down? #f) ; only #t if left-down happened on this snip
(define zoom-timer #f)
(define zoom-timer #f)
(define (set-zoom-timer)
(when (not zoom-timer)
(set! zoom-timer (make-object timer% (λ ()
(set! zoom-timer #f)
(refresh))
(set! zoom-timer (make-object timer%
(λ ()
(set! zoom-timer #f)
(refresh))
zoom-delay #t))))
(define zoomed? #f)
(define unzoomed? #f)
(define (set-click-message)
(cond [(and zoomed? unzoomed?) (void)]
[zoomed? (set-message "Click to unzoom once")]
[unzoomed? (set-message "Click and drag to zoom")]
[else (set-message "Click and drag to zoom\n Click to unzoom once")]))
(when show-zoom-message?
(set-message "Click and drag to zoom\n Click to unzoom once")))
(define (update-plot new-plot-bounds-rect)
(define-values (new-bm new-area-bounds-rect new-area-bounds->plot-bounds)
@ -90,14 +88,13 @@
#;(printf "~a: new-plot-bounds-rect = ~v~n"
(current-milliseconds) new-rect)
(set! plot-bounds-rects (cons plot-bounds-rect plot-bounds-rects))
(update-plot new-rect)
(set! zoomed? #t)]
(update-plot new-rect)]
[else (refresh)])]
[(not (empty? plot-bounds-rects))
(define new-rect (first plot-bounds-rects))
(set! plot-bounds-rects (rest plot-bounds-rects))
(update-plot new-rect)
(set! unzoomed? #t)])]
(set! show-zoom-message? #f)])]
[(motion) (cond [left-down? ; not event's left-down: only #t if clicked on snip
(when (not (and (= left-drag-x mouse-x)
(= left-drag-y mouse-y)))
@ -108,7 +105,8 @@
[(and (not (send evt get-left-down))
(<= 0 mouse-x (send (get-bitmap) get-width))
(<= 0 mouse-y (send (get-bitmap) get-height)))
(set-click-message)])]))
(set-click-message)])])
(super on-event dc x y editorx editory evt))
(define/override (draw dc dc-x-min dc-y-min left top right bottom dx dy draw-caret)
;(printf "~a: drawing~n" (current-milliseconds))
@ -128,7 +126,7 @@
;; inside of selection box
(send pd set-pen select-color 1 'transparent)
(send pd set-brush select-color 'solid)
(send pd set-alpha 1/8)
(send pd set-alpha 1/4)
(send pd draw-rect draw-rect)
;; border of selection box
@ -176,11 +174,7 @@
'center #:outline? #t))
(send pd restore-drawing-params))))
(define cross-cursor (make-object cursor% 'cross))
(define/override (adjust-cursor dc x y editorx editory evt) cross-cursor)
(send this set-flags (list* 'handles-events 'handles-all-mouse-events (send this get-flags)))))
))
(define (make-2d-plot-snip bm saved-plot-parameters
make-plot plot-bounds-rect area-bounds-rect area-bounds->plot-bounds)

View File

@ -9,6 +9,7 @@
(provide 3d-plot-snip% make-3d-plot-snip)
(define update-delay 16) ; about 60 fps (just over)
(define show-rotate-message? #t)
(struct draw-command (animating? angle altitude) #:transparent)
@ -51,8 +52,9 @@
(define draw? #t)
(define left-down? #f) ; only #t if left-down happened on this snip
(define update-timer #f)
(define rth (make-render-thread make-bm saved-plot-parameters))
(define update-timer #f)
(define (stop-update-timer)
(when update-timer
@ -85,9 +87,8 @@
(number->string (inexact->exact (round altitude))))
#:refresh? #f))
(define rotated? #f)
(define (set-click-message)
(unless rotated?
(when show-rotate-message?
(set-message "Click and drag to rotate")))
(define/override (on-event dc x y editorx editory evt)
@ -125,16 +126,13 @@
(set! left-drag-x mouse-x)
(set! left-drag-y mouse-y)
(set! draw? #t)
(set! rotated? #t))]
(set! show-rotate-message? #f))]
[else (and (not (send evt get-left-down))
(<= 0 mouse-x (send (get-bitmap) get-width))
(<= 0 mouse-y (send (get-bitmap) get-height)))
(set-click-message)])]))
(define cross-cursor (make-object cursor% 'cross))
(define/override (adjust-cursor dc x y editorx editory evt) cross-cursor)
(send this set-flags (list* 'handles-events 'handles-all-mouse-events (send this get-flags)))))
(set-click-message)])])
(super on-event dc x y editorx editory evt))
))
(define (make-3d-plot-snip bm saved-plot-parameters make-bm angle altitude)
(make-object 3d-plot-snip% bm saved-plot-parameters make-bm angle altitude))

View File

@ -1,11 +1,6 @@
#lang racket
(require racket/flonum
plot
plot/utils
plot/common/contract
plot/common/contract-doc
)
(require plot plot/utils)
(x-axis-ticks? #f)
(y-axis-ticks? #f)