]> git.mxchange.org Git - flightgear.git/blob - src/GUI/MapWidget.hxx
Check for and warn about old nVidia drivers.
[flightgear.git] / src / GUI / MapWidget.hxx
1 #ifndef GUI_MAPWIDGET_HXX
2 #define GUI_MAPWIDGET_HXX
3
4 #include <map>
5 #include <simgear/compiler.h>
6 #include <simgear/math/SGMath.hxx>
7 #include <simgear/props/props.hxx>
8
9 #include <Navaids/positioned.hxx>
10 #include <plib/pu.h>
11
12 #include "FGPUIDialog.hxx"
13
14 // forward decls
15 class FGRouteMgr;
16 class FGRunway;
17 class FGHelipad;
18 class FGAirport;
19 class FGNavRecord;
20 class FGFix;
21 class MapData;
22 class SGMagVar;
23
24 typedef std::vector<SGGeod> SGGeodVec;
25
26 class MapWidget : public puObject, public FGPUIDialog::ActiveWidget
27 {
28 public:
29   MapWidget(int x, int y, int width, int height);
30   virtual ~MapWidget();
31   
32     // puObject over-rides
33   virtual void setSize(int width, int height);
34   virtual void doHit( int button, int updown, int x, int y ) ;
35   virtual void draw( int dx, int dy ) ;
36   virtual int checkKey(int key, int updown);
37     
38   void setProperty(SGPropertyNode_ptr prop);
39     
40     // PUIDialog::ActiveWidget over-rides
41     virtual void update();
42     
43 private:
44     enum Projection {
45         PROJECTION_SAMSON_FLAMSTEED,
46         PROJECTION_ORTHO_AZIMUTH,
47         PROJECTION_SPHERICAL
48     };
49     
50   int zoom() const;
51   
52   void handlePan(int x, int y);
53   
54   void pan(const SGVec2d& delta);
55   void zoomIn();
56   void zoomOut();
57   
58   void paintAircraftLocation(const SGGeod& aircraftPos);
59   void paintRoute();
60   void paintRuler();
61   void drawFlightHistory();
62   
63   void drawGPSData();
64   void drawNavRadio(SGPropertyNode_ptr radio);
65   void drawTunedLocalizer(SGPropertyNode_ptr radio);
66   
67   void drawLatLonGrid();
68   SGVec2d gridPoint(int ix, int iy);
69   bool drawLineClipped(const SGVec2d& a, const SGVec2d& b);
70   
71   void drawAirport(FGAirport* apt);
72   int scoreAirportRunways(FGAirport* apt);
73   void drawRunwayPre(FGRunway* rwy);
74   void drawRunway(FGRunway* rwy);
75   void drawHelipad(FGHelipad* hp);
76   void drawILS(bool tuned, FGRunway* rwy);
77   
78   void drawPositioned();
79   void drawNDB(bool tuned, FGNavRecord* nav);
80   void drawVOR(bool tuned, FGNavRecord* nav);
81   void drawFix(FGFix* fix);
82
83   void drawPOI(FGPositioned* rec);
84     
85   void drawTraffic();
86     
87     class DrawAIObject
88     {
89     public:
90         DrawAIObject(SGPropertyNode* model, const SGGeod& g);
91         
92         SGPropertyNode* model;
93         bool boat;
94         SGGeod pos;
95         double heading;
96         int speedKts;
97         std::string label;
98         std::string legend;
99     };
100     
101     typedef std::vector<DrawAIObject> AIDrawVec;
102     AIDrawVec _aiDrawVec;
103     
104     void updateAIObjects();
105     void drawAI(const DrawAIObject& dai);
106   
107   void drawData();
108   bool validDataForKey(void* key);
109   MapData* getOrCreateDataForKey(void* key);
110   MapData* createDataForKey(void* key);
111   void setAnchorForKey(void* key, const SGVec2d& anchor);
112   void clearData();
113   
114   SGVec2d project(const SGGeod& geod) const;
115   SGGeod unproject(const SGVec2d& p) const;
116   double currentScale() const;
117   
118   int displayHeading(double trueHeading) const;
119   
120   void circleAt(const SGVec2d& center, int nSides, double r);
121   void circleAtAlt(const SGVec2d& center, int nSides, double r, double r2);
122   void squareAt(const SGVec2d& center, double r);
123   void drawLine(const SGVec2d& p1, const SGVec2d& p2);
124   void drawLegendBox(const SGVec2d& pos, const std::string& t);
125   
126   int _width, _height;
127   int _cachedZoom;
128   double _drawRangeNm;
129   double _upHeading; // true heading corresponding to +ve y-axis
130   bool _magneticHeadings;
131   bool _hasPanned;
132   bool _aircraftUp;
133   int _displayHeading;
134     
135   SGGeod _projectionCenter;
136   Projection _projection;
137   SGGeod _aircraft;
138   SGGeod _clickGeod;
139   SGVec2d _hitLocation;
140   FGRouteMgr* _route;
141   SGPropertyNode_ptr _root;
142   SGPropertyNode_ptr _gps;
143   SGGeodVec _flightHistoryPath;
144     
145   FGPositionedList _itemsToDraw;
146     
147   typedef std::map<void*, MapData*> KeyDataMap;
148   KeyDataMap _mapData;
149   std::vector<MapData*> _dataQueue;
150   
151   SGMagVar* _magVar;
152   
153   typedef std::map<int, SGVec2d> GridPointCache;
154   GridPointCache _gridCache;
155   double _gridSpacing;
156   SGGeod _gridCenter;
157 };
158
159 #endif // of GUI_MAPWIDGET_HXX