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