MouseWheel Zooming

Greetings: I am trying, with little success, to enhance the GoView +MouseWheel zoom in and out function. The default behavior is for the GoView.DocPosition to remain fixed and the rest of the X and Y to change scale. In my application, I like to be able to "drill down" right on top of the mouse cursor. Alas, after way too much experimentation, I’ve only been able to achieve a very wandering, mouse cursor centered zoom. I’m beginning to wonder if there is a very good reason why this very CAD style feature is not already included in GoDiagram. Has anyone any pointers which might illuminate a path through this darkness? Thanks, Doug P.

Hey, that sounds like a nice feature.
[Serializable]
public class FocussingTool : GoToolManager {
public FocussingTool(GoView view) : base(view) {}
public override void DoMouseWheel() {
GoInputEventArgs evt = this.LastInput;
if (evt.Control && evt.Delta != 0) {
PointF oldpos = this.View.DocPosition;
this.View.DocScale *= (1 + ((float)evt.Delta)/2400);
PointF focus = this.View.ConvertViewToDoc(evt.ViewPoint);
this.View.DocPosition = new PointF(oldpos.X + evt.DocPoint.X - focus.X, oldpos.Y + evt.DocPoint.Y - focus.Y);
} else {
base.DoMouseWheel();
}
}
}
and then initialize your view as follows:
myView.DefaultTool = new FocussingTool(myView);
myView.ReplaceMouseTool(typeof(GoToolManager), myView.DefaultTool);
Question for other people: should this be the default control-mouse-wheel behavior?

It would be handy if both modes were available. Perhaps it could be switchable via a view property?

This seems more intuitive than the way it works right now.

Hey Walter! Thanks very much! You code works just fine, and it shows that I was going at the problem entirely wrong. Doug P.


Good Morning Walter:
Could I bug you again regarding your mouse wheel zooming code snippet? I converted your code to VB.NET and came up with the following code. As I reported, it does work great for the zooming feature. Unfortunately, our testers immediately pointed out (to my utter chagrin), that GoNodes within the GoView will now only respond to a single mouse click. As I’m still a little fuzzy about what’s going on here, could you offer any further suggestions? Here’s my implementation:
<Serializable()> Public Class clsVTGoTool
Inherits Northwoods.Go.GoTool
Private m_GoView As Northwoods.Go.GoView
Public Sub New(ByRef gView As Northwoods.Go.GoView)
MyBase.New(gView)
m_GoView = gView
End Sub
Public Overrides Sub DoMouseWheel()
Dim evt As Northwoods.Go.GoInputEventArgs = Me.m_GoView.LastInput
If (evt.Control = True) And (evt.Delta <> 0) Then
Dim oldpos As PointF = Me.m_GoView.DocPosition
Me.m_GoView.DocScale *= (1 + (CDbl(evt.Delta) / 2400))
Dim focus As PointF = Me.m_GoView.ConvertViewToDoc(evt.ViewPoint)
Me.m_GoView.DocPosition = New PointF(oldpos.X + evt.DocPoint.X - focus.X, oldpos.Y + evt.DocPoint.Y - focus.Y)
Else
MyBase.DoMouseWheel()
End If
End Sub
End Class
Then, when I dynamically allocate my GoView:
gView.DefaultTool = New clsVTGoTool(gView)
gView.ReplaceMouseTool(GetType(GoToolManager), gView.DefaultTool)
Do you see any glaring errors in this?
Thanks very much for any pointers,
Doug P.

Except for the unnecessary m_GoView field (you can use the GoTool.View property), it looks fine to me.
The tool you defined has no effect on clicking or other mouse actions, so I don’t believe it caused your nodes not to respond to double-clicks. I can’t reproduce any problem with double-clicks in my applications.

Walter: This is embarrassing! Rather than "Inherits Northwoods.Go.GoTool", it should be "Inherits Northwoods.Go.GoToolManager", which is what your example stated in the first place. Thanks for your time, Doug P.

Hi, just implemented this behavior and my opinion is that this should be the default behavior.

Actually, it has been the default behavior since v2.2.2, since soon after this discussion took place.