Changeset main,52


Ignore:
Timestamp:
11/15/2007 07:43:22 PM (19 years ago)
Author:
David Owen <dsowen@…>
branch-nick:
tui
revision id:
dsowen@fugue88.ws-20071115194322-ilcysmh1p3jqzjao
Message:

Improved ACS translation.
New box and line drawing functions.
Setting active color.

Location:
main
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • main/cdk_wrapper.c

    r6 r52  
     1#define _XOPEN_SOURCE_EXTENDED
     2
     3#include <ncursesw/ncurses.h>
    14#include <cdk/cdk.h>
    25
     
    2629
    2730D(ENTRY, Entry)
     31
     32#undef D
  • main/output.lisp

    r31 r52  
    22  (:use #:cl #:cffi #:tui-cursor #:tui-window)
    33  (:export #:background #:add-string #:move-and-add-string
    4            #:add-clipped-string))
     4           #:add-clipped-string #:border #:hline #:vline #:color))
    55
    66(in-package #:tui-output)
     
    88
    99
    10 (defctype wchar :int32)                 ; On my 64-bit laptop.
     10(defctype wchar_t :int32)               ; On my 64-bit laptop.
    1111(defctype chtype :uint64)
     12(defctype attr_t chtype)
    1213
    1314(defcstruct cchar_t
    14   (attr chtype)
    15   (char wchar :count 5))
     15  (attr attr_t)
     16  (chars wchar_t :count 5))
    1617
    1718
     
    3132    (destructuring-bind (ch color) pair
    3233      (with-foreign-object (wch 'cchar_t)
    33         (with-foreign-slots ((attr char) wch cchar_t)
     34        (with-foreign-slots ((attr chars) wch cchar_t)
    3435          (dotimes (i 5)
    35             (setf (mem-aref char 'wchar i) 0))
     36            (setf (mem-aref chars 'wchar_t i) 0))
    3637          (setf attr (cdk::color-pair color)
    37                 (mem-aref char 'wchar) (char-code ch)))
     38                (mem-aref chars 'wchar_t) (char-code ch)))
    3839        (wbkgrnd (window-pointer window) wch)))))
    3940
     
    4849  (let ((ptr (window-pointer window))
    4950        (n (length s)))
    50     (with-foreign-object (a 'wchar n)
     51    (with-foreign-object (a 'wchar_t n)
    5152      (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))))
    5354      (waddnwstr ptr a n))))
    5455
     
    7273
    7374
     75(defcvar "_nc_wacs" :pointer)
    7476
    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))
    7689
    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))))))
    9296
    9397(defcfun "wadd_wchnstr" :int
     
    97101
    98102(defun clear-complex-char (cc)
    99   (with-foreign-slots ((attr char) cc cchar_t)
     103  (with-foreign-slots ((attr chars) cc cchar_t)
    100104    (setf attr 0)
    101105    (dotimes (i 5 cc)
    102       (setf (mem-aref char :uint32 i) 0))))
     106      (setf (mem-aref chars :uint32 i) 0))))
    103107
    104108(defun extract-complex-char (cc)
    105109  (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)
    107111      (dotimes (i 5 x)
    108         (setf (aref x i) (mem-aref char :uint32 i))))))
     112        (setf (aref x i) (mem-aref chars :uint32 i))))))
    109113
    110114(defun copy-complex-char (dst src-vector)
    111   (with-foreign-slots ((char) dst cchar_t)
     115  (with-foreign-slots ((chars) dst cchar_t)
    112116    (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)))))
    114118
    115119(defun set-complex-char (cc ch)
    116   (with-foreign-slots ((char) cc cchar_t)
     120  (with-foreign-slots ((chars) cc cchar_t)
    117121    (etypecase ch
    118122      (character
    119        (setf (mem-aref char :uint32) (char-code ch)))
     123       (setf (mem-aref chars :uint32) (char-code ch)))
    120124      (symbol
    121        (copy-complex-char cc (extract-complex-char (wacs-char ch)))))))
     125       (copy-complex-char cc (extract-complex-char (translate-wacs ch)))))))
    122126
    123127(defun add-complex-string (window s)
     
    132136
    133137
    134 (defcfun ("box" c-box) :int
     138(defcfun "wborder_set" :int
    135139  (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))
    138148
    139 (defcfun ("wborder" c-window-border) :int
     149(defcfun "whline_set" :int
    140150  (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.