CVS: source/src/GUI MapWidget.cxx, NONE, 1.1 MapWidget.hxx, NONE, 1.1 Makefile.am, 1.25, 1.26 dialog.cxx, 1.124, 1.125

James Turner <[email protected]>
Newsgroups gmane.games.flightgear.cvc
Message-ID <[email protected]>
Update of /var/cvs/FlightGear-0.9/source/src/GUI
In directory baron.flightgear.org:/tmp/cvs-serv24394/src/GUI

Modified Files:
	Makefile.am dialog.cxx 
Added Files:
	MapWidget.cxx MapWidget.hxx 
Log Message:
MapWidget for the GUI, initial commit.


--- NEW FILE "MapWidget.cxx" ---
#ifdef HAVE_CONFIG_H
#  include "config.h"
#endif

#include "MapWidget.hxx"

#include <sstream>
#include <algorithm> // for std::sort
#include <plib/puAux.h>

#include <simgear/route/waypoint.hxx>
#include <simgear/sg_inlines.h>
#include <simgear/misc/strutils.hxx>
#include <simgear/magvar/magvar.hxx>
#include <simgear/timing/sg_time.hxx> // for magVar julianDate
#include <simgear/structure/exception.hxx>

#include <Main/globals.hxx>
#include <Main/fg_props.hxx>
[...1574 lines suppressed...]
  }
  
  it->second->resetAge(); // mark data as valid this frame
  _dataQueue.push_back(it->second);
  return it->second;
}

MapData* MapWidget::createDataForKey(void* key)
{
  KeyDataMap::iterator it = _mapData.find(key);
  if (it != _mapData.end()) {
    throw sg_exception("duplicate data requested for key!");
  }
  
  MapData* d =  new MapData(0);
  _mapData[key] = d;
  _dataQueue.push_back(d);
  d->resetAge();
  return d;
}

--- NEW FILE "MapWidget.hxx" ---
#ifndef GUI_MAPWIDGET_HXX
#define GUI_MAPWIDGET_HXX

#include <simgear/compiler.h>
#include <simgear/math/SGMath.hxx>
#include <simgear/props/props.hxx>

#include <plib/pu.h>

#include "dialog.hxx" // for GUI_ID

// forward decls
class FGRouteMgr;
class FGRunway;
class FGAirport;
class FGNavRecord;
class FGFix;
class MapData;
class SGMagVar;

class MapWidget : public puObject
{
public:
  MapWidget(int x, int y, int width, int height);
  virtual ~MapWidget();
  
  virtual void setSize(int width, int height);
  virtual void doHit( int button, int updown, int x, int y ) ;
  virtual void draw( int dx, int dy ) ;
  virtual int checkKey(int key, int updown);
    
  void setProperty(SGPropertyNode_ptr prop);
private:
  void handlePan(int x, int y);
  
  void pan(const SGVec2d& delta);
  void zoomIn();
  void zoomOut();
  
  void paintAircraftLocation(const SGGeod& aircraftPos);
  void paintRoute();
  void paintRuler();
  
  void drawGPSData();
  void drawNavRadio(SGPropertyNode_ptr radio);
  void drawTunedLocalizer(SGPropertyNode_ptr radio);
  
  void drawLatLonGrid();
  SGVec2d gridPoint(int ix, int iy);
  bool drawLineClipped(const SGVec2d& a, const SGVec2d& b);
  
  void drawAirports();
  void drawAirport(FGAirport* apt);
  int scoreAirportRunways(FGAirport* apt);
  void drawRunwayPre(FGRunway* rwy);
  void drawRunway(FGRunway* rwy);
  void drawILS(bool tuned, FGRunway* rwy);
  
  void drawNavaids();
  void drawNDB(bool tuned, FGNavRecord* nav);
  void drawVOR(bool tuned, FGNavRecord* nav);
  void drawFix(FGFix* fix);
  
  void drawTraffic();
  void drawAIAircraft(const SGPropertyNode* model, const SGGeod& pos, double hdg);
  void drawAIShip(const SGPropertyNode* model, const SGGeod& pos, double hdg);
  
  void drawData();
  bool validDataForKey(void* key);
  MapData* getOrCreateDataForKey(void* key);
  MapData* createDataForKey(void* key);
  void setAnchorForKey(void* key, const SGVec2d& anchor);
  
