diff options
| author | Carl Hetherington <cth@carlh.net> | 2015-01-14 15:13:48 +0000 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2015-01-14 15:13:48 +0000 |
| commit | 972d33c500c9de02aa007440f665637e455610c1 (patch) | |
| tree | 5956c54b3b97ab10b61fd1383cfd12de15959214 /src/vertical_position.cc | |
| parent | 65244fb9190e6d0aefc83c9cc4de83b1df18001d (diff) | |
Forward-port some stuff from 0.x.
Diffstat (limited to 'src/vertical_position.cc')
| -rw-r--r-- | src/vertical_position.cc | 34 |
1 files changed, 32 insertions, 2 deletions
diff --git a/src/vertical_position.cc b/src/vertical_position.cc index 1fdb1e1..5f7d0d0 100644 --- a/src/vertical_position.cc +++ b/src/vertical_position.cc @@ -21,14 +21,44 @@ 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 { if (proportional && reference && other.proportional && other.reference) { return proportional.get() == other.proportional.get() && reference.get() == other.reference.get(); - } else if (reference && line && other.reference && other.line) { - return line.get() == other.line.get() && reference.get() == other.reference.get(); + } else if (reference && line && lines && other.reference && other.line && other.lines) { + return line.get() == other.line.get() && lines.get() == other.lines.get() && reference.get() == other.reference.get(); } return false; } + +bool +VerticalPosition::operator< (VerticalPosition const & other) const +{ + return fraction_from_screen_top() < other.fraction_from_screen_top(); +} |
