Debian Codegraph @

src/GUI/WaypointList.hxx

raw symbols SCIP
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 #include <simgear/misc/strutils.hxx>
11 #include <simgear/structure/callback.hxx>
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(simgear::Callback cb);
67 void setScrollCallback(simgear::Callback 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(simgear::Callback 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 void drawRowText(int x, int baseline, int rowIndex, const RoutePath &path);
99
100 void handleDrag(int x, int y);
101 void doDrop(int x, int y);
102 void doDragScroll();
103
104 /**
105 * Pixel height of a row, including padding
106 */
107 int rowHeightPx() const;
108
109 /**
110 * model row corresponding to an on-screen y-value
111 */
112 int rowForY(int y) const;
113
114 /**
115 * reutrn rowheight * total number of rows, i.e the height we'd
116 * need to be to show every row without scrolling
117 */
118 int totalHeightPx() const;
119
120 /**
121 * Pixel scroll range, based on widget height and number of rows
122 */
123 int scrollRangePx() const;
124
125 int firstVisibleRow() const;
126 int lastVisibleRow() const;
127
128 int numFullyVisibleRows() const;
129 int firstFullyVisibleRow() const;
130 int lastFullyVisibleRow() const;
131
132 void modelUpdateCallback();
133
134 int _scrollPx; // scroll ammount (in pixels)
135 int _heightPx;
136
137 bool _dragging;
138 int _dragSourceRow;
139 int _dragTargetRow;
140 int _mouseDownX, _mouseDownY;
141
142 int _dragScroll;
143 SGTimeStamp _dragScrollTime;
144
145 bool _showLatLon;
146 Model* _model;
147 simgear::Callback _updateCallback;
148 simgear::Callback _scrollCallback;
149
150 SGTimeStamp _blinkTimer;
151 bool _blink;
152 int _arrowWidth;
153
154 // cached value from /sim/lon-lat-format
155 simgear::strutils::LatLonFormat _latLonFormat = simgear::strutils::LatLonFormat::DECIMAL_DEGREES;
156 };
157
158 class ScrolledWaypointList : public puGroup
159 {
160 public:
161 ScrolledWaypointList(int x, int y, int width, int height);
162
163 virtual void setSize(int width, int height);
164
165 void setScrollPercent(float v);
166
167 virtual void setValue(float v);
168 virtual void setValue(int v);
169 private:
170 void init(int w, int h);
171
172 void updateScroll();
173 void updateWantsScroll(int w, int h);
174
175 void modelUpdated();
176
177 puaScrollBar* _scrollbar;
178 WaypointList* _list;
179 int _scrollWidth;
180 bool _hasVScroll;
181 };
182
183 #endif // GUI_WAYPOINT_LIST_HXX