1 // FGMagRibbon.cxx - Built-in layer for the magnetic compass ribbon layer.
3 // Written by David Megginson, started January 2000.
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.
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.
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.
22 #include "FGMagRibbon.hxx"
23 #include "../steam.hxx"
26 FGMagRibbon::FGMagRibbon (int w, int h)
27 : FGTexturedLayer(w, h)
29 FGCroppedTexture texture("Aircraft/Instruments/Textures/compass-ribbon.rgb");
36 double heading = globals->get_steam()->get_MH_deg();
37 double xoffset, yoffset;
39 while (heading >= 360.0) {
42 while (heading < 0.0) {
46 if (heading >= 60.0 && heading <= 180.0) {
47 xoffset = heading / 240.0;
49 } else if (heading >= 150.0 && heading <= 270.0) {
50 xoffset = (heading - 90.0) / 240.0;
52 } else if (heading >= 240.0 && heading <= 360.0) {
53 xoffset = (heading - 180.0) / 240.0;
58 xoffset = (heading - 270.0) / 240.0;
62 xoffset = 1.0 - xoffset;
63 // Adjust to put the number in the centre
66 FGCroppedTexture &t = getTexture();
67 t.setCrop(xoffset, yoffset, xoffset + 0.5, yoffset + 0.25);
68 FGTexturedLayer::draw();
71 // end of FGMagRibbon.cxx