Fixed \move drag. Note to self: std::vector != std::list, iterators are not preserved after a push_back().

Originally committed to SVN as r1344.
This commit is contained in:
Rodrigo Braz Monteiro 2007-07-04 01:22:10 +00:00
parent 7554bd373b
commit d6e9c3f730
3 changed files with 12 additions and 12 deletions

View file

@ -50,7 +50,7 @@ VisualDraggableFeature::VisualDraggableFeature() {
layer = 0; layer = 0;
lineN = -1; lineN = -1;
line = NULL; line = NULL;
for (int i=0;i<4;i++) brother[i] = NULL; for (int i=0;i<4;i++) brother[i] = -1;
} }

View file

@ -70,7 +70,7 @@ public:
AssDialogue *line; AssDialogue *line;
int lineN; int lineN;
VisualDraggableFeature *brother[4]; int brother[4];
bool IsMouseOver(int x,int y); bool IsMouseOver(int x,int y);
void Draw(OpenGLWrapper *gl); void Draw(OpenGLWrapper *gl);

View file

@ -72,11 +72,11 @@ void VisualToolDrag::Draw() {
// Draw arrows // Draw arrows
for (size_t i=0;i<features.size();i++) { for (size_t i=0;i<features.size();i++) {
if (features[i].brother[0] != NULL && features[i].type == DRAG_BIG_SQUARE) { if (features[i].brother[0] != -1 && features[i].type == DRAG_BIG_SQUARE) {
// Get features // Get features
VisualDraggableFeature *p1,*p2; VisualDraggableFeature *p1,*p2;
p1 = &features[i]; p1 = &features[i];
p2 = p1->brother[0]; p2 = &features[p1->brother[0]];
// See if the distance between them is at least 30 pixels // See if the distance between them is at least 30 pixels
int dx = p2->x - p1->x; int dx = p2->x - p1->x;
@ -154,11 +154,12 @@ void VisualToolDrag::PopulateFeatureList() {
feat.value = t2; feat.value = t2;
feat.line = diag; feat.line = diag;
feat.lineN = i; feat.lineN = i;
// Add each other as brothers. Yes, this looks weird.
feat.brother[0] = &features.back();
features.push_back(feat); features.push_back(feat);
feat.brother[0]->brother[0] = &features.back();
// Add each other as brothers.
int n = features.size();
features[n-1].brother[0] = n-2;
features[n-2].brother[0] = n-1;
} }
} }
} }
@ -176,7 +177,6 @@ void VisualToolDrag::InitializeDrag(VisualDraggableFeature &feature) {
// Update drag // Update drag
void VisualToolDrag::UpdateDrag(VisualDraggableFeature &feature) { void VisualToolDrag::UpdateDrag(VisualDraggableFeature &feature) {
// Update "value" to reflect the time of the frame in which the feature is being dragged // Update "value" to reflect the time of the frame in which the feature is being dragged
int frame_n = VideoContext::Get()->GetFrameN();
int time = VFR_Output.GetTimeAtFrame(frame_n,true,true); 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.value = MID(0,time - feature.line->Start.GetMS(),feature.line->End.GetMS()-feature.line->Start.GetMS());
} }
@ -186,7 +186,7 @@ void VisualToolDrag::UpdateDrag(VisualDraggableFeature &feature) {
// Commit drag // Commit drag
void VisualToolDrag::CommitDrag(VisualDraggableFeature &feature) { void VisualToolDrag::CommitDrag(VisualDraggableFeature &feature) {
// Position // Position
if (feature.brother[0] == NULL) { if (feature.brother[0] == -1) {
SetOverride(_T("\\pos"),wxString::Format(_T("(%i,%i)"),feature.x,feature.y)); SetOverride(_T("\\pos"),wxString::Format(_T("(%i,%i)"),feature.x,feature.y));
} }
@ -195,8 +195,8 @@ void VisualToolDrag::CommitDrag(VisualDraggableFeature &feature) {
// Get source on p1 and dest on p2 // Get source on p1 and dest on p2
VisualDraggableFeature *p1,*p2; VisualDraggableFeature *p1,*p2;
p1 = &feature; p1 = &feature;
if (p1->type == DRAG_BIG_CIRCLE) p1 = p1->brother[0]; if (p1->type == DRAG_BIG_CIRCLE) p1 = &features[p1->brother[0]];
p2 = p1->brother[0]; p2 = &features[p1->brother[0]];
// Set override // Set override
SetOverride(_T("\\move"),wxString::Format(_T("(%i,%i,%i,%i,%i,%i)"),p1->x,p1->y,p2->x,p2->y,p1->value,p2->value)); SetOverride(_T("\\move"),wxString::Format(_T("(%i,%i,%i,%i,%i,%i)"),p1->x,p1->y,p2->x,p2->y,p1->value,p2->value));