public override ColorBgra Apply(ColorBgra color) { float colorAverage = color.GetAverageColorChannelValueF(); float scale = (colorAverage - BackAverage) / (ForeAverage - BackAverage); byte alpha = Utility.ClampToByte(scale * 255); return(color.NewAlpha(alpha)); }
protected override bool ProcessCmdKey(ref Message msg, Keys keyData) { bool handled = false; int gWidth = ClientRectangle.Width - 1 - 2 * nubSize; float pixeldelta = 1 / (float)gWidth; int alphadelta = 4; if ((keyData & Keys.Control) != Keys.None) { pixeldelta *= 10; alphadelta *= 4; } Keys keyCode = Keys.KeyCode & keyData; switch (keyCode) { case Keys.Left: if (selectedIndex >= 0 && selectedIndex < gradient.Count) { selectedIndex = gradient.SetPosition(selectedIndex, (gradient.GetPosition(selectedIndex) - pixeldelta).Clamp(0, 1)); handled = true; cmdkeydown = true; Invalidate(); } break; case Keys.Right: if (selectedIndex >= 0 && selectedIndex < gradient.Count) { selectedIndex = gradient.SetPosition(selectedIndex, (gradient.GetPosition(selectedIndex) + pixeldelta).Clamp(0, 1)); handled = true; cmdkeydown = true; Invalidate(); } break; case Keys.Apps: Point pt = GetNubLocation(selectedIndex); OnMouseClick(new MouseEventArgs(MouseButtons.Right, 0, pt.X, pt.Y, 0)); handled = true; break; case Keys.Tab: handled = ProcessTabKey((keyData & Keys.Modifiers) == Keys.None); break; case Keys.OemMinus: handled = ProcessTabKey(false); break; case Keys.Oemplus: handled = ProcessTabKey(true); break; case Keys.Up: if (selectedIndex >= 0 && selectedIndex < gradient.Count) { ColorBgra currentColor = gradient.GetColor(selectedIndex); gradient.SetColor(selectedIndex, currentColor.NewAlpha((currentColor.A + alphadelta).ClampToByte())); cmdkeydown = true; handled = true; Invalidate(); } break; case Keys.Down: if (selectedIndex >= 0 && selectedIndex < gradient.Count) { ColorBgra currentColor = gradient.GetColor(selectedIndex); gradient.SetColor(selectedIndex, currentColor.NewAlpha((currentColor.A - alphadelta).ClampToByte())); handled = true; cmdkeydown = true; Invalidate(); } break; case Keys.Enter: if (selectedIndex >= 0 && selectedIndex < gradient.Count) { pt = GetNubLocation(selectedIndex); OnMouseDoubleClick(new MouseEventArgs(MouseButtons.Left, 0, pt.X, pt.Y, 0)); handled = true; } break; } if ((int)keyData <= 57 && (int)keyData >= 48) { ProcessNumberKeys(keyData); handled = true; } return(handled || base.ProcessCmdKey(ref msg, keyData)); }
public override ColorBgra Apply(ColorBgra color) { ColorBgra newColor = Color; return(newColor.NewAlpha(color.A)); }