Shift Drag


Hi Walter & Co



Hope 2007 is a great year for Northwoods.



I’m trying to replicate the Shift-Drag behaviour of some applications, where the user can only drag the selection along one axis - depending on the difference between X and Y on the offset.



--------

public override void MoveSelection(GoSelection sel, SizeF offset, bool grid)

{

if (LastInput.Shift)

{

if (IsDraggingY.HasValue)

{

if (IsDraggingY.Value)

{

offset.Width = 0;

}

else

{

offset.Height = 0;

}

}

else

{

float Y; float X;

Y = (offset.Height > 0) ? offset.Height : offset.Height * -1f;

X = (offset.Width > 0) ? offset.Width : offset.Width * -1f;



if (Y > X)

{

offset.Width = 0;

IsDraggingY = true;

}

else

{

offset.Height = 0;

IsDraggingY = false;

}

}

lastOffset = offset;

}

base.MoveSelection(sel, offset, grid);



}

----------



This approach works, kinda - but as soon as I let go of the mouse button (or shift), the selection snaps to the mouse’s current position over the view. Any ideas?



Keep well & TIA

Deon

Isn’t having the selection snap to the current mouse point the behavior you want when the user stops holding down the Shift key? In other words, isn’t the Shift key telling the dragging tool how to operate?

In any case, instead of overriding GoView.MoveSelection, I would customize the dragging tool:
[Serializable]
public class CustomDraggingTool : GoToolDragging {
public CustomDraggingTool(GoView view) : base(view) {}
public override void DoDragging(GoInputState evttype) {
if (this.CurrentObject == null) return;
if (this.LastInput.Shift) {
PointF first = this.FirstInput.DocPoint;
PointF last = this.LastInput.DocPoint;
if (Math.Abs(last.X-first.X) >= Math.Abs(last.Y-first.Y)) {
this.LastInput.DocPoint = new PointF(last.X, first.Y);
} else {
this.LastInput.DocPoint = new PointF(first.X, last.Y);
}
// keep ViewPoint up-to-date with DocPoint
this.LastInput.ViewPoint = this.View.ConvertDocToView(this.LastInput.DocPoint);
}
base.DoDragging(evttype);
}
}
Install this tool with:
goView1.ReplaceMouseTool(typeof(GoToolDragging), new CustomDraggingTool(goView1));

Very much awesomeness.



Did the trick! Cheers!