Esempio n. 1
0
        public void Select(PointF point)
        {
            VertexSettings lastSelected = this.Selected;

            this.Selected = this.vertices.Where(vertex => vertex.GetBounds().Contains(point)).LastOrDefault();
            if (this.Selected != lastSelected)
            {
                Redraw();
            }
        }
Esempio n. 2
0
        public ILGraphViewer(ILGraph graph)
        {
            InitializeComponent();

            this.Graph = graph;

            // Defaults
            this.BackColor = Color.White;

            // Create the vertex settings
            Dictionary <Instruction, VertexSettings>         vertices = new Dictionary <Instruction, VertexSettings>();
            Dictionary <Instruction, HashSet <Instruction> > targets  = graph.Targets;
            float x = this.Padding;
            float y = this.Padding;

            foreach (Instruction instruction in graph.Code)
            {
                if (!vertices.ContainsKey(instruction))
                {
                    vertices[instruction] = new VertexSettings(instruction, x, y)
                    {
                        Targets = targets[instruction].Select(i => {
                            if (!vertices.ContainsKey(i))
                            {
                                vertices[i] = new VertexSettings(i, 0, 0);
                            }
                            return(vertices[i]);
                        })
                    };
                }

                vertices[instruction].Center = new PointF(x, y);
                x += this.Spacing;
            }
            this.vertices = new SortedSet <VertexSettings>(vertices.Values, new VertexComparer());

            this.Size = GetPreferredSize(this.Size);

            this.Image = new Bitmap(this.Width, this.Height);

            this.Paint     += (sender, e) => Redraw();
            this.MouseMove += (sender, e) => {
                VertexSettings prevHovered = this.Hovered;
                this.Hovered = this.vertices.Where(vertex => vertex.GetBounds().Contains(this.ClientMousePosition)).LastOrDefault();
                if (prevHovered != this.Hovered)
                {
                    Redraw();
                }
            };
            this.Click += (sender, e) => Select(this.ClientMousePosition);
        }