1 #include <util.h>
2
3 #include "Bucket.h"
4 #include "Cable.h"
5 #include "Game.h"
6 #include "Network.h"
7 #include "UI.h"
8
9 static Picture *picture;
10 static MCursor *cursor;
11 static int grabbed;
12
13 void
Bucket_load_pix()14 Bucket_load_pix() {
15 UI_load_picture("bucket", 1, &picture);
16 UI_load_cursor("bucket", CURSOR_OWN_MASK, &cursor);
17 }
18
19 int
Bucket_clicked(int x,int y)20 Bucket_clicked(int x, int y) {
21 return (x > 0 && x < UI_picture_width(picture) &&
22 y > 0 && y < UI_picture_height(picture));
23 }
24
25 void
Bucket_draw()26 Bucket_draw() {
27 if (!grabbed)
28 UI_draw(picture, 0, 0);
29 }
30
31 void
Bucket_grab(int x,int y)32 Bucket_grab(int x, int y) {
33 UNUSED(x);
34 UNUSED(y);
35
36 UI_set_cursor(cursor);
37 grabbed = 1;
38 }
39
40 void
Bucket_release(int x,int y)41 Bucket_release(int x, int y) {
42 int i;
43 for (i = 0; i < Network_num_cables(); i++) {
44 Cable *cable = Network_get_cable(i);
45 if (Cable_onspark(cable, x, y))
46 Cable_reset(cable);
47 }
48 grabbed = 0;
49 }
50