www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2001/03/08/03:15:56

Date: Thu, 8 Mar 2001 10:46:27 +0530 (IST)
From: Mridul Muralidharan <ec97027 AT matrix DOT reccal DOT ernet DOT in>
To: aek AT digitalanime DOT com
cc: Djgpp mailing list <djgpp AT delorie DOT com>
Subject: Re: allegro mouse problem
In-Reply-To: <3aa686a1.4801516@news.dingoblue.net.au>
Message-ID: <Pine.LNX.4.04.10103081041160.31724-100000@matrix.reccal.ernet.in>
MIME-Version: 1.0
Reply-To: djgpp AT delorie DOT com
Errors-To: nobody AT delorie DOT com
X-Mailing-List: djgpp AT delorie DOT com
X-Unsubscribes-To: listserv AT delorie DOT com

On Wed, 7 Mar 2001 aek AT digitalanime DOT com wrote:
> hi, im having some problems with the code below
> its purpose is to draw circles using mouse clicks
> first it collects the starting (x1,y1) co-ordinates.. then the second
> time mouse b1 is pressed it gets (x2,y2) then calculates the radius,
> then draws the circle... but if i try reset the got_click flag all i
> get is 'mouse droppings' when i press mouse b1. 
> 
> i think it might be the kb interupt butting in when it shouldnt..
> i tried to use mouse_pos instead and didnt have any luck but im sure
> im doing something wrong when using mouse_pos.
try this one out - just a few modifications :)

----------------------cut here----------------------------------------

#include <allegro.h>
#include <math.h>

inline int calc_radius( int x1,int y1,int x2,int y2 ){
        return (int)sqrt((double)((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)));
}
int
main ()
{
 int x1,x2,y1,y2;
 int radius;

  allegro_init ();
  install_mouse ();
  install_timer ();
  install_keyboard ();
  set_gfx_mode (GFX_AUTODETECT, 800, 600, 0, 0);

  show_mouse (screen);
  while (!keypressed ())
    {
      if (mouse_b & 1)
        {
              x1 = mouse_x;
              y1 = mouse_y;
  	      /* Wait for user to release mouse button */
	      /* If u want to continously show the circle as it is 
                 drawn - just add some code in the loop below to remove
		 the prev
                 circle and then redraw a new circle */
	      while (mouse_b&1)
        	     ;
              x2 = mouse_x;
              y2 = mouse_y;
              radius = calc_radius (x1, y1, x2, y2);
              scare_mouse ();
              circle (screen, x1, y1, radius, 255);
              unscare_mouse ();
        }
      vsync ();
    }
}
END_OF_MAIN();

----------------------cut here------------------------------------

hope this helps u .

Mridul Muralidharan
S8 Electronics and Communication
Regional Engineering College
Calicut
India

------------------------------------------------------------------------------

If the code and the comments disagree, then both are probably wrong.
                -- Norm Schryer

All generalizations are false, including this one.
                -- Mark Twain

/earth is 98% full ... please delete anyone you can.

        - fortune



- Raw text -


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