Changeset main,52
- Timestamp:
- 11/15/2007 07:43:22 PM (19 years ago)
- branch-nick:
- tui
- revision id:
- dsowen@fugue88.ws-20071115194322-ilcysmh1p3jqzjao
- Location:
- main
- Files:
-
- 2 edited
-
cdk_wrapper.c (modified) (2 diffs)
-
output.lisp (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
main/cdk_wrapper.c
r6 r52 1 #define _XOPEN_SOURCE_EXTENDED 2 3 #include <ncursesw/ncurses.h> 1 4 #include <cdk/cdk.h> 2 5 … … 26 29 27 30 D(ENTRY, Entry) 31 32 #undef D -
main/output.lisp
r31 r52 2 2 (:use #:cl #:cffi #:tui-cursor #:tui-window) 3 3 (:export #:background #:add-string #:move-and-add-string 4 #:add-clipped-string ))4 #:add-clipped-string #:border #:hline #:vline #:color)) 5 5 6 6 (in-package #:tui-output) … … 8 8 9 9 10 (defctype wchar :int32); On my 64-bit laptop.10 (defctype wchar_t :int32) ; On my 64-bit laptop. 11 11 (defctype chtype :uint64) 12 (defctype attr_t chtype) 12 13 13 14 (defcstruct cchar_t 14 (attr chtype)15 (char wchar:count 5))15 (attr attr_t) 16 (chars wchar_t :count 5)) 16 17 17 18 … … 31 32 (destructuring-bind (ch color) pair 32 33 (with-foreign-object (wch 'cchar_t) 33 (with-foreign-slots ((attr char ) wch cchar_t)34 (with-foreign-slots ((attr chars) wch cchar_t) 34 35 (dotimes (i 5) 35 (setf (mem-aref char 'wchari) 0))36 (setf (mem-aref chars 'wchar_t i) 0)) 36 37 (setf attr (cdk::color-pair color) 37 (mem-aref char 'wchar) (char-code ch)))38 (mem-aref chars 'wchar_t) (char-code ch))) 38 39 (wbkgrnd (window-pointer window) wch))))) 39 40 … … 48 49 (let ((ptr (window-pointer window)) 49 50 (n (length s))) 50 (with-foreign-object (a 'wchar n)51 (with-foreign-object (a 'wchar_t n) 51 52 (dotimes (i n) 52 (setf (mem-aref a 'wchar i) (char-code (aref s i))))53 (setf (mem-aref a 'wchar_t i) (char-code (aref s i)))) 53 54 (waddnwstr ptr a n)))) 54 55 … … 72 73 73 74 75 (defcvar "_nc_wacs" :pointer) 74 76 75 (defcvar ("_nc_wacs" nc-wacs) :pointer :read-only t) 77 (defconstant +wacs-table+ 78 '(:ul-corner #\l 79 :ll-corner #\m 80 :ur-corner #\k 81 :lr-corner #\j 82 :r-tee #\u 83 :l-tee #\t 84 :b-tee #\v 85 :t-tee #\w 86 :h-line #\q 87 :v-line #\x 88 :plus #\n)) 76 89 77 (defun wacs-char (ch) 78 (let ((code (char-code (ecase ch 79 (:ul-corner #\l) 80 (:ll-corner #\m) 81 (:ur-corner #\k) 82 (:lr-corner #\j) 83 (:r-tee #\u) 84 (:l-tee #\t) 85 (:b-tee #\v) 86 (:t-tee #\w) 87 (:h-line #\q) 88 (:v-line #\x) 89 (:plus #\n) 90 (:solid #\0))))) 91 (inc-pointer nc-wacs (* (foreign-type-size 'cchar_t) code)))) 90 91 (defun translate-wacs (wacs) 92 (etypecase wacs 93 (null (null-pointer)) 94 (keyword 95 (mem-aref *-nc-wacs* 'cchar_t (char-code (getf +wacs-table+ wacs)))))) 92 96 93 97 (defcfun "wadd_wchnstr" :int … … 97 101 98 102 (defun clear-complex-char (cc) 99 (with-foreign-slots ((attr char ) cc cchar_t)103 (with-foreign-slots ((attr chars) cc cchar_t) 100 104 (setf attr 0) 101 105 (dotimes (i 5 cc) 102 (setf (mem-aref char :uint32 i) 0))))106 (setf (mem-aref chars :uint32 i) 0)))) 103 107 104 108 (defun extract-complex-char (cc) 105 109 (let ((x (make-sequence '(vector integer) 5 :initial-element 0))) 106 (with-foreign-slots ((char ) cc cchar_t)110 (with-foreign-slots ((chars) cc cchar_t) 107 111 (dotimes (i 5 x) 108 (setf (aref x i) (mem-aref char :uint32 i))))))112 (setf (aref x i) (mem-aref chars :uint32 i)))))) 109 113 110 114 (defun copy-complex-char (dst src-vector) 111 (with-foreign-slots ((char ) dst cchar_t)115 (with-foreign-slots ((chars) dst cchar_t) 112 116 (dotimes (i 5 dst) 113 (setf (mem-aref char :uint32 i) (aref src-vector i)))))117 (setf (mem-aref chars :uint32 i) (aref src-vector i))))) 114 118 115 119 (defun set-complex-char (cc ch) 116 (with-foreign-slots ((char ) cc cchar_t)120 (with-foreign-slots ((chars) cc cchar_t) 117 121 (etypecase ch 118 122 (character 119 (setf (mem-aref char :uint32) (char-code ch)))123 (setf (mem-aref chars :uint32) (char-code ch))) 120 124 (symbol 121 (copy-complex-char cc (extract-complex-char ( wacs-charch)))))))125 (copy-complex-char cc (extract-complex-char (translate-wacs ch))))))) 122 126 123 127 (defun add-complex-string (window s) … … 132 136 133 137 134 (defcfun ("box" c-box):int138 (defcfun "wborder_set" :int 135 139 (window :pointer) 136 (vertical-ch chtype) 137 (horizontal-ch chtype)) 140 (ls :pointer) 141 (rs :pointer) 142 (ts :pointer) 143 (bs :pointer) 144 (tl :pointer) 145 (tr :pointer) 146 (bl :pointer) 147 (br :pointer)) 138 148 139 (defcfun ("wborder" c-window-border):int149 (defcfun "whline_set" :int 140 150 (window :pointer) 141 (ls chtype) 142 (rs chtype) 143 (ts chtype) 144 (bs chtype) 145 (tl chtype) 146 (tr chtype) 147 (bl chtype) 148 (br chtype)) 151 (wch :pointer) 152 (n :int)) 153 154 (defcfun "wvline_set" :int 155 (window :pointer) 156 (wch :pointer) 157 (n :int)) 158 159 (defun border (window &key left right top bottom top-left top-right bottom-left 160 bottom-right) 161 (let* ((args (list left right top bottom top-left top-right bottom-left 162 bottom-right)) 163 (trans (mapcar 'translate-wacs args))) 164 (apply 'wborder-set (window-pointer window) trans))) 165 166 (defun hline (window wch n) 167 (whline-set (window-pointer window) (translate-wacs wch) n)) 168 169 (defun vline (window wch n) 170 (wvline-set (window-pointer window) (translate-wacs wch) n)) 171 172 173 174 (defcfun "wcolor_set" :int 175 (window :pointer) 176 (color-pair-number :short) 177 (opts :pointer)) 178 179 (defmethod (setf color) (color-pair-number (w window)) 180 (wcolor-set (window-pointer w) color-pair-number (null-pointer)))
Note: See TracChangeset
for help on using the changeset viewer.
