Changeset main,28 for main/cdk.lisp
- Timestamp:
- 11/04/2007 06:19:33 AM (19 years ago)
- branch-nick:
- tui-new
- revision id:
- dsowen@fugue88.ws-20071104061933-b5oiof728551luy5
- File:
-
- 1 edited
-
main/cdk.lisp (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
main/cdk.lisp
r27 r28 1 1 (defpackage #:cdk 2 (:use #:cl #:cffi) 3 (:export #:with-screen #:with-der-window #:add-string #:add-clipped-string 4 #:wmove)) 2 (:use #:cl #:cffi #:dso-util) 3 (:export #:+err+ #:+ok+)) 5 4 6 5 (in-package #:cdk) … … 17 16 ;;; Global constants. 18 17 19 (defctype chtype :uint64) 20 (defctype wchar :int32) ; On my 64-bit laptop. 18 19 20 (defconstant +err+ -1) 21 (defconstant +ok+ 0) 21 22 22 23 (defcvar ("cdk_exit_early" +cdk-exit-early+) :int :read-only t) … … 27 28 ;;; Screen-wide, initialization, and finalization routines. 28 29 29 (defcfun ("initscr" c-init-curses-screen) :pointer)30 30 31 31 (defcfun ("start_color" c-curs-start-color) :int) 32 32 33 (defcfun ("endwin" c-end-curses) :int)34 35 (defmacro with-screen ((screen) &body body)36 `(let ((,screen (c-init-curses-screen)))37 (unwind-protect (progn ,@body)38 (c-end-curses))))39 40 (defcfun ("initCDKScreen" c-init-cdk-screen) :pointer41 (curseswindow :pointer))42 43 (defcfun ("initCDKColor" c-init-color) :void)44 45 (defcfun ("eraseCDKScreen" c-erase-screen) :void46 (screen :pointer))47 48 (defcfun ("destroyCDKScreen" c-destroy-screen) :void49 (screen :pointer))50 51 (defcfun ("endCDK" c-end-cdk) :void)52 53 (defcfun ("refreshCDKScreen" c-refresh-screen) :void54 (screen :pointer))55 56 (defcfun ("newwin" c-new-window) :pointer57 (lines :int)58 (columns :int)59 (y :int)60 (x :int))61 62 (defcfun ("subwin" c-sub-window) :pointer63 (orig :pointer)64 (lines :int)65 (columns :int)66 (y :int)67 (x :int))68 69 (defcfun ("derwin" c-der-window) :pointer70 (orig :pointer)71 (lines :int)72 (columns :int)73 (y :int)74 (x :int))75 76 (defcfun ("delwin" c-delete-window) :int77 (window :pointer))78 79 (defmacro with-der-window ((window parent lines columns y x) &body body)80 `(let ((,window (c-der-window ,parent ,lines ,columns ,y ,x)))81 (when (null-pointer-p ,window)82 ;; TODO: Replace this with a condition and a restart.83 (error "Couldn't create window."))84 (unwind-protect (progn ,@body)85 (c-delete-window ,window))))86 87 (defcfun ("box" c-box) :int88 (window :pointer)89 (vertical-ch chtype)90 (horizontal-ch chtype))91 92 (defcfun ("wborder" c-window-border) :int93 (window :pointer)94 (ls chtype)95 (rs chtype)96 (ts chtype)97 (bs chtype)98 (tl chtype)99 (tr chtype)100 (bl chtype)101 (br chtype))102 103 (defcfun ("wbkgd" c-set-window-background) :int104 (window :pointer)105 (ch chtype))106 107 (defcfun "wbkgrnd" :int108 (window :pointer)109 (wch :pointer))110 111 (defcfun ("werase" c-erase-window) :int112 (window :pointer))113 114 (defcfun "getcury" :int115 (window :pointer))116 117 (defcfun "getcurx" :int118 (window :pointer))119 120 (defcfun "getmaxy" :int121 (window :pointer))122 123 (defcfun "getmaxx" :int124 (window :pointer))125 126 (defcfun "wmove" :int127 (window :pointer)128 (y :int)129 (x :int))130 131 (defcfun "wadd_wch" :int132 (window :pointer)133 (wch :pointer))134 135 (defcstruct cchar_t136 (attr chtype)137 (char :uint32 :count 5))138 33 139 34 140 35 141 (defcvar ("_nc_wacs" nc-wacs) :pointer :read-only t)142 36 143 (defun wacs-char (ch)144 (let ((code (char-code (ecase ch145 (:ul-corner #\l)146 (:ll-corner #\m)147 (:ur-corner #\k)148 (:lr-corner #\j)149 (:r-tee #\u)150 (:l-tee #\t)151 (:b-tee #\v)152 (:t-tee #\w)153 (:h-line #\q)154 (:v-line #\x)155 (:plus #\n)156 (:solid #\0)))))157 (inc-pointer nc-wacs (* (foreign-type-size 'cchar_t) code))))158 159 (defcfun "wadd_wchnstr" :int160 (window :pointer)161 (cchstr :pointer)162 (n :int))163 164 (defun clear-complex-char (cc)165 (with-foreign-slots ((attr char) cc cchar_t)166 (setf attr 0)167 (dotimes (i 5 cc)168 (setf (mem-aref char :uint32 i) 0))))169 170 (defun extract-complex-char (cc)171 (let ((x (make-sequence '(vector integer) 5 :initial-element 0)))172 (with-foreign-slots ((char) cc cchar_t)173 (dotimes (i 5 x)174 (setf (aref x i) (mem-aref char :uint32 i))))))175 176 (defun copy-complex-char (dst src-vector)177 (with-foreign-slots ((char) dst cchar_t)178 (dotimes (i 5 dst)179 (setf (mem-aref char :uint32 i) (aref src-vector i)))))180 181 (defun set-complex-char (cc ch)182 (with-foreign-slots ((char) cc cchar_t)183 (etypecase ch184 (character185 (setf (mem-aref char :uint32) (char-code ch)))186 (symbol187 (copy-complex-char cc (extract-complex-char (wacs-char ch)))))))188 189 (defun add-complex-string (window s)190 (let ((n (length s)))191 (with-foreign-object (a 'cchar_t n)192 (dotimes (i n)193 (let ((cc (mem-aref a 'cchar_t i)))194 (clear-complex-char cc)195 (set-complex-char cc (aref s i))))196 (wadd-wchnstr window a n))))197 198 (defcfun ("wmove" c-wmove) :int199 (window :pointer)200 (y :int)201 (x :int))202 203 (defcfun "waddnwstr" :int204 (window :pointer)205 (wstr :pointer)206 (n :int))207 208 (defun add-string (window s)209 (let ((n (length s)))210 (with-foreign-object (a 'wchar n)211 (dotimes (i n)212 (setf (mem-aref a 'wchar i) (char-code (aref s i))))213 (waddnwstr window a n))))214 215 (defun move-and-add-string (window y x s)216 (wmove window y x)217 (add-string window s))218 219 (defun add-clipped-string (window y x s)220 (let ((maxy (getmaxy window)))221 (unless (<= 0 y maxy) (return-from add-clipped-string)))222 (let ((maxx (getmaxx window)))223 (when (< x 0)224 (setf s (subseq s (- x))225 x 0))226 (let ((over (- (+ x (length s)) maxx)))227 (when (> over 0)228 (setf s (subseq s 0 (- (length s) over)))))229 (move-and-add-string window y x s)))230 231 (defcfun ("wrefresh" c-refresh-window) :int232 (window :pointer))233 37 234 38 (defun color-pair (n) … … 237 41 238 42 239 ;;; Generic functions.240 43 241 (defcfun ("bindCDKObject" c-bind-key) :void242 (object-type :int)243 (object :pointer)244 (key chtype)245 (function :pointer)246 (user-data :pointer))247 248 (defcfun ("cleanCDKObjectBindings" c-clear-bindings) :void249 (object-type :int)250 (object :pointer))251 252 (defcfun ("setCDKObjectBackgroundColor" c-set-background-color) :void253 (object :pointer)254 (color :string))255 256 257 258 ;;; Labels.259 260 (defcfun ("newCDKLabel" c-new-label) :pointer261 (screen :pointer)262 (x-pos :int)263 (y-pos :int)264 (message :pointer)265 (message-lines :int)266 (box :boolean)267 (shadow :boolean))268 269 (defcfun ("freeCDKLabel" c-free-label) :void270 (label :pointer))271 272 (defcfun ("waitCDKLabel" c-wait-on-label) :char273 (label :pointer)274 (key :char))275 276 (defun new-label (screen row column text &optional box shadow)277 (let* ((cstr (foreign-string-alloc text))278 (array (foreign-alloc :pointer :initial-element cstr :count 1))279 (label (c-new-label screen column row array 1 box shadow)))280 (foreign-free array)281 (foreign-string-free cstr)282 label))283 284 285 286 ;;; Entries.287 288 (defcfun ("newCDKEntry" c-new-entry) :pointer289 (screen :pointer)290 (x-pos :int)291 (y-pos :int)292 (title :string)293 (label :string)294 (attribute :int)295 (filler :int)296 (display-type :int)297 (width :int)298 (minimum-length :int)299 (maximum-length :int)300 (box :boolean)301 (shadow :boolean))302 303 (defcfun ("freeCDKEntry" c-free-entry) :void304 (entry :pointer))305 306 (defcfun ("activateCDKEntry" c-activate-entry) :string307 (entry :pointer)308 (actions :string))309 310 (defcfun ("setCDKEntryHighlight" c-set-entry-highlight) :void311 (entry :pointer)312 (highlight :unsigned-int) ; Still not sure about this.313 (cursor :boolean))314 315 (defcfun ("getCDKEntryExitType" c-entry-exit-type) :int316 (entry :pointer))317 318 (defcfun ("getCDKEntryValue" c-get-entry-value) :string319 (entry :pointer))320 321 (defcfun ("setCDKEntryValue" c-set-entry-value) :void322 (entry :pointer)323 (new-value :string))324 325 (defcfun ("setCDKEntryExitType" c-set-entry-exit-type) :void326 (entry :pointer)327 (ch chtype))328 329 330 331 (defcfun ("wattron" c-wattron) :int332 (window :pointer)333 (attrs :int))334 335 (defcfun ("wattroff" c-wattroff) :int336 (window :pointer)337 (attrs :int))338 44 339 45 (defcfun ("wgetch" c-wgetch) :int … … 349 55 350 56 (defcfun ("nonl" c-nonl) :int) 57 58 (defcfun ("wattron" c-wattron) :int 59 (window :pointer) 60 (attrs :int)) 61 62 (defcfun ("wattroff" c-wattroff) :int 63 (window :pointer) 64 (attrs :int)) 65
Note: See TracChangeset
for help on using the changeset viewer.
