Changeset tag,last-working,8 for tag/last-working
- Timestamp:
- 10/18/2007 01:02:28 AM (19 years ago)
- branch-nick:
- tui
- revision id:
- dsowen@tux-20071018010228-1zi84upn20zpkrom
- File:
-
- 1 edited
-
tag/last-working/flat-menu.lisp (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
tag/last-working/flat-menu.lisp
r7 r8 8 8 9 9 (defclass entry () 10 ((text :initarg :text))) 11 12 (defun draw-entry (entry window row column) 13 (with-slots (text) entry 14 (cdk::move-and-add-string window row column text))) 15 16 17 18 (defclass menu () 10 19 ((window :initarg :window) 11 20 (row :initarg :row) 12 21 (column :initarg :column) 13 ( text :initarg :text)14 ( highlight :accessor highlight)))22 (entries :type vector :initarg :entries) 23 (selected :type (integer 0) :initform 0 :accessor selected))) 15 24 16 (defun draw-entry (entry)17 (with-slots (window row column text highlight) entry18 (when highlight25 (defun redraw-selected (menu with-highlight) 26 (with-slots (window row column entries selected) menu 27 (when with-highlight 19 28 (cdk::c-wattron window 262144)) 20 ( cdk::move-and-add-string window row column text)21 (when highlight29 (draw-entry (aref entries selected) window (+ row selected) column) 30 (when with-highlight 22 31 (cdk::c-wattroff window 262144)))) 23 32 24 (defmethod (setf highlight) :after (flag (entry entry))25 ( draw-entry entry))33 (defmethod (setf selected) :before (i (menu menu)) 34 (redraw-selected menu nil)) 26 35 27 (defun activate-entry (entry) 28 (with-slots (window) entry 29 (setf (highlight entry) t) 30 (cdk::c-refresh-window window) 31 (let ((ch (cdk::c-wgetch window))) 32 (setf (highlight entry) nil) 33 ch))) 36 (defun bound (a b c) 37 (min (max a b) c)) 34 38 35 (defclass menu () 36 ((entries :type vector :initarg :entries) 37 (selected :type (integer 0) :accessor selected))) 39 (defmethod (setf selected) :around (i (menu menu)) 40 (call-next-method (bound 0 i (1- (length (slot-value menu 'entries)))) menu)) 41 42 (defmethod (setf selected) :after (i (menu menu)) 43 (redraw-selected menu t)) 38 44 39 45 (defmethod initialize-instance :after ((menu menu) &rest initargs) 40 (with-slots (entries) menu 41 (dotimes (i (length entries)) 42 (setf (highlight (aref entries i)) nil)) 43 (setf (selected menu) 0))) 46 (declare (ignore initargs)) 47 (setf (selected menu) 0)) 44 48 45 49 (defun activate-menu (menu) 46 (with-slots (entries selected) menu 47 (loop 48 (multiple-value-bind (exit) (activate-entry (aref entries selected)) 49 (cond 50 ((= exit 258) 51 52 (incf selected)) 53 ((= exit 259) 54 (decf selected)) 55 (t (break))) 56 (setf selected (mod selected (length entries))))))) 50 (with-slots (window) menu 51 (with-accessors ((selected selected)) menu 52 (loop 53 (let ((ch (cdk::c-wgetch window))) 54 (cond 55 ((= ch 258) 56 (incf selected)) 57 ((= ch 259) 58 (decf selected)) 59 (t (break)))))))) 57 60 58 61 (defun test () … … 64 67 (cdk::c-init-color) 65 68 (cdk::c-erase-window screen) 66 (let ((entry1 (make-instance 'entry :window screen :row 5 :column 10 :text "Hello, world!")) 67 (entry2 (make-instance 'entry :window screen :row 6 :column 10 :text "Goodbye, galaxy!"))) 68 (setf (highlight entry1) t) 69 (let ((menu (make-instance 'menu :entries (vector entry1 entry2)))) 69 (let ((entry1 (make-instance 'entry :text "Hello, world!")) 70 (entry2 (make-instance 'entry :text "Goodbye, galaxy!"))) 71 (let ((menu (make-instance 'menu :window screen :row 5 :column 10 :entries (vector entry1 entry2)))) 70 72 (activate-menu menu) 71 73 (format t "Here~%")
Note: See TracChangeset
for help on using the changeset viewer.
