Piccolo Snippets
From eqqon
(Difference between revisions)
m (Piccolo Nuts and Bolts moved to Piccolo Snippets) |
Revision as of 21:33, 28 October 2007
Useful Piccolo Extensions
MouseWheelScrollController
This class replaces Piccolo's default zoom event handler which is not very attractive with a mouse wheel zoom event handler. Just instanciate it with your canvas' camera as parameter and mouse wheel zooming just works!
public class MouseWheelZoomController { public static float MIN_SCALE = .0001f; public static float MAX_SCALE = 2500; PCamera camera; public MouseWheelZoomController(PCamera camera) { this.camera = camera; camera.Canvas.ZoomEventHandler = null; camera.MouseWheel += OnMouseWheel; } public void OnMouseWheel(object o, PInputEventArgs ea) { float currentScale = camera.ViewScale; float scaleDelta = (1.0f + (0.001f * ea.WheelDelta)); float newScale = currentScale * scaleDelta; if (newScale < MIN_SCALE) { camera.ViewScale = MIN_SCALE; return; } if ((MAX_SCALE > 0) && (newScale > MAX_SCALE)) { camera.ViewScale = MAX_SCALE; return; } PointF pos = ea.Position; camera.ScaleViewBy(scaleDelta, pos.X, pos.Y); } }