;;; -*- Mode: Common-Lisp; Package: User; Base: 10.; Patch-File: T -*-
;;; Written 04/06/89 19:48:06 by marky,
;;; Reason: Changed tv:draw-shadow-border to work correctly on b&w and color
;;; monitors for w:menu-choose and w:mouse-confirm.
;;; while running on MX5 from band NB22
;;; With SYSTEM 5.19, GC 5.3, VIRTUAL-MEMORY 5.5, MICRONET 5.5, MICRONET-COMM 5.13,
;;;  DISK-IO 5.9, BASIC-PATHNAME 5.2, MAC-PATHNAME 5.0, NETWORK-SUPPORT-COLD 5.1,
;;;  BASIC-NAMESPACE 5.6, BASIC-FILE 5.3, RPC 5.4, NFS 5.10, EH 5.3, MAKE-SYSTEM 5.2,
;;;  MEMORY-AUX 5.1, MACTOOLBOX 1.25, COMPILER 5.1, TV 5.21, NVRAM 5.1, UCL 5.0, INPUT-EDITOR 5.0,
;;;  METER 5.0, ZWEI 5.9, DEBUG-TOOLS 5.1, WINDOW-MX 5.28, PRINTER 5.11, MAC-PRINTER-TYPES 5.4,
;;;  NETWORK-PATHNAME 5.0, NETWORK-NAMESPACE 5.0, DATALINK 5.7, CHAOSNET 5.6, NETWORK-SUPPORT 5.0,
;;;  NETWORK-SERVICE 5.0, DATALINK-DISPLAYS 5.0, NAMESPACE-EDITOR 5.1, IP 3.33, NFS-SERVER 5.3,
;;;  PRINTER-TYPES 5.2, IMAGEN 5.1, MAIL-DAEMON 5.1, MAIL-READER 5.3, TELNET 5.1,
;;;  VT100 5.0, STREAMER-TAPE 5.6, DECNET 1.45, VISIDOC 5.4, PROFILE 5.1, DISK-LABEL 5.1,
;;;   microcode 128, Band Name: microExplorer Network (11/22)


;; by may 04/06/89 

