示例#1
0
        public void Begin(Rect zoomRect)
        {
            // Ends group that Unity implicity begins for every editor window
            zoomAreaRect = zoomRect;
            GUI.EndGroup();


            Vector2 offset = GetContentOffset();

            //float xFactor = offset.x / bgTexture.width;
            //float yFactor = offset.y / bgTexture.height;

            //GUI.DrawTextureWithTexCoords(zoomAreaRect, bgTexture, // texcoords are between 0 and 1! 1 == fullwrap!
            //	new Rect(xFactor, -yFactor, zoomAreaRect.width / (bgTexture.width * zoomScale),
            //		zoomAreaRect.height / (bgTexture.height * zoomScale)));

            GraphBackground.DrawGraphBackground(zoomAreaRect, -offset, zoomScale);


            Rect clippedArea = ScaleSizeBy(zoomAreaRect, 1.0f / zoomScale, new Vector2(zoomAreaRect.xMin, zoomAreaRect.yMin));

            GUI.BeginGroup(clippedArea);

            prevGUIMatrix = GUI.matrix;

            Matrix4x4 translation = Matrix4x4.TRS(
                new Vector2(clippedArea.xMin, clippedArea.yMin), Quaternion.identity, Vector3.one);
            Matrix4x4 scale = Matrix4x4.Scale(new Vector3(zoomScale, zoomScale, 1f));

            GUI.matrix = translation * scale * translation.inverse * GUI.matrix;
        }
示例#2
0
    public override void DrawPreview(Rect rect)
    {
        GUIStyle style = new GUIStyle(GUI.skin.label)
        {
            fontSize  = 12,
            alignment = TextAnchor.MiddleCenter
        };

        rect = GetCenteredRect(rect);

        // Draw background of the rect we plot points in
        GraphBackground.DrawGraphBackground(rect, rect);
        //EditorGUI.DrawRect(rect, new Color(0.9f, 0.9f, 0.9f));

        float dotSize     = 15; // size in pixels of the point we draw
        float halfDotSize = dotSize * 0.5f;

        float viewportSize = 5; // size of our viewport in Units

        // a value of 10 means we can display any vector from -5,-5 to 5,5 within our rect.
        // change this value for your needs

        for (int i = 0; i < Pattern.arraySize; i++)
        {
            SerializedProperty vectorProperty = Pattern.GetArrayElementAtIndex(i);

            Vector2 vector             = new Vector2(vectorProperty.vector2Value.x, vectorProperty.vector2Value.y);
            Vector2 normalizedPosition = vector / new Vector2(viewportSize, -viewportSize);

            if (Mathf.Abs(normalizedPosition.x) > 0.5f || Mathf.Abs(normalizedPosition.y) > 0.5f)
            {
                // don't draw points outside our viewport
                continue;
            }

            float   l           = (float)i / (float)Pattern.arraySize;
            Color32 lerpedColor = Color32.Lerp(low, high, l);

            Vector2 pixelPosition = rect.center + rect.size * normalizedPosition;
            EditorGUI.DrawRect(new Rect(pixelPosition.x - halfDotSize, pixelPosition.y - halfDotSize, dotSize, dotSize), lerpedColor);
            EditorGUI.LabelField(new Rect(pixelPosition.x - halfDotSize, pixelPosition.y - halfDotSize, dotSize, dotSize), i.ToString(), style);
        }
    }
