protected Color GetButtonColor(LcarsColorFunction colorFunction) { Color color; switch (AlertState) { case LcarsAlert.Red: color = Color.Red; break; case LcarsAlert.Yellow: color = Color.Yellow; break; case LcarsAlert.White: color = Color.White; break; case LcarsAlert.Custom: color = CustomAlertColor; break; default: color = ColorManager.GetColor(colorFunction); break; } // turn color white when pressed, unless already white, then turn it red if (isPressed) { color = ColorsAreClose(Color.White, color) ? Color.Red : Color.White; } return(color); }
public Color GetFunctionNativeColor(LcarsColorFunction colorFunction) { if (!Enum.IsDefined(typeof(LcarsColorFunction), colorFunction)) { throw new Exception("Invalid LcarsColorStyle specified"); } return(ColorTranslator.FromHtml(colorSet[colorFunction])); }
protected override void OnPaint(PaintEventArgs e) { Graphics g = e.Graphics; Color barColor; Color buttonColor; switch (alertState) { case LcarsAlert.Normal: barColor = ColorManager.GetColor(mainColor); break; case LcarsAlert.Red: barColor = Color.Red; break; case LcarsAlert.White: barColor = Color.White; break; case LcarsAlert.Yellow: barColor = Color.Yellow; break; case LcarsAlert.Custom: barColor = customAlertColor; break; default: barColor = Color.Red; break; } if (!isLit) { barColor = Color.FromArgb(255, barColor.R / 2, barColor.G / 2, barColor.B / 2); } Rectangle btnRect = ButtonBounds; if (alertState == LcarsAlert.Normal) { if (mouseDown & btnRect.Contains(PointToClient(MousePosition))) { buttonColor = Color.Red; } else { buttonColor = ColorManager.GetColor(this.buttonColor); } } else { buttonColor = barColor; } //Setup brushes SolidBrush barBrush = new SolidBrush(barColor); SolidBrush buttonBrush = new SolidBrush(buttonColor); g.SmoothingMode = SmoothingMode.AntiAlias; g.PixelOffsetMode = PixelOffsetMode.HighQuality; //Draw top/bottom ellipse sections if required if (e.ClipRectangle.Height != Height - Width / 2) { g.FillPie(barBrush, 0, 0, Width, Width / 2, 180, 180); g.FillPie(barBrush, 0, Height - Width / 2, Width, Width / 2, 0, 180); } //Draw main rectangles int railStart = Width / 4; g.FillRectangle(barBrush, 0, railStart, Width, btnRect.Top - railStart - padding); g.FillRectangle(barBrush, 0, btnRect.Bottom + padding, Width, Height - (btnRect.Bottom + padding) - Width / 4); //Draw button g.FillRectangle(buttonBrush, btnRect); //scale font down to fit float fontSize = 16; Font f; SizeF textSize; do { f = FontProvider.Lcars(fontSize); textSize = CreateGraphics().MeasureString(val.ToString(), f); fontSize -= .5f; }while (textSize.Width > btnRect.Width); var placement = new Rectangle( (int)(btnRect.X + (btnRect.Width - textSize.Width) / 2), (int)(btnRect.Y + (btnRect.Height - textSize.Height) / 2), (int)Math.Ceiling(textSize.Width), (int)Math.Ceiling(textSize.Height)); g.DrawString(val.ToString(), f, Brushes.Black, placement); }
public System.Drawing.Color GetColor(LcarsColorFunction colorFunction) { return(currentColorSet.GetFunctionNativeColor(colorFunction)); }
public void SetFunctionColor(LcarsColorFunction colorFunction, string color) { // warning: directly calling an LcarsColorManager.CurrentColorSet.SetFunctionColor(.....) will not trigger redraw colorSet[colorFunction] = color; }