コード例 #1
0
ファイル: SplitStrategy.cs プロジェクト: dxc31202/ZXStudio
        /**
         * calculate the positions for all the elements of the root.
         *
         * @param root the root to calculate
         */
        public void calculatePositions(TreeMapNode root)
        {
            if (root == null)
            {
                return;
            }

            ArrayList v = root.Nodes;

            if (v != null)
            {
                calculatePositionsRec(root.getX(), root.getY(), root.getWidth(), root.getHeight(), this.sumWeight(v), v);
            }
        }
コード例 #2
0
        private void paint(TreeMapNode n, Graphics g, int level)
        {
            if (n.IsLeaf)
            {
                RectangleF rect = new RectangleF((float)n.getX(), (float)n.getY(), (float)n.getWidth(), (float)n.getHeight());
                if (rect.Width > 0 && rect.Height > 0)
                {
                    gp.Reset();
                    gp.AddEllipse(rect.Left - rect.Width / 4, rect.Top - rect.Height / 4, rect.Width + 2 * rect.Width / 4,
                                  rect.Height + 2 * rect.Height / 4);
                    PathGradientBrush pgb = new PathGradientBrush(gp);
                    pgb.CenterColor = Color.White;
                    string ext = Path.GetExtension(n.getLabel()).TrimStart('.');
                    if (extensions.ContainsKey(ext.ToLower()))
                    {
                        pgb.SurroundColors = new Color[] { (Color)extensions[ext.ToLower()] };
                    }
                    else
                    {
                        Color c = Color.FromKnownColor((KnownColor)((int)KnownColor.ForestGreen + extensions.Count));
                        extensions[ext.ToLower()] = c;
                        pgb.SurroundColors        = new Color[] { c };
                    }
                    pgb.CenterPoint = new PointF(rect.Left + rect.Width / 4, rect.Top + rect.Height / 2);

                    g.FillRectangle(pgb, rect);
                    pgb.Dispose();

                    string label     = Path.GetFileName(n.getLabel());
                    SizeF  labelSize = g.MeasureString(label, f, (int)rect.Width);

                    if (rect.Width > 1 && rect.Height > 1 && File.Exists(n.getLabel()))
                    {
                        if (n.Icon == null)
                        {
                            n.Icon = Icon.ExtractAssociatedIcon(n.getLabel());
                        }
                        if (rect.Width >= n.Icon.Width && rect.Height >= n.Icon.Height + labelSize.Height)
                        {
                            Rectangle iconRect = new Rectangle((int)rect.Left + (int)rect.Width / 2 - n.Icon.Width / 2,
                                                               (int)rect.Top + (int)rect.Height / 2 - n.Icon.Height / 2 - (int)labelSize.Height / 2, n.Icon.Width, n.Icon.Height);
                            if (clipBoard == n && cutClipboard)
                            {
                                ImageAttributes ia = new ImageAttributes();
                                ia.SetGamma(0.3F);
                                g.DrawImage(n.Icon.ToBitmap(), iconRect, 0, 0, n.Icon.Width, n.Icon.Height, GraphicsUnit.Pixel, ia);
                            }
                            else
                            {
                                g.DrawIconUnstretched(n.Icon, iconRect);
                            }
                            Region clip = g.Clip;
                            g.Clip = new Region(rect);
                            g.DrawString(label, f, Brushes.Black, new RectangleF(rect.Left + rect.Width / 2 - labelSize.Width / 2,
                                                                                 rect.Top + rect.Height / 2 - labelSize.Height / 2 + iconRect.Height / 2, labelSize.Width, labelSize.Height));
                            g.Clip = clip;
                        }
                        else
                        {
                            double ratio = Math.Min(rect.Width / n.Icon.Width, rect.Height / n.Icon.Height);
                            if (clipBoard == n && cutClipboard)
                            {
                                ImageAttributes ia = new ImageAttributes();
                                ia.SetGamma(0.3F);
                                g.DrawImage(n.Icon.ToBitmap(), new Rectangle((int)Math.Round(rect.Left + rect.Width / 2 - n.Icon.Width * ratio / 2),
                                                                             (int)Math.Round(rect.Top + rect.Height / 2 - n.Icon.Height * ratio / 2),
                                                                             (int)Math.Round(n.Icon.Width * ratio), (int)Math.Round(n.Icon.Height * ratio)), 0, 0, n.Icon.Width, n.Icon.Height,
                                            GraphicsUnit.Pixel, ia);
                            }
                            else
                            {
                                g.DrawIcon(n.Icon, new Rectangle((int)Math.Round(rect.Left + rect.Width / 2 - n.Icon.Width * ratio / 2),
                                                                 (int)Math.Round(rect.Top + rect.Height / 2 - n.Icon.Height * ratio / 2),
                                                                 (int)Math.Round(n.Icon.Width * ratio), (int)Math.Round(n.Icon.Height * ratio)));
                            }
                        }
                    }
                }
            }
            else if (level > 1)
            {
                RectangleF rect = new RectangleF((float)n.getX(), (float)n.getY(), (float)n.getWidth(), (float)n.getHeight());
                if (rect.Width > 0 && rect.Height > 0)
                {
                    gp.Reset();
                    gp.AddEllipse(rect.Left - rect.Width / 4, rect.Top - rect.Height / 4, rect.Width + 2 * rect.Width / 4,
                                  rect.Height + 2 * rect.Height / 4);
                    PathGradientBrush pgb = new PathGradientBrush(gp);
                    pgb.CenterColor    = Color.White;
                    pgb.SurroundColors = new Color[] { Color.YellowGreen };
                    pgb.CenterPoint    = new PointF(rect.Left + rect.Width / 4, rect.Top + rect.Height / 2);

                    g.FillRectangle(pgb, rect);
                    pgb.Dispose();

                    string label     = Path.GetFileName(n.getLabel());
                    SizeF  labelSize = g.MeasureString(label, f);
                    Region clip      = g.Clip;
                    g.Clip = new Region(rect);
                    g.DrawString(label, f, Brushes.Black, new RectangleF(rect.Left + rect.Width / 2 - labelSize.Width / 2,
                                                                         rect.Top + rect.Height / 2 - labelSize.Height / 2, labelSize.Width, labelSize.Height));
                    g.Clip = clip;
                }
            }
            if (depthLevel == 0 || level < depthLevel)
            {
                foreach (TreeMapNode child in n.Nodes)
                {
                    paint(child, g, level + 1);
                }
            }
        }
コード例 #3
0
        protected override void OnPaint(PaintEventArgs e)
        {
            if (repaint)
            {
                if (buffer == null)
                {
                    buffer         = new Bitmap(ClientSize.Width, ClientSize.Height, e.Graphics);
                    bufferGraphics = Graphics.FromImage(buffer);
                }
                paint(root, bufferGraphics, 0);
                repaint = false;
            }

            e.Graphics.DrawImageUnscaled(buffer, 0, 0);
            if (highLighted != null)
            {
                if (highLightedIsDir)
                {
                    e.Graphics.DrawRectangle(yellow2, highLighted.Bounds);
                }
                else if (highLighted.Parent != null)
                {
                    e.Graphics.DrawRectangle(yellow2, highLighted.Parent.Bounds);
                }
                if (!highLightedIsDir)
                {
                    e.Graphics.DrawRectangle(Pens.Red, (int)Math.Round(highLighted.getX()), (int)Math.Round(highLighted.getY()),
                                             (int)Math.Round(highLighted.getWidth() - 1D), (int)Math.Round(highLighted.getHeight() - 1D));
                }
            }
        }