]> git.mxchange.org Git - flightgear.git/blob - src/Cockpit/built_in/FGMagRibbon.cxx
Moved "scenery" from being declaried in scenery.cxx to being declared
[flightgear.git] / src / Cockpit / built_in / FGMagRibbon.cxx
1 //  FGMagRibbon.cxx - Built-in layer for the magnetic compass ribbon layer.
2 //
3 //  Written by David Megginson, started January 2000.
4 //
5 //  This program is free software; you can redistribute it and/or
6 //  modify it under the terms of the GNU General Public License as
7 //  published by the Free Software Foundation; either version 2 of the
8 //  License, or (at your option) any later version.
9 // 
10 //  This program is distributed in the hope that it will be useful, but
11 //  WITHOUT ANY WARRANTY; without even the implied warranty of
12 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 //  General Public License for more details.
14 // 
15 //  You should have received a copy of the GNU General Public License
16 //  along with this program; if not, write to the Free Software
17 //  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 //
19 //  $Id$
20
21
22 #include "FGMagRibbon.hxx"
23 #include "../steam.hxx"
24
25
26 FGMagRibbon::FGMagRibbon (int w, int h)
27   : FGTexturedLayer(w, h)
28 {
29   FGCroppedTexture texture("Aircraft/Instruments/Textures/compass-ribbon.rgb");
30   setTexture(texture);
31 }
32
33 void
34 FGMagRibbon::draw ()
35 {
36   double heading = FGSteam::get_MH_deg();
37   double xoffset, yoffset;
38
39   while (heading >= 360.0) {
40     heading -= 360.0;
41   }
42   while (heading < 0.0) {
43     heading += 360.0;
44   }
45
46   if (heading >= 60.0 && heading <= 180.0) {
47     xoffset = heading / 240.0;
48     yoffset = 0.75;
49   } else if (heading >= 150.0 && heading <= 270.0) {
50     xoffset = (heading - 90.0) / 240.0;
51     yoffset = 0.50;
52   } else if (heading >= 240.0 && heading <= 360.0) {
53     xoffset = (heading - 180.0) / 240.0;
54     yoffset = 0.25;
55   } else {
56     if (heading < 270.0)
57       heading += 360.0;
58     xoffset = (heading - 270.0) / 240.0;
59     yoffset = 0.0;
60   }
61
62   xoffset = 1.0 - xoffset;
63                                 // Adjust to put the number in the centre
64   xoffset -= 0.25;
65
66   FGCroppedTexture &t = getTexture();
67   t.setCrop(xoffset, yoffset, xoffset + 0.5, yoffset + 0.25);
68   FGTexturedLayer::draw();
69 }
70
71 // end of FGMagRibbon.cxx