Detached Video display mostly works.

Originally committed to SVN as r883.
This commit is contained in:
Rodrigo Braz Monteiro 2007-01-23 06:32:16 +00:00
parent c232b625ff
commit 8231034cb1
9 changed files with 103 additions and 54 deletions

View File

@ -97,6 +97,7 @@ Please visit http://aegisub.net to download latest version
- Added an audio clip export by right clicking on a line. (Dansolo)
- Added a clear button for shifting history. (Dansolo)
- Fixed Custom Aspect Ratio input. (Dansolo)
- Made the video display detachable. (AMZ)
= 1.10 beta - 2006.08.07 ===========================

View File

@ -40,6 +40,7 @@
#include "dialog_detached_video.h"
#include "video_box.h"
#include "video_context.h"
#include "video_display.h"
#include "frame_main.h"
@ -56,11 +57,13 @@ DialogDetachedVideo::DialogDetachedVideo(FrameMain *par)
// Video area;
videoBox = new VideoBox(panel);
videoBox->videoDisplay->freeSize = true;
// Set sizer
wxSizer *mainSizer = new wxBoxSizer(wxVERTICAL);
mainSizer->Add(videoBox,1,wxEXPAND | wxALL,5);
panel->SetSizer(mainSizer);
mainSizer->SetSizeHints(this);
// Update
parent->SetDisplayMode(0,-1);

View File

