/// <summary> /// Controls the actual drawing for this gradient slider control. /// </summary> /// <param name="g">The graphics object used for drawing.</param> /// <param name="clipRectangle">The clip rectangle.</param> protected virtual void OnDraw(Graphics g, Rectangle clipRectangle) { GraphicsPath gp = new GraphicsPath(); Rectangle innerRect = new Rectangle(LeftHandle.Width, 3, Width - 1 - RightHandle.Width - LeftHandle.Width, Height - 1 - 6); gp.AddRoundedRectangle(innerRect, 2); if (Width == 0 || Height == 0) { return; } // Create a rounded gradient effect as the backdrop that other colors will be drawn to LinearGradientBrush silver = new LinearGradientBrush(ClientRectangle, BackColor.Lighter(.2F), BackColor.Darker(.6F), LinearGradientMode.Vertical); g.FillPath(silver, gp); silver.Dispose(); LinearGradientBrush lgb = new LinearGradientBrush(innerRect, MinimumColor, MaximumColor, LinearGradientMode.Horizontal); g.FillPath(lgb, gp); lgb.Dispose(); g.DrawPath(Pens.Gray, gp); gp.Dispose(); if (Enabled) { LeftHandle.Draw(g); RightHandle.Draw(g); } }
/// <summary> /// Test to see if the given point is inside of the current bounds /// </summary> /// <returns><c>true</c>, if in bounds, <c>false</c> otherwise.</returns> /// <param name="point">Point.</param> public virtual bool PointInBound(SKPoint point) { // Clear hit handle and test point HitHandle = null; var inBounds = (ValueBetween(point.X, Left, Right) && ValueBetween(point.Y, Top, Bottom)); // Test all handles to see if they have been hit if (TopLeftHandle != null && TopLeftHandle.PointInBound(point)) { HitHandle = TopLeftHandle; inBounds = true; } else if (TopHandle != null && TopHandle.PointInBound(point)) { HitHandle = TopHandle; inBounds = true; } else if (TopRightHandle != null && TopRightHandle.PointInBound(point)) { HitHandle = TopRightHandle; inBounds = true; } else if (RightHandle != null && RightHandle.PointInBound(point)) { HitHandle = RightHandle; inBounds = true; } else if (BottomRightHandle != null && BottomRightHandle.PointInBound(point)) { HitHandle = BottomRightHandle; inBounds = true; } else if (BottomHandle != null && BottomHandle.PointInBound(point)) { HitHandle = BottomHandle; inBounds = true; } else if (BottomLeftHandle != null && BottomLeftHandle.PointInBound(point)) { HitHandle = BottomLeftHandle; inBounds = true; } else if (LeftHandle != null && LeftHandle.PointInBound(point)) { HitHandle = LeftHandle; inBounds = true; } else if (inBounds) { // See if we are in bounds HitOffset = new SKPoint((Left > Right) ? point.X - Right : point.X - Left, (Top > Bottom) ? point.Y - Bottom : point.Y - Top); } return(inBounds); }
/// <summary> /// Draws the bounding box and its edit handles into the given canvas /// </summary> /// <param name="canvas">Canvas.</param> public virtual void Draw(SKCanvas canvas) { // Anything to process? if (State != KimonoShapeState.Selected && State != KimonoShapeState.Constructing && State != KimonoShapeState.Grouping) { return; } // Define the paint style var paint = new SKPaint() { Style = SKPaintStyle.Stroke, StrokeWidth = 1 }; // Set stroke based on the state switch (State) { case KimonoShapeState.Grouping: paint.Color = KimonoColor.Ice; break; case KimonoShapeState.Selected: paint.Color = KimonoColor.Tungsten; break; case KimonoShapeState.Constructing: paint.Color = KimonoColor.Aqua; break; } // Draw bounding frame canvas.DrawRect(Rect, paint); // Draw the four corner handles TopLeftHandle?.Draw(canvas); TopRightHandle?.Draw(canvas); BottomRightHandle?.Draw(canvas); BottomLeftHandle?.Draw(canvas); // Draw optional handles TopHandle?.Draw(canvas); RightHandle?.Draw(canvas); BottomHandle?.Draw(canvas); LeftHandle?.Draw(canvas); }
/// <summary> /// Controls the actual drawing for this gradient slider control. /// </summary> /// <param name="g">The graphics object used for drawing.</param> /// <param name="clipRectangle">The clip rectangle.</param> protected virtual void OnDraw(Graphics g, Rectangle clipRectangle) { using (GraphicsPath gp = new()) { Rectangle innerRect = new(LeftHandle.Width, 3, Width - 1 - RightHandle.Width - LeftHandle.Width, Height - 1 - 6); gp.AddRoundedRectangle(innerRect, 2); if (Width == 0 || Height == 0) { return; } // Create a rounded gradient effect as the backdrop that other colors will be drawn to LinearGradientBrush silver = new(ClientRectangle, BackColor.Lighter(.2F), BackColor.Darker(.6F), LinearGradientMode.Vertical); g.FillPath(silver, gp); silver.Dispose(); using (LinearGradientBrush lgb = new(innerRect, Color.White, Color.White, LinearGradientMode.Horizontal)) { Color[] colors = new Color[37]; float[] positions = new float[37]; for (int i = 0; i <= 36; i++) { int j = _inverted ? 36 - i : i; colors[j] = SymbologyGlobal.ColorFromHsl(((i * 10) + _hueShift) % 360, 1, .7).ToTransparent(.7f); positions[i] = i / 36f; } ColorBlend cb = new() { Colors = colors, Positions = positions }; lgb.InterpolationColors = cb; g.FillPath(lgb, gp); } g.DrawPath(Pens.Gray, gp); } if (Enabled) { LeftHandle.Draw(g); RightHandle.Draw(g); } }
/// <summary> /// Controls the actual drawing for this gradient slider control. /// </summary> /// <param name="g">The graphics object used for drawing.</param> /// <param name="clipRectangle">The clip rectangle.</param> protected virtual void OnDraw(Graphics g, Rectangle clipRectangle) { if (Width == 0 || Height == 0) { return; } LinearGradientBrush lgb = new LinearGradientBrush(ClientRectangle, BackColor.Lighter(.2F), BackColor.Darker(.2F), LinearGradientMode.Vertical); g.FillRectangle(lgb, ClientRectangle); lgb.Dispose(); int l = Convert.ToInt32((Width * (LeftHandle.Position - _min)) / (_max - _min)); int r = Convert.ToInt32((Width * (RightHandle.Position - _min)) / (_max - _min)); Rectangle a = new Rectangle(0, 5, l, Height - 10); Rectangle b = new Rectangle(l, 5, r - l, Height - 10); Rectangle c = new Rectangle(r, 5, Right - r, Height - 10); if (a.Width > 0) { SolidBrush sb = new SolidBrush(_minColor); g.FillRectangle(sb, a); sb.Dispose(); } if (b.Width > 0) { LinearGradientBrush center = new LinearGradientBrush(new Point(b.X, 0), new Point(b.Right, 0), _minColor, _maxColor); g.FillRectangle(center, b); center.Dispose(); } if (c.Width > 0) { SolidBrush sb = new SolidBrush(_maxColor); g.FillRectangle(sb, c); sb.Dispose(); } if (Enabled) { LeftHandle.Draw(g); RightHandle.Draw(g); } }
/// <summary> /// Initiates slider dragging. /// </summary> /// <param name="e">The event args.</param> protected override void OnMouseDown(MouseEventArgs e) { if (e.Button == MouseButtons.Left && Enabled) { Rectangle l = LeftHandle.GetBounds(); if (l.Contains(e.Location) && LeftHandle.Visible) { LeftHandle.IsDragging = true; } Rectangle r = RightHandle.GetBounds(); if (r.Contains(e.Location) && RightHandle.Visible) { RightHandle.IsDragging = true; } } base.OnMouseDown(e); }
/// <summary> /// Updates the location of the edit handles when the bounds has been relocated or /// resized. /// </summary> public virtual void BoundsChanged() { // Anything to process? if (TopLeftHandle == null) { return; } // Adjust the four courner drag handles TopLeftHandle.MoveTo(Left - KimonoHandle.DrawOffset, Top - KimonoHandle.DrawOffset); TopRightHandle.MoveTo(Right - KimonoHandle.DrawOffset, Top - KimonoHandle.DrawOffset); BottomRightHandle.MoveTo(Right - KimonoHandle.DrawOffset, Bottom - KimonoHandle.DrawOffset); BottomLeftHandle.MoveTo(Left - KimonoHandle.DrawOffset, Bottom - KimonoHandle.DrawOffset); // Set handle state var newHandleState = (State == KimonoShapeState.Selected) ? KimonoShapeState.Unselected : State; // Adjust top and bottom drag handles based on width if (Width < 50) { // Too small so remove handles TopHandle = null; BottomHandle = null; } else { // Move or create handles as needed if (TopHandle == null) { TopHandle = new KimonoHandle(HorizontalCenter - KimonoHandle.DrawOffset, Top - KimonoHandle.DrawOffset, KimonoHandleConstraint.Vertical, newHandleState); TopHandle.Moved += (point) => { Top = point.Y; }; } else { TopHandle.MoveTo(HorizontalCenter - KimonoHandle.DrawOffset, Top - KimonoHandle.DrawOffset); } if (BottomHandle == null) { BottomHandle = new KimonoHandle(HorizontalCenter - KimonoHandle.DrawOffset, Bottom - KimonoHandle.DrawOffset, KimonoHandleConstraint.Vertical, newHandleState); BottomHandle.Moved += (point) => { Bottom = point.Y; }; } else { BottomHandle.MoveTo(HorizontalCenter - KimonoHandle.DrawOffset, Bottom - KimonoHandle.DrawOffset); } } // Adjust left and right drag handles based on the height if (Height < 50) { // Too small so remove handles LeftHandle = null; RightHandle = null; } else { // Move or create handles as needed if (LeftHandle == null) { LeftHandle = new KimonoHandle(Left - KimonoHandle.DrawOffset, VerticalCenter - KimonoHandle.DrawOffset, KimonoHandleConstraint.Horizontal, newHandleState); LeftHandle.Moved += (point) => { Left = point.X; }; } else { LeftHandle.MoveTo(Left - KimonoHandle.DrawOffset, VerticalCenter - KimonoHandle.DrawOffset); } if (RightHandle == null) { RightHandle = new KimonoHandle(Right - KimonoHandle.DrawOffset, VerticalCenter - KimonoHandle.DrawOffset, KimonoHandleConstraint.Horizontal, newHandleState); RightHandle.Moved += (point) => { Right = point.X; }; } else { RightHandle.MoveTo(Right - KimonoHandle.DrawOffset, VerticalCenter - KimonoHandle.DrawOffset); } } }