From bd8b8ce4c51f17944cb47751cf1b042e3f22baa7 Mon Sep 17 00:00:00 2001 From: Rodrigo Braz Monteiro Date: Sun, 8 Jul 2007 07:22:09 +0000 Subject: [PATCH] Finished vector clip visual typesetting tool. Originally committed to SVN as r1392. --- aegisub/spline.cpp | 20 ++++++-- aegisub/spline.h | 2 +- aegisub/visual_tool.cpp | 4 +- aegisub/visual_tool_vector_clip.cpp | 71 +++++++++++++++++++++-------- 4 files changed, 70 insertions(+), 27 deletions(-) diff --git a/aegisub/spline.cpp b/aegisub/spline.cpp index 946234514..d5c26d7b2 100644 --- a/aegisub/spline.cpp +++ b/aegisub/spline.cpp @@ -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 &points) { +void Spline::GetPointList(std::vector &points,std::vector &pointCurve) { // Prepare points.clear(); + pointCurve.clear(); Vector2D pt; bool isFirst = true; + int curve = 0; // Generate points for each curve - for (std::list::iterator cur = curves.begin();cur!=curves.end();cur++) { + for (std::list::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 &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 &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 &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; diff --git a/aegisub/spline.h b/aegisub/spline.h index 8ff869da2..a497fc22c 100644 --- a/aegisub/spline.h +++ b/aegisub/spline.h @@ -61,7 +61,7 @@ public: void MovePoint(int curveIndex,int point,wxPoint pos); void Smooth(float smooth=1.0f); - void GetPointList(std::vector &points); + void GetPointList(std::vector &points,std::vector &pointCurve); SplineCurve *GetCurve(int index); void GetClosestParametricPoint(Vector2D reference,int &curve,float &t,Vector2D &point); diff --git a/aegisub/visual_tool.cpp b/aegisub/visual_tool.cpp index fa8ae32d3..a016754b7 100644 --- a/aegisub/visual_tool.cpp +++ b/aegisub/visual_tool.cpp @@ -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 diff --git a/aegisub/visual_tool_vector_clip.cpp b/aegisub/visual_tool_vector_clip.cpp index c873f6ebe..750643058 100644 --- a/aegisub/visual_tool_vector_clip.cpp +++ b/aegisub/visual_tool_vector_clip.cpp @@ -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;iToggleTool(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;iToggleTool(i,i == _mode + BUTTON_DRAG); + } mode = _mode; } @@ -115,14 +115,8 @@ void VisualToolVectorClip::Draw() { // Parse vector std::vector points; - spline.GetPointList(points); - - // Draw lines - SetLineColour(colour[3],1.0f,2); - SetFillColour(colour[3],0.0f); - for (size_t i=1;i 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;itype == 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); }