Re: Multi-line text in graphs (or other pinboard layouts).
this is not as pretty as I'd like, but it works for capi:item-pinboard-object: (defun draw-text (pane string center_x start_y) (let* ((strg-length (length string)) ; The length of the given string. (strg-list (if (or (equalp 0 strg-length) (not (find #\newline string))) (list string) ;If string is empty or contains no newlines, ;return a list containing that string. (loop for begin-point = 0 then end-point while (< begin-point strg-length) for cut-point = (position #\newline string :start begin-point :end strg-length) ;Cut just in front of the #\newline. for end-point = (if cut-point cut-point strg-length) collect (subseq string begin-point end-point) if cut-point do (setf end-point (1+ end-point)))) ;Don't include the #\newline itself in the next string. )) (draw-string-list pane strg-list center_x start_y))) (defun draw-string-list (pane strg-list center_x start_y) (let ((font (capi:simple-pane-font pane))) (loop for strg in strg-list ; (left top right bottom): for strgsize = (multiple-value-list (gp::get-string-extent pane strg font)) for xpos = (- center_x (* .5 (- (third strgsize) (first strgsize)))) for ypos = (- start_y (* .5 (- (fourth strgsize) (second strgsize)))) then (+ ypos -3 (- (fourth strgsize) (second strgsize))) ;The -3 above squishes the lines of text closer together. do (gp::draw-string pane strg xpos ypos :foreground (capi:simple-pane-foreground pane) :font font)))) A typical call would be (defmethod capi::draw-pinboard-object (pane (nod nodetype) &key &allow-other-keys) (capi:with-geometry nod (draw-text pane text (+ capi:%x% (floor capi:%width% 2)) (+ capi:%y% (floor (1- capi:%height%) 2) (gp:get-font-ascent pane (capi:simple-pane-font pane)))) you also need methods for capi::draw-pinboard-object-highlighted and capi::draw-pinboard-object-unhighlighted HTH, Ray Laning Tim Bradshaw <tfb@cley.com> To: lisp-hug@xanalys.com Sent by: cc: owner-lisp-hug@x Subject: Multi-line text in graphs (or other pinboard analys.com layouts). 05/14/02 05:53 AM Please respond to Tim Bradshaw I'd like to be able to produce trees/graphs where items have more than one line of text in them. If I try the obvious print-function-which-produces-newlines thing, this doesn't work - I just get black blobs where the newlines should be. I guess I need to use some item class which can hack newlines, or otherwise supports multi-line text. Does anyone know how to do this? Thanks --tim