-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathselection.h
39 lines (33 loc) · 905 Bytes
/
selection.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#ifndef SELECTION_H
#define SELECTION_H
class Selection
{
public:
enum State {
EMPTY,
DRAGGING,
DONE
};
Selection() : mState(EMPTY), mStart(0), mEnd(0) {}
inline void setStart(double start) {
mStart = start;
mState = DRAGGING;
}
inline void setEnd(double end) {
mEnd = end;
mState = DRAGGING;
}
inline void setDone() { mState = DONE; }
inline void reset() { mState = EMPTY; }
inline State state() const { return mState; }
inline double start() const { return mStart; }
inline double end() const { return mEnd; }
inline double left() const { return std::min(mStart, mEnd); }
inline double right() const { return std::max(mStart, mEnd); }
inline double length() const { return right() - left(); }
private:
State mState;
double mStart;
double mEnd;
};
#endif // SELECTION_H