]> git.mxchange.org Git - flightgear.git/blob - src/ATC/ATCdisplay.cxx
Oops. A change to an upstream header seems to have remove glu.h, which
[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 <GL/glu.h>
26
27 #include <simgear/props/props.hxx>
28
29 #include <Include/general.hxx>
30 #include <Main/fg_props.hxx>
31 #include <GUI/gui.h>
32
33 #include "ATCdisplay.hxx"
34
35
36 // Constructor
37 FGATCDisplay::FGATCDisplay() {
38         rep_msg = false;
39         change_msg_flag = false;
40         dsp_offset1 = 0.0;
41         dsp_offset2 = 0.0;
42 }
43
44
45 // Destructor
46 FGATCDisplay::~FGATCDisplay() {
47 }
48
49 void FGATCDisplay::init() {
50 }
51
52 void FGATCDisplay::bind() {
53 }
54
55 void FGATCDisplay::unbind() {
56 }
57
58 // update - this actually draws the visuals and should be called from the main Flightgear rendering loop.
59 void FGATCDisplay::update(double dt) {
60         
61         // These strings are used for temporary storage of the transmission string in order
62         // that the string we view only changes when the next repetition starts scrolling
63         // even though the master string (rep_msg_str) may change at any time.
64         static string msg1 = "";
65         static string msg2 = "";
66         
67         if( rep_msg || msgList.size() ) {
68                 //cout << "In FGATC::update()" << endl;
69                 SGPropertyNode *xsize_node = fgGetNode("/sim/startup/xsize");
70                 SGPropertyNode *ysize_node = fgGetNode("/sim/startup/ysize");
71                 int iwidth   = xsize_node->getIntValue();
72                 int iheight  = ysize_node->getIntValue();
73                 
74                 glMatrixMode( GL_PROJECTION );
75                 glPushMatrix();
76                 glLoadIdentity();
77                 gluOrtho2D( 0, iwidth, 0, iheight );
78                 glMatrixMode( GL_MODELVIEW );
79                 glPushMatrix();
80                 glLoadIdentity();
81                 
82                 glDisable( GL_DEPTH_TEST );
83                 glDisable( GL_LIGHTING );
84                 
85                 glColor3f( 0.9, 0.4, 0.2 );
86                 
87                 float fps = general.get_frame_rate();
88                 
89                 if(rep_msg) {
90                         //cout << "dsp_offset1 = " << dsp_offset1 << " dsp_offset2 = " << dsp_offset2 << endl;
91                         if(dsp_offset1 == 0) {
92                                 msg1 = rep_msg_str;
93                         }
94                         if(dsp_offset2 == 0) {
95                                 msg2 = rep_msg_str;
96                         }
97                         // Check for the situation where one offset is negative and the message is changed
98                         if(change_msg_flag) {
99                                 if(dsp_offset1 < 0) {
100                                         msg1 = rep_msg_str;
101                                 } else if(dsp_offset2 < 0) {
102                                         msg2 = rep_msg_str;
103                                 }
104                                 change_msg_flag = false;
105                         }
106                         
107                         //      guiFnt.drawString( rep_msg_str.c_str(),
108                         //          int(iwidth - guiFnt.getStringWidth(buf) - 10 - (int)dsp_offset),
109                         //          (iheight - 20) );
110                         guiFnt.drawString( msg1.c_str(),
111                         int(iwidth - 10 - dsp_offset1),
112                         (iheight - 20) );
113                         guiFnt.drawString( msg2.c_str(),
114                         int(iwidth - 10 - dsp_offset2),
115                         (iheight - 20) );
116                         
117                         // Try to scroll at a frame rate independent speed
118                         // 40 pixels/second looks about right for now
119                         if(dsp_offset1 >= dsp_offset2) {
120                                 dsp_offset1+=(40.0/fps);
121                                 dsp_offset2 = dsp_offset1 - (rep_msg_str.size() * 10) - 100;
122                                 if(dsp_offset1 > (iwidth + (rep_msg_str.size() * 10)))
123                                         dsp_offset1 = 0;
124                         } else {
125                                 dsp_offset2+=(40.0/fps);
126                                 dsp_offset1 = dsp_offset2 - (rep_msg_str.size() * 10) - 100;
127                                 if(dsp_offset2 > (iwidth + (rep_msg_str.size() * 10)))
128                                         dsp_offset2 = 0;
129                         }
130                         
131                 }
132                 
133                 if(msgList.size()) {
134                         //cout << "Attempting to render single message\n";
135                         // We have at least one non-repeating message to process
136                         if(fgGetBool("/ATC/display/scroll-single-messages")) {  // Scroll single messages across the screen.
137                                 msgList_itr = msgList.begin();
138                                 int i = 0;
139                                 while(msgList_itr != msgList.end()) {
140                                         atcMessage m = *msgList_itr;
141                                         //cout << "m.counter = " << m.counter << '\n';
142                                         if(m.dsp_offset > (iwidth + (m.msg.size() * 10))) {
143                                                 //cout << "Stopping single message\n";
144                                                 msgList_itr = msgList.erase(msgList_itr);
145                                         } else if(m.counter > m.start_count) {
146                                                 //cout << "Drawing single message\n";
147                                                 guiFnt.drawString( m.msg.c_str(),
148                                                 int(iwidth - 10 - m.dsp_offset),
149                                                 (iheight - 40) );
150                                                 m.counter += dt;
151                                                 m.dsp_offset += (80.0/fps);
152                                                 msgList[i] = m;
153                                                 ++msgList_itr;
154                                                 ++i;
155                                         } else {
156                                                 //cout << "Not yet started single message\n";
157                                                 m.counter += dt;
158                                                 msgList[i] = m;
159                                                 ++msgList_itr;
160                                                 ++i;
161                                         }
162                                 }
163                         } else {        // Display single messages for a short period of time.
164                                 msgList_itr = msgList.begin();
165                                 int i = 0;
166                                 while(msgList_itr != msgList.end()) {
167                                         atcMessage m = *msgList_itr;
168                                         //cout << "m.counter = " << m.counter << '\n';
169                                         if(m.counter > m.stop_count) {
170                                                 //cout << "Stopping single message\n";
171                                                 msgList_itr = msgList.erase(msgList_itr);
172                                         } else if(m.counter > m.start_count) {
173                                                 int pin = (((int)m.msg.size() * 8) >= iwidth ? 5 : (iwidth - (m.msg.size() * 8))/2);
174                                                 //cout << m.msg << '\n';
175                                                 //cout << "pin = " << pin << ", iwidth = " << iwidth << ", msg.size = " << m.msg.size() << '\n';
176                                                 guiFnt.drawString( m.msg.c_str(), pin, (iheight - 40) );
177                                                 m.counter += dt;
178                                                 msgList[i] = m;
179                                                 ++msgList_itr;
180                                                 ++i;
181                                         } else {
182                                                 m.counter += dt;
183                                                 msgList[i] = m;
184                                                 ++msgList_itr;
185                                                 ++i;
186                                         }
187                                 }
188                         }
189                 }
190                 glEnable( GL_DEPTH_TEST );
191                 glEnable( GL_LIGHTING );
192                 glMatrixMode( GL_PROJECTION );
193                 glPopMatrix();
194                 glMatrixMode( GL_MODELVIEW );
195                 glPopMatrix();
196         }
197 }
198
199 void FGATCDisplay::RegisterSingleMessage(string msg, double delay) {
200         //cout << msg << '\n';
201         atcMessage m;
202         m.msg = msg;
203         m.repeating = false;
204         m.counter = 0.0;
205         m.start_count = delay;
206         m.stop_count = m.start_count + 5.0;             // Display for 5ish seconds for now - this might have to change eg. be related to length of message in future
207         //cout << "m.stop_count = " << m.stop_count << '\n';
208         m.id = 0;
209         m.dsp_offset = 0.0;
210         
211         msgList.push_back(m);
212         //cout << "Single message registered\n";
213 }
214
215 void FGATCDisplay::RegisterRepeatingMessage(string msg) {
216         rep_msg = true;
217         rep_msg_str = msg;
218         return;
219 }
220
221 void FGATCDisplay::ChangeRepeatingMessage(string newmsg) {
222         rep_msg_str = newmsg;
223         change_msg_flag = true;
224         return;
225 }
226
227 void FGATCDisplay::CancelRepeatingMessage() {
228         rep_msg = false;
229         rep_msg_str = "";
230         dsp_offset1 = 0;
231         dsp_offset2 = 0;
232         return;
233 }
234