delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/07/02/19:35:20

Message-Id: <199807022332.AAA15390@sable.ox.ac.uk>
Comments: Authenticated sender is <mert0407 AT sable DOT ox DOT ac DOT uk>
From: George Foot <george DOT foot AT merton DOT oxford DOT ac DOT uk>
To: djgpp AT delorie DOT com
Date: Fri, 3 Jul 1998 00:27:43 +0000
MIME-Version: 1.0
Subject: Re: allegro mouse problems
Reply-to: george DOT foot AT merton DOT oxford DOT ac DOT uk

On  2 Jul 98 at 4:43, Roger W. Huggins wrote:

> I am trying to get the mouse to work with allegro.  I get the mouse to
> display and move about the screen okay, but I can't seem to detect when a
> mouse button is pressed .  I would appreciate it if someone could tell me
> what is wrong with the following code:
> 
> show_mouse(NULL);
>     rectfill(screen,x,y,x1,y1,BLACK);
>     show_mouse(screen);
>   do
>     {
>      if(mouse_b & 1)
>         {
>          textout_centre(screen,font,"Left Button Pressed",10,10,YELLOW);

Side note: you should have hidden the mouse before the above line.

>          //left button pressed
>             show_mouse(NULL);
>             rectfill(screen,x,y,x1,y1,BLUE);
>             show_mouse(screen);
>         }
> }while(!readkey());

You're using the wrong function here -- I think you mean 
`keypressed'.  The `readkey' function reads a character from the 
buffer, or, if the buffer is empty, waits for it to stop being empty 
(i.e. waits for a key to be pressed).  It blocks, though, so your 
test on `mouse_b' is only made after keys are pressed.

In fact, though, you're looping until `readkey' returns a nonzero 
number -- but it always returns a nonzero number, so your while loop 
will terminate after the first pass.

Replace `readkey' with `keypressed' and move the `show_mouse(NULL);' 
line before the `textout_centre' line.

-- 
george DOT foot AT merton DOT oxford DOT ac DOT uk

- Raw text -


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