Move all userdata in VisualDraggableFeature not used by VisualTool to subclasses specific to each tool that needs userdata.

Originally committed to SVN as r4321.
This commit is contained in:
Thomas Goyne 2010-05-20 08:55:52 +00:00
parent a282393b47
commit 8ff2728322
9 changed files with 149 additions and 129 deletions

View file

@ -44,12 +44,9 @@ VisualDraggableFeature::VisualDraggableFeature()
, x(INT_MIN)
, y(INT_MIN)
, layer(0)
, value(0)
, value2(0)
, line(NULL)
, lineN(-1)
{
for (int i=0;i<4;i++) brother[i] = -1;
}
bool VisualDraggableFeature::IsMouseOver(int mx,int my) {

View file

@ -77,14 +77,9 @@ public:
int layer; /// Layer; Higher = above
int value; /// userdata; used by drag tool for time
int value2; /// more userdata
AssDialogue* line; /// The dialogue line this feature is for
int lineN; /// The line's index in the file
int brother[4]; /// userdata; generally indexes of other features in an array
/// @brief Is the given point over this feature?
/// @param mx x coordinate to test
/// @param my y coordinate to test

View file

@ -61,6 +61,9 @@
#include "video_provider_manager.h"
#include "visual_feature.h"
#include "visual_tool.h"
#include "visual_tool_clip.h"
#include "visual_tool_drag.h"
#include "visual_tool_vector_clip.h"
const wxColour IVisualTool::colour[4] = {wxColour(106,32,19), wxColour(255,169,40), wxColour(255,253,185), wxColour(187,0,0)};
@ -676,4 +679,8 @@ void VisualTool<FeatureType>::SetOverride(AssDialogue* line, wxString tag, wxStr
parent->SetFocus();
}
// If only export worked
template class VisualTool<VisualDraggableFeature>;
template class VisualTool<ClipCorner>;
template class VisualTool<VisualToolDragDraggableFeature>;
template class VisualTool<VisualToolVectorClipDraggableFeature>;

View file

@ -150,43 +150,39 @@ void VisualToolClip::PopulateFeatureList() {
int i = 0;
features[i].x = curX1;
features[i].y = curY1;
features[i].brother[0] = 1;
features[i].brother[1] = 2;
features[i].brother[2] = 3;
features[i].horiz = &features[1];
features[i].vert = &features[2];
features[i].type = DRAG_SMALL_CIRCLE;
i++;
// Top-right
features[i].x = curX2;
features[i].y = curY1;
features[i].brother[0] = 0;
features[i].brother[1] = 3;
features[i].brother[2] = 2;
features[i].horiz = &features[0];
features[i].vert = &features[3];
features[i].type = DRAG_SMALL_CIRCLE;
i++;
// Bottom-left
features[i].x = curX1;
features[i].y = curY2;
features[i].brother[0] = 3;
features[i].brother[1] = 0;
features[i].brother[2] = 1;
features[i].horiz = &features[3];
features[i].vert = &features[0];
features[i].type = DRAG_SMALL_CIRCLE;
i++;
// Bottom-right
features[i].x = curX2;
features[i].y = curY2;
features[i].brother[0] = 2;
features[i].brother[1] = 1;
features[i].brother[2] = 0;
features[i].horiz = &features[2];
features[i].vert = &features[1];
features[i].type = DRAG_SMALL_CIRCLE;
i++;
}
/// @brief Initialize
/// @param feature
bool VisualToolClip::InitializeDrag(VisualDraggableFeature &feature) {
bool VisualToolClip::InitializeDrag(ClipCorner &feature) {
curDiag = GetActiveDialogueLine();
curDiag->StripTag(L"\\clip");
curDiag->StripTag(L"\\iclip");
@ -195,10 +191,10 @@ bool VisualToolClip::InitializeDrag(VisualDraggableFeature &feature) {
/// @brief Update drag
/// @param feature
void VisualToolClip::UpdateDrag(VisualDraggableFeature &feature) {
void VisualToolClip::UpdateDrag(ClipCorner &feature) {
// Update brothers
features[feature.brother[0]].y = feature.y;
features[feature.brother[1]].x = feature.x;
feature.horiz->y = feature.y;
feature.vert->x = feature.x;
// Get "cur" from features
curX1 = features[0].x;
@ -213,6 +209,6 @@ void VisualToolClip::UpdateDrag(VisualDraggableFeature &feature) {
/// @brief Done dragging
/// @param feature
void VisualToolClip::CommitDrag(VisualDraggableFeature &feature) {
void VisualToolClip::CommitDrag(ClipCorner &feature) {
CommitHold();
}

View file

@ -37,12 +37,26 @@
#include "visual_feature.h"
#include "visual_tool.h"
/// @class ClipCorner
/// @brief VisualDraggableFeature with siblings
class ClipCorner : public VisualDraggableFeature {
public:
ClipCorner* horiz; /// Other corner on this corner's horizontal line
ClipCorner* vert; /// Other corner on this corner's vertical line
/// @brief Constructor
ClipCorner()
: VisualDraggableFeature()
, horiz(NULL)
, vert(NULL)
{ }
};
/// DOCME
/// @class VisualToolClip
/// @brief DOCME
///
/// DOCME
class VisualToolClip : public VisualTool<VisualDraggableFeature> {
class VisualToolClip : public VisualTool<ClipCorner> {
private:
/// DOCME
@ -73,9 +87,9 @@ private:
/// @brief DOCME
///
void PopulateFeatureList();
bool InitializeDrag(VisualDraggableFeature &feature);
void UpdateDrag(VisualDraggableFeature &feature);
void CommitDrag(VisualDraggableFeature &feature);
bool InitializeDrag(ClipCorner &feature);
void UpdateDrag(ClipCorner &feature);
void CommitDrag(ClipCorner &feature);
public:
VisualToolClip(VideoDisplay *parent, VideoState const& video, wxToolBar *);

View file

@ -128,57 +128,53 @@ void VisualToolDrag::Draw() {
// Draw arrows
for (size_t i=0;i<features.size();i++) {
if (features[i].brother[0] != -1 && (features[i].type == DRAG_BIG_CIRCLE || features[i].type == DRAG_BIG_TRIANGLE)) {
// Get features
VisualDraggableFeature *p1,*p2;
p2 = &features[i];
p1 = &features[p2->brother[0]];
if (features[i].type == DRAG_BIG_SQUARE) continue;
VisualDraggableFeature *p2 = &features[i];
VisualDraggableFeature *p1 = &features[features[i].parent];
// Has arrow?
bool hasArrow = p2->type == DRAG_BIG_CIRCLE;
int arrowLen = hasArrow ? 10 : 0;
// Has arrow?
bool hasArrow = p2->type == DRAG_BIG_CIRCLE;
int arrowLen = hasArrow ? 10 : 0;
// See if the distance between them is enough
int dx = p2->x - p1->x;
int dy = p2->y - p1->y;
int dist = (int)sqrt(double(dx*dx + dy*dy));
if (dist < 20+arrowLen) continue;
// See if the distance between them is enough
int dx = p2->x - p1->x;
int dy = p2->y - p1->y;
int dist = (int)sqrt(double(dx*dx + dy*dy));
if (dist < 20+arrowLen) continue;
// Get end points
int x1 = p1->x + dx*10/dist;
int x2 = p2->x - dx*(10+arrowLen)/dist;
int y1 = p1->y + dy*10/dist;
int y2 = p2->y - dy*(10+arrowLen)/dist;
// Get end points
int x1 = p1->x + dx*10/dist;
int x2 = p2->x - dx*(10+arrowLen)/dist;
int y1 = p1->y + dy*10/dist;
int y2 = p2->y - dy*(10+arrowLen)/dist;
// Draw arrow
if (hasArrow) {
// Calculate angle
double angle = atan2(double(y2-y1),double(x2-x1))+1.570796;
int sx = int(cos(angle)*4);
int sy = int(-sin(angle)*4);
// Draw arrow
if (hasArrow) {
// Calculate angle
double angle = atan2(double(y2-y1),double(x2-x1))+1.570796;
int sx = int(cos(angle)*4);
int sy = int(-sin(angle)*4);
// Arrow line
SetLineColour(colour[3],0.8f,2);
DrawLine(x1,y1,x2,y2);
// Arrow line
SetLineColour(colour[3],0.8f,2);
DrawLine(x1,y1,x2,y2);
// Arrow head
DrawLine(x2+sx,y2-sy,x2-sx,y2+sy);
DrawLine(x2+sx,y2-sy,x2+dx*10/dist,y2+dy*10/dist);
DrawLine(x2-sx,y2+sy,x2+dx*10/dist,y2+dy*10/dist);
}
// Arrow head
DrawLine(x2+sx,y2-sy,x2-sx,y2+sy);
DrawLine(x2+sx,y2-sy,x2+dx*10/dist,y2+dy*10/dist);
DrawLine(x2-sx,y2+sy,x2+dx*10/dist,y2+dy*10/dist);
}
// Draw dashed line
else {
SetLineColour(colour[3],0.5f,2);
DrawDashedLine(x1,y1,x2,y2,6);
}
// Draw dashed line
else {
SetLineColour(colour[3],0.5f,2);
DrawDashedLine(x1,y1,x2,y2,6);
}
}
}
/// @brief Populate list
void VisualToolDrag::PopulateFeatureList() {
// Clear features
features.clear();
// Get video data
@ -204,16 +200,16 @@ void VisualToolDrag::PopulateFeatureList() {
GetLineMove(diag,hasMove,x1,y1,x2,y2,t1,t2);
// Create \pos feature
VisualDraggableFeature feat;
VisualToolDragDraggableFeature feat;
feat.x = x1;
feat.y = y1;
feat.layer = 0;
feat.type = DRAG_BIG_SQUARE;
feat.value = t1;
feat.time = t1;
feat.line = diag;
feat.lineN = i;
features.push_back(feat);
int parentN = features.size()-1;
feat.parent = features.size() - 1;
// Create move destination feature
if (hasMove) {
@ -221,32 +217,22 @@ void VisualToolDrag::PopulateFeatureList() {
feat.y = y2;
feat.layer = 1;
feat.type = DRAG_BIG_CIRCLE;
feat.value = t2;
feat.time = t2;
feat.line = diag;
feat.lineN = i;
features.push_back(feat);
// Add each other as brothers.
int n = features.size();
features[n-1].brother[0] = parentN;
features[parentN].brother[0] = n-1;
features[feat.parent].parent = features.size() - 1;
}
// Create org feature
if (torgx != x1 || torgy != y1) {
feat.x = torgx;
feat.y = torgy;
feat.layer = -1;
feat.type = DRAG_BIG_TRIANGLE;
feat.value = 0;
feat.time = 0;
feat.line = diag;
feat.lineN = i;
features.push_back(feat);
// Add each other as brothers.
int n = features.size();
features[n-1].brother[0] = parentN;
features[parentN].brother[1] = n-1;
}
}
}
@ -255,47 +241,44 @@ void VisualToolDrag::PopulateFeatureList() {
/// @brief Update drag
/// @param feature
void VisualToolDrag::UpdateDrag(VisualDraggableFeature &feature) {
// Update "value" to reflect the time of the frame in which the feature is being dragged
void VisualToolDrag::UpdateDrag(VisualToolDragDraggableFeature &feature) {
// Update "time" to reflect the time of the frame in which the feature is being dragged
int time = VFR_Output.GetTimeAtFrame(frame_n,true,true);
feature.value = MID(0,time - feature.line->Start.GetMS(),feature.line->End.GetMS()-feature.line->Start.GetMS());
feature.time = MID(0,time - feature.line->Start.GetMS(),feature.line->End.GetMS()-feature.line->Start.GetMS());
}
/// @brief Commit drag
/// @param feature
void VisualToolDrag::CommitDrag(VisualDraggableFeature &feature) {
void VisualToolDrag::CommitDrag(VisualToolDragDraggableFeature &feature) {
// Origin
if (feature.type == DRAG_BIG_TRIANGLE) {
int x = feature.x;
int y = feature.y;
parent->ToScriptCoords(&x, &y);
SetOverride(feature.line, L"\\org",wxString::Format(L"(%i,%i)",x,y));
return;
}
VisualToolDragDraggableFeature *p = feature->parent > -1 ? &features[feature->parent] : NULL;
if (feature->type == DRAG_BIG_CIRCLE) {
std::swap(feature, p);
}
int x1 = feature->x;
int y1 = feature->y;
parent->ToScriptCoords(&x1, &y1);
// Position
else if (feature.brother[0] == -1) {
int x = feature.x;
int y = feature.y;
parent->ToScriptCoords(&x, &y);
SetOverride(feature.line, L"\\pos",wxString::Format(L"(%i,%i)",x,y));
if (!p) {
SetOverride(feature.line, L"\\pos", wxString::Format(L"(%i,%i)", x1, y1));
}
// Move
else {
// Get source on p1 and dest on p2
VisualDraggableFeature *p1,*p2;
p1 = &feature;
if (p1->type == DRAG_BIG_CIRCLE) p1 = &features[p1->brother[0]];
p2 = &features[p1->brother[0]];
int x1 = p1->x;
int y1 = p1->y;
parent->ToScriptCoords(&x1, &y1);
int x2 = p2->x;
int y2 = p2->y;
int x2 = p->x;
int y2 = p->y;
parent->ToScriptCoords(&x2, &y2);
// Set override
SetOverride(feature.line, L"\\move", wxString::Format(L"(%i,%i,%i,%i,%i,%i)", x1, y1, x2, y2, p1->value, p2->value));
SetOverride(feature->line, L"\\move", wxString::Format(L"(%i,%i,%i,%i,%i,%i)", x1, y1, x2, y2, feature->time, p->time));
}
}

View file

@ -42,13 +42,26 @@
#include "visual_feature.h"
#include "visual_tool.h"
/// @class VisualToolDragDraggableFeature
/// @brief VisualDraggableFeature with a time value
class VisualToolDragDraggableFeature : public VisualDraggableFeature {
public:
int time;
int parent;
VisualToolDragDraggableFeature()
: VisualDraggableFeature()
, time(0)
, parent(-1)
{ }
};
/// DOCME
/// @class VisualToolDrag
/// @brief DOCME
///
/// DOCME
class VisualToolDrag : public VisualTool<VisualDraggableFeature> {
class VisualToolDrag : public VisualTool<VisualToolDragDraggableFeature> {
private:
/// DOCME
wxToolBar *toolBar;
@ -60,8 +73,8 @@ private:
///
bool CanDrag() { return true; }
void PopulateFeatureList();
void UpdateDrag(VisualDraggableFeature &feature);
void CommitDrag(VisualDraggableFeature &feature);
void UpdateDrag(VisualToolDragDraggableFeature &feature);
void CommitDrag(VisualToolDragDraggableFeature &feature);
void UpdateToggleButtons();
void DoRefresh();

View file

@ -206,7 +206,7 @@ void VisualToolVectorClip::Draw() {
void VisualToolVectorClip::PopulateFeatureList() {
// Clear
features.clear();
VisualDraggableFeature feat;
VisualToolVectorClipDraggableFeature feat;
// Go through each curve
bool isFirst = true;
@ -218,8 +218,8 @@ void VisualToolVectorClip::PopulateFeatureList() {
feat.x = (int)cur->p1.x;
feat.y = (int)cur->p1.y;
feat.type = DRAG_SMALL_CIRCLE;
feat.value = i;
feat.value2 = 0;
feat.index = i;
feat.point = 0;
features.push_back(feat);
}
@ -228,8 +228,8 @@ void VisualToolVectorClip::PopulateFeatureList() {
feat.x = (int)cur->p2.x;
feat.y = (int)cur->p2.y;
feat.type = DRAG_SMALL_CIRCLE;
feat.value = i;
feat.value2 = 1;
feat.index = i;
feat.point = 1;
features.push_back(feat);
}
@ -241,22 +241,20 @@ void VisualToolVectorClip::PopulateFeatureList() {
// Control points
feat.x = (int)cur->p2.x;
feat.y = (int)cur->p2.y;
feat.value = i;
feat.value2 = 1;
feat.brother[0] = size-1;
feat.index = i;
feat.point = 1;
feat.type = DRAG_SMALL_SQUARE;
features.push_back(feat);
feat.x = (int)cur->p3.x;
feat.y = (int)cur->p3.y;
feat.value2 = 2;
feat.brother[0] = size+2;
feat.point = 2;
features.push_back(feat);
// End point
feat.x = (int)cur->p4.x;
feat.y = (int)cur->p4.y;
feat.type = DRAG_SMALL_CIRCLE;
feat.value2 = 3;
feat.point = 3;
features.push_back(feat);
}
}
@ -264,27 +262,27 @@ void VisualToolVectorClip::PopulateFeatureList() {
/// @brief Update
/// @param feature
void VisualToolVectorClip::UpdateDrag(VisualDraggableFeature &feature) {
spline.MovePoint(feature.value,feature.value2,wxPoint(feature.x,feature.y));
void VisualToolVectorClip::UpdateDrag(VisualToolVectorClipDraggableFeature &feature) {
spline.MovePoint(feature.index,feature.point,wxPoint(feature.x,feature.y));
}
/// @brief Commit
/// @param feature
void VisualToolVectorClip::CommitDrag(VisualDraggableFeature &feature) {
void VisualToolVectorClip::CommitDrag(VisualToolVectorClipDraggableFeature &feature) {
SetOverride(GetActiveDialogueLine(), inverse ? L"\\iclip" : L"\\clip", L"(" + spline.EncodeToASS() + L")");
}
/// @brief Clicked a feature
/// @param feature
/// @return
bool VisualToolVectorClip::InitializeDrag(VisualDraggableFeature &feature) {
bool VisualToolVectorClip::InitializeDrag(VisualToolVectorClipDraggableFeature &feature) {
// Delete a control point
if (mode == 5) {
int i = 0;
for (std::list<SplineCurve>::iterator cur=spline.curves.begin();cur!=spline.curves.end();i++,cur++) {
if (i == feature.value) {
if (i == feature.index) {
// Update next
if (i != 0 || feature.value2 != 0) {
if (i != 0 || feature.point != 0) {
std::list<SplineCurve>::iterator next = cur;
next++;
if (next != spline.curves.end()) next->p1 = cur->p1;

View file

@ -40,10 +40,27 @@
class wxToolBar;
/// @class VisualToolVectorClipDraggableFeature
/// @brief VisualDraggableFeature with information about a feature's location
/// in the spline
class VisualToolVectorClipDraggableFeature : public VisualDraggableFeature {
public:
/// Which curve in the spline this feature is a point on
int index;
/// 0-3; indicates which part of the curve this point is
int point;
/// @brief Constructor
VisualToolVectorClipDraggableFeature()
: VisualDraggableFeature()
, index(0)
, point(0)
{ }
};
/// DOCME
/// @class VisualToolVectorClip
/// @brief DOCME
class VisualToolVectorClip : public VisualTool<VisualDraggableFeature> {
class VisualToolVectorClip : public VisualTool<VisualToolVectorClipDraggableFeature> {
private:
/// DOCME
@ -75,9 +92,9 @@ private:
void PopulateFeatureList();
void UpdateDrag(VisualDraggableFeature &feature);
void CommitDrag(VisualDraggableFeature &feature);
bool InitializeDrag(VisualDraggableFeature &feature);
void UpdateDrag(VisualToolVectorClipDraggableFeature &feature);
void CommitDrag(VisualToolVectorClipDraggableFeature &feature);
bool InitializeDrag(VisualToolVectorClipDraggableFeature &feature);
void DoRefresh();