;;; -*- Mode: Common-Lisp; Package: User; Base: 10.; Patch-File: T -*-

;;; Reason: Fixes problem with unfilled arcs of line width = 1. When drawn to a
;;;  mapped drawable, they would be erased every other time they were
;;;  drawn. That is, they behaved as if they were being XORed.

;;;                           RESTRICTED RIGHTS LEGEND
;;;
;;; Use, duplication, or disclosure by the Government is subject to
;;; restrictions as set forth in subdivision (c)(1)(ii) of the Rights in
;;; Technical Data and Computer Software clause at 52.227-7013.
;;;
;;;   TEXAS INSTRUMENTS INCORPORATED      
;;;   P.O. BOX 2909, M/S 2151             
;;;   AUSTIN, TEXAS 78769                 
;;;
;;; Copyright (C) 1989 Texas Instruments Incorporated.
;;; All rights reserved.

;;; Written 11/21/89 14:42:28 by HAGY,
;;; while running on Zwingli from band LOD1
;;; With SYSTEM 6.15, VIRTUAL-MEMORY 6.1, EH 6.4, MAKE-SYSTEM 6.0, MICRONET 6.0, LOCAL-FILE 6.0,
;;;  BASIC-PATHNAME 6.1, NETWORK-SUPPORT-COLD 6.0, BASIC-NAMESPACE 6.2, NETWORK-NAMESPACE 6.0,
;;;  DISK-IO 6.1, DISK-LABEL 6.0, BASIC-FILE 6.2, MAC-PATHNAME 6.0, NETWORK-PATHNAME 6.0,
;;;  COMPILER 6.10, TV 6.15, DATALINK 6.0, CHAOSNET 6.0, GC 6.3, MEMORY-AUX 6.0, NVRAM 6.1,
;;;  SYSLOG 6.1, STREAMER-TAPE 6.4, UCL 6.0, INPUT-EDITOR 6.0, METER 6.1, ZWEI 6.5,
;;;  DEBUG-TOOLS 6.3, NETWORK-SUPPORT 6.0, NETWORK-SERVICE 6.1, DATALINK-DISPLAYS 6.0,
;;;  FONT-EDITOR 6.1, SERIAL 6.0, PRINTER 6.3, MAC-PRINTER-TYPES 6.1, PRINTER-TYPES 6.1,
;;;  IMAGEN 6.0, SUGGESTIONS 6.0, MAIL-DAEMON 6.2, MAIL-READER 6.2, TELNET 6.0, VT100 6.0,
;;;  NAMESPACE-EDITOR 6.0, PROFILE 6.1, VISIDOC 6.4, TI-CLOS 6.20, CLEH 6.5, IP 3.47,
;;;  Experimental CLX 6.7, CLUE 6.10, X11M 6.16, Experimental BUG 11.15,  microcode 429,
;;;  Band Name: Rel 6.0 + SLE 9/8

#!C
; From file POLY-ARC-REQUESTS.LISP#> X11M.SERVER; SYS:
#10R X11#:
(COMPILER-LET ((*PACKAGE* (FIND-PACKAGE "X11"))
                          (SI:*LISP-MODE* :COMMON-LISP)
                          (*READTABLE* SYS:COMMON-LISP-READTABLE)
                          (SI:*READER-SYMBOL-SUBSTITUTIONS* SYS::*COMMON-LISP-SYMBOL-SUBSTITUTIONS*))
  (COMPILER#:PATCH-SOURCE-FILE "SYS: X11M.SERVER; POLY-ARC-REQUESTS.#"


(DEFUN POLY-ARC (GCONTEXT DRAWABLE NUM-ARCS ARC-ARRAY ARRAY-OFFSET)
  " Draws circular or elliptical arcs .  Each arc is
 specified by a rectangle and two angles.  The angles are signed
 integers in degrees scaled by 64, with positive indicating
 counterclockwise motion and negative indicating clockwise motion.  The
 start of the arc is specified by angle1 relative to the three-oclock
 position from the center of the rectangle, and the path and extent of
 the arc is specified by angle2 relative to the start of the
 arc."
  
;;;  X-ORG,Y-ORG of DRAWABLE   
;;;     o--------------------->
;;;     | \
;;;     |   \  
;;;     |     \
;;;     |       \
;;;     V         \
;;;             RECT-X,RECT-Y        TOP-X and Y INT                         
;;;                    O------------------X--------------------o  ^
;;;                    |                                       |  |                                          
;;;                    |                                       |  |                                             
;;;                    |                                       |  HALF-H                                         
;;;                    |                                       |  |                                          
;;;                    |                                       |  |                                          
;;;                    |          CENTER-X,CENTER-Y             |  V
;;;  LEFT-X and Y INT  X                  X                    X        RIGHT-X and Y INT                         
;;;                    |                                       |                                             
;;;                    |                                       |                                             
;;;                    |                                       |
;;;                    |                                       |                                             
;;;                    |                                       |                                             
;;;                    |                                       |                                             
;;;                    o------------------X--------------------o
;;;                                BOT-X and Y INT                         
  
						; DOWN THE ARRAY GRABING [X,Y,W,H, ANGLE1, ANGLE2] FOR EACH ARC.....
  
  (with-drawable (drawable gcontext :clipping-rectangle t
			   ;; Wide lines overlap.  Force drawing to a temporary when alu is xor.
			   :overlap (and (>= (gcontext.line-width gcontext) 1) :always))  ; LEH - SPR 9491
		 (destination-array window-x window-y alu drawable-boundaries)
    (setq alu (AREF X-ALU-TO-EXPLORER-ALU alu))
    (LET* ((INDEX ARRAY-OFFSET)
	   (HALF-WIDTH     (/ (GCONTEXT.LINE-WIDTH  GCONTEXT) 2.0s0 ))	; GETHALF-WIDTH IF WIDE.
	   )
      (DOTIMES (I NUM-ARCS)
	(let* ((X          (AREF ARC-ARRAY INDEX))    
	       (Y          (AREF ARC-ARRAY (+ INDEX 1 ))) 
	       (RECT-X     (+ X window-X )) ;;(+ X X-ORG))             
	       (RECT-Y     (+ Y window-Y )) ;;(+ Y Y-ORG))
	       (W          (AREF ARC-ARRAY  (+ INDEX 2)))
	       (H          (AREF ARC-ARRAY (+ INDEX 3))) 
	       (HALF-W     (ROUND W 2))
	       (HALF-H     (ROUND H 2))
	       (CENTER-X    (+ RECT-X HALF-W)) 
	       (CENTER-Y    (+ RECT-Y HALF-H)) 
	       ;; CONVERT TO SCALED ANGLES
	       (theta1 (* (AREF-INT16 ARC-ARRAY  (+ INDEX 4)) radians-per-UNSCALED-degrees))
	       (theta2 (* (AREF-INT16 ARC-ARRAY  (+ INDEX 5)) radians-per-UNSCALED-degrees)))
	  (INCF INDEX 6)			;next arc
	  ;; RETURN ANGLES IN UNSCALED RADIANS
	  (unless (OR (zerop theta2) (ZEROP half-w) (ZEROP half-h))
	    ;; JUST DOIT
	    (if nil ;; ellipse is fast and general ;; (eql half-w half-h) ;; circular pie