]> git.mxchange.org Git - flightgear.git/blob - src/ATC/ATCdisplay.cxx
Corrected typo ("Celsius" rather than "Celcius") and added to cast to
[flightgear.git] / src / ATC / ATCdisplay.cxx
1 // ATCdisplay.cxx - routines to display ATC output - graphically for now
2 //
3 // Written by David Luff, started October 2001.
4 //
5 // Copyright (C) 2001  David C Luff - david.luff@nottingham.ac.uk
6 //
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License as
9 // published by the Free Software Foundation; either version 2 of the
10 // License, or (at your option) any later version.
11 //
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 // General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20
21 #ifdef HAVE_CONFIG_H
22 #  include <config.h>
23 #endif
24
25 #include <simgear/misc/props.hxx>
26
27 #include <Include/general.hxx>
28 #include <Main/fg_props.hxx>
29 #include <GUI/gui.h>
30
31 #include "ATCdisplay.hxx"
32
33
34 FGATCDisplay *current_atcdisplay;
35
36
37 // Constructor
38 FGATCDisplay::FGATCDisplay( void ) {
39     rep_msg = false;
40     change_msg_flag = false;
41     dsp_offset1 = 0;
42     dsp_offset2 = 0;
43 }
44
45
46 // Destructor
47 FGATCDisplay::~FGATCDisplay( void ) {
48 }
49
50 void FGATCDisplay::init( void ) {
51 }
52
53
54 // update - this actually draws the visuals and should be called from the main Flightgear rendering loop.
55 void FGATCDisplay::update() {
56
57     // These strings are used for temporary storage of the transmission string in order
58     // that the string we view only changes when the next repitition starts scrolling
59     // even though the master string (rep_msg_str) may change at any time.
60     static string msg1 = "";
61     static string msg2 = "";
62
63     if(rep_msg) {
64         //cout << "dsp_offset1 = " << dsp_offset1 << " dsp_offset2 = " << dsp_offset2 << endl;
65         if(dsp_offset1 == 0) {
66             msg1 = rep_msg_str;
67         }
68         if(dsp_offset2 == 0) {
69             msg2 = rep_msg_str;
70         }
71         // Check for the situation where one offset is negative and the message is changed
72         if(change_msg_flag) {
73             if(dsp_offset1 < 0) {
74                 msg1 = rep_msg_str;
75             } else if(dsp_offset2 < 0) {
76                 msg2 = rep_msg_str;
77             }
78             change_msg_flag = false;
79         }
80
81         float fps = general.get_frame_rate();
82         
83         //cout << "In FGATC::update()" << endl;
84         SGPropertyNode *xsize_node = fgGetNode("/sim/startup/xsize");
85         SGPropertyNode *ysize_node = fgGetNode("/sim/startup/ysize");
86         int iwidth   = xsize_node->getIntValue();
87         int iheight  = ysize_node->getIntValue();
88         
89         glMatrixMode( GL_PROJECTION );
90         glPushMatrix();
91         glLoadIdentity();
92         gluOrtho2D( 0, iwidth, 0, iheight );
93         glMatrixMode( GL_MODELVIEW );
94         glPushMatrix();
95         glLoadIdentity();
96         
97         glDisable( GL_DEPTH_TEST );
98         glDisable( GL_LIGHTING );
99         
100         glColor3f( 0.9, 0.4, 0.2 );
101         
102 //      guiFnt.drawString( rep_msg_str.c_str(),
103 //          int(iwidth - guiFnt.getStringWidth(buf) - 10 - (int)dsp_offset),
104 //          (iheight - 20) );
105         guiFnt.drawString( msg1.c_str(),
106             int(iwidth - 10 - dsp_offset1),
107             (iheight - 20) );
108         guiFnt.drawString( msg2.c_str(),
109             int(iwidth - 10 - dsp_offset2),
110             (iheight - 20) );
111         glEnable( GL_DEPTH_TEST );
112         glEnable( GL_LIGHTING );
113         glMatrixMode( GL_PROJECTION );
114         glPopMatrix();
115         glMatrixMode( GL_MODELVIEW );
116         glPopMatrix();
117         
118         // Try to scroll at a frame rate independent speed
119         // 40 pixels/second looks about right for now
120         if(dsp_offset1 >= dsp_offset2) {
121             dsp_offset1+=(40.0/fps);
122             dsp_offset2 = dsp_offset1 - (rep_msg_str.size() * 10) - 100;
123             if(dsp_offset1 > (iwidth + (rep_msg_str.size() * 10)))
124                 dsp_offset1 = 0;
125         } else {
126             dsp_offset2+=(40.0/fps);
127             dsp_offset1 = dsp_offset2 - (rep_msg_str.size() * 10) - 100;
128             if(dsp_offset2 > (iwidth + (rep_msg_str.size() * 10)))
129                 dsp_offset2 = 0;
130         }
131         
132     }
133 }
134
135
136 void FGATCDisplay::RegisterRepeatingMessage(string msg) {
137     rep_msg = true;
138     rep_msg_str = msg;
139     return;
140 }
141
142 void FGATCDisplay::ChangeRepeatingMessage(string newmsg) {
143     rep_msg_str = newmsg;
144     change_msg_flag = true;
145     return;
146 }
147
148 void FGATCDisplay::CancelRepeatingMessage() {
149     rep_msg = false;
150     rep_msg_str = "";
151     dsp_offset1 = 0;
152     dsp_offset2 = 0;
153     return;
154 }