/// <summary>
        /// Create a mini gauge image with the given data.
        /// </summary>
        /// <param name="count">The side counts that determine the needle angle.</param>
        /// <param name="doubleScale">If true the needle angle will be exaggerated x 2.</param>
        /// <returns>An image containing the gauge needle (doesn't include the gauge background).</returns>
        private Bitmap DrawGauge(SideCount count, bool doubleScale)
        {
            const int radius = 25;
            const int left   = 5;
            const int top    = 5;


            // calculate needle angle

            float angle;

            if (count.Allied != 0 || count.Axis != 0)
            {
                angle = ((float)count.Axis / (count.Allied + count.Axis)) * 180;
            }
            else
            {
                angle = 90;
            }

            if (doubleScale)
            {
                angle += (angle - 90); // exaggerate angle x2
            }
            if (angle < 10)
            {
                angle = 10;
            }
            if (angle > 170)
            {
                angle = 170;
            }


            // get points to draw

            PointF needleCenter = new PointF(left + radius - 0.5F, top + radius - 1);
            PointF needleStart  = Misc.AngleOffset(needleCenter, angle - 90, radius * 0.4);
            PointF needleEnd    = Misc.AngleOffset(needleCenter, angle - 270, radius * 1.1);


            // init graphics resources

            Pen penNeedle = new Pen(Color.FromArgb(192, 192, 192), 2F);

            Bitmap   img = new Bitmap(60, 40);
            Graphics g   = Graphics.FromImage(img);

            g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;


            // draw gauge

            g.DrawLine(penNeedle, needleStart, needleEnd);

            g.Dispose();
            return(img);
        }
Esempio n. 2
0
        // play last momentum after mouse release
        private void tmrMomentum_Tick(object sender, EventArgs e)
        {
            PointF prevCenter = this.Center;

            this.Center = Misc.AngleOffset(this.Center, momuntumAngle, momentumSpeed);

            if (this.Center == prevCenter) // at edge (corner), can't move any further
            {
                tmrMomentum.Stop();
            }

            momentumSpeed -= 1;

            if (momentumSpeed < 1)
            {
                tmrMomentum.Stop();
            }
        }