Finished vector clip visual typesetting tool.

Originally committed to SVN as r1392.
This commit is contained in:
Rodrigo Braz Monteiro 2007-07-08 07:22:09 +00:00
parent b0e2ef92c2
commit bd8b8ce4c5
4 changed files with 70 additions and 27 deletions

View File

@ -269,19 +269,27 @@ void Spline::MovePoint(int curveIndex,int point,wxPoint pos) {
//////////////////////////////////////
// Gets a list of points in the curve
void Spline::GetPointList(std::vector<Vector2D> &points) {
void Spline::GetPointList(std::vector<Vector2D> &points,std::vector<int> &pointCurve) {
// Prepare
points.clear();
pointCurve.clear();
Vector2D pt;
bool isFirst = true;
int curve = 0;
// Generate points for each curve
for (std::list<SplineCurve>::iterator cur = curves.begin();cur!=curves.end();cur++) {
for (std::list<SplineCurve>::iterator cur = curves.begin();cur!=curves.end();cur++,curve++) {
// First point
if (isFirst) points.push_back(cur->p1);
if (isFirst) {
points.push_back(cur->p1);
pointCurve.push_back(curve);
}
// Line
if (cur->type == CURVE_LINE) points.push_back(cur->p2);
if (cur->type == CURVE_LINE) {
points.push_back(cur->p2);
pointCurve.push_back(curve);
}
// Bicubic
else if (cur->type == CURVE_BICUBIC) {
@ -300,6 +308,7 @@ void Spline::GetPointList(std::vector<Vector2D> &points) {
// Get t and t-1 (u)
float t = float(i)/float(steps);
points.push_back(cur->GetPoint(t));
pointCurve.push_back(curve);
}
}
}
@ -307,6 +316,7 @@ void Spline::GetPointList(std::vector<Vector2D> &points) {
// Insert a copy of the first point at the end
if (points.size()) {
points.push_back(points[0]);
pointCurve.push_back(curve);
}
}
@ -315,7 +325,7 @@ void Spline::GetPointList(std::vector<Vector2D> &points) {
// t value and curve of the point closest to reference
void Spline::GetClosestParametricPoint(Vector2D reference,int &curve,float &t,Vector2D &pt) {
// Has at least one curve?
curve = 0;
curve = -1;
t = 0.0f;
if (curves.size() == 0) return;

View File

@ -61,7 +61,7 @@ public:
void MovePoint(int curveIndex,int point,wxPoint pos);
void Smooth(float smooth=1.0f);
void GetPointList(std::vector<Vector2D> &points);
void GetPointList(std::vector<Vector2D> &points,std::vector<int> &pointCurve);
SplineCurve *GetCurve(int index);
void GetClosestParametricPoint(Vector2D reference,int &curve,float &t,Vector2D &point);

View File

@ -104,13 +104,15 @@ void VisualTool::OnMouseEvent (wxMouseEvent &event) {
parent->GetClientSize(&w,&h);
VideoContext::Get()->GetScriptSize(sw,sh);
frame_n = VideoContext::Get()->GetFrameN();
SubtitlesGrid *grid = VideoContext::Get()->grid;
bool realTime = Options.AsBool(_T("Video Visual Realtime"));
// Mouse leaving control
if (event.Leaving()) {
mouseX = -1;
mouseY = -1;
mx = -1;
my = -1;
return;
}
// Transformed mouse x/y

View File

@ -84,10 +84,6 @@ VisualToolVectorClip::VisualToolVectorClip(VideoDisplay *parent,wxToolBar *_tool
////////////////////
// Sub-tool pressed
void VisualToolVectorClip::OnSubTool(wxCommandEvent &event) {
// Make sure clicked is checked and everything else isn't. (Yes, this is radio behavior, but the separators won't let me use it)
for (int i=BUTTON_DRAG;i<BUTTON_LAST;i++) {
toolBar->ToggleTool(i,i == event.GetId());
}
SetMode(event.GetId() - BUTTON_DRAG);
}
@ -95,6 +91,10 @@ void VisualToolVectorClip::OnSubTool(wxCommandEvent &event) {
////////////
// Set mode
void VisualToolVectorClip::SetMode(int _mode) {
// Make sure clicked is checked and everything else isn't. (Yes, this is radio behavior, but the separators won't let me use it)
for (int i=BUTTON_DRAG;i<BUTTON_LAST;i++) {
toolBar->ToggleTool(i,i == _mode + BUTTON_DRAG);
}
mode = _mode;
}
@ -115,14 +115,8 @@ void VisualToolVectorClip::Draw() {
// Parse vector
std::vector<Vector2D> points;
spline.GetPointList(points);
// Draw lines
SetLineColour(colour[3],1.0f,2);
SetFillColour(colour[3],0.0f);
for (size_t i=1;i<points.size();i++) {
DrawLine(points[i-1].x,points[i-1].y,points[i].x,points[i].y);
}
std::vector<int> pointCurve;
spline.GetPointList(points,pointCurve);
// Draw stencil mask
glEnable(GL_STENCIL_TEST);
@ -146,8 +140,26 @@ void VisualToolVectorClip::Draw() {
DrawRectangle(0,0,sw,sh);
glDisable(GL_STENCIL_TEST);
// Draw features
DrawAllFeatures();
// Get current position information for modes 3 and 4
Vector2D pt;
int highCurve = -1;
if (mode == 3 || mode == 4) {
float t;
spline.GetClosestParametricPoint(Vector2D(mx,my),highCurve,t,pt);
}
// Draw lines
SetFillColour(colour[3],0.0f);
SetLineColour(colour[3],1.0f,2);
int col = 3;
for (size_t i=1;i<points.size();i++) {
int useCol = pointCurve[i] == highCurve && curFeature == -1 ? 2 : 3;
if (col != useCol) {
col = useCol;
SetLineColour(colour[col],1.0f,2);
}
DrawLine(points[i-1].x,points[i-1].y,points[i].x,points[i].y);
}
// Draw lines connecting the bicubic features
SetLineColour(colour[3],0.9f,1);
@ -158,6 +170,9 @@ void VisualToolVectorClip::Draw() {
}
}
// Draw features
DrawAllFeatures();
// Draw preview of inserted line
if (mode == 1 || mode == 2) {
if (spline.curves.size()) {
@ -169,10 +184,7 @@ void VisualToolVectorClip::Draw() {
}
// Draw preview of insert point
if (mode == 4) {
Vector2D p1 = spline.GetClosestPoint(Vector2D(mx,my));
DrawCircle(p1.x,p1.y,4);
}
if (mode == 4) DrawCircle(pt.x,pt.y,4);
}
@ -241,7 +253,7 @@ void VisualToolVectorClip::PopulateFeatureList() {
/////////////
// Can drag?
bool VisualToolVectorClip::DragEnabled() {
return mode <= 2;
return mode <= 4;
}
@ -330,6 +342,22 @@ void VisualToolVectorClip::InitializeHold() {
// Convert
if (mode == 3) {
SplineCurve *c1 = spline.GetCurve(curve);
if (!c1) {
}
else {
if (c1->type == CURVE_LINE) {
c1->type = CURVE_BICUBIC;
c1->p4 = c1->p2;
c1->p2 = c1->p1 * 0.75 + c1->p4 * 0.25;
c1->p3 = c1->p1 * 0.25 + c1->p4 * 0.75;
}
else if (c1->type == CURVE_BICUBIC) {
c1->type = CURVE_LINE;
c1->p2 = c1->p4;
}
}
}
// Insert
@ -354,11 +382,11 @@ void VisualToolVectorClip::InitializeHold() {
// Commit
SetOverride(_T("\\clip"),_T("(") + spline.EncodeToASS() + _T(")"));
Commit(true);
holding = false;
}
// Freehand
else if (mode == 6 || mode == 7) {
features.clear();
spline.curves.clear();
lastX = -100000;
lastY = -100000;
@ -424,6 +452,9 @@ void VisualToolVectorClip::CommitHold() {
// Save it
if (mode != 3 && mode != 4) SetOverride(_T("\\clip"),_T("(") + spline.EncodeToASS() + _T(")"));
// End freedraw
if (mode == 6 || mode == 7) SetMode(0);
}