Changeset tag,last-working,25


Ignore:
Timestamp:
11/03/2007 03:55:10 PM (19 years ago)
Author:
David Owen <dsowen@…>
branch-nick:
tui
revision id:
dsowen@fugue88.ws-20071103155510-r69yh2jkr423i49e
Message:

Display-strings now clip to the window.

Location:
tag/last-working
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • tag/last-working/display-string.lisp

    r22.1.1 r25  
    3030    (f 0)))
    3131
     32
     33
    3234(defun renderlen-part (part)
    3335  (destructuring-bind (class image) part
    34     (if (eq class 'literal)
    35         (length image)
    36         0)))
     36    (ecase class
     37      (literal (length image))
     38      (escape 0))))
    3739
    3840(defun renderlen (parts)
    3941  (let ((lens (mapcar 'renderlen-part parts)))
    4042    (reduce '+ lens)))
     43
     44
    4145
    4246(defconstant +attributes+ '(#\s #.(expt 2 16)
     
    4953                            #\p #.(expt 2 24)))
    5054
     55(defun fmt-part (part)
     56  (destructuring-bind (class image) part
     57    (ecase class
     58      (literal (enquote image))
     59      (escape (format nil "`~A" image)))))
     60
     61(defun fmt (parts)
     62  (let ((s (mapcar 'fmt-part parts)))
     63    (apply 'concatenate 'string s)))
     64
     65
     66
    5167(defun render (dstr window y x)
    52   (let ((parts (scan-dstring dstr)))
    53     (cdk:wmove window y x)
     68  (let ((parts (scan-dstring dstr))
     69        (printed 0))
    5470    (dolist (p parts)
    5571      (destructuring-bind (class image) p
    5672        (if (eq class 'literal)
    57             (add-string window image)
     73            (let ((n (length image)))
     74              (add-clipped-string window y (+ x printed) image)
     75              (incf printed n))
    5876            (let ((on (upper-case-p image))
    5977                  (attr (getf +attributes+ (char-downcase image))))
     
    6381
    6482(defun test ()
    65   (with-screen (s)
    66     (render "Now `B`Ris `bthe`r ``time.'" s 10 10)
    67     (input:%wget-wch s)))
     83  (let ((m "`UNow `B`Ris `bthe`r ``time.'`u"))
     84    (with-screen (s)
     85      (cdk::c-erase-window s)
     86      (cdk::c-refresh-window s)
     87      (with-der-window (w s 3 10 5 5)
     88        (wmove w 0 0)
     89        (add-string w (make-sequence 'string 15 :initial-element #\.))
     90        (render m w 1 -2)
     91        (input:%wget-wch w)))))
  • tag/last-working/tui.asd

    r22.1.1 r25  
    66               (:file "cdk")
    77               (:file "display-string"
    8                       :depends-on ("cdk"))
     8                      ;; "input" only for testing
     9                      :depends-on ("cdk" "input"))
    910               (:module "grid"
    10                         :depends-on ("cdk")
     11                        :depends-on ("cdk" "display-string")
    1112                        :components ((:file "package")
    1213                                     (:file "model")
Note: See TracChangeset for help on using the changeset viewer.