2 * WaypointList.hxx - scrolling list of waypoints, with special formatting
5 #ifndef GUI_WAYPOINT_LIST_HXX
6 #define GUI_WAYPOINT_LIST_HXX
8 #include <simgear/compiler.h>
9 #include <simgear/timing/timestamp.hxx>
13 #include "FGPUIDialog.hxx" // for GUI_ID
20 namespace flightgear {
25 class WaypointList : public puFrame, public GUI_ID
28 WaypointList(int x, int y, int width, int height);
29 virtual ~WaypointList();
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);
38 void setSelected(int rowIndex);
42 * Do we want a vertical scrollbar (or similar)
44 bool wantsVScroll() const;
47 * Get scrollbar position as a percentage of total range.
48 * returns negative number if scrolling is not possible
50 float getVScrollPercent() const;
55 void setVScrollPercent(float perc);
58 * Get required thumb size as percentage of total height
60 float getVScrollThumbPercent() const;
62 int numVisibleRows() const;
64 void ensureRowVisible(int row);
66 void setUpdateCallback(SGCallback* cb);
67 void setScrollCallback(SGCallback* cb);
70 * Abstract interface for waypoint source
77 virtual unsigned int numWaypoints() const = 0;
78 virtual int currentWaypoint() const = 0;
79 virtual flightgear::Waypt* waypointAt(unsigned int index) const = 0;
81 virtual flightgear::FlightPlan* flightplan() const = 0;
83 // update notifications
84 virtual void setUpdateCallback(SGCallback* cb) = 0;
87 virtual void deleteAt(unsigned int index) = 0;
88 virtual void moveWaypointToIndex(unsigned int srcIndex, unsigned int dstIndex) = 0;
91 void setModel(Model* model);
93 unsigned int numWaypoints() const;
97 void drawRow(int dx, int dy, int rowIndex, int yOrigin, const RoutePath& path);
99 void handleDrag(int x, int y);
100 void doDrop(int x, int y);
104 * Pixel height of a row, including padding
106 int rowHeightPx() const;
109 * model row corresponding to an on-screen y-value
111 int rowForY(int y) const;
114 * reutrn rowheight * total number of rows, i.e the height we'd
115 * need to be to show every row without scrolling
117 int totalHeightPx() const;
120 * Pixel scroll range, based on widget height and number of rows
122 int scrollRangePx() const;
124 int firstVisibleRow() const;
125 int lastVisibleRow() const;
127 int numFullyVisibleRows() const;
128 int firstFullyVisibleRow() const;
129 int lastFullyVisibleRow() const;
131 void modelUpdateCallback();
133 int _scrollPx; // scroll ammount (in pixels)
139 int _mouseDownX, _mouseDownY;
142 SGTimeStamp _dragScrollTime;
146 SGCallback* _updateCallback;
147 SGCallback* _scrollCallback;
149 SGTimeStamp _blinkTimer;
154 class ScrolledWaypointList : public puGroup
157 ScrolledWaypointList(int x, int y, int width, int height);
159 virtual void setSize(int width, int height);
161 void setScrollPercent(float v);
163 virtual void setValue(float v);
164 virtual void setValue(int v);
166 void init(int w, int h);
169 void updateWantsScroll(int w, int h);
173 puaScrollBar* _scrollbar;
179 #endif // GUI_WAYPOINT_LIST_HXX