Exemplo n.º 1
0
        /// <summary>
        /// Begins a scaled local area.
        /// Returns vector to offset GUI controls with to account for zooming to the pivot.
        /// Using adjustGUILayout does that automatically for GUILayout rects. Theoretically can be nested!
        /// </summary>
        public static Vector2 BeginScale(ref Rect rect, Vector2 zoomPivot, float zoom, bool adjustGUILayout)
        {
            Rect screenRect;

            GUIScaleUtility.BeginNoClip();
            screenRect = GUIScaleUtility.GUIToScaledSpace(rect);

            rect = Scale(screenRect, screenRect.position + zoomPivot, new Vector2(zoom, zoom));

            // Now continue drawing using the new clipping group
            GUI.BeginGroup(rect);
            rect.position = Vector2.zero;             // Adjust because we entered the new group

            // Because I currently found no way to actually scale to a custom pivot rather than (0, 0),
            // we'll make use of a cheat and just offset it accordingly to let it appear as if it would scroll to the center
            // Note, due to that, controls not adjusted are still scaled to (0, 0)
            Vector2 zoomPosAdjust = rect.center - screenRect.size / 2 + zoomPivot;

            // Take a matrix backup to restore back later on
            GUIMatrices.Add(GUI.matrix);

            // Scale GUI.matrix. After that we have the correct clipping group again.
            GUIUtility.ScaleAroundPivot(new Vector2(1 / zoom, 1 / zoom), zoomPosAdjust);

            return(zoomPosAdjust);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Ends a scale region previously opened with BeginScale
        /// </summary>
        public static void EndScale()
        {
            // Set last matrix and clipping group
            if (GUIMatrices.Count == 0)
            {
                throw new UnityException("GUIScaleUtility: You are ending more scale regions than you are beginning!");
            }
            GUI.matrix = GUIMatrices[GUIMatrices.Count - 1];
            GUIMatrices.RemoveAt(GUIMatrices.Count - 1);

            // End the scaled group
            GUI.EndGroup();

            GUIScaleUtility.RestoreClips();
        }
Exemplo n.º 3
0
        //draw the default node graph:
        public override void OnGUI()
        {
            base.OnGUI();

            if (graph == null)
            {
                RenderGraphNotFound();
                return;
            }

            //update the current GUI settings storage and clear drawed popup list:
            PWGUI.StartFrame(position);

            //set the skin for the current window
            GUI.skin = PWGUISkin;

            if (!graph.presetChoosed)
            {
                return;
            }

            RenderBackground();

            //protection against node class rename & corrupted nodes
            for (int i = 0; i < graph.nodes.Count; i++)
            {
                var node = graph.nodes[i];
                if (node == null)
                {
                    graph.nodes.RemoveAt(i);
                }
                else if (node.GetType() == typeof(BaseNode))
                {
                    graph.RemoveNode(node);
                }
            }

            //disable events if mouse is above an eventMask Rect.
            eventMasks = layout.GetRects();
            MaskEvents();

            //profiling
            Profiler.BeginSample("[PW] Graph redering (" + e.type + ")");

            Rect pos = position;

            pos.position            = Vector2.zero;
            graph.zoomPanCorrection = GUIScaleUtility.BeginScale(ref pos, pos.size / 2, 1f / graph.scale, false);
            {
                //draw the background:
                RenderBackground();

                //manage selection:
                SelectAndDrag();

                //graph rendering
                RenderOrderingGroups();
                RenderLinks();
                RenderNodes();

                //context menu
                ContextMenu();

                //fill and process remaining events if there is
                ManageEvents();

                //reset events for the next frame
                editorEvents.Reset();

                if (e.type == EventType.Repaint)
                {
                    Repaint();
                }
            }
            GUIScaleUtility.EndScale();

            Profiler.EndSample();

            //restore masked events:
            UnMaskEvents();

            //update delayedChanges
            delayedChanges.Update();
        }