1 // Copyright (C) 2012-2019 The VPaint Developers.
2 // See the COPYRIGHT file at the top-level directory of this distribution
3 // and at https://github.com/dalboris/vpaint/blob/master/COPYRIGHT
4 //
5 // Licensed under the Apache License, Version 2.0 (the "License");
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 
17 #ifndef TIME_H
18 #define TIME_H
19 
20 class QTextStream;
21 
22 class Time
23 {
24 public:
25 
26     enum Type {
27         ExactFrame,
28         JustBeforeFrame,
29         JustAfterFrame,
30         FloatTime
31     };
32 
33 
34     Time(); // exact frame 0
35 
36     Time(int f); // exact frame f
37 
38     Time(int f, bool justAfter); // just before or after frame f
39 
40     Time(double t); // floating value, automatically converted to ExactFrame
41                     // if close enough within small threshold
42 
~Time()43     virtual ~Time() {} // make the constructor virtual
44 
type()45     Type type() const { return type_; }
frame()46     int frame() const { return frame_; }
floatTime()47     double floatTime() const { return time_; } // Assume 1 fps, i.e. ExactFrame(5) < FloatTime(5.2) < ExactFrame(6).
48 
49     bool operator<(const Time & other) const;
50     bool operator<=(const Time & other) const;
51     bool operator>(const Time & other) const;
52     bool operator>=(const Time & other) const;
53     bool operator==(const Time & other) const;
54     bool operator!=(const Time & other) const;
55 
56     Time operator+(const Time & other) const;
57     Time operator-(const Time & other) const;
58 
59     // Save and Load
60     virtual void save(QTextStream & out);
61     friend QTextStream & operator<<(QTextStream &, const Time & time);
62     friend QTextStream & operator>>(QTextStream &, Time & time);
63 
64 private:
65     Type type_;
66     int frame_;
67     double time_;
68 };
69 
70 #endif
71