guile-gtk-general
[Top][All Lists]
Advanced

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

Re: canvas bpath and def


From: Greg Troxel
Subject: Re: canvas bpath and def
Date: 08 Mar 2005 19:57:40 -0500
User-agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3

I found some bugs in my code (was using "hide" elsewhere in code,
since I used to create a new bpath and def each time).  But, some
mysterious behavior remains.  I tried to get to the minimal code to
keep things working, and find more done per-update than I would think.

Things that I still don't understand:

  If I don't do set-path-def anew, I don't get the new line.  It seems
  that this copies the contents of the def into the bpath, rather than
  referencing the def.  I expected that reset and redrawing the def
  would change the line.

  If I don't (move bpath 0 0) anew, the old line remains on the screen
  and is not replaced by the new.  A single move in create-line was
  insufficient.
 
This version seems much better about memory.   So I still believe that
gcing of a bpath does not free some resources in the guile process or
in the X server.


;; create a line object, with no path
(define (create-line color parent)
  (let*
      ((bpath (make <gnome-canvas-bpath>
                ;; parent must be first or this crashes!
                #:parent parent
                #:fill-color color
                #:width-pixels 20))
       (def (make <gnome-canvas-path-def>)))

    ;; Attach def as property so we can get at it - get-path-def
    ;; causes a stack overflow.
    (set-object-property! bpath 'def def)

    ;; It seems to suffice to do this only once.
    (gnome-canvas-item-lower-to-bottom bpath)

    bpath))

;; utility function that doesn't belong here
(define (draw-line bpath x1 y1 x2 y2 width)
  (let*
      ((def (object-property bpath 'def))
       (theta (atan (- y2 y1) (- x2 x1)))
       (right (+ theta 1.5707963267949))
       (incx (* width (cos right)))
       (incy (* width (sin right))))

    ;; Old segments are present, but modifying def does not affect
       bpath
    (reset def)
    (moveto def x1 y1)
    (lineto def x2 y2)
    (lineto def (+ x2 incx) (+ y2 incy))
    (lineto def (+ x1 incx) (+ y1 incy))
    (closepath def)

    ;; Why is this necessary every time?  Without it, the following
    ;; set-path-def has no effect and the old line remains.
    (move bpath 0 0)

    ;; Why must this be redone?  It seems that this copies the def
    ;; into the bpath, rather than referencing it.
    (set-path-def bpath def)

    ;; side-effect only - avoid return value
    #f))

(define-method (hide (l <link-map>))
  (let
      ((the-line (line l)))
    (if the-line
        (begin
          (hide the-line)
          (set! (line l) #f)))))

(define-method (do-notify-create (l <link-map>))
  (if (not (line l))
      (set! (line l)
            (create-line "black" (canvas-root (nodeset (endpoint1 l))))))
  (draw-line (line l)
             (x (endpoint1 l)) (y (endpoint1 l))
             (x (endpoint2 l)) (y (endpoint2 l))
             (metric-to-width (link-to-metric l))))




-- 
        Greg Troxel <address@hidden>




reply via email to

[Prev in Thread] Current Thread [Next in Thread]