<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<font size="+1"><font face="Arial">Good afternoon from Greg Bennett<br>
<br>
Running under Windows 7; Clozure version 14869; 32-bit
implementation,<br>
I am trying to erase something I have just drawn - a line
diagonally<br>
across a view. The code below works partially as the comment
indicates.<br>
<br>
From the fact that the Cocoa Drawing Guide does not mention
erasing<br>
(except for EraseRect) as far as I can see, I assume that I am
not thinking<br>
correctly about the updating of a view through the removal of an
existing<br>
element; pointers to the right way to think about things would
be much<br>
appreciated.<br>
<br>
Cheers /Greg<br>
<br>
;; This is erasing.lisp in CCL-CODE<br>
;; 16 August 2011<br>
;; This sequence seems to work partially<br>
;; The original line fades with successive calls to<br>
;; drawing with the background color of the window<br>
;; but it never completely disappears<br>
<br>
(in-package :ccl)<br>
;; the seemingly inevtiable wrapper for Windows<br>
(defmacro with-focused-view (view &body forms)<br>
`(when (#/lockFocusIfCanDraw ,view)<br>
(unwind-protect<br>
(progn ,@forms)<br>
(#/unlockFocus ,view)<br>
(#/flushGraphics (#/currentContext
ns:ns-graphics-context))<br>
(#/flushWindow (#/window ,view)))))<br>
<br>
(setf w1 (make-instance 'ns:ns-window :x 50 :y 50 :width 400
:height 400))<br>
<br>
(#/orderFront: w1 nil)<br>
;; There is the empty window<br>
(with-focused-view (#/contentView w1)<br>
(let* ((path (#/bezierPath ns:ns-bezier-path)))<br>
(#/moveToPoint: path (ns:make-ns-point 10 10))<br>
(#/lineToPoint: path (ns:make-ns-point 400 400))<br>
(#/stroke path)<br>
))<br>
<br>
;; There is a line diagonally across the view<br>
<br>
;; Add a horizontal line too<br>
(with-focused-view (#/contentView w1)<br>
(let* ((path (#/bezierPath ns:ns-bezier-path)))<br>
(#/moveToPoint: path (ns:make-ns-point 10 300))<br>
(#/lineToPoint: path (ns:make-ns-point 400 300))<br>
(#/stroke path)<br>
))<br>
;; OK<br>
;; To erase the diagonal, try drawing with stroke color =
background color <br>
;; from CocoaDrawingGuide P63<br>
;; set the stoke color<br>
;; note that #/backgoundColor works on windows rather than views<br>
;; -- interesting<br>
<br>
(#/setStroke (#/backgroundColor w1)) <br>
;-> NIL<br>
(with-focused-view (#/contentView w1)<br>
(let* ((path (#/bezierPath ns:ns-bezier-path)))<br>
(#/moveToPoint: path (ns:make-ns-point 10 10))<br>
(#/lineToPoint: path (ns:make-ns-point 400 400))<br>
(#/stroke path)<br>
))<br>
;-> NIL<br>
;; and the path fades but does not vanish<br>
;; perhaps a redisplay will help<br>
(#/setNeedsDisplay: (#/contentView w1) #$YES)<br>
;-> NIL<br>
;; and the window/view is cleared!<br>
;; With the extra, horizontal line, #/setNeedsDisplay erases
both<br>
;; It even erases a single line without changing the stroke
color ... Hmm!<br>
<br>
</font></font>
</body>
</html>