Changeset main,10


Ignore:
Timestamp:
10/18/2007 03:19:37 PM (19 years ago)
Author:
David Owen <dsowen@…>
branch-nick:
tui
revision id:
dsowen@fugue88.ws-20071018151937-126h3altfrx96ahq
Message:

Changed drawing once again, to place cursor at end of entry.
Added parameters to control drawing style.
Made a nice constructor.
Exported symbols.

Location:
main
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • main/cdk.lisp

    r8 r10  
    132132    (move-and-add-char window y (+ x i) (aref s i))))
    133133
     134(defcfun ("wmove" c-wmove) :int
     135  (window :pointer)
     136  (y :int)
     137  (x :int))
     138
    134139(defcfun ("wrefresh" c-refresh-window) :int
    135140  (window :pointer))
  • main/flat-menu.lisp

    r9 r10  
    11(defpackage #:flat-menu
    22  (:use #:cl #:cffi)
    3   (:export))
     3  (:export #:*shortcut-style* #:*highlight-style* #:menu #:selected
     4           #:make-menu))
    45
    56(in-package #:flat-menu)
     
    1112   (shortcut-pos :initarg :shortcut-pos)))
    1213
     14(defun break-text (text shortcut-pos)
     15  (if shortcut-pos
     16      (values (subseq text 0 shortcut-pos)
     17              (string (aref text shortcut-pos))
     18              (subseq text (1+ shortcut-pos)))
     19      (values "" "" text)))
     20
     21(defparameter *shortcut-style* (expt 2 17))
     22(defparameter *highlight-style* (expt 2 #|21|# 18))
     23
    1324(defun %draw-entry (entry window row column highlight)
    1425  (with-slots (text shortcut-pos) entry
    15     (when highlight
    16       (cdk::c-wattron window 262144))
    17     (cdk::move-and-add-string window row column text)
    18     (when shortcut-pos
    19       (cdk::c-wattron window 131072)
    20       (cdk::move-and-add-string window row (+ column shortcut-pos) (string (aref text shortcut-pos)))
    21       (cdk::c-wattroff window 131072))
    22     (when highlight
    23       (cdk::c-wattroff window 262144))))
     26    (multiple-value-bind (s1 s2 s3) (break-text text shortcut-pos)
     27      (when highlight
     28        (cdk::c-wattron window *highlight-style*))
     29      (cdk::move-and-add-string window row column s1)
     30      (cdk::c-wattron window *shortcut-style*)
     31      (cdk::move-and-add-string window row (incf column (length s1)) s2)
     32      (cdk::c-wattroff window *shortcut-style*)
     33      (cdk::move-and-add-string window row (incf column (length s2)) s3)
     34      (when highlight
     35        (cdk::c-wattroff window *highlight-style*)))))
    2436
    2537
     
    5971  (setf (selected menu) 0))
    6072
     73
     74
     75(defun parse-entry (entry)
     76  (destructuring-bind (text shortcut-pos) entry
     77    (make-instance 'entry :text text :shortcut-pos shortcut-pos)))
     78
     79(defun make-menu (window row column entries)
     80  (let ((entries (map 'vector #'parse-entry entries)))
     81    (make-instance 'menu
     82                   :window window
     83                   :row row
     84                   :column column
     85                   :entries entries)))
     86
     87 
     88
    6189(defun activate-menu (menu)
     90  "Some simple behavior just for testing."
    6291  (with-slots (window) menu
    6392    (with-accessors ((selected selected)) menu
     
    6998             ((= ch 259)
    7099              (decf selected))
    71              (t (break))))))))
     100             (t (return))))))))
    72101
    73102(defun test ()
     
    77106    (cdk::c-nonl)
    78107    (cdk::c-keypad screen t)
    79     (cdk::c-init-color)
    80108    (cdk::c-erase-window screen)
    81     (let ((entry1 (make-instance 'entry :text "Hello, world!" :shortcut-pos 0))
    82           (entry2 (make-instance 'entry :text "Goodbye, galaxy!" :shortcut-pos 0)))
    83       (let ((menu (make-instance 'menu :window screen :row 5 :column 10 :entries (vector entry1 entry2))))
    84         (activate-menu menu)
    85         (format t "Here~%")
    86         (read-line)))
    87     (cdk::c-refresh-window screen)
    88     (read-line)
     109    (let ((menu (make-menu screen 5 10 '(("Hello, world!" 7) ("Goodbye, galaxy!" 9)))))
     110      (activate-menu menu))
    89111    (cdk::c-end-curses)))
Note: See TracChangeset for help on using the changeset viewer.