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
|
char *str = "mouse click 2";
char *str3= "redrawing...";
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;
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) {
textprintf(buffer, font, 0, 40, makecol(255, 255, 255), "%s", str);
cursor_x = mouse_x;
cursor_y = mouse_y;
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) {
selected = i;
}
}
textprintf(buffer, font, 0, 10, makecol(255, 255,255), "selected = %i", selected);
return 1;
}
return 0;
}
void updateScreen() {
textprintf(buffer, font, 0, 50, makecol(255, 255, 255), "%s", str3);
show_mouse(NULL);
for (int i = 0; i < scene.size(); i++) {
circlefill ( buffer, scene[i].x, scene[i].y, scene[i].radius,
makecol( 0, 0, 255));
if (i == selected) {
textprintf(buffer, font, 0, 20, makecol(255, 255,255), "selected = %i", 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);
}
}
|