Add support for the scale parameter of vector clips. Closes #1415.

Originally committed to SVN as r6364.
This commit is contained in:
Thomas Goyne 2012-01-26 00:29:08 +00:00
parent 214079af58
commit d001d66b12
4 changed files with 54 additions and 15 deletions

View file

@ -47,10 +47,26 @@
#include "utils.h"
#include "visual_tool.h"
Spline::Spline(const VisualToolBase &scale) : scale(scale) {
Spline::Spline(const VisualToolBase &tl)
: coord_translator(tl)
, scale(1)
, raw_scale(1)
{
}
Vector2D Spline::ToScript(Vector2D vec) const {
return coord_translator.ToScriptCoords(vec) * scale;
}
Vector2D Spline::FromScript(Vector2D vec) const {
return coord_translator.FromScriptCoords(vec / scale);
}
void Spline::SetScale(int new_scale) {
raw_scale = new_scale;
scale = 1 << (raw_scale - 1);
}
/// @brief Encode to ASS
wxString Spline::EncodeToASS() {
wxString result;
result.reserve(size() * 10);
@ -63,7 +79,7 @@ wxString Spline::EncodeToASS() {
result += "m ";
last = 'm';
}
result += scale.ToScriptCoords(cur->p1).DStr(' ');
result += ToScript(cur->p1).DStr(' ');
break;
case SplineCurve::LINE:
@ -71,7 +87,7 @@ wxString Spline::EncodeToASS() {
result += "l ";
last = 'l';
}
result += scale.ToScriptCoords(cur->p2).DStr(' ');
result += ToScript(cur->p2).DStr(' ');
break;
case SplineCurve::BICUBIC:
@ -79,9 +95,9 @@ wxString Spline::EncodeToASS() {
result += "b ";
last = 'b';
}
result += scale.ToScriptCoords(cur->p2).DStr(' ') + " ";
result += scale.ToScriptCoords(cur->p3).DStr(' ') + " ";
result += scale.ToScriptCoords(cur->p4).DStr(' ');
result += ToScript(cur->p2).DStr(' ') + " ";
result += ToScript(cur->p3).DStr(' ') + " ";
result += ToScript(cur->p4).DStr(' ');
break;
default: break;
@ -110,7 +126,7 @@ void Spline::DecodeFromASS(wxString str) {
// Move
if (stack.size() == 2 && command == 'm') {
pt = scale.FromScriptCoords(Vector2D(stack[0], stack[1]));
pt = FromScript(Vector2D(stack[0], stack[1]));
stack.clear();
push_back(pt);
@ -118,7 +134,7 @@ void Spline::DecodeFromASS(wxString str) {
// Line
if (stack.size() == 2 && command == 'l') {
SplineCurve curve(pt, scale.FromScriptCoords(Vector2D(stack[0], stack[1])));
SplineCurve curve(pt, FromScript(Vector2D(stack[0], stack[1])));
push_back(curve);
pt = curve.p2;
@ -128,9 +144,9 @@ void Spline::DecodeFromASS(wxString str) {
// Bicubic
else if (stack.size() == 6 && command == 'b') {
SplineCurve curve(pt,
scale.FromScriptCoords(Vector2D(stack[0], stack[1])),
scale.FromScriptCoords(Vector2D(stack[2], stack[3])),
scale.FromScriptCoords(Vector2D(stack[4], stack[5])));
FromScript(Vector2D(stack[0], stack[1])),
FromScript(Vector2D(stack[2], stack[3])),
FromScript(Vector2D(stack[4], stack[5])));
push_back(curve);
pt = curve.p4;

View file

@ -49,7 +49,17 @@ class VisualToolBase;
/// @class Spline
/// @brief DOCME
class Spline : private std::list<SplineCurve> {
const VisualToolBase &scale;
/// Visual tool to do the conversion between script and video pixels
const VisualToolBase &coord_translator;
/// Spline scale
int scale;
int raw_scale;
/// Video coordinates -> Script coordinates
Vector2D ToScript(Vector2D vec) const;
/// Script coordinates -> Video coordinates
Vector2D FromScript(Vector2D vec) const;
public:
Spline(const VisualToolBase &scale);
@ -59,6 +69,12 @@ public:
/// Decode an ASS vector drawing
void DecodeFromASS(wxString str);
/// Set the scale
/// @param new_scale Power-of-two to scale coordinates by
void SetScale(int new_scale);
/// Get the current scale
int GetScale() const { return raw_scale; }
/// @brief Moves a specific point in the spline
/// @param curve Curve which the point is in
/// @param point Index in the curve

View file

@ -553,7 +553,7 @@ wxString VisualToolBase::GetLineVectorClip(AssDialogue *diag, int &scale, bool &
(*tag)[0]->Get<int>(), (*tag)[3]->Get<int>());
}
if (tag) {
scale = (*tag)[0]->Get<int>(scale);
scale = std::max((*tag)[0]->Get(scale), 1);
return (*tag)[1]->Get<wxString>("");
}

View file

@ -196,7 +196,13 @@ void VisualToolVectorClip::MakeFeatures() {
}
void VisualToolVectorClip::Save() {
SetOverride(active_line, inverse ? "\\iclip" : "\\clip", "(" + spline.EncodeToASS() + ")");
wxString tag = inverse ? "\\iclip" : "\\clip";
wxString value = "(";
if (spline.GetScale() != 1)
value += wxString::Format("%d,", spline.GetScale());
value += spline.EncodeToASS() + ")";
SetOverride(active_line, tag, value);
}
void VisualToolVectorClip::UpdateDrag(feature_iterator feature) {
@ -382,6 +388,7 @@ void VisualToolVectorClip::DoRefresh() {
wxString vect;
int scale;
vect = GetLineVectorClip(active_line, scale, inverse);
spline.SetScale(scale);
spline.DecodeFromASS(vect);
MakeFeatures();