1 // ATCdisplay.cxx - routines to display ATC output - graphically for now
3 // Written by David Luff, started October 2001.
5 // Copyright (C) 2001 David C Luff - david.luff@nottingham.ac.uk
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.
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.
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.
29 #include <simgear/compiler.h>
33 #include <simgear/props/props.hxx>
35 #include <Include/general.hxx>
36 #include <Main/fg_props.hxx>
39 #include "ATCdisplay.hxx"
43 FGATCDisplay::FGATCDisplay() {
45 change_msg_flag = false;
52 FGATCDisplay::~FGATCDisplay() {
55 void FGATCDisplay::init() {
58 void FGATCDisplay::bind() {
61 void FGATCDisplay::unbind() {
64 // update - this actually draws the visuals and should be called from the main Flightgear rendering loop.
65 void FGATCDisplay::update(double dt) {
67 // These strings are used for temporary storage of the transmission string in order
68 // that the string we view only changes when the next repetition starts scrolling
69 // even though the master string (rep_msg_str) may change at any time.
70 static string msg1 = "";
71 static string msg2 = "";
73 if( rep_msg || msgList.size() ) {
74 //cout << "In FGATC::update()" << endl;
75 SGPropertyNode *xsize_node = fgGetNode("/sim/startup/xsize");
76 SGPropertyNode *ysize_node = fgGetNode("/sim/startup/ysize");
77 int iwidth = xsize_node->getIntValue();
78 int iheight = ysize_node->getIntValue();
80 glMatrixMode( GL_PROJECTION );
83 gluOrtho2D( 0, iwidth, 0, iheight );
84 glMatrixMode( GL_MODELVIEW );
88 glDisable( GL_DEPTH_TEST );
89 glDisable( GL_LIGHTING );
91 glColor3f( 0.9, 0.4, 0.2 );
93 float fps = general.get_frame_rate();
96 //cout << "dsp_offset1 = " << dsp_offset1 << " dsp_offset2 = " << dsp_offset2 << endl;
97 if(dsp_offset1 == 0) {
100 if(dsp_offset2 == 0) {
103 // Check for the situation where one offset is negative and the message is changed
104 if(change_msg_flag) {
105 if(dsp_offset1 < 0) {
107 } else if(dsp_offset2 < 0) {
110 change_msg_flag = false;
113 // guiFnt.drawString( rep_msg_str.c_str(),
114 // int(iwidth - guiFnt.getStringWidth(buf) - 10 - (int)dsp_offset),
116 guiFnt.drawString( msg1.c_str(),
117 int(iwidth - 10 - dsp_offset1),
119 guiFnt.drawString( msg2.c_str(),
120 int(iwidth - 10 - dsp_offset2),
123 // Try to scroll at a frame rate independent speed
124 // 40 pixels/second looks about right for now
125 if(dsp_offset1 >= dsp_offset2) {
126 dsp_offset1+=(40.0/fps);
127 dsp_offset2 = dsp_offset1 - (rep_msg_str.size() * 10) - 100;
128 if(dsp_offset1 > (iwidth + (rep_msg_str.size() * 10)))
131 dsp_offset2+=(40.0/fps);
132 dsp_offset1 = dsp_offset2 - (rep_msg_str.size() * 10) - 100;
133 if(dsp_offset2 > (iwidth + (rep_msg_str.size() * 10)))
140 //cout << "Attempting to render single message\n";
141 // We have at least one non-repeating message to process
142 if(fgGetBool("/ATC/display/scroll-single-messages")) { // Scroll single messages across the screen.
143 msgList_itr = msgList.begin();
145 while(msgList_itr != msgList.end()) {
146 atcMessage m = *msgList_itr;
147 //cout << "m.counter = " << m.counter << '\n';
148 if(m.dsp_offset > (iwidth + (m.msg.size() * 10))) {
149 //cout << "Stopping single message\n";
150 msgList_itr = msgList.erase(msgList_itr);
151 } else if(m.counter > m.start_count) {
152 //cout << "Drawing single message\n";
153 guiFnt.drawString( m.msg.c_str(),
154 int(iwidth - 10 - m.dsp_offset),
157 m.dsp_offset += (80.0/fps);
162 //cout << "Not yet started single message\n";
169 } else { // Display single messages for a short period of time.
170 msgList_itr = msgList.begin();
172 while(msgList_itr != msgList.end()) {
173 atcMessage m = *msgList_itr;
174 //cout << "m.counter = " << m.counter << '\n';
175 if(m.counter > m.stop_count) {
176 //cout << "Stopping single message\n";
177 msgList_itr = msgList.erase(msgList_itr);
178 } else if(m.counter > m.start_count) {
179 int pin = (((int)m.msg.size() * 8) >= iwidth ? 5 : (iwidth - (m.msg.size() * 8))/2);
180 //cout << m.msg << '\n';
181 //cout << "pin = " << pin << ", iwidth = " << iwidth << ", msg.size = " << m.msg.size() << '\n';
182 guiFnt.drawString( m.msg.c_str(), pin, (iheight - 40) );
196 glEnable( GL_DEPTH_TEST );
197 glEnable( GL_LIGHTING );
198 glMatrixMode( GL_PROJECTION );
200 glMatrixMode( GL_MODELVIEW );
205 void FGATCDisplay::RegisterSingleMessage(string msg, double delay) {
206 //cout << msg << '\n';
211 m.start_count = delay;
212 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
213 //cout << "m.stop_count = " << m.stop_count << '\n';
217 msgList.push_back(m);
218 //cout << "Single message registered\n";
221 void FGATCDisplay::RegisterRepeatingMessage(string msg) {
227 void FGATCDisplay::ChangeRepeatingMessage(string newmsg) {
228 rep_msg_str = newmsg;
229 change_msg_flag = true;
233 void FGATCDisplay::CancelRepeatingMessage() {