@ -499,7 +499,7 @@ void FrameMain::DeInitContents() {
// Update toolbar
void FrameMain::UpdateToolbar() {
// Collect flags
bool isVideo = showVideo;
bool isVideo = VideoContext::Get()->IsLoaded();
HasSelection = true;
int selRows = SubsBox->GetNumberSelection();
@ -838,7 +838,7 @@ void FrameMain::SynchronizeProject(bool fromSubs) {
if (curSubsVideo != _T("")) {
LoadVideo(curSubsVideo);
if (VideoContext::Get()->IsLoaded()) {
videoBox->videoDisplay->SetAspectRatio(videoAr,videoArValue);
VideoContext::Get()->SetAspectRatio(videoAr,videoArValue);
videoBox->videoDisplay->SetZoomPos(videoZoom-1);
VideoContext::Get()->JumpToFrame(videoPos);
}
@ -901,8 +901,8 @@ void FrameMain::SynchronizeProject(bool fromSubs) {
seekpos = wxString::Format(_T("%i"),videoBox->videoDisplay->ControlSlider->GetValue());
zoom = wxString::Format(_T("%i"),videoBox->videoDisplay->zoomBox->GetSelection()+1);
int arType = videoBox->videoDisplay->GetAspectRatioType();
if (arType == 4) ar = wxString(_T("c")) + FloatToString(videoBox->videoDisplay->GetAspectRatioValue());
int arType = VideoContext::Get()->GetAspectRatioType();
if (arType == 4) ar = wxString(_T("c")) + FloatToString(VideoContext::Get()->GetAspectRatioValue());
else ar = wxString::Format(_T("%i"),arType);
}

View File

@ -298,7 +298,7 @@ void FrameMain::OnMenuOpen (wxMenuEvent &event) {
MenuBar->Enable(Menu_Video_Save_Keyframes,VideoContext::Get()->KeyFramesLoaded());
// Set AR radio
int arType = videoBox->videoDisplay->GetAspectRatioType();
int arType = VideoContext::Get()->GetAspectRatioType();
MenuBar->Check(Menu_Video_AR_Default,false);
MenuBar->Check(Menu_Video_AR_Full,false);
MenuBar->Check(Menu_Video_AR_Wide,false);
@ -1191,7 +1191,7 @@ void FrameMain::OnReplace(wxCommandEvent &event) {
// Change aspect ratio to default
void FrameMain::OnSetARDefault (wxCommandEvent &event) {
VideoContext::Get()->Stop();
videoBox->videoDisplay->SetAspectRatio(0);
VideoContext::Get()->SetAspectRatio(0);
SetDisplayMode(-1,-1);
}
@ -1200,7 +1200,7 @@ void FrameMain::OnSetARDefault (wxCommandEvent &event) {
// Change aspect ratio to fullscreen
void FrameMain::OnSetARFull (wxCommandEvent &event) {
VideoContext::Get()->Stop();
videoBox->videoDisplay->SetAspectRatio(1);
VideoContext::Get()->SetAspectRatio(1);
SetDisplayMode(-1,-1);
}
@ -1209,7 +1209,7 @@ void FrameMain::OnSetARFull (wxCommandEvent &event) {
// Change aspect ratio to widescreen
void FrameMain::OnSetARWide (wxCommandEvent &event) {
VideoContext::Get()->Stop();
videoBox->videoDisplay->SetAspectRatio(2);
VideoContext::Get()->SetAspectRatio(2);
SetDisplayMode(-1,-1);
}
@ -1218,7 +1218,7 @@ void FrameMain::OnSetARWide (wxCommandEvent &event) {
// Change aspect ratio to 2:35
void FrameMain::OnSetAR235 (wxCommandEvent &event) {
VideoContext::Get()->Stop();
videoBox->videoDisplay->SetAspectRatio(3);
VideoContext::Get()->SetAspectRatio(3);
SetDisplayMode(-1,-1);
}
@ -1229,7 +1229,7 @@ void FrameMain::OnSetARCustom (wxCommandEvent &event) {
// Get text
VideoContext::Get()->Stop();
wxString value = wxGetTextFromUser(_("Enter aspect ratio in either decimal (e.g. 2.35) or fractional (e.g. 16:9) form. Enter a value like 853x480 to set a specific resolution."),_("Enter aspect ratio"),FloatToString(videoBox->videoDisplay->GetAspectRatioValue()));
wxString value = wxGetTextFromUser(_("Enter aspect ratio in either decimal (e.g. 2.35) or fractional (e.g. 16:9) form. Enter a value like 853x480 to set a specific resolution."),_("Enter aspect ratio"),FloatToString(VideoContext::Get()->GetAspectRatioValue()));
if (value.IsEmpty()) return;
value.MakeLower();
@ -1268,7 +1268,7 @@ void FrameMain::OnSetARCustom (wxCommandEvent &event) {
// Set value
else {
videoBox->videoDisplay->SetAspectRatio(4,numval);
VideoContext::Get()->SetAspectRatio(4,numval);
SetDisplayMode(-1,-1);
}
}

View File

@ -103,6 +103,8 @@ VideoContext::VideoContext() {
keyFramesLoaded = false;
overKeyFramesLoaded = false;
frame_n = 0;
arType = 0;
arValue = 1.0;
isPlaying = false;
threaded = Options.AsBool(_T("Threaded Video"));
nextFrame = -1;
@ -415,7 +417,7 @@ GLuint VideoContext::GetFrameAsTexture(int n) {
// Set context
GetGLContext(displayList.front())->SetCurrent(*displayList.front());
glEnable(GL_TEXTURE_2D);
if (glGetError() != 0) throw _T("Error enabling texturing.");
if (glGetError() != 0) throw _T("Error enabling texture.");
if (lastTex == 0) {
// Enable
@ -700,3 +702,29 @@ bool VideoContext::OverKeyFramesLoaded() {
bool VideoContext::KeyFramesLoaded() {
return overKeyFramesLoaded || keyFramesLoaded;
}
//////////////////////////
// Calculate aspect ratio
double VideoContext::GetARFromType(int type) {
if (type == 0) return (double)VideoContext::Get()->GetWidth()/(double)VideoContext::Get()->GetHeight();
if (type == 1) return 4.0/3.0;
if (type == 2) return 16.0/9.0;
if (type == 3) return 2.35;
return 1.0; //error
}
/////////////////////
// Sets aspect ratio
void VideoContext::SetAspectRatio(int _type, double value) {
// Get value
if (_type != 4) value = GetARFromType(_type);
if (value < 0.5) value = 0.5;
if (value > 5.0) value = 5.0;
// Set
arType = _type;
arValue = value;
UpdateDisplays(true);
}

View File

@ -102,6 +102,9 @@ private:
int length;
double fps;
double arValue;
int arType;
void UnloadTexture();
void OnPlayTimer(wxTimerEvent &event);
@ -139,6 +142,11 @@ public:
double GetFPS() { return fps; }
void SetFPS(double _fps) { fps = _fps; }
double GetARFromType(int type);
void SetAspectRatio(int type,double value=1.0);
int GetAspectRatioType() { return arType; }
double GetAspectRatioValue() { return arValue; }
void SetVideo(const wxString &filename);
void Reset();

View File

@ -103,9 +103,8 @@ VideoDisplay::VideoDisplay(wxWindow* parent, wxWindowID id, const wxPoint& pos,
ControlSlider = NULL;
PositionDisplay = NULL;
origSize = size;
arType = 0;
arValue = 1.0;
zoomValue = 1.0;
freeSize = false;
visual = new VideoDisplayVisual(this);
tracker = NULL;
#if USE_FEXTRACKER == 1
@ -143,11 +142,39 @@ void VideoDisplay::Render() {
pw = context->GetWidth();
ph = context->GetHeight();
// Freesized transform
dx1 = 0;
dy1 = 0;
dx2 = w;
dy2 = h;
if (freeSize) {
glClearColor(0,0,0,0);
glClear(GL_COLOR_BUFFER_BIT);
float thisAr = float(w)/float(h);
float vidAr;
if (context->GetAspectRatioType() == 0) vidAr = float(pw)/float(ph);
else vidAr = context->GetAspectRatioValue();
// Window is wider than video, blackbox left/right
if (thisAr - vidAr > 0.01f) {
int delta = (w-vidAr*h);
dx1 += delta/2;
dx2 -= delta;
}
// Video is wider than window, blackbox top/bottom
else if (vidAr - thisAr > 0.01f) {
int delta = (h-w/vidAr);
dy1 += delta/2;
dy2 -= delta;
}
}
// Set viewport
glEnable(GL_TEXTURE_2D);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glViewport(0,0,w,h);
glViewport(dx1,dy1,dx2,dy2);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0.0f,sw,sh,0.0f,-1000.0f,1000.0f);
@ -209,13 +236,17 @@ void VideoDisplay::Render() {
///////////////
// Update size
void VideoDisplay::UpdateSize() {
// Free size?
if (freeSize) return;
// Loaded?
if (!VideoContext::Get()->IsLoaded()) return;
VideoContext *con = VideoContext::Get();
if (!con->IsLoaded()) return;
// Get size
if (arType == 0) w = VideoContext::Get()->GetWidth() * zoomValue;
else w = VideoContext::Get()->GetHeight() * zoomValue * arValue;
h = VideoContext::Get()->GetHeight() * zoomValue;
if (con->GetAspectRatioType() == 0) w = con->GetWidth() * zoomValue;
else w = con->GetHeight() * zoomValue * con->GetAspectRatioValue();
h = con->GetHeight() * zoomValue;
int _w,_h;
// Set the size for this control
@ -330,32 +361,6 @@ void VideoDisplay::SetZoomPos(int value) {
}
//////////////////////////
// Calculate aspect ratio
double VideoDisplay::GetARFromType(int type) {
if (type == 0) return (double)VideoContext::Get()->GetWidth()/(double)VideoContext::Get()->GetHeight();
if (type == 1) return 4.0/3.0;
if (type == 2) return 16.0/9.0;
if (type == 3) return 2.35;
return 1.0; //error
}
/////////////////////
// Sets aspect ratio
void VideoDisplay::SetAspectRatio(int _type, double value) {
// Get value
if (_type != 4) value = GetARFromType(_type);
if (value < 0.5) value = 0.5;
if (value > 5.0) value = 5.0;
// Set
arType = _type;
arValue = value;
UpdateSize();
}
////////////////////////////
// Updates position display
void VideoDisplay::UpdatePositionDisplay() {
@ -478,3 +483,12 @@ void VideoDisplay::DrawText( wxPoint Pos, wxString text ) {
//dc.DrawText(text,Pos.x,Pos.y);
}
/////////////////////////////
// Convert mouse coordinates
void VideoDisplay::ConvertMouseCoords(int &x,int &y) {
int w,h;
GetClientSize(&w,&h);
x = (x-dx1)*w/dx2;
y = (y-dy1)*h/dy2;
}

View File

@ -69,6 +69,7 @@ class VideoDisplay: public wxGLCanvas {
private:
wxSize origSize;
int w,h;
int dx1,dx2,dy1,dy2;
void OnPaint(wxPaintEvent& event);
void OnKey(wxKeyEvent &event);
@ -85,9 +86,8 @@ public:
VideoDisplayFexTracker *tracker;
VideoBox *box;
double arValue;
int arType;
double zoomValue;
bool freeSize;
VideoSlider *ControlSlider;
wxComboBox *zoomBox;
@ -100,6 +100,7 @@ public:
void Render();
void ConvertMouseCoords(int &x,int &y);
void DrawText(wxPoint Pos, wxString Text);
void UpdatePositionDisplay();
void UpdateSize();
@ -107,11 +108,6 @@ public:
void SetZoomPos(int pos);
void UpdateSubsRelativeTime();
double GetARFromType(int type);
void SetAspectRatio(int type,double value=1.0);
int GetAspectRatioType() { return arType; }
double GetAspectRatioValue() { return arValue; }
DECLARE_EVENT_TABLE()
};

View File

@ -745,14 +745,13 @@ void VideoDisplayVisual::OnMouseEvent (wxMouseEvent &event) {
// Coords
int x = event.GetX();
int y = event.GetY();
parent->ConvertMouseCoords(x,y);
int w,h;
parent->GetClientSize(&w,&h);
int orgx = -1;
int orgy = -1;
int sw,sh;
VideoContext::Get()->GetScriptSize(sw,sh);
int mx = x * VideoContext::Get()->GetWidth() / w;
int my = y * VideoContext::Get()->GetHeight() / h;
int frame_n = VideoContext::Get()->GetFrameN();
SubtitlesGrid *grid = VideoContext::Get()->grid;
bool hasOverlay = false;