public LcarsLabel() { UseCompatibleTextRendering = true; BackColor = Color.Black; Font = FontProvider.Lcars(textHeight); ColorManager = new LcarsColorManager(); }
/// <summary> /// Creates a new instance of the LcarsButtonBase object /// </summary> /// <remarks></remarks> public LcarsButtonBase() : base() { // for designer, InitEvents (esp resize) before InitializeComponent() InitEvents(); textSize = Size; font = FontProvider.Lcars(textHeight); InitializeComponent(); base.DoubleBuffered = true; }
public LcarsInputBox(string prompt, string title, string defaultResponse, int posX, int posY) { BackColor = Color.Black; ForeColor = Color.Orange; Size = new Size(400, 200); FormBorderStyle = FormBorderStyle.None; if (posX == -1) { posX = Screen.AllScreens[0].Bounds.Width / 2 - 200; } if (posY == -1) { posY = Screen.AllScreens[0].Bounds.Height / 2 - 100; } StartPosition = FormStartPosition.Manual; Location = new Point(posX, posY); TextButton titleBar = new TextButton(); titleBar.Width = 390; titleBar.Height = 30; titleBar.Location = new Point(5, 5); titleBar.Text = title; titleBar.Clickable = true; Controls.Add(titleBar); TextButton bottomBar = new TextButton(); bottomBar.Width = 390; bottomBar.Top = 195 - bottomBar.Height; bottomBar.Left = 5; bottomBar.Text = ""; bottomBar.Clickable = false; Controls.Add(bottomBar); RichTextBox txtPrompt = new RichTextBox(); txtPrompt.Width = 390; txtPrompt.Height = 65; txtPrompt.Top = titleBar.Bottom + 7; txtPrompt.Left = 5; txtPrompt.Text = prompt; txtPrompt.BackColor = Color.Black; txtPrompt.ForeColor = Color.Orange; txtPrompt.BorderStyle = BorderStyle.None; txtPrompt.Font = FontProvider.Lcars(14); txtPrompt.ReadOnly = true; txtPrompt.WordWrap = true; Controls.Add(txtPrompt); inputBox.Left = 10; inputBox.Width = 380; inputBox.Top = txtPrompt.Bottom + 7; inputBox.BackColor = Color.Black; inputBox.ForeColor = Color.Orange; inputBox.Font = FontProvider.Lcars(14); inputBox.Text = defaultResponse; inputBox.TabIndex = 0; inputBox.Focus(); Controls.Add(inputBox); StandardButton okButton = new StandardButton(); okButton.Height = bottomBar.Height; okButton.Top = bottomBar.Top - 7 - okButton.Height; okButton.Width = 70; okButton.Left = 325; okButton.ColorFunction = LcarsColorFunction.PrimaryFunction; okButton.Text = "OK"; okButton.ButtonTextAlign = ContentAlignment.MiddleCenter; Controls.Add(okButton); okButton.Click += Ok_Click; StandardButton cancelButton = new StandardButton(); cancelButton.Height = bottomBar.Height; cancelButton.Top = bottomBar.Top - 7 - cancelButton.Height; cancelButton.Width = 70; cancelButton.Left = 248; cancelButton.ColorFunction = LcarsColorFunction.CriticalFunction; cancelButton.Text = "Cancel"; cancelButton.ButtonTextAlign = ContentAlignment.MiddleCenter; Controls.Add(cancelButton); cancelButton.Click += Cancel_Click; KeyPreview = true; KeyDown += Me_KeyDown; titleBar.MouseDown += Title_MouseDown; titleBar.MouseMove += Title_MouseMove; inputBox.Select(); }
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 override Bitmap DrawButton() { Bitmap mybitmap = null; Graphics g = null; SizeF buttonTextSize = default(SizeF); SizeF sideTextSize = default(SizeF); int curLeft = 0; Font textFont = FontProvider.Lcars((Height / 2) + 4, GraphicsUnit.Pixel); Font sideFont = FontProvider.Lcars((float)(Height / 2.9) + Height, GraphicsUnit.Pixel); SolidBrush myBrush = new SolidBrush(GetButtonColor()); SolidBrush sideBrush = new SolidBrush(GetButtonColor(sideBlockColor)); SolidBrush sideTextBrush = new SolidBrush(GetButtonColor(sideTextColor)); if (sideText == null) { sideText = "47"; } //initialize the graphics mybitmap = new Bitmap(Width, Height); g = Graphics.FromImage(mybitmap); g.FillRectangle(Brushes.Black, 0, 0, mybitmap.Width, mybitmap.Height); g.SmoothingMode = SmoothingMode.AntiAlias; g.PixelOffsetMode = PixelOffsetMode.HighQuality; //get the width and height of the fonts buttonTextSize = g.MeasureString(Text.ToUpper(), textFont); sideTextSize = g.MeasureString(sideText.ToUpper(), sideFont); //draw the left orange block. If the mouse is down, draw it white. g.FillRectangle(sideBrush, 0, 0, Height / 2, Height); //set the curleft to the right side of what we have already drawn. curLeft = Height / 2; if (sideTextWidth > -1) { curLeft += sideTextWidth - (int)sideTextSize.Width; } else { curLeft -= Height / 5; } //draw the side text g.DrawString(sideText.ToUpper(), sideFont, sideTextBrush, curLeft, (-1) * (float)Height / (float)4.7); if (!string.IsNullOrEmpty(sideText)) { curLeft = (curLeft + (int)sideTextSize.Width) - (Height / 6); } else { curLeft = curLeft + (Height / 10); } //draw the main button area g.FillRectangle(myBrush, curLeft, 0, (Width - curLeft) - (Height + (Height / 10)), Height); TextLocation = new Point(curLeft, 0); TextSize = new Size((Width - curLeft) - (Height / 2), Height); curLeft += (Width - curLeft) - (Height + (Height / 10)); curLeft -= Height / 10; //draw the straight section of the right side pill shape g.FillRectangle(myBrush, curLeft, 0, Height / 2, Height); //draw the curved end g.FillEllipse(myBrush, curLeft, 0, Height, Height); return(mybitmap); }
public LcarsMessageBox(object prompt, string title, MessageBoxButtons buttons, MessageBoxIcon icon) { buttonStyle = buttons; bool cancelVisible = false; bool abortVisible = false; bool retryVisible = false; bool ignoreVisible = false; bool yesVisible = false; bool noVisible = false; int okx = 183; int cx = 50; switch (buttons) { case MessageBoxButtons.OKCancel: cancelVisible = true; break; case MessageBoxButtons.AbortRetryIgnore: abortVisible = true; retryVisible = true; ignoreVisible = true; // cancelEnabled = true; cx = 210; okx = 115; break; case MessageBoxButtons.RetryCancel: retryVisible = true; cancelVisible = true; break; case MessageBoxButtons.YesNo: yesVisible = true; noVisible = true; okx = 210; cx = 115; break; case MessageBoxButtons.YesNoCancel: cancelVisible = true; yesVisible = true; noVisible = true; okx = 210; cx = 115; break; } LcarsColorFunction colorFunction; switch (icon) { case MessageBoxIcon.Error: //vbCritical colorFunction = LcarsColorFunction.FunctionOffline; // pass redAlert() to LCARSmain if exists. break; case MessageBoxIcon.Question: //vbQuestion colorFunction = LcarsColorFunction.StaticBlue; break; case MessageBoxIcon.Exclamation: //vbExclamation colorFunction = LcarsColorFunction.StaticTan; break; case MessageBoxIcon.Information: //vbInformation colorFunction = LcarsColorFunction.LCARSDisplayOnly; break; default: colorFunction = LcarsColorFunction.StaticTan; break; } FormBorderStyle = FormBorderStyle.None; Size = new Size(305, 200); BackColor = Color.Black; StartPosition = FormStartPosition.CenterScreen; TopMost = true; Elbow elbow1 = new Elbow(); Controls.Add(elbow1); elbow1.Location = new Point(0, 0); elbow1.Size = new Size(80, 60); elbow1.HorizantalBarHeight = 30; elbow1.VerticalBarWidth = 10; elbow1.ElbowStyle = LcarsElbowStyle.UpperLeft; elbow1.ColorFunction = colorFunction; elbow1.Text = ""; Elbow elbow2 = new Elbow(); Controls.Add(elbow2); elbow2.Location = new Point(0, 140); elbow2.Size = new Size(80, 60); elbow2.HorizantalBarHeight = 15; elbow2.VerticalBarWidth = 10; elbow2.Clickable = false; elbow2.ElbowStyle = LcarsElbowStyle.LowerLeft; elbow2.ColorFunction = colorFunction; elbow2.Text = ""; TextButton titleBar = new TextButton(); Controls.Add(titleBar); titleBar.Location = new Point(50, 0); titleBar.Size = new Size(255, 30); titleBar.TextHeight = 31; titleBar.ColorFunction = colorFunction; titleBar.Text = title; FlatButton vertBar = new FlatButton(); Controls.Add(vertBar); vertBar.Location = new Point(0, 66); vertBar.Size = new Size(10, 68); vertBar.Clickable = false; vertBar.ColorFunction = colorFunction; vertBar.Text = ""; HalfPillButton bottomBar = new HalfPillButton(); Controls.Add(bottomBar); bottomBar.Location = new Point(85, 185); bottomBar.Size = new Size(217, 15); bottomBar.Clickable = false; bottomBar.ColorFunction = colorFunction; bottomBar.Text = ""; //draw text RichTextBox errorTextBox = new RichTextBox(); Controls.Add(errorTextBox); errorTextBox.Location = new Point(30, 36); errorTextBox.Size = new Size(243, 107); errorTextBox.BackColor = Color.Black; errorTextBox.BorderStyle = BorderStyle.None; errorTextBox.WordWrap = true; errorTextBox.Font = FontProvider.Lcars(14); errorTextBox.ForeColor = Color.Orange; errorTextBox.BringToFront(); errorTextBox.Text = prompt.ToString(); errorTextBox.ReadOnly = true; // BUTTONS //draw OK/Yes/retry button StandardButton yesOkRetryButton = new StandardButton(); Controls.Add(yesOkRetryButton); yesOkRetryButton.Location = new Point(okx, 149); yesOkRetryButton.Size = new Size(90, 30); yesOkRetryButton.ColorFunction = LcarsColorFunction.PrimaryFunction; yesOkRetryButton.Name = "yesOkRetryButton"; if (yesVisible) { yesOkRetryButton.Text = "YES"; yesOkRetryButton.Click += OnYesClick; } else if (retryVisible) { yesOkRetryButton.Text = "RETRY"; yesOkRetryButton.Click += OnRetryClick; } else { yesOkRetryButton.Text = "OK"; yesOkRetryButton.Click += OnOkClick; } yesOkRetryButton.ButtonTextAlign = ContentAlignment.MiddleCenter; yesOkRetryButton.BringToFront(); if (cancelVisible || ignoreVisible) { StandardButton cancelIgnoreButton = new StandardButton(); Controls.Add(cancelIgnoreButton); cancelIgnoreButton.Location = new Point(cx, 149); cancelIgnoreButton.Size = new Size(90, 30); cancelIgnoreButton.Name = "cancelIgnoreButton"; cancelIgnoreButton.ColorFunction = LcarsColorFunction.CriticalFunction; if (ignoreVisible) { cancelIgnoreButton.Text = "IGNORE"; cancelIgnoreButton.Click += OnIgnoreClick; } else if (cancelVisible) { cancelIgnoreButton.Text = "CANCEL"; cancelIgnoreButton.Click += OnCancelClick; } cancelIgnoreButton.ButtonTextAlign = ContentAlignment.MiddleCenter; cancelIgnoreButton.BringToFront(); } if (abortVisible || noVisible) { //draw abort/no button StandardButton noAbortButton = new StandardButton(); Controls.Add(noAbortButton); noAbortButton.Location = new Point(20, 149); noAbortButton.Size = new Size(90, 30); noAbortButton.ColorFunction = LcarsColorFunction.CriticalFunction; if (abortVisible) { noAbortButton.Text = "ABORT"; noAbortButton.Click += OnAbortClick; } else if (noVisible) { noAbortButton.Text = "NO"; noAbortButton.Click += OnNoClick; } noAbortButton.ButtonTextAlign = ContentAlignment.MiddleCenter; noAbortButton.BringToFront(); } KeyPreview = true; KeyDown += Me_KeyDown; elbow1.MouseDown += Title_MouseDown; elbow1.MouseMove += Title_MouseMove; titleBar.MouseDown += Title_MouseDown; titleBar.MouseMove += Title_MouseMove; }
/// <summary> /// Redraws the lightweight complex button /// </summary> public override void Redraw() { if (holdDraw) { return; } if (bounds.Height <= 0) { return; } if (bounds.Width <= 0) { return; } Font sideFont = FontProvider.Lcars(Height + (Height / 2.9f), GraphicsUnit.Pixel); //Set up brushes SolidBrush myBrush = new SolidBrush(ColorManager.GetColor(ColorFunction)); SolidBrush sideBrush; SolidBrush sideTextBrush; myBrush = GetBrush(); if (alertState == LcarsAlert.Normal && !isPressed) { sideBrush = new SolidBrush(ColorManager.GetColor(sideBlockColor)); sideTextBrush = new SolidBrush(ColorManager.GetColor(sideTextColor)); } else { sideBrush = myBrush; sideTextBrush = myBrush; } //Set up graphics and image myBitmap = new Bitmap(bounds.Width, bounds.Height); Graphics g = Graphics.FromImage(myBitmap); g.SmoothingMode = SmoothingMode.AntiAlias; g.PixelOffsetMode = PixelOffsetMode.HighQuality; g.Clear(Color.Black); //Left orange block g.FillRectangle(sideBrush, 0, 0, Height / 2, Height); int curLeft = Height / 2; SizeF sideTextSize = g.MeasureString(sideText.ToUpper(), sideFont); if (sideTextWidth > -1) { curLeft += sideTextWidth - (int)sideTextSize.Width; } else { curLeft -= Height / 5; } //draw the side text g.DrawString(sideText.ToUpper(), sideFont, sideTextBrush, curLeft, -Height / 4.7f); if (!string.IsNullOrEmpty(sideText)) { curLeft = (int)((curLeft + sideTextSize.Width) - (Height / 6f)); } else { curLeft = Height / 2; } //Draw text and remainder of button Rectangle textRect = new Rectangle(curLeft, 0, (Width - curLeft) - Height / 2, Height); g.FillRectangle(myBrush, textRect); g.FillEllipse(myBrush, Width - Height, 0, Height, Height); DrawText(textRect, g); ChangeLit(g); g.Dispose(); DoEvent(LightweightEvents.Update); }