示例#3
0
        private void DrawViewGeneral()
        {
            if (CurrentView != View.General)
            {
                return;
            }
            m_mode = GraphMode.None;

            var graphArea = new Rect(0, 0, position.width, position.height);

            GraphBackground.DrawGrid(graphArea, 1f, Vector2.zero);

            float splashPadding   = 16f;
            float splashTopOffset = 48f;

            bool drawRecentlyOpenedGraphsBar = NodyWindowSettings.Instance.RecentlyOpenedGraphs.Count > 0;
            var  recentAreaRect = new Rect(graphArea.width - NodyWindowSettings.RECENT_GRAPHS_AREA_WIDTH, 0, NodyWindowSettings.RECENT_GRAPHS_AREA_WIDTH, graphArea.height);

            var splashArea = new Rect(graphArea.x + splashPadding + ToolbarWidth,
                                      graphArea.y + splashPadding,
                                      graphArea.width - splashPadding * 2 - ToolbarWidth - (drawRecentlyOpenedGraphsBar ? recentAreaRect.width : 0),
                                      graphArea.height - splashPadding * 2);

            float width  = 1024;
            float height = 1024;

            float sizeWidthRatio  = 1;
            float sizeHeightRatio = 1;

            if (splashArea.width < width)
            {
                sizeWidthRatio = splashArea.width / width;
            }
            if (splashArea.height - splashTopOffset < height)
            {
                sizeHeightRatio = (splashArea.height - splashTopOffset) / height;
            }

            float sizeRatio = Mathf.Min(sizeWidthRatio, sizeHeightRatio);

            width  *= sizeRatio;
            height *= sizeRatio;

            float x = splashArea.x + splashArea.width / 2 - width / 2;
            float y = splashArea.y + +splashTopOffset + splashArea.height / 2 - height / 2;


            var splashScreenRect = new Rect(x, y, width, height);

            GUI.Box(splashScreenRect, GUIContent.none, SplashScreen);

            if (!drawRecentlyOpenedGraphsBar)
            {
                return;
            }


            //Recent Area
            EditorGUI.DrawRect(recentAreaRect, (EditorGUIUtility.isProSkin ? Color.black.Lighter() : Color.white.Darker()).WithAlpha(NodyWindowSettings.TOOLBAR_OPACITY * 0.6f));
            GUILayout.BeginArea(recentAreaRect);
            {
                DrawRecentOpenedGraphs();
            }
            GUILayout.EndArea();
        }
示例#4
0
        private void DrawViewGraph()
        {
            if (CurrentView != View.Graph)
            {
                return;
            }
            Event current = Event.current;

            if (m_recalculateAllPointRects && current.type == EventType.Repaint)
            {
                CalculateAllPointRects();
                CalculateAllConnectionCurves();
            }

            var graphArea = new Rect(0, 0, position.width, position.height);

            GraphBackground.DrawGrid(graphArea, CurrentZoom, CurrentPanOffset);

            m_graphAreaIncludingTab = new Rect(0, DGUI.Properties.StandardWindowTabHeight, position.width, position.height);
            m_scaledGraphArea       = new Rect(0,
                                               0,
                                               graphArea.width / CurrentZoom,
                                               graphArea.height / CurrentZoom);

            Matrix4x4 initialMatrix = GUI.matrix; //save initial matrix

            GUI.EndClip();
            GUI.BeginClip(new Rect(m_graphAreaIncludingTab.position, m_scaledGraphArea.size));
            {
                Matrix4x4 translation = Matrix4x4.TRS(m_graphAreaIncludingTab.position, Quaternion.identity, Vector3.one);
                Matrix4x4 scale       = Matrix4x4.Scale(Vector3.one * CurrentZoom);
                GUI.matrix = translation * scale * translation.inverse;
                {
                    DrawConnections();
                    DrawNodes(graphArea);
                    DrawSocketsConnectionPoints();
                    DrawLineFromSocketToPosition(m_activeSocket, CurrentMousePosition);
                    DrawSelectionBox();
                }
            }
            GUI.EndClip();
            GUI.BeginClip(m_graphAreaIncludingTab);
            GUI.matrix = initialMatrix; //reset the matrix to the initial value

//            DrawOverlay();

//            DrawGraphName();
//            DrawGraphBottomInfoBar();
//            DrawGraphToolbar();

//            DrawGraphModes();
//            DrawGraphInfo();
//            DrawWindowInfo();

            HandleZoom();
            HandlePanning();


            if (current.mousePosition.x > ToolbarWidth &&
                current.mousePosition.y > NodySettings.Instance.GraphTabsAreaHeight + DGUI.Properties.Space() ||
                m_mode != GraphMode.None)
            {
                HandleMouseHover();
                HandleMouseMiddleClicks();
                HandleMouseLeftClicks();
                HandleMouseRightClicks();
            }

            HandleKeys();

            WhileDraggingUpdateSelectedNodes();

            UpdateNodesActiveNode();
        }