2007-01-23 05:42:08 +01:00
|
|
|
// Copyright (c) 2007, Rodrigo Braz Monteiro
|
2006-04-15 00:37:05 +02:00
|
|
|
// All rights reserved.
|
|
|
|
//
|
|
|
|
// Redistribution and use in source and binary forms, with or without
|
|
|
|
// modification, are permitted provided that the following conditions are met:
|
|
|
|
//
|
|
|
|
// * Redistributions of source code must retain the above copyright notice,
|
|
|
|
// this list of conditions and the following disclaimer.
|
|
|
|
// * Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
// this list of conditions and the following disclaimer in the documentation
|
|
|
|
// and/or other materials provided with the distribution.
|
|
|
|
// * Neither the name of the Aegisub Group nor the names of its contributors
|
|
|
|
// may be used to endorse or promote products derived from this software
|
|
|
|
// without specific prior written permission.
|
|
|
|
//
|
|
|
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
|
|
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
|
|
|
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
// POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
//
|
2009-07-29 07:43:02 +02:00
|
|
|
// Aegisub Project http://www.aegisub.org/
|
|
|
|
|
|
|
|
/// @file dialog_detached_video.cpp
|
|
|
|
/// @brief Detached video window
|
|
|
|
/// @ingroup main_ui
|
|
|
|
///
|
2006-04-15 00:37:05 +02:00
|
|
|
|
2007-01-23 05:42:08 +01:00
|
|
|
#include "dialog_detached_video.h"
|
2011-07-30 01:16:36 +02:00
|
|
|
|
2014-05-29 17:28:37 +02:00
|
|
|
#include "format.h"
|
2011-07-30 01:16:36 +02:00
|
|
|
#include "include/aegisub/context.h"
|
|
|
|
#include "include/aegisub/hotkey.h"
|
2013-01-07 02:50:09 +01:00
|
|
|
#include "options.h"
|
2011-07-27 07:36:02 +02:00
|
|
|
#include "persist_location.h"
|
2014-05-22 01:23:28 +02:00
|
|
|
#include "project.h"
|
2012-06-07 04:48:11 +02:00
|
|
|
#include "utils.h"
|
2007-01-23 05:42:08 +01:00
|
|
|
#include "video_box.h"
|
2014-05-22 01:23:28 +02:00
|
|
|
#include "video_controller.h"
|
2007-01-23 07:32:16 +01:00
|
|
|
#include "video_display.h"
|
2011-07-30 01:16:36 +02:00
|
|
|
|
2014-05-29 17:28:37 +02:00
|
|
|
#include <libaegisub/format_path.h>
|
2014-04-23 22:53:24 +02:00
|
|
|
#include <libaegisub/make_unique.h>
|
2013-06-10 15:58:13 +02:00
|
|
|
|
2013-01-04 16:01:50 +01:00
|
|
|
#include <boost/filesystem/path.hpp>
|
|
|
|
|
2013-01-07 02:50:09 +01:00
|
|
|
#include <wx/sizer.h>
|
|
|
|
#include <wx/display.h> /// Must be included last.
|
|
|
|
|
2012-03-09 01:23:41 +01:00
|
|
|
DialogDetachedVideo::DialogDetachedVideo(agi::Context *context)
|
2011-07-30 01:16:36 +02:00
|
|
|
: wxDialog(context->parent, -1, "Detached Video", wxDefaultPosition, wxSize(400,300), wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER | wxMAXIMIZE_BOX | wxMINIMIZE_BOX | wxWANTS_CHARS)
|
|
|
|
, context(context)
|
2011-11-12 02:23:18 +01:00
|
|
|
, old_display(context->videoDisplay)
|
|
|
|
, old_slider(context->videoSlider)
|
2014-05-22 01:23:28 +02:00
|
|
|
, video_open(context->project->AddVideoProviderListener(&DialogDetachedVideo::OnVideoOpen, this))
|
2007-01-23 05:42:08 +01:00
|
|
|
{
|
2008-01-11 06:44:00 +01:00
|
|
|
// Set obscure stuff
|
2009-09-02 10:23:18 +02:00
|
|
|
SetExtraStyle((GetExtraStyle() & ~wxWS_EX_BLOCK_EVENTS) | wxWS_EX_PROCESS_UI_UPDATES);
|
2008-01-11 06:44:00 +01:00
|
|
|
|
2014-05-29 17:28:37 +02:00
|
|
|
SetTitle(fmt_tl("Video: %s", context->project->VideoName().filename()));
|
2007-07-27 07:25:51 +02:00
|
|
|
|
2012-07-04 17:30:21 +02:00
|
|
|
old_display->Unload();
|
|
|
|
|
2007-01-23 05:42:08 +01:00
|
|
|
// Video area;
|
2013-11-21 18:13:36 +01:00
|
|
|
auto videoBox = new VideoBox(this, true, context);
|
2012-03-09 01:23:41 +01:00
|
|
|
context->videoDisplay->SetMinClientSize(old_display->GetClientSize());
|
2011-08-17 07:32:15 +02:00
|
|
|
videoBox->Layout();
|
2006-04-15 00:37:05 +02:00
|
|
|
|
2007-01-23 05:42:08 +01:00
|
|
|
// Set sizer
|
|
|
|
wxSizer *mainSizer = new wxBoxSizer(wxVERTICAL);
|
2013-01-10 04:26:39 +01:00
|
|
|
mainSizer->Add(videoBox,1,wxEXPAND);
|
2011-12-22 22:31:57 +01:00
|
|
|
SetSizerAndFit(mainSizer);
|
2006-04-15 00:37:05 +02:00
|
|
|
|
2009-06-06 16:36:22 +02:00
|
|
|
// Ensure we can grow smaller, without these the window is locked to at least the initial size
|
2011-11-12 02:23:29 +01:00
|
|
|
context->videoDisplay->SetMinSize(wxSize(1,1));
|
2009-06-06 16:36:22 +02:00
|
|
|
videoBox->SetMinSize(wxSize(1,1));
|
|
|
|
SetMinSize(wxSize(1,1));
|
|
|
|
|
2014-04-23 22:53:24 +02:00
|
|
|
persist = agi::make_unique<PersistLocation>(this, "Video/Detached");
|
2011-07-27 07:36:02 +02:00
|
|
|
|
2009-11-14 01:42:55 +01:00
|
|
|
int display_index = wxDisplay::GetFromWindow(this);
|
2011-07-27 07:36:02 +02:00
|
|
|
// Ensure that the dialog is no larger than the screen
|
|
|
|
if (display_index != wxNOT_FOUND) {
|
2009-11-14 01:42:55 +01:00
|
|
|
wxRect bounds_rect = GetRect();
|
|
|
|
wxRect disp_rect = wxDisplay(display_index).GetClientArea();
|
2011-07-27 07:36:02 +02:00
|
|
|
SetSize(std::min(bounds_rect.width, disp_rect.width), std::min(bounds_rect.height, disp_rect.height));
|
2009-11-14 01:42:55 +01:00
|
|
|
}
|
|
|
|
|
2010-05-21 03:13:36 +02:00
|
|
|
OPT_SET("Video/Detached/Enabled")->SetBool(true);
|
2006-04-15 00:37:05 +02:00
|
|
|
|
2011-07-30 01:16:36 +02:00
|
|
|
Bind(wxEVT_CLOSE_WINDOW, &DialogDetachedVideo::OnClose, this);
|
|
|
|
Bind(wxEVT_ICONIZE, &DialogDetachedVideo::OnMinimize, this);
|
2012-04-27 21:07:49 +02:00
|
|
|
Bind(wxEVT_CHAR_HOOK, &DialogDetachedVideo::OnKeyDown, this);
|
2012-06-07 04:48:11 +02:00
|
|
|
|
|
|
|
AddFullScreenButton(this);
|
2007-01-23 05:42:08 +01:00
|
|
|
}
|
2007-07-27 06:05:18 +02:00
|
|
|
|
2011-07-30 01:16:36 +02:00
|
|
|
DialogDetachedVideo::~DialogDetachedVideo() { }
|
2007-07-27 06:05:18 +02:00
|
|
|
|
2012-03-09 01:23:41 +01:00
|
|
|
void DialogDetachedVideo::OnClose(wxCloseEvent &evt) {
|
2012-04-03 19:38:38 +02:00
|
|
|
context->videoDisplay->Destroy();
|
|
|
|
|
2011-11-12 02:23:18 +01:00
|
|
|
context->videoDisplay = old_display;
|
|
|
|
context->videoSlider = old_slider;
|
2012-04-03 19:38:38 +02:00
|
|
|
|
2010-05-21 03:13:36 +02:00
|
|
|
OPT_SET("Video/Detached/Enabled")->SetBool(false);
|
2012-04-03 19:38:38 +02:00
|
|
|
|
2014-05-22 01:23:28 +02:00
|
|
|
context->videoController->JumpToFrame(context->videoController->GetFrameN());
|
2012-07-04 17:30:21 +02:00
|
|
|
|
2012-04-03 19:38:38 +02:00
|
|
|
evt.Skip();
|
2008-01-12 04:29:45 +01:00
|
|
|
}
|
|
|
|
|
2009-10-13 06:10:55 +02:00
|
|
|
void DialogDetachedVideo::OnMinimize(wxIconizeEvent &event) {
|
|
|
|
if (event.IsIconized()) {
|
|
|
|
// Force the video display to repaint as otherwise the last displayed
|
|
|
|
// frame stays visible even though the dialog is minimized
|
|
|
|
Hide();
|
|
|
|
Show();
|
|
|
|
}
|
|
|
|
}
|
2011-07-30 01:16:36 +02:00
|
|
|
|
|
|
|
void DialogDetachedVideo::OnKeyDown(wxKeyEvent &evt) {
|
2012-03-13 00:34:34 +01:00
|
|
|
hotkey::check("Video Display", context, evt);
|
2011-07-30 01:16:36 +02:00
|
|
|
}
|
|
|
|
|
2014-06-15 16:03:51 +02:00
|
|
|
void DialogDetachedVideo::OnVideoOpen(AsyncVideoProvider *new_provider) {
|
|
|
|
if (new_provider)
|
2014-05-29 17:28:37 +02:00
|
|
|
SetTitle(fmt_tl("Video: %s", context->project->VideoName().filename()));
|
2013-06-12 23:21:56 +02:00
|
|
|
else {
|
2012-03-09 01:23:41 +01:00
|
|
|
Close();
|
|
|
|
OPT_SET("Video/Detached/Enabled")->SetBool(true);
|
2011-07-30 01:16:36 +02:00
|
|
|
}
|
|
|
|
}
|