[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Color Text on CAD Buffer II --- revisited



The idea of changing the default char-aluf out from under the screen is
a real win.  I want to especially thank Peter Paine, who had the same
idea, and who also sent along this useful macro to handle the various
issues. 

    A macro to wrap around you code, so that the printer produces the color
    of your choice:

    (defmacro MAYBE-WITH-COLOR-CHAR-ALUF (&optional alu (stream *standard-output*) &body body)
      `(if (and ,alu
		(eq (send (send ,stream :screen) :video) :color))
	   (let ((old-alu (send ,stream :char-aluf)))
	     (unwind-protect
		 (progn
		   (send ,stream :set-char-aluf ,alu)
		   ,@body)
	       (send ,stream :set-char-aluf old-alu)))
	   ,@body))

    (let ((active T) ;; your choice
	  (screen (send *standard-output* :screen)))
      (maybe-with-color-char-aluf
	(if active ;; save the color alus for reuse
	   (send screen :compute-color-alu tv:alu-seta 0 0 1) ;; blue
	   (send screen :compute-color-alu tv:alu-seta 1 0 0)) ;; red
	window
	(format *standard-output* "~&Test text in ~Aactive color" (if active "" "in"))))

    It is probably a good idea to store ready-made color alus as properties
    associated with your code. To make alus, it is probably easiest to use
    the :compute-color-alu message; it is easy enough to get you colors by
    blending red green and blue to taste.

    Alternatively try using the graphics:draw-string function with an alu
    argument or (for simple colors) the :color argument. Eg.
    (graphics:draw-string "Test" x y :color :yellow)

    <= p2