Ejemplo n.º 1
0
        public void DrawHud(int width, int height, Point center, Color crosshair)
        {
            GL.MatrixMode(MatrixMode.Projection);
            GL.PushMatrix();
            GL.LoadIdentity();
            GL.Ortho(0, width, height, 0, 0, 1);

            GL.MatrixMode(MatrixMode.Modelview);
            GL.LoadIdentity();

            GL.Clear(ClearBufferMask.DepthBufferBit);

            GL.LineWidth(1);

            GLUtils.SafeBegin(BeginMode.Lines, () =>
            {
                GL.Color3(crosshair);

                GL.Vertex2(center.X - 2, center.Y);
                GL.Vertex2(center.X + 3, center.Y);
                GL.Vertex2(center.X, center.Y - 3);
                GL.Vertex2(center.X, center.Y + 2);
            });

            GL.MatrixMode(MatrixMode.Projection);
            GL.PopMatrix();
        }
Ejemplo n.º 2
0
        private void DoSelectionPass()
        {
            // turn off lighting and draw world as flat colored objects who's color corresponds to their node id
            GLUtils.SafeDisable(EnableCap.Lighting, () =>
            {
                // reset vbo
                Nodes.Reset();

                // call render
                Model.Render();

                // load vbo
                Nodes.Load();

                // draw node vbo
                Nodes.Draw(BeginMode.Triangles);

                // read pixel at cursor
                byte[] rgb = new byte[3];
                GL.ReadPixels(SelectionPoint.X, Height - SelectionPoint.Y, 1, 1, PixelFormat.Rgb, PixelType.UnsignedByte, rgb);

                // convert to color int
                int id = (rgb[0] << 24) | (rgb[1] << 16) | rgb[2];

                // look up in map
                NodeModel node;
                SelectionMap.TryGetValue(id, out node);

                if (SelectionMode == SelectionModes.Single)
                {
                    Model.ClickNode(node);
                }
                else
                {
                    Model.SetRoot(node);
                }
            });

            // clear buffer
            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

            // turn off selection mode
            SelectionMode = SelectionModes.None;
        }
Ejemplo n.º 3
0
        public void Draw(BeginMode mode)
        {
            // To draw a VBO:
            // 1) Ensure that the VertexArray client state is enabled.
            // 2) Bind the vertex and element buffer handles.
            // 3) Set up the data pointers (vertex, normal, color) according to your vertex format.
            // 4) Call DrawElements. (Note: the last parameter is an offset into the element buffer
            //    and will usually be IntPtr.Zero).

            GLUtils.SafeGLEnableClientStates(DrawStates, () =>
            {
                GL.BindBuffer(BufferTarget.ArrayBuffer, VboID);

                GL.VertexPointer(3, VertexPointerType.Float, BlittableValueType.StrideOf(Vertices), new IntPtr(0));
                GL.ColorPointer(4, ColorPointerType.UnsignedByte, BlittableValueType.StrideOf(Vertices), new IntPtr(12));
                GL.NormalPointer(NormalPointerType.Float, BlittableValueType.StrideOf(Vertices), new IntPtr(16));

                GL.DrawArrays(mode, 0, VertexCount);
            });
        }
Ejemplo n.º 4
0
        public void DrawNode(Color color, RectangleF area, bool outside, NodeModel node, int depth)
        {
            float x      = area.X + 0.1f;
            float y      = area.Y + 0.1f;
            float width  = area.Width - 0.2f;
            float length = area.Height - 0.2f;
            float bottom = depth * LevelSize + 0.1f;
            float height = GetNodeHeight(node) - 0.2f;

            if (SelectionMode != SelectionModes.None)
            {
                SelectionMap[node.ID] = node;
                color = Color.FromArgb((255 << 24) | node.ID);
            }

            if (outside)
            {
                DrawPyramid(color, x, y, width, length, bottom, height);
            }
            else
            {
                GLUtils.DrawCube(Nodes, color, x, y, width, length, bottom, height);
            }
        }
Ejemplo n.º 5
0
        void GLRenderer_Paint(object sender, PaintEventArgs e)
        {
            if (!GLLoaded)
            {
                return;
            }

            GL.Clear(ClearBufferMask.ColorBufferBit);

            if (!Model.Paused)
            {
                // reset vertex buffers
                Nodes.Reset();
                FontMap.Values.ForEach(f => f.ResetVBOs());
                Outlines.Values.ForEach(v => v.Reset());
                CallLines.Values.ForEach(v => v.Reset());
                DashedCallLines.Values.ForEach(v => v.Reset());
                Overlays.Reset();

                // render
                Model.Render();

                // send vertex buffers to gpu
                Nodes.Load();
                FontMap.Values.ForEach(f => f.LoadVBOs());
                Outlines.Values.Where(v => v.VertexCount > 0).ForEach(v => v.Load());
                CallLines.Values.Where(v => v.VertexCount > 0).ForEach(v => v.Load());
                DashedCallLines.Values.Where(v => v.VertexCount > 0).ForEach(v => v.Load());
                Overlays.Load();
            }

            // draw vertex buffers
            Nodes.Draw(BeginMode.Triangles);
            DrawLineVbo(Outlines);

            GLUtils.SafeEnable(LineCaps, () =>
            {
                GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);

                DrawLineVbo(CallLines);

                GLUtils.SafeEnable(EnableCap.LineStipple, () =>
                {
                    //1111 1000 0000 0000
                    ushort pattern = (ushort)(0xF800 >> (XRay.DashOffset * 5));
                    GL.LineStipple(1, pattern);

                    DrawLineVbo(DashedCallLines);
                });
            });

            GLUtils.SafeEnable(EnableCap.Blend, () =>
            {
                GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);
                Overlays.Draw(BeginMode.Triangles);
                FontMap.Values.ForEach(f => f.DrawVBOs());
            });

            SwapBuffers();

            Model.FpsCount++;
        }
