Lisp HUG Maillist Archive

capi bounding rects question

I'm building a simple 2D graphics editor using CAPI, using pinboard objects.  
I noticed that many of my objects would not redraw correctly.  For example, 
when I slide (using the mouse) another window over the pinboard and slide it 
off, the damaged objects sometimes do not redraw at all.  It looks like I'm 
not causing the bounding rect of capi objects to be set correctly, or that I 
have a basic misunderstanding somewhere.

Here's a lump of code that appears to demonstrate my problem (a slightly 
modified version of example code in the manual).  Test1 and test2 cause two 
3x3 grids of rectangles to be drawn.  The test2 rectangles are the size of 
the "bounding box" (to my current understanding) and the test1 rectangles are 
slightly smaller.  If you grab, say, the Listener window and slide it slowly 
over these two windows, the test1 rectangles redraw, whereas the test2 
rectangles lose parts of their sides (sometimes).  I get the same results in 
LWW and LWL (4.2.7).  I expected the test2 rectangles to redraw fully (since 
their edges are coincident with the "bounding box" and the damage 
rectangles).

Can anyone spot the bug in my understanding or my code?

thanx
pt


(defclass small-rectangle (capi:drawn-pinboard-object)
  ((id :accessor id :initarg :id :initform nil))
  (:default-initargs
   :display-callback 'draw-small-rectangle
   :visible-min-width 30
   :visible-min-height 30))
   

(defun draw-small-rectangle (gp pane x y w h)
  (capi:with-geometry pane
    (gp:draw-rectangle gp
                       (+ 1 capi:%x%)
                       (+ 1 capi:%y%)
                       (- capi:%width% 2)
                       (- capi:%height% 2))))

(defclass big-rectangle (capi:drawn-pinboard-object)
  ((id :accessor id :initarg :id :initform nil))
  (:default-initargs
   :display-callback 'draw-big-rectangle
   :visible-min-width 30
   :visible-min-height 30))
   

(defun draw-big-rectangle (gp pane x y w h)
  (capi:with-geometry pane
    (gp:draw-rectangle gp capi:%x% capi:%y%
                       capi:%width% capi:%height%)))

