public static ColorF ColorLerp(ColorF from, Color to, float speed) { if (from == to) return from; var r = FloatLerp(from.R, to.R, speed); var g = FloatLerp(from.G, to.G, speed); var b = FloatLerp(from.B, to.B, speed); var a = FloatLerp(from.A, to.A, speed); return ColorF.FromArgb(a, r, g, b); }
private void SelectColorClick(object sender, EventArgs e) { colorDialog1.Color = System.Drawing.Color.Black; if (colorDialog1.ShowDialog() != DialogResult.Cancel) { color1 = new ColorF( colorDialog1.Color.R / 255F, colorDialog1.Color.G / 255F, colorDialog1.Color.B / 255F, colorDialog1.Color.A / 255F); colorLabel.Text = string.Format("R = {0}, G = {1}, B = {2}, A = {3}", color1.Red, color1.Green, color1.Blue, color1.Alpha); } }
public Button() { BackColor = Color.FromArgb(234, 234, 234); BackgroundImageLayout = ImageLayout.Center; BorderColor = Color.FromArgb(172, 172, 172); BorderDisableColor = Color.FromArgb(217, 217, 217); BorderHoverColor = Color.FromArgb(126, 180, 234); BorderSelectColor = Color.FromArgb(51, 153, 255); CanSelect = true; DisableColor = Color.FromArgb(239, 239, 239); Font = new Drawing.Font("Arial", 12); ForeColor = Color.FromArgb(64, 64, 64); ImageColor = Color.White; HoverColor = Color.FromArgb(223, 238, 252); TextAlign = ContentAlignment.MiddleCenter; Size = new Drawing.Size(75, 23); currentBackColor = BackColor; }
private void gradiantBrushColor2Button_Click(object sender, EventArgs e) { colorDialog1.Color = System.Drawing.Color.Black; if (colorDialog1.ShowDialog() != DialogResult.Cancel) { color2 = new ColorF( colorDialog1.Color.R / 255F, colorDialog1.Color.G / 255F, colorDialog1.Color.B / 255F, colorDialog1.Color.A / 255F); gradBrushColor2Label.Text = string.Format("R = {0}, G = {1}, B = {2}, A = {3}", color2.Red, color2.Green, color2.Blue, color2.Alpha); } }
protected override void OnPaint(PaintEventArgs e) { if (Hovered) scrollDestinationColor = ScrollHoverColor; else scrollDestinationColor = ScrollColor; scrollCurrentColor = MathHelper.ColorLerp(scrollCurrentColor, scrollDestinationColor, 4); if (scrollOrientation == ScrollOrientation.HorizontalScroll) { int backX = subtractButton.Location.X + subtractButton.Width; e.Graphics.FillRectangle(BackColor, backX, 0, addButton.Location.X - backX, Height); } else { int backY = subtractButton.Location.Y + subtractButton.Height; e.Graphics.FillRectangle(BackColor, 0, backY, Width, addButton.Location.Y - backY); } e.Graphics.FillRectangle(scrollCurrentColor, scrollRect.X, scrollRect.Y, scrollRect.Width, scrollRect.Height); }
protected override void OnPaint(PaintEventArgs e) { Graphics g = e.Graphics; // Back. if (Enabled) { if (Hovered == false) currentBackColor = MathHelper.ColorLerp(currentBackColor, BackColor, 5); else currentBackColor = MathHelper.ColorLerp(currentBackColor, HoverColor, 5); } else currentBackColor = MathHelper.ColorLerp(currentBackColor, DisableColor, 5); g.FillRectangle(new SolidBrush(currentBackColor), 0, 0, Width, Height); // Border. if (Enabled == false) g.DrawRectangle(new Pen(BorderDisableColor), 0, 0, Width, Height); else if (Hovered) g.DrawRectangle(new Pen(BorderHoverColor), 0, 0, Width, Height); else if (Focused) g.DrawRectangle(new Pen(BorderSelectColor), 0, 0, Width, Height); else g.DrawRectangle(new Pen(BorderColor), 0, 0, Width, Height); SolidBrush textBrush = new SolidBrush(ForeColor); if (!Enabled) textBrush.Color = ForeColor + Color.FromArgb(0, 128, 128, 128); if (Image != null && Image.uTexture != null) { var imageToPaint = Image; var imageColorToPaint = ImageColor; if (Hovered) { if (ImageHover != null) imageToPaint = ImageHover; if (ImageHoverColor != null) imageColorToPaint = ImageHoverColor.Value; } switch (BackgroundImageLayout) { default: case ImageLayout.None: g.DrawTexture(imageToPaint, 0, 0, Image.Width, Image.Height, imageColorToPaint); break; case ImageLayout.Center: g.DrawTexture(imageToPaint, Width / 2 - Image.Width / 2, Height / 2 - Image.Height / 2, Image.Width, Image.Height, imageColorToPaint); break; case ImageLayout.Stretch: g.DrawTexture(imageToPaint, 0, 0, Width, Height, imageColorToPaint); break; case ImageLayout.Zoom: // TODO: not working. break; } } g.DrawString(Text, Font, textBrush, Padding.Left, Padding.Top, Width - Padding.Left - Padding.Right, Height - Padding.Top - Padding.Bottom, TextAlign); }
protected override void OnBackColorChanged(EventArgs e) { base.OnBackColorChanged(e); backColorF = new ColorF( BackColor.R / 256f, BackColor.G / 256f, BackColor.B / 256f, 1.0f); backgroundBrush = new SolidBrush(BackColor); }
public D2DShapesControl(IContainer components) { components.Add(this); SetStyle(ControlStyles.UserPaint, true); SetStyle(ControlStyles.AllPaintingInWmPaint, true); UpdateStyles(); backColorF = new ColorF( BackColor.R / 256f, BackColor.G / 256f, BackColor.B / 256f, 1.0f); //Initialize the background render thread and synchronization objects renderSyncObject = new object(); killThread = new ManualResetEvent(false); ThreadStart ts = RenderThreadProcedure; renderThread = new Thread( ts ); renderThread.Start(); }
public override void SetPen(IPen pen) { strokeWidth = pen.Width; ColorF penColor = new ColorF(pen.Color.Red, pen.Color.Green, pen.Color.Blue,1); fStrokeBrush = Graphics.CreateSolidColorBrush(penColor); }
void IImageViewrCommon.ClearBackGround(Color color) { backgroundColor = new ColorF(color.ToArgb()); RenderScene(); }