Exemple #1
0
        private void Circle_PointerPressed(object sender, PointerRoutedEventArgs e)
        {
            Point currentLocation = e.GetCurrentPoint(RingGrid).Position;

            RingGrid.CapturePointer(e.Pointer);

            PointerEventHandler moved = null;

            moved = (s, args) =>
            {
                currentLocation = e.GetCurrentPoint(RingGrid).Position;
                double dx = currentLocation.X - colorRingCenter.X;
                double dy = currentLocation.Y - colorRingCenter.Y;
                //---
                double hue = Math2.ComputeH(dx, dy);
                //---
                Hue          = Math2.ComputeH(dx, dy);
                CurrentColor = Math2.HSVToRGB(Hue, Saturation, Value);

                CompositeTransform ct = SeletcedColorEllipseCompositeTransform;
                Point targetPoint     = new Point(ct.TranslateX, ct.TranslateY);
                ColorPickerStoryboardStart(Hue, targetPoint);
                SelectedColorShowArea.Fill = new SolidColorBrush(CurrentColor);
            };
            PointerEventHandler released = null;

            released = (s, args) =>
            {
                double dx = currentLocation.X - colorRingCenter.X;
                double dy = currentLocation.Y - colorRingCenter.Y;
                //---
                double hue = Math2.ComputeH(dx, dy);
                //---
                Hue          = Math2.ComputeH(dx, dy);
                CurrentColor = Math2.HSVToRGB(Hue, Saturation, Value);

                CompositeTransform ct = SeletcedColorEllipseCompositeTransform;
                Point targetPoint     = new Point(ct.TranslateX, ct.TranslateY);
                ColorPickerStoryboardStart(Hue, targetPoint);
                SelectedColorShowArea.Fill = new SolidColorBrush(CurrentColor);
                RingGrid.PointerMoved     -= moved;
                RingGrid.PointerReleased  -= released;
            };

            RingGrid.PointerMoved    += moved;
            RingGrid.PointerReleased += released;
        }
        public void RingGridTest()
        {
            for (int height = 1; height <= 8; height++)
            {
                for (int width = 2; width <= 8; width++)
                {
                    Console.WriteLine($"size = {width}, {height}");

                    RingGrid grid = new RingGrid(width, height);

                    Console.WriteLine($"mapsize = {grid.MapWidth}, {grid.MapHeight}");

                    Console.WriteLine("map :");

                    Console.WriteLine(grid.ToString());

                    Console.WriteLine("link :");

                    foreach ((int index, var link) in grid.Link)
                    {
                        Console.WriteLine($"{index} : {string.Join(',', link)}");
                    }

                    Assert.IsTrue(GridValidationUtil.IsValid(grid), $"{width}, {height}");
                    Assert.AreEqual(width * height, grid.Count, $"count {width}, {height}");

                    if (height >= 2)
                    {
                        Assert.AreEqual(4, grid[0].Links);
                        Assert.AreEqual(4, grid[width - 1].Links);
                        Assert.AreEqual(4, grid[width * height - width].Links);
                        Assert.AreEqual(4, grid[width * height - 1].Links);

                        Assert.AreEqual(0, grid.Cells.Where((cell) => cell.Links < 4).Count());
                    }

                    Console.WriteLine("---------------------------");
                }
            }
        }
Exemple #3
0
        private void HiddenSquare_PointerPressed(object sender, PointerRoutedEventArgs e)
        {
            Point currentLocation = e.GetCurrentPoint(RingGrid).Position;

            RingGrid.CapturePointer(e.Pointer);

            PointerEventHandler moved = null;

            moved = (s, args) =>
            {
                currentLocation = e.GetCurrentPoint(RingGrid).Position;
                CompositeTransform ct = SeletcedColorEllipseCompositeTransform;
                if (currentLocation.X < 70)
                {
                    ct.TranslateX = 60;
                }
                else if (currentLocation.X > 230)
                {
                    ct.TranslateX = 220;
                }
                else
                {
                    ct.TranslateX = currentLocation.X - seletcedColorEllipse_r;
                }
                if (currentLocation.Y < 70)
                {
                    ct.TranslateY = 60;
                }
                else if (currentLocation.Y > 230)
                {
                    ct.TranslateY = 220;
                }
                else
                {
                    ct.TranslateY = currentLocation.Y - seletcedColorEllipse_r;
                }

                ColorPickerStoryboardStart(Hue, new Point(ct.TranslateX, ct.TranslateY));

                Saturation   = (ct.TranslateX - 60) / squareSideLength;
                Value        = (squareSideLength - (ct.TranslateY - 60)) / squareSideLength;
                CurrentColor = Math2.HSVToRGB(Hue, Saturation, Value);
                SelectedColorShowArea.Fill = new SolidColorBrush(CurrentColor);
            };
            PointerEventHandler released = null;

            released = (s, args) =>
            {
                CompositeTransform ct = SeletcedColorEllipseCompositeTransform;
                if (currentLocation.X < 70)
                {
                    ct.TranslateX = 60;
                }
                else if (currentLocation.X > 230)
                {
                    ct.TranslateX = 220;
                }
                else
                {
                    ct.TranslateX = currentLocation.X - seletcedColorEllipse_r;
                }
                if (currentLocation.Y < 70)
                {
                    ct.TranslateY = 60;
                }
                else if (currentLocation.Y > 230)
                {
                    ct.TranslateY = 220;
                }
                else
                {
                    ct.TranslateY = currentLocation.Y - seletcedColorEllipse_r;
                }

                ColorPickerStoryboardStart(Hue, new Point(ct.TranslateX, ct.TranslateY));

                Saturation   = (ct.TranslateX - 60) / squareSideLength;
                Value        = (squareSideLength - (ct.TranslateY - 60)) / squareSideLength;
                CurrentColor = Math2.HSVToRGB(Hue, Saturation, Value);
                SelectedColorShowArea.Fill = new SolidColorBrush(CurrentColor);
                RingGrid.PointerMoved     -= moved;
                RingGrid.PointerReleased  -= released;
            };

            RingGrid.PointerMoved    += moved;
            RingGrid.PointerReleased += released;
        }