Mail Archives: djgpp/2001/03/08/03:15:56
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 -