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