Example #1
0
        private void Panel1_MouseMove(object sender, MouseEventArgs e)
        {
            Point p = e.Location;

            //p = new Point(p.X - (int)mapVisualizer.OffsetX, p.Y - (int)mapVisualizer.OffsetY);
            p = new Point(p.X - (int)(mapVisualizer.OffsetX * mapVisualizer.ZoomScale),
                          p.Y - (int)(mapVisualizer.OffsetY * mapVisualizer.ZoomScale));
            PointF pf = mapVisualizer.TranslatePoint(p);
            //label1.Text = pf.ToString();
            Dot dot = null;

            if (selectedDot != null && dotMode == DotMode.Move)
            {
                if (pf.X < 0)
                {
                    pf.X = 0;
                }
                if (pf.Y < 0)
                {
                    pf.Y = 0;
                }
                //var s = panel1.ContentSize;
                //if (point.X > s.Width - 1) point.X = s.Width - 1;
                //if (point.Y > s.Height - 1) point.Y = s.Height - 1;

                selectedDot.Point = pf;
                dot = selectedDot;
                try
                {
                    lock (__lock)
                    {
                        cts.Cancel();
                        cts.Dispose();
                    }
                    cts = new CancellationTokenSource();
                    StepSync.Instance.Step();
                    work?.Join();
                    work = new Thread(arg =>
                    {
                        CancellationToken cancellation = (CancellationToken)arg;
                        try
                        {
                            Map.AutoFind(cancellation);
                        }
                        catch (Exception ex)
                        {
                            Invoke((Action)(() => MessageBox.Show(ex.ToString())));
                        }
                        lock (__lock)
                        {
                            if (!cancellation.IsCancellationRequested)
                            {
                                new Thread(() => Invoke((Action)(() => matrixImageView.Invalidate())))
                                {
                                    Name = "MatrixInvalidate"
                                }.Start();
                            }
                        }
                    })
                    {
                        Name = "MapAutoFind"
                    };
                    work.Start(cts.Token);
                    matrixImageView.Invalidate();

                    //if (Map.AutoRebuildLineSets)
                    //    Map.FindLines();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
            }
            else
            {
                dot = mapVisualizer.FindDotFromTranslatedPoint(pf);
            }
            if (dot != null)
            {
                string nl = Environment.NewLine;
                //label5.Text = $"Dot{nl}ID {dot.ID}{nl}{dot.Point}";
            }
            //else label5.Text = String.Empty;
            if (Map.LineSets.TryGetValue(1, out LineSet lineSet))
            {
                var pp = mapVisualizer.TranslatePoint(e.Location);
                LineSet.CheckContains(lineSet.dots.Select(a => a.Point).ToArray(), pp);
            }
        }