mirror of
https://github.com/odrling/Aegisub
synced 2025-04-11 22:56:02 +02:00
Finished vector clip visual typesetting tool.
Originally committed to SVN as r1392.
This commit is contained in:
parent
b0e2ef92c2
commit
bd8b8ce4c5
@ -269,19 +269,27 @@ void Spline::MovePoint(int curveIndex,int point,wxPoint pos) {
|
|||||||
|
|
||||||
//////////////////////////////////////
|
//////////////////////////////////////
|
||||||
// Gets a list of points in the curve
|
// 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
|
// Prepare
|
||||||
points.clear();
|
points.clear();
|
||||||
|
pointCurve.clear();
|
||||||
Vector2D pt;
|
Vector2D pt;
|
||||||
bool isFirst = true;
|
bool isFirst = true;
|
||||||
|
int curve = 0;
|
||||||
|
|
||||||
// Generate points for each curve
|
// 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
|
// First point
|
||||||
if (isFirst) points.push_back(cur->p1);
|
if (isFirst) {
|
||||||
|
points.push_back(cur->p1);
|
||||||
|
pointCurve.push_back(curve);
|
||||||
|
}
|
||||||
|
|
||||||
// Line
|
// 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
|
// Bicubic
|
||||||
else if (cur->type == 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)
|
// Get t and t-1 (u)
|
||||||
float t = float(i)/float(steps);
|
float t = float(i)/float(steps);
|
||||||
points.push_back(cur->GetPoint(t));
|
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
|
// Insert a copy of the first point at the end
|
||||||
if (points.size()) {
|
if (points.size()) {
|
||||||
points.push_back(points[0]);
|
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
|
// t value and curve of the point closest to reference
|
||||||
void Spline::GetClosestParametricPoint(Vector2D reference,int &curve,float &t,Vector2D &pt) {
|
void Spline::GetClosestParametricPoint(Vector2D reference,int &curve,float &t,Vector2D &pt) {
|
||||||
// Has at least one curve?
|
// Has at least one curve?
|
||||||
curve = 0;
|
curve = -1;
|
||||||
t = 0.0f;
|
t = 0.0f;
|
||||||
if (curves.size() == 0) return;
|
if (curves.size() == 0) return;
|
||||||
|
|
||||||
|
@ -61,7 +61,7 @@ public:
|
|||||||
void MovePoint(int curveIndex,int point,wxPoint pos);
|
void MovePoint(int curveIndex,int point,wxPoint pos);
|
||||||
void Smooth(float smooth=1.0f);
|
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);
|
SplineCurve *GetCurve(int index);
|
||||||
|
|
||||||
void GetClosestParametricPoint(Vector2D reference,int &curve,float &t,Vector2D &point);
|
void GetClosestParametricPoint(Vector2D reference,int &curve,float &t,Vector2D &point);
|
||||||
|
@ -104,13 +104,15 @@ void VisualTool::OnMouseEvent (wxMouseEvent &event) {
|
|||||||
parent->GetClientSize(&w,&h);
|
parent->GetClientSize(&w,&h);
|
||||||
VideoContext::Get()->GetScriptSize(sw,sh);
|
VideoContext::Get()->GetScriptSize(sw,sh);
|
||||||
frame_n = VideoContext::Get()->GetFrameN();
|
frame_n = VideoContext::Get()->GetFrameN();
|
||||||
SubtitlesGrid *grid = VideoContext::Get()->grid;
|
|
||||||
bool realTime = Options.AsBool(_T("Video Visual Realtime"));
|
bool realTime = Options.AsBool(_T("Video Visual Realtime"));
|
||||||
|
|
||||||
// Mouse leaving control
|
// Mouse leaving control
|
||||||
if (event.Leaving()) {
|
if (event.Leaving()) {
|
||||||
mouseX = -1;
|
mouseX = -1;
|
||||||
mouseY = -1;
|
mouseY = -1;
|
||||||
|
mx = -1;
|
||||||
|
my = -1;
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Transformed mouse x/y
|
// Transformed mouse x/y
|
||||||
|
@ -84,10 +84,6 @@ VisualToolVectorClip::VisualToolVectorClip(VideoDisplay *parent,wxToolBar *_tool
|
|||||||
////////////////////
|
////////////////////
|
||||||
// Sub-tool pressed
|
// Sub-tool pressed
|
||||||
void VisualToolVectorClip::OnSubTool(wxCommandEvent &event) {
|
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);
|
SetMode(event.GetId() - BUTTON_DRAG);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -95,6 +91,10 @@ void VisualToolVectorClip::OnSubTool(wxCommandEvent &event) {
|
|||||||
////////////
|
////////////
|
||||||
// Set mode
|
// Set mode
|
||||||
void VisualToolVectorClip::SetMode(int _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;
|
mode = _mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -115,14 +115,8 @@ void VisualToolVectorClip::Draw() {
|
|||||||
|
|
||||||
// Parse vector
|
// Parse vector
|
||||||
std::vector<Vector2D> points;
|
std::vector<Vector2D> points;
|
||||||
spline.GetPointList(points);
|
std::vector<int> pointCurve;
|
||||||
|
spline.GetPointList(points,pointCurve);
|
||||||
// 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);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Draw stencil mask
|
// Draw stencil mask
|
||||||
glEnable(GL_STENCIL_TEST);
|
glEnable(GL_STENCIL_TEST);
|
||||||
@ -146,8 +140,26 @@ void VisualToolVectorClip::Draw() {
|
|||||||
DrawRectangle(0,0,sw,sh);
|
DrawRectangle(0,0,sw,sh);
|
||||||
glDisable(GL_STENCIL_TEST);
|
glDisable(GL_STENCIL_TEST);
|
||||||
|
|
||||||
// Draw features
|
// Get current position information for modes 3 and 4
|
||||||
DrawAllFeatures();
|
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
|
// Draw lines connecting the bicubic features
|
||||||
SetLineColour(colour[3],0.9f,1);
|
SetLineColour(colour[3],0.9f,1);
|
||||||
@ -158,6 +170,9 @@ void VisualToolVectorClip::Draw() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Draw features
|
||||||
|
DrawAllFeatures();
|
||||||
|
|
||||||
// Draw preview of inserted line
|
// Draw preview of inserted line
|
||||||
if (mode == 1 || mode == 2) {
|
if (mode == 1 || mode == 2) {
|
||||||
if (spline.curves.size()) {
|
if (spline.curves.size()) {
|
||||||
@ -169,10 +184,7 @@ void VisualToolVectorClip::Draw() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Draw preview of insert point
|
// Draw preview of insert point
|
||||||
if (mode == 4) {
|
if (mode == 4) DrawCircle(pt.x,pt.y,4);
|
||||||
Vector2D p1 = spline.GetClosestPoint(Vector2D(mx,my));
|
|
||||||
DrawCircle(p1.x,p1.y,4);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -241,7 +253,7 @@ void VisualToolVectorClip::PopulateFeatureList() {
|
|||||||
/////////////
|
/////////////
|
||||||
// Can drag?
|
// Can drag?
|
||||||
bool VisualToolVectorClip::DragEnabled() {
|
bool VisualToolVectorClip::DragEnabled() {
|
||||||
return mode <= 2;
|
return mode <= 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -330,6 +342,22 @@ void VisualToolVectorClip::InitializeHold() {
|
|||||||
|
|
||||||
// Convert
|
// Convert
|
||||||
if (mode == 3) {
|
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
|
// Insert
|
||||||
@ -354,11 +382,11 @@ void VisualToolVectorClip::InitializeHold() {
|
|||||||
// Commit
|
// Commit
|
||||||
SetOverride(_T("\\clip"),_T("(") + spline.EncodeToASS() + _T(")"));
|
SetOverride(_T("\\clip"),_T("(") + spline.EncodeToASS() + _T(")"));
|
||||||
Commit(true);
|
Commit(true);
|
||||||
holding = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Freehand
|
// Freehand
|
||||||
else if (mode == 6 || mode == 7) {
|
else if (mode == 6 || mode == 7) {
|
||||||
|
features.clear();
|
||||||
spline.curves.clear();
|
spline.curves.clear();
|
||||||
lastX = -100000;
|
lastX = -100000;
|
||||||
lastY = -100000;
|
lastY = -100000;
|
||||||
@ -424,6 +452,9 @@ void VisualToolVectorClip::CommitHold() {
|
|||||||
|
|
||||||
// Save it
|
// Save it
|
||||||
if (mode != 3 && mode != 4) SetOverride(_T("\\clip"),_T("(") + spline.EncodeToASS() + _T(")"));
|
if (mode != 3 && mode != 4) SetOverride(_T("\\clip"),_T("(") + spline.EncodeToASS() + _T(")"));
|
||||||
|
|
||||||
|
// End freedraw
|
||||||
|
if (mode == 6 || mode == 7) SetMode(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user