protected override void OnPointerPressed(PointerRoutedEventArgs e) { var pt = new UniPoint(e.GetCurrentPoint(this).Position.X, e.GetCurrentPoint(this).Position.Y); selCoord = pt; pt.X -= ((Width - cpRender.Bounds.Width) / 2); pt.Y -= ((Height - cpRender.Bounds.Height) / 2); if (!cpRender.Bounds.Contains((System.Drawing.PointF)pt)) { selCoord = null; return; } var c = cpRender.HitTest((int)pt.X, (int)pt.Y); if (c == System.Drawing.Color.Empty) { selCoord = null; return; } SetSelectedColor(c); CapturePointer(e.Pointer); colorDragging = true; ColorHit?.Invoke(this, new ColorHitEventArgs(c)); }
void OnTouch(object sender, TouchActionEventArgs args) { if (args.Type == TouchActionType.Pressed || args.Type == TouchActionType.Moved) { var pt = new UniPoint(args.Location.X, args.Location.Y); selCoord = pt; pt.X -= (Width - cpRender.Bounds.Width) / 2; pt.Y -= (Height - cpRender.Bounds.Height) / 2; if (!cpRender.Bounds.Contains((System.Drawing.PointF)pt)) { selCoord = null; Canvas.InvalidateSurface(); return; } var c = cpRender.HitTest((int)pt.X, (int)pt.Y); if (c == System.Drawing.Color.Empty) { selCoord = null; Canvas.InvalidateSurface(); return; } Canvas.InvalidateSurface(); SetSelectedColor(c); ColorHit?.Invoke(this, new ColorHitEventArgs(c)); } else if (args.Type == TouchActionType.Moved) { var pt = new UniPoint(args.Location.X, args.Location.Y); pt.X -= (Width - cpRender.Bounds.Width) / 2; pt.Y -= (Height - cpRender.Bounds.Height) / 2; if (!cpRender.Bounds.Contains((System.Drawing.PointF)pt)) { return; } var c = cpRender.HitTest((int)pt.X, (int)pt.Y); if (c == System.Drawing.Color.Empty) { return; } ColorOver?.Invoke(this, new ColorHitEventArgs(c)); } }
protected override void OnPointerMoved(PointerRoutedEventArgs e) { var pt = new UniPoint(e.GetCurrentPoint(this).Position.X, e.GetCurrentPoint(this).Position.Y); pt.X -= ((Width - cpRender.Bounds.Width) / 2); pt.Y -= ((Height - cpRender.Bounds.Height) / 2); //if (!cpRender.Bounds.Contains((System.Drawing.PointF)pt)) //{ // selCoord = null; // return; //} var c = cpRender.HitTest((int)pt.X, (int)pt.Y, true, out int fixX, out int fixY); selCoord = new UniPoint(fixX, fixY); if (c == System.Drawing.Color.Empty) { selCoord = null; if (ProtectedCursor == null || ProtectedCursor.Type != CoreCursorType.Arrow) { ProtectedCursor = new CoreCursor(CoreCursorType.Arrow, 1); } return; } if (ProtectedCursor == null || ProtectedCursor.Type != CoreCursorType.Cross) { ProtectedCursor = new CoreCursor(CoreCursorType.Cross, 2); } if (e.GetCurrentPoint(this).Properties.IsLeftButtonPressed&& colorDragging) { SetSelectedColor(c); } }