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

Graphics clipping question



;;; -*- Syntax: Common-Lisp -*-

#||

Symbolics System, FEP1:>enhanced-pci-from-pci.load.1
3640 Processor, 1536K words Physical memory, 21250K words Swapping space.
 Genera                                             7.2
 System                                             376.158 (ECO level 6)
 Utilities                                          27.29   (ECO level 4)
 Server Utilities                                   28.5    (ECO level 1)
 Hardcopy                                           118.17  (ECO level 1)
 Zmail                                              165.20  (ECO level 1)
 LMFS                                               102.7   (ECO level 1)
 Tape                                               82.18   (ECO level 3)
 Nsage                                              27.120  (ECO level 1)
 Documentation Database                             62.1
 IP-TCP                                             67.5
 BBN site system                                    9.7
 Fortran                                            19.2
 Color Support                                      409.13
 Color                                              405.13
 Color Editor                                       405.1
 Color Doc                                          408.0
 SGD Book Design                                    2.6

I am trying to convert some graph drawing software to use GRAPHICS:
functions rather than window operations, and one thing i'm having
trouble with is clipping.  I need to be able to clip drawing
operations to the rectangular outline of the graph.  My old software
modified the TV:CLIPPING-REGION instance variable of the stream being
drawn on, and that worked fine.  This doesn't work with GRAPHICS:
functions because the stream you think you are drawing on often has
nothing to do with the steam you are actually drawing on because you
are in a maze of twistly little continuations all alike.

So, the question is what should i be using.  I've found
GRAPHICS:WITH-CLIPPING-FROM-OUTPUT, but i don't think it is what i
want. The following software and terminal hystery shows what happens.
It is a very simplified version of a typical situation: your data goes
from 0 <= x <= a zillion, but you are only interested in looking at
0 <= x <= 1000 say.  The function (TRY-CLIP WINDOW LENGTH) draws a
line of length LENGTH clipped to a small region on the window.  As
LENGTH increase, larger and larger TV:ROVING-BITMAPS get created in
the TV:BITMAP-STREAM resource.  For example LENGTH = 50000 produces a
bitmap over 50 screens wide.  Once you've created a bitmap that big,
the system just spends the rest of your life paging the bitmap in and
out until you do (SCL:CLEAR-RESOURCE 'TV:BITMAP-STREAM).

I can clip my own lines, but i hoped i could rely on Symbolics to clip
other arbitrary things like text, circles, etc.

Any suggestions?

||#

(defun try-clip (e length)
  (let ((w 200)
	(h 200))
    (let ((cx (/ w 2))
	  (cy (/ h 2)))
      (send e :expose)
      (graphics:with-room-for-graphics  (e h)
	(setq w (/ w 4) h (/ h 4))
	(graphics:draw-rectangle (- cx w) (+ cy h) (+ cx w) (- cy h)
				 :stream e :filled nil)	; Outline clipping region
	(decf w 1) (decf h 1)
	(graphics:with-clipping-from-output
	  (e (progn 
	       (print e)
	       (graphics:draw-rectangle (- cx w) (+ cy h) (+ cx w) (- cy h)
					:stream e :filled t)))
	  ;; Anything drawn below gets clipped
	  ;; Huge TV:ROVING-BITMAP created here
	  (graphics:draw-line 0 100 length 100 :stream e)
	  (print e))))))


;;; Terminal session:

(try-clip *terminal-io* 500)

#<Roving Bitmap 1  1280,791 x 1 2533256> 
#<Roving Bitmap 2  1280,791 x 1 2533430> 

NIL
(try-clip *terminal-io* 5000)


#<Roving Bitmap 1  1280,791 x 1 2533256> 
#<Roving Bitmap 2  5740,791 x 1 2533430> 

NIL
(try-clip *terminal-io* 50000)


#<Roving Bitmap 1  1280,791 x 1 2533256> 
#<Roving Bitmap 2  52970,791 x 1 2533430> 

NIL