Re-implemented drag in visual typesetting (thus completing the rewriting), fixed lots of other visual typesetting stuff, and maybe, JUST MAYBE, fixed the video playback issue on unix.

Originally committed to SVN as r1331.
This commit is contained in:
Rodrigo Braz Monteiro 2007-07-01 07:09:37 +00:00
parent 5b1a326804
commit 80573bcb78
7 changed files with 222 additions and 23 deletions

View File

@ -52,6 +52,7 @@
#include "video_display.h"
#include "video_context.h"
#include "video_provider.h"
#include "visual_tool.h"
#include "subtitles_provider.h"
#include "vfr.h"
#include "ass_file.h"
@ -372,9 +373,13 @@ void VideoContext::UpdateDisplays(bool full) {
// If not shown, don't update the display itself
if (!display->IsShownOnScreen()) continue;
// Update visual controls
if (display->visual) display->visual->Refresh();
// Update controls
display->Refresh();
display->Update();
//display->Refresh();
//display->Update();
display->Render();
}
}

View File

@ -37,6 +37,7 @@
///////////
// Headers
#include "visual_feature.h"
#include "gl_wrap.h"
///////////////
@ -45,18 +46,32 @@ VisualDraggableFeature::VisualDraggableFeature() {
type = DRAG_NONE;
x = -1;
y = -1;
value = 0;
layer = 0;
lineN = -1;
line = NULL;
}
/////////////////////
// Is mouse over it?
bool VisualDraggableFeature::IsMouseOver(int x,int y) {
bool VisualDraggableFeature::IsMouseOver(int mx,int my) {
if (type == DRAG_BIG_SQUARE) {
if (mx < x-8 || mx > x+8 || my < y-8 || my > y+8) return false;
return true;
}
return false;
}
////////////////
// Draw feature
void VisualDraggableFeature::Draw(bool highlighted) {
void VisualDraggableFeature::Draw(OpenGLWrapper *gl) {
wxASSERT(gl);
if (type == DRAG_BIG_SQUARE) {
gl->DrawRectangle(x-8,y-8,x+8,y+8);
gl->DrawLine(x,y-16,x,y+16);
gl->DrawLine(x-16,y,x+16,y);
}
}

View File

@ -42,6 +42,11 @@
#include "ass_dialogue.h"
//////////////
// Prototypes
class OpenGLWrapper;
////////////////
// Feature type
enum DraggableFeatureType {
@ -59,11 +64,14 @@ class VisualDraggableFeature {
public:
DraggableFeatureType type;
int x,y;
int index;
int layer; // Higher = above
int value;
AssDialogue *line;
int lineN;
bool IsMouseOver(int x,int y);
void Draw(bool highlighted);
void Draw(OpenGLWrapper *gl);
VisualDraggableFeature();
};

View File

@ -66,6 +66,15 @@ VisualTool::VisualTool(VideoDisplay *par) {
holding = false;
curDiag = NULL;
dragging = false;
curFeature = -1;
dragListOK = false;
mouseX = mouseY = -1;
if (CanDrag()) PopulateFeatureList();
frame_n = VideoContext::Get()->GetFrameN();
}
@ -105,8 +114,76 @@ void VisualTool::OnMouseEvent (wxMouseEvent &event) {
ctrlDown = event.m_controlDown;
altDown = event.m_altDown;
// Drag a feature
if (CanDrag()) {
// Populate list if needed
if (!dragListOK) {
PopulateFeatureList();
dragListOK = true;
}
// Start dragging
if (!dragging && leftClick) {
// Get a feature
curFeature = GetHighlightedFeature();
if (curFeature != -1) {
// Initialize drag
InitializeDrag(features[curFeature]);
VideoContext::Get()->grid->editBox->SetToLine(features[curFeature].lineN,true);
// Set start value
dragStartX = mx;
dragStartY = my;
dragOrigX = features[curFeature].x;
dragOrigY = features[curFeature].y;
// Set flags
dragging = true;
parent->CaptureMouse();
if (realTime) AssLimitToVisibleFilter::SetFrame(frame_n);
}
}
if (dragging) {
// Dragging
if (event.LeftIsDown()) {
// Update position
features[curFeature].x = (mx - dragStartX + dragOrigX);
features[curFeature].y = (my - dragStartY + dragOrigY);
// Update drag
UpdateDrag(features[curFeature]);
if (realTime) {
// Commit
CommitDrag(features[curFeature]);
grid->editBox->CommitText(true);
grid->CommitChanges(false,true);
}
}
// Release
else {
// Disable limiting
if (realTime) AssLimitToVisibleFilter::SetFrame(-1);
// Commit
CommitDrag(features[curFeature]);
grid->ass->FlagAsModified(_("visual typesetting"));
grid->CommitChanges(false,true);
// Clean up
dragging = false;
curFeature = -1;
parent->ReleaseMouse();
parent->SetFocus();
}
}
}
// Hold
if (CanHold()) {
if (!dragging && CanHold()) {
// Start holding
if (!holding && event.LeftIsDown()) {
// Get a dialogue
@ -180,6 +257,45 @@ AssDialogue* VisualTool::GetActiveDialogueLine() {
}
///////////////////////////
// Get feature under mouse
int VisualTool::GetHighlightedFeature() {
int highestLayerFound = -99999;
int bestMatch = -1;
for (size_t i=0;i<features.size();i++) {
if (features[i].IsMouseOver(mx,my) && features[i].layer > highestLayerFound) {
bestMatch = i;
highestLayerFound = features[i].layer;
}
}
return bestMatch;
}
/////////////////////
// Draw all features
void VisualTool::DrawAllFeatures() {
if (!dragListOK) {
PopulateFeatureList();
dragListOK = true;
}
int mouseOver = GetHighlightedFeature();
for (size_t i=0;i<features.size();i++) {
SetFillColour(colour[(signed)i == mouseOver ? 2 : 1],0.3f);
SetLineColour(colour[0]);
features[i].Draw(this);
}
}
///////////
// Refresh
void VisualTool::Refresh() {
frame_n = VideoContext::Get()->GetFrameN();
dragListOK = false;
}
////////////////////////
// Get position of line
void VisualTool::GetLinePosition(AssDialogue *diag,int &x, int &y) {

View File

@ -39,8 +39,10 @@
///////////
// Headers
#include <vector>
#include "video_display.h"
#include "gl_wrap.h"
#include "visual_feature.h"
//////////////
@ -61,6 +63,12 @@ protected:
bool holding;
AssDialogue *curDiag;
bool dragging;
int curFeature;
std::vector<VisualDraggableFeature> features;
int dragStartX,dragStartY,dragOrigX,dragOrigY;
bool dragListOK;
int w,h,sw,sh,mx,my;
int frame_n;
@ -79,19 +87,28 @@ protected:
void SetOverride(wxString tag,wxString value);
VideoDisplay *GetParent() { return parent; }
AssDialogue *GetActiveDialogueLine();
int GetHighlightedFeature();
void DrawAllFeatures();
virtual AssDialogue *GetActiveDialogueLine();
virtual bool CanHold() { return false; }
virtual void InitializeHold() {}
virtual void UpdateHold() {}
virtual void CommitHold() {}
virtual bool CanDrag() { return false; }
virtual void PopulateFeatureList() { wxLogMessage(_T("wtf?")); }
virtual void InitializeDrag(VisualDraggableFeature &feature) {}
virtual void UpdateDrag(VisualDraggableFeature &feature) {}
virtual void CommitDrag(VisualDraggableFeature &feature) {}
public:
int mouseX,mouseY;
void OnMouseEvent(wxMouseEvent &event);
virtual void Update()=0;
virtual void Draw()=0;
void Refresh();
VisualTool(VideoDisplay *parent);
virtual ~VisualTool();

View File

@ -45,6 +45,7 @@
#include "ass_file.h"
#include "ass_dialogue.h"
#include "utils.h"
#include "vfr.h"
///////////////
@ -67,28 +68,64 @@ void VisualToolDrag::Update() {
////////
// Draw
void VisualToolDrag::Draw() {
// Get line to draw
AssDialogue *line = GetActiveDialogueLine();
if (!line) return;
DrawAllFeatures();
}
/////////////////
// Start holding
void VisualToolDrag::InitializeHold() {
// Populate list
void VisualToolDrag::PopulateFeatureList() {
// Clear features
features.clear();
// Get video data
int numRows = VideoContext::Get()->grid->GetRows();
int framen = VideoContext::Get()->GetFrameN();
// For each line
AssDialogue *diag;
for (int i=numRows;--i>=0;) {
diag = VideoContext::Get()->grid->GetDialogue(i);
if (diag) {
// Line visible?
int f1 = VFR_Output.GetFrameAtTime(diag->Start.GetMS(),true);
int f2 = VFR_Output.GetFrameAtTime(diag->End.GetMS(),false);
if (f1 <= framen && f2 >= framen) {
// Get position
int lineX,lineY;
int torgx,torgy;
GetLinePosition(diag,lineX,lineY,torgx,torgy);
// Create \pos feature
VisualDraggableFeature feat;
feat.x = lineX;
feat.y = lineY;
feat.layer = 0;
feat.type = DRAG_BIG_SQUARE;
feat.value = 0;
feat.line = diag;
feat.lineN = i;
features.push_back(feat);
}
}
}
}
//////////////////
// Start dragging
void VisualToolDrag::InitializeDrag(VisualDraggableFeature &feature) {
}
///////////////
// Update hold
void VisualToolDrag::UpdateHold() {
// Update drag
void VisualToolDrag::UpdateDrag(VisualDraggableFeature &feature) {
}
///////////////
// Commit hold
void VisualToolDrag::CommitHold() {
// Commit drag
void VisualToolDrag::CommitDrag(VisualDraggableFeature &feature) {
SetOverride(_T("\\pos"),wxString::Format(_T("(%i,%i)"),feature.x,feature.y));
}

View File

@ -46,10 +46,11 @@
// Drag tool class
class VisualToolDrag : public VisualTool {
private:
bool CanHold() { return true; }
void InitializeHold();
void UpdateHold();
void CommitHold();
bool CanDrag() { return true; }
void PopulateFeatureList();
void InitializeDrag(VisualDraggableFeature &feature);
void UpdateDrag(VisualDraggableFeature &feature);
void CommitDrag(VisualDraggableFeature &feature);
public:
VisualToolDrag(VideoDisplay *parent);