private void DrawBattery(Graphics g, Rectangle rect) { g.ResetClip(); g.ResetTransform(); g.SetClip(rect); Point center = new Point(0, 0); int batteryTopHeight = rect.Height / 20; int batteryHeight = rect.Height - batteryTopHeight - 1; int batteryWidth = batteryHeight / 3; int batteryTopWidth = batteryWidth / 3; bool warning = BatteryLevel <= BatteryWarningLevel; // draw fill/level double batteryLevel = MathHelper.Clamp(BatteryLevel, 0.0, 1.0); int fill = (int)(batteryHeight * Math.Max(0.05, batteryLevel)); g.FillRect(warning ? _brushWarning : _brush, center, 0.0, new Rectangle(0, batteryHeight - fill + batteryTopHeight, batteryWidth, fill)); // draw outline g.DrawRect(_pen, center, 0.0, new Rectangle((batteryWidth - batteryTopWidth) / 2, 0, batteryTopWidth, batteryTopHeight)); g.DrawRect(_pen, center, 0.0, new Rectangle(0, batteryTopHeight, batteryWidth, batteryHeight)); // draw value StringFormat stringFormat = new StringFormat { Alignment = StringAlignment.Near, LineAlignment = StringAlignment.Far }; g.DrawString((BatteryLevel * 100.0).ToString("000"), _font, warning ? _brushWarning : _brush, center, 0.0, new Point(batteryWidth + 5, rect.Height), stringFormat); }
private void DrawBlade(Graphics g, Rectangle rect, double level) { g.ResetClip(); g.ResetTransform(); g.SetClip(rect); Point center = new Point(rect.Width / 2, rect.Height / 2); int barWidth = rect.Width / 5; int barHeight = (int)(rect.Width * 0.7); int radius = rect.Width / 2; double barOffset = Math.Cos(Math.Asin((barHeight / 2.0) / radius)) * radius; if (double.IsNaN(barOffset)) { barOffset = 0; } // circle g.DrawEllipse(_pen, center, 0.0, new Rectangle(0, 0, rect.Width - 1, rect.Height - 1)); // bar int fill = barHeight - (int)(barHeight * level); g.FillRect(_brush, center, 0.0, new Rectangle((int)(center.X - barOffset), (rect.Height - barHeight) / 2 + fill, barWidth, barHeight - fill)); g.DrawRect(_pen, center, 0.0, new Rectangle((int)(center.X - barOffset), (rect.Height - barHeight) / 2, barWidth, barHeight)); // text StringFormat stringFormat = new StringFormat { LineAlignment = StringAlignment.Center }; g.DrawString((level * 100).ToString("00"), _font, _brush, center, 0.0, new Point((int)(center.X - barOffset + barWidth + 5), center.Y), stringFormat); }
private void DrawBackground(Graphics g) { g.ResetClip(); g.ResetTransform(); g.SetClip(_rect); Point center = new Point(_rect.Width / 2, _rect.Height / 2); double roll = Roll; double scale = 12; double pitch = MathHelper.Rad2Deg(Pitch) * scale; int y = (int)(center.Y + pitch); g.FillRect(_skyBrush, center, roll, new Rectangle(0, 0, _rect.Width, y)); g.FillRect(_groundBrush, center, roll, new Rectangle(0, y, _rect.Width, _rect.Height - y)); }