]> git.mxchange.org Git - flightgear.git/blob - src/ATC/ATCdisplay.cxx
Initial revision of ATIS module contributed by Dave Luff.
[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     dsp_offset1 = 0;
41     dsp_offset2 = 0;
42 }
43
44
45 // Destructor
46 FGATCDisplay::~FGATCDisplay( void ) {
47 }
48
49 void FGATCDisplay::init( void ) {
50 }
51
52
53 // update - this actually draws the visuals and should be called from the main Flightgear rendering loop.
54 void FGATCDisplay::update() {
55
56     if(rep_msg) {
57         float fps = general.get_frame_rate();
58         
59         //cout << "In FGATC::update()" << endl;
60         SGPropertyNode *xsize_node = fgGetNode("/sim/startup/xsize");
61         SGPropertyNode *ysize_node = fgGetNode("/sim/startup/ysize");
62         int iwidth   = xsize_node->getIntValue();
63         int iheight  = ysize_node->getIntValue();
64         
65         //TODO - if the string is bigger than the buffer the program exits - we really ought to have a robust check here
66         char buf[256];
67         //float fps = visibility/1600;
68         //      sprintf(buf,"%-4.1f  %7.0f  %7.0f", fps, tris, culled);
69 //      sprintf(buf,"%s %-5.1f", "visibility ", visibility);
70         sprintf(buf,"%s", rep_msg_str.c_str());
71         
72         glMatrixMode( GL_PROJECTION );
73         glPushMatrix();
74         glLoadIdentity();
75         gluOrtho2D( 0, iwidth, 0, iheight );
76         glMatrixMode( GL_MODELVIEW );
77         glPushMatrix();
78         glLoadIdentity();
79         
80         glDisable( GL_DEPTH_TEST );
81         glDisable( GL_LIGHTING );
82         
83         glColor3f( 0.9, 0.4, 0.2 );
84         
85 //      guiFnt.drawString( buf,
86 //          int(iwidth - guiFnt.getStringWidth(buf) - 10 - (int)dsp_offset),
87 //          (iheight - 20) );
88         guiFnt.drawString( buf,
89             int(iwidth - 10 - dsp_offset1),
90             (iheight - 20) );
91         guiFnt.drawString( buf,
92             int(iwidth - 10 - dsp_offset2),
93             (iheight - 20) );
94         glEnable( GL_DEPTH_TEST );
95         glEnable( GL_LIGHTING );
96         glMatrixMode( GL_PROJECTION );
97         glPopMatrix();
98         glMatrixMode( GL_MODELVIEW );
99         glPopMatrix();
100         
101         // Try to scroll at a frame rate independent speed
102         // 40 pixels/second looks about right for now
103         if(dsp_offset1 >= dsp_offset2) {
104             dsp_offset1+=(40.0/fps);
105             dsp_offset2 = dsp_offset1 - (rep_msg_str.size() * 10) - 100;
106             if(dsp_offset1 > (iwidth + (rep_msg_str.size() * 10)))
107                 dsp_offset1 = 0;
108         } else {
109             dsp_offset2+=(40.0/fps);
110             dsp_offset1 = dsp_offset2 - (rep_msg_str.size() * 10) - 100;
111             if(dsp_offset2 > (iwidth + (rep_msg_str.size() * 10)))
112                 dsp_offset2 = 0;
113         }
114         
115     }
116 }
117
118
119 void FGATCDisplay::RegisterRepeatingMessage(string msg) {
120     rep_msg = true;
121     rep_msg_str = msg;
122     return;
123 }
124
125 void FGATCDisplay::ChangeRepeatingMessage(string newmsg) {
126     //Not implemented yet
127     return;
128 }
129
130 void FGATCDisplay::CancelRepeatingMessage() {
131     rep_msg = false;
132     rep_msg_str = "";
133     dsp_offset1 = 0;
134     dsp_offset2 = 0;
135     return;
136 }