Re: [racket-users] Re: EDIT: Building a rectangle builder: trailing rectangle bug.

2020-11-23 Thread KOKOU AFIDEGNON
Hi Alex, thanks for your reply. Are you on Slack?

On Tue, Nov 24, 2020, 00:21 Alex Harsanyi  wrote:

> The snip selection and resize is handled by the pasteboard
> on-default-event, and it looks like your code also handles events,
> resulting in duplicate handling.   There is no clear solution to this, as
> the system does not know if you want to select snips or draw rectangles.
>  However, you could use Ctrl + drag to draw the rectangles.  To do that,
> move your own code into a new method, say "my-on-default-event" and call
> that method for mouse events which have the control key set.
>
>  (define/override (on-default-event event)
>(if (send event get-control-down)
>(on-default-event-1 event)
>(super on-default-event event)))
>
> The disadvantage now, is that there is no visual feedback when you use
> Ctrl + drag (previously, the selection rectangle was drawn).  To draw an
> intermediate selection rectangle, you can track mouse motion events in your
> "my-on-default-event" and keep the intermediate rectangle, same as you do
> for "start-pos", than override the "on-paint" method of the pasteboard to
> draw the intermediate rectangle.  Note that you cannot call on-paint
> directly from on-default-event, and the pasteboard does not know it needs
> to redraw itself unless you call "refresh".
>
> Alex.
>
> On Monday, November 23, 2020 at 7:49:00 PM UTC+8 kokou.a...@gmail.com
> wrote:
>
>>
>>
>>
>>
>> *please, disregard the previous email, there was a little bug. this is
>> the correct code. the issue still exists. *
>>
>> I can click to drag in order to draw a rectangle, but when i drag the
>> created rectangle (for position adjustment), a new rectangle is created
>> from the said position. How do i constrain/fix the issue? i have been
>> trying to use key-combination to draw a new rectangle on demand. How do i
>> fix it ?
>>
>> ```
>> #lang racket/gui
>>
>> (define (maybe-set-box! b v)
>>   (when b
>> (set-box! b v)))
>>
>>
>>
>> (define rect-snip-class%
>>   (class snip-class%
>> (inherit set-classname)
>> (super-new)
>>
>> (set-classname "rect-snip-class%")
>> ))
>>
>>
>> (define rect-snip-class (new rect-snip-class%))
>>
>> (define rect-snip%
>>   (class snip%
>> (inherit set-snipclass
>>  set-flags get-flags
>>  get-admin)
>> (init w h)
>> (super-new)
>> (set-snipclass rect-snip-class)
>> (define height h)
>> (define width w)
>>
>> (define/override (get-extent dc x y [w #f] [h #f] . _)
>>   (maybe-set-box! w width)
>>   (maybe-set-box! h height))
>>
>> (define/override (draw dc x y left top right bottom . _)
>>   (send dc draw-rectangle x y width height))
>> ))
>>
>>
>>
>> (define pb
>>   (new
>>(class pasteboard%
>>  (super-new)
>>  (inherit insert)
>>
>>  (define start-pos #f)
>>
>>  (define/override (on-default-event event)
>>(super on-default-event event)
>>(define x (send event get-x))
>>(define y (send event get-y))
>>(cond
>>  [(and (equal? (send event get-event-type) 'left-down)
>>(send event button-down? 'left)
>>(not (send event dragging?)))
>>   (set! start-pos (cons x y))]
>>  [(and (equal? (send event get-event-type) 'left-up)
>>start-pos)
>>   (let ([dx (- (car start-pos) x)]
>> [dy (- (cdr start-pos) y)])
>> (define-values (nx nw)
>>   (if (> dx 0)
>>   (values x dx)
>>   (values (+ x dx) (abs dx
>> (define-values (ny nh)
>>   (if (> dy 0)
>>   (values y dy)
>>   (values (+ y dy) (abs dy
>> (define sn (new rect-snip%
>> [w nw]
>> [h nh]))
>> (insert sn nx ny)
>> (set! start-pos #f))]))
>>
>>
>>  )))
>>
>> (define f-main (new frame% [label "wireframe"]))
>> (define cnv-main (new editor-canvas%
>>   [editor pb]
>>   [parent f-main]))
>>
>>
>> (send f-main show #t)
>> ```
>>
>> --
> You received this message because you are subscribed to the Google Groups
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to racket-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/racket-users/c1da5a4e-730f-43ec-8d53-c6e223225b0an%40googlegroups.com
> 
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 

