-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathoption_button.js
More file actions
63 lines (51 loc) · 1.67 KB
/
option_button.js
File metadata and controls
63 lines (51 loc) · 1.67 KB
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
// Have a rectangle representing their position and a state to go to when clicked
// spec:
// rect : spec for a rectangle representing the button
// click_fun : what to do when clicked
// global_var : var that determines whether this option is enabled or not
var option_button = function(p, spec) {
// --- defaults ---
//spec.rect.width = spec.width || 200;
//spec.rect.height = spec.height || 60;
// obj to return
var obj = {};
// --- private variables ---
var but = button(p, spec);
var rect = rectangle(p, spec.rect);
// Left-edge x and top-edge y coordinates of 'checkbox' indicating whether
// option is enabled
var status_x = rect.get_left_x() + 28//50;
var status_y = rect.get_top_y() + 30//37;
var tick_size = 30;
var tick_yes_image = image_manager.get_image("check1.png");
var tick_no_image = image_manager.get_image("check0.png");
// --- public methods ---
obj.draw = function() {
//rect.draw();
but.draw();
p.imageMode(p.CENTER);
if (g[spec.global_var]) {
//p.fill(255, 255, 255);
//p.ellipse(status_x, status_y, 10, 10);
p.image(tick_yes_image, status_x, status_y, tick_size, tick_size);
}
else {
p.image(tick_no_image, status_x, status_y, tick_size, tick_size);
}
};
// Returns the state to go to if clicked, or
// null if not clicked
obj.click = function(x, y) {
//but.is_clicked();
if (rect.is_in(x, y)) {
spec.click_fun();
}
// Redraw in case anything changes
obj.draw();
};
obj.is_clicked = function() { return null; };
obj.mouse_moved = function(x, y) {
but.mouse_moved(x, y);
};
return obj;
};