public override void Initialize() { PRoot root = Canvas.Root; PCamera camera = Canvas.Camera; PLayer mainLayer = Canvas.Layer; // viewed by the PCanvas camera, the lens is added to this layer. PLayer sharedLayer = new PLayer(); // viewed by both the lens camera and the PCanvas camera PLayer lensOnlyLayer = new PLayer(); // viewed by only the lens camera root.AddChild(lensOnlyLayer); root.AddChild(sharedLayer); camera.AddLayer(0, sharedLayer); PLens lens = new PLens(); lens.SetBounds(10, 10, 100, 130); lens.AddLayer(0, lensOnlyLayer); lens.AddLayer(1, sharedLayer); mainLayer.AddChild(lens); PBoundsHandle.AddBoundsHandlesTo(lens); // Create an event handler that draws squiggles on the first layer of the bottom // most camera. PDragSequenceEventHandler squiggleEventHandler = new SquiggleEventHandler(); // add the squiggle event handler to both the lens and the // canvas camera. lens.Camera.AddInputEventListener(squiggleEventHandler); camera.AddInputEventListener(squiggleEventHandler); // remove default event handlers, not really nessessary since the squiggleEventHandler // consumes everything anyway, but still good to do. Canvas.RemoveInputEventListener(Canvas.PanEventHandler); Canvas.RemoveInputEventListener(Canvas.ZoomEventHandler); PNode sharedNode = new SharedNode(lens); sharedNode.Brush = Brushes.Green; sharedNode.SetBounds(0, 0, 100, 200); sharedNode.TranslateBy(200, 200); sharedLayer.AddChild(sharedNode); PText label = new PText("Move the lens \n (by dragging title bar) over the green rectangle, and it will appear red. press and drag the mouse on the canvas and it will draw squiggles. press and drag the mouse over the lens and drag squiggles that are only visible through the lens."); label.ConstrainWidthToTextWidth = false; label.SetBounds(200, 100, 200, 200); sharedLayer.AddChild(label); }
public SharedNode(PLens lens) { this.lens = lens; }