1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
|
#include <allegro.h>
#include <vector>
#include <math.h>
BITMAP* buffer;
int cursor_x = 20;
int cursor_y = 20;
int radius = 30;
double distance(double x , double y){
double Z = sqrt((x*x) + (y*y));
return Z;
}
struct Circle{
int x, y, radius;
};
std::vector<Circle> scene;
int selected = -1;
Circle c = {300, 300, radius};
int getMouseInfo(){
if(mouse_b & 1){
cursor_x = mouse_x;
cursor_y = mouse_y;
Circle c;
c.x = cursor_x;
c.y = cursor_y;
c.radius = radius;
scene.push_back(c);
return 1;
}
if (mouse_b & 2){
cursor_x = mouse_x;
cursor_y = mouse_x;
return 1;
}
return 0;
}
void updateScreen(){
show_mouse(NULL);
int g;
selected = -1;
for(int i = 0; i < scene.size(); i++){
if (distance(cursor_x-scene[i].x, cursor_y-scene[i].y) <= scene[i].radius){
g = selected;
if( g != selected){
circlefill ( buffer, cursor_x, cursor_y, radius, makecol( 0, 0, 255));
}
else if(g == selected){
rect(buffer, scene[i].x - scene[i].radius - 10, scene[i].y - scene[i].radius - 10,
scene[i].x + scene[i].radius + 10, scene[i].y + scene[i].radius + 10, makecol(0,0,255));
}
}
draw_sprite( screen, buffer, 0, 0);
}
}
int main(){
allegro_init();
install_mouse();
install_keyboard();
set_color_depth(16);
set_gfx_mode( GFX_AUTODETECT, 640, 480, 0, 0);
buffer = create_bitmap( 640, 480);
show_mouse(screen);
while( !key[KEY_ESC])
{
int switcher=1;
while(getMouseInfo())
{
updateScreen();
if(getMouseInfo()==0) switcher=0;
}
if(switcher==0) show_mouse(screen);
}
return 0;
}
END_OF_MAIN();
|