public void SetZoomedWindowRect(Vector2 zoomOrigin, float zoomScale) { zoomedWindowRect = windowRect; zoomedWindowRect = RectExtensions.ScaleSizeBy(zoomedWindowRect, zoomScale, zoomOrigin); zoomedWindowRect.x -= zoomOrigin.x; zoomedWindowRect.y -= zoomOrigin.y; }
public VisualCapturer(SilverlightSceneView sceneView, Size targetSize) : base(targetSize) { SilverlightArtboard silverlightArtboard = (SilverlightArtboard)sceneView.Artboard; Rect documentBounds = silverlightArtboard.DocumentBounds; ImageHost silverlightImageHost = silverlightArtboard.SilverlightImageHost; if (documentBounds.Width <= 0.0 || documentBounds.Height <= 0.0) { return; } using (new VisualCapturer.ImageHostActivator(silverlightImageHost)) { silverlightImageHost.SetTransformMatrix(Matrix.Identity, new Vector(1.0, 1.0)); silverlightImageHost.Measure(documentBounds.Size); silverlightImageHost.Arrange(documentBounds); silverlightImageHost.UpdateLayout(); silverlightImageHost.Redraw(false); double proportionalScale = RectExtensions.GetProportionalScale(documentBounds, targetSize); documentBounds.Scale(proportionalScale, proportionalScale); Image image1 = new Image(); image1.Source = silverlightImageHost.InternalSource; image1.LayoutTransform = (Transform) new ScaleTransform(proportionalScale, proportionalScale); Image image2 = image1; image2.Measure(documentBounds.Size); image2.Arrange(documentBounds); this.DefaultSize = new Size(documentBounds.Width, documentBounds.Height); this.visual = (Visual)image2; } }
public Rect Layout(Vector2 position, float footprint_height) { return(RectExtensions.CreateMinMaxRect( position + new Vector2(left_offset, bottom_offset), position + new Vector2(right_offset, top_offset + footprint_height) )); }
internal virtual Geometry GetSelectionOutline(DataPoint dataPoint) { if (dataPoint.View != null) { FrameworkElement frameworkElement = dataPoint.View.MainView ?? dataPoint.View.MarkerView; if (frameworkElement != null) { Rect rect; if (dataPoint.View.AnchorRectOrientation == RectOrientation.None) { Rect layoutSlot = LayoutInformation.GetLayoutSlot(frameworkElement); Point anchorPoint = dataPoint.View.AnchorPoint; rect = new Rect(anchorPoint.X - layoutSlot.Width / 2.0, anchorPoint.Y - layoutSlot.Height / 2.0, layoutSlot.Width, layoutSlot.Height); } else { rect = dataPoint.View.AnchorRect; } return((Geometry) new RectangleGeometry() { Rect = RectExtensions.TranslateToParent(rect, frameworkElement, (FrameworkElement)this.ChartArea) }); } } return((Geometry)null); }
public override Rect Apply(Rect oldDataRect, Rect newDataRect, Viewport2D viewport) { Rect output = viewport.Output; if (output.Width == 0 || output.Height == 0) { return(newDataRect); } double screenRatio = output.Width / output.Height; double viewportRatio = newDataRect.Width / newDataRect.Height; double ratio = screenRatio / viewportRatio; double width = proportionRatio * newDataRect.Width * ratio; double height = newDataRect.Height; if (width < newDataRect.Width) { height = newDataRect.Height / proportionRatio / ratio; width = newDataRect.Width; } Point center = newDataRect.GetCenter(); Rect res = RectExtensions.FromCenterSize(center, width, height); return(res); }
protected override Rect GetBoundingRectangleCore() { if (this.Series == null || this.Series.ChartArea == null || !this.Series.ChartArea.IsTemplateApplied) { return(base.GetBoundingRectangleCore()); } FrameworkElement dataPointView = SeriesVisualStatePresenter.GetDataPointView(this.DataPoint); if (dataPointView != null) { return(new FrameworkElementAutomationPeer(dataPointView).GetBoundingRectangle()); } AutomationPeer peerForElement = UIElementAutomationPeer.CreatePeerForElement((UIElement)this.Series); if (!(this.Series is LineSeries) || this.DataPoint.View == null || peerForElement == null) { return(base.GetBoundingRectangleCore()); } Point anchorPoint = this.DataPoint.View.AnchorPoint; Rect rectangle = RectExtensions.Expand(new Rect(anchorPoint.X, anchorPoint.Y, 0.0, 0.0), 2.0, 2.0); Rect boundingRectangle = peerForElement.GetBoundingRectangle(); Size renderSize = this.Series.SeriesPresenter.RootPanel.RenderSize; Size size = RectExtensions.GetSize(boundingRectangle); return(RectExtensions.Translate(RectExtensions.Transform(rectangle, (Transform) new ScaleTransform() { ScaleX = (size.Width / renderSize.Width), ScaleY = (size.Height / renderSize.Height) }), boundingRectangle.X, boundingRectangle.Y)); }
private void UpdateLittleVisible(Point pos) { Size littleSize = new Size(Plotter2D.Viewport.Visible.Width / zoomCoeff * ActualWidth / Plotter2D.Viewport.Output.Width, Plotter2D.Viewport.Visible.Height / zoomCoeff * ActualHeight / Plotter2D.Viewport.Output.Height); Rect littleVisible = RectExtensions.FromCenterSize(pos.ScreenToViewport(Plotter2D.Viewport.Transform), littleSize); littlePlotter.Viewport.Visible = littleVisible; }
/// <summary> /// Initializes a view representation of a model element /// </summary> /// <param name="modelElement">Element to be represented</param> /// <param name="viewHelper">Element's viewHelper</param> /// <param name="controller">Element's controller</param> public override void InitializeRepresentant(Element modelElement, ViewHelper viewHelper, ElementController controller) { PIM_Association associationRepresentant = new PIM_Association(XCaseCanvas); associationRepresentant.InitializeRepresentant(modelElement, ((AssociationClassViewHelper)viewHelper).AssociationViewHelper, new AssociationController((Association)modelElement, controller.DiagramController)); Association = associationRepresentant; Association.AssociationClass = this; Association.AssociationName = null; Association.ViewHelper.MainLabelViewHelper.LabelVisible = false; AssociationClassViewHelper _viewHelper = (AssociationClassViewHelper)viewHelper; if (double.IsNaN(_viewHelper.X) || double.IsNaN(_viewHelper.Y)) { Rect r = RectExtensions.GetEncompassingRectangle(associationRepresentant.participantElements.Values); if (associationRepresentant.participantElements.Count > 2) { _viewHelper.X = r.GetCenter().X + 30; _viewHelper.Y = r.GetCenter().Y; } else { _viewHelper.X = r.GetCenter().X; _viewHelper.Y = r.GetCenter().Y + 20; } } base.InitializeRepresentant(modelElement, viewHelper, controller); if (associationRepresentant.ViewHelper.UseDiamond) { if (((AssociationClassViewHelper)ViewHelper).Points.Count == 0) { ((AssociationClassViewHelper)ViewHelper).Points.AppendRange( JunctionGeometryHelper.ComputeOptimalConnection(this, associationRepresentant.Diamond)); ((AssociationClassViewHelper)ViewHelper).Points.PointsInvalid = true; } junction = new XCaseJunction(XCaseCanvas, ((AssociationClassViewHelper)ViewHelper).Points) { Pen = MediaLibrary.DashedBlackPen }; XCaseCanvas.Children.Add(junction); junction.NewConnection(this, null, Association.Diamond, null, ((AssociationClassViewHelper)ViewHelper).Points); junction.SelectionOwner = this; } else { primitiveJunction = new XCasePrimitiveJunction(XCaseCanvas, this, Association) { Pen = MediaLibrary.DashedBlackPen }; } this.StartBindings(); }
private RectangleGeometry GetBoundingRectangle(FrameworkElement element) { Rect rect = element == this.ChartArea ? new Rect(0.0, 0.0, this.ActualWidth, this.ActualHeight) : LayoutInformation.GetLayoutSlot(element); return(new RectangleGeometry() { Rect = RectExtensions.TranslateToParent(rect, element, (FrameworkElement)this.ChartArea) }); }
void pt_PositionChanged(object sender, PositionChangedEventArgs e) { DraggablePoint pt = (DraggablePoint)sender; Ellipse ellipse = (Ellipse)pt.Tag; Rect bounds = RectExtensions.FromCenterSize(e.Position, xSize, ySize); //ViewportRectPanel.SetPoint1(ellipse, bounds.TopLeft); //ViewportRectPanel.SetPoint2(ellipse, bounds.BottomRight); }
private static Rect GetScaledRectangle(FrameworkElement element, Size targetSize, out double scale) { Rect rect = new Rect(0.0, 0.0, 0.0, 0.0); element.Measure(rect.Size); element.Arrange(rect); element.UpdateLayout(); rect = new Rect(0.0, 0.0, element.ActualWidth, element.ActualHeight); scale = RectExtensions.GetProportionalScale(rect, targetSize); rect.Scale(scale, scale); return(rect); }
public static Rect GetBoundsRect() { List <Rect> levelBoundRectsInstances = new List <Rect>(); foreach (Renderer renderer in FindObjectsOfType <Renderer>()) { if (renderer.GetComponent <OmitFromLevelMap>() == null) { levelBoundRectsInstances.Add(renderer.bounds.ToRect()); } } return(RectExtensions.Combine(levelBoundRectsInstances.ToArray())); }
protected Rect EnlargeRect(Rect rect) { Size newSize = rect.Size; newSize.Width += 1; newSize.Height += 1; Rect result = RectExtensions.FromCenterSize(rect.GetCenter(), newSize); return(result); //double coeff = 1 + 1.0 / tileWidth; //return EnlargeRect(rect, coeff); }
/// <summary> /// Returns bounding rectangle of the element (rectangle containing all points of the junction). /// </summary> /// <returns>Bounding rectangle</returns> public Rect GetBounds() { Point[] p = new Point[Points.Count()]; int i = 0; foreach (JunctionPoint point in Points) { //p[i] = point.TranslatePoint(point.Position, XCaseCanvas); p[i] = point.CanvasPosition; i++; } return(RectExtensions.GetEncompassingRectangle(p)); }
public override Rect Apply(Rect oldDataRect, Rect newDataRect, Viewport2D viewport) { double ratio = newDataRect.Width / newDataRect.Height; double coeff = Math.Sqrt(ratio); double newWidth = newDataRect.Width / coeff; double newHeight = newDataRect.Height * coeff; Point center = newDataRect.GetCenter(); Rect res = RectExtensions.FromCenterSize(center, newWidth, newHeight); return(res); }
public static Rect GetWorldRect(this RectTransform transform) { transform.GetWorldCorners(_worldRectCache); /*for (int i = 0; i < _worldRectCache.Length; i++) * { * var vector3 = _worldRectCache[i]; * UIDebug.Point("worldpoint"+i, vector3, Color.blue, 10); * }*/ var rect = new Rect(_worldRectCache[0], Vector2.zero); rect = RectExtensions.Encapsulate(rect, _worldRectCache[2]); rect = RectExtensions.Encapsulate(rect, _worldRectCache[1]); rect = RectExtensions.Encapsulate(rect, _worldRectCache[3]); return(rect); }
internal static double DistanceToLineSegment(this Point point, IList polyline, double delta) { double num1 = double.NaN; for (int index = 0; index < polyline.Count - 1; ++index) { Point point1 = (Point)polyline[index]; Point point2 = (Point)polyline[index + 1]; double num2 = PointExtensions.DistanceToLine(point, point1, point2); bool flag = Math.Abs(point1.X - point2.X) < 1E-06 ? PointExtensions.IsYBetween(point, point1, point2) : PointExtensions.IsXBetween(point, point1, point2); if (num2 < delta && flag || RectExtensions.AroundPoint(point1, point, delta)) { num1 = num2; break; } } return(num1); }
protected override void DrawArrayInternal(Rect rect, int array_size) { EditProperty_Array property = GetProperty(); EditorGUI.DrawRect(border_rect, Color.black); EditorGUI.DrawRect(background_rect, Color.gray); float x = background_rect.xMin; float y = background_rect.yMax; float element_width = background_rect.width / array_size; float element_max_height = background_rect.height; for (int i = 0; i < array_size; i++) { float value; if (property.TryGetElementValue <float>(i, out value)) { float height = element_max_height * value.ConvertFromRangeToPercent(min_value, max_value); EditorGUI.DrawRect(RectExtensions.CreateMinMaxRect( new Vector2(x, y), new Vector2(x + element_width, y - height) ), Color.cyan); } x += element_width; } Vector2 percent; if (GUIExtensions.MousePercentArea(background_rect, out percent, true, true)) { int index = (int)(array_size * percent.x); float magnitude = 1.0f - percent.y; if (property.IsIndexValid(index)) { property.SetElementValue(index, magnitude.ConvertFromPercentToRange(min_value, max_value)); } } }
/// <summary> /// Configures the rectangle used for selection /// </summary> public override void AfterEditorEvents() { CheckActivation(); if (!IsActivated) { return; } if (Event.current.button != 0) { Cancel(); Event.current.Use(); return; } if (Event.current.type == EventType.MouseDrag) { Vector2 startPoint = NodeEditor.ApplyZoomToVector(dragStartPos); Vector2 endPoint = NodeEditor.GetZoomedMousePosition(); selectionRect = RectExtensions.FromPoints(startPoint, endPoint); NodeEditor.FlagRepaint(); Event.current.Use(); } else if (Event.current.type == EventType.MouseUp) { SelectNodes(); SelectConnectors(); NodeEditor.RaiseSelectionChanged(); selectionRect = Rect.zero; Deactivate(); Event.current.Use(); } else if (Event.current.type == EventType.MouseLeaveWindow) { Cancel(); } }
public virtual void Start() { Canvas.ForceUpdateCanvases(); RectTransform[] children = GetComponentsInChildren <RectTransform>(); children = children.Remove(combinedRectTrs); Rect[] graphicRects = new Rect[children.Length]; for (int i = 0; i < children.Length; i++) { graphicRects[i] = children[i].GetRectInCanvasNormalized(canvasRectTrs); } Rect combinedRect = RectExtensions.Combine(graphicRects); Vector2 combinedRectCenter; combinedRectCenter = combinedRect.center; combinedRect.size = combinedRect.size.Multiply(canvasRectTrs.sizeDelta); combinedRect.center = combinedRectCenter.Multiply(canvasRectTrs.sizeDelta); combinedRectTrs.sizeDelta = combinedRect.size; rectTrs = combinedRectTrs; }
protected override void OnRender(DrawingContext drawingContext) { var dc = drawingContext; Rect bounds = new Rect(RenderSize); dc.DrawRectangle(Brushes.Orange.MakeTransparent(0.3), null, bounds); if (points == null) { return; } for (int i = 0; i < points.Length; i++) { Point viewportPt = points[i]; var screenPoint = new Point(viewportPt.X * bounds.Width, viewportPt.Y * bounds.Height); dc.DrawRectangle(Brushes.Blue, null, RectExtensions.FromCenterSize(screenPoint, new Size(2, 2))); } }
public static bool IsUnderPoint(this GameObject gameObject, Vector2 point) { BoxCollider2D boxCollider2D = gameObject.GetComponent <BoxCollider2D> (); if (boxCollider2D != null) { Rect r = RectExtensions.FromCollider(boxCollider2D); return(r.Contains(point)); } CircleCollider2D circleCollider2D = gameObject.GetComponent <CircleCollider2D> (); if (circleCollider2D != null) { Vector2 dist = ((Vector2)circleCollider2D.transform.position + circleCollider2D.offset) - point; return(dist.magnitude < circleCollider2D.radius); } Debug.LogWarning("IsUnderPoint : No collider on object " + gameObject.name); return(false); }
public static GameObject GetChildUnderPoint(this GameObject gameObject, Vector2 point) { int count = gameObject.transform.childCount; for (int i = 0; i < count; i++) { GameObject child = gameObject.transform.GetChild(i).gameObject; BoxCollider2D boxCollider2D = child.GetComponent <BoxCollider2D> (); if (boxCollider2D != null) { Rect r = RectExtensions.FromCollider(boxCollider2D); // Debug.Log ( "Rect : " + r.ToString() + " - Point : " + point.ToString() ); if (r.Contains(point)) { return(child); } } } return(null); }
public override void Render(DrawingContext dc, Point screenPoint) { FormattedText textToDraw = new FormattedText(Text, Thread.CurrentThread.CurrentCulture, FlowDirection.LeftToRight, new Typeface("Arial"), 12, Brushes.Black); double width = textToDraw.Width; double height = textToDraw.Height; const double verticalShift = -20; // px Rect bounds = RectExtensions.FromCenterSize(new Point(screenPoint.X, screenPoint.Y + verticalShift - height / 2), new Size(width, height)); Point loc = bounds.Location; bounds = CoordinateUtilities.RectZoom(bounds, 1.05, 1.15); dc.DrawLine(new Pen(Brushes.Black, 1), Point.Add(screenPoint, new Vector(0, verticalShift)), screenPoint); dc.DrawRectangle(Brushes.White, new Pen(Brushes.Black, 1), bounds); dc.DrawText(textToDraw, loc); }
internal override Geometry GetSelectionOutline(DataPoint dataPoint) { if (dataPoint.View == null) { return((Geometry)null); } Rect rect1 = new Rect(0.0, 0.0, 6.0, 6.0); Point anchorPoint = dataPoint.View.AnchorPoint; if (double.IsNaN(anchorPoint.X) || double.IsInfinity(anchorPoint.X) || (double.IsNaN(anchorPoint.Y) || double.IsInfinity(anchorPoint.Y))) { return((Geometry)null); } Rect rect2 = new Rect(anchorPoint.X - rect1.Width / 2.0, anchorPoint.Y - rect1.Height / 2.0, rect1.Width, rect1.Height); FrameworkElement child = Enumerable.FirstOrDefault <FrameworkElement>(Enumerable.OfType <FrameworkElement>((IEnumerable)this.RootPanel.Children)); return((Geometry) new RectangleGeometry() { Rect = RectExtensions.Expand(RectExtensions.TranslateToParent(rect2, child, (FrameworkElement)this.ChartArea), 1.0, 1.0) }); }
public static BitmapSource OverlayInk(BitmapSource bitmapSource, double scale, StrokeCollection inkStrokes) { if (bitmapSource == null) { return((BitmapSource)null); } if (inkStrokes == null || inkStrokes.Count == 0) { return(bitmapSource); } Rect rect1 = new Rect(0.0, 0.0, (double)bitmapSource.PixelWidth, (double)bitmapSource.PixelHeight); Vector offsetVector = (Vector)RectExtensions.GetCenter(rect1); Rect rect2 = RectExtensions.Union(Enumerable.Select <Stroke, Rect>((IEnumerable <Stroke>)inkStrokes, (Func <Stroke, Rect>)(stroke => stroke.GetBounds()))); rect2.Scale(scale, scale); rect2.Offset(offsetVector); Rect rect3 = Rect.Union(rect1, rect2); Canvas canvas1 = new Canvas(); canvas1.Width = rect3.Width; canvas1.Height = rect3.Height; canvas1.Children.Add((UIElement) new Image() { Source = (ImageSource)bitmapSource }); UIElementCollection children = canvas1.Children; InkPresenter inkPresenter1 = new InkPresenter(); inkPresenter1.Strokes = inkStrokes; inkPresenter1.Margin = new Thickness(offsetVector.X, offsetVector.Y, -offsetVector.X, -offsetVector.Y); inkPresenter1.LayoutTransform = (Transform) new ScaleTransform(scale, scale); InkPresenter inkPresenter2 = inkPresenter1; children.Add((UIElement)inkPresenter2); Canvas canvas2 = canvas1; Point newOrigin = new Point(-rect3.Left, -rect3.Top); EnumerableExtensions.ForEach <UIElement>(Enumerable.OfType <UIElement>((IEnumerable)canvas2.Children), (Action <UIElement>)(child => DependencyObjectExtensions.SetCanvasPos((DependencyObject)child, newOrigin))); return(new FrameworkElementCapturer((FrameworkElement)canvas2, ImageCapturer.MaxSize).Capture()); }
protected override Size ArrangeOverride(Size finalSize) { using (new DebugDisposableTimer("ViewportPanel arrange")) { if (plotter == null) { return(finalSize); } var transform = plotter.Viewport.Transform; foreach (UIElement element in base.InternalChildren) { if (element == null) { continue; } double x = GetDataX(element); if (Double.IsNaN(x)) { x = 0; } double y = GetDataY(element); if (Double.IsNaN(y)) { y = 0; } Point screenPos = new Point(x, y).DataToScreen(transform); Rect bounds = RectExtensions.FromCenterSize(screenPos, element.DesiredSize); element.Arrange(bounds); } return(finalSize); } }
public override void Execute(object parameter) { IEnumerable <PIM_Class> selectedClasses = ActiveDiagramView.SelectedItems.OfType <PIM_Class>(); Class[] classes = new Class[selectedClasses.Count()]; int i = 0; foreach (PIM_Class xCaseClass in selectedClasses) { classes[i] = (Class)xCaseClass.ModelElement; i++; } Rect r = RectExtensions.GetEncompassingRectangle(selectedClasses.OfType <IConnectable>()); if (selectedClasses.Count() > 2) { ActiveDiagramView.Controller.NewAssociationClass(null, classes); //r.GetCenter().X + 30, r.GetCenter().Y ); } else { ActiveDiagramView.Controller.NewAssociationClass(null, classes); //r.GetCenter().X, r.GetCenter().Y + 20); } }
private void HandleEditorEvents(NodeGroup group) { int multi_select_nodes = EditorPrefs.GetInt("nodify.hotkeys.multi_select_nodes", 303); // Begin Context Menu Controls if (Event.current.type == EventType.ContextClick) { if (NodifyEditorUtilities.currentConnectingAnchor != null) { NodifyEditorUtilities.currentConnectingAnchor = null; Event.current.Use(); } else { ShowNodeCreationMenu(); Event.current.Use(); } } if (Event.current.type == EventType.KeyDown) { // Begin Focus Element Control if (Event.current.keyCode == (KeyCode)EditorPrefs.GetInt("nodify.hotkeys.focus_on_selected_node2", 102) && NodifyPreferencesGUI.GetAdditionalButtons(EditorPrefs.GetInt("nodify.hotkeys.focus_on_selected_node", 0))) { if (Selection.activeGameObject != null) { if (Selection.activeGameObject.GetComponent <Node>()) { FocusNode(group, Selection.activeGameObject.GetComponent <Node>()); } if (Selection.activeGameObject.GetComponent <Anchor>()) { FocusNode(group, Selection.activeGameObject.GetComponent <Anchor>().parent); } } ForceRepaint(); } if (Event.current.keyCode == KeyCode.Delete || Event.current.keyCode == KeyCode.Backspace) { for (int i = Selection.gameObjects.Length - 1; i >= 0; i--) { GameObject obj = Selection.gameObjects[i]; if (obj != NodifyEditorUtilities.currentSelectedGroup.gameObject && (obj.GetComponent <Node>() || obj.GetComponent <Anchor>())) { if (EditorUtility.DisplayDialog("Are you sure?", "Do you wish to delete the node: " + obj.name, "Delete", "Cancel")) { NodifyEditorUtilities.SafeDestroy(obj); } } } } } // Begin Mouse Selection Events if (NodifyEditorUtilities.currentManipulatingNode == null && NodifyPreferencesGUI.GetAdditionalButtons(EditorPrefs.GetInt("nodify.hotkeys.multi_select_nodes", 303))) { switch (Event.current.type) { case EventType.MouseDown: if (Event.current.button == 0) { MouseSelectionStartPoint = Event.current.mousePosition; MouseSelection = true; ForceRepaint(); } break; case EventType.MouseUp: if (MouseSelection == true) { SelectNodesInRect(RectExtensions.GetRectFromPoints(MouseSelectionStartPoint, Event.current.mousePosition)); MouseSelection = false; } ForceRepaint(); break; case EventType.MouseDrag: if (Event.current.button == 0) { ForceRepaint(); } else if (Event.current.button == 2) // Begin Mouse Drag Controls { if (new Rect(0, 0, position.width, position.height).Contains(Event.current.mousePosition)) { Vector2 mouseDelta = Event.current.delta; Vector2 mouseZoomDelta = (1f / group.editorZoomAmount) * mouseDelta; group.editorWindowOffset += mouseZoomDelta; Event.current.Use(); } } break; } } if (Event.current.type == EventType.MouseDrag && multi_select_nodes != 0 && !NodifyPreferencesGUI.GetAdditionalButtons(EditorPrefs.GetInt("nodify.hotkeys.multi_select_nodes", 303))) { if (new Rect(0, 0, position.width, position.height).Contains(Event.current.mousePosition)) { Vector2 mouseDelta = Event.current.delta; Vector2 mouseZoomDelta = (1f / group.editorZoomAmount) * mouseDelta; group.editorWindowOffset += mouseZoomDelta; } } // Begin Zoom Controls if (Event.current.type == EventType.ScrollWheel) { group.editorZoomAmount -= Event.current.delta.y / 80; group.editorZoomAmount = (float)System.Math.Round((double)Mathf.Clamp(group.editorZoomAmount, minimumZoomFactor, maximumZoomFactor), 2); Event.current.Use(); } if (Event.current.type == EventType.MouseDown && multi_select_nodes != 0 && NodifyPreferencesGUI.GetAdditionalButtons(EditorPrefs.GetInt("nodify.hotkeys.deselect_all", 303))) { Selection.objects = new UnityEngine.Object[0]; Event.current.Use(); } // Begin Drag & Drop Components into Variables if (Event.current.type == EventType.DragPerform || Event.current.type == EventType.DragUpdated) { DragAndDrop.visualMode = DragAndDropVisualMode.Link; if (Event.current.type == EventType.DragPerform) { DragAndDrop.AcceptDrag(); foreach (UnityEngine.Object obj in DragAndDrop.objectReferences) { foreach (CreateMenu nodeMenu in NodifyEditorUtilities.FindNodeTypes()) { if (nodeMenu.type.BaseType.IsGenericType) { if (nodeMenu.type.BaseType.GetGenericArguments()[0] == obj.GetType()) { GameObject nodeObj = new GameObject(obj.GetType().Name); #if UNITY_5 Node nodeClass = (Node)nodeObj.AddComponent(nodeMenu.type); #else Node nodeClass = (Node)UnityEngineInternal.APIUpdaterRuntimeServices.AddComponent(nodeObj, "Assets/Nodify/Editor/NodifyEditorWindow.cs (635,32)", nodeMenu.type.Name); #endif nodeClass.editorPosition = Event.current.mousePosition - group.editorWindowOffset; nodeClass.editorResourceIcon = nodeMenu.iconResourcePath; nodeClass.OnEditorNodeCreated(); nodeObj.transform.parent = group.transform; nodeClass.GetType().GetField("value").SetValue(nodeClass, obj); } } } } } } }
public void OnGUI() { AssignSelectedGroup(); NodeGroup selectedGroup = NodifyEditorUtilities.currentSelectedGroup; if (selectedGroup != null) { selectedGroup.SetHideStateChildrenNonNodes(HideFlags.None); OnDrawEditorBackground(); NodifyEditorUtilities.BeginZoomArea(selectedGroup.editorZoomAmount, new Rect(0, 0, Screen.width, Screen.height)); this.RemoveNotification(); selectedGroup.editorWindowOffset.x = Mathf.Min(selectedGroup.editorWindowOffset.x, 0); selectedGroup.editorWindowOffset.y = Mathf.Min(selectedGroup.editorWindowOffset.y, 0); this.OnDrawEditorGrid(); if (selectedGroup != null) { if (NodifyEditorUtilities.currentConnectingAnchor != null) { DrawCurrentConnectingAnchor(NodifyEditorUtilities.currentConnectingAnchor); } /// Begin Node Anchor Rendering (Anchors rendered behind everything) foreach (Node node in selectedGroup.childNodes) { foreach (Anchor anchor in node.anchors) { for (int i = 0; i < anchor.anchorConnections.Count; i++) { if (anchor.anchorConnections[i] == null) { continue; } DrawAnchorConnection(anchor.anchorConnections[i]); } for (int i = 0; i < anchor.nodeConnections.Count; i++) { if (anchor.nodeConnections[i] == null) { continue; } DrawNodeConnection(anchor.nodeConnections[i]); } } } // End Node Anchor Rendering //Begin Node Group Anchor Rendering foreach (NodeGroup nodeGroup in selectedGroup.childGroups) { foreach (Anchor anchor in nodeGroup.anchors) { foreach (AnchorConnection connection in anchor.anchorConnections) { DrawAnchorConnection(connection); } foreach (NodeConnection connection in anchor.nodeConnections) { DrawNodeConnection(connection); } } } // End Node Group Anchor Rendering // Node Rendering foreach (Node node in selectedGroup.childNodes) { if (node.GetComponent <NodeGroup>()) { continue; } foreach (Anchor anchor in node.anchors) { DrawAnchor(anchor); } DrawNode(node); } // End Node Rendering // Node Group Rendering foreach (NodeGroup nodeGroup in selectedGroup.childGroups) { if (nodeGroup == selectedGroup) { continue; } foreach (Anchor anchor in nodeGroup.anchors) { DrawAnchor(anchor); } DrawNodeGroup(nodeGroup); } // End Node Group Rendering } NodifyEditorUtilities.EndZoomArea(); HandleEditorEvents(selectedGroup); if (MouseSelection == true && Event.current.type == EventType.Repaint) { editorSelectionRect.Draw(RectExtensions.GetRectFromPoints(MouseSelectionStartPoint, Event.current.mousePosition), false, false, false, false); } } else { ShowNotification(new GUIContent("Create or Select a Node Group")); } DrawToolbar(); DrawBreadcrumbs(); DrawLogo(); if (ShouldRepaint()) { this.Repaint(); } }