Changeset main,24 for main


Ignore:
Timestamp:
11/03/2007 03:54:31 PM (19 years ago)
Author:
David Owen <dsowen@…>
branch-nick:
tui
revision id:
dsowen@fugue88.ws-20071103155431-vqezrka9oztick7q
Message:

Added routine to add strings but clip to the window.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/cdk.lisp

    r22.1.1 r24  
    11(defpackage #:cdk
    22  (:use #:cl #:cffi)
    3   (:export #:with-screen #:with-der-window #:add-ch #:add-string #:wmove))
     3  (:export #:with-screen #:with-der-window #:add-string #:add-clipped-string
     4           #:wmove))
    45
    56(in-package #:cdk)
     
    1718
    1819(defctype chtype :uint64)
     20(defctype wchar :int32)                 ; On my 64-bit laptop.
    1921
    2022(defcvar ("cdk_exit_early" +cdk-exit-early+) :int :read-only t)
     
    160162  (x :int))
    161163
    162 (defun add-char (window ch)
    163   (with-foreign-object (s 'cchar_t)
    164     (with-foreign-slots ((attr char) s cchar_t)
    165       (setf attr 0)
    166       (dotimes (i 5)
    167         (setf (mem-aref char :uint32 i) 0))
    168       (setf (mem-aref char :uint32) (char-code ch)))
    169     (wadd-wch window s)))
     164(defcfun "waddnwstr" :int
     165  (window :pointer)
     166  (wstr :pointer)
     167  (n :int))
    170168
    171169(defun add-string (window s)
    172   (dotimes (i (length s))
    173     (add-char window (aref s i))))
    174 
    175 (defun move-and-add-char (window y x ch)
    176   (wmove window y x)
    177   (add-char window ch))
     170  (let ((n (length s)))
     171    (with-foreign-object (a 'wchar n)
     172      (dotimes (i n)
     173        (setf (mem-aref a 'wchar i) (char-code (aref s i))))
     174      (waddnwstr window a n))))
    178175
    179176(defun move-and-add-string (window y x s)
    180177  (wmove window y x)
    181178  (add-string window s))
     179
     180(defun add-clipped-string (window y x s)
     181  (let ((maxy (getmaxy window)))
     182    (unless (<= 0 y maxy) (return-from add-clipped-string)))
     183  (let ((maxx (getmaxx window)))
     184    (when (< x 0)
     185      (setf s (subseq s (- x))
     186            x 0))
     187    (let ((over (- (+ x (length s)) maxx)))
     188      (when (> over 0)
     189        (setf s (subseq s 0 (- (length s) over)))))
     190    (move-and-add-string window y x s)))
    182191
    183192(defcfun ("wrefresh" c-refresh-window) :int
Note: See TracChangeset for help on using the changeset viewer.