Ejemplo n.º 6
0
        private void DrawNode(NodeModel node, RectangleF area, RectangleF labelArea, int depth, bool drawChildren, bool showHit)
        {
            if (!node.Show)
            {
                return;
            }

            var xNode = node.XNode;

            // set background of node base color
            Color background = XColors.EmptyColor;

            // if selcted
            if (node.Hovered && ViewLayout == LayoutType.TreeMap)
            {
                if (depth > XColors.OverColors.Length - 1)
                {
                    depth = XColors.OverColors.Length - 1;
                }

                background = XColors.OverColors[depth];
            }
            else if (ViewLayout != LayoutType.TreeMap && !CenterMap.Contains(node.ID))
            {
                background = XColors.OutsideColor;
            }

            // if no overlay, draw the border color as the entire node cause its very small
            bool noBorder = area.Width < 3.0f || area.Height < 3.0f;

            if (noBorder)
            {
                background = XColors.ObjColors[(int)node.ObjType];
            }


            Color overlay = XColors.EmptyColor;

            if (showHit)
            {
                // check if function is an entry point or holding
                if (XRay.FlowTracking && xNode.StillInside > 0)
                {
                    GLUtils.BlendColors((xNode.EntryPoint > 0) ? XColors.EntryColor : XColors.HoldingColor, ref overlay);
                }

                // not an else if, draw over holding or entry
                if (xNode.ExceptionHit > 0)
                {
                    GLUtils.BlendColors(XColors.ExceptionColors[xNode.ExceptionHit], ref overlay);
                }

                else if (xNode.FunctionHit > 0)
                {
                    if (node.ObjType == XObjType.Field)
                    {
                        if (xNode.LastFieldOp == FieldOp.Set)
                        {
                            GLUtils.BlendColors(XColors.FieldSetColors[xNode.FunctionHit], ref overlay);
                        }
                        else
                        {
                            GLUtils.BlendColors(XColors.FieldGetColors[xNode.FunctionHit], ref overlay);
                        }
                    }
                    else
                    {
                        GLUtils.BlendColors(XColors.HitColors[xNode.FunctionHit], ref overlay);
                    }
                }

                else if (xNode.ConstructedHit > 0)
                {
                    GLUtils.BlendColors(XColors.ConstructedColors[xNode.ConstructedHit], ref overlay);
                }

                else if (xNode.DisposeHit > 0)
                {
                    GLUtils.BlendColors(XColors.DisposedColors[xNode.DisposeHit], ref overlay);
                }
            }

            if (FocusedNodes.Count > 0 && node.ObjType == XObjType.Class)
            {
                bool dependent   = DependentClasses.Contains(node.ID);
                bool independent = IndependentClasses.Contains(node.ID);

                if (dependent && independent)
                {
                    GLUtils.BlendColors(XColors.InterdependentColor, ref overlay);
                }

                else if (dependent)
                {
                    GLUtils.BlendColors(XColors.DependentColor, ref overlay);
                }

                else if (independent)
                {
                    GLUtils.BlendColors(XColors.IndependentColor, ref overlay);
                }
            }

            if (node.SearchMatch && !SearchStrobe)
            {
                GLUtils.BlendColors(XColors.SearchMatchColor, ref overlay);
            }

            if (FilteredNodes.Contains(node.ID))
            {
                GLUtils.BlendColors(XColors.FilteredColor, ref overlay);
            }
            else if (IgnoredNodes.Contains(node.ID))
            {
                GLUtils.BlendColors(XColors.IgnoredColor, ref overlay);
            }

            // mix background with overlay
            if (overlay != XColors.EmptyColor)
            {
                GLUtils.BlendColors(overlay, ref background);
            }

            // use a circle for external/outside nodes in the call map
            bool outside = (ViewLayout == LayoutType.CallGraph && node.XNode.External);


            // if just a point, drawing a border messes up pixels
            if (noBorder && !DrawSubpixel)
            {
                Renderer.DrawNode(background, area, outside, node, depth);
            }
            else
            {
                Color pen = XColors.ObjColors[(int)node.ObjType];

                if (FilteredNodes.Contains(node.ID))
                {
                    pen = XColors.FilteredColor;
                }
                else if (IgnoredNodes.Contains(node.ID))
                {
                    pen = XColors.IgnoredColor;
                }

                int penWidth = 1;
                if (FocusedNodes.Contains(node))
                {
                    penWidth = 2;
                }

                Renderer.DrawNode(background, area, outside, node, depth);
                Renderer.DrawNodeOutline(pen, penWidth, area, outside, node, depth);
            }

            // draw label
            //buffer.FillRectangle(SearchMatchBrush, node.DebugRect);
            if (ShowLabels && node.RoomForLabel)
            {
                Renderer.DrawTextBackground(XColors.LabelBgColor, labelArea.X, labelArea.Y, labelArea.Width, labelArea.Height);
                Renderer.DrawNodeLabel(node.Name, TextFont, XColors.ObjColors[(int)node.ObjType], labelArea, node, depth);

                // draw code inside node
                if (ShowCode && node.AreaF.Width > 50 && node.AreaF.Height > 50)
                {
                    if (node.ObjType == XObjType.Method)
                    {
                        string code = node.XNode.GetMethodCode();

                        Renderer.DrawString(code, TextFont, XColors.CodeColor, node.AreaF.X + 5, node.AreaF.Y + labelArea.Height + 5, node.AreaF.Width - 10, node.AreaF.Height - 10 - labelArea.Height);
                    }
                    // draw field values inside node
                    else if (node.ObjType == XObjType.Field)
                    {
                        var summary = "";
                        foreach (var value in node.GetFieldValues())
                        {
                            summary += value + "\r\n";
                        }

                        Renderer.DrawString(summary, TextFont, XColors.CodeColor, node.AreaF.X + 5, node.AreaF.Y + labelArea.Height + 5, node.AreaF.Width - 10, node.AreaF.Height - 10 - labelArea.Height);
                    }
                }
            }
            if (MapMode == TreeMapMode.Dependencies && node.ObjType == XObjType.Class)
            {
                drawChildren = false;
            }

            if (drawChildren && ((area.Width > 1 && area.Height > 1) || DrawSubpixel))
            {
                foreach (var sub in node.Nodes)
                {
                    DrawNode(sub, depth + 1, drawChildren);
                }
            }


            // after drawing children, draw instance tracking on top of it all

            /*if (XRay.InstanceTracking && node.ObjType == XObjType.Class)
             * {
             * if (XRay.InstanceCount[node.ID] > 0)
             *  {
             *      string count = XRay.InstanceCount[node.ID].ToString();
             *      Rectangle x = new Rectangle(node.Area.Location, buffer.MeasureString(count, InstanceFont).ToSize());
             *
             *      if (node.Area.Contains(x))
             *      {
             *          buffer.FillRectangle(NothingBrush, x);
             *          buffer.DrawString(count, InstanceFont, InstanceBrush, node.Area.Location.X + 2, node.Area.Location.Y + 2);
             *      }
             *  }
             * }*/
        }
