public override void Initialize() { PRoot root = Canvas.Root; PCamera camera = Canvas.Camera; //PLayer gridLayer = new GridLayer(); // replace standard layer with grid layer. root.RemoveChild(camera.GetLayer(0)); camera.RemoveLayer(0); root.AddChild(gridLayer); camera.AddLayer(gridLayer); // add constraints so that grid layers bounds always match cameras view bounds. This makes // it look like an infinite grid. camera.BoundsChanged += new PPropertyEventHandler(camera_BoundsChanged); camera.ViewTransformChanged += new PPropertyEventHandler(camera_ViewTransformChanged); gridLayer.Bounds = camera.ViewBounds; PNode n = new PNode(); n.Brush = Brushes.Blue; n.SetBounds(0, 0, 100, 80); Canvas.Layer.AddChild(n); Canvas.RemoveInputEventListener(Canvas.PanEventHandler); Canvas.AddInputEventListener(new GridDragHandler(Canvas)); }
/// <summary> /// Traverse from the bottom right of the scene graph (top visible node) /// up the tree determining which parent nodes are occluded by their children /// nodes. /// </summary> /// <param name="n">The node to find occlusions for.</param> /// <param name="pickPath"> /// A pick path representing the bounds of <c>n</c> in parent coordinates. /// </param> /// <remarks> /// Note that this is only detecting a subset of occlusions (parent, child), /// others such as overlapping siblings or cousins are not detected. /// </remarks> public void DetectOcclusions(PNode n, PPickPath pickPath) { if (n.FullIntersects(pickPath.PickBounds)) { pickPath.PushMatrix(n.MatrixReference); int count = n.ChildrenCount; for (int i = count - 1; i >= 0; i--) { PNode each = n[i]; if (n.Occluded) { // if n has been occluded by a previous decendent then // this child must also be occluded each.Occluded = true; } else { // see if child each occludes n DetectOcclusions(each, pickPath); } } // see if n occludes it's parents if (!n.Occluded) { if (n.Intersects(pickPath.PickBounds)) { if (n.IsOpaque(pickPath.PickBounds)) { PNode p = n.Parent; while (p != null && !p.Occluded) { p.Occluded = true; } } } } pickPath.PopMatrix(n.MatrixReference); } }
public Timeline(int width, int height) { InitializeComponent(); DefaultRenderQuality = RenderQuality.LowQuality; this.Size = new Size(width, height); TimeLineView = this.Layer; Camera.AddLayer(TimeLineView); TimeLineView.MoveToBack(); TimeLineView.Pickable = false; TimeLineView.Brush = new SolidBrush(Color.FromArgb(92, 92, 92)); //BackColor = Color.FromArgb(60, 60, 60); GroupList = new InterpData(); GroupList.Bounds = new RectangleF(0, 0, ListWidth, Camera.Bounds.Bottom - InfoHeight); GroupList.Brush = new SolidBrush(Color.FromArgb(60, 60, 60)); Root.AddChild(GroupList); this.Camera.AddChild(GroupList); TimeLineInfo = new PNode(); TimeLineInfo.Bounds = new RectangleF(0, Camera.Bounds.Bottom - InfoHeight, ListWidth, InfoHeight); TimeLineInfo.Brush = Brushes.Black; Root.AddChild(TimeLineInfo); this.Camera.AddChild(TimeLineInfo); RemoveInputEventListener(PanEventHandler); RemoveInputEventListener(ZoomEventHandler); setupDone = true; }
/// <summary> /// Adds bounds handles to the given node. /// </summary> /// <param name="aNode">The node to isLocal bounds handles to.</param> public static void AddBoundsHandlesTo(PNode aNode) { aNode.AddChild(new PBoundsHandle(PBoundsLocator.CreateEastLocator(aNode))); aNode.AddChild(new PBoundsHandle(PBoundsLocator.CreateWestLocator(aNode))); aNode.AddChild(new PBoundsHandle(PBoundsLocator.CreateNorthLocator(aNode))); aNode.AddChild(new PBoundsHandle(PBoundsLocator.CreateSouthLocator(aNode))); aNode.AddChild(new PBoundsHandle(PBoundsLocator.CreateNorthEastLocator(aNode))); aNode.AddChild(new PBoundsHandle(PBoundsLocator.CreateNorthWestLocator(aNode))); aNode.AddChild(new PBoundsHandle(PBoundsLocator.CreateSouthEastLocator(aNode))); aNode.AddChild(new PBoundsHandle(PBoundsLocator.CreateSouthWestLocator(aNode))); }
public void MasterLayer_OnMouseDown(object sender, PInputEventArgs e) { if (e.PickedNode.Tag.GetType().ToString().Contains("SectorSprite")) { setOriginalText(pSelectedNode); SectorSprite tmp2 = (SectorSprite)e.PickedNode.Tag; PText pnameNew = tmp2.getText(); pnameNew.TextBrush = Brushes.Red; } pSelectedNode = e.PickedNode; }
public override void Initialize() { PLayer layer = Canvas.Layer; PNode aNode = new PNode(); aNode.MouseDown += new PInputEventHandler(aNode_MouseDown); aNode.MouseDrag += new PInputEventHandler(aNode_MouseDrag); aNode.MouseUp += new PInputEventHandler(aNode_MouseUp); aNode.SetBounds(0, 0, 200, 200); aNode.Brush = new SolidBrush(Color.Green); // add another node to the canvas that does not handle events as a reference // point, so that we can make sure that our green node is getting dragged. layer.AddChild(PPath.CreateRectangle(0, 0, 100, 80)); layer.AddChild(aNode); }
public override void Initialize() { Canvas.PanEventHandler = null; Canvas.AddInputEventListener(new PDragEventHandler()); node1 = PPath.CreateEllipse(0, 0, 100, 100); node2 = PPath.CreateEllipse(0, 0, 100, 100); link = PPath.CreateLine(50, 50, 50, 50); link.Pickable = false; Canvas.Layer.AddChild(node1); Canvas.Layer.AddChild(node2); Canvas.Layer.AddChild(link); node2.TranslateBy(200, 200); node1.FullBoundsChanged += new PPropertyEventHandler(node1_FullBoundsChanged); node2.FullBoundsChanged += new PPropertyEventHandler(node2_FullBoundsChanged); }
public InterpData() : base() { InterpGroups = new List<InterpGroup>(); TimelineView = new PNode(); AddChild(TimelineView); TimelineView.MoveToBack(); TimelineView.Pickable = false; //TimelineView.Brush = new SolidBrush(Color.FromArgb(60, 60, 60)); TimelineView.SetBounds(0, 0, 3600, Height); TimelineView.TranslateBy(Timeline.ListWidth, 0); TimeScale = PPath.CreateRectangle(0, 0, 3600, Timeline.InfoHeight); TimeScale.TranslateBy(Timeline.ListWidth, 0); TimeScale.Pickable = false; TimeScale.Brush = new SolidBrush(Color.FromArgb(80, 80, 80)); AddChild(TimeScale); TimeScale.MoveToFront(); //seperationLine = PPath.CreateLine(Timeline.ListWidth, 0, Timeline.ListWidth, 10); //seperationLine.Pickable = false; //AddChild(seperationLine); }
public virtual PActivity DirectCameraViewToFocus(PCamera aCamera, PNode aFocusNode, PPickPath path, int duration) { PMatrix originalViewMatrix = aCamera.ViewMatrix; // Scale the canvas to include SizeF s = new SizeF(1, 0); s = aFocusNode.GlobalToLocal(s); float scaleFactor = s.Width / aCamera.ViewScale; PointF scalePoint = PUtil.CenterOfRectangle(aFocusNode.GlobalFullBounds); if (scaleFactor != 1) { aCamera.ScaleViewBy(scaleFactor, scalePoint.X, scalePoint.Y); } // Pan the canvas to include the view bounds with minimal canvas // movement. aCamera.AnimateViewToPanToBounds(aFocusNode.GlobalFullBounds, 0); // Get rid of any white space. The canvas may be panned and // zoomed in to do this. But make sure not stay constrained by max // magnification. //FillViewWhiteSpace(aCamera); PMatrix resultingMatrix = aCamera.ViewMatrix; aCamera.ViewMatrix = originalViewMatrix; // Animate the canvas so that it ends up with the given // view transform. PActivity animateCameraViewActivity = AnimateCameraViewMatrixTo(aCamera, resultingMatrix, duration); PControl controlNode = (PControl)aFocusNode; aCamera.Root.WaitForActivities(); controlNode.CurrentCanvas = path.TopCamera.Canvas; PointF pf = path.GetPathTransformTo(controlNode).Transform(new PointF(controlNode.X, controlNode.Y)); controlNode.ControlLocation = new Point((int)pf.X, (int)pf.Y); controlNode.Editing = true; return animateCameraViewActivity; }
public override void Initialize() { long currentTime = PUtil.CurrentTimeMillis; // Create a new node that we will apply different activities to, and // place that node at location 200, 200. aNode = PPath.CreateRectangle(0, 0, 100, 80); PLayer layer = Canvas.Layer; layer.AddChild(aNode); aNode.SetOffset(200, 200); // Create a new custom "flash" activity. This activity will start running in // five seconds, and while it runs it will flash aNode's brush color between // red and green every half second. The same effect could be achieved by // extending PActivity and override OnActivityStep. PActivity flash = new PActivity(-1, 500, currentTime + 5000); flash.ActivityStepped = new ActivitySteppedDelegate(ActivityStepped); Canvas.Root.AddActivity(flash); // Use the PNode animate methods to create three activities that animate // the node's position. Since our node already descends from the root node the // animate methods will automatically schedule these activities for us. PActivity a1 = aNode.AnimateToPositionScaleRotation(0f, 0f, 0.5f, 0f, 5000); PActivity a2 = aNode.AnimateToPositionScaleRotation(100f, 0f, 1.5f, 110f, 5000); PActivity a3 = aNode.AnimateToPositionScaleRotation(200f, 100f, 1f, 0f, 5000); // the animate activities will start immediately (in the next call to PRoot.processInputs) // by default. Here we set their start times (in PRoot global time) so that they start // when the previous one has finished. a1.StartTime = currentTime; a2.StartAfter(a1); a3.StartAfter(a2); // or the previous three lines could be replaced with these lines for the same effect. //a2.setStartTime(currentTime + 5000); //a3.setStartTime(currentTime + 10000); }
/// <summary> /// Create a new CommandInterface attached to a specific camera /// </summary> /// <param Name="camera"></param> public CommandInterface(PCamera camera) : base(new PImage(Properties.Resources.Gear)) { Camera = camera; //Add the Auxillary box AuxillaryBox = new PNode(); AddChild(AuxillaryBox); //Add the _Commands _Commands.Add(new ToggleStyleCommand("bold", FontStyle.Bold)); _Commands.Add(new ToggleStyleCommand("italic", FontStyle.Italic)); _Commands.Add(new ToggleStyleCommand("underline", FontStyle.Underline)); _Commands.Add(new ToggleStyleCommand("strike", FontStyle.Strikeout)); _Commands.Add(new StyleCommand()); _Commands.Add(new SizeCommand()); _Commands.Add(new ColorCommand()); _Commands.Add(new CalculateCommand(Camera)); _Commands.Add(new TranslateCommand("En", Camera)); _RecentCommands = _Commands.OrderBy(x => x.Name).Take(4).Reverse().ToList(); Entry.KeyUp += EntryKeyUp; }
/// <summary> /// Unselects the given node, if it is currently selected. /// </summary> /// <param name="node">The node to unselect.</param> /// <returns>True if the node was unselected; otherwise, false.</returns> /// <remarks> /// The handles will be removed from the node if it is unselected. /// </remarks> protected virtual bool InternalUnselect(PNode node) { if (!IsSelected(node)) { return false; } UndecorateSelectedNode(node); selection.Remove(node); return true; }
/// <summary> /// Adds bounds handles to the given node. /// </summary> /// <param name="node">The node to decorate.</param> public virtual void DecorateSelectedNode(PNode node) { PBoundsHandle.AddBoundsHandlesTo(node); }
/// <summary> /// Selects the given node, if it is not already selected. /// </summary> /// <param name="node">The node to select.</param> /// <returns>True if the node was selected; otherwise, false.</returns> /// <remarks> /// The node will be decorated with handles if it is selected. /// </remarks> protected virtual bool InternalSelect(PNode node) { if (IsSelected(node)) { return false; } selection.Add(node, true); DecorateSelectedNode(node); return true; }
/// <summary> /// Constructs a new PSelectionEventHandler that will handle selection for the /// children of the given list of selectable parent nodes. /// </summary> /// <param name="marqueeParent"> /// The node to which the event handler dynamically adds a marquee (temporarily) /// to represent the area being selected. /// </param> /// <param name="selectableParents"> /// A list of nodes whose children will be selected by this event handler. /// </param> public PSelectionEventHandler(PNode marqueeParent, PNodeList selectableParents) { this.marqueeParent = marqueeParent; this.selectableParents = selectableParents; Init(); }
/// <summary> /// Constructs a new PSelectionEventHandler that will handle selection for the /// children of the given selectable parent node. /// </summary> /// <param name="marqueeParent"> /// The node to which the event handler dynamically adds a marquee (temporarily) /// to represent the area being selected. /// </param> /// <param name="selectableParent"> /// The node whose children will be selected by this event handler. /// </param> public PSelectionEventHandler(PNode marqueeParent, PNode selectableParent) { this.marqueeParent = marqueeParent; selectableParents = new PNodeList(); selectableParents.Add(selectableParent); Init(); }
/// <summary> /// Sets the initial press point and press node for the selection. /// </summary> /// <param name="e">A PInputEventArgs that contains the event data.</param> protected virtual void InitializeSelection(PInputEventArgs e) { canvasPressPt = e.CanvasPosition; presspt = e.Position; pressNode = e.Path.PickedNode; if (pressNode is PCamera) { pressNode = null; } }
//**************************************************************** // Selectable Parents - Methods for modifying the set of // selectable parents //**************************************************************** /// <summary> /// Adds the specified node to the list of selectable parents. /// </summary> /// <param name="node">The node to isLocal.</param> /// <remarks> /// Only nodes whose parents are added to the selectable parents list will /// be selectable. /// </remarks> public virtual void AddSelectableParent(PNode node) { selectableParents.Add(node); }
/// <summary> /// Returns true if the specified node is currently selected and false /// otherwise. /// </summary> /// <param name="node">The node to test.</param> /// <returns>True if the node is selected; otherwise, false.</returns> public virtual bool IsSelected(PNode node) { if ((node != null) && (selection.ContainsKey(node))) { return true; } else { return false; } }
/// <summary> /// Unselects the given node, if it is currently selected, and posts a /// SELECTION_CHANGED_NOTIFICATION if the current selection has changed. /// </summary> /// <param name="node">The node to unselect.</param> /// <remarks> /// The handles will be removed from the node if it is unselected. /// </remarks> public virtual void Unselect(PNode node) { if (InternalUnselect(node)) { PostSelectionChanged(); } }
/// <summary> /// Removes bounds handles from the given node. /// </summary> /// <param name="node">The node to undecorate.</param> public virtual void UndecorateSelectedNode(PNode node) { PBoundsHandle.RemoveBoundsHandlesFrom(node); }
/// <summary> /// Constructs a new PNodeTransformTarget. /// </summary> /// <param name="target">The target node.</param> public PNodeTransformTarget(PNode target) { this.target = target; }
/// <summary> /// Determines if the specified node is selectable (i.e., if it is a child /// of a node in the list of selectable parents). /// </summary> /// <param name="node">The node to test.</param> /// <returns>True if the node is selectable; otherwise, false.</returns> protected virtual bool IsSelectable(PNode node) { bool selectable = false; foreach (PNode parent in selectableParents) { if (parent.ChildrenReference.Contains(node)) { selectable = true; break; } else if (parent is PCamera) { PCamera cameraParent = (PCamera)parent; for(int i=0; i<cameraParent.LayerCount; i++) { PLayer layer = cameraParent.GetLayer(i); if (layer.ChildrenReference.Contains(node)) { selectable = true; break; } } } } return selectable; }
/// <summary> /// Constructs a new PNodeColorTarget /// </summary> /// <param name="target">The target node.</param> public PNodeColorTarget(PNode target) { this.target = target; }
/// <summary> /// Removes the specified node from the list of selectable parents. /// </summary> /// <param name="node">The node to remove.</param> public virtual void RemoveSelectableParent(PNode node) { selectableParents.Remove(node); }
/// <summary> /// Add child to this system. /// </summary> /// <param name="child">child</param> public override void AddChild(PNode child) { base.AddChild(child); }
/// <summary> /// Ends a standard selection sequence. /// </summary> /// <param name="e">A PInputEventArgs that contains the event data.</param> /// <remarks> /// <b>Notes to Inheritors:</b> Subclasses can override this method to be notified /// at the End of a standard selection sequence. /// <para> /// Overriding methods must still call <c>base.EndStandardSelection()</c> for correct /// behavior. /// </para> /// </remarks> protected virtual void EndStandardSelection(PInputEventArgs e) { pressNode = null; }
/// <summary> /// Returns true if the node is a selectable parent or a layer that is viewed /// by a camera that is a selectable parent. /// </summary> /// <param name="node">The node to test.</param> /// <returns> /// True if the node's children should be accepted; otherwise, false. /// </returns> public virtual bool AcceptChildrenOf(PNode node) { return selectionHandler.selectableParents.Contains(node) || IsCameraLayer(node); }
/// <summary> /// Returns true if the node's bounds intersects the bounds specified by the /// BoundsFilter. /// </summary> /// <remarks> /// For a node to be accepted, it must also satisfy the following conditions: /// it must be pickable, it must not be the marquee node, it must not be a /// selectable parent, and the it must not be a layer that is viewed by a camera /// that is a selectable parent /// </remarks> /// <param name="node">The node to test.</param> /// <returns>True if the node is accepted; otherwise, false.</returns> public virtual bool Accept(PNode node) { localBounds = bounds; localBounds = node.GlobalToLocal(localBounds); bool boundsIntersects = node.Intersects(localBounds); bool isMarquee = (node == selectionHandler.marquee); return (node.Pickable && boundsIntersects && !isMarquee && !selectionHandler.selectableParents.Contains(node) && !IsCameraLayer(node)); }
/// <summary> /// Returns true if the node a layer that is viewed by a camera that is a /// selectable parent. /// </summary> /// <param name="node">The node to test.</param> /// <returns> /// True if the node is a layer that is viewed by a camera that is a selectable /// parent; otherwise, false. /// </returns> public virtual bool IsCameraLayer(PNode node) { if (node is PLayer) { foreach (PNode parent in selectionHandler.selectableParents) { if (parent is PCamera) { if (((PCamera)parent).IndexOfLayer((PLayer)node) != -1) { return true; } } } } return false; }