/// <summary> /// Creates a new instance of the window. /// </summary> public ColorPickerPopup() : base(60, 35) { Border.AddToWindow(this); Title = "Select color"; CloseOnEscKey = true; CanDrag = false; UsePixelPositioning = true; Center(); otherColorPopup = new OtherColorsPopup(); otherColorPopup.Closed += (sender2, e2) => { if (otherColorPopup.DialogResult) { _barR.SelectedColor = otherColorPopup.SelectedColor.RedOnly(); _barG.SelectedColor = otherColorPopup.SelectedColor.GreenOnly(); _barB.SelectedColor = otherColorPopup.SelectedColor.BlueOnly(); _alphaInput.Text = otherColorPopup.SelectedColor.A.ToString(); } }; _picker = new Controls.ColorPicker(Width - RideSideX - 1, Height - 11, Color.YellowGreen) { Position = new Point(1, 1) }; _picker.SelectedColorChanged += _picker_SelectedColorChanged; Controls.Add(_picker); #region TextBoxes _redInput = new TextBox(5); _redInput.IsNumeric = true; _redInput.MaxLength = 3; _redInput.Position = new Point(Width - 7, Height - 14); _redInput.TextChanged += (sender, e) => { _barR.SelectedColor = new Color(int.Parse(_redInput.Text), 0, 0); }; Controls.Add(_redInput); _greenInput = new TextBox(5); _greenInput.IsNumeric = true; _greenInput.MaxLength = 3; _greenInput.Position = new Point(Width - 7, Height - 13); _greenInput.TextChanged += (sender, e) => { _barG.SelectedColor = new Color(0, int.Parse(_greenInput.Text), 0); }; Controls.Add(_greenInput); _blueInput = new TextBox(5); _blueInput.IsNumeric = true; _blueInput.MaxLength = 3; _blueInput.Position = new Point(Width - 7, Height - 12); _blueInput.TextChanged += (sender, e) => { _barB.SelectedColor = new Color(0, 0, int.Parse(_blueInput.Text)); }; Controls.Add(_blueInput); _alphaInput = new TextBox(5); _alphaInput.IsNumeric = true; _alphaInput.MaxLength = 3; _alphaInput.Position = new Point(Width - 7, Height - 11); _alphaInput.Text = "255"; Controls.Add(_alphaInput); #endregion #region Bars _barH = new HueBar(Width - 2); _barH.Position = new Point(1, Height - 9); _barH.ColorChanged += _barH_ColorChanged; Controls.Add(_barH); _barR = new ColorBar(Width - 2); _barR.StartingColor = Color.Black; _barR.EndingColor = Color.Red; _barR.Position = new Point(1, Height - 7); _barR.ColorChanged += bar_ColorChanged; Controls.Add(_barR); _barG = new ColorBar(Width - 2); _barG.StartingColor = Color.Black; _barG.EndingColor = new Color(0, 255, 0); _barG.Position = new Point(1, Height - 5); _barG.ColorChanged += bar_ColorChanged; Controls.Add(_barG); _barB = new ColorBar(Width - 2); _barB.StartingColor = Color.Black; _barB.EndingColor = Color.Blue; _barB.Position = new Point(1, Height - 3); _barB.ColorChanged += bar_ColorChanged; Controls.Add(_barB); _selectedColor = _picker.SelectedColor; _barH.SelectedColor = _selectedColor; #endregion #region Buttons _okButton = new Button(RideSideX - 4); _okButton.Text = "OK"; _okButton.Position = new Point(Width - RideSideX + 2, Height - 18); _okButton.Click += (sender, r) => { this.DialogResult = true; _selectedColor = _selectedColor.SetAlpha(byte.Parse(_alphaInput.Text)); AddPreviousColor(SelectedColor); Hide(); }; Controls.Add(_okButton); _cancelButton = new Button(RideSideX - 4); _cancelButton.Text = "Cancel"; _cancelButton.Position = new Point(Width - RideSideX + 2, Height - 17); _cancelButton.Click += (sender, r) => { this.DialogResult = false; Hide(); }; Controls.Add(_cancelButton); _otherColorsButton = new Button(RideSideX - 4); _otherColorsButton.Text = "Other Colors"; _otherColorsButton.Position = new Point(Width - RideSideX + 2, Height - 20); _otherColorsButton.Click += (sender, e) => { otherColorPopup.Show(true); }; Controls.Add(_otherColorsButton); #endregion _previousColors = new ListBox(RideSideX - 4, Height - 20 - 9 + 1, new SadConsole.UI.Themes.ListBoxItemColorTheme()); _previousColors.Position = new Point(Width - RideSideX + 2, 8); _previousColors.SelectedItemChanged += (sender, e) => { if (_previousColors.SelectedItem != null) { SelectedColor = (Color)_previousColors.SelectedItem; } }; Controls.Add(_previousColors); var colors = Controls.GetThemeColors(); this.Print(Width - RideSideX + 2, _redInput.Position.Y, "Red", colors.Red); this.Print(Width - RideSideX + 2, _greenInput.Position.Y, "Green", colors.Green); this.Print(Width - RideSideX + 2, _blueInput.Position.Y, "Blue", colors.Blue); this.Print(Width - RideSideX + 2, _alphaInput.Position.Y, "Alpha", colors.Gray); // Preview area this.Print(Width - RideSideX + 2, 1, "Selected Color"); this.Fill(new Rectangle(Width - RideSideX + 2, 2, 14, 3), colors.ControlHostForeground, colors.ControlHostBackground, 219); // Current selected gradient colors this.Print(Width - RideSideX + 2, 5, SelectedColor.R.ToString().PadLeft(3, '0'), colors.Red); this.Print(Width - RideSideX + 2, 6, SelectedColor.G.ToString().PadLeft(3, '0'), colors.Green); this.Print(Width - RideSideX + 13, 5, SelectedColor.B.ToString().PadLeft(3, '0'), colors.Blue); // Previous Colors this.Print(Width - RideSideX + 2, _previousColors.Position.Y - 1, "Prior Colors"); }
/// <summary> /// Creates a new instance of this window with size 40, 20. /// </summary> public OtherColorsPopup() : base(40, 20) { Border.AddToWindow(this); Title = "Pick known color"; Center(); CloseOnEscKey = true; CanDrag = false; _ansiSelectButton = new RadioButton(Width - 4, 1); _ansiSelectButton.Position = new Point(2, 2); _ansiSelectButton.Text = "Ansi Colors"; _ansiSelectButton.CanFocus = false; _ansiSelectButton.IsSelectedChanged += _ansiSelectButton_IsSelectedChanged; Controls.Add(_ansiSelectButton); _knownSelectButton = new RadioButton(Width - 4, 1); _knownSelectButton.Position = new Point(2, 3); _knownSelectButton.Text = "List of Known Colors"; _knownSelectButton.CanFocus = false; _knownSelectButton.IsSelectedChanged += _ansiSelectButton_IsSelectedChanged; Controls.Add(_knownSelectButton); #region Ansi Buttons int ansiButtonStartY = 5; int ansiButtonStartX = 3; int ansiButtonStartBrightX = 20; _ansiButtons[0] = new Button(15, 1); _ansiButtons[0].Position = new Point(ansiButtonStartX, ansiButtonStartY); _ansiButtons[0].Text = "Red Dark"; _ansiButtons[0].Theme = new AnsiButtonTheme(Color.AnsiRed, Color.AnsiRedBright); _ansiButtons[0].Click += AnsiColorButton_Click; Controls.Add(_ansiButtons[0]); _ansiButtons[1] = new Button(15, 1); _ansiButtons[1].Position = new Point(ansiButtonStartBrightX, ansiButtonStartY); _ansiButtons[1].Text = "Red Bright"; _ansiButtons[1].Theme = new AnsiButtonTheme(Color.AnsiRedBright, Color.AnsiRed); _ansiButtons[1].Click += AnsiColorButton_Click; Controls.Add(_ansiButtons[1]); _ansiButtons[2] = new Button(15, 1); _ansiButtons[2].Position = new Point(ansiButtonStartX, ansiButtonStartY + 1); _ansiButtons[2].Text = "Yellow Dark"; _ansiButtons[2].Theme = new AnsiButtonTheme(Color.AnsiYellow, Color.AnsiYellowBright); _ansiButtons[2].Click += AnsiColorButton_Click; Controls.Add(_ansiButtons[2]); _ansiButtons[3] = new Button(15, 1); _ansiButtons[3].Position = new Point(ansiButtonStartBrightX, ansiButtonStartY + 1); _ansiButtons[3].Text = "Yellow Bright"; _ansiButtons[3].Theme = new AnsiButtonTheme(Color.AnsiYellowBright, Color.AnsiYellow); _ansiButtons[3].Click += AnsiColorButton_Click; Controls.Add(_ansiButtons[3]); _ansiButtons[4] = new Button(15, 1); _ansiButtons[4].Position = new Point(ansiButtonStartX, ansiButtonStartY + 2); _ansiButtons[4].Text = "Green Dark"; _ansiButtons[4].Theme = new AnsiButtonTheme(Color.AnsiGreen, Color.AnsiGreenBright); _ansiButtons[4].Click += AnsiColorButton_Click; Controls.Add(_ansiButtons[4]); _ansiButtons[5] = new Button(15, 1); _ansiButtons[5].Position = new Point(ansiButtonStartBrightX, ansiButtonStartY + 2); _ansiButtons[5].Text = "Green Bright"; _ansiButtons[5].Theme = new AnsiButtonTheme(Color.AnsiGreenBright, Color.AnsiGreen); _ansiButtons[5].Click += AnsiColorButton_Click; Controls.Add(_ansiButtons[5]); _ansiButtons[6] = new Button(15, 1); _ansiButtons[6].Position = new Point(ansiButtonStartX, ansiButtonStartY + 3); _ansiButtons[6].Text = "Cyan Dark"; _ansiButtons[6].Theme = new AnsiButtonTheme(Color.AnsiCyan, Color.AnsiCyanBright); _ansiButtons[6].Click += AnsiColorButton_Click; Controls.Add(_ansiButtons[6]); _ansiButtons[7] = new Button(15, 1); _ansiButtons[7].Position = new Point(ansiButtonStartBrightX, ansiButtonStartY + 3); _ansiButtons[7].Text = "Cyan Bright"; _ansiButtons[7].Theme = new AnsiButtonTheme(Color.AnsiCyanBright, Color.AnsiCyan); _ansiButtons[7].Click += AnsiColorButton_Click; Controls.Add(_ansiButtons[7]); _ansiButtons[8] = new Button(15, 1); _ansiButtons[8].Position = new Point(ansiButtonStartX, ansiButtonStartY + 4); _ansiButtons[8].Text = "Blue Dark"; _ansiButtons[8].Theme = new AnsiButtonTheme(Color.AnsiBlue, Color.AnsiBlueBright); _ansiButtons[8].Click += AnsiColorButton_Click; Controls.Add(_ansiButtons[8]); _ansiButtons[9] = new Button(15, 1); _ansiButtons[9].Position = new Point(ansiButtonStartBrightX, ansiButtonStartY + 4); _ansiButtons[9].Text = "Blue Bright"; _ansiButtons[9].Theme = new AnsiButtonTheme(Color.AnsiBlueBright, Color.AnsiBlue); _ansiButtons[9].Click += AnsiColorButton_Click; Controls.Add(_ansiButtons[9]); _ansiButtons[10] = new Button(15, 1); _ansiButtons[10].Position = new Point(ansiButtonStartX, ansiButtonStartY + 5); _ansiButtons[10].Text = "Magenta Dark"; _ansiButtons[10].Theme = new AnsiButtonTheme(Color.AnsiMagenta, Color.AnsiMagentaBright); _ansiButtons[10].Click += AnsiColorButton_Click; Controls.Add(_ansiButtons[10]); _ansiButtons[11] = new Button(15, 1); _ansiButtons[11].Position = new Point(ansiButtonStartBrightX, ansiButtonStartY + 5); _ansiButtons[11].Text = "Magenta Bright"; _ansiButtons[11].Theme = new AnsiButtonTheme(Color.AnsiMagentaBright, Color.AnsiMagenta); _ansiButtons[11].Click += AnsiColorButton_Click; Controls.Add(_ansiButtons[11]); _ansiButtons[12] = new Button(15, 1); _ansiButtons[12].Position = new Point(ansiButtonStartX, ansiButtonStartY + 6); _ansiButtons[12].Text = "Black Dark"; _ansiButtons[12].Theme = new AnsiButtonTheme(Color.AnsiBlack, Color.AnsiBlackBright); _ansiButtons[12].Click += AnsiColorButton_Click; Controls.Add(_ansiButtons[12]); _ansiButtons[13] = new Button(15, 1); _ansiButtons[13].Position = new Point(ansiButtonStartBrightX, ansiButtonStartY + 6); _ansiButtons[13].Text = "Black Bright"; _ansiButtons[13].Theme = new AnsiButtonTheme(Color.AnsiBlackBright, Color.AnsiBlack); _ansiButtons[13].Click += AnsiColorButton_Click; Controls.Add(_ansiButtons[13]); _ansiButtons[14] = new Button(15, 1); _ansiButtons[14].Position = new Point(ansiButtonStartX, ansiButtonStartY + 7); _ansiButtons[14].Text = "White Dark"; _ansiButtons[14].Theme = new AnsiButtonTheme(Color.AnsiWhite, Color.AnsiWhiteBright); _ansiButtons[14].Click += AnsiColorButton_Click; Controls.Add(_ansiButtons[14]); _ansiButtons[15] = new Button(15, 1); _ansiButtons[15].Position = new Point(ansiButtonStartBrightX, ansiButtonStartY + 7); _ansiButtons[15].Text = "White Bright"; _ansiButtons[15].Theme = new AnsiButtonTheme(Color.AnsiWhiteBright, Color.AnsiWhite); _ansiButtons[15].Click += AnsiColorButton_Click; Controls.Add(_ansiButtons[15]); #endregion #region Named Color Control _namedColorsList = new ListBox(Width - 4, Height - 3 - ansiButtonStartY, new SadConsole.UI.Themes.ListBoxItemColorTheme()); _namedColorsList.Position = new Point(ansiButtonStartX - 1, ansiButtonStartY); Controls.Add(_namedColorsList); // Fill out the named colors var colorType = typeof(Color); foreach (FieldInfo item in colorType.GetFields(BindingFlags.Public | BindingFlags.Static).Where((t) => t.FieldType.Name == colorType.Name)) { var color = (Color)item.GetValue(null); _namedColorsList.Items.Add((color, item.Name)); } _namedColorsList.SelectedItem = _namedColorsList.Items[0]; _namedColorsList.SelectedItemChanged += (s, e) => { var a = _namedColorsList.Theme; }; #endregion _cancelButton = new Button(12, 1); _cancelButton.Position = new Point(2, Height - 2); _cancelButton.Text = "Cancel"; _cancelButton.Click += (sender, e) => { DialogResult = false; Hide(); }; Controls.Add(_cancelButton); _okButton = new Button(12, 1); _okButton.Position = new Point(Width - 2 - _okButton.Width, Height - 2); _okButton.Text = "OK"; _okButton.Click += (sender, e) => { SelectedColor = _ansiSelectButton.IsSelected ? _selectedAnsiColor : (Color)(((Color, string))_namedColorsList.SelectedItem).Item1; DialogResult = true; Hide(); }; Controls.Add(_okButton); _ansiSelectButton.IsSelected = true; this.CloseOnEscKey = true; _ansiButtons[0].InvokeClick(); }