/// <summary> /// Invokes the pixel clicked event with the correct coordinates. /// </summary> /// <param name="textureSpace"></param> private void OnPixelSelected(Vector2 textureSpace) { var max = _rectTransform.rect.max; var min = _rectTransform.rect.min; var xRange = max.x - min.x; var yRange = max.y - min.y; float xCur = textureSpace.x - min.x; float yCur = textureSpace.y - min.y; xCur = xCur / xRange; yCur = yCur / yRange; OnPixelClick.Invoke(xCur, yCur); }
private void PixelMouseDown(object sender, MouseButtonEventArgs e) { var clickedPixel = (Rectangle)sender; var name = clickedPixel.Name; if (name.Length <= 5) { return; } int pixelNumber; if (!int.TryParse(name.Substring(5), out pixelNumber)) { return; } pixelNumber--; PixelClicked?.Invoke(pixelNumber, e); _lastPixelMouseMovedOver = clickedPixel; }
private void LedDisplay_OnMouseMove(object sender, MouseEventArgs e) { if (e.LeftButton != MouseButtonState.Pressed) { return; } var pixel = Mouse.DirectlyOver as Rectangle; if ((pixel == null) || (pixel.Name.Length <= 4) || (pixel.Name.Substring(0, 5) != "Pixel") || Equals(_lastPixelMouseMovedOver, pixel)) { return; } _lastPixelMouseMovedOver = pixel; int pixelNumber; if (!int.TryParse(pixel.Name.Substring(5), out pixelNumber)) { return; } pixelNumber--; PixelClicked?.Invoke(pixelNumber, EventArgs.Empty); }