  SGVec2d project(const SGGeod& geod) const;
  SGGeod unproject(const SGVec2d& p) const;
  double currentScale() const;
  
  void circleAt(const SGVec2d& center, int nSides, double r);
  void circleAtAlt(const SGVec2d& center, int nSides, double r, double r2);
  void drawLine(const SGVec2d& p1, const SGVec2d& p2);
  void drawLegendBox(const SGVec2d& pos, const std::string& t);
  
  int _width, _height;
  int _zoom;
  double _drawRangeNm;
  double _upHeading; // true heading corresponding to +ve y-axis
  bool _magneticHeadings;
  
  SGGeod _projectionCenter;
  SGGeod _aircraft;
  SGGeod _clickGeod;
  SGVec2d _hitLocation;
  FGRouteMgr* _route;
  SGPropertyNode_ptr _root;
  SGPropertyNode_ptr _gps;
  
  typedef std::map<void*, MapData*> KeyDataMap;
  KeyDataMap _mapData;
  std::vector<MapData*> _dataQueue;
  
  SGMagVar* _magVar;
  
  typedef std::map<int, SGVec2d> GridPointCache;
  GridPointCache _gridCache;
  double _gridSpacing;
  SGGeod _gridCenter;
};

#endif // of GUI_MAPWIDGET_HXX

Index: Makefile.am
===================================================================
RCS file: /var/cvs/FlightGear-0.9/source/src/GUI/Makefile.am,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -r1.25 -r1.26
--- Makefile.am	21 Feb 2010 21:56:37 -0000	1.25
+++ Makefile.am	27 Mar 2010 16:57:44 -0000	1.26
@@ -23,7 +23,8 @@
         property_list.cxx property_list.hxx \
         layout.cxx layout-props.cxx layout.hxx \
         SafeTexFont.cxx SafeTexFont.hxx \
-        WaypointList.cxx WaypointList.hxx
+        WaypointList.cxx WaypointList.hxx \
+        MapWidget.cxx MapWidget.hxx
         
 INCLUDES = -I$(top_srcdir) -I$(top_srcdir)/src
 

Index: dialog.cxx
===================================================================
RCS file: /var/cvs/FlightGear-0.9/source/src/GUI/dialog.cxx,v
retrieving revision 1.124
retrieving revision 1.125
diff -u -r1.124 -r1.125
--- dialog.cxx	21 Feb 2010 20:48:50 -0000	1.124
+++ dialog.cxx	27 Mar 2010 17:00:09 -0000	1.125
@@ -14,6 +14,7 @@
 #include "property_list.hxx"
 #include "layout.hxx"
 #include "WaypointList.hxx"
+#include "MapWidget.hxx"
 
 enum format_type { f_INVALID, f_INT, f_LONG, f_FLOAT, f_DOUBLE, f_STRING };
 static const int FORMAT_BUFSIZE = 255;
@@ -815,7 +816,10 @@
         setupObject(obj, props);
         setColor(obj, props);
         return obj;
-
+    } else if (type == "map") {
+        MapWidget* mapWidget = new MapWidget(x, y, x + width, y + height);
+        setupObject(mapWidget, props);
+        return mapWidget;
     } else if (type == "combo") {
         fgComboBox *obj = new fgComboBox(x, y, x + width, y + height, props,
                 props->getBoolValue("editable", false));
@@ -953,12 +957,21 @@
             name = "";
         const char *propname = props->getStringValue("property");
         SGPropertyNode_ptr node = fgGetNode(propname, true);
-        copy_to_pui(node, object);
+        if (type == "map") {
+          // mapWidget binds to a sub-tree of properties, and
+          // ignroes the puValue mechanism, so special case things here
+          MapWidget* mw = static_cast<MapWidget*>(object);
+          mw->setProperty(node);
+        } else {
+            // normal widget, creating PropertyObject
+            copy_to_pui(node, object);
+            PropertyObject *po = new PropertyObject(name, object, node);
+            _propertyObjects.push_back(po);
+            if (props->getBoolValue("live"))
+                _liveObjects.push_back(po);
+        }
+        
 
-        PropertyObject *po = new PropertyObject(name, object, node);
-        _propertyObjects.push_back(po);
-        if (props->getBoolValue("live"))
-            _liveObjects.push_back(po);
     }
 
     SGPropertyNode *dest = fgGetNode("/sim/bindings/gui", true);


------------------------------------------------------------------------------
Download Intel&#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.