Ejemplo n.º 1
0
        private void RebuildRegion()
        {
            // Wipe out the previous background image
            if (_bitmap != null)
            {
                _bitmap.Dispose();
            }
            _bitmap = null;

            #region Validate Width/Height

            // See if the height and width are unstable
            if (this.Width <= 0 || this.Height <= 0)
            {
                return;
            }

            #endregion

            // Calculate the pie wedge
            _regionPath = new GraphicsPath();

            // Calculate the angle
            double angle = Math.Asin(Convert.ToDouble(Width - Height) / Convert.ToDouble(Width));
            angle = Utility3D.GetRadiansToDegrees(angle);
            angle = 90d - angle;

            // Calculate the base length
            double baseLength = Math.Sqrt((Width * Width) - ((Width - Height) * (Width - Height)));

            // Draw the path
            _regionPath.AddArc(this.Width * -1, 0, this.Width * 2, this.Width * 2, 270, Convert.ToSingle(angle));
            _regionPath.AddLine(Convert.ToSingle(baseLength), Height, 0, Height);
            _regionPath.CloseFigure();          //outline.AddLine(0, Height, 0, 0);

            // Draw my background image
            _bitmap = new Bitmap(this.Width, this.Height);

            //TODO:  Make a gradient forground
            using (Graphics graphics = Graphics.FromImage(_bitmap))
            {
                graphics.SmoothingMode = SmoothingMode.HighQuality;

                graphics.Clear(this.BackColor);

                using (Pen pen = new Pen(SystemColors.ControlDark, 1f))
                {
                    graphics.DrawPath(pen, _regionPath);
                    //graphics.DrawLine(pen, 0, this.Height - 1, this.Width, this.Height - 1);		// the bottom line isn't drawing, so I'll back up a pixel
                }
            }

            // Make me the shape of the pie wedge
            this.Region = new Region(_regionPath);
            this.Refresh();
        }
Ejemplo n.º 2
0
        public void FillPie(Brush brush, MyVector centerPoint, double radius, MyVector centerLine, double sweepRadians)
        {
            // Turn the centerline and sweep radians into angles that GDI likes
            MyVector dummy = new MyVector(1, 0, 0);
            double   startDegrees;

            dummy.GetAngleAroundAxis(out dummy, out startDegrees, centerLine);
            startDegrees = Utility3D.GetRadiansToDegrees(startDegrees);

            if (centerLine.Y < 0)
            {
                startDegrees *= -1;
            }

            double sweepDegrees = Utility3D.GetRadiansToDegrees(sweepRadians);

            startDegrees -= sweepDegrees / 2d;

            // Call my overload
            FillPie(brush, centerPoint, radius, startDegrees, sweepDegrees);
        }