From 8d968e4dd5ad1fc52bc227d883c02e895e6fe13b Mon Sep 17 00:00:00 2001 From: Thomas Goyne Date: Sun, 23 Jan 2011 07:48:07 +0000 Subject: [PATCH] Move the code for updating the time/frame display boxes from VideoDisplay to VideoBox Originally committed to SVN as r5266. --- aegisub/src/base_grid.cpp | 1 - aegisub/src/dialog_timing_processor.cpp | 1 - aegisub/src/video_box.cpp | 51 ++++++++++++++++++++++-- aegisub/src/video_box.h | 25 ++++++------ aegisub/src/video_context.cpp | 1 - aegisub/src/video_display.cpp | 52 ------------------------- aegisub/src/video_display.h | 14 +------ 7 files changed, 61 insertions(+), 84 deletions(-) diff --git a/aegisub/src/base_grid.cpp b/aegisub/src/base_grid.cpp index 34e0843fa..7c79dd1fc 100644 --- a/aegisub/src/base_grid.cpp +++ b/aegisub/src/base_grid.cpp @@ -60,7 +60,6 @@ #include "main.h" #include "subs_edit_box.h" #include "utils.h" -#include "video_box.h" #include "video_context.h" #include "video_slider.h" diff --git a/aegisub/src/dialog_timing_processor.cpp b/aegisub/src/dialog_timing_processor.cpp index ca553ebac..840d2a89b 100644 --- a/aegisub/src/dialog_timing_processor.cpp +++ b/aegisub/src/dialog_timing_processor.cpp @@ -52,7 +52,6 @@ #include "subs_grid.h" #include "utils.h" #include "validators.h" -#include "video_box.h" #include "video_context.h" #include "video_display.h" diff --git a/aegisub/src/video_box.cpp b/aegisub/src/video_box.cpp index b53a19a47..f4d2e67a0 100644 --- a/aegisub/src/video_box.cpp +++ b/aegisub/src/video_box.cpp @@ -45,7 +45,10 @@ #include "include/aegisub/context.h" +#include "ass_dialogue.h" +#include "ass_file.h" #include "command/command.h" +#include "compat.h" #include "help_button.h" #include "libresrc/libresrc.h" #include "main.h" @@ -118,7 +121,7 @@ VideoBox::VideoBox(wxWindow *parent, bool isDetached, wxComboBox *zoomBox, agi:: visualToolBar->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE)); // Display - videoDisplay = new VideoDisplay(this,isDetached,VideoPosition,VideoSubsPos,zoomBox,this,context); + videoDisplay = new VideoDisplay(this,isDetached,zoomBox,this,context); // Top sizer // Detached and attached video needs different flags, see bugs #742 and #853 @@ -133,14 +136,14 @@ VideoBox::VideoBox(wxWindow *parent, bool isDetached, wxComboBox *zoomBox, agi:: topSizer->Add(new wxStaticLine(this),0,wxEXPAND,0); // Sizers - videoSliderSizer = new wxBoxSizer(wxHORIZONTAL); + wxSizer *videoSliderSizer = new wxBoxSizer(wxHORIZONTAL); videoSliderSizer->Add(videoSlider,1,wxEXPAND|wxLEFT,0); videoBottomSizer->Add(VideoPosition,1,wxLEFT|wxALIGN_CENTER,5); videoBottomSizer->Add(VideoSubsPos,1,wxALIGN_CENTER,0); // If we're detached we do want to fill out as much space we can. // But if we're in the main window, the subs grid needs space more than us. - VideoSizer = new wxBoxSizer(wxVERTICAL); + wxSizer *VideoSizer = new wxBoxSizer(wxVERTICAL); VideoSizer->Add(topSizer,isDetached?1:0,wxEXPAND,0); VideoSizer->Add(videoSliderSizer,0,wxEXPAND,0); VideoSizer->Add(videoBottomSizer,0,wxEXPAND,0); @@ -150,6 +153,12 @@ VideoBox::VideoBox(wxWindow *parent, bool isDetached, wxComboBox *zoomBox, agi:: Bind(wxEVT_COMMAND_BUTTON_CLICKED, &VideoBox::OnButton, this); Bind(wxEVT_COMMAND_TOGGLEBUTTON_CLICKED, &VideoBox::OnButton, this); + + slots.push_back(context->videoController->AddSeekListener(&VideoBox::UpdateTimeBoxes, this)); + slots.push_back(context->videoController->AddKeyframesListener(&VideoBox::UpdateTimeBoxes, this)); + slots.push_back(context->videoController->AddTimecodesListener(&VideoBox::UpdateTimeBoxes, this)); + slots.push_back(context->videoController->AddVideoOpenListener(&VideoBox::UpdateTimeBoxes, this)); + slots.push_back(context->ass->AddCommitListener(&VideoBox::UpdateTimeBoxes, this)); } void VideoBox::OnButton(wxCommandEvent &evt) { @@ -164,3 +173,39 @@ void VideoBox::OnButton(wxCommandEvent &evt) { #endif cmd::call(context, evt.GetId()); } + +void VideoBox::UpdateTimeBoxes() { + if (!context->videoController->IsLoaded()) return; + + int frame = context->videoController->GetFrameN(); + int time = context->videoController->TimeAtFrame(frame, agi::vfr::EXACT); + + int h = time / 3600000; + int m = time % 3600000 / 60000; + int s = time % 60000 / 1000; + int ms = time % 1000; + + // Set the text box for frame number and time + VideoPosition->SetValue(wxString::Format("%01i:%02i:%02i.%03i - %i", h, m, s, ms, frame)); + if (binary_search(context->videoController->GetKeyFrames().begin(), context->videoController->GetKeyFrames().end(), frame)) { + // Set the background color to indicate this is a keyframe + VideoPosition->SetBackgroundColour(lagi_wxColour(OPT_GET("Colour/Subtitle Grid/Background/Selection")->GetColour())); + VideoPosition->SetForegroundColour(lagi_wxColour(OPT_GET("Colour/Subtitle Grid/Selection")->GetColour())); + } + else { + VideoPosition->SetBackgroundColour(wxNullColour); + VideoPosition->SetForegroundColour(wxNullColour); + } + + AssDialogue *active_line = context->selectionController->GetActiveLine(); + if (!active_line) { + VideoSubsPos->SetValue(""); + } + else { + VideoSubsPos->SetValue(wxString::Format( + "%+dms; %+dms", + time - active_line->Start.GetMS(), + time - active_line->End.GetMS())); + } + +} diff --git a/aegisub/src/video_box.h b/aegisub/src/video_box.h index 2ff156dcc..736adfba6 100644 --- a/aegisub/src/video_box.h +++ b/aegisub/src/video_box.h @@ -37,6 +37,8 @@ #pragma once #ifndef AGI_PRE +#include + #include #include #include @@ -44,6 +46,8 @@ #include #endif +#include + namespace agi { struct Context; } class ToggleBitmap; class VideoDisplay; @@ -56,9 +60,16 @@ class wxComboBox; /// /// DOCME class VideoBox : public wxPanel { - agi::Context *context; + std::list slots; + agi::Context *context; ///< Project context + wxTextCtrl *VideoPosition; ///< Current frame/time + wxTextCtrl *VideoSubsPos; ///< Time relative to the active subtitle line + /// Handle a click on the play/pause buttons void OnButton(wxCommandEvent &evt); + + /// Update VideoPosition and VideoSubsPos + void UpdateTimeBoxes(); public: /// DOCME @@ -67,18 +78,6 @@ public: /// DOCME wxToolBar *visualSubToolBar; - /// DOCME - wxBoxSizer *VideoSizer; - - /// DOCME - wxBoxSizer *videoSliderSizer; - - /// DOCME - wxTextCtrl *VideoPosition; - - /// DOCME - wxTextCtrl *VideoSubsPos; - /// DOCME VideoDisplay *videoDisplay; diff --git a/aegisub/src/video_context.cpp b/aegisub/src/video_context.cpp index a4ca450e5..f18f334ea 100644 --- a/aegisub/src/video_context.cpp +++ b/aegisub/src/video_context.cpp @@ -74,7 +74,6 @@ #include "subs_edit_box.h" #include "threaded_frame_source.h" #include "utils.h" -#include "video_box.h" #include "video_context.h" #include "video_frame.h" diff --git a/aegisub/src/video_display.cpp b/aegisub/src/video_display.cpp index 62747c9d3..7ae266a15 100644 --- a/aegisub/src/video_display.cpp +++ b/aegisub/src/video_display.cpp @@ -62,7 +62,6 @@ #include "video_display.h" #include "selection_controller.h" -#include "ass_dialogue.h" #include "ass_file.h" #include "main.h" #include "subs_grid.h" @@ -125,8 +124,6 @@ public: VideoDisplay::VideoDisplay( VideoBox *box, bool freeSize, - wxTextCtrl *PositionDisplay, - wxTextCtrl *SubsPosition, wxComboBox *zoomBox, wxWindow* parent, agi::Context *c) @@ -136,8 +133,6 @@ VideoDisplay::VideoDisplay( , currentFrame(-1) , w(8), h(8), viewport_x(0), viewport_width(0), viewport_bottom(0), viewport_top(0), viewport_height(0) , zoomValue(OPT_GET("Video/Default Zoom")->GetInt() * .125 + .125) -, SubsPosition(SubsPosition) -, PositionDisplay(PositionDisplay) , videoOut(new VideoOutGL()) , activeMode(Video_Mode_Standard) , toolBar(box->visualSubToolBar) @@ -189,52 +184,9 @@ void VideoDisplay::ShowCursor(bool show) { } } -void VideoDisplay::UpdateRelativeTimes(int time) { - wxString startSign; - wxString endSign; - int startOff = 0; - int endOff = 0; - - if (AssDialogue *curLine = con->selectionController->GetActiveLine()) { - startOff = time - curLine->Start.GetMS(); - endOff = time - curLine->End.GetMS(); - } - - // Positive signs - if (startOff > 0) startSign = L"+"; - if (endOff > 0) endSign = L"+"; - - // Set the text box for time relative to active subtitle line - SubsPosition->SetValue(wxString::Format(L"%s%ims; %s%ims", startSign.c_str(), startOff, endSign.c_str(), endOff)); -} - - void VideoDisplay::SetFrame(int frameNumber) { currentFrame = frameNumber; - // Get time for frame - { - int time = con->videoController->TimeAtFrame(frameNumber, agi::vfr::EXACT); - int h = time / 3600000; - int m = time % 3600000 / 60000; - int s = time % 60000 / 1000; - int ms = time % 1000; - - // Set the text box for frame number and time - PositionDisplay->SetValue(wxString::Format(L"%01i:%02i:%02i.%03i - %i", h, m, s, ms, frameNumber)); - if (std::binary_search(con->videoController->GetKeyFrames().begin(), con->videoController->GetKeyFrames().end(), frameNumber)) { - // Set the background color to indicate this is a keyframe - PositionDisplay->SetBackgroundColour(lagi_wxColour(OPT_GET("Colour/Subtitle Grid/Background/Selection")->GetColour())); - PositionDisplay->SetForegroundColour(lagi_wxColour(OPT_GET("Colour/Subtitle Grid/Selection")->GetColour())); - } - else { - PositionDisplay->SetBackgroundColour(wxNullColour); - PositionDisplay->SetForegroundColour(wxNullColour); - } - - UpdateRelativeTimes(time); - } - // Render the new frame if (con->videoController->IsLoaded()) { tool->SetFrame(frameNumber); @@ -277,7 +229,6 @@ void VideoDisplay::OnCommit(int type) { if (type == AssFile::COMMIT_FULL || type == AssFile::COMMIT_UNDO) con->videoController->GetScriptSize(scriptW, scriptH); if (tool.get()) tool->Refresh(); - UpdateRelativeTimes(con->videoController->TimeAtFrame(currentFrame, agi::vfr::EXACT)); } void VideoDisplay::Render() try { @@ -536,9 +487,6 @@ void VideoDisplay::SetZoomFromBox() { UpdateSize(); } } -double VideoDisplay::GetZoom() const { - return zoomValue; -} template void VideoDisplay::SetTool() { diff --git a/aegisub/src/video_display.h b/aegisub/src/video_display.h index 203a94b3d..81d98dfa3 100644 --- a/aegisub/src/video_display.h +++ b/aegisub/src/video_display.h @@ -131,12 +131,6 @@ class VideoDisplay : public wxGLCanvas { /// The current zoom level, where 1.0 = 100% double zoomValue; - /// The display for the the video position relative to the current subtitle line - wxTextCtrl *SubsPosition; - - /// The display for the absolute time of the video position - wxTextCtrl *PositionDisplay; - /// The video renderer std::auto_ptr videoOut; @@ -154,10 +148,6 @@ class VideoDisplay : public wxGLCanvas { /// @return Could the context be set? bool InitContext(); - /// @brief Update the time relative to current subtitle line box - /// @param time Currently displayed frame's time - void UpdateRelativeTimes(int time); - /// @brief Set this video display to the given frame /// @frameNumber The desired frame number void SetFrame(int frameNumber); @@ -197,8 +187,6 @@ public: VideoDisplay( VideoBox *box, bool isDetached, - wxTextCtrl *PositionDisplay, - wxTextCtrl *SubsPosition, wxComboBox *zoomBox, wxWindow* parent, agi::Context *context); @@ -213,7 +201,7 @@ public: /// @brief Set the zoom level to that indicated by the dropdown void SetZoomFromBox(); /// @brief Get the current zoom level - double GetZoom() const; + double GetZoom() const { return zoomValue; } /// @brief Convert a point from screen to script coordinate frame /// @param x x coordinate; in/out