~ubuntu-branches/ubuntu/lucid/gnome-subtitles/lucid

« back to all changes in this revision

Viewing changes to sublib-0.8/src/SubLib/Application/Frames.cs

  • Committer: Bazaar Package Importer
  • Author(s): Tiago Bortoletto Vaz
  • Date: 2007-12-03 20:52:52 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20071203205252-2y6uuv4gcw9mi9n5
Tags: 0.7-1
* New upstream release;
* Add libxml-parser-perl to Build-Depends-Indep. Thanks to Lucas Nussbaum.
  (Closes: #445799);
* Fixes manpage issue with dpatch

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * This file is part of SubLib.
 
3
 * Copyright (C) 2005-2006 Pedro Castro
 
4
 *
 
5
 * SubLib is free software; you can redistribute it and/or modify
 
6
 * it under the terms of the GNU General Public License as published by
 
7
 * the Free Software Foundation; either version 2 of the License, or
 
8
 * (at your option) any later version.
 
9
 *
 
10
 * SubLib is distributed in the hope that it will be useful,
 
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 
13
 * GNU General Public License for more details.
 
14
 *
 
15
 * You should have received a copy of the GNU General Public License
 
16
 * along with this program; if not, write to the Free Software
 
17
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
18
 */
 
19
 
 
20
using System;
 
21
 
 
22
namespace SubLib {
 
23
 
 
24
/// <summary>Represents the frames of a subtitle.</summary>
 
25
/// <remarks><see cref="Frames" /> and <see cref="Times" /> always exist for any <see cref="Subtitle" />.
 
26
/// This class is automatically constructed when constructing a <see cref="Subtitle" />.</remarks>
 
27
public class Frames {
 
28
        private double start = 0;
 
29
        private double end = 0;
 
30
        private Subtitle subtitle = null;
 
31
        
 
32
        
 
33
        /// <summary>The start frame.</summary>
 
34
        /// <remarks>Upon setting the start frame, the start time (<see cref="Times.Start">Times.Start</see>) is also updated based on
 
35
        /// the <see cref="SubtitleProperties.CurrentFrameRate" />.</remarks>
 
36
        public int Start {
 
37
                get { return (int)Math.Round(PreciseStart); }
 
38
                set {
 
39
                        PreciseStart = value;
 
40
                        subtitle.UpdateStartTimeFromFrames();
 
41
                }
 
42
        }
 
43
        
 
44
        /// <summary>The end frame.</summary>
 
45
        /// <remarks>Upon setting the end frame, the end time (<see cref="Times.End">Times.End</see>) is also updated based on
 
46
        /// the <see cref="SubtitleProperties.CurrentFrameRate" />.</remarks>
 
47
        public int End {
 
48
                get { return (int)Math.Round(PreciseEnd); }
 
49
                set {
 
50
                        PreciseEnd = value;
 
51
                        subtitle.UpdateEndTimeFromFrames();
 
52
                }
 
53
        }
 
54
        
 
55
        /// <summary>The duration, in frames.</summary>
 
56
        /// <remarks>Setting the duration maintains the start frame and changes the end frame.
 
57
        /// Upon setting the duration, the end time (<see cref="Times.End">Times.End</see>) is also updated based on
 
58
        /// the <see cref="SubtitleProperties.CurrentFrameRate" />.</remarks>
 
59
        public int Duration {
 
60
                get { return End - Start; }     
 
61
                set { End = Start + value; }
 
62
        }
 
63
        
 
64
        /// <summary>Shifts the subtitle with a specified amount of frames.</summary>
 
65
        /// <param name="frames">The number of frames to shift the subtitle with, which can be positive or negative.</param>
 
66
        public void Shift (int frames) {
 
67
                PreciseStart += frames;
 
68
                PreciseEnd += frames;
 
69
                subtitle.UpdateTimesFromFrames();
 
70
        }
 
71
        
 
72
        
 
73
        public override string ToString() {
 
74
                return Start + "->" + End;
 
75
        }
 
76
        
 
77
        /* Internal members */
 
78
                
 
79
        internal Frames (Subtitle subtitle) {
 
80
                this.subtitle = subtitle;
 
81
        }
 
82
        
 
83
        internal Frames (Subtitle subtitle, int start, int end) {
 
84
                this.start = start;
 
85
                this.end = end;
 
86
                this.subtitle = subtitle;       
 
87
        }
 
88
        
 
89
        /// <remarks>Doesn't update times.</remarks>
 
90
        internal double PreciseStart {
 
91
                get { return start; }
 
92
                set { start = value; }
 
93
        }
 
94
        
 
95
        /// <remarks>Doesn't update times.</remarks>
 
96
        internal double PreciseEnd {
 
97
                get { return end; }
 
98
                set { end = value; }
 
99
        }
 
100
        
 
101
        /// <remarks>Doesn't update times.</remarks>
 
102
        internal double PreciseDuration {
 
103
                get { return end - start; }
 
104
                set { end = start + value; }
 
105
        }
 
106
        
 
107
        internal void Scale (double factor, int baseFrame) {    
 
108
                PreciseStart = baseFrame + ((PreciseStart - baseFrame) * factor);
 
109
                PreciseEnd = baseFrame + ((PreciseEnd - baseFrame) * factor);
 
110
                
 
111
                subtitle.UpdateTimesFromFrames();       
 
112
        }
 
113
 
 
114
}
 
115
 
 
116
}