-
Notifications
You must be signed in to change notification settings - Fork 0
/
commands.lisp
50 lines (44 loc) · 1.6 KB
/
commands.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
(in-package :clim3-scigraph)
(defun zoom (plot &optional (in-p t))
(with-accessors ((min-x plot-xmin)
(max-x plot-xmax)
(min-y plot-ymin)
(max-y plot-ymax)) plot
(let* ((dx (- max-x min-x))
(dy (- max-y min-y))
(some-x (/ dx 10))
(some-y (/ dy 10))
(at-max (if in-p #'- #'+))
(at-min (if in-p #'+ #'-))
(new-max-x (funcall at-max max-x some-x))
(new-min-x (funcall at-min min-x some-x))
(new-max-y (funcall at-max max-y some-y))
(new-min-y (funcall at-min min-y some-y)))
(setf min-x new-min-x
max-x new-max-x
min-y new-min-y
max-y new-max-y))))
(defun forward (plot percent)
(with-accessors ((min-x plot-xmin)
(max-x plot-xmax)) plot
(let* ((dx (- max-x min-x))
(amount (* dx (/ percent 100))))
(setf min-x (+ min-x amount)
max-x (+ max-x amount)))))
(defun center (plot)
(with-accessors ((min-x plot-xmin)
(max-x plot-xmax)) plot
(let ((dx (- max-x min-x)))
(setf min-x (- (/ dx 2))
max-x (/ dx 2)))))
(defclass scigraph-command-processor (clim3:command-table) ())
(defmethod clim3:submit-keystroke ((key-processor scigraph-command-processor) keystroke)
(case (car keystroke)
(#\+ (zoom *plot*))
(#\- (zoom *plot* nil))
(#\f (forward *plot* 10))
(#\b (forward *plot* -10))
(#\. (center *plot*))
(#\q (throw :quit nil))))
(defun make-command-processor ()
(make-instance 'scigraph-command-processor))