1 /***************************************************************************
2 control.cpp - description
3 -------------------
4 begin : Tue June 11 2002
5 copyright : (C) 2002 by Rick McDaniel
6 email : rickeym@swbell.net
7 $Id: control.cpp,v 1.3 2003/04/20 19:30:29 anoncvs_pygsl Exp $
8 ***************************************************************************/
9
10 /***************************************************************************
11 * *
12 * This program is free software; you can redistribute it and/or modify *
13 * it under the terms of the GNU General Public License as published by *
14 * the Free Software Foundation; either version 2 of the License. *
15 * . *
16 * *
17 ***************************************************************************/
18 #include <string>
19 #include "SDL/SDL.h"
20 #include "SDL/SDL_image.h"
21 #include "SDL/SDL_thread.h"
22 #include "SDL/SDL_gfxPrimitives.h" //rdm 9/11
23 #include "dfont.h"
24 #include "submarine.h"
25 #include "files.h"
26
27 #include "control.h"
28 #include "dstack.h"
29 #include <cmath>
30 #include <cstdlib>
31
32 #include <iostream>
33 using namespace std;
34
35 // Use these for the display
36 DStack HeadingStack, SpeedStack, DepthStack;
37
38 // Used to remember last ordered heading, to clear display.
39 float old_heading;
40
41
Control(Submarine * temp)42 Control::Control(Submarine *temp): Subs(temp)
43 {
44 // Default Values
45 BEMER = false;
46 BSTD = false;
47 B23 = false;
48 B13 = false;
49 ASTOP = false;
50 A13 = true;
51 A23 = false;
52 ASTD = false;
53 AFULL = false;
54 AFLK = false;
55 depthup = false;
56 depthdown = false;
57 }
58
~Control()59 Control::~Control(){
60 }
61
InitGraphics(SDL_Surface * temp,SDL_Surface * tempcontrolscreen)62 void Control::InitGraphics(SDL_Surface *temp, SDL_Surface *tempcontrolscreen)
63 {
64 screen=temp;
65 controlscreen=tempcontrolscreen;
66
67 temp = SDL_CreateRGBSurface(SDL_SWSURFACE, 420, 490, 16,
68 screen->format->Rmask,
69 screen->format->Gmask,
70 screen->format->Bmask,
71 screen->format->Amask);
72 tempscreen=SDL_DisplayFormat(temp);
73 SDL_FreeSurface(temp);
74
75 LoadWidgets();
76 DisplayWidgets();
77
78 // orange = SDL_MapRGB(screen->format, 238, 118, 0); //rdm 9/11 not needed
79 // green = SDL_MapRGB(screen->format, 0, 128, 0);
80 // black = SDL_MapRGB(screen->format, 0, 0, 0);
81
82 }
83
LoadWidgets()84 void Control::LoadWidgets(){
85 SDL_Surface *temp;
86
87 temp = Load_Image("images/STOPoff.png");
88 if(temp != NULL) STOPoff = SDL_DisplayFormat(temp);
89 if ( STOPoff == NULL ) {
90 cerr<<"Function LoadWidgets()" << endl
91 << SDL_GetError() << endl;
92 SDL_Quit();
93 exit(0);
94 }
95 SDL_FreeSurface(temp);
96
97 temp = Load_Image("images/STOPon.png");
98 if(temp != NULL) STOPon = SDL_DisplayFormat(temp);
99 if ( STOPon == NULL ) {
100 cerr<<"Function LoadWidgets()" << endl
101 << SDL_GetError() << endl;
102 SDL_Quit();
103 exit(0);
104 }
105 SDL_FreeSurface(temp);
106
107 temp = Load_Image("images/A13off.png");
108 if(temp != NULL) A13off = SDL_DisplayFormat(temp);
109 if ( A13off == NULL ) {
110 cerr<<"Function LoadWidgets()" << endl
111 << SDL_GetError() << endl;
112 SDL_Quit();
113 exit(0);
114 }
115 SDL_FreeSurface(temp);
116
117 temp = Load_Image("images/A13on.png");
118 if(temp != NULL) A13on = SDL_DisplayFormat(temp);
119 if ( A13on == NULL ) {
120 cerr<<"Function LoadWidgets()" << endl
121 << SDL_GetError() << endl;
122 SDL_Quit();
123 exit(0);
124 }
125 SDL_FreeSurface(temp);
126
127 temp = Load_Image("images/A23off.png");
128 if(temp != NULL) A23off = SDL_DisplayFormat(temp);
129 if ( A23off == NULL ) {
130 cerr<<"Function LoadWidgets()" << endl
131 << SDL_GetError() << endl;
132 SDL_Quit();
133 exit(0);
134 }
135 SDL_FreeSurface(temp);
136
137 temp = Load_Image("images/A23on.png");
138 if(temp != NULL) A23on = SDL_DisplayFormat(temp);
139 if ( A23on == NULL ) {
140 cerr<<"Function LoadWidgets()" << endl
141 << SDL_GetError() << endl;
142 SDL_Quit();
143 exit(0);
144 }
145 SDL_FreeSurface(temp);
146
147 temp = Load_Image("images/ASTDoff.png");
148 if(temp != NULL) ASTDoff = SDL_DisplayFormat(temp);
149 if ( ASTDoff == NULL ) {
150 cerr<<"Function LoadWidgets()" << endl
151 << SDL_GetError() << endl;
152 SDL_Quit();
153 exit(0);
154 }
155 SDL_FreeSurface(temp);
156
157 temp = Load_Image("images/ASTDon.png");
158 if(temp != NULL) ASTDon = SDL_DisplayFormat(temp);
159 if ( ASTDon == NULL ) {
160 cerr<<"Function LoadWidgets()" << endl
161 << SDL_GetError() << endl;
162 SDL_Quit();
163 exit(0);
164 }
165 SDL_FreeSurface(temp);
166
167 temp = Load_Image("images/AFULLoff.png");
168 if(temp != NULL) AFULLoff = SDL_DisplayFormat(temp);
169 if ( AFULLoff == NULL ) {
170 cerr<<"Function LoadWidgets()" << endl
171 << SDL_GetError() << endl;
172 SDL_Quit();
173 exit(0);
174 }
175 SDL_FreeSurface(temp);
176
177 temp = Load_Image("images/AFULLon.png");
178 if(temp != NULL) AFULLon = SDL_DisplayFormat(temp);
179 if ( AFULLon == NULL ) {
180 cerr<<"Function LoadWidgets()" << endl
181 << SDL_GetError() << endl;
182 SDL_Quit();
183 exit(0);
184 }
185 SDL_FreeSurface(temp);
186
187 temp = Load_Image("images/AFLKoff.png");
188 if(temp != NULL) AFLKoff = SDL_DisplayFormat(temp);
189 if ( AFLKoff == NULL ) {
190 cerr<<"Function LoadWidgets()" << endl
191 << SDL_GetError() << endl;
192 SDL_Quit();
193 exit(0);
194 }
195 SDL_FreeSurface(temp);
196
197 temp = Load_Image("images/AFLKon.png");
198 if(temp != NULL) AFLKon = SDL_DisplayFormat(temp);
199 if ( AFLKon == NULL ) {
200 cerr<<"Function LoadWidgets()" << endl
201 << SDL_GetError() << endl;
202 SDL_Quit();
203 exit(0);
204 }
205 SDL_FreeSurface(temp);
206
207 temp = Load_Image("images/depthupoff.png");
208 if(temp != NULL) depthupoff = SDL_DisplayFormat(temp);
209 if ( depthupoff == NULL ) {
210 cerr<<"Function LoadWidgets()" << endl
211 << SDL_GetError() << endl;
212 SDL_Quit();
213 exit(0);
214 }
215 SDL_FreeSurface(temp);
216
217 temp = Load_Image("images/depthupon.png");
218 if(temp != NULL) depthupon = SDL_DisplayFormat(temp);
219 if ( depthupon == NULL ) {
220 cerr<<"Function LoadWidgets()" << endl
221 << SDL_GetError() << endl;
222 SDL_Quit();
223 exit(0);
224 }
225 SDL_FreeSurface(temp);
226
227 temp = Load_Image("images/depthdownoff.png");
228 if(temp != NULL) depthdownoff = SDL_DisplayFormat(temp);
229 if ( depthdownoff == NULL ) {
230 cerr<<"Function LoadWidgets()" << endl
231 << SDL_GetError() << endl;
232 SDL_Quit();
233 exit(0);
234 }
235 SDL_FreeSurface(temp);
236
237 temp = Load_Image("images/depthdownon.png");
238 if(temp != NULL) depthdownon = SDL_DisplayFormat(temp);
239 if ( depthdownon == NULL ) {
240 cerr<<"Function LoadWidgets()" << endl
241 << SDL_GetError() << endl;
242 SDL_Quit();
243 exit(0);
244 }
245 SDL_FreeSurface(temp);
246
247 }
248
DisplayWidgets()249 void Control::DisplayWidgets(){
250 if(ASTOP)
251 {
252 dest.x = 231;
253 dest.y = 582;
254 dest.h = STOPon->h;
255 dest.w = STOPon->w;
256 SDL_BlitSurface(STOPon, NULL, screen, &dest);
257 SDL_UpdateRects(screen, 1, &dest);
258 }
259 else
260 {
261 dest.x = 231;
262 dest.y = 582;
263 dest.h = STOPoff->h;
264 dest.w = STOPoff->w;
265 SDL_BlitSurface(STOPoff, NULL, screen, &dest);
266 SDL_UpdateRects(screen, 1, &dest);
267 }
268
269 if(A13)
270 {
271 dest.x = 264;
272 dest.y = 582;
273 dest.h = A13on->h;
274 dest.w = A13on->w;
275 SDL_BlitSurface(A13on, NULL, screen, &dest);
276 SDL_UpdateRects(screen, 1, &dest);
277 }
278 else
279 {
280 dest.x = 264;
281 dest.y = 582;
282 dest.h = A13off->h;
283 dest.w = A13off->w;
284 SDL_BlitSurface(A13off, NULL, screen, &dest);
285 SDL_UpdateRects(screen, 1, &dest);
286 }
287
288 if(A23)
289 {
290 dest.x = 297;
291 dest.y = 581;
292 dest.h = A23on->h;
293 dest.w = A23on->w;
294 SDL_BlitSurface(A23on, NULL, screen, &dest);
295 SDL_UpdateRects(screen, 1, &dest);
296 }
297 else
298 {
299 dest.x = 297;
300 dest.y = 581;
301 dest.h = A23off->h;
302 dest.w = A23off->w;
303 SDL_BlitSurface(A23off, NULL, screen, &dest);
304 SDL_UpdateRects(screen, 1, &dest);
305 }
306
307 if(ASTD)
308 {
309 dest.x = 330;
310 dest.y = 581;
311 dest.h = ASTDon->h;
312 dest.w = ASTDon->w;
313 SDL_BlitSurface(ASTDon, NULL, screen, &dest);
314 SDL_UpdateRects(screen, 1, &dest);
315 }
316 else
317 {
318 dest.x = 330;
319 dest.y = 581;
320 dest.h = ASTDoff->h;
321 dest.w = ASTDoff->w;
322 SDL_BlitSurface(ASTDoff, NULL, screen, &dest);
323 SDL_UpdateRects(screen, 1, &dest);
324 }
325
326 if(AFULL)
327 {
328 dest.x = 363;
329 dest.y = 581;
330 dest.h = AFULLon->h;
331 dest.w = AFULLon->w;
332 SDL_BlitSurface(AFULLon, NULL, screen, &dest);
333 SDL_UpdateRects(screen, 1, &dest);
334 }
335 else
336 {
337 dest.x = 363;
338 dest.y = 581;
339 dest.h = AFULLoff->h;
340 dest.w = AFULLoff->w;
341 SDL_BlitSurface(AFULLoff, NULL, screen, &dest);
342 SDL_UpdateRects(screen, 1, &dest);
343 }
344
345 if(AFLK)
346 {
347 dest.x = 396;
348 dest.y = 581;
349 dest.h = AFLKon->h;
350 dest.w = AFLKon->w;
351 SDL_BlitSurface(AFLKon, NULL, screen, &dest);
352 SDL_UpdateRects(screen, 1, &dest);
353 }
354 else
355 {
356 dest.x = 396;
357 dest.y = 581;
358 dest.h = AFLKoff->h;
359 dest.w = AFLKoff->w;
360 SDL_BlitSurface(AFLKoff, NULL, screen, &dest);
361 SDL_UpdateRects(screen, 1, &dest);
362 }
363
364 if(B13)
365 {
366 dest.x = 198;
367 dest.y = 582;
368 dest.h = A13on->h;
369 dest.w = A13on->w;
370 SDL_BlitSurface(A13on, NULL, screen, &dest);
371 SDL_UpdateRects(screen, 1, &dest);
372 }
373 else
374 {
375 dest.x = 198;
376 dest.y = 582;
377 dest.h = A13off->h;
378 dest.w = A13off->w;
379 SDL_BlitSurface(A13off, NULL, screen, &dest);
380 SDL_UpdateRects(screen, 1, &dest);
381 }
382 if(B23)
383 {
384 dest.x = 165;
385 dest.y = 581;
386 dest.h = A23on->h;
387 dest.w = A23on->w;
388 SDL_BlitSurface(A23on, NULL, screen, &dest);
389 SDL_UpdateRects(screen, 1, &dest);
390 }
391 else
392 {
393 dest.x = 165;
394 dest.y = 581;
395 dest.h = A23off->h;
396 dest.w = A23off->w;
397 SDL_BlitSurface(A23off, NULL, screen, &dest);
398 SDL_UpdateRects(screen, 1, &dest);
399 }
400 if(BSTD)
401 {
402 dest.x = 132;
403 dest.y = 581;
404 dest.h = ASTDon->h;
405 dest.w = ASTDon->w;
406 SDL_BlitSurface(ASTDon, NULL, screen, &dest);
407 SDL_UpdateRects(screen, 1, &dest);
408 }
409 else
410 {
411 dest.x = 132;
412 dest.y = 581;
413 dest.h = ASTDoff->h;
414 dest.w = ASTDoff->w;
415 SDL_BlitSurface(ASTDoff, NULL, screen, &dest);
416 SDL_UpdateRects(screen, 1, &dest);
417 }
418
419 if(BEMER)
420 {
421 dest.x = 99;
422 dest.y = 581;
423 dest.h = AFLKon->h;
424 dest.w = AFLKon->w;
425 SDL_BlitSurface(AFLKon, NULL, screen, &dest);
426 SDL_UpdateRects(screen, 1, &dest);
427 }
428 else
429 {
430 dest.x = 99;
431 dest.y = 581;
432 dest.h = AFLKoff->h;
433 dest.w = AFLKoff->w;
434 SDL_BlitSurface(AFLKoff, NULL, screen, &dest);
435 SDL_UpdateRects(screen, 1, &dest);
436 }
437
438 if(depthdown)
439 {
440 dest.x = 111;
441 dest.y = 253;
442 dest.h = depthdownon->h;
443 dest.w = depthdownon->w;
444 SDL_BlitSurface(depthdownon, NULL, screen, &dest);
445 SDL_UpdateRects(screen, 1, &dest);
446 }
447 else
448 {
449 dest.x = 111;
450 dest.y = 253;
451 dest.h = depthdownoff->h;
452 dest.w = depthdownoff->w;
453 SDL_BlitSurface(depthdownoff, NULL, screen, &dest);
454 SDL_UpdateRects(screen, 1, &dest);
455 }
456 if(depthup)
457 {
458 dest.x = 384;
459 dest.y = 256;
460 dest.h = depthupon->h;
461 dest.w = depthupon->w;
462 SDL_BlitSurface(depthupon, NULL, screen, &dest);
463 SDL_UpdateRects(screen, 1, &dest);
464 }
465 else
466 {
467 dest.x = 384;
468 dest.y = 256;
469 dest.h = depthupoff->h;
470 dest.w = depthupoff->w;
471 SDL_BlitSurface(depthupoff, NULL, screen, &dest);
472 SDL_UpdateRects(screen, 1, &dest);
473 }
474 }
475
ClearHeading()476 void Control::ClearHeading(){
477
478 // Clear the screen
479 SDL_Surface *temp;
480 temp = Load_Image("images/ClearControl.png");
481 if(temp != NULL) ClearControl = SDL_DisplayFormat(temp);
482 if ( ClearControl == NULL ) {
483 cerr<<"Function LoadWidgets()" << endl
484 << SDL_GetError() << endl;
485 SDL_Quit();
486 exit(0);
487 }
488
489 SDL_FreeSurface(temp);
490
491 src.x = 0;
492 src.y = 0;
493 src.w = ClearControl->w;
494 src.h = ClearControl->h;
495
496 dest.x = 107; // Blit destination x&y to the upper left
497 dest.y = 140;
498 dest.w = ClearControl->w; // Height and width equal to the
499 dest.h = ClearControl->h; // source images....
500 SDL_BlitSurface(ClearControl, NULL, screen, &dest); // Do the actual Blit
501
502 SDL_UpdateRects(screen, 1, &dest); //Show the screen.
503 SDL_FreeSurface(ClearControl); //Free up the surface memory.
504 }
505
ClearOrdHeading()506 void Control::ClearOrdHeading(){
507 int x, y;
508 double x1, y1, x2, y2;//rdm 9/11
509
510 // Clear Last Ordered Heading Compass //rdm 9/11
511 x = int(251.0 + 58.0*cos(1.57-old_heading*3.14/180.0));
512 y = int(344.0 - 58.0*sin(1.57-old_heading*3.14/180.0));
513 // filledTrigonRGBA(screen, 251, 341, 251, 347, x, y, 0, 0, 0, 255); //rdm 9/11
514
515 x1 = int(251.0 + 4.0*sin(1.57-old_heading*3.14/180.0));
516 y1 = int(344.0 + 4.0*cos(1.57-old_heading*3.14/180.0));
517 x2 = int(251.0 - 4.0*sin(1.57-old_heading*3.14/180.0));
518 y2 = int(344.0 - 4.0*cos(1.57-old_heading*3.14/180.0));
519
520 filledTrigonRGBA(screen, x1, y1, x2, y2, x, y, 0, 0, 0, 255);
521
522 // Clear the screen
523 SDL_Surface *temp;
524 temp = Load_Image("images/ClearControl.png");
525 if(temp != NULL) ClearControl = SDL_DisplayFormat(temp);
526 if ( ClearControl == NULL ) {
527 cerr<<"Function LoadWidgets()" << endl
528 << SDL_GetError() << endl;
529 SDL_Quit();
530 exit(0);
531 }
532
533 SDL_FreeSurface(temp);
534
535 src.x = 0;
536 src.y = 0;
537 src.w = ClearControl->w;
538 src.h = ClearControl->h;
539
540 dest.x = 107; // Blit destination x&y to the upper left
541 dest.y = 195;
542 dest.w = ClearControl->w; // Height and width equal to the
543 dest.h = ClearControl->h; // source images....
544 SDL_BlitSurface(ClearControl, NULL, screen, &dest); // Do the actual Blit
545
546 SDL_UpdateRects(screen, 1, &dest); //Show the screen.
547 SDL_FreeSurface(ClearControl); //Free up the surface memory.
548 DisplayWidgets();
549
550 }
551
ClearDepth()552 void Control::ClearDepth(){
553
554 // Clear the screen
555 SDL_Surface *temp;
556 temp = Load_Image("images/ClearControl.png");
557 if(temp != NULL) ClearControl = SDL_DisplayFormat(temp);
558 if ( ClearControl == NULL ) {
559 cerr<<"Function LoadWidgets()" << endl
560 << SDL_GetError() << endl;
561 SDL_Quit();
562 exit(0);
563 }
564
565 SDL_FreeSurface(temp);
566
567 src.x = 0;
568 src.y = 0;
569 src.w = ClearControl->w;
570 src.h = ClearControl->h;
571
572 dest.x = 211; // Blit destination x&y to the upper left
573 dest.y = 140;
574 dest.w = ClearControl->w; // Height and width equal to the
575 dest.h = ClearControl->h; // source images....
576 SDL_BlitSurface(ClearControl, NULL, screen, &dest); // Do the actual Blit
577
578 SDL_UpdateRects(screen, 1, &dest); //Show the screen.
579 SDL_FreeSurface(ClearControl); //Free up the surface memory.
580 }
581
ClearOrdDepth()582 void Control::ClearOrdDepth(){
583
584 // Clear the screen
585 SDL_Surface *temp;
586 temp = Load_Image("images/ClearControl.png");
587 if(temp != NULL) ClearControl = SDL_DisplayFormat(temp);
588 if ( ClearControl == NULL ) {
589 cerr<<"Function LoadWidgets()" << endl
590 << SDL_GetError() << endl;
591 SDL_Quit();
592 exit(0);
593 }
594
595 SDL_FreeSurface(temp);
596
597 src.x = 0;
598 src.y = 0;
599 src.w = ClearControl->w;
600 src.h = ClearControl->h;
601
602 dest.x = 211; // Blit destination x&y to the upper left
603 dest.y = 195;
604 dest.w = ClearControl->w; // Height and width equal to the
605 dest.h = ClearControl->h; // source images....
606 SDL_BlitSurface(ClearControl, NULL, screen, &dest); // Do the actual Blit
607
608
609 SDL_UpdateRects(screen, 1, &dest); //Show the screen.
610 SDL_FreeSurface(ClearControl); //Free up the surface memory.
611 DisplayWidgets();
612 }
613
ClearOrdSpeed()614 void Control::ClearOrdSpeed(){
615 BEMER = false;
616 BSTD = false;
617 B23 = false;
618 B13 = false;
619 ASTOP = false;
620 A13 = false;
621 A23 = false;
622 ASTD = false;
623 AFULL = false;
624 AFLK = false;
625
626 // Clear the screen
627 SDL_Surface *temp;
628 temp = Load_Image("images/ClearControl.png");
629 if(temp != NULL) ClearControl = SDL_DisplayFormat(temp);
630 if ( ClearControl == NULL ) {
631 cerr<<"Function LoadWidgets()" << endl
632 << SDL_GetError() << endl;
633 SDL_Quit();
634 exit(0);
635 }
636
637 SDL_FreeSurface(temp);
638
639 src.x = 0;
640 src.y = 0;
641 src.w = ClearControl->w;
642 src.h = ClearControl->h;
643
644 dest.x = 317; // Blit destination x&y to the upper left
645 dest.y = 194;
646 dest.w = ClearControl->w; // Height and width equal to the
647 dest.h = ClearControl->h; // source images....
648 SDL_BlitSurface(ClearControl, NULL, screen, &dest); // Do the actual Blit
649
650
651 SDL_UpdateRects(screen, 1, &dest); //Show the screen.
652 SDL_FreeSurface(ClearControl); //Free up the surface memory.
653 DisplayWidgets();
654 }
655
ClearSpeed()656 void Control::ClearSpeed(){
657 // Clear the screen
658 SDL_Surface *temp;
659 temp = Load_Image("images/ClearControl.png");
660 if(temp != NULL) ClearControl = SDL_DisplayFormat(temp);
661 if ( ClearControl == NULL ) {
662 cerr<<"Function LoadWidgets()" << endl
663 << SDL_GetError() << endl;
664 SDL_Quit();
665 exit(0);
666 }
667
668 SDL_FreeSurface(temp);
669
670 src.x = 0;
671 src.y = 0;
672 src.w = ClearControl->w;
673 src.h = ClearControl->h;
674
675 dest.x = 317; // Blit destination x&y to the upper left
676 dest.y = 139;
677 dest.w = ClearControl->w; // Height and width equal to the
678 dest.h = ClearControl->h; // source images....
679 SDL_BlitSurface(ClearControl, NULL, screen, &dest); // Do the actual Blit
680
681 SDL_UpdateRects(screen, 1, &dest); //Show the screen.
682 SDL_FreeSurface(ClearControl); //Free up the surface memory.
683 }
684
ToggleBEMER()685 void Control::ToggleBEMER(){
686 ClearOrdSpeed();
687 BEMER = !BEMER;
688 Subs->DesiredSpeed = -16;
689 }
ToggleBSTD()690 void Control::ToggleBSTD(){
691 ClearOrdSpeed();
692 BSTD = !BSTD;
693 Subs->DesiredSpeed = -12;
694 }
ToggleB23()695 void Control::ToggleB23(){
696 ClearOrdSpeed();
697 B23 = !B23;
698 Subs->DesiredSpeed = -8;
699 }
ToggleB13()700 void Control::ToggleB13(){
701 ClearOrdSpeed();
702 B13 = !B13;
703 Subs->DesiredSpeed = -4;
704 }
ToggleASTOP()705 void Control::ToggleASTOP(){
706 ClearOrdSpeed();
707 ASTOP = !ASTOP;
708 Subs->DesiredSpeed = 0;
709 }
ToggleA13()710 void Control::ToggleA13(){
711 ClearOrdSpeed();
712 A13 = !A13;
713 Subs->DesiredSpeed = 5;
714 }
ToggleA23()715 void Control::ToggleA23(){
716 ClearOrdSpeed();
717 A23 = !A23;
718 Subs->DesiredSpeed = 10;
719 }
ToggleASTD()720 void Control::ToggleASTD(){
721 ClearOrdSpeed();
722 ASTD = !ASTD;
723 Subs->DesiredSpeed = 15;
724 }
ToggleAFULL()725 void Control::ToggleAFULL(){
726 ClearOrdSpeed();
727 AFULL = !AFULL;
728 Subs->DesiredSpeed = 20;
729 }
ToggleAFLK()730 void Control::ToggleAFLK(){
731 ClearOrdSpeed();
732 AFLK = !AFLK;
733 Subs->DesiredSpeed = 32;
734 }
735
Display()736 void Control::Display(){
737 static char text[120];
738 char file1[] = "images/font.png";
739 char file2[] = "data/font.dat";
740 DFont fnt(file1, file2);
741 float radians, previous_radians;
742 float previous_speed, previous_depth;
743 double x1, y1, x2, y2;
744
745
746 if (depthup) Subs->DesiredDepth--; // Take her up!!
747 if (depthdown) Subs->DesiredDepth++; // Take her down!!
748
749 // Heading Screen
750 src.x=110;
751 src.y=142; //define a rectangle on the screen and make it black
752 src.h=15;
753 src.w=75;
754
755 sprintf(text, "%i",(int)Subs[0].Heading);
756 fnt.PutString(screen, 145, 144, text);
757
758 // Ordered Heading Screen
759 src.x=110;
760 src.y=196; //define a rectangle on the screen and make it black
761 src.h=15;
762 src.w=75;
763
764 sprintf(text, "%i",(int)Subs[0].DesiredHeading);
765 fnt.PutString(screen, 145, 198, text);
766
767 //Replot desired heading compass if we left control screen before turn completed //rdm 9/11
768 if (Subs->DesiredHeading != Subs->Heading )
769 {
770 // Draw a green filled triangle with vertices (x1, y1), (x2, y2), (x3, y3) and RGBA color (r, g, b, a)
771 x = int(251.0 + 58.0*cos(1.57-Subs[0].DesiredHeading*3.14/180.0));
772 y = int(344.0 - 58.0*sin(1.57-Subs[0].DesiredHeading*3.14/180.0));
773
774 x1 = int(251.0 + 4.0*sin(1.57-Subs[0].DesiredHeading*3.14/180.0));
775 y1 = int(344.0 + 4.0*cos(1.57-Subs[0].DesiredHeading*3.14/180.0));
776 x2 = int(251.0 - 4.0*sin(1.57-Subs[0].DesiredHeading*3.14/180.0));
777 y2 = int(344.0 - 4.0*cos(1.57-Subs[0].DesiredHeading*3.14/180.0));
778
779 filledTrigonRGBA(screen, x1, y1, x2, y2, x, y, 0, 128, 0, 255);
780 }
781
782 // Depth Screen
783 src.x=212;
784 src.y=142;
785 src.h=15;
786 src.w=75;
787
788 sprintf(text, "%i", (int)Subs[0].Depth);
789 fnt.PutString(screen, 247, 144, text);
790
791 // Desired Depth Screen
792 src.x=212;
793 src.y=197;
794 src.h=15;
795 src.w=75;
796
797 sprintf(text, "%i", (int)Subs[0].DesiredDepth);
798 fnt.PutString(screen, 247, 199, text);
799
800 // Clear the Ordered Depth Boxes if needed.
801 if(Subs->DesiredDepth == 100.0) ClearOrdDepth();
802 if(Subs->DesiredDepth == 1000.0) ClearOrdDepth();
803
804
805 // Speed Screen
806 src.x=320;
807 src.y=142;
808 src.h=15;
809 src.w=75;
810
811 sprintf(text, "%d", int(Subs->Speed));
812 fnt.PutString(screen, 355, 144, text);
813
814 // Desired Speed Screen
815 src.x=320;
816 src.y=197;
817 src.h=15;
818 src.w=75;
819
820 sprintf(text, "%i", (int)Subs->DesiredSpeed);
821 fnt.PutString(screen, 355, 199, text);
822
823 radians = Subs->Heading *(3.14/180.0); // degrees to radians
824
825 if (!HeadingStack.empty()) // Is there is data on the stack?
826 {
827 previous_radians = HeadingStack.pop();
828 previous_speed = SpeedStack.pop();
829 previous_depth = DepthStack.pop();
830
831 // Next lines clear the display as nec to prevent garbage on screen
832 if(Subs->Heading <= 10.0 && previous_radians*(180.0/3.14) > 10.0) ClearHeading();
833 if(Subs->Heading <= 100.0 && previous_radians*(180.0/3.14) > 100.0) ClearHeading();
834 if(Subs->Speed <= 10.0 && previous_speed > 10.0) ClearSpeed();
835 if(Subs->Speed >= -10.0 && previous_speed < -10.0) ClearSpeed();
836 if(Subs->Speed >= 0.0 && previous_speed < 0.0) ClearSpeed();
837
838 if(Subs->Depth <= 100.0 && previous_depth > 100.0) ClearDepth();
839 if(Subs->Depth <= 1000.0 && previous_depth > 1000.0) ClearDepth();
840
841
842 // Clear Old Data from Heading Compass //rdm 9/11
843 // Draw a orange filled triangle with vertices (x1, y1), (x2, y2), (x3, y3) and RGBA color (r, g, b, a)
844 x = int(251.0 + 58.0*cos(1.57-previous_radians));
845 y = int(344.0 - 58.0*sin(1.57-previous_radians));
846
847 x1 = int(251.0 + 4.0*sin(1.57-previous_radians));
848 y1 = int(344.0 + 4.0*cos(1.57-previous_radians));
849 x2 = int(251.0 - 4.0*sin(1.57-previous_radians));
850 y2 = int(344.0 - 4.0*cos(1.57-previous_radians));
851
852 filledTrigonRGBA(screen, x1, y1, x2, y2, x, y, 0, 0, 0, 255);
853
854 }
855
856 // Draw Desired Heading Compass //rdm 9/11
857 // Draw a orange filled triangle with vertices (x1, y1), (x2, y2), (x3, y3) and RGBA color (r, g, b, a)
858 x = int(251.0 + 58.0*cos(1.57-radians));
859 y = int(344.0 - 58.0*sin(1.57-radians));
860
861 x1 = int(251.0 + 4.0*sin(1.57-radians));
862 y1 = int(344.0 + 4.0*cos(1.57-radians));
863 x2 = int(251.0 - 4.0*sin(1.57-radians));
864 y2 = int(344.0 - 4.0*cos(1.57-radians));
865
866 filledTrigonRGBA(screen, x1, y1, x2, y2, x, y, 238, 118, 0, 255);
867
868 // Push the data on the stack
869 HeadingStack.push(radians);
870 SpeedStack.push(Subs->Speed);
871 DepthStack.push(Subs->Depth);
872
873 SDL_UpdateRect(screen,0, 0, 0, 0);
874
875 }
876
AdjustHeading(int x,int y)877 void Control::AdjustHeading(int x, int y){
878
879 double c1, c3, c5, c6;
880 double x1, y1, x2, y2;
881 int heading;
882
883 c1 = double(251);
884 c3 = double(344);
885
886 // c5 = 60.0*(double(y)-c3);
887 // c6 = 60.0*(double(x)-c1);
888
889 c5 = 58.0*(double(y)-c3);
890 c6 = 58.0*(double(x)-c1);
891
892
893 ClearOrdHeading();
894
895 if(x >= 251)
896 {
897 heading = int(90.0 + (180/3.14)*atan(c5/c6));
898 }
899 else
900 {
901 heading = int(270.0 + (180/3.14)*atan(c5/c6));
902 }
903
904 Subs->DesiredHeading = heading;
905 old_heading = heading;
906
907 // Draw Desired Heading Compass//rdm 9/11
908 // Draw a green filled triangle with vertices (x1, y1), (x2, y2), (x3, y3) and RGBA color (r, g, b, a)
909 x = int(251.0 + 58.0*cos(1.57-heading*3.14/180.0));
910 y = int(344.0 - 58.0*sin(1.57-heading*3.14/180.0));
911 // filledTrigonRGBA(screen, 251, 341, 251, 347, x, y, 0, 128, 0, 255); //rdm 9/11
912
913 x1 = int(251.0 + 4.0*sin(1.57-heading*3.14/180.0));
914 y1 = int(344.0 + 4.0*cos(1.57-heading*3.14/180.0));
915 x2 = int(251.0 - 4.0*sin(1.57-heading*3.14/180.0));
916 y2 = int(344.0 - 4.0*cos(1.57-heading*3.14/180.0));
917
918 filledTrigonRGBA(screen, x1, y1, x2, y2, x, y, 0, 128, 0, 255);
919 return;
920
921 }
922
AdjustDepth(int x)923 void Control::AdjustDepth(int x){
924
925 ClearOrdDepth();
926 if(x > 112 && x < 126)
927 {
928 if(depthup)
929 {
930 depthup = false;
931 }
932 else
933 {
934 depthdown = true;
935 depthup = false;
936 }
937 }
938
939 if(x > 385 && x < 401)
940 {
941 if(depthdown)
942 {
943 depthdown = false;
944 }
945 else
946 {
947 depthdown = false;
948 depthup = true;
949 }
950 }
951 DisplayWidgets();
952 return;
953 }
954
955 //Not needed if use SDL_gfx rdm 9/11
956
957 /*
958 void Control::DLine(SDL_Surface *screen, int X1, int Y1, int X2, int Y2, Uint32 Color)
959 {
960
961 int dx,dy,sdx,sdy,py,px,x,y;
962 dx = X2 - X1;
963 dy = Y2 - Y1;
964 if (dx < 0) sdx = -1;
965 else sdx = 1;
966 if (dy < 0) sdy = -1;
967 else sdy = 1;
968 dx = sdx * dx + 1;
969 dy = sdy * dy + 1;
970 x = 0;
971 y = 0;
972 px = X1;
973 py = Y1;
974 if (dx >= dy){
975 for (int x = 0; x < dx; x++){
976 DPixel(screen, px, py, Color);
977 y = y + dy;
978 if (y >= dx){
979 y = y - dx;
980 py = py + sdy;
981 }
982 px = px + sdx;
983 }
984 }else{
985 for (int y = 0; y < dy; y++){
986 DPixel(screen, px, py, Color);
987 x = x + dx;
988 if (x >= dy){
989 x = x - dy;
990 px = px + sdx;
991 }
992 py = py + sdy;
993 }
994 }
995 }
996
997 void Control::DPixel(SDL_Surface *screen, int x, int y, Uint32 color)
998 {
999 //this only works for 16bpp screens
1000 //are we outside the screen?????
1001 //If we are bail out now before it's too late!
1002
1003 //cerr << ".";
1004 if (x > 1023 || x < 0 || y > 759 || y < 0) {
1005 return;
1006 }
1007
1008 //place the pixel on the screen
1009 Uint16 *pixel_location;
1010 pixel_location = (Uint16 *)screen->pixels + y*screen->pitch/2 + x;
1011 *pixel_location = color;
1012 }
1013 */
1014