diff options
| author | Carl Hetherington <cth@carlh.net> | 2015-01-07 23:16:41 +0000 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2015-01-07 23:16:41 +0000 |
| commit | 9361d68621cc45bc8a13c9eebe7fee1b405a3e0e (patch) | |
| tree | 1db488e441bf7e6c5968354081b5d83cf6af3205 /src | |
| parent | 74765c0660239f48702ebc6d149d522b85392b63 (diff) | |
Add operator< for VerticalPosition.
Diffstat (limited to 'src')
| -rw-r--r-- | src/vertical_position.cc | 31 | ||||
| -rw-r--r-- | src/vertical_position.h | 3 |
2 files changed, 34 insertions, 0 deletions
diff --git a/src/vertical_position.cc b/src/vertical_position.cc index cdf0b6c..37930d0 100644 --- a/src/vertical_position.cc +++ b/src/vertical_position.cc @@ -21,6 +21,29 @@ using namespace sub; +float +VerticalPosition::fraction_from_screen_top () const +{ + if (!reference || (!proportional && !line)) { + return 0; + } + + float const prop = proportional ? proportional.get() : (float (line.get()) / lines.get ()); + + switch (reference.get ()) { + case TOP_OF_SCREEN: + return prop; + case CENTRE_OF_SCREEN: + return prop + 0.5; + case BOTTOM_OF_SCREEN: + return 1 - prop; + case TOP_OF_SUBTITLE: + return prop; + } + + return 0; +} + bool VerticalPosition::operator== (VerticalPosition const & other) const { @@ -32,3 +55,11 @@ VerticalPosition::operator== (VerticalPosition const & other) const return false; } + +bool +VerticalPosition::operator< (VerticalPosition const & other) const +{ + return fraction_from_screen_top() < other.fraction_from_screen_top(); +} + + diff --git a/src/vertical_position.h b/src/vertical_position.h index 77b0675..9f04056 100644 --- a/src/vertical_position.h +++ b/src/vertical_position.h @@ -41,6 +41,9 @@ public: boost::optional<VerticalReference> reference; bool operator== (VerticalPosition const & other) const; + bool operator< (VerticalPosition const & other) const; + + float fraction_from_screen_top () const; }; } |
