delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/10/30/06:16:01

From: G DOT DegliEsposti AT ads DOT it
To: djgpp AT delorie DOT com
Message-ID: <C1256540.003C2FFF.00@vega.ads.it>
Date: Thu, 30 Oct 1997 12:15:56 +0100
Subject: Re: Mouse polling : Giving me a headache! HELP HELP HELP (Allegro
).
Mime-Version: 1.0




>for(;;)  // First forever loop
>{
>  if(MouseMove())  // Mouse has moved from it's previous position.  First.
>    {
>    if(mouse_b & 1)     // User has clicked left-button.  First.
>    {
[...]
>    for(;;)   // Second forever loop.  Do until mouse is pressed second
time.
>    {
>    if(MouseMove())     // Mouse has moved from it's previous position.
>        {
[...]
>         }
>      if(mouse_b & 1) return;     // Mouse pressed second time.  We're
done.
>      }
>   }
>}
>
>As you can see, it should work as expected, but it doesn't.  What's going
on?  I
You have to check the mouse button release, otherwise the function returns
at the first button pression.
This is because the program runs from the first check of mouse_b to
the second very quickly, before the user releases the mouse button (unless
he is
able to click the mouse in some nanoseconds :-)

You have then to poll, there is no way, unless you rewrite the program to
some sort of event driven program, but that's another story...

>don't want to resort to having the user draw a circle while holding a
mouse button
>down. (It works, but I don't want that.  I would however like to leave it
up to the
>user to choose which mode they like - mouse up or mouse down style).

I use this method (if I recall everything fine):

f = click_or_drag();
if (f == CLICK) {();f
  while(mouse_b == 0) {
     // draw circles & so on
  }
} else {
  while(mouse_b & 1 ) {
     // draw circles & so on
  }
}

click_or_drag()
{

while(mouse_b == 0)
     ;
x = mouse_x; y = mouse_y;
while(mouse_b != 0 && distance(mouse_x, mouse_y, x, y) < DRAG_TOLERANCE)
     ;

if mouse_b == 0)
     return CLICK
else
     return DRAG;
}

Hope this helps.

ciao
  Giacomo



- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019