[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: hilighting views
- To: info-mcl@cambridge.apple.com
- Subject: Re: hilighting views
- From: "Andre Koehorst" <andre_koehorst@riks.nl>
- Date: 10 Aug 93 11:01:12 U
Reply to: RE>hilighting views
Nichole Pinkard wrote
> Hello,
>
> I am trying to emulate the hilight word action that takes place in a
> text editor with subviews of a window. I want to be able to click on
> a view and drag the mouse and have every subview that the mouse goes over
> hilighted. Does anyone have any suggestion on how this can be done.
>
> pinkard@ils.nwu.edu
This might give her a quick start
Andre,
;;;
;;; highlighting views
;;;
;;; Research Institute for Knowlegde Systems
;;; Maastricht, The Netherlands
;;; Andre Koehorst
;;; August 10, 1993
;;;
;;; Usual disclaimers apply to using this code
;;;
(defclass drawing-board (window)
(
)
(:documentation
"The class of windows that we draw in")
)
(defclass highlightable-view (view)
(
(highlightp :initarg :highlightp :initform nil :accessor highlightp
:documentation
"t if highllighted, false if not")
)
(:documentation
"The views that can be highlighted")
)
(defmethod view-draw-contents ((view highlightable-view))
"A method to draw a highlightable-view either highlighted or not"
(let ((down-right (subtract-points (view-size view) #@(1 1)))
(left-up #@(1 1)))
(if (highlightp view)
(paint-rect view left-up down-right)
(progn
(erase-rect view left-up down-right)
(frame-rect view left-up down-right)
))))
(defmethod highlight ((view highlightable-view))
"Method to highlight a view"
(with-slots (highlightp) view
(unless highlightp
(setf highlightp t)
(invalidate-view view)
(view-draw-contents view))))
(defmethod delight ((view highlightable-view))
"Method to un-highlight a view"
(with-slots (highlightp) view
(when highlightp
(setf highlightp nil)
(invalidate-view view)
(view-draw-contents view))))
(defmethod view-click-event-handler ((view drawing-board) where)
"Highlights the clicked view, delights the others (unless the option key is
down)"
(let ((clicked-sub (find-clicked-subview view where)))
(do-subviews (sub view)
(if (eq sub clicked-sub)
(highlight sub)
(unless (option-key-p)
(delight sub))))))
(defmethod view-mouse-enter-event-handler ((view highlightable-view))
"Highlights a view when the mouse enters and the mouse button is down"
(when (mouse-down-p)
(highlight view)))
#|
(setq sub1
(make-instance 'highlightable-view
:view-position #@(10 10)
:view-size #@(50 50)
))
(setq sub2
(make-instance 'highlightable-view
:view-position #@(70 80)
:view-size #@(50 50)
))
(setq sub3
(make-instance 'highlightable-view
:view-position #@(80 90)
:view-size #@(50 50)
))
(setq sub4
(make-instance 'highlightable-view
:view-position #@(10 80)
:view-size #@(50 50)
))
(setq win
(make-instance 'drawing-board
:window-title "Drawing Board"
:view-subviews (list sub1 sub2 sub3 sub4)))
|#