Detangle FrameMain and DialogDetachedVideo

Originally committed to SVN as r5530.
This commit is contained in:
Thomas Goyne 2011-07-29 23:16:36 +00:00
parent 3f50ce6d46
commit 65368c5f35
5 changed files with 60 additions and 67 deletions

View File

@ -238,7 +238,13 @@ struct video_detach : public validator_video_loaded {
}
void operator()(agi::Context *c) {
wxGetApp().frame->DetachVideo(!c->detachedVideo);
if (!c->detachedVideo) {
c->detachedVideo = new DialogDetachedVideo(c, c->videoBox->videoDisplay->GetClientSize());
}
else {
c->detachedVideo->Destroy();
c->detachedVideo = 0;
}
}
};

View File

@ -38,39 +38,35 @@
#ifndef AGI_PRE
#include <wx/filename.h>
#include <wx/settings.h>
#include <wx/display.h> /// Must be included last.
#endif
#include "include/aegisub/context.h"
#include "dialog_detached_video.h"
#include "frame_main.h"
#include "include/aegisub/context.h"
#include "include/aegisub/hotkey.h"
#include "main.h"
#include "persist_location.h"
#include "video_box.h"
#include "video_context.h"
#include "video_display.h"
#include "video_slider.h"
/// @brief Constructor
/// @param par FrameMain this was spawned from
/// @param initialDisplaySize Initial size of the window
DialogDetachedVideo::DialogDetachedVideo(FrameMain *parent, agi::Context *context, const wxSize &initialDisplaySize)
: wxDialog(parent,-1,_T("Detached Video"),wxDefaultPosition,wxSize(400,300),wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER | wxMAXIMIZE_BOX | wxMINIMIZE_BOX | wxWANTS_CHARS)
, parent(parent)
DialogDetachedVideo::DialogDetachedVideo(agi::Context *context, const wxSize &initialDisplaySize)
: wxDialog(context->parent, -1, "Detached Video", wxDefaultPosition, wxSize(400,300), wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER | wxMAXIMIZE_BOX | wxMINIMIZE_BOX | wxWANTS_CHARS)
, context(context)
, video_open(context->videoController->AddVideoOpenListener(&DialogDetachedVideo::OnVideoOpen, this))
{
// Set obscure stuff
SetExtraStyle((GetExtraStyle() & ~wxWS_EX_BLOCK_EVENTS) | wxWS_EX_PROCESS_UI_UPDATES);
// Set title
wxFileName fn(context->videoController->videoName);
SetTitle(wxString::Format(_("Video: %s"),fn.GetFullName().c_str()));
SetTitle(wxString::Format(_("Video: %s"), wxFileName(context->videoController->videoName).GetFullName()));
// Set a background panel
wxPanel *panel = new wxPanel(this,-1,wxDefaultPosition,wxDefaultSize,wxTAB_TRAVERSAL | wxCLIP_CHILDREN);
// Video area;
videoBox = new VideoBox(panel, true, context);
VideoBox *videoBox = new VideoBox(panel, true, context);
videoBox->videoDisplay->SetClientSize(initialDisplaySize);
// Set sizer
@ -95,35 +91,23 @@ DialogDetachedVideo::DialogDetachedVideo(FrameMain *parent, agi::Context *contex
}
// Update
parent->SetDisplayMode(0, -1);
OPT_SET("Video/Detached/Enabled")->SetBool(true);
// Copy the main accelerator table to this dialog
wxAcceleratorTable *table = parent->GetAcceleratorTable();
SetAcceleratorTable(*table);
Bind(wxEVT_CLOSE_WINDOW, &DialogDetachedVideo::OnClose, this);
Bind(wxEVT_ICONIZE, &DialogDetachedVideo::OnMinimize, this);
Bind(wxEVT_KEY_DOWN, &DialogDetachedVideo::OnKeyDown, this);
Show();
}
/// @brief Destructor
DialogDetachedVideo::~DialogDetachedVideo() {
}
DialogDetachedVideo::~DialogDetachedVideo() { }
// Event table
BEGIN_EVENT_TABLE(DialogDetachedVideo,wxDialog)
EVT_CLOSE(DialogDetachedVideo::OnClose)
EVT_ICONIZE(DialogDetachedVideo::OnMinimize)
END_EVENT_TABLE()
/// @brief Close window
/// @param event UNUSED
void DialogDetachedVideo::OnClose(wxCloseEvent &WXUNUSED(event)) {
void DialogDetachedVideo::OnClose(wxCloseEvent&) {
context->detachedVideo = 0;
OPT_SET("Video/Detached/Enabled")->SetBool(false);
Destroy();
parent->context->detachedVideo = 0;
parent->SetDisplayMode(1,-1);
}
/// @brief Minimize event handler
/// @param event
void DialogDetachedVideo::OnMinimize(wxIconizeEvent &event) {
if (event.IsIconized()) {
// Force the video display to repaint as otherwise the last displayed
@ -132,3 +116,15 @@ void DialogDetachedVideo::OnMinimize(wxIconizeEvent &event) {
Show();
}
}
void DialogDetachedVideo::OnKeyDown(wxKeyEvent &evt) {
evt.StopPropagation();
hotkey::check("Video Display", evt.GetKeyCode(), evt.GetUnicodeKey(), evt.GetModifiers());
}
void DialogDetachedVideo::OnVideoOpen() {
if (!context->videoController->IsLoaded()) {
context->detachedVideo = 0;
Destroy();
}
}

View File

@ -34,16 +34,14 @@
/// @ingroup main_ui
///
#pragma once
#ifndef AGI_PRE
#include <wx/dialog.h>
#endif
#include <libaegisub/scoped_ptr.h>
#include <libaegisub/signal.h>
namespace agi { struct Context; }
class FrameMain;
class PersistLocation;
class VideoBox;
@ -53,20 +51,21 @@ class VideoBox;
///
/// DOCME
class DialogDetachedVideo : public wxDialog {
agi::Context *context;
agi::signal::Connection video_open;
agi::scoped_ptr<PersistLocation> persist;
/// DOCME
VideoBox *videoBox;
/// DOCME
FrameMain *parent;
void OnClose(wxCloseEvent &event);
void OnMinimize(wxIconizeEvent &event);
void OnClose(wxCloseEvent &);
/// Minimize event handler to hack around a wx bug
void OnMinimize(wxIconizeEvent &evt);
void OnKeyDown(wxKeyEvent &evt);
void OnVideoOpen();
public:
DialogDetachedVideo(FrameMain *parent, agi::Context *context, const wxSize &initialDisplaySize);
/// @brief Constructor
/// @param context Project context
/// @param initialDisplaySize Initial size of the window
DialogDetachedVideo(agi::Context *context, const wxSize &initialDisplaySize);
/// Destructor
~DialogDetachedVideo();
DECLARE_EVENT_TABLE()
};

View File

@ -63,7 +63,6 @@
#endif
#include "compat.h"
#include "command/command.h"
#include "dialog_detached_video.h"
#include "dialog_search_replace.h"
#include "dialog_styling_assistant.h"
#include "dialog_version_check.h"
@ -183,6 +182,7 @@ FrameMain::FrameMain (wxArrayString args)
context->detachedVideo = 0;
context->stylingAssistant = 0;
InitContents();
OPT_SUB("Video/Detached/Enabled", &FrameMain::OnVideoDetach, this, agi::signal::_1);
StartupLog("Complete context initialization");
context->videoController->SetContext(context.get());
@ -224,7 +224,6 @@ FrameMain::FrameMain (wxArrayString args)
FrameMain::~FrameMain () {
context->videoController->SetVideo("");
context->audioController->CloseAudio();
if (context->detachedVideo) context->detachedVideo->Destroy();
if (context->stylingAssistant) context->stylingAssistant->Destroy();
SubsGrid->ClearMaps();
delete audioBox;
@ -440,7 +439,6 @@ void FrameMain::UpdateTitle() {
void FrameMain::OnVideoOpen() {
if (!context->videoController->IsLoaded()) {
SetDisplayMode(0, -1);
DetachVideo(false);
return;
}
@ -481,22 +479,16 @@ void FrameMain::OnVideoOpen() {
SetDisplayMode(1,-1);
DetachVideo(OPT_GET("Video/Detached/Enabled")->GetBool());
if (OPT_GET("Video/Detached/Enabled")->GetBool())
cmd::call("video/detach", context.get());
Thaw();
}
void FrameMain::DetachVideo(bool detach) {
if (detach) {
if (!context->detachedVideo) {
context->detachedVideo = new DialogDetachedVideo(this, context.get(), videoBox->videoDisplay->GetClientSize());
context->detachedVideo->Show();
}
}
else if (context->detachedVideo) {
context->detachedVideo->Destroy();
context->detachedVideo = 0;
SetDisplayMode(1,-1);
}
void FrameMain::OnVideoDetach(agi::OptionValue const& opt) {
if (opt.GetBool())
SetDisplayMode(0, -1);
else if (context->videoController->IsLoaded())
SetDisplayMode(1, -1);
}
void FrameMain::StatusTimeout(wxString text,int ms) {

View File

@ -63,7 +63,7 @@ class VideoDisplay;
class VideoSlider;
class VideoZoomSlider;
namespace agi { struct Context; }
namespace agi { struct Context; class OptionValue; }
namespace Automation4 { class FeatureMacro; class ScriptManager; }
/// DOCME
@ -84,7 +84,6 @@ public:
/// @param audio -1: leave unchanged; 0: hide; 1: show
void SetDisplayMode(int showVid, int showAudio);
void LoadSubtitles(wxString filename,wxString charset="");
void DetachVideo(bool detach=true);
agi::scoped_ptr<agi::Context> context;
@ -139,6 +138,7 @@ private:
void OnAudioClose();
void OnVideoOpen();
void OnVideoDetach(agi::OptionValue const& opt);
void OnSubtitlesOpen();
void OnSubtitlesSave();