home *** CD-ROM | disk | FTP | other *** search
- ; book pp.257-260
-
- (defproto bitmap-edit-proto '(bitmap h v) nil graph-window-proto)
-
- (defmeth bitmap-edit-proto :isnew (width height)
- (setf (slot-value 'bitmap)
- (make-array (list height width) :initial-element 0))
- (call-next-method))
- (defmeth bitmap-edit-proto :bitmap () (slot-value 'bitmap))
- (defmeth bitmap-edit-proto :v () (slot-value 'v))
- (defmeth bitmap-edit-proto :h () (slot-value 'h))
- (defmeth bitmap-edit-proto :resize ()
- (let ((m (array-dimension (send self :bitmap) 0))
- (n (array-dimension (send self :bitmap) 1))
- (height (send self :canvas-height))
- (width (send self :canvas-width)))
- (setf (slot-value 'v)
- (coerce (floor (* (iseq 0 m) (/ height m))) 'vector))
- (setf (slot-value 'h)
- (coerce (floor (* (iseq 0 n) (/ width n))) 'vector))))
- (defmeth bitmap-edit-proto :draw-pixel (i j)
- (let* ((b (send self :bitmap))
- (v (send self :v))
- (h (send self :h))
- (left (aref h j))
- (right (aref h (+ j 1)))
- (top (aref v i))
- (bottom (aref v (+ i 1))))
- (send self (if (= 1 (aref b i j)) :paint-rect :erase-rect)
- left top (- right left) (- bottom top))))
- (defmeth bitmap-edit-proto :redraw ()
- (let* ((b (send self :bitmap))
- (m (array-dimension b 0))
- (n (array-dimension b 1))
- (width (send self :canvas-width))
- (height (send self :canvas-height)))
- (send self :start-buffering)
- (send self :erase-rect 0 0 width height)
- (dotimes (i m)
- (dotimes (j n)
- (send self :draw-pixel i j)))
- (send self :buffer-to-screen)))
- (defmeth bitmap-edit-proto :set-pixel (x y)
- (let* ((b (send self :bitmap))
- (m (array-dimension b 0))
- (n (array-dimension b 1))
- (width (send self :canvas-width))
- (height (send self :canvas-height))
- (i (min (floor (* y (/ m height))) (- m 1)))
- (j (min (floor (* x (/ n width))) (- n 1))))
- (setf (aref b i j) (if (= (aref b i j) 1) 0 1))
- (send self :draw-pixel i j)))
- (defmeth bitmap-edit-proto :do-click (x y m1 m2)
- (send self :set-pixel x y))
-