Objects and boundaries

Those anyone know how to restrict the window boundaries so when you drag objects to the edges, it doesn’t allow you to drag past it and make half the object dissappear? Thanks a bunch

Ludwig

There isn’t a property you can set on the GoView to get this behavior.

You could override GoObject.DoMove to respect your wish:

[code] [Serializable]
public class LimitedTextNode : GoTextNode {
public LimitedTextNode() { }

public override void DoMove(GoView view, PointF origLoc, PointF newLoc) {
  RectangleF extent = view.DocExtent;
  RectangleF b = this.Bounds;
  float x = Math.Min(newLoc.X, extent.Right-(b.Right-origLoc.X));
  float y = Math.Min(newLoc.Y, extent.Bottom-(b.Bottom-origLoc.Y));
  x = Math.Max(x, extent.Left+(origLoc.X-b.Left));
  y = Math.Max(y, extent.Top+(origLoc.Y-b.Top));
  base.DoMove(view, origLoc, new PointF(x, y));
}

}[/code]
Don’t forget to set GoView.AutoScrollRegion to 0,0, to turn off autoscrolling.

An alternative is use a grid so that objects always stay within the grid. You just need to override GoGrid.SnapPoint to do something like the DoMove method above, and make sure the grid’s Bounds are the same as the GoView.DocExtent. (The appearance of the GoGrid doesn’t affect its GoGrid.SnapDrag behavior, so you can set the GoGrid.Style to None.)

For all of these strategies you may need to think about what should happen when the user is dragging more than one object. In some cases customizing GoToolDragging or GoView.MoveSelection might be easier than doing the above customization of DoMove for individual GoObjects.

Is there a reason why the method isn't overiding? This is my first expereince in nwoods go environment. It may be something silly. Thanks
using System;
using System.Collections.Generic; using System.Text; using Northwoods.Go; using System.Drawing; using System.Windows.Forms; namespace OpenSpan.Automation.Design { [Serializable] class LimitedTextNode: GoTextNode { public LimitedTextNode() {

}
public override void DoMove(GoView view, PointF origLoc, PointF newLoc)
{
RectangleF extent = view.DocExtent;
RectangleF b = this.Bounds;
float x = Math.Min(newLoc.X, extent.Right - (b.Right - origLoc.X));
float y = Math.Min(newLoc.Y, extent.Bottom - (b.Bottom - origLoc.Y));
x = Math.Max(x, extent.Left + (origLoc.X - b.Left));
y = Math.Max(y, extent.Top + (origLoc.Y - b.Top));
base.DoMove(view, origLoc, new PointF(x, y));
}
}
}

What’s the problem?

The code isn’t running. It doesn’t overide the default method.

Is your code the same as what I posted above? I did test that code, and it worked fine.

If your node class is different, or doesn’t inherit from GoTextNode, you just need to include that DoMove method override in your own node class.

Hi walter Thanks for your help so far. I am trying to move multiple objects and have the selected objects not move if one of them hit the boundaries… The following works for moving. But if I dragged an object onto the boundary, It obvously doesn’t work because I need the new location of the objects not the old. Is there a way of getting the new location of other nodes in the selection?

public override void DoMove(GoView view, PointF origLoc, PointF newLoc) { RectangleF extent = view.DocExtent; RectangleF b = this.Bounds; float right = view.Selection.First.Bounds.Right; float bottom = view.Selection.First.Bounds.Bottom; float left = view.Selection.First.Bounds.Left; float top = view.Selection.First.Bounds.Top; foreach (GoObject node in view.Selection) { if(node.Bounds.Right > right) right = node.Bounds.Right; if (node.Bounds.Bottom > bottom) bottom = node.Bounds.Bottom; if (node.Bounds.Left < left) left = node.Bounds.Left; if (node.Bounds.Top < top) top = node.Bounds.Top; }

if (right >= extent.Right)
{
Debug.WriteLine(“Right” + right + " " + extent.Right);
}
else if (bottom >= extent.Bottom)
{
Debug.WriteLine(“Bottom” + bottom + " " + extent.Bottom);
}
else if (left <= extent.Left)
{
Debug.WriteLine(“Left” + left + " " + extent.Left);
}
else if (top <= extent.Top)
{
Debug.WriteLine(“Top” + top + " " + extent.Top);
}
else
{
float x = Math.Min(newLoc.X, extent.Right - (b.Right - origLoc.X));
float y = Math.Min(newLoc.Y, extent.Bottom - (b.Bottom - origLoc.Y));
x = Math.Max(x, extent.Left + (origLoc.X - b.Left));
y = Math.Max(y, extent.Top + (origLoc.Y - b.Top));
base.DoMove(view, origLoc, new PointF(x, y));
}
}

Here’s a simpler version of what you’ve done:
[Serializable]
public class LimitedTextNode : GoTextNode {
public LimitedTextNode() { }
public override void DoMove(GoView view, PointF origLoc, PointF newLoc) {
RectangleF extent = view.DocExtent;
RectangleF b = GoDocument.ComputeBounds(view.Selection, view);
float x = Math.Min(newLoc.X, extent.Right-(b.Right-origLoc.X));
float y = Math.Min(newLoc.Y, extent.Bottom-(b.Bottom-origLoc.Y));
x = Math.Max(x, extent.Left+(origLoc.X-b.Left));
y = Math.Max(y, extent.Top+(origLoc.Y-b.Top));
base.DoMove(view, origLoc, new PointF(x, y));
}
}
It turns out this doesn’t work reliably, because the repeated calls to compute the bounds of the selection will produce varying results, thereby resulting in some selected objects being moved more than others when the movement is limited by the boundary.
Also, the repeated computation of the selection’s bounds is wasteful, anyway.
So, just compute the bounds once, and remember it:
public class SpecialView : GoView {
public SpecialView() {}
public override void MoveSelection(GoSelection sel, SizeF offset, bool grid) {
myMoveSelectionBounds = GoDocument.ComputeBounds(sel, this);
base.MoveSelection(sel, offset, grid);
}
public RectangleF MoveSelectionBounds {
get { return myMoveSelectionBounds; }
}
private RectangleF myMoveSelectionBounds;
}
and use it in DoMove:
[Serializable]
public class LimitedTextNode : GoTextNode {
public LimitedTextNode() { }
public override void DoMove(GoView view, PointF origLoc, PointF newLoc) {
SpecialView specialview = view as SpecialView;
if (specialview != null) {
RectangleF extent = view.DocExtent;
RectangleF b = specialview.MoveSelectionBounds;
float x = Math.Min(newLoc.X, extent.Right-(b.Right-origLoc.X));
float y = Math.Min(newLoc.Y, extent.Bottom-(b.Bottom-origLoc.Y));
x = Math.Max(x, extent.Left+(origLoc.X-b.Left));
y = Math.Max(y, extent.Top+(origLoc.Y-b.Top));
base.DoMove(view, origLoc, new PointF(x, y));
} else {
base.DoMove(view, origLoc, newLoc);
}
}
}
This just works for moving the selection within a GoView, not for external drag-and-drops or for copies.