-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontrols.pde
164 lines (155 loc) · 3.87 KB
/
controls.pde
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
void mouseMoved() {
switch( moment ){
case 'o':
observe.mouseMoved();
break;
case 'c':
create.mouseMoved();
break;
}
}
void paint(){
if( mouseX > sx && mouseY > sy && mouseX < sx+1000 && mouseY < sy + 600 ){
if( mouseButton == LEFT ){
if( turn ){
B.set( floor((mouseX -sx -tx)/zoom), floor((mouseY -sy -ty)/zoom), states.get( brush_color.n ) );
}
else{
A.set( floor((mouseX -sx -tx)/zoom), floor((mouseY -sy -ty)/zoom), states.get( brush_color.n ) );
}
}
}
}
void mousePressed() {
switch( moment ){
case 'o':
observe.mousePressed();
paint();
break;
case 'c':
create.mousePressed();
break;
}
}
void mouseReleased() {
switch( moment ){
case 'o':
observe.mouseReleased();
paint();
break;
case 'c':
create.mouseReleased();
break;
}
}
void mouseDragged() {
switch( moment ){
case 'o':
observe.mouseDragged();
if( mouseX > sx && mouseY > sy && mouseX < sx+1000 && mouseY < sy + 600 ){
if( mouseButton == RIGHT ){
tx += (mouseX - pmouseX);
ty += (mouseY - pmouseY);
}
else if( mouseButton == LEFT && pmouseX > sx && pmouseY > sy && pmouseX < sx+1000 && pmouseY < sy + 600 ){
//if( turn ){
// B.set( floor((mouseX -sx -tx)/zoom), floor((mouseY -sy -ty)/zoom), states.get( brush_color.n ) );
//}
//else{
// A.set( floor((mouseX -sx -tx)/zoom), floor((mouseY -sy -ty)/zoom), states.get( brush_color.n ) );
//}
int[] ref;
if( play.b ){
if( turn ) ref = B.pixels;
else ref = A.pixels;
}
else{
if( paused_turn ) ref = A.pixels;
else ref = B.pixels;
}
int ix = floor((pmouseX -sx -tx)/zoom);
int iy = floor((pmouseY -sy -ty)/zoom);
int fx = floor((mouseX -sx -tx)/zoom);
int fy = floor((mouseY -sy -ty)/zoom);
int dx = fx-ix;
int dy = fy-iy;
if( abs( dx ) >= abs( dy ) ){
float a = dy / float(abs(dx));
int v = ( fx > ix )? 1 : -1;
for( int i = 0; i <= abs(dx); ++i ){
int x = ix + (i*v);
int y = iy + round( a * i );
ref[ (A.width * y) + x ] = states.get( brush_color.n );
}
}
else{
float a = dx / float(abs(dy));
int v = ( fy > iy )? 1 : -1;
for( int i = 0; i <= abs(dy); ++i ){
int y = iy + (i*v);
int x = ix + round( a * i );
ref[ (A.width * y) + x ] = states.get( brush_color.n );
}
}
if( paused_turn ){
A.updatePixels();
A.loadPixels();
}
else{
B.updatePixels();
B.loadPixels();
}
}
}
break;
case 'c':
create.mouseDragged();
break;
}
}
void mouseWheel(MouseEvent E) {
switch( moment ){
case 'o':
observe.mouseWheel( E );
float xrd = (mouseX-tx) / zoom;
float yrd = (mouseY-ty) / zoom;
zI -= E.getAmount();
zoom = pow( 1.1, zI );
if( zoom < 2 ){
zoom = 2.0;
zI = 7.27254089;
tx = 0;
ty = 0;
}
else{
tx = mouseX - xrd * zoom;
ty = mouseY - yrd * zoom;
}
break;
case 'c':
create.mouseWheel( E );
break;
}
}
void keyTyped() {
switch( moment ){
case 'o':
observe.keyTyped();
break;
case 'c':
create.keyTyped();
break;
}
}
void keyReleased() {
switch( moment ){
case 'o':
observe.keyReleased();
if( key == ' ' ) play.b = !play.b;
if( key == TAB ) observe.set[2].mouseReleased( true );
break;
case 'c':
create.keyReleased();
break;
}
}