(defun test1 ()
  (capi:contain
   (make-instance 'capi:grid-layout
                  :description (loop for i below 9
                                     collect
                                     (make-instance 'small-rectangle))
                  :columns 3)))

(defun test2 ()
  (capi:contain
   (make-instance 'capi:grid-layout
                  :description (loop for i below 9
                                     collect
                                     (make-instance 'big-rectangle))
                  :columns 3)))
  


Re: capi bounding rects question

I had the same problem then discovered I had to explicitly provide :x, :y,
:width
and :height initargs when constructing drawn-pinboard-objects. I suspect my
original
expectation was from having used CLIM previously.

Greg

----- Original Message -----
From: "Paul Tarvydas" <tarvydas@attcanada.ca>
To: <lisp-hug@xanalys.com>
Sent: Sunday, January 05, 2003 2:32 PM
Subject: capi bounding rects question


> I'm building a simple 2D graphics editor using CAPI, using pinboard
objects.
> I noticed that many of my objects would not redraw correctly.  For
example,
> when I slide (using the mouse) another window over the pinboard and slide
it
> off, the damaged objects sometimes do not redraw at all.  It looks like
I'm
> not causing the bounding rect of capi objects to be set correctly, or that
I
> have a basic misunderstanding somewhere.
>
> Here's a lump of code that appears to demonstrate my problem (a slightly
> modified version of example code in the manual).  Test1 and test2 cause
two
> 3x3 grids of rectangles to be drawn.  The test2 rectangles are the size of
> the "bounding box" (to my current understanding) and the test1 rectangles
are
> slightly smaller.  If you grab, say, the Listener window and slide it
slowly
> over these two windows, the test1 rectangles redraw, whereas the test2
> rectangles lose parts of their sides (sometimes).  I get the same results
in
> LWW and LWL (4.2.7).  I expected the test2 rectangles to redraw fully
(since
> their edges are coincident with the "bounding box" and the damage
> rectangles).
>
> Can anyone spot the bug in my understanding or my code?
>
> thanx
> pt
>
>
> (defclass small-rectangle (capi:drawn-pinboard-object)
>   ((id :accessor id :initarg :id :initform nil))
>   (:default-initargs
>    :display-callback 'draw-small-rectangle
>    :visible-min-width 30
>    :visible-min-height 30))
>
>
> (defun draw-small-rectangle (gp pane x y w h)
>   (capi:with-geometry pane
>     (gp:draw-rectangle gp
>                        (+ 1 capi:%x%)
>                        (+ 1 capi:%y%)
>                        (- capi:%width% 2)
>                        (- capi:%height% 2))))
>
> (defclass big-rectangle (capi:drawn-pinboard-object)
>   ((id :accessor id :initarg :id :initform nil))
>   (:default-initargs
>    :display-callback 'draw-big-rectangle
>    :visible-min-width 30
>    :visible-min-height 30))
>
>
> (defun draw-big-rectangle (gp pane x y w h)
>   (capi:with-geometry pane
>     (gp:draw-rectangle gp capi:%x% capi:%y%
>                        capi:%width% capi:%height%)))
>
> (defun test1 ()
>   (capi:contain
>    (make-instance 'capi:grid-layout
>                   :description (loop for i below 9
>                                      collect
>                                      (make-instance 'small-rectangle))
>                   :columns 3)))
>
> (defun test2 ()
>   (capi:contain
>    (make-instance 'capi:grid-layout
>                   :description (loop for i below 9
>                                      collect
>                                      (make-instance 'big-rectangle))
>                   :columns 3)))
>
>


Re: capi bounding rects question

On Sun, 2003-01-05 at 19:32, Paul Tarvydas wrote:
> I'm building a simple 2D graphics editor using CAPI, using pinboard objects.  
> I noticed that many of my objects would not redraw correctly.  For example, 
> when I slide (using the mouse) another window over the pinboard and slide it 
> off, the damaged objects sometimes do not redraw at all.  It looks like I'm 
> not causing the bounding rect of capi objects to be set correctly, or that I 
> have a basic misunderstanding somewhere.
> 
> Here's a lump of code that appears to demonstrate my problem (a slightly 
> modified version of example code in the manual).  Test1 and test2 cause two 
> 3x3 grids of rectangles to be drawn.  The test2 rectangles are the size of 
> the "bounding box" (to my current understanding) and the test1 rectangles are 
> slightly smaller.  If you grab, say, the Listener window and slide it slowly 
> over these two windows, the test1 rectangles redraw, whereas the test2 
> rectangles lose parts of their sides (sometimes).  I get the same results in 

I think it happens because you cannot use every pixel on the border of
the pane. When the mouse goes over a pane it is highlighted by drawing a
frame inside the pane and not outside. In order to user a smaller part
of the pane you may use a macro like this one:

(defmacro my-with-geometry (pane &body body)
  `(capi:with-geometry ,pane 
     (progn 
       (let ((capi:%x% (+ 1 capi:%x%))
             (capi:%y% (+ 1 capi:%y%))
             (capi:%width% (- capi:%width% 2))
             (capi:%height% (- capi:%height% 2)))
         ,@body))))

but I am not sure this is what you want to do. 
The right way would be to prevent the highlighting of the pane but I
don't know how to do that.

Thibault

> LWW and LWL (4.2.7).  I expected the test2 rectangles to redraw fully (since 
> their edges are coincident with the "bounding box" and the damage 
> rectangles).
> 
> Can anyone spot the bug in my understanding or my code?
> 
> thanx
> pt
> 


-- 
Thibault Langlois <tl@inesc-id.pt>


Re: capi bounding rects question

Hello Paul,

| I'm building a simple 2D graphics editor using CAPI, using pinboard
| objects.  I noticed that many of my objects would not redraw correctly.
| For example, when I slide (using the mouse) another window over the
| pinboard and slide it off, the damaged objects sometimes do not redraw
| at all.  It looks like I'm not causing the bounding rect of capi
| objects to be set correctly, or that I have a basic misunderstanding
| somewhere.
|
| Here's a lump of code that appears to demonstrate my problem (a
| slightly modified version of example code in the manual).  Test1 and
| test2 cause two 3x3 grids of rectangles to be drawn.  The test2
| rectangles are the size of the "bounding box" (to my current
| understanding) and the test1 rectangles are slightly smaller.  If you
| grab, say, the Listener window and slide it slowly over these two
| windows, the test1 rectangles redraw, whereas the test2 rectangles lose
| parts of their sides (sometimes).  I get the same results in LWW and
| LWL (4.2.7).  I expected the test2 rectangles to redraw fully (since
| their edges are coincident with the "bounding box" and the damage
| rectangles).
|
| Can anyone spot the bug in my understanding or my code?
|...snip...|

In my LWW 4.2.5, both of them sometimes get redrawn correctly, but sometimes
look damaged on depressing the mouse button. Later, on moving the mouse
pointer they are completely restored.

I consider this a CAPI feature of redrawing in a background process.
---
Sincerely,
Dmitri Ivanov
www.aha.ru/~divanov


Updated at: 2020-12-10 09:01 UTC