]> git.mxchange.org Git - flightgear.git/blob - src/GUI/WaypointList.hxx
Merge branch 'jmt/acinclude' into next
[flightgear.git] / src / GUI / WaypointList.hxx
1 /**
2  * WaypointList.hxx - scrolling list of waypoints, with special formatting
3  */
4
5 #ifndef GUI_WAYPOINT_LIST_HXX
6 #define GUI_WAYPOINT_LIST_HXX
7
8 #include <simgear/compiler.h>
9 #include <simgear/timing/timestamp.hxx>
10
11 #include <plib/pu.h>
12
13 #include "dialog.hxx" // for GUI_ID
14
15 // forward decls
16 class puaScrollBar;
17 class SGWayPoint;
18 class SGCallback;
19
20 class WaypointList : public puFrame, public GUI_ID
21 {
22 public:
23   WaypointList(int x, int y, int width, int height);
24   virtual ~WaypointList();
25
26   virtual void setSize(int width, int height);
27   virtual int checkHit ( int button, int updown, int x, int y);
28   virtual void doHit( int button, int updown, int x, int y ) ;
29   virtual void draw( int dx, int dy ) ;
30   virtual int checkKey(int key, int updown);
31   virtual void invokeDownCallback (void);
32   
33   void setSelected(int rowIndex);
34   int getSelected();
35   
36   /**
37    * Do we want a vertical scrollbar (or similar)
38    */
39   bool wantsVScroll() const;
40   
41   /**
42    * Get scrollbar position as a percentage of total range.
43    * returns negative number if scrolling is not possible
44    */
45   float getVScrollPercent() const;
46   
47   /**
48    *
49    */
50   void setVScrollPercent(float perc);
51   
52   /**
53    * Get required thumb size as percentage of total height
54    */
55   float getVScrollThumbPercent() const;
56   
57   int numVisibleRows() const;
58   
59   void ensureRowVisible(int row);
60   
61   void setUpdateCallback(SGCallback* cb);
62   void setScrollCallback(SGCallback* cb);
63   
64   /**
65    * Abstract interface for waypoint source
66    */
67   class Model
68   {
69   public:
70     virtual ~Model() { }
71     
72     virtual unsigned int numWaypoints() const = 0;
73     virtual int currentWaypoint() const = 0;
74     virtual SGWayPoint waypointAt(unsigned int index) const = 0;
75   
76   // update notifications
77     virtual void setUpdateCallback(SGCallback* cb) = 0;
78   
79   // editing operations
80     virtual void deleteAt(unsigned int index) = 0;
81     virtual void setWaypointTargetAltitudeFt(unsigned int index, int altFt) = 0;
82     virtual void moveWaypointToIndex(unsigned int srcIndex, unsigned int dstIndex) = 0;
83   };
84   
85   void setModel(Model* model);
86   
87   unsigned int numWaypoints() const;
88 protected:
89
90 private:
91   void drawRow(int dx, int dy, int rowIndex, int yOrigin);
92
93   void handleDrag(int x, int y);
94   void doDrop(int x, int y);
95   void doDragScroll();
96   
97   /**
98    * Pixel height of a row, including padding
99    */
100   int rowHeightPx() const;
101   
102   /**
103    * model row corresponding to an on-screen y-value
104    */
105   int rowForY(int y) const;
106   
107   /**
108    * reutrn rowheight * total number of rows, i.e the height we'd
109    * need to be to show every row without scrolling
110    */
111   int totalHeightPx() const;
112   
113   /**
114    * Pixel scroll range, based on widget height and number of rows
115    */
116   int scrollRangePx() const;
117   
118   int firstVisibleRow() const;
119   int lastVisibleRow() const;
120
121   int numFullyVisibleRows() const;
122   int firstFullyVisibleRow() const;
123   int lastFullyVisibleRow() const;
124   
125   int wayptAltFtHundreds(int index) const;
126   
127   void modelUpdateCallback();
128   
129   int _scrollPx; // scroll ammount (in pixels)
130   int _heightPx;
131   
132   bool _dragging;
133   int _dragSourceRow;
134   int _dragTargetRow;
135   int _mouseDownX, _mouseDownY;
136   
137   int _dragScroll;
138   SGTimeStamp _dragScrollTime;
139
140   bool _showLatLon;
141   Model* _model;
142   SGCallback* _updateCallback;
143   SGCallback* _scrollCallback;
144 };
145
146 class ScrolledWaypointList : public puGroup
147 {
148 public:
149   ScrolledWaypointList(int x, int y, int width, int height);
150   
151   virtual void setSize(int width, int height);
152   
153   void setScrollPercent(float v);
154   
155   virtual void setValue(float v);
156   virtual void setValue(int v);
157 private:  
158   void init(int w, int h);
159   
160   void updateScroll();
161   void updateWantsScroll(int w, int h);
162   
163   void modelUpdated();
164   
165   puaScrollBar* _scrollbar;
166   WaypointList* _list;
167   int _scrollWidth;
168   bool _hasVScroll;
169 };
170
171 #endif // GUI_WAYPOINT_LIST_HXX