2010-05-13 20:37:41 +02:00
|
|
|
// Copyright (c) 2005-2010, Rodrigo Braz Monteiro
|
2006-01-16 22:02:54 +01: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 video_display.cpp
|
|
|
|
/// @brief Control displaying a video frame obtained from the video context
|
|
|
|
/// @ingroup video main_ui
|
|
|
|
///
|
2006-01-16 22:02:54 +01:00
|
|
|
|
2010-05-16 08:39:11 +02:00
|
|
|
#include "video_display.h"
|
|
|
|
|
2010-12-07 20:09:28 +01:00
|
|
|
#include "ass_file.h"
|
2011-11-06 18:18:20 +01:00
|
|
|
#include "command/command.h"
|
2013-01-04 16:01:50 +01:00
|
|
|
#include "compat.h"
|
2011-11-06 18:18:20 +01:00
|
|
|
#include "include/aegisub/context.h"
|
|
|
|
#include "include/aegisub/hotkey.h"
|
|
|
|
#include "include/aegisub/menu.h"
|
2013-01-07 02:50:09 +01:00
|
|
|
#include "options.h"
|
2013-12-27 18:56:39 +01:00
|
|
|
#include "retina_helper.h"
|
2012-03-20 01:39:42 +01:00
|
|
|
#include "spline_curve.h"
|
2013-01-26 02:57:46 +01:00
|
|
|
#include "subs_controller.h"
|
2010-07-23 07:58:39 +02:00
|
|
|
#include "threaded_frame_source.h"
|
2011-10-25 21:40:45 +02:00
|
|
|
#include "utils.h"
|
2009-10-05 06:22:28 +02:00
|
|
|
#include "video_out_gl.h"
|
2009-09-10 03:41:34 +02:00
|
|
|
#include "video_context.h"
|
2012-07-29 05:23:24 +02:00
|
|
|
#include "video_frame.h"
|
2007-07-01 02:19:55 +02:00
|
|
|
#include "visual_tool.h"
|
2009-09-10 15:06:40 +02:00
|
|
|
|
2013-06-10 15:58:13 +02:00
|
|
|
#include <libaegisub/util.h>
|
|
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
|
|
|
|
#include <wx/combobox.h>
|
|
|
|
#include <wx/dataobj.h>
|
|
|
|
#include <wx/dcclient.h>
|
|
|
|
#include <wx/menu.h>
|
|
|
|
#include <wx/textctrl.h>
|
|
|
|
#include <wx/toolbar.h>
|
|
|
|
|
|
|
|
#ifdef HAVE_OPENGL_GL_H
|
|
|
|
#include <OpenGL/gl.h>
|
|
|
|
#else
|
|
|
|
#include <GL/gl.h>
|
|
|
|
#endif
|
|
|
|
|
2009-09-10 03:41:34 +02:00
|
|
|
/// Attribute list for gl canvases; set the canvases to doublebuffered rgba with an 8 bit stencil buffer
|
2007-07-05 06:32:46 +02:00
|
|
|
int attribList[] = { WX_GL_RGBA , WX_GL_DOUBLEBUFFER, WX_GL_STENCIL_SIZE, 8, 0 };
|
2007-01-22 23:57:45 +01:00
|
|
|
|
2010-05-16 08:39:11 +02:00
|
|
|
/// @class VideoOutRenderException
|
|
|
|
/// @extends VideoOutException
|
2010-12-07 20:09:21 +01:00
|
|
|
/// @brief An OpenGL error occurred while uploading or displaying a frame
|
2014-03-13 02:39:07 +01:00
|
|
|
class OpenGlException final : public agi::Exception {
|
2010-05-16 08:39:11 +02:00
|
|
|
public:
|
2011-09-28 21:43:11 +02:00
|
|
|
OpenGlException(const char *func, int err)
|
2013-01-04 16:01:50 +01:00
|
|
|
: agi::Exception(from_wx(wxString::Format("%s failed with error code %d", func, err)))
|
2010-05-16 08:39:11 +02:00
|
|
|
{ }
|
2013-11-21 18:13:36 +01:00
|
|
|
const char * GetName() const override { return "video/opengl"; }
|
|
|
|
Exception * Copy() const override { return new OpenGlException(*this); }
|
2010-05-16 08:39:11 +02:00
|
|
|
};
|
|
|
|
|
2011-09-28 21:43:11 +02:00
|
|
|
#define E(cmd) cmd; if (GLenum err = glGetError()) throw OpenGlException(#cmd, err)
|
2010-05-16 08:39:11 +02:00
|
|
|
|
2010-08-13 07:51:17 +02:00
|
|
|
VideoDisplay::VideoDisplay(
|
2011-11-12 02:23:29 +01:00
|
|
|
wxToolBar *visualSubToolBar,
|
2011-01-23 08:47:59 +01:00
|
|
|
bool freeSize,
|
2010-08-13 07:51:17 +02:00
|
|
|
wxComboBox *zoomBox,
|
|
|
|
wxWindow* parent,
|
2011-01-16 08:17:08 +01:00
|
|
|
agi::Context *c)
|
2012-07-04 17:30:16 +02:00
|
|
|
: wxGLCanvas(parent, -1, attribList)
|
2012-05-05 04:11:15 +02:00
|
|
|
, autohideTools(OPT_GET("Tool/Visual/Autohide"))
|
2011-01-16 08:17:08 +01:00
|
|
|
, con(c)
|
2010-08-13 07:51:17 +02:00
|
|
|
, zoomValue(OPT_GET("Video/Default Zoom")->GetInt() * .125 + .125)
|
2011-11-12 02:23:29 +01:00
|
|
|
, toolBar(visualSubToolBar)
|
2010-08-13 07:51:17 +02:00
|
|
|
, zoomBox(zoomBox)
|
2011-01-23 08:47:59 +01:00
|
|
|
, freeSize(freeSize)
|
2013-12-27 18:56:39 +01:00
|
|
|
, retina_helper(agi::util::make_unique<RetinaHelper>(this))
|
|
|
|
, scale_factor(retina_helper->GetScaleFactor())
|
|
|
|
, scale_factor_connection(retina_helper->AddScaleFactorListener([=](int new_scale_factor) {
|
|
|
|
double new_zoom = zoomValue * new_scale_factor / scale_factor;
|
|
|
|
scale_factor = new_scale_factor;
|
|
|
|
SetZoom(new_zoom);
|
|
|
|
}))
|
2006-01-16 22:02:54 +01:00
|
|
|
{
|
2011-07-15 06:06:23 +02:00
|
|
|
zoomBox->SetValue(wxString::Format("%g%%", zoomValue * 100.));
|
2013-12-12 03:25:13 +01:00
|
|
|
zoomBox->Bind(wxEVT_COMBOBOX, &VideoDisplay::SetZoomFromBox, this);
|
|
|
|
zoomBox->Bind(wxEVT_TEXT_ENTER, &VideoDisplay::SetZoomFromBoxText, this);
|
2010-12-07 20:09:21 +01:00
|
|
|
|
2011-01-16 08:17:08 +01:00
|
|
|
con->videoController->Bind(EVT_FRAME_READY, &VideoDisplay::UploadFrameData, this);
|
2012-07-04 17:30:16 +02:00
|
|
|
slots.push_back(con->videoController->AddVideoOpenListener(&VideoDisplay::UpdateSize, this));
|
|
|
|
slots.push_back(con->videoController->AddARChangeListener(&VideoDisplay::UpdateSize, this));
|
2010-12-07 20:09:21 +01:00
|
|
|
|
2013-01-26 02:57:46 +01:00
|
|
|
slots.push_back(con->subsController->AddFileSaveListener(&VideoDisplay::OnSubtitlesSave, this));
|
2012-07-24 04:40:37 +02:00
|
|
|
|
2012-09-25 01:35:27 +02:00
|
|
|
Bind(wxEVT_PAINT, std::bind(&VideoDisplay::Render, this));
|
2011-11-18 02:20:47 +01:00
|
|
|
Bind(wxEVT_SIZE, &VideoDisplay::OnSizeEvent, this);
|
2011-08-31 06:17:37 +02:00
|
|
|
Bind(wxEVT_CONTEXT_MENU, &VideoDisplay::OnContextMenu, this);
|
2011-11-06 18:18:20 +01:00
|
|
|
Bind(wxEVT_ENTER_WINDOW, &VideoDisplay::OnMouseEvent, this);
|
2012-04-27 21:07:49 +02:00
|
|
|
Bind(wxEVT_CHAR_HOOK, &VideoDisplay::OnKeyDown, this);
|
2011-11-06 18:18:20 +01:00
|
|
|
Bind(wxEVT_LEAVE_WINDOW, &VideoDisplay::OnMouseLeave, this);
|
2011-09-30 22:42:37 +02:00
|
|
|
Bind(wxEVT_LEFT_DCLICK, &VideoDisplay::OnMouseEvent, this);
|
2011-08-31 06:17:37 +02:00
|
|
|
Bind(wxEVT_LEFT_DOWN, &VideoDisplay::OnMouseEvent, this);
|
|
|
|
Bind(wxEVT_LEFT_UP, &VideoDisplay::OnMouseEvent, this);
|
|
|
|
Bind(wxEVT_MOTION, &VideoDisplay::OnMouseEvent, this);
|
|
|
|
Bind(wxEVT_MOUSEWHEEL, &VideoDisplay::OnMouseWheel, this);
|
2011-01-23 08:47:59 +01:00
|
|
|
|
2007-01-21 07:30:19 +01:00
|
|
|
SetCursor(wxNullCursor);
|
2011-07-15 06:04:01 +02:00
|
|
|
|
2011-11-12 02:23:18 +01:00
|
|
|
c->videoDisplay = this;
|
|
|
|
|
2011-11-06 18:18:20 +01:00
|
|
|
if (con->videoController->IsLoaded())
|
2012-04-03 19:38:38 +02:00
|
|
|
con->videoController->JumpToFrame(con->videoController->GetFrameN());
|
2006-01-16 22:02:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
VideoDisplay::~VideoDisplay () {
|
2011-01-16 08:17:08 +01:00
|
|
|
con->videoController->Unbind(EVT_FRAME_READY, &VideoDisplay::UploadFrameData, this);
|
2006-01-16 22:02:54 +01:00
|
|
|
}
|
|
|
|
|
2010-07-18 07:45:52 +02:00
|
|
|
bool VideoDisplay::InitContext() {
|
2012-01-09 21:31:38 +01:00
|
|
|
if (!IsShownOnScreen())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// If this display is in a minimized detached dialog IsShownOnScreen will
|
|
|
|
// return true, but the client size is guaranteed to be 0
|
|
|
|
if (GetClientSize() == wxSize(0, 0))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (!glContext)
|
2013-06-10 15:58:13 +02:00
|
|
|
glContext = agi::util::make_unique<wxGLContext>(this);
|
2012-01-09 21:31:38 +01:00
|
|
|
|
2013-06-10 15:58:13 +02:00
|
|
|
SetCurrent(*glContext);
|
2010-07-18 07:45:52 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-07-23 07:58:39 +02:00
|
|
|
void VideoDisplay::UploadFrameData(FrameReadyEvent &evt) {
|
2012-07-29 05:23:24 +02:00
|
|
|
pending_frame = evt.frame;
|
|
|
|
Render();
|
|
|
|
}
|
|
|
|
|
|
|
|
void VideoDisplay::Render() try {
|
|
|
|
if (!con->videoController->IsLoaded() || !InitContext() || (!videoOut && !pending_frame))
|
2012-04-03 19:38:38 +02:00
|
|
|
return;
|
2010-07-23 07:58:39 +02:00
|
|
|
|
2011-11-23 19:32:23 +01:00
|
|
|
if (!videoOut)
|
2013-06-10 15:58:13 +02:00
|
|
|
videoOut = agi::util::make_unique<VideoOutGL>();
|
2011-11-23 19:32:23 +01:00
|
|
|
|
2012-04-03 19:38:38 +02:00
|
|
|
if (!tool)
|
|
|
|
cmd::call("video/tool/cross", con);
|
|
|
|
|
2010-06-28 09:39:42 +02:00
|
|
|
try {
|
2012-07-29 05:23:24 +02:00
|
|
|
if (pending_frame) {
|
|
|
|
videoOut->UploadFrameData(*pending_frame);
|
|
|
|
pending_frame.reset();
|
|
|
|
}
|
2010-06-28 09:39:42 +02:00
|
|
|
}
|
|
|
|
catch (const VideoOutInitException& err) {
|
|
|
|
wxLogError(
|
2011-09-28 21:43:11 +02:00
|
|
|
"Failed to initialize video display. Closing other running "
|
|
|
|
"programs and updating your video card drivers may fix this.\n"
|
|
|
|
"Error message reported: %s",
|
2011-09-28 21:43:48 +02:00
|
|
|
err.GetMessage());
|
2011-11-23 19:32:37 +01:00
|
|
|
con->videoController->SetVideo("");
|
2012-07-29 05:23:24 +02:00
|
|
|
return;
|
2010-06-28 09:39:42 +02:00
|
|
|
}
|
|
|
|
catch (const VideoOutRenderException& err) {
|
|
|
|
wxLogError(
|
2011-09-28 21:43:11 +02:00
|
|
|
"Could not upload video frame to graphics card.\n"
|
|
|
|
"Error message reported: %s",
|
2011-09-28 21:43:48 +02:00
|
|
|
err.GetMessage());
|
2012-01-09 21:31:38 +01:00
|
|
|
return;
|
2012-07-29 05:23:24 +02:00
|
|
|
}
|
2011-11-23 19:32:23 +01:00
|
|
|
|
2013-10-09 00:21:26 +02:00
|
|
|
if (videoSize.GetWidth() == 0) videoSize.SetWidth(1);
|
|
|
|
if (videoSize.GetHeight() == 0) videoSize.SetHeight(1);
|
|
|
|
|
2011-11-23 19:32:23 +01:00
|
|
|
if (!viewport_height || !viewport_width)
|
2012-07-04 17:30:16 +02:00
|
|
|
PositionVideo();
|
2007-04-02 01:07:29 +02:00
|
|
|
|
2011-11-06 18:18:20 +01:00
|
|
|
videoOut->Render(viewport_left, viewport_bottom, viewport_width, viewport_height);
|
2012-07-04 17:30:16 +02:00
|
|
|
E(glViewport(0, std::min(viewport_bottom, 0), videoSize.GetWidth(), videoSize.GetHeight()));
|
2010-05-16 08:39:11 +02:00
|
|
|
|
|
|
|
E(glMatrixMode(GL_PROJECTION));
|
|
|
|
E(glLoadIdentity());
|
2013-12-27 18:56:39 +01:00
|
|
|
E(glOrtho(0.0f, videoSize.GetWidth() / scale_factor, videoSize.GetHeight() / scale_factor, 0.0f, -1000.0f, 1000.0f));
|
2010-05-16 08:39:11 +02:00
|
|
|
|
2010-05-21 03:13:36 +02:00
|
|
|
if (OPT_GET("Video/Overscan Mask")->GetBool()) {
|
2011-01-16 08:17:08 +01:00
|
|
|
double ar = con->videoController->GetAspectRatioValue();
|
2010-05-16 08:39:11 +02:00
|
|
|
|
|
|
|
// Based on BBC's guidelines: http://www.bbc.co.uk/guidelines/dq/pdf/tv/tv_standards_london.pdf
|
|
|
|
// 16:9 or wider
|
|
|
|
if (ar > 1.75) {
|
2011-11-06 18:18:20 +01:00
|
|
|
DrawOverscanMask(.1f, .05f);
|
|
|
|
DrawOverscanMask(0.035f, 0.035f);
|
2010-05-16 08:39:11 +02:00
|
|
|
}
|
|
|
|
// Less wide than 16:9 (use 4:3 standard)
|
|
|
|
else {
|
2011-11-06 18:18:20 +01:00
|
|
|
DrawOverscanMask(.067f, .05f);
|
|
|
|
DrawOverscanMask(0.033f, 0.035f);
|
2010-05-16 08:39:11 +02:00
|
|
|
}
|
|
|
|
}
|
2007-01-02 21:07:52 +01:00
|
|
|
|
2012-05-05 04:11:15 +02:00
|
|
|
if ((mouse_pos || !autohideTools->GetBool()) && tool)
|
2011-12-27 02:38:00 +01:00
|
|
|
tool->Draw();
|
2007-01-02 21:07:52 +01:00
|
|
|
|
2007-01-21 07:30:19 +01:00
|
|
|
SwapBuffers();
|
2007-01-02 21:07:52 +01:00
|
|
|
}
|
2011-11-06 18:18:20 +01:00
|
|
|
catch (const agi::Exception &err) {
|
2010-04-30 05:00:15 +02:00
|
|
|
wxLogError(
|
2011-09-28 21:43:11 +02:00
|
|
|
"An error occurred trying to render the video frame on the screen.\n"
|
|
|
|
"Error message reported: %s",
|
2011-11-06 18:18:20 +01:00
|
|
|
err.GetChainedMessage());
|
2011-11-23 19:32:37 +01:00
|
|
|
con->videoController->SetVideo("");
|
2009-06-01 17:26:26 +02:00
|
|
|
}
|
2007-01-02 21:07:52 +01:00
|
|
|
|
2011-11-06 18:18:20 +01:00
|
|
|
void VideoDisplay::DrawOverscanMask(float horizontal_percent, float vertical_percent) const {
|
2011-11-12 02:23:40 +01:00
|
|
|
Vector2D v(viewport_width, viewport_height);
|
|
|
|
Vector2D size = Vector2D(horizontal_percent, vertical_percent) / 2 * v;
|
2012-03-20 01:39:42 +01:00
|
|
|
|
|
|
|
// Clockwise from top-left
|
|
|
|
Vector2D corners[] = {
|
|
|
|
size,
|
|
|
|
Vector2D(viewport_width - size.X(), size),
|
|
|
|
v - size,
|
|
|
|
Vector2D(size, viewport_height - size.Y())
|
|
|
|
};
|
|
|
|
|
|
|
|
// Shift to compensate for black bars
|
|
|
|
Vector2D pos(viewport_left, viewport_top);
|
2013-11-21 18:13:36 +01:00
|
|
|
for (auto& corner : corners)
|
|
|
|
corner = corner + pos;
|
2012-03-20 01:39:42 +01:00
|
|
|
|
|
|
|
int count = 0;
|
|
|
|
std::vector<float> points;
|
|
|
|
for (size_t i = 0; i < 4; ++i) {
|
|
|
|
size_t prev = (i + 3) % 4;
|
|
|
|
size_t next = (i + 1) % 4;
|
|
|
|
count += SplineCurve(
|
|
|
|
(corners[prev] + corners[i] * 4) / 5,
|
|
|
|
corners[i], corners[i],
|
|
|
|
(corners[next] + corners[i] * 4) / 5)
|
|
|
|
.GetPoints(points);
|
|
|
|
}
|
2007-06-28 22:29:56 +02:00
|
|
|
|
|
|
|
OpenGLWrapper gl;
|
2011-11-06 18:18:20 +01:00
|
|
|
gl.SetFillColour(wxColor(30, 70, 200), .5f);
|
|
|
|
gl.SetLineColour(*wxBLACK, 0, 1);
|
2007-06-28 22:29:56 +02:00
|
|
|
|
2012-03-20 01:39:42 +01:00
|
|
|
std::vector<int> vstart(1, 0);
|
|
|
|
std::vector<int> vcount(1, count);
|
|
|
|
gl.DrawMultiPolygon(points, vstart, vcount, Vector2D(viewport_left, viewport_top), Vector2D(viewport_width, viewport_height), true);
|
2007-06-28 22:29:56 +02:00
|
|
|
}
|
|
|
|
|
2012-07-04 17:30:16 +02:00
|
|
|
void VideoDisplay::PositionVideo() {
|
2012-04-03 19:38:38 +02:00
|
|
|
if (!con->videoController->IsLoaded() || !IsShownOnScreen()) return;
|
2007-01-22 00:16:03 +01:00
|
|
|
|
2012-07-04 17:30:16 +02:00
|
|
|
viewport_left = 0;
|
2013-12-27 18:56:39 +01:00
|
|
|
viewport_bottom = GetClientSize().GetHeight() * scale_factor - videoSize.GetHeight();
|
2012-07-04 17:30:16 +02:00
|
|
|
viewport_top = 0;
|
|
|
|
viewport_width = videoSize.GetWidth();
|
|
|
|
viewport_height = videoSize.GetHeight();
|
2010-01-31 19:49:37 +01:00
|
|
|
|
2012-07-04 17:30:16 +02:00
|
|
|
if (freeSize) {
|
|
|
|
int vidW = con->videoController->GetWidth();
|
|
|
|
int vidH = con->videoController->GetHeight();
|
2010-05-16 08:39:06 +02:00
|
|
|
|
2013-01-20 22:05:24 +01:00
|
|
|
AspectRatio arType = con->videoController->GetAspectRatioType();
|
2012-07-04 17:30:16 +02:00
|
|
|
double displayAr = double(viewport_width) / viewport_height;
|
2013-01-20 22:05:24 +01:00
|
|
|
double videoAr = arType == AspectRatio::Default ? double(vidW) / vidH : con->videoController->GetAspectRatioValue();
|
2010-05-16 08:38:59 +02:00
|
|
|
|
|
|
|
// Window is wider than video, blackbox left/right
|
|
|
|
if (displayAr - videoAr > 0.01f) {
|
2012-07-04 17:30:16 +02:00
|
|
|
int delta = viewport_width - videoAr * viewport_height;
|
2011-11-06 18:18:20 +01:00
|
|
|
viewport_left = delta / 2;
|
2012-07-04 17:30:16 +02:00
|
|
|
viewport_width -= delta;
|
2010-05-16 08:38:59 +02:00
|
|
|
}
|
|
|
|
// Video is wider than window, blackbox top/bottom
|
|
|
|
else if (videoAr - displayAr > 0.01f) {
|
2012-07-04 17:30:16 +02:00
|
|
|
int delta = viewport_height - viewport_width / videoAr;
|
2010-05-16 08:39:11 +02:00
|
|
|
viewport_top = viewport_bottom = delta / 2;
|
2012-07-04 17:30:16 +02:00
|
|
|
viewport_height -= delta;
|
2010-05-16 08:38:59 +02:00
|
|
|
}
|
|
|
|
}
|
2010-05-16 08:39:06 +02:00
|
|
|
|
2012-07-04 17:30:16 +02:00
|
|
|
if (tool)
|
2013-12-27 18:56:39 +01:00
|
|
|
tool->SetDisplayArea(viewport_left / scale_factor, viewport_top / scale_factor,
|
|
|
|
viewport_width / scale_factor, viewport_height / scale_factor);
|
2011-12-22 22:31:57 +01:00
|
|
|
|
2012-07-04 17:30:16 +02:00
|
|
|
Render();
|
|
|
|
}
|
2010-05-16 08:39:06 +02:00
|
|
|
|
2012-07-04 17:30:16 +02:00
|
|
|
void VideoDisplay::UpdateSize() {
|
|
|
|
if (!con->videoController->IsLoaded() || !IsShownOnScreen()) return;
|
|
|
|
|
|
|
|
videoSize.Set(con->videoController->GetWidth(), con->videoController->GetHeight());
|
|
|
|
videoSize *= zoomValue;
|
2013-01-20 22:05:24 +01:00
|
|
|
if (con->videoController->GetAspectRatioType() != AspectRatio::Default)
|
2012-07-04 17:30:16 +02:00
|
|
|
videoSize.SetWidth(videoSize.GetHeight() * con->videoController->GetAspectRatioValue());
|
|
|
|
|
|
|
|
wxEventBlocker blocker(this);
|
|
|
|
if (freeSize) {
|
|
|
|
wxWindow *top = GetParent();
|
|
|
|
while (!top->IsTopLevel()) top = top->GetParent();
|
2012-10-28 04:44:09 +01:00
|
|
|
|
|
|
|
wxSize cs = GetClientSize();
|
|
|
|
wxSize oldSize = top->GetSize();
|
2013-12-27 18:56:39 +01:00
|
|
|
top->SetSize(top->GetSize() + videoSize / scale_factor - cs);
|
2012-10-28 04:44:09 +01:00
|
|
|
SetClientSize(cs + top->GetSize() - oldSize);
|
2010-05-16 08:39:06 +02:00
|
|
|
}
|
2012-07-04 17:30:16 +02:00
|
|
|
else {
|
2013-12-27 18:56:39 +01:00
|
|
|
SetMinClientSize(videoSize / scale_factor);
|
|
|
|
SetMaxClientSize(videoSize / scale_factor);
|
2010-05-16 08:38:59 +02:00
|
|
|
|
2012-07-04 17:30:16 +02:00
|
|
|
GetGrandParent()->Layout();
|
|
|
|
}
|
2010-05-16 08:39:11 +02:00
|
|
|
|
2012-07-04 17:30:16 +02:00
|
|
|
PositionVideo();
|
2006-01-16 22:02:54 +01:00
|
|
|
}
|
|
|
|
|
2007-01-23 05:42:08 +01:00
|
|
|
void VideoDisplay::OnSizeEvent(wxSizeEvent &event) {
|
2012-07-04 17:30:16 +02:00
|
|
|
if (freeSize) {
|
2013-12-27 18:56:39 +01:00
|
|
|
videoSize = GetClientSize() * scale_factor;
|
2012-07-04 17:30:16 +02:00
|
|
|
PositionVideo();
|
|
|
|
zoomValue = double(viewport_height) / con->videoController->GetHeight();
|
|
|
|
zoomBox->ChangeValue(wxString::Format("%g%%", zoomValue * 100.));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
PositionVideo();
|
|
|
|
}
|
2007-01-23 05:42:08 +01:00
|
|
|
}
|
|
|
|
|
2006-01-16 22:02:54 +01:00
|
|
|
void VideoDisplay::OnMouseEvent(wxMouseEvent& event) {
|
2011-08-31 06:17:37 +02:00
|
|
|
if (event.ButtonDown())
|
2007-01-09 02:52:30 +01:00
|
|
|
SetFocus();
|
|
|
|
|
2012-08-26 03:33:44 +02:00
|
|
|
last_mouse_pos = mouse_pos = event.GetPosition();
|
2011-08-31 06:17:37 +02:00
|
|
|
|
2012-04-03 19:38:38 +02:00
|
|
|
if (tool)
|
|
|
|
tool->OnMouseEvent(event);
|
2011-08-31 06:17:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void VideoDisplay::OnMouseLeave(wxMouseEvent& event) {
|
2011-12-07 00:13:06 +01:00
|
|
|
mouse_pos = Vector2D();
|
2012-04-03 19:38:38 +02:00
|
|
|
if (tool)
|
|
|
|
tool->OnMouseEvent(event);
|
2010-05-16 08:39:11 +02:00
|
|
|
}
|
2011-08-31 06:17:37 +02:00
|
|
|
|
|
|
|
void VideoDisplay::OnMouseWheel(wxMouseEvent& event) {
|
2011-10-25 21:40:45 +02:00
|
|
|
if (int wheel = event.GetWheelRotation()) {
|
|
|
|
if (ForwardMouseWheelEvent(this, event))
|
2011-12-27 02:38:00 +01:00
|
|
|
SetZoom(zoomValue + .125 * (wheel / event.GetWheelDelta()));
|
2011-10-25 21:40:45 +02:00
|
|
|
}
|
2011-08-31 06:17:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void VideoDisplay::OnContextMenu(wxContextMenuEvent&) {
|
2013-06-10 15:58:13 +02:00
|
|
|
if (!context_menu.get()) context_menu = menu::GetMenu("video_context", con);
|
2011-11-06 18:18:20 +01:00
|
|
|
SetCursor(wxNullCursor);
|
2011-08-31 06:17:37 +02:00
|
|
|
menu::OpenPopupMenu(context_menu.get(), this);
|
|
|
|
}
|
|
|
|
|
Merge the dynamic menu, hotkey and toolbar branch to trunk. This doesn't include Windows support as vs2008 was being a major pain. This involves revisions r4921:4950, r4961:5002, r5005:5006, r5008:5056, r5062:5065, r5072, r5081:5082, r5087, r5096:5110, r5124:5125. Updates #1258.
Originally committed to SVN as r5126.
2011-01-05 14:00:46 +01:00
|
|
|
void VideoDisplay::OnKeyDown(wxKeyEvent &event) {
|
2012-03-13 00:34:34 +01:00
|
|
|
hotkey::check("Video", con, event);
|
2007-01-09 02:52:30 +01:00
|
|
|
}
|
|
|
|
|
2006-01-16 22:02:54 +01:00
|
|
|
void VideoDisplay::SetZoom(double value) {
|
2010-08-12 08:39:49 +02:00
|
|
|
zoomValue = std::max(value, .125);
|
2012-10-28 04:44:09 +01:00
|
|
|
size_t selIndex = zoomValue / .125 - 1;
|
2012-07-06 01:05:34 +02:00
|
|
|
if (selIndex < zoomBox->GetCount())
|
|
|
|
zoomBox->SetSelection(selIndex);
|
2012-01-27 20:23:26 +01:00
|
|
|
zoomBox->ChangeValue(wxString::Format("%g%%", zoomValue * 100.));
|
2012-07-04 17:30:16 +02:00
|
|
|
UpdateSize();
|
2006-01-16 22:02:54 +01:00
|
|
|
}
|
2011-11-06 18:18:20 +01:00
|
|
|
|
2011-07-15 06:03:54 +02:00
|
|
|
void VideoDisplay::SetZoomFromBox(wxCommandEvent &) {
|
2012-01-27 20:23:26 +01:00
|
|
|
int sel = zoomBox->GetSelection();
|
|
|
|
if (sel != wxNOT_FOUND) {
|
|
|
|
zoomValue = (sel + 1) * .125;
|
2012-07-04 17:30:16 +02:00
|
|
|
UpdateSize();
|
2010-05-01 03:07:05 +02:00
|
|
|
}
|
|
|
|
}
|
2006-01-16 22:02:54 +01:00
|
|
|
|
2012-01-27 20:23:26 +01:00
|
|
|
void VideoDisplay::SetZoomFromBoxText(wxCommandEvent &) {
|
|
|
|
wxString strValue = zoomBox->GetValue();
|
|
|
|
if (strValue.EndsWith("%"))
|
|
|
|
strValue.RemoveLast();
|
|
|
|
|
|
|
|
double value;
|
|
|
|
if (strValue.ToDouble(&value))
|
|
|
|
SetZoom(value / 100.);
|
|
|
|
}
|
|
|
|
|
2013-09-16 15:43:17 +02:00
|
|
|
void VideoDisplay::SetTool(std::unique_ptr<VisualToolBase> new_tool) {
|
2010-05-16 08:39:11 +02:00
|
|
|
toolBar->ClearTools();
|
|
|
|
toolBar->Realize();
|
|
|
|
toolBar->Show(false);
|
|
|
|
|
2013-06-10 15:58:13 +02:00
|
|
|
tool = std::move(new_tool);
|
2011-11-06 18:18:20 +01:00
|
|
|
tool->SetToolbar(toolBar);
|
2010-05-16 08:39:11 +02:00
|
|
|
|
|
|
|
// Update size as the new typesetting tool may have changed the subtoolbar size
|
2013-12-21 17:24:59 +01:00
|
|
|
if (!freeSize)
|
|
|
|
UpdateSize();
|
|
|
|
else {
|
|
|
|
// UpdateSize fits the window to the video, which we don't want to do
|
|
|
|
GetGrandParent()->Layout();
|
2013-12-27 18:56:39 +01:00
|
|
|
tool->SetDisplayArea(viewport_left / scale_factor, viewport_top / scale_factor,
|
|
|
|
viewport_width / scale_factor, viewport_height / scale_factor);
|
2013-12-21 17:24:59 +01:00
|
|
|
}
|
2010-05-16 08:39:11 +02:00
|
|
|
}
|
|
|
|
|
2012-01-13 21:18:40 +01:00
|
|
|
bool VideoDisplay::ToolIsType(std::type_info const& type) const {
|
2012-02-01 19:47:37 +01:00
|
|
|
return tool && typeid(*tool) == type;
|
2012-01-13 21:18:40 +01:00
|
|
|
}
|
|
|
|
|
2011-11-06 18:18:20 +01:00
|
|
|
Vector2D VideoDisplay::GetMousePosition() const {
|
2012-08-26 03:33:44 +02:00
|
|
|
return last_mouse_pos ? tool->ToScriptCoords(last_mouse_pos) : last_mouse_pos;
|
2006-01-16 22:02:54 +01:00
|
|
|
}
|
2012-04-03 19:38:38 +02:00
|
|
|
|
2012-07-04 17:30:21 +02:00
|
|
|
void VideoDisplay::Unload() {
|
2012-04-03 19:38:38 +02:00
|
|
|
glContext.reset();
|
|
|
|
videoOut.reset();
|
|
|
|
tool.reset();
|
2012-07-29 05:23:24 +02:00
|
|
|
pending_frame.reset();
|
2012-04-03 19:38:38 +02:00
|
|
|
}
|
2012-07-24 04:40:37 +02:00
|
|
|
|
|
|
|
void VideoDisplay::OnSubtitlesSave() {
|
2013-10-08 02:42:09 +02:00
|
|
|
con->ass->SaveUIState("Video Zoom Percent", std::to_string(zoomValue));
|
2012-07-24 04:40:37 +02:00
|
|
|
}
|