;; SPR 9504 PROBLEM : On a color screen the shadow border could
;; not be seen, and if in dual monitor mode, bits from the
;; black&white plane affected the shadow border. The first mistake
;; was in the patch for color which ONLY did the 2nd and 3rd bleed-thru
;; BITBLT's if color-sheet-p. Since there was some argument about how to
;; make shadow borders look right on a color system - the code WAS SUPPOSED
;; to NOT do the BITBLT's if on a color system - instead the code ONLY did
;; the BITBLT's on a color system - and did them wrong.
;;
;; Additional Changes: 
;; * Used color-sheet-p instead of color-system-p
;; * Rearranged order of BITBLT's so that it WORKS. The only broblem with
;;   this is that alu arg passed in is passed to the GRAY bitblt not to the
;;   bleed-thru bitblt - this is probably as it should be anyway!
;;
;;   The original ordering : 
;;    1. bitblt alu-seta   gray-level screen
;;    2. bitblt alu-transp temp-array screen
;;
;;   The NEW ordering : 
;;    1. bitblt alu-seta   temp-array screen
;;    2. bitblt alu-transp gray-level screen
;; 
;;   The difference is that when the new ordering is used the transp bitblt
;;   will cause a 1-bit array to be used. This means transp will work
;;   as follows : each 1 bit-value in the array will cause the foreground register
;;   to be written to the screen. NOTICE that this method changes the destination
;;   INDEPENDENTLY of what is on the screen at the time.
;;     If we start off with the temp-array - which
;;   just replaces the original screen contents - and then use the transp blt to
;;   darken 33% or 50% of the pixels - leaving other values alone - the net
;;   effect will be to darken (lighten if reverse-video-p) whatever colors are there.
;;     The OLD way did not work because the transparency was performed using
;;   the TEMP-ARRAY as the source - which could have many different colors -
;;   which quarantees only that the colors in the source which happen to also
;;   be in the screen - which has only two values ( unless in dual-monitor-p, which
;;   then causes the screen to have 4 values - #80 + the fg reg and bg reg ).
;;    So of ALL the possible colors in the src (temp-array), ONLY those colors
;;   that match will be LEFT ALONE so almost everything will get changed, typically.
;;   
;; * Removed unecesary (IF (SHEET-TEMPORARY-P WINDOW) ...) check since
;;   (SHEET-TEMPORARY-BIT-ARRAY WINDOW) and (ARRAYP TEMP-ARRAY) does this anyway.

#!C
; From file BASWIN.LISP#> WINDOW; SYS:
#10R TV#:
(COMPILER-LET ((*PACKAGE* (FIND-PACKAGE "TV"))
                          (SI:*LISP-MODE* :COMMON-LISP)
                          (*READTABLE* COMMON-LISP-READTABLE)
                          (SI:*READER-SYMBOL-SUBSTITUTIONS* SYS::*COMMON-LISP-SYMBOL-SUBSTITUTIONS*))
  (COMPILER#:PATCH-SOURCE-FILE "SYS: WINDOW; BASWIN.#"


(DEFUN DRAW-SHADOW-BORDER (WINDOW ALU LEFT TOP RIGHT BOTTOM WIDTH-OFFSET HEIGHT-OFFSET
			   &AUX (GRAY-LEVEL 50%-gray)
			   (WINDOW-SCREEN-ARRAY (SEND WINDOW :SCREEN-ARRAY))
                           (color-sheet (color-sheet-p window)))
  "Draw the shadow for the window."
  (when color-sheet
    ;; use an array with fewer bits, since the pixels are closer together
    ;; on the color screen as compared with the monochrome screen.
    (SETQ gray-level 33%-gray))

  (PREPARE-SHEET (WINDOW)
    ;; If the window is a temporary window then draw the invisible part.
    (LET ((TEMP-ARRAY (SHEET-TEMPORARY-BIT-ARRAY WINDOW)))
      ;; There will be no temporary-bit-array if the window is created
      ;; as a resource with SAVE-BITS set to T.  For this case (the
      ;; system menu for example), the window is created fully but not
      ;; exposed, hence it is a temporary window but has no
      ;; temporary-bit-array. ( until it is actually exposed - may 04/06/89 )
      
      ;; may 04/06/89 This does NOT work right on color
      ;; sheets, especially in dual-monitor-p mode since the
      ;; information in the temporary-bit-array contains bits
      ;; from ALL planes. Rearranged order of bitblts to make this work for color
      ;; and for b&w.
      (WHEN (ARRAYP TEMP-ARRAY)  ;; may 04/06/89 
	;; Make the existing screen contents bleed through the shadow
	(BITBLT ALU ;; this had better be alu-seta or what will happen is beyond me !
		(- RIGHT LEFT WIDTH-OFFSET)	; Width
		(- BOTTOM TOP HEIGHT-OFFSET)	; Height
		TEMP-ARRAY
		(+ LEFT WIDTH-OFFSET)
		(+ TOP HEIGHT-OFFSET)
		WINDOW-SCREEN-ARRAY
		(+ LEFT WIDTH-OFFSET)
		(+ TOP HEIGHT-OFFSET)))

      ;; Draw the shadow border.
      (BITBLT alu-transp (- RIGHT LEFT WIDTH-OFFSET) (- BOTTOM TOP HEIGHT-OFFSET) GRAY-LEVEL
	      (REM (+ LEFT WIDTH-OFFSET) (ARRAY-DIMENSION GRAY-LEVEL 1))
	      (REM (+ TOP HEIGHT-OFFSET) (ARRAY-DIMENSION GRAY-LEVEL 0))
	      WINDOW-SCREEN-ARRAY (+ LEFT WIDTH-OFFSET) (+ TOP HEIGHT-OFFSET))      
      
      (when (arrayp temp-array) ;; may 04/06/89 
	;; Show the existing screen contents in the part of the temporary
	;; window which has the corners.
	(BITBLT ALU-seta (IF (= 0 WIDTH-OFFSET)			;; Width
			     (- RIGHT LEFT)
			     WIDTH-OFFSET)
		(IF (= 0 HEIGHT-OFFSET)				;; Height
		    (- BOTTOM TOP)
		    HEIGHT-OFFSET)
		TEMP-ARRAY					;; From-array
		(REM LEFT (ARRAY-DIMENSION TEMP-ARRAY 1))	;; From-X
		(REM TOP  (ARRAY-DIMENSION TEMP-ARRAY 0))	;; From-Y
		WINDOW-SCREEN-ARRAY				;; To-array
		LEFT						;; To-X
		TOP						;; To-Y
		)))))
))
