Beispiel #1
0
        private static void _drawHealthBar(Graphics gfx, float x, float y, double amount)
        {
            int hpBarWidth  = 50;
            int hpBarHeight = 9;
            int hpBarRadius = 4;

            Rectangle bounds = new Rectangle((int)x - hpBarWidth / 2, (int)y, hpBarWidth, hpBarHeight);

            System.Drawing.Color color = System.Drawing.Color.Green;

            if (amount >= 0.5)
            {
                color = GraphicsUtils.Blend(System.Drawing.Color.Orange, System.Drawing.Color.Green, (1.0 - amount) / 0.5);
            }
            else
            {
                color = GraphicsUtils.Blend(System.Drawing.Color.Red, System.Drawing.Color.Orange, (0.5 - amount) / 0.5);
            }

            using (Brush brush = new SolidBrush(System.Drawing.Color.White))
                GraphicsUtils.FillRoundedRectangle(gfx, brush, bounds, hpBarRadius);

            gfx.SetClip(GraphicsUtils.RoundedRect(bounds, hpBarRadius), CombineMode.Replace);

            using (Brush brush = new SolidBrush(color))
                gfx.FillRectangle(brush, new Rectangle((int)x - hpBarWidth / 2, (int)y, (int)(hpBarWidth * amount), hpBarHeight));

            gfx.ResetClip();

            using (Brush brush = new SolidBrush(System.Drawing.Color.Black))
                using (Pen pen = new Pen(brush))
                    GraphicsUtils.DrawRoundedRectangle(gfx, pen, new Rectangle((int)(x - hpBarWidth / 2), (int)y, hpBarWidth, hpBarHeight), hpBarRadius);
        }