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/
|
2006-01-16 22:02:54 +01:00
|
|
|
//
|
2009-07-29 07:43:02 +02:00
|
|
|
// $Id$
|
|
|
|
|
|
|
|
/// @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
|
|
|
|
|
|
|
// Includes
|
2009-01-04 07:31:48 +01:00
|
|
|
#include "config.h"
|
|
|
|
|
2009-09-10 15:06:40 +02:00
|
|
|
#ifndef AGI_PRE
|
2010-08-03 00:14:11 +02:00
|
|
|
#include <algorithm>
|
|
|
|
|
2011-08-27 08:30:23 +02:00
|
|
|
#include <wx/combobox.h>
|
2009-09-10 15:06:40 +02:00
|
|
|
#include <wx/dataobj.h>
|
|
|
|
#include <wx/dcclient.h>
|
|
|
|
#include <wx/menu.h>
|
2011-08-27 08:30:23 +02:00
|
|
|
#include <wx/textctrl.h>
|
2010-06-14 21:26:27 +02:00
|
|
|
#include <wx/toolbar.h>
|
2009-09-10 15:06:40 +02:00
|
|
|
#endif
|
|
|
|
|
2007-09-12 01:22:26 +02:00
|
|
|
#ifdef __APPLE__
|
2011-01-11 18:52:17 +01:00
|
|
|
#include <OpenGL/gl.h>
|
2007-04-22 04:24:27 +02:00
|
|
|
#include <OpenGL/glu.h>
|
|
|
|
#else
|
2007-01-22 23:57:45 +01:00
|
|
|
#include <GL/gl.h>
|
|
|
|
#include <GL/glu.h>
|
2007-04-22 04:24:27 +02:00
|
|
|
#endif
|
2009-09-10 15:06:40 +02: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"
|
|
|
|
#include "include/aegisub/context.h"
|
|
|
|
#include "include/aegisub/hotkey.h"
|
|
|
|
#include "include/aegisub/menu.h"
|
2010-05-21 03:13:36 +02:00
|
|
|
#include "main.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"
|
2007-01-11 04:53:20 +01:00
|
|
|
#include "video_box.h"
|
2009-09-10 03:41:34 +02:00
|
|
|
#include "video_context.h"
|
2007-07-01 02:19:55 +02:00
|
|
|
#include "visual_tool.h"
|
2009-09-10 15:06:40 +02:00
|
|
|
|
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
|
2010-05-21 03:13:36 +02:00
|
|
|
class OpenGlException : 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)
|
2010-05-21 03:13:36 +02:00
|
|
|
: agi::Exception(STD_STR(wxString::Format("%s failed with error code %d", func, err)))
|
2010-05-16 08:39:11 +02:00
|
|
|
{ }
|
2010-05-21 03:13:36 +02:00
|
|
|
const char * GetName() const { return "video/opengl"; }
|
2010-05-16 08:39:11 +02:00
|
|
|
Exception * Copy() const { return new OpenGlException(*this); }
|
|
|
|
};
|
|
|
|
|
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(
|
|
|
|
VideoBox *box,
|
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)
|
2010-12-30 20:13:53 +01:00
|
|
|
: wxGLCanvas (parent, -1, attribList, wxDefaultPosition, wxDefaultSize, 0, wxPanelNameStr)
|
2010-06-04 05:07:33 +02:00
|
|
|
, alwaysShowTools(OPT_GET("Tool/Visual/Always Show"))
|
2011-01-16 08:17:08 +01:00
|
|
|
, con(c)
|
2011-11-06 18:18:20 +01:00
|
|
|
, w(8)
|
|
|
|
, h(8)
|
|
|
|
, mouse_pos(Vector2D::Bad())
|
|
|
|
, viewport_left(0)
|
|
|
|
, viewport_width(0)
|
|
|
|
, viewport_bottom(0)
|
|
|
|
, viewport_top(0)
|
|
|
|
, viewport_height(0)
|
2010-08-13 07:51:17 +02:00
|
|
|
, zoomValue(OPT_GET("Video/Default Zoom")->GetInt() * .125 + .125)
|
2009-10-13 19:28:39 +02:00
|
|
|
, videoOut(new VideoOutGL())
|
2010-05-16 08:39:11 +02:00
|
|
|
, toolBar(box->visualSubToolBar)
|
2010-08-13 07:51:17 +02:00
|
|
|
, zoomBox(zoomBox)
|
2010-05-16 09:06:08 +02:00
|
|
|
, box(box)
|
2011-01-23 08:47:59 +01:00
|
|
|
, freeSize(freeSize)
|
2006-01-16 22:02:54 +01:00
|
|
|
{
|
2010-12-07 20:09:28 +01:00
|
|
|
assert(box);
|
|
|
|
|
2011-07-15 06:06:23 +02:00
|
|
|
zoomBox->SetValue(wxString::Format("%g%%", zoomValue * 100.));
|
|
|
|
zoomBox->Bind(wxEVT_COMMAND_COMBOBOX_SELECTED, &VideoDisplay::SetZoomFromBox, 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);
|
|
|
|
slots.push_back(con->videoController->AddVideoOpenListener(&VideoDisplay::OnVideoOpen, this));
|
|
|
|
slots.push_back(con->videoController->AddARChangeListener(&VideoDisplay::UpdateSize, this));
|
2010-12-07 20:09:21 +01:00
|
|
|
|
2011-01-23 08:47:59 +01:00
|
|
|
Bind(wxEVT_PAINT, std::tr1::bind(&VideoDisplay::Render, this));
|
|
|
|
if (freeSize) {
|
|
|
|
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);
|
2011-08-31 06:17:37 +02:00
|
|
|
Bind(wxEVT_KEY_DOWN, &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-06 18:18:20 +01:00
|
|
|
if (con->videoController->IsLoaded())
|
2011-07-15 06:04:01 +02:00
|
|
|
OnVideoOpen();
|
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() {
|
|
|
|
if (!IsShownOnScreen()) return false;
|
|
|
|
if (!glContext.get()) {
|
|
|
|
glContext.reset(new wxGLContext(this));
|
|
|
|
}
|
|
|
|
SetCurrent(*glContext.get());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-07-23 07:58:39 +02:00
|
|
|
void VideoDisplay::UploadFrameData(FrameReadyEvent &evt) {
|
2010-07-18 07:45:52 +02:00
|
|
|
if (!InitContext()) return;
|
2010-07-23 07:58:39 +02:00
|
|
|
|
2010-06-28 09:39:42 +02:00
|
|
|
try {
|
2010-07-23 07:58:39 +02:00
|
|
|
videoOut->UploadFrameData(*evt.frame);
|
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-01-16 08:17:08 +01:00
|
|
|
con->videoController->Reset();
|
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());
|
2010-06-28 09:39:42 +02:00
|
|
|
}
|
2010-07-23 07:58:39 +02:00
|
|
|
Render();
|
2009-10-05 06:22:28 +02:00
|
|
|
}
|
|
|
|
|
2010-12-07 20:09:28 +01:00
|
|
|
void VideoDisplay::OnVideoOpen() {
|
2011-01-16 08:17:08 +01:00
|
|
|
if (!con->videoController->IsLoaded()) return;
|
2011-11-06 18:18:20 +01:00
|
|
|
if (!tool.get())
|
|
|
|
cmd::call("video/tool/cross", con);
|
2010-12-07 20:09:28 +01:00
|
|
|
UpdateSize();
|
2011-11-06 18:18:20 +01:00
|
|
|
con->videoController->JumpToFrame(0);
|
2009-10-05 06:22:28 +02:00
|
|
|
}
|
|
|
|
|
2009-10-27 15:27:39 +01:00
|
|
|
void VideoDisplay::Render() try {
|
2010-07-18 07:45:52 +02:00
|
|
|
if (!InitContext()) return;
|
2011-01-16 08:17:08 +01:00
|
|
|
if (!con->videoController->IsLoaded()) return;
|
2010-05-16 08:39:11 +02:00
|
|
|
assert(wxIsMainThread());
|
2010-08-13 07:51:31 +02:00
|
|
|
if (!viewport_height || !viewport_width) UpdateSize();
|
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);
|
2010-08-13 07:51:17 +02:00
|
|
|
E(glViewport(0, std::min(viewport_bottom, 0), w, h));
|
2010-05-16 08:39:11 +02:00
|
|
|
|
|
|
|
E(glMatrixMode(GL_PROJECTION));
|
|
|
|
E(glLoadIdentity());
|
|
|
|
E(glOrtho(0.0f, w, h, 0.0f, -1000.0f, 1000.0f));
|
|
|
|
|
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
|
|
|
|
2011-11-06 18:18:20 +01:00
|
|
|
if (mouse_pos || alwaysShowTools->GetBool()) {
|
2011-09-02 02:03:40 +02:00
|
|
|
if (!con->videoController->IsPlaying())
|
|
|
|
tool->Draw();
|
2010-05-01 03:45:10 +02:00
|
|
|
}
|
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-01-16 08:17:08 +01:00
|
|
|
con->videoController->Reset();
|
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 {
|
|
|
|
Vector2D size(w * horizontal_percent / 2, h * vertical_percent / 2);
|
2010-05-16 08:39:11 +02:00
|
|
|
int rad1 = h * 0.05;
|
2011-11-06 18:18:20 +01:00
|
|
|
Vector2D gap = size + rad1;
|
|
|
|
int rad2 = gap.Len() + 1;
|
|
|
|
Vector2D v(w, h);
|
|
|
|
Vector2D igap = v - gap;
|
|
|
|
Vector2D isize = v - size;
|
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
|
|
|
|
2010-05-13 20:37:46 +02:00
|
|
|
// Draw sides
|
2011-11-06 18:18:20 +01:00
|
|
|
gl.DrawRectangle(Vector2D(gap, 0), Vector2D(igap, size)); // Top
|
|
|
|
gl.DrawRectangle(Vector2D(isize, gap), Vector2D(v, igap)); // Right
|
|
|
|
gl.DrawRectangle(Vector2D(gap, isize), Vector2D(igap, v)); // Bottom
|
|
|
|
gl.DrawRectangle(Vector2D(0, gap), Vector2D(size, igap)); // Left
|
2007-06-28 22:29:56 +02:00
|
|
|
|
2010-05-13 20:37:46 +02:00
|
|
|
// Draw rounded corners
|
2011-11-06 18:18:20 +01:00
|
|
|
gl.DrawRing(gap, rad1, rad2, 1.f, 90.f, 180.f); // Top-left
|
|
|
|
gl.DrawRing(Vector2D(igap, gap), rad1, rad2, 1.f, 0.f, 90.f); // Top-right
|
|
|
|
gl.DrawRing(v - gap, rad1, rad2, 1.f, 270.f, 360.f); // Bottom-right
|
|
|
|
gl.DrawRing(Vector2D(gap, igap), rad1, rad2, 1.f, 180.f, 270.f); // Bottom-left
|
2007-06-28 22:29:56 +02:00
|
|
|
|
2010-05-16 08:39:11 +02:00
|
|
|
E(glDisable(GL_BLEND));
|
2007-06-28 22:29:56 +02:00
|
|
|
}
|
|
|
|
|
2010-12-07 20:09:28 +01:00
|
|
|
void VideoDisplay::UpdateSize(int arType, double arValue) {
|
2011-01-16 08:17:08 +01:00
|
|
|
if (!con->videoController->IsLoaded()) return;
|
2007-01-23 21:50:41 +01:00
|
|
|
if (!IsShownOnScreen()) return;
|
2007-01-22 00:16:03 +01:00
|
|
|
|
2011-01-16 08:17:08 +01:00
|
|
|
int vidW = con->videoController->GetWidth();
|
|
|
|
int vidH = con->videoController->GetHeight();
|
2010-12-07 20:09:28 +01:00
|
|
|
|
|
|
|
if (arType == -1) {
|
2011-01-16 08:17:08 +01:00
|
|
|
arType = con->videoController->GetAspectRatioType();
|
|
|
|
arValue = con->videoController->GetAspectRatioValue();
|
2010-12-07 20:09:28 +01:00
|
|
|
}
|
2010-01-31 19:49:37 +01:00
|
|
|
|
2010-05-16 08:38:59 +02:00
|
|
|
if (freeSize) {
|
2010-05-16 08:39:06 +02:00
|
|
|
GetClientSize(&w,&h);
|
2011-11-06 18:18:20 +01:00
|
|
|
viewport_left = 0;
|
2010-05-16 08:39:11 +02:00
|
|
|
viewport_bottom = 0;
|
|
|
|
viewport_top = 0;
|
|
|
|
viewport_width = w;
|
|
|
|
viewport_height = h;
|
2010-05-16 08:39:06 +02:00
|
|
|
|
2010-05-16 08:38:59 +02:00
|
|
|
// Set aspect ratio
|
2010-12-07 20:09:28 +01:00
|
|
|
double displayAr = double(w) / h;
|
|
|
|
double videoAr = arType == 0 ? double(vidW)/vidH : arValue;
|
2010-05-16 08:38:59 +02:00
|
|
|
|
|
|
|
// Window is wider than video, blackbox left/right
|
|
|
|
if (displayAr - videoAr > 0.01f) {
|
|
|
|
int delta = w - videoAr * h;
|
2011-11-06 18:18:20 +01:00
|
|
|
viewport_left = delta / 2;
|
2010-05-16 08:39:11 +02:00
|
|
|
viewport_width = w - delta;
|
2010-05-16 08:38:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Video is wider than window, blackbox top/bottom
|
|
|
|
else if (videoAr - displayAr > 0.01f) {
|
|
|
|
int delta = h - w / videoAr;
|
2010-05-16 08:39:11 +02:00
|
|
|
viewport_top = viewport_bottom = delta / 2;
|
|
|
|
viewport_height = h - delta;
|
2010-05-16 08:38:59 +02:00
|
|
|
}
|
|
|
|
}
|
2010-05-16 08:39:06 +02:00
|
|
|
else {
|
|
|
|
wxWindow* parent = GetParent();
|
|
|
|
while (!parent->IsTopLevel()) parent = parent->GetParent();
|
|
|
|
int maxH, maxW;
|
|
|
|
parent->GetClientSize(&maxW, &maxH);
|
|
|
|
|
|
|
|
h = vidH * zoomValue;
|
2010-12-07 20:09:28 +01:00
|
|
|
w = arType == 0 ? vidW * zoomValue : vidH * zoomValue * arValue;
|
2010-05-16 08:39:06 +02:00
|
|
|
|
|
|
|
// Cap the canvas size to the window size
|
2010-08-13 07:51:17 +02:00
|
|
|
int cw = std::min(w, maxW), ch = std::min(h, maxH);
|
2010-05-16 08:39:06 +02:00
|
|
|
|
2011-11-06 18:18:20 +01:00
|
|
|
viewport_left = 0;
|
2010-05-16 08:39:11 +02:00
|
|
|
viewport_bottom = ch - h;
|
|
|
|
viewport_top = 0;
|
|
|
|
viewport_width = w;
|
|
|
|
viewport_height = h;
|
|
|
|
|
|
|
|
wxSize size(cw, ch);
|
2010-08-03 22:21:19 +02:00
|
|
|
SetMinClientSize(size);
|
|
|
|
SetMaxClientSize(size);
|
2010-05-16 08:39:06 +02:00
|
|
|
|
2010-12-07 20:09:28 +01:00
|
|
|
SetEvtHandlerEnabled(false);
|
2010-05-16 08:39:06 +02:00
|
|
|
box->GetParent()->Layout();
|
|
|
|
|
|
|
|
// The sizer makes us use the full width, which at very low zoom levels
|
|
|
|
// results in stretched video, so after using the sizer to update the
|
|
|
|
// parent window sizes, reset our size to the correct value
|
2010-05-16 08:39:11 +02:00
|
|
|
SetSize(cw, ch);
|
2010-05-16 08:39:06 +02:00
|
|
|
|
2010-12-07 20:09:28 +01:00
|
|
|
SetEvtHandlerEnabled(true);
|
2010-05-16 08:39:06 +02:00
|
|
|
}
|
2010-05-16 08:38:59 +02:00
|
|
|
|
2011-11-06 18:18:20 +01:00
|
|
|
if (tool.get())
|
|
|
|
tool->SetDisplayArea(viewport_left, viewport_top, viewport_width, viewport_height);
|
2010-05-16 08:39:11 +02:00
|
|
|
|
2011-01-23 08:47:59 +01:00
|
|
|
Refresh(false);
|
2006-01-16 22:02:54 +01:00
|
|
|
}
|
|
|
|
|
2007-01-23 05:42:08 +01:00
|
|
|
void VideoDisplay::OnSizeEvent(wxSizeEvent &event) {
|
2011-01-23 08:47:59 +01:00
|
|
|
UpdateSize();
|
2007-01-23 21:50:41 +01:00
|
|
|
event.Skip();
|
2007-01-23 05:42:08 +01:00
|
|
|
}
|
|
|
|
|
2006-01-16 22:02:54 +01:00
|
|
|
void VideoDisplay::OnMouseEvent(wxMouseEvent& event) {
|
2010-05-16 08:39:11 +02:00
|
|
|
assert(w > 0);
|
2008-03-07 00:27:54 +01:00
|
|
|
|
2006-01-16 22:02:54 +01:00
|
|
|
// Disable when playing
|
2011-01-16 08:17:08 +01:00
|
|
|
if (con->videoController->IsPlaying()) return;
|
2006-01-16 22:02:54 +01:00
|
|
|
|
2011-08-31 06:17:37 +02:00
|
|
|
if (event.ButtonDown())
|
2007-01-09 02:52:30 +01:00
|
|
|
SetFocus();
|
|
|
|
|
2011-11-06 18:18:20 +01:00
|
|
|
mouse_pos = event.GetPosition();
|
2011-08-31 06:17:37 +02:00
|
|
|
|
|
|
|
tool->OnMouseEvent(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
void VideoDisplay::OnMouseLeave(wxMouseEvent& event) {
|
2011-11-06 18:18:20 +01:00
|
|
|
mouse_pos = Vector2D::Bad();
|
2011-08-31 06:17:37 +02:00
|
|
|
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))
|
|
|
|
SetZoom (zoomValue + .125 * (wheel / event.GetWheelDelta()));
|
|
|
|
}
|
2011-08-31 06:17:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void VideoDisplay::OnContextMenu(wxContextMenuEvent&) {
|
|
|
|
if (!context_menu.get()) context_menu.reset(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) {
|
2011-11-06 18:18:20 +01:00
|
|
|
event.StopPropagation();
|
|
|
|
if (hotkey::check("Video", con, event.GetKeyCode(), event.GetUnicodeKey(), event.GetModifiers()))
|
|
|
|
return;
|
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);
|
2011-07-15 06:06:23 +02:00
|
|
|
zoomBox->SetValue(wxString::Format("%g%%", zoomValue * 100.));
|
2007-01-21 07:30:19 +01: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 &) {
|
2010-05-01 03:07:05 +02:00
|
|
|
wxString strValue = zoomBox->GetValue();
|
2011-09-28 21:43:11 +02:00
|
|
|
strValue.EndsWith("%", &strValue);
|
2010-05-01 03:07:05 +02:00
|
|
|
double value;
|
|
|
|
if (strValue.ToDouble(&value)) {
|
|
|
|
zoomValue = value / 100.;
|
|
|
|
UpdateSize();
|
|
|
|
}
|
|
|
|
}
|
2006-01-16 22:02:54 +01:00
|
|
|
|
2011-11-06 18:18:20 +01:00
|
|
|
void VideoDisplay::SetTool(VisualToolBase *new_tool) {
|
2010-05-16 08:39:11 +02:00
|
|
|
toolBar->ClearTools();
|
|
|
|
toolBar->Realize();
|
|
|
|
toolBar->Show(false);
|
|
|
|
|
2011-11-06 18:18:20 +01:00
|
|
|
tool.reset(new_tool);
|
|
|
|
tool->SetToolbar(toolBar);
|
|
|
|
tool->SetDisplayArea(viewport_left, viewport_top, viewport_width, viewport_height);
|
2010-05-16 08:39:11 +02:00
|
|
|
|
|
|
|
// Update size as the new typesetting tool may have changed the subtoolbar size
|
|
|
|
UpdateSize();
|
|
|
|
}
|
|
|
|
|
2011-11-06 18:18:20 +01:00
|
|
|
Vector2D VideoDisplay::GetMousePosition() const {
|
|
|
|
return mouse_pos ? tool->ToScriptCoords(mouse_pos) : mouse_pos;
|
2006-01-16 22:02:54 +01:00
|
|
|
}
|