private static void PreventSaturationHandlesExceedingLimits(HueSelectorHandle handleToChange) { if (handleToChange.SaturationRange > 0) { if (handleToChange.SaturationRange + handleToChange.Saturation > 1) { handleToChange.SaturationRange = 1 - handleToChange.Saturation; } else if (handleToChange.Saturation - handleToChange.SaturationRange < 0) { handleToChange.SaturationRange = handleToChange.Saturation; } } else { if (handleToChange.Saturation - handleToChange.SaturationRange > 1) { handleToChange.SaturationRange = -1 + handleToChange.Saturation; } else if (handleToChange.Saturation + handleToChange.SaturationRange < 0) { handleToChange.SaturationRange = handleToChange.Saturation; } } }
private void DrawHandle(PaintEventArgs e, HueSelectorHandle handle, bool label, SolidBrush handleBrush, Rectangle handleRect, bool fill = false) { e.Graphics.FillEllipse(handleBrush, handleRect); e.Graphics.DrawEllipse(Pens.LightGray, handleRect); if (label) { using (var font1 = new Font("Segoe UI", ClientRectangle.Width / 30, System.Drawing.FontStyle.Bold, GraphicsUnit.Point)) { var stringFormat = new StringFormat { Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center }; var centrePoint = new PointF((handleRect.Left + handleRect.Right) / 2, (handleRect.Top + handleRect.Bottom) / 2); if (_labels == null || _labels.Count <= handle.HandleNumber) { return; } e.Graphics.DrawString(_labels[handle.HandleNumber], labelFont, Brushes.Black, new PointF((handleRect.Left + handleRect.Right) / 2 + 1, (handleRect.Top + handleRect.Bottom) / 2 + 1), stringFormat); e.Graphics.DrawString(_labels[handle.HandleNumber], labelFont, Brushes.Black, new PointF((handleRect.Left + handleRect.Right) / 2 - 1, (handleRect.Top + handleRect.Bottom) / 2 - 1), stringFormat); e.Graphics.DrawString(_labels[handle.HandleNumber], labelFont, Brushes.Black, new PointF((handleRect.Left + handleRect.Right) / 2 + 1, (handleRect.Top + handleRect.Bottom) / 2 - 1), stringFormat); e.Graphics.DrawString(_labels[handle.HandleNumber], labelFont, Brushes.Black, new PointF((handleRect.Left + handleRect.Right) / 2 - 1, (handleRect.Top + handleRect.Bottom) / 2 + 1), stringFormat); e.Graphics.DrawString(_labels[handle.HandleNumber], labelFont, Brushes.White, new PointF((handleRect.Left + handleRect.Right) / 2, (handleRect.Top + handleRect.Bottom) / 2), stringFormat); //e.Graphics.DrawString(_labels[handle.HandleNumber], labelFont, Brushes.White, centrePoint, stringFormat); //var stringSize = e.Graphics.MeasureString(_labels[handle.HandleNumber], labelFont); //e.Graphics.DrawString(_labels[handle.HandleNumber], labelFont, Brushes.Black, new PointF((handleRect.Left + handleRect.Right) / 2 - stringSize.Width/2, handleRect.Top)); // //GraphicsPath p = new GraphicsPath(); //p.AddString( // _labels[handle.HandleNumber], // text to draw // FontFamily.GenericSansSerif, // or any other font family // (int)System.Drawing.FontStyle.Bold, // font style (bold, italic, etc.) // (float)(e.Graphics.DpiY * 10.1 / 72), // em size // new System.Drawing.Point((int)((handleRect.Left + handleRect.Right) / 2 - stringSize.Width / 2), handleRect.Top), // location where to draw text // new StringFormat()); // set options here (e.g. center alignment) //e.Graphics.DrawPath(Pens.Black, p); // //e.Graphics.DrawString(_labels[handle.HandleNumber], labelFont, Brushes.Black, new PointF((handleRect.Left + handleRect.Right) / 2 - stringSize.Width / 2 + 1, handleRect.Top + 1)); //e.Graphics.DrawString(_labels[handle.HandleNumber], labelFont, Brushes.Black, new PointF((handleRect.Left + handleRect.Right) / 2 - stringSize.Width / 2 - 1, handleRect.Top - 1)); //e.Graphics.DrawString(_labels[handle.HandleNumber], labelFont, Brushes.Black, new PointF((handleRect.Left + handleRect.Right) / 2 - stringSize.Width / 2 + 1, handleRect.Top - 1)); //e.Graphics.DrawString(_labels[handle.HandleNumber], labelFont, Brushes.Black, new PointF((handleRect.Left + handleRect.Right) / 2 - stringSize.Width / 2 - 1, handleRect.Top + 1)); //e.Graphics.DrawString(_labels[handle.HandleNumber], labelFont, Brushes.White, new PointF((handleRect.Left + handleRect.Right) / 2 - stringSize.Width / 2, handleRect.Top )); } } }
private void DrawHandles(PaintEventArgs e, HueSelectorHandle handle, bool shadow) { var handleBrush = new SolidBrush(Color.FromArgb(128, 32, 32, 32)); DrawHandle(e, handle, false, handleBrush, handle.GetHandleRangeRectangle(ClientRectangle, HalfHandleSizeX / 2, HalfHandleSizeY / 2, true, PerBulb ? handle.HandleNumber : 1, shadow)); DrawHandle(e, handle, false, handleBrush, handle.GetHandleRangeRectangle(ClientRectangle, HalfHandleSizeX / 2, HalfHandleSizeY / 2, false, PerBulb ? handle.HandleNumber : 1, shadow)); handleBrush = new SolidBrush(Color.FromArgb(128, 32, 32, 32)); DrawHandle(e, handle, true, handleBrush, handle.GetHandleRectangle(ClientRectangle, HalfHandleSizeX, HalfHandleSizeY, PerBulb ? handle.HandleNumber : 1, shadow)); }
private void DrawHandle(PaintEventArgs e, HueSelectorHandle handle, bool label, SolidBrush handleBrush, Rectangle handleRect) { e.Graphics.FillEllipse(handleBrush, handleRect); if (label) { using (var font1 = new Font("Segoe UI", ClientRectangle.Width / 30, System.Drawing.FontStyle.Bold, GraphicsUnit.Point)) { var stringFormat = new StringFormat { Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center }; e.Graphics.DrawString(handle.HandleNumber.ToString(), font1, Brushes.White, handleRect, stringFormat); } } }