forked from elastomania/across
-
Notifications
You must be signed in to change notification settings - Fork 0
/
EDITTOOL.CPP
557 lines (517 loc) · 14.2 KB
/
EDITTOOL.CPP
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
#include "all.h"
void alaphelp( void ) {
switch( Tool ) {
case T_MOVE: toolhelp( "Move the cursor near a vertex or an object center you want to move, and click left button." ); break;
case T_ZOOMIN: toolhelp( "Click the left button to place the first corner of zoom window." ); break;
case T_CREATE_VERT: toolhelp( "If you click left button near a vertex you will add to a polygon, else create a new polygon." ); break;
case T_DELETE_VERT: toolhelp( "Click the left button near the vertex you want to delete." ); break;
case T_DELETE_POLY: toolhelp( "Click the left button near any vertex of the polygon you want to delete." ); break;
case T_CREATE_FOOD: toolhelp( "Click the left button to place a new Food object." ); break;
case T_CREATE_KILLER: toolhelp( "Click the left button to place a new Killer object." ); break;
case T_DELETE_KEREK: toolhelp( "Click the left button near the center of the object you want to delete." ); break;
default: toolhelp( "Ehhez a tool-hoz meg nincs alaphelp!" );
}
}
// MOVE MOVE MOVE MOVE MOVE MOVE MOVE MOVE MOVE MOVE MOVE MOVE
// MOVE MOVE MOVE MOVE MOVE MOVE MOVE MOVE MOVE MOVE MOVE MOVE
// MOVE MOVE MOVE MOVE MOVE MOVE MOVE MOVE MOVE MOVE MOVE MOVE
// MOVE MOVE MOVE MOVE MOVE MOVE MOVE MOVE MOVE MOVE MOVE MOVE
static double Moveorigx = 0, Moveorigy = 0;
void t_move_nyomva( int mx, int my ) {
if( Pgy || Pker ) {
// Most fogjuk elengedni pontot:
if( Pgy ) {
if( Pker )
hiba( "iuofiuceyhbuc" );
Pgy->ponttomb[K] = konv( mx, my );
Pgy = NULL;
}
else {
Pker->r = konv( mx, my );
Pker = NULL;
}
Valtozott = 1;
alaphelp();
invalidate();
}
else {
// Most probalunk megfogni egy pontot:
double x = konvx_i2d( mx );
double y = konvy_i2d( my );
double tavpont, tavkerek;
Pgy = Ptop->legkozpont( x, y, &K, &tavpont );
Pker = Ptop->legkozkerek( x, y, &tavkerek );
if( !Pgy && !Pker )
return;
if( Pgy && Pker ) {
if( tavpont < tavkerek )
Pker = NULL;
else
Pgy = NULL;
}
// Talaltunk egy pontot:
if( Pgy ) {
toolhelp( "Move the vertex and press the left button to place it. Press ESC or right button to cancel." );
Moveorigx = Pgy->ponttomb[K].x;
Moveorigy = Pgy->ponttomb[K].y;
mx = konvx_d2i( Moveorigx );
my = konvy_d2i( Moveorigy );
}
else {
toolhelp( "Move the object and press the left button to place it. Press ESC or right button to cancel." );
Moveorigx = Pker->r.x;
Moveorigy = Pker->r.y;
mx = konvx_d2i( Moveorigx );
my = konvy_d2i( Moveorigy );
}
setmou( mx, my );
push();
Moux = mx;
Mouy = my;
pop();
}
}
void t_move_esc( void ) {
if( Pgy ) {
Pgy->ponttomb[K].x = Moveorigx;
Pgy->ponttomb[K].y = Moveorigy;
Pgy = NULL;
invalidate();
}
if( Pker ) {
Pker->r.x = Moveorigx;
Pker->r.y = Moveorigy;
Pker = NULL;
invalidate();
}
}
void t_move_mmove( int mx, int my ) {
if( !Pgy && !Pker )
hiba( "t_move_mmove-ban !Pgy && !Pker!" );
if( Pgy && Pker )
hiba( "ioggiugghiigoijgoijer" );
push();
// Letoroljuk oket:
if( Pgy ) {
Pgy->kirajz( K, Fel, 0 );
Pgy->kirajz( K, !Fel, 0 );
// Uj koord:
double dx = konvx_i2d( mx );
double dy = konvy_i2d( my );
Pgy->ujkoord( K, dx, dy );
// Visszarajzoljuk oket:
Pgy->kirajz( K, Fel, 0 );
Pgy->kirajz( K, !Fel, 0 );
}
else {
Pker->kirajzol();
double dx = konvx_i2d( mx );
double dy = konvy_i2d( my );
Pker->r.x = dx;
Pker->r.y = dy;
Pker->kirajzol();
}
Moux = mx;
Mouy = my;
pop();
}
// CREATE_VERTEX CREATE_VERTEX CREATE_VERTEX CREATE_VERTEX
// CREATE_VERTEX CREATE_VERTEX CREATE_VERTEX CREATE_VERTEX
// CREATE_VERTEX CREATE_VERTEX CREATE_VERTEX CREATE_VERTEX
// CREATE_VERTEX CREATE_VERTEX CREATE_VERTEX CREATE_VERTEX
int Egypont = 0;
static int Epontx = 0, Eponty = 0;
static int Kpontx = 0, Kponty = 0;
// Bal gomb nyomva:
void t_create_vert_nyomva( int mx, int my ) {
Valtozott = 1;
if( !Pgy && !Egypont ) {
// Most probalunk megfogni egy pontot:
double x = konvx_i2d( mx );
double y = konvy_i2d( my );
Pgy = Ptop->legkozpont( x, y, &K );
if( !Pgy ) {
// Egy uj poligon elso pontjat rakjuk le:
// Eloszor megnezzuk, hogy van-e meg hely uj poligonnak:
int gyuruszam = 0;
for( int i = 0; i < MAXGYURU; i++ )
if( Ptop->ptomb[i] )
gyuruszam++;
#ifdef SARVARI
if( gyuruszam >= Maxgyuru_sarvari ) {
dialog( "You cannot create a new polygon",
"because you have already reached the maximum number of polygons!",
"In the shareware version this number is 3." );
return;
}
#else
if( gyuruszam >= MAXGYURU ) {
dialog( "You cannot create a new polygon",
"because you have already reached the maximum number of polygons (300)!" );
return;
}
#endif
toolhelp( "Click the left button to place the second point. ESC or right button cancels." );
Egypont = 1;
Epontx = Kpontx = mx;
Eponty = Kponty = my;
return;
}
else {
// Talaltunk egy mar meglevo poligonon egy pontot:
toolhelp( "Click the left button to place point. SPACE and ENTER swaps. ESC or right button cancels." );
push();
Moux = konvx_d2i( Pgy->ponttomb[K].x );
Mouy = konvy_d2i( Pgy->ponttomb[K].y );
pop();
}
}
if( Pgy ) {
// Most fogunk letenni uj pontot:
#ifdef SARVARI
// Azert +1, mivel mikor elengedi polygont, letorli utolso pontot:
if( Pgy->getpontszam() >= Maxpont_sarvari+1 ) {
dialog( "You cannot create a new vertex, because you have",
"already reached the maximum number of vertices in this polygon!",
"In the shareware version this number is 10." );
return;
}
#else
if( Pgy->getpontszam() >= MAXPONT ) {
dialog( "You cannot create a new vertex, because you have",
"already reached the maximum number of vertices in this polygon (1000)!" );
return;
}
#endif
toolhelp( "Click the left button to place point. SPACE and ENTER swaps. ESC or right button cancels." );
Pgy->beszur( K );
invalidate();
if( Fel )
K++;
}
else {
// Eddig egy pontja volt meg poligonnak, most mar valodi poligon-t
// csinalunk belole:
toolhelp( "Click the left button to place point. SPACE and ENTER swaps. ESC or right button cancels." );
if( !Egypont )
hiba( "!Egypont, pedig annak kene lennie (ffdsgiu)!" );
for( int i = 0; i < MAXGYURU; i++ ) {
if( !Ptop->ptomb[i] ) {
Pgy = Ptop->ptomb[i] = new gyuru;
Pgy->pontszam = 3;
Pgy->ponttomb[0] = konv( Epontx, Eponty );
Pgy->ponttomb[1] = konv( mx, my );
Pgy->ponttomb[2] = konv( mx, my );
K = 2;
Fel = 1;
Egypont = 0;
invalidate();
return;
}
};
hiba( "Tul sok gyuru (iycriyfd)!" );
}
}
// Jobb gomb nyomva:
// Ha nem fogtunk pontot, akkor uj poligonnak veszi fel elso pontjat,
// Ha fogtuk pontot, akkor torli es elengedi:
void t_create_vert_esc( void ) {
if( !Pgy && !Egypont )
return; // Nincsen semmi dolgunk
alaphelp();
if( Pgy ) {
// Pgy igaz, tehat egy pont meg van fogva, amit torlunk:
if( Pgy->getpontszam() <= 3 ) {
// Egesz poligont toroljuk:
// Eloszor egy kis ellenorzes:
int gyuruszam = 0;
for( int i = 0; i < MAXGYURU; i++ ) {
if( Ptop->ptomb[i] )
gyuruszam++;
}
if( gyuruszam <= 1 )
hiba( "t_create_vert_nyomva_esc-ban gyuruszam <= 1 (7pq4)!" );
int talalt = 0;
for( i = 0; i < MAXGYURU; i++ ) {
if( Ptop->ptomb[i] == Pgy ) {
// Megtalaltuk:
talalt = 1;
delete Pgy;
Pgy = NULL;
Ptop->ptomb[i] = NULL;
K = 0;
invalidate();
break;
}
}
if( !talalt )
hiba( "Gyuru torlesekor !talalt!" );
}
else {
// Csak a pontot toroljuk:
Pgy->torol( K );
Pgy = NULL;
K = 0;
invalidate();
}
}
else {
if( !Egypont )
hiba( "!Egypont (jygfeuye)!" );
Egypont = 0;
invalidate();
}
}
void t_create_vert_enter( void ) {
Fel = !Fel;
if( Pgy && !Egypont )
invalidate();
}
void t_create_vert_space( void ) {
if( !Pgy || Egypont )
return;
int kkov = K;
if( Fel ) {
// Lejjebb maszunk egy pontot:
kkov--;
if( kkov < 0 )
kkov = Pgy->pontszam-1;
}
else {
// Feljebb maszunk egy pontot:
kkov++;
if( kkov >= Pgy->pontszam )
kkov = 0;
}
Pgy->ponttomb[K] = Pgy->ponttomb[kkov];
K = kkov;
Moux = konvx( Pgy->ponttomb[K] );
Mouy = konvy( Pgy->ponttomb[K] );
setmou( Moux, Mouy );
Fel = !Fel;
invalidate();
}
void t_create_vert_mmove( int mx, int my ) {
if( !Pgy && !Egypont ) {
// Teljesen normalis kurzor mozgatas:
hiba( "Ezt most edituj.cpp-nek kellene csinalnia!" );
}
push();
if( Pgy ) {
// Letoroljuk oket:
Pgy->kirajz( K, Fel, 1 ); // szaggatott
Pgy->kirajz( K, !Fel, 0 );
// Uj koord:
double dx = konvx_i2d( mx );
double dy = konvy_i2d( my );
Pgy->ujkoord( K, dx, dy );
// Visszarajzoljuk oket:
Pgy->kirajz( K, Fel, 1 ); // szaggatott
Pgy->kirajz( K, !Fel, 0 );
Moux = mx;
Mouy = my;
}
else {
if( !Egypont )
hiba( "!Egypont (yifeye)" );
vonalrajz( konv( Epontx, Eponty ), konv( Kpontx, Kponty ), 0 );
Moux = Kpontx = mx;
Mouy = Kponty = my;
vonalrajz( konv( Epontx, Eponty ), konv( Kpontx, Kponty ), 0 );
}
pop();
}
// DELETE DELETE DELETE DELETE DELETE DELETE DELETE DELETE
// DELETE DELETE DELETE DELETE DELETE DELETE DELETE DELETE
// DELETE DELETE DELETE DELETE DELETE DELETE DELETE DELETE
// DELETE DELETE DELETE DELETE DELETE DELETE DELETE DELETE
void t_delete_vert_nyomva( int mx, int my ) {
if( Pgy )
hiba( "yffwiye" );
// Most probalunk megfogni egy pontot:
double x = konvx_i2d( mx );
double y = konvy_i2d( my );
int k = 0;
gyuru* pgy = Ptop->legkozpont( x, y, &k );
if( !pgy )
return;
// Talaltunk egy pontot, amit le kene torolni:
if( pgy->pontszam < 3 )
hiba( "yigfdsyhifeiu" );
if( pgy->pontszam == 3 ) {
//dialog( "You cannot delete this polygon, because every" );
dialog( "You cannot delete this vertex, because every polygon must",
"have at least three vertices! If you want to delete the",
"whole polygon, please select the DEL POLYGON tool!" );
return;
}
pgy->torol( k );
Valtozott = 1;
invalidate();
}
void t_delete_poly_nyomva( int mx, int my ) {
if( Pgy )
hiba( "oiutrgiuot" );
// Most probalunk megfogni egy pontot:
double x = konvx_i2d( mx );
double y = konvy_i2d( my );
int k = 0;
gyuru* pgy = Ptop->legkozpont( x, y, &k );
if( !pgy )
return;
// Talaltunk egy poligont, amit le kene torolni:
int szam = 0;
for( int i = 0; i < MAXGYURU; i++ )
if( Ptop->ptomb[i] )
szam++;
if( szam == 0 )
hiba( "oufeifwe" );
if( szam == 1 ) {
dialog( "This is the only polygon, so you cannot delete it." );
return;
}
for( i = 0; i < MAXGYURU; i++ ) {
if( Ptop->ptomb[i] == pgy ) {
delete Ptop->ptomb[i];
Ptop->ptomb[i] = NULL;
Valtozott = 1;
invalidate();
return;
}
}
hiba( "fdsiyfdfei" );
}
// CREATE_KEREK CREATE_KEREK CREATE_KEREK CREATE_KEREK CREATE_KEREK
// CREATE_KEREK CREATE_KEREK CREATE_KEREK CREATE_KEREK CREATE_KEREK
// CREATE_KEREK CREATE_KEREK CREATE_KEREK CREATE_KEREK CREATE_KEREK
// CREATE_KEREK CREATE_KEREK CREATE_KEREK CREATE_KEREK CREATE_KEREK
// Food es killer is egyben:
void t_create_kerek_nyomva( int mx, int my, int food ) {
// Megszamoljuk eddigi objektumokat:
int objszam = 0;
for( int i = 0; i < MAXKEREK; i++ )
if( Ptop->kerektomb[i] )
objszam++;
#ifdef SARVARI
if( objszam >= Maxkerek_sarvari ) {
dialog( "You cannot create a new object",
"because you have already reached the maximum number of objects!",
// exit es start objectet nem szamolom bele:
"In the shareware version this number is 6." );
return;
}
#else
if( objszam >= MAXKEREK ) {
dialog( "You have already reached the maximum number of objects (50)!" );
return;
}
#endif
for( i = 0; i < MAXKEREK; i++ ) {
if( !Ptop->kerektomb[i] ) {
double x = konvx_i2d( mx );
double y = konvy_i2d( my );
int tipus = T_KAJA;
if( !food )
tipus = T_HALALOS;
Ptop->kerektomb[i] = new kerek( x, y, tipus );
invalidate();
Valtozott = 1;
return;
}
}
hiba( "yer8yryfryfr!" );
}
// DELETE_KEREK DELETE_KEREK DELETE_KEREK DELETE_KEREK DELETE_KEREK
// DELETE_KEREK DELETE_KEREK DELETE_KEREK DELETE_KEREK DELETE_KEREK
// DELETE_KEREK DELETE_KEREK DELETE_KEREK DELETE_KEREK DELETE_KEREK
// DELETE_KEREK DELETE_KEREK DELETE_KEREK DELETE_KEREK DELETE_KEREK
void t_delete_kerek_nyomva( int mx, int my ) {
double x = konvx_i2d( mx );
double y = konvy_i2d( my );
kerek* pker = Ptop->legkozkerek( x, y );
if( !pker )
return;
for( int i = 0; i < MAXKEREK; i++ ) {
if( Ptop->kerektomb[i] == pker ) {
if( pker->tipus == T_CEL ) { // T_KEZDO
dialog( "You cannot delete the Exit object!" );
return;
}
if( pker->tipus == T_KEZDO ) {
dialog( "You cannot delete the Start object!" );
return;
}
delete pker;
Ptop->kerektomb[i] = NULL;
Valtozott = 1;
invalidate();
return;
}
}
hiba( "iufewifewiyfweiyhfewiyh" );
}
// ZOOM ZOOM ZOOM ZOOM ZOOM ZOOM ZOOM ZOOM ZOOM ZOOM ZOOM ZOOM
// ZOOM ZOOM ZOOM ZOOM ZOOM ZOOM ZOOM ZOOM ZOOM ZOOM ZOOM ZOOM
// ZOOM ZOOM ZOOM ZOOM ZOOM ZOOM ZOOM ZOOM ZOOM ZOOM ZOOM ZOOM
// ZOOM ZOOM ZOOM ZOOM ZOOM ZOOM ZOOM ZOOM ZOOM ZOOM ZOOM ZOOM
int Zoomfogva = 0; // Ha ez igaz, akkor nem szabad gombokat nyomkodni
static int Zoomx1 = 0, Zoomy1 = 0;
static int Zoomx2 = 0, Zoomy2 = 0;
void t_zoomin_nyomva( int x, int y ) {
if( Zoomfogva ) {
// Megvan masodik pont is:
alaphelp();
zoomin( Zoomx1, Zoomy1, x, y );
Zoomfogva = 0;
invalidate();
}
else {
// Most tesszuk le elso pontot:
toolhelp( "Click left button to place the second corner of zoom window. ESC or right button cancels." );
Zoomfogva = 1;
Zoomx1 = Zoomx2 = x;
Zoomy1 = Zoomy2 = y;
}
}
void t_zoomin_esc( void ) {
if( Zoomfogva ) {
alaphelp();
Zoomfogva = 0;
invalidate();
}
}
static void zoompont( int x, int y ) {
unsigned char szin = Editbuffer->gpixel( x, y );
szin += 128;
Editbuffer->ppixel( x, y, szin );
Pscr8->ppixel( x, y, szin );
}
static void kikeret( int x1, int y1, int x2, int y2 ) {
if( x2 < x1 ) { int tmp = x1; x1 = x2; x2 = tmp; }
if( y2 < y1 ) { int tmp = y1; y1 = y2; y2 = tmp; }
for( int x = x1; x <= x2; x++ ) {
zoompont( x, y1 );
zoompont( x, y2 );
}
for( int y = y1; y <= y2; y++ ) {
zoompont( x1, y );
zoompont( x2, y );
}
}
void t_zoomin_mmove( int x, int y ) {
push();
if( Zoomfogva ) {
kikeret( Zoomx1, Zoomy1, Zoomx2, Zoomy2 );
Zoomx2 = x;
Zoomy2 = y;
Moux = x;
Mouy = y;
kikeret( Zoomx1, Zoomy1, Zoomx2, Zoomy2 );
}
else {
// Teljesen normalis kurzor mozgatas:
Moux = x;
Mouy = y;
}
pop();
}