ezd /src/rectangle.sc

Language Lisp Lines 217
MD5 Hash 8f5ec82cdbf36e176de4bbc28f84c4ca Estimated Cost $3,893 (why?)
Repository https://bitbucket.org/bunny351/ezd.git View Raw File View Project SPDX
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
;;; ezd - easy drawing for X11 displays.
;;;
;;; The procedures in this module generate the GRAPHIC objects representing
;;; rectangles and polygons.

;*           Copyright 1990-1993 Digital Equipment Corporation
;*                         All Rights Reserved
;*
;* Permission to use, copy, and modify this software and its documentation is
;* hereby granted only under the following terms and conditions.  Both the
;* above copyright notice and this permission notice must appear in all copies
;* of the software, derivative works or modified versions, and any portions
;* thereof, and both notices must appear in supporting documentation.
;*
;* Users of this software agree to the terms and conditions set forth herein,
;* and hereby grant back to Digital a non-exclusive, unrestricted, royalty-free
;* right and license under any changes, enhancements or extensions made to the
;* core functions of the software, including but not limited to those affording
;* compatibility with other hardware or software environments, but excluding
;* applications which incorporate this software.  Users further agree to use
;* their best efforts to return to Digital any such changes, enhancements or
;* extensions that they make and inform Digital of noteworthy uses of this
;* software.  Correspondence should be provided to Digital at:
;* 
;*                       Director of Licensing
;*                       Western Research Laboratory
;*                       Digital Equipment Corporation
;*                       250 University Avenue
;*                       Palo Alto, California  94301  
;* 
;* This software may be distributed (but not offered for sale or transferred
;* for compensation) to third parties, provided such third parties agree to
;* abide by the terms and conditions of this notice.  
;* 
;* THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
;* WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
;* MERCHANTABILITY AND FITNESS.   IN NO EVENT SHALL DIGITAL EQUIPMENT
;* CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
;* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
;* PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
;* ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
;* SOFTWARE.

(module rectangle)

(include "struct.sch")
(include "commands.sch")
(include "ginfo.sch")
(include "display.sch")
(include "view.sch")
(include "psdraw.sch")
(include "drawing.sch")
(include "graphic.sch")
(include "xternal.sch")

;;; A rectangle is generated by the following procedure.

