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 "dialog.hxx" // for GUI_ID
19 namespace flightgear {
23 class WaypointList : public puFrame, public GUI_ID
26 WaypointList(int x, int y, int width, int height);
27 virtual ~WaypointList();
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);
36 void setSelected(int rowIndex);
40 * Do we want a vertical scrollbar (or similar)
42 bool wantsVScroll() const;
45 * Get scrollbar position as a percentage of total range.
46 * returns negative number if scrolling is not possible
48 float getVScrollPercent() const;
53 void setVScrollPercent(float perc);
56 * Get required thumb size as percentage of total height
58 float getVScrollThumbPercent() const;
60 int numVisibleRows() const;
62 void ensureRowVisible(int row);
64 void setUpdateCallback(SGCallback* cb);
65 void setScrollCallback(SGCallback* cb);
68 * Abstract interface for waypoint source
75 virtual unsigned int numWaypoints() const = 0;
76 virtual int currentWaypoint() const = 0;
77 virtual flightgear::Waypt* waypointAt(unsigned int index) const = 0;
79 // update notifications
80 virtual void setUpdateCallback(SGCallback* cb) = 0;
83 virtual void deleteAt(unsigned int index) = 0;
84 virtual void moveWaypointToIndex(unsigned int srcIndex, unsigned int dstIndex) = 0;
87 void setModel(Model* model);
89 unsigned int numWaypoints() const;
93 void drawRow(int dx, int dy, int rowIndex, int yOrigin);
95 void handleDrag(int x, int y);
96 void doDrop(int x, int y);
100 * Pixel height of a row, including padding
102 int rowHeightPx() const;
105 * model row corresponding to an on-screen y-value
107 int rowForY(int y) const;
110 * reutrn rowheight * total number of rows, i.e the height we'd
111 * need to be to show every row without scrolling
113 int totalHeightPx() const;
116 * Pixel scroll range, based on widget height and number of rows
118 int scrollRangePx() const;
120 int firstVisibleRow() const;
121 int lastVisibleRow() const;
123 int numFullyVisibleRows() const;
124 int firstFullyVisibleRow() const;
125 int lastFullyVisibleRow() const;
127 void modelUpdateCallback();
129 int _scrollPx; // scroll ammount (in pixels)
135 int _mouseDownX, _mouseDownY;
138 SGTimeStamp _dragScrollTime;
142 SGCallback* _updateCallback;
143 SGCallback* _scrollCallback;
145 SGTimeStamp _blinkTimer;
150 class ScrolledWaypointList : public puGroup
153 ScrolledWaypointList(int x, int y, int width, int height);
155 virtual void setSize(int width, int height);
157 void setScrollPercent(float v);
159 virtual void setValue(float v);
160 virtual void setValue(int v);
162 void init(int w, int h);
165 void updateWantsScroll(int w, int h);
169 puaScrollBar* _scrollbar;
175 #endif // GUI_WAYPOINT_LIST_HXX