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
20 class WaypointList : public puFrame, public GUI_ID
23 WaypointList(int x, int y, int width, int height);
24 virtual ~WaypointList();
26 virtual void setSize(int width, int height);
27 virtual int checkHit ( int button, int updown, int x, int y);
28 virtual void doHit( int button, int updown, int x, int y ) ;
29 virtual void draw( int dx, int dy ) ;
30 virtual int checkKey(int key, int updown);
31 virtual void invokeDownCallback (void);
33 void setSelected(int rowIndex);
37 * Do we want a vertical scrollbar (or similar)
39 bool wantsVScroll() const;
42 * Get scrollbar position as a percentage of total range.
43 * returns negative number if scrolling is not possible
45 float getVScrollPercent() const;
50 void setVScrollPercent(float perc);
53 * Get required thumb size as percentage of total height
55 float getVScrollThumbPercent() const;
57 int numVisibleRows() const;
59 void ensureRowVisible(int row);
61 void setUpdateCallback(SGCallback* cb);
62 void setScrollCallback(SGCallback* cb);
65 * Abstract interface for waypoint source
72 virtual unsigned int numWaypoints() const = 0;
73 virtual int currentWaypoint() const = 0;
74 virtual SGWayPoint waypointAt(unsigned int index) const = 0;
76 // update notifications
77 virtual void setUpdateCallback(SGCallback* cb) = 0;
80 virtual void deleteAt(unsigned int index) = 0;
81 virtual void setWaypointTargetAltitudeFt(unsigned int index, int altFt) = 0;
82 virtual void moveWaypointToIndex(unsigned int srcIndex, unsigned int dstIndex) = 0;
85 void setModel(Model* model);
87 unsigned int numWaypoints() const;
91 void drawRow(int dx, int dy, int rowIndex, int yOrigin);
93 void handleDrag(int x, int y);
94 void doDrop(int x, int y);
98 * Pixel height of a row, including padding
100 int rowHeightPx() const;
103 * model row corresponding to an on-screen y-value
105 int rowForY(int y) const;
108 * reutrn rowheight * total number of rows, i.e the height we'd
109 * need to be to show every row without scrolling
111 int totalHeightPx() const;
114 * Pixel scroll range, based on widget height and number of rows
116 int scrollRangePx() const;
118 int firstVisibleRow() const;
119 int lastVisibleRow() const;
121 int numFullyVisibleRows() const;
122 int firstFullyVisibleRow() const;
123 int lastFullyVisibleRow() const;
125 int wayptAltFtHundreds(int index) const;
127 void modelUpdateCallback();
129 int _scrollPx; // scroll ammount (in pixels)
135 int _mouseDownX, _mouseDownY;
138 SGTimeStamp _dragScrollTime;
142 SGCallback* _updateCallback;
143 SGCallback* _scrollCallback;
146 class ScrolledWaypointList : public puGroup
149 ScrolledWaypointList(int x, int y, int width, int height);
151 virtual void setSize(int width, int height);
153 void setScrollPercent(float v);
155 virtual void setValue(float v);
156 virtual void setValue(int v);
158 void init(int w, int h);
161 void updateWantsScroll(int w, int h);
165 puaScrollBar* _scrollbar;
171 #endif // GUI_WAYPOINT_LIST_HXX