(define (RECTANGLE x y width height line-width color dash)
    (make-graphic
	#f
	(lambda ()
		(let ((ux1 (user->x x))
		      (ux2 (user->x (+ x width)))
		      (uy1 (user->y y))
		      (uy2 (user->y (+ y height)))
		      (lwdiv2 (quotient (user->lw line-width) 2)))
		     (list (- (min ux1 ux2) lwdiv2)
			   (- (min uy1 uy2) lwdiv2)
			   (+ (max ux1 ux2) lwdiv2 1)
			   (+ (max uy1 uy2) lwdiv2 1))))
	(if (eq? color 'clear)
	    draw-clear
	    (lambda ()
		    (xdrawrectangle *dpy* *xwindow*
			(cv-gc (user->lw line-width) color #f dash #f #f)
			(min (user->x x) (user->x (+ x width)))
			(min (user->y y) (user->y (+ y height)))
			(user->width width) (user->height height))))
	(if (eq? color 'clear)
	    draw-clear
	    (lambda ()
		    (pscolor color)
		    (pscommand "newpath" x y "moveto" width 0 "rlineto"
			0 height "rlineto" (- width) 0 "rlineto"
			"closepath")
		    (psstroke (user->lw line-width) dash)))
	(lambda (minx miny maxx maxy)
		(let* ((lwdiv2 (quotient (user->lw line-width) 2))
		       (in-minx (+ x (width->user lwdiv2)))
		       (in-miny (+ y (height->user lwdiv2)))
		       (in-maxx (+ x width (- (width->user lwdiv2))))
		       (in-maxy (+ y height (- (height->user lwdiv2)))))
		      (not (and (<= in-minx minx maxx in-maxx)
				(<= in-miny miny maxy in-maxy)))))))

(define-ezd-command
    `(rectangle ,number? ,number? ,non-negative? ,non-negative?
	 (optional ,non-negative?) (optional ,color?) (optional ,dash?))
    "(rectangle x y width height [<line-width>] [<color>] [dash])"
    rectangle)

;;; A filled rectangle is generated by the following procedure.

(define (FILL-RECTANGLE x y width height color stipple)
    (make-graphic
	#f
	(lambda ()
		(let ((ux1 (user->x x))
		      (ux2 (user->x (+ x width)))
		      (uy1 (user->y y))
		      (uy2 (user->y (+ y height))))
		     (list (min ux1 ux2)
			   (min uy1 uy2)
			   (+ (max ux1 ux2) 1)
			   (+ (max uy1 uy2) 1))))
	(if (eq? color 'clear)
	    draw-clear
	    (lambda ()
		    (xfillrectangle *dpy* *xwindow*
			(cv-gc #f color stipple #f #f #f)
			(min (user->x x) (user->x (+ x width)))
			(min (user->y y) (user->y (+ y height)))
			(user->width width) (user->height height))))
	(if (eq? color 'clear)
	    draw-clear
	    (lambda ()
		    (pscolor color)
		    (pscommand "newpath" x y "moveto" width 0 "rlineto"
			0 height "rlineto" (- width) 0 "rlineto" "closepath"
			"fill")))
	(lambda (minx miny max maxy) #t)))

(define-ezd-command
    `(fill-rectangle ,number? ,number? ,non-negative? ,non-negative?
	 (optional ,color?) (optional ,stipple?))
    "(fill-rectangle x y width height [<color>] [<stipple>])"
    fill-rectangle)

;;; A filled polygon is generated by the following procedure.

(define (FILL-POLYGON points color stipple)
    (let ((buffer (make-string (* 4 (length points))))
	  (point-count (length points)))
	 
	 (define (LOAD-BUFFER)
		 (let loop ((i 0) (points points))
		      (if  points
			   (let ((x (caar points))
				 (y (cadar points)))
				(c-shortint-set! buffer i (user->x x))
				(c-shortint-set! buffer (+ i 2) (user->y y))
				(loop (+ i 4) (cdr points))))))
	 
	 (let loop ((pl points) (minx #f) (miny #f) (maxx #f) (maxy #f))
	      (if  pl
		   (let ((x (caar pl))
			 (y (cadar pl)))
			(loop (cdr pl) (bbmin x minx) (bbmin y miny)
			      (bbmax x maxx) (bbmax y maxy)))
		   (make-graphic
		       #f
		       (lambda ()
			       (let ((ux1 (user->x minx))
				     (ux2 (user->x maxx))
				     (uy1 (user->y miny))
				     (uy2 (user->y maxy)))
				    (list (min ux1 ux2)
					  (min uy1 uy2)
					  (+ (max ux1 ux2) 1)
					  (+ (max uy1 uy2) 1))))
		       (if (eq? color 'clear)
			   draw-clear
			   (lambda ()
				   (load-buffer)
				   (xfillpolygon *dpy* *xwindow*
				       (cv-gc #f color stipple #f #f #f)
				       (cons 'xpointap buffer) point-count
				       complex coordmodeorigin)))
		       (if (eq? color 'clear)
			   draw-clear
			   (lambda ()
				   (pscolor color)
				   (pscommand "newpath")
				   (let loop ((pl points) (cmd "moveto"))
					(when pl
					      (pscommand (caar pl)
						  (cadar pl) cmd)
					      (loop (cdr pl) "lineto")))
				   (pscommand "closepath" "fill")))
		       (lambda (minx miny maxx maxy)
			       (let ((region (begin (load-buffer)
						    (xpolygonregion
							(cons 'xpointap buffer)
							point-count
							evenoddrule))))
				    (define (IN? x y)
					    (not (zero? (xpointinregion
							    region (user->x x)
							    (user->y y)))))
				    (let ((in (or (in? minx miny)
						  (in? minx maxy)
						  (in? maxx miny)
						  (in? maxx maxy)
						  (in? (+ minx
							  (/ (- maxx minx) 2))
						       (+ miny
							  (/ (- maxy miny)
							     2))))))
					 (xdestroyregion region)
					 in))))))))

(define-ezd-command
    `(fill-polygon (repeat ,number? ,number?) (optional ,color?)
	 (optional ,stipple?))
    "(fill-polygon x1 y1 ... xn yn [<color>] [<stipple>])"
    fill-polygon)
Back to Top