# HG changeset patch # User Steve Losh # Date 1488800867 0 # Node ID 05bcf3c72a2715d36efc1ba8362c207a0b0ee7cb # Parent 7d9a9d2a4af236bd8deae9647a72d70bfd8eea4a Add `print` diff -r 7d9a9d2a4af2 -r 05bcf3c72a27 examples/terrain.lisp --- a/examples/terrain.lisp Sat Feb 11 17:14:03 2017 +0000 +++ b/examples/terrain.lisp Mon Mar 06 11:47:47 2017 +0000 @@ -114,7 +114,12 @@ (setf (blt:color) (blt:rgbaf height height height 1.0) (blt:cell-char x y) (terrain-char height))) - ; (blt:print 1 1 "Demo!") + (setf (blt:color) (blt:rgbaf 1.0 0.0 0.0 1.0)) + (pr (multiple-value-list (blt:print 1 1 (format nil "Demo!~%There is a lot of text in this line, will BLT manage to word wrap everything properly? We'll see!") + :width 50 + :height 10 + :halign :center + :valign :center))) (blt:refresh)) (defun config () diff -r 7d9a9d2a4af2 -r 05bcf3c72a27 src/high-level/bearlibterminal.lisp --- a/src/high-level/bearlibterminal.lisp Sat Feb 11 17:14:03 2017 +0000 +++ b/src/high-level/bearlibterminal.lisp Mon Mar 06 11:47:47 2017 +0000 @@ -85,6 +85,21 @@ (code-char code-point)) +(defun horizontal-alignment (alignment-keyword) + (ccase alignment-keyword + (:default blt/ll:+tk-align-default+) + (:left blt/ll:+tk-align-left+) + (:right blt/ll:+tk-align-right+) + ((:middle :center) blt/ll:+tk-align-center+))) + +(defun vertical-alignment (alignment-keyword) + (ccase alignment-keyword + (:default blt/ll:+tk-align-default+) + (:top blt/ll:+tk-align-top+) + (:bottom blt/ll:+tk-align-bottom+) + ((:middle :center) blt/ll:+tk-align-middle+))) + + ;;;; Error Checking ----------------------------------------------------------- (define-condition bearlibterminal-error (error) ()) @@ -197,6 +212,25 @@ (blt/ll:terminal-pick-bkcolor x y)) +(defun print (x y string &key + width + height + (halign :default) + (valign :default)) + (cffi:with-foreign-objects ((measured-width :int) + (measured-height :int)) + (blt/ll:terminal-print-ext-8 x y + (or width 0) + (or height 0) + (logior (horizontal-alignment halign) + (vertical-alignment valign)) + string + measured-width + measured-height) + (values (cffi:mem-ref measured-width :int) + (cffi:mem-ref measured-height :int)))) + + ;;;; Higher-Level API --------------------------------------------------------- (defmacro defuck-floats (&body body) #+sbcl diff -r 7d9a9d2a4af2 -r 05bcf3c72a27 src/low-level/bearlibterminal.lisp --- a/src/low-level/bearlibterminal.lisp Sat Feb 11 17:14:03 2017 +0000 +++ b/src/low-level/bearlibterminal.lisp Mon Mar 06 11:47:47 2017 +0000 @@ -719,7 +719,7 @@ (w :int) (h :int) (align :int) - (s :pointer) + (s :string) (out_w :pointer) (out_h :pointer)) @@ -752,7 +752,7 @@ (cffi:defcfun ("terminal_measure_ext8" #.(swig-lispify "terminal_measure_ext8" 'function)) :void (w :int) (h :int) - (s :pointer) + (s :string) (out_w :pointer) (out_h :pointer)) @@ -792,7 +792,7 @@ (cffi:defcfun ("terminal_read_str8" #.(swig-lispify "terminal_read_str8" 'function)) :int (x :int) (y :int) - (buffer :pointer) + (buffer :string) (max :int)) (cl:export '#.(swig-lispify "terminal_read_str8" 'function)) @@ -822,9 +822,9 @@ (cl:export '#.(swig-lispify "terminal_delay" 'function)) -(cffi:defcfun ("terminal_get8" #.(swig-lispify "terminal_get8" 'function)) :pointer - (key :pointer) - (default_ :pointer)) +(cffi:defcfun ("terminal_get8" #.(swig-lispify "terminal_get8" 'function)) :string + (key :string) + (default_ :string)) (cl:export '#.(swig-lispify "terminal_get8" 'function)) @@ -841,7 +841,7 @@ (cl:export '#.(swig-lispify "terminal_get32" 'function)) (cffi:defcfun ("color_from_name8" #.(swig-lispify "color_from_name8" 'function)) color - (name :pointer)) + (name :string)) (cl:export '#.(swig-lispify "color_from_name8" 'function)) diff -r 7d9a9d2a4af2 -r 05bcf3c72a27 src/low-level/bearlibterminal.swig --- a/src/low-level/bearlibterminal.swig Sat Feb 11 17:14:03 2017 +0000 +++ b/src/low-level/bearlibterminal.swig Mon Mar 06 11:47:47 2017 +0000 @@ -14,7 +14,10 @@ %feature("intern_function","1"); %feature("export"); -%typemap(cin) color_t "color"; +%typemap(cin) color_t "color"; %typemap(cout) color_t "color"; +%typemap(cin) int8_t* ":string"; +%typemap(cout) int8_t* ":string"; + %include "src/low-level/include/BearLibTerminal.h"