[racket-users] Re: EDIT: Building a rectangle builder: trailing rectangle bug.

2020-11-23 Thread Alex Harsanyi
The snip selection and resize is handled by the pasteboard 
on-default-event, and it looks like your code also handles events, 
resulting in duplicate handling.   There is no clear solution to this, as 
the system does not know if you want to select snips or draw rectangles.  
 However, you could use Ctrl + drag to draw the rectangles.  To do that, 
move your own code into a new method, say "my-on-default-event" and call 
that method for mouse events which have the control key set.

 (define/override (on-default-event event)
   (if (send event get-control-down)
   (on-default-event-1 event)
   (super on-default-event event)))

The disadvantage now, is that there is no visual feedback when you use Ctrl 
+ drag (previously, the selection rectangle was drawn).  To draw an 
intermediate selection rectangle, you can track mouse motion events in your 
"my-on-default-event" and keep the intermediate rectangle, same as you do 
for "start-pos", than override the "on-paint" method of the pasteboard to 
draw the intermediate rectangle.  Note that you cannot call on-paint 
directly from on-default-event, and the pasteboard does not know it needs 
to redraw itself unless you call "refresh".

Alex.

On Monday, November 23, 2020 at 7:49:00 PM UTC+8 kokou.a...@gmail.com wrote:

>
>
>
>
> *please, disregard the previous email, there was a little bug. this is the 
> correct code. the issue still exists. *
>
> I can click to drag in order to draw a rectangle, but when i drag the 
> created rectangle (for position adjustment), a new rectangle is created 
> from the said position. How do i constrain/fix the issue? i have been 
> trying to use key-combination to draw a new rectangle on demand. How do i 
> fix it ? 
>
> ```
> #lang racket/gui
>
> (define (maybe-set-box! b v)
>   (when b
> (set-box! b v)))
>
>
>
> (define rect-snip-class%
>   (class snip-class%
> (inherit set-classname)
> (super-new)
>
> (set-classname "rect-snip-class%")
> ))
>
>
> (define rect-snip-class (new rect-snip-class%))
>
> (define rect-snip%
>   (class snip%
> (inherit set-snipclass
>  set-flags get-flags
>  get-admin)
> (init w h)
> (super-new)
> (set-snipclass rect-snip-class)
> (define height h)
> (define width w)
>
> (define/override (get-extent dc x y [w #f] [h #f] . _)
>   (maybe-set-box! w width)
>   (maybe-set-box! h height))
>
> (define/override (draw dc x y left top right bottom . _)
>   (send dc draw-rectangle x y width height))
> ))
>
>
>
> (define pb
>   (new
>(class pasteboard%
>  (super-new)
>  (inherit insert)
>
>  (define start-pos #f)
>
>  (define/override (on-default-event event)
>(super on-default-event event)
>(define x (send event get-x))
>(define y (send event get-y))
>(cond
>  [(and (equal? (send event get-event-type) 'left-down)
>(send event button-down? 'left)
>(not (send event dragging?)))
>   (set! start-pos (cons x y))]
>  [(and (equal? (send event get-event-type) 'left-up)
>start-pos)
>   (let ([dx (- (car start-pos) x)]
> [dy (- (cdr start-pos) y)])
> (define-values (nx nw)
>   (if (> dx 0)
>   (values x dx)
>   (values (+ x dx) (abs dx
> (define-values (ny nh)
>   (if (> dy 0)
>   (values y dy)
>   (values (+ y dy) (abs dy
> (define sn (new rect-snip%
> [w nw]
> [h nh]))
> (insert sn nx ny)
> (set! start-pos #f))]))
>
>
>  )))
>
> (define f-main (new frame% [label "wireframe"]))
> (define cnv-main (new editor-canvas%
>   [editor pb]
>   [parent f-main]))
>
>
> (send f-main show #t)
> ```
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/c1da5a4e-730f-43ec-8d53-c6e223225b0an%40googlegroups.com.