예제 #1
0
    public void Draw(Graphics g)
    {
        using (Pen p = new Pen(Color.White)) {
            p.Width = (RadiusOut - RadiusIn);
            int r = (RadiusOut + RadiusIn) / 2;
            g.DrawEllipse(p, X - r, Y - r, 2 * r, 2 * r);
        }
        using (Pen p = new Pen(Color.Black)) {
            p.Width = 1.0F;
            g.DrawEllipse(p, X - RadiusIn, Y - RadiusIn, 2 * RadiusIn, 2 * RadiusIn);
            g.DrawEllipse(p, X - RadiusOut, Y - RadiusOut, 2 * RadiusOut, 2 * RadiusOut);
        }

        // Draw the slice borders
        using (Pen p = new Pen(Color.Black)) {
            p.Width = 1.0F;
            Matrix m      = new Matrix();
            float  ang    = (float)360 / (float)Slices.Count;
            float  angSum = 0;

            float angMouse = (float)AngMouse() *
                             (180 / (float)Math.PI); // Radians to degrees

            // Make the mouse angle go from 0..360 as the slice angles.
            if (angMouse < 0)
            {
                angMouse += 360;
            }

            foreach (var s in Slices)
            {
                bool sel = (angSum <= angMouse) && (angMouse <= (angSum + ang));

                m.Reset();
                m.RotateAt(angSum, new Point(X, Y), MatrixOrder.Append);
                g.Transform = m;

                g.DrawLine(p, X + RadiusIn, Y, X + RadiusOut, Y);

                // Rotate a little bit more to show the text
                m.RotateAt(ang / 2, new Point(X, Y), MatrixOrder.Append);
                g.Transform = m;

                // FIXME: Render the text in upright position
                RenderText(g, s.Name, X + RadiusIn + 5, Y - 6, sel);

                g.ResetTransform();
                angSum += ang;

                if (sel)
                {
                    SelectedSlice = s;
                }
            }
            m.Dispose();
            m = null;
        }
    }
예제 #2
0
    public void AddSlice(MenuSlice type, string text)
    {
        ContextMenuSlice s = new ContextMenuSlice(type, text);

        Slices.Add(s);
    }