Make the duration field not completely wrong in frame mode

This commit is contained in:
Thomas Goyne 2014-04-15 08:41:58 -07:00
parent 780c93ed4d
commit 3528e49286
2 changed files with 20 additions and 7 deletions

View File

@ -313,7 +313,7 @@ void SubsEditBox::OnCommit(int type) {
if (type & AssFile::COMMIT_DIAG_TIME) {
start_time->SetTime(line->Start);
end_time->SetTime(line->End);
duration->SetTime(line->End - line->Start);
SetDurationField();
}
if (type & AssFile::COMMIT_DIAG_TEXT) {
@ -468,7 +468,7 @@ void SubsEditBox::CommitTimes(TimeField field) {
case TIME_DURATION:
if (by_frame->GetValue())
d->End = c->videoController->TimeAtFrame(c->videoController->FrameAtTime(d->Start, agi::vfr::START) + duration->GetFrame(), agi::vfr::END);
d->End = c->videoController->TimeAtFrame(c->videoController->FrameAtTime(d->Start, agi::vfr::START) + duration->GetFrame() - 1, agi::vfr::END);
else
d->End = d->Start + duration->GetTime();
initial_times[d].second = d->End;
@ -479,10 +479,8 @@ void SubsEditBox::CommitTimes(TimeField field) {
start_time->SetTime(line->Start);
end_time->SetTime(line->End);
if (by_frame->GetValue())
duration->SetFrame(end_time->GetFrame() - start_time->GetFrame() + 1);
else
duration->SetTime(end_time->GetTime() - start_time->GetTime());
if (field != TIME_DURATION)
SetDurationField();
if (field != last_time_commit_type)
commit_id = -1;
@ -493,6 +491,16 @@ void SubsEditBox::CommitTimes(TimeField field) {
file_changed_slot.Unblock();
}
void SubsEditBox::SetDurationField() {
// With VFR, the frame count calculated from the duration in time can be
// completely wrong (since the duration is calculated as if it were a start
// time), so we need to explicitly set it with the correct units.
if (by_frame->GetValue())
duration->SetFrame(end_time->GetFrame() - start_time->GetFrame() + 1);
else
duration->SetTime(end_time->GetTime() - start_time->GetTime());
}
void SubsEditBox::OnSize(wxSizeEvent &evt) {
int availableWidth = GetVirtualSize().GetWidth();
int midMin = middle_left_sizer->GetMinSize().GetWidth();
@ -517,12 +525,15 @@ void SubsEditBox::OnSize(wxSizeEvent &evt) {
}
void SubsEditBox::OnFrameTimeRadio(wxCommandEvent &event) {
event.Skip();
bool byFrame = by_frame->GetValue();
start_time->SetByFrame(byFrame);
end_time->SetByFrame(byFrame);
duration->SetByFrame(byFrame);
c->subsGrid->SetByFrame(byFrame);
event.Skip();
SetDurationField();
}
void SubsEditBox::SetControlsState(bool state) {

View File

@ -195,6 +195,8 @@ class SubsEditBox final : public wxPanel {
/// Call a command the restore focus to the edit box
void CallCommand(const char *cmd_name);
void SetDurationField();
SubsTextEditCtrl *edit_ctrl;
wxTextCtrl *secondary_editor;
std::unique_ptr<TextSelectionController> textSelectionController;