Ejemplo n.º 7
0
        void GLRenderer_Paint(object sender, PaintEventArgs e)
        {
            if (!GLLoaded)
            {
                return;
            }

            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

            GL.MatrixMode(MatrixMode.Modelview);
            GL.LoadIdentity();

            // Move the camera to our location in space
            FpsCam.SetupCamera();

            if (!Model.Paused)
            {
                if (SelectionMode != SelectionModes.None)
                {
                    DoSelectionPass();
                }

                // reset vertex buffers
                Nodes.Reset();
                FontMap.Values.ForEach(f => f.ResetVBOs());
                Outlines.Values.ForEach(v => v.Reset());
                CallLines.Values.ForEach(v => v.Reset());
                DashedCallLines.Values.ForEach(v => v.Reset());

                // render
                Model.Render();

                // send vertex buffers to gpu
                Nodes.Load();
                FontMap.Values.ForEach(f => f.LoadVBOs());
                Outlines.Values.Where(v => v.VertexCount > 0).ForEach(v => v.Load());
                CallLines.Values.Where(v => v.VertexCount > 0).ForEach(v => v.Load());
                DashedCallLines.Values.Where(v => v.VertexCount > 0).ForEach(v => v.Load());
            }

            // draw vertex buffers
            Nodes.Draw(BeginMode.Triangles);

            GLUtils.SafeEnable(LineCaps, () =>
            {
                GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);

                DrawLineVbo(Outlines);
                DrawLineVbo(CallLines);

                GLUtils.SafeEnable(EnableCap.LineStipple, () =>
                {
                    //1111 1000 0000 0000
                    ushort pattern = (ushort)(0xF800 >> (XRay.DashOffset * 5));
                    GL.LineStipple(1, pattern);

                    DrawLineVbo(DashedCallLines);
                });
            });

            GLUtils.SafeSaveMatrix(() =>
            {
                GL.Rotate(90, 1.0f, 0.0f, 0.0f);
                FontMap.Values.ForEach(f => f.DrawVBOs());
            });

            if (MouseLook)
            {
                FpsCam.DrawHud(Width, Height, MidWindow, Color.Black);
            }

            SwapBuffers();

            Model.FpsCount++;
        }