1. Click, drag, release

I have a window that I want people to be able to draw on with the mouse.  I
want to test on every firing of the onMouse event whether the mouse button
is down or up, so I can program my other routines accordingly.

Right now, the LeftDown and LeftUp events are only fired once per "drag".  I
do not want to have a variable that stores which the last event was, because
if the mouse button is released outside of the window it will continue to
drag until they click again.

Can somebody help with this problem?

~Tom

new topic     » topic index » view message » categorize

2. Re: Click, drag, release

Tom,

This following demo should do what you want.

Dan Moyer

-- CODE BEGINS:

--  code generated by Win32Lib IDE v0.10.6

include Win32Lib.ew
without warning

----------------------------------------------------------------------------
----
--  Window Window1
global constant Window1 = create( Window, "Show all mouse events", 0,
Default, Default, 400, 300, 0 )
global constant StatusBar2 = create( StatusBar, "StatusBar2", Window1, 0, 0,
0, 0, 0 )
global constant LText3 = create( LText, "", Window1, 28, 24, 152, 24, 0 )
global constant LText4 = create( LText, "", Window1, 28, 76, 152, 24, 0 )
---------------------------------------------------------
----------------------------------------------------------------------------
----
integer MouseState
MouseState = 0

procedure Window1_onMouse ( int event, int x, int y, int shift )


  if event = MOUSE_MOVE  then
     setText(LText3, sprint(x) & ",  " & sprint(y))
     if MouseState = 1 then
        setText(StatusBar2, "left down, " & sprint(x) & ",  " & sprint(y))
     elsif MouseState = 2 then
        setText(StatusBar2, "right down, " & sprint(x) & ",  " & sprint(y))
     else
         setText(StatusBar2, " ")
     end if
 end if

  if event = LEFT_DOWN  then
     setText(LText4, "LEFT_DOWN ")
     MouseState = 1
  elsif event = RIGHT_DOWN   then
     setText(LText4, "RIGHT_DOWN")
     MouseState = 2
  elsif event = LEFT_UP   then
     setText(LText4, "LEFT_UP")
     MouseState = 3
  elsif event = RIGHT_UP  then
     setText(LText4, "RIGHT_UP")
     MouseState = 4
  end if

  if  event = LEFT_DOUBLECLICK then
     setText(StatusBar2, "LEFT_DOUBLECLICK")
     MouseState = 5
  elsif event = RIGHT_DOUBLECLICK then
     setText(StatusBar2, "RIGHT_DOUBLECLICK")
     MouseState = 6
  end if

end procedure

onMouse[Window1] = routine_id("Window1_onMouse")


WinMain( Window1, Normal )

-- CODE ENDS

----- Original Message -----
From: <thomas at columbus.rr.com>
To: "EUforum" <EUforum at topica.com>
Sent: Saturday, June 08, 2002 1:57 PM
Subject: Click, drag, release


>
> I have a window that I want people to be able to draw on with the mouse.
I
> want to test on every firing of the onMouse event whether the mouse button
> is down or up, so I can program my other routines accordingly.
>
> Right now, the LeftDown and LeftUp events are only fired once per "drag".
I
> do not want to have a variable that stores which the last event was,
because
> if the mouse button is released outside of the window it will continue to
> drag until they click again.
>
> Can somebody help with this problem?
>
> ~Tom
>

new topic     » goto parent     » topic index » view message » categorize

3. Re: Click, drag, release

except there's a problem if you double-click and hold the button down
instead of releasing it, neither my example nor any variations I try can't
seem to handle that.  :(

Dan Moyer

----- Original Message -----
From: "Dan Moyer" <DANIELMOYER at prodigy.net>
To: "EUforum" <EUforum at topica.com>
Subject: Re: Click, drag, release


>
> Tom,
>
> This following demo should do what you want.
>
> Dan Moyer
>
<<SNIP>>
>
> ----- Original Message -----
> From: <thomas at columbus.rr.com>
> To: "EUforum" <EUforum at topica.com>
> Sent: Saturday, June 08, 2002 1:57 PM
> Subject: Click, drag, release
>
>
> >
> > I have a window that I want people to be able to draw on with the mouse.
> I
> > want to test on every firing of the onMouse event whether the mouse
button
> > is down or up, so I can program my other routines accordingly.
> >
> > Right now, the LeftDown and LeftUp events are only fired once per
"drag".
> I
> > do not want to have a variable that stores which the last event was,
> because
> > if the mouse button is released outside of the window it will continue
to
> > drag until they click again.
> >
> > Can somebody help with this problem?
> >
> > ~Tom
> >
>
>
>
>

new topic     » goto parent     » topic index » view message » categorize

4. Re: Click, drag, release

Tom,

I think *this* version will show you how to do everything you might want.

Dan Moyer

-- <CODE FOLLOWS>

--  code generated by Win32Lib IDE v0.10.6

include Win32Lib.ew
without warning

----------------------------------------------------------------------------
----
--  Window Window1
global constant Window1 = create( Window, "Show all mouse events", 0,
Default, Default, 400, 300, 0 )
global constant LText3 = create( LText, "", Window1, 28, 24, 152, 24, 0 )
global constant LText4 = create( LText, "", Window1, 28, 76, 200, 24, 0 )
global constant LText5 = create( LText, "", Window1, 28, 120, 200, 24, 0 )

---------------------------------------------------------
----------------------------------------------------------------------------
----
integer MouseState
MouseState = 0

procedure Window1_onMouse ( int event, int x, int y, int shift )


  if event = MOUSE_MOVE  then
     setText(LText3, sprint(x) & ",  " & sprint(y))
     if MouseState = 1  then
        setText(LText4, "left down, " & sprint(x) & ",  " & sprint(y))
     elsif MouseState = 2  then
        setText(LText4, "right down, " & sprint(x) & ",  " & sprint(y))
     elsif MouseState = 5  then  -- just in case hold button down after dbl
        setText(LText4, "left down, " & sprint(x) & ",  " & sprint(y))
     elsif MouseState = 6  then  -- just in case hold button down after dbl
        setText(LText4, "right down, " & sprint(x) & ",  " & sprint(y))
     else
         setText(LText4, "MOVING,no mouse button pressed")
         setText(LText5, " ")
     end if

  elsif event = LEFT_DOWN  then
     setText(LText4, "LEFT_DOWN ")
     MouseState = 1
  elsif event = RIGHT_DOWN   then
     setText(LText4, "RIGHT_DOWN")
     MouseState = 2
  elsif event = LEFT_UP   then
     setText(LText4, "LEFT_UP")
     MouseState = 3
  elsif event = RIGHT_UP  then
     setText(LText4, "RIGHT_UP")
     MouseState = 4

  elsif  event = LEFT_DOUBLECLICK then
     setText(LText5, "LEFT_DOUBLECLICK")
     MouseState = 5
  elsif event = RIGHT_DOUBLECLICK then
     setText(LText5, "RIGHT_DOUBLECLICK")
     MouseState = 6
  end if


end procedure
onMouse[Window1] = routine_id("Window1_onMouse")



WinMain( Window1, Normal )

-- <CODE ENDS>


----- Original Message -----
From: <thomas at columbus.rr.com>
To: "EUforum" <EUforum at topica.com>
Sent: Saturday, June 08, 2002 1:57 PM
Subject: Click, drag, release


>
> I have a window that I want people to be able to draw on with the mouse.
I
> want to test on every firing of the onMouse event whether the mouse button
> is down or up, so I can program my other routines accordingly.
>
> Right now, the LeftDown and LeftUp events are only fired once per "drag".
I
> do not want to have a variable that stores which the last event was,
because
> if the mouse button is released outside of the window it will continue to
> drag until they click again.
>
> Can somebody help with this problem?
>
> ~Tom
>
>
>
>

new topic     » goto parent     » topic index » view message » categorize

5. Re: Click, drag, release

Thanks VERY much for your replies, but they all contain the bug that I have
been working to get around.  If you click, drag outside the window, and lift
up, you can go back onto the form and it will still think that the mouse is
down.

After much searching through the win32lib help files (that I downloaded in
the Windows help format from the archives) I found the function captureMouse
that jami helped explain to me.  Using this, all mouse events, *even outside
the window* are sent to the form so that your basic script DOES in fact
work.  Here is the snippet of code that I plan on using.  If you notice
anything else that might go awry, don't be afraid to reply. ;)

-- CODE STARTS

-------------------------------------------------------------
procedure MainWindow_onMouse( atom event, atom x, atom y, atom shift )
  sequence mouse_pos

  mouse_pos = getMousePos()
  mouse_pos = ScreenToClient( MainWindow, mouse_pos[1], mouse_pos[2] )

  if event = LeftDown then
    captureMouse( MainWindow )
    dragging = 1
  elsif event = LeftUp then
    releaseMouse()
    dragging = 0
  end if

  setText( MainWindow, sprintf( "point position: %d, %d" , mouse_pos ) )
end procedure
onMouse[MainWindow] = routine_id( "MainWindow_onMouse" )

-- CODE ENDS, HAVE A GREAT DAY

----- Original Message -----
From: "Dan Moyer" <DANIELMOYER at prodigy.net>
To: "EUforum" <EUforum at topica.com>
Sent: Saturday, June 08, 2002 8:15 PM
Subject: Re: Click, drag, release


>
> Tom,
>
> I think *this* version will show you how to do everything you might want.
>
> Dan Moyer
>
> -- <CODE FOLLOWS>
>
> --  code generated by Win32Lib IDE v0.10.6
>
> include Win32Lib.ew
> without warning
>
> --------------------------------------------------------------------------
--
> ----
> --  Window Window1
> global constant Window1 = create( Window, "Show all mouse events", 0,
> Default, Default, 400, 300, 0 )
> global constant LText3 = create( LText, "", Window1, 28, 24, 152, 24, 0 )
> global constant LText4 = create( LText, "", Window1, 28, 76, 200, 24, 0 )
> global constant LText5 = create( LText, "", Window1, 28, 120, 200, 24, 0 )
>
> ---------------------------------------------------------
> --------------------------------------------------------------------------
--
> ----
> integer MouseState
> MouseState = 0
>
> procedure Window1_onMouse ( int event, int x, int y, int shift )
>
>
>   if event = MOUSE_MOVE  then
>      setText(LText3, sprint(x) & ",  " & sprint(y))
>      if MouseState = 1  then
>         setText(LText4, "left down, " & sprint(x) & ",  " & sprint(y))
>      elsif MouseState = 2  then
>         setText(LText4, "right down, " & sprint(x) & ",  " & sprint(y))
>      elsif MouseState = 5  then  -- just in case hold button down after
dbl
>         setText(LText4, "left down, " & sprint(x) & ",  " & sprint(y))
>      elsif MouseState = 6  then  -- just in case hold button down after
dbl
>         setText(LText4, "right down, " & sprint(x) & ",  " & sprint(y))
>      else
>          setText(LText4, "MOVING,no mouse button pressed")
>          setText(LText5, " ")
>      end if
>
>   elsif event = LEFT_DOWN  then
>      setText(LText4, "LEFT_DOWN ")
>      MouseState = 1
>   elsif event = RIGHT_DOWN   then
>      setText(LText4, "RIGHT_DOWN")
>      MouseState = 2
>   elsif event = LEFT_UP   then
>      setText(LText4, "LEFT_UP")
>      MouseState = 3
>   elsif event = RIGHT_UP  then
>      setText(LText4, "RIGHT_UP")
>      MouseState = 4
>
>   elsif  event = LEFT_DOUBLECLICK then
>      setText(LText5, "LEFT_DOUBLECLICK")
>      MouseState = 5
>   elsif event = RIGHT_DOUBLECLICK then
>      setText(LText5, "RIGHT_DOUBLECLICK")
>      MouseState = 6
>   end if
>
>
> end procedure
> onMouse[Window1] = routine_id("Window1_onMouse")
>
>
>
> WinMain( Window1, Normal )
>
> -- <CODE ENDS>

new topic     » goto parent     » topic index » view message » categorize

6. Re: Click, drag, release

Tom,

Oh, I see you're right!

I suspect you don't need the following, but I've taken your fix & put it in
my example, & it shows most everything that happens with the mouse, now
including releasing a drag outside the window, but it does have at least one
bug:  I've caught the event in which a user might double-click and for some
weird reason hold the button down after, but I can't get THAT to be
responded to correctly if they then release the button outside the main
window.  But that might not be important in your application.

Dan Moyer

-- CODE STARTS:

--  code generated by Win32Lib IDE v0.10.6

include Win32Lib.ew
without warning

----------------------------------------------------------------------------
----
--  Window Window1
global constant Window1 = create( Window, "Show all mouse events", 0,
Default, Default, 400, 300, 0 )
global constant LText3 = create( LText, "", Window1, 28, 24, 200, 24, 0 )
global constant LText4 = create( LText, "", Window1, 28, 76, 200, 24, 0 )
global constant LText5 = create( LText, "", Window1, 28, 120, 200, 24, 0 )
--constant aStatusBar = create(StatusBar, "", Window1, 0,0,0,0,0)

---------------------------------------------------------
----------------------------------------------------------------------------
----
integer MouseState
MouseState = 0

procedure Window1_onMouse ( int event, int x, int y, int shift )
integer dragging
sequence mouse_pos, wD

dragging = 0

wD = getWindowRect(Window1)  -- get app window dimensions in screen


mouse_pos = getMousePos()  -- get screen oriented mouse point

  if event = MOUSE_MOVE  then
     if mouse_pos[1] >= wD[1] and mouse_pos[1] <= wD[3] and
        mouse_pos[2] >= wD[2] and mouse_pos[2] <= wD[4] then
          setText(LText3, sprintf("point position in window: %d,%d", {x,y}))
     end if
     if MouseState = 1  then
        if mouse_pos[1] >= wD[1] and mouse_pos[1] <= wD[3] and
          mouse_pos[2] >= wD[2] and mouse_pos[2] <= wD[4] then
            setText(LText4, "left down, " & sprint(x) & ",  " & sprint(y))
        end if

     elsif MouseState = 2  then

     if mouse_pos[1] >= wD[1] and mouse_pos[1] <= wD[3] and
        mouse_pos[2] >= wD[2] and mouse_pos[2] <= wD[4] then
           setText(LText4, "right down, " & sprint(x) & ",  " & sprint(y))
         -- setText(LText3, sprintf("point position in window: %d,%d",
{x,y}))
     end if
     elsif MouseState = 5  then  -- just in case hold button down after dbl
        setText(LText4, "left down, " & sprint(x) & ",  " & sprint(y))
     elsif MouseState = 6  then  -- just in case hold button down after dbl
        setText(LText4, "right down, " & sprint(x) & ",  " & sprint(y))
     else
         setText(LText4, "MOVING,no mouse button pressed")
         setText(LText5, " ")
     end if

  elsif event = LEFT_DOWN  then
     setText(LText4, "LEFT_DOWN ")
     MouseState = 1
     captureMouse(Window1)
     dragging = 1
  elsif event = RIGHT_DOWN   then
     setText(LText4, "RIGHT_DOWN")
     MouseState = 2
     captureMouse(Window1)
     dragging = 1
  elsif event = LEFT_UP   then
     setText(LText4, "LEFT_UP")
     setText(LText5, "")
     MouseState = 3
     releaseMouse()
     dragging = 0
  elsif event = RIGHT_UP  then
     setText(LText4, "RIGHT_UP")
     setText(LText5, "")
     MouseState = 4
     releaseMouse()
     dragging = 0

  elsif  event = LEFT_DOUBLECLICK then
     setText(LText5, "LEFT_DOUBLECLICK")
     setText(LText4, "")
     MouseState = 5
  elsif event = RIGHT_DOUBLECLICK then
     setText(LText5, "RIGHT_DOUBLECLICK")
     setText(LText4, "")
     MouseState = 6
  end if


end procedure
onMouse[Window1] = routine_id("Window1_onMouse")



WinMain( Window1, Normal )

-- CODE ENDS



----- Original Message -----
From: <thomas at columbus.rr.com>
To: "EUforum" <EUforum at topica.com>
Sent: Sunday, June 09, 2002 9:55 AM
Subject: Re: Click, drag, release


>
> Thanks VERY much for your replies, but they all contain the bug that I
have
> been working to get around.  If you click, drag outside the window, and
lift
> up, you can go back onto the form and it will still think that the mouse
is
> down.
>
> After much searching through the win32lib help files (that I downloaded in
> the Windows help format from the archives) I found the function
captureMouse
> that jami helped explain to me.  Using this, all mouse events, *even
outside
> the window* are sent to the form so that your basic script DOES in fact
> work.  Here is the snippet of code that I plan on using.  If you notice
> anything else that might go awry, don't be afraid to reply. ;)
>
> -- CODE STARTS
>
> -------------------------------------------------------------
> procedure MainWindow_onMouse( atom event, atom x, atom y, atom shift )
>   sequence mouse_pos
>
>   mouse_pos = getMousePos()
>   mouse_pos = ScreenToClient( MainWindow, mouse_pos[1], mouse_pos[2] )
>
>   if event = LeftDown then
>     captureMouse( MainWindow )
>     dragging = 1
>   elsif event = LeftUp then
>     releaseMouse()
>     dragging = 0
>   end if
>
>   setText( MainWindow, sprintf( "point position: %d, %d" , mouse_pos ) )
> end procedure
> onMouse[MainWindow] = routine_id( "MainWindow_onMouse" )
>
> -- CODE ENDS, HAVE A GREAT DAY
>

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu