[Openmcl-devel] erasing under Windows

Greg Bennett gwbennett at sentex.ca
Tue Aug 16 14:00:55 PDT 2011


Good afternoon from Greg Bennett

Running under Windows 7; Clozure version 14869; 32-bit implementation,
I am trying to erase something I have just drawn - a line diagonally
across a view. The code below works partially as the comment indicates.

 From the fact that the Cocoa Drawing Guide does not mention erasing
(except for EraseRect) as far as I can see, I assume that I am not thinking
correctly about the updating of a view through the removal of an existing
element; pointers to the right way to think about things would be much
appreciated.

Cheers /Greg

;; This is erasing.lisp in CCL-CODE
;; 16 August 2011
;; This sequence seems to work partially
;; The original line fades with successive calls to
;; drawing with the background color of the window
;; but it never completely disappears

(in-package :ccl)
;; the seemingly inevtiable wrapper for Windows
(defmacro with-focused-view (view &body forms)
   `(when (#/lockFocusIfCanDraw ,view)
      (unwind-protect
       (progn , at forms)
        (#/unlockFocus ,view)
        (#/flushGraphics (#/currentContext ns:ns-graphics-context))
        (#/flushWindow (#/window ,view)))))

(setf w1 (make-instance 'ns:ns-window :x 50 :y 50 :width 400 :height 400))

(#/orderFront: w1 nil)
;; There is the empty window
(with-focused-view (#/contentView w1)
     (let* ((path (#/bezierPath ns:ns-bezier-path)))
       (#/moveToPoint: path (ns:make-ns-point 10 10))
       (#/lineToPoint: path (ns:make-ns-point 400 400))
       (#/stroke path)
       ))

;; There is a line diagonally across the view

;; Add a horizontal line too
(with-focused-view (#/contentView w1)
     (let* ((path (#/bezierPath ns:ns-bezier-path)))
       (#/moveToPoint: path (ns:make-ns-point 10 300))
       (#/lineToPoint: path (ns:make-ns-point 400 300))
       (#/stroke path)
       ))
;; OK
;; To erase the diagonal, try drawing with stroke color = background color
;; from CocoaDrawingGuide P63
;; set the stoke color
;; note that #/backgoundColor works on windows rather than views
;; -- interesting

(#/setStroke (#/backgroundColor w1))
;-> NIL
(with-focused-view (#/contentView w1)
     (let* ((path (#/bezierPath ns:ns-bezier-path)))
       (#/moveToPoint: path (ns:make-ns-point 10 10))
       (#/lineToPoint: path (ns:make-ns-point 400 400))
       (#/stroke path)
       ))
;-> NIL
;; and the path fades but does not vanish
;; perhaps a redisplay will help
(#/setNeedsDisplay: (#/contentView w1) #$YES)
;-> NIL
;; and the window/view is cleared!
;; With the extra, horizontal line, #/setNeedsDisplay erases both
;; It even erases a single line without changing the stroke color ... Hmm!

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.clozure.com/pipermail/openmcl-devel/attachments/20110816/7e754fd5/attachment.htm>


More information about the Openmcl-devel mailing list