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