Xojo Conferences
MBSOct2019CologneDE

control dragging (Real Studio network user group Mailinglist archive)

Back to the thread list
Previous thread: Parsing text file
Next thread: App slowing down


Re: Stuffit...=> Five comments and one offer $$$$$$$!   -   Patrick Wynne
  control dragging   -   Craig A. Finseth
   Re: control dragging   -   Seth Willits
    Re: control dragging   -   Craig A. Finseth
   Re: control dragging   -   Seth Willits

control dragging
Date: 31.05.02 17:07 (Fri, 31 May 2002 11:07:19 -0500 (CDT))
From: Craig A. Finseth
I'm trying to implement a simple control drag.

My MouseDown handler is:

dragx = x
startx = me.Left
return true

and my MouseDrag handler is:

me.Left = startx - (dragx - x)

dragx and startx are Properties declared as Integers.

So far so good. If the control is an ImageWell, dragging is very
smooth. If the control is a Canvas or Rect, dragging causes the
control to bounce all over, sort of like changing the me.Left value
causes the MouseDrag handler to be called again.

But ImageWell is derived from Canvas!

Anyone have any idea of what I'm doing wrong here?


---
Subscribe to the digest:
<mailto:<email address removed>>
Unsubscribe:
<mailto:<email address removed>>

Re: control dragging
Date: 01.06.02 01:09 (Fri, 31 May 2002 17:09:13 -0700)
From: Seth Willits
On 5/31/02 9:07 AM, the NSA intercepted the following message from "Craig A.
Finseth" <<email address removed>>:

> Anyone have any idea of what I'm doing wrong here?

You're trying to set the canvas's left property based on 'X' which is the
position within the canvas the cursor is over. When you move the canvas, the
cursor's position of the canvas is different which cause it to bounce
around.

Say X begins at 100, startx = 50 and me.left = 0.

me.Left = startx + x
--> me.left = (50) + (100)

me.left now equals 150 and x = -50
Even if the cursor doesn't move the mouseDrag event is called so here it
goes again:

me.left = startx + x
--> me.left = (50) + (-50)

me.left now equals zero again. Now the event is called again:

me.Left = startx + x
--> me.left = (50) + (100)

me.left now equals 150 and x = -50

The loop just keeps going and going causing the canvas to bounce around.

> But ImageWell is derived from Canvas!

My guess is that in the ImageWell the mousedrag even is only called when the
mosue moves. I'M NOT SURE IF THIS IS CORRECT BUT JUST FROM WHAT YOU TOLD ME
AND WHAT I JUST EXPLAINED IT SEEMS AS IF THAT COULD BE TRUE. (sorry, I just
don't want anyone to think I'm giving false information as fact)

Here is the correct code:

MouseDown
startx = x
return true

MouseDrag:
me.left = self.mousex - startx


Seth Willits
---------------------------------------------------------------------------
President and Head Developer of Freak Software - http://www.freaksw.com
Q&A Columnist for REALbasic Developer Magazine - http://www.rbdeveloper.com

"Hi! I'm a .signature virus! Copy me into your ~/.signature to help me
spread!"
-- Vengence Virii
---------------------------------------------------------------------------



---
Subscribe to the digest:
<mailto:<email address removed>>
Unsubscribe:
<mailto:<email address removed>>

Re: control dragging
Date: 01.06.02 05:32 (Fri, 31 May 2002 23:32:15 -0500 (CDT))
From: Craig A. Finseth
> Anyone have any idea of what I'm doing wrong here?

You're trying to set the canvas's left property based on 'X' which is the
position within the canvas the cursor is over. When you move the canvas, the
cursor's position of the canvas is different which cause it to bounce
around.

Say X begins at 100, startx = 50 and me.left = 0.
...
The loop just keeps going and going causing the canvas to bounce around.

> But ImageWell is derived from Canvas!

My guess is that in the ImageWell the mousedrag even is only called when the
mosue moves. I'M NOT SURE IF THIS IS CORRECT BUT JUST FROM WHAT YOU TOLD ME
AND WHAT I JUST EXPLAINED IT SEEMS AS IF THAT COULD BE TRUE. (sorry, I just
don't want anyone to think I'm giving false information as fact)

Here is the correct code:

MouseDown
startx = x
return true

MouseDrag:
me.left = self.mousex - startx

Actually, this code didn't work either. But you did confirm what I
suspected -- that changing Left causes a new MouseDrag to fire (no good
reason that I can see, but I'm sure it makes sense to someone).

The working code is:

MouseDown
startx = Wnd.mousex ' Wnd is the contining window
return true

MouseDrag
me.left = Wnd.mousex

Obvious in hindsight.

Thanks

Craig

---
Subscribe to the digest:
<mailto:<email address removed>>
Unsubscribe:
<mailto:<email address removed>>

Re: control dragging
Date: 02.06.02 03:29 (Sat, 01 Jun 2002 19:29:04 -0700)
From: Seth Willits
On 5/31/02 9:07 AM, the NSA intercepted the following message from "Craig A.
Finseth" <<email address removed>>:

> Anyone have any idea of what I'm doing wrong here?

You're trying to set the canvas's left property based on 'X' which is the
position within the canvas the cursor is over. When you move the canvas, the
cursor's position of the canvas is different which cause it to bounce
around.

Say X begins at 100, startx = 50 and me.left = 0.

me.Left = startx + x
--> me.left = (50) + (100)

me.left now equals 150 and x = -50
Even if the cursor doesn't move the mouseDrag event is called so here it
goes again:

me.left = startx + x
--> me.left = (50) + (-50)

me.left now equals zero again. Now the event is called again:

me.Left = startx + x
--> me.left = (50) + (100)

me.left now equals 150 and x = -50

The loop just keeps going and going causing the canvas to bounce around.

> But ImageWell is derived from Canvas!

My guess is that in the ImageWell the mousedrag even is only called when the
mosue moves. I'M NOT SURE IF THIS IS CORRECT BUT JUST FROM WHAT YOU TOLD ME
AND WHAT I JUST EXPLAINED IT SEEMS AS IF THAT COULD BE TRUE. (sorry, I just
don't want anyone to think I'm giving false information as fact)

Here is the correct code:

MouseDown
startx = x
return true

MouseDrag:
me.left = self.mousex - startx


Seth Willits
---------------------------------------------------------------------------
President and Head Developer of Freak Software - http://www.freaksw.com
Q&A Columnist for REALbasic Developer Magazine - http://www.rbdeveloper.com

"Hi! I'm a .signature virus! Copy me into your ~/.signature to help me
spread!"
-- Vengence Virii
---------------------------------------------------------------------------



---
Subscribe to the digest:
<mailto:<email address removed>>
Unsubscribe:
<mailto:<email address removed>>