1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-06-17 16:40:07 +02:00

Label dragging enhancements, especial point labels (Bugzilla:109)

This commit is contained in:
james.k.crook 2010-01-31 17:26:21 +00:00
parent d6b0e9e0bb
commit 77b874c5d9

View File

@ -242,7 +242,7 @@ double LabelTrack::AdjustTimeStampOnScale(double t, double b, double e, double c
// (If necessary this could be optimised by ignoring labels that occur before a // (If necessary this could be optimised by ignoring labels that occur before a
// specified time, as in most cases they don't need to move.) // specified time, as in most cases they don't need to move.)
void LabelTrack::WarpLabels(const TimeWarper &warper) { void LabelTrack::WarpLabels(const TimeWarper &warper) {
for (int i = 0; i < mLabels.GetCount(); ++i) { for (int i = 0; i < (int)mLabels.GetCount(); ++i) {
double &labelT0 = mLabels[i]->t; labelT0 = warper.Warp(labelT0); double &labelT0 = mLabels[i]->t; labelT0 = warper.Warp(labelT0);
double &labelT1 = mLabels[i]->t1; labelT1 = warper.Warp(labelT1); double &labelT1 = mLabels[i]->t1; labelT1 = warper.Warp(labelT1);
} }
@ -561,9 +561,9 @@ void LabelStruct::DrawGlyphs(wxDC & dc, const wxRect & r, int GlyphLeft, int Gly
if((x >= r.x) && (x <= (r.x+r.width))) if((x >= r.x) && (x <= (r.x+r.width)))
dc.DrawBitmap(LabelTrack::GetGlyph(GlyphLeft), x-xHalfWidth,yStart, true); dc.DrawBitmap(LabelTrack::GetGlyph(GlyphLeft), x-xHalfWidth,yStart, true);
// The extra test here suppresses right hand markers when they overlap // The extra test commented out here would suppress right hand markers
// the left hand marker (e.g. zoomed out) or are to the left. // when they overlap the left hand marker (e.g. zoomed out) or to the left.
if((x1 >= r.x) && (x1 <= (r.x+r.width)) && (x1>x+LabelTrack::mIconWidth)) if((x1 >= r.x) && (x1 <= (r.x+r.width)) /*&& (x1>x+LabelTrack::mIconWidth)*/)
dc.DrawBitmap(LabelTrack::GetGlyph(GlyphRight), x1-xHalfWidth,yStart, true); dc.DrawBitmap(LabelTrack::GetGlyph(GlyphRight), x1-xHalfWidth,yStart, true);
} }
@ -1163,7 +1163,29 @@ int LabelTrack::OverGlyph(int x, int y)
pLabel = mLabels[i]; pLabel = mLabels[i];
//over left or right selection bound //over left or right selection bound
//Check right bound first, since it is drawn after left bound,
//so give it precedence for matching/highlighting.
if( abs(pLabel->y - (y - (LabelTrack::mTextHeight+3)/2)) < d1 && if( abs(pLabel->y - (y - (LabelTrack::mTextHeight+3)/2)) < d1 &&
abs(pLabel->x1 - d2 -x) < d1)
{
mMouseOverLabelRight = i;
if(abs(pLabel->x1 - x) < d2 )
{
mbHitCenter = true;
// If left and right co-incident at this resolution, then we drag both.
// We could be a little less stringent about co-incidence here if we liked.
if( abs(pLabel->x1-pLabel->x) < 1.0 )
{
result |=1;
mMouseOverLabelLeft = i;
}
}
result |= 2;
mInBox = false; // to disable the dragging for selecting the text in text box
}
// Use else-if here rather than else to avoid detecting left and right
// of the same label.
else if( abs(pLabel->y - (y - (LabelTrack::mTextHeight+3)/2)) < d1 &&
abs(pLabel->x + d2 - x) < d1 ) abs(pLabel->x + d2 - x) < d1 )
{ {
mMouseOverLabelLeft = i; mMouseOverLabelLeft = i;
@ -1172,17 +1194,6 @@ int LabelTrack::OverGlyph(int x, int y)
result |= 1; result |= 1;
mInBox = false; // to disable the dragging for selecting the text in text box mInBox = false; // to disable the dragging for selecting the text in text box
} }
// use else-if so that we don't detect left and right
// of the same label.
else if( abs(pLabel->y - (y - (LabelTrack::mTextHeight+3)/2)) < d1 &&
abs(pLabel->x1 - d2 -x) < d1)
{
mMouseOverLabelRight = i;
if(abs(pLabel->x1 - x) < d2 )
mbHitCenter = true;
result |= 2;
mInBox = false; // to disable the dragging for selecting the text in text box
}
// give text box better priority for selecting // give text box better priority for selecting
if(OverTextBox(pLabel, x, y)) if(OverTextBox(pLabel, x, y))
@ -1261,22 +1272,35 @@ bool LabelTrack::HandleMouse(const wxMouseEvent & evt,
x = r.width - 2; x = r.width - 2;
} }
double width;
bool bSameLabel = mMouseOverLabelLeft==mMouseOverLabelRight;
//Adjust boundary and make sure that t < t1 on any dragged labels. //Adjust boundary and make sure that t < t1 on any dragged labels.
//This code pushes both of them in one direction, instead of swapping //This code pushes both of them in one direction, instead of swapping
//bounds like happens for the selection region. //bounds like happens for the selection region.
//If button is down, then we preserve the label width.
if(mMouseOverLabelLeft>=0) if(mMouseOverLabelLeft>=0)
{ {
width = mLabels[mMouseOverLabelLeft]->t1 - mLabels[mMouseOverLabelLeft]->t;
mLabels[mMouseOverLabelLeft]->t = h + x / pps; mLabels[mMouseOverLabelLeft]->t = h + x / pps;
if( mLabels[mMouseOverLabelLeft]->t > mLabels[mMouseOverLabelLeft]->t1) if( evt.ShiftDown() || bSameLabel )
{
mLabels[mMouseOverLabelLeft]->t1 = mLabels[mMouseOverLabelLeft]->t+width;
}
else if( mLabels[mMouseOverLabelLeft]->t > mLabels[mMouseOverLabelLeft]->t1)
{ {
mLabels[mMouseOverLabelLeft]->t1 = mLabels[mMouseOverLabelLeft]->t; mLabels[mMouseOverLabelLeft]->t1 = mLabels[mMouseOverLabelLeft]->t;
} }
mLabels[mMouseOverLabelLeft]->updated = true; mLabels[mMouseOverLabelLeft]->updated = true;
} }
if (mMouseOverLabelRight>=0) if( (mMouseOverLabelRight>=0) && !bSameLabel )
{ {
width = mLabels[mMouseOverLabelRight]->t1 - mLabels[mMouseOverLabelRight]->t;
mLabels[mMouseOverLabelRight]->t1 = h + x / pps; mLabels[mMouseOverLabelRight]->t1 = h + x / pps;
if( mLabels[mMouseOverLabelRight]->t > mLabels[mMouseOverLabelRight]->t1) if( evt.ShiftDown() )
{
mLabels[mMouseOverLabelRight]->t = mLabels[mMouseOverLabelRight]->t1-width;
}
else if( mLabels[mMouseOverLabelRight]->t > mLabels[mMouseOverLabelRight]->t1)
{ {
mLabels[mMouseOverLabelRight]->t = mLabels[mMouseOverLabelRight]->t1; mLabels[mMouseOverLabelRight]->t = mLabels[mMouseOverLabelRight]->t1;
} }
@ -1340,12 +1364,16 @@ bool LabelTrack::HandleMouse(const wxMouseEvent & evt,
// and use that in subsequent dragging calculations. The mouse stays // and use that in subsequent dragging calculations. The mouse stays
// at the same relative displacement throughout dragging. // at the same relative displacement throughout dragging.
// However, if two labels are being dragged, then the displacement // However, if two label's edges are being dragged
// is relative to the initial average position of them, and in that // then the displacement is relative to the initial average
// case there can be a jump of at most a few pixels to bring the // position of them, and in that case there can be a jump of at most
// two label boundaries to exactly the same position when we start // a few pixels to bring the two label boundaries to exactly the same
// dragging. // position when we start dragging.
if((mMouseOverLabelRight >=0) && (mMouseOverLabelLeft >=0))
// Dragging of three label edges at the same time is not supported (yet).
if( (mMouseOverLabelRight >=0) &&
(mMouseOverLabelLeft >=0)
)
{ {
t = (mLabels[mMouseOverLabelRight]->t1+mLabels[mMouseOverLabelLeft]->t)/2.0f; t = (mLabels[mMouseOverLabelRight]->t1+mLabels[mMouseOverLabelLeft]->t)/2.0f;
} }