예제 #1
0
        public static Control FindControlAtCursor(DrawPanel dp)
        {
            Point pos = Cursor.Position;

            if (dp.Bounds.Contains(pos))
            {
                return(FindControlAtPoint(dp, dp.PointToClient(pos)));
            }
            return(null);
        }
예제 #2
0
 // add lines to drawLines when mouse is moving with time interval of 10
 private void GetPoints(object sender, EventArgs e)
 {
     finish = DrawPanel.PointToClient(Cursor.Position);
     points.Add(new Tuple <Point, Point>(start, finish));
     start = finish;
 }
예제 #3
0
        private void MusicCircleVisualDraw()
        {
            int fqEndIndex = (int)(circleFrequencyEnd / frequencyPerIndex);

            double[] resultPaint = DftData.Take(fqEndIndex).ToArray();
            Graphics g           = bufferedGraphics.Graphics;
            float
                dataRight = resultPaint.Length, panelRight = DrawPanel.Width, panelHeight = DrawPanel.Height;

            dftDataFilter ??= (v) => v;

            int centerX = DrawPanel.Width / 2,
                centerY = DrawPanel.Height / 2;

            float offsetXPix = curOffsetX, offsetYPix = curOffsetY;
            Point mouse = DrawPanel.PointToClient(MousePosition);

            if (mouse.X > 0 && mouse.Y > 0 && mouse.X < DrawPanel.Width && mouse.Y < DrawPanel.Height || true)
            {
                double
                    halfX = DrawPanel.Width / 2,
                    halfY = DrawPanel.Height / 2;
                double
                    offsetX = (halfX - mouse.X) / halfX * maxOffset,
                    offsetY = (halfY - mouse.Y) / halfY * maxOffset;

                offsetXPix = (int)(curOffsetX + (offsetX - curOffsetX) * offsetSpeed);
                offsetYPix = (int)(curOffsetY + (offsetY - curOffsetY) * offsetSpeed);

                curOffsetX = offsetXPix;
                curOffsetY = offsetYPix;
            }

            if (circleCurOffset > 360)
            {
                circleCurOffset = 0;
            }
            double piOffset          = circleCurOffset / 360f * Math.PI * 2;
            double radius            = Math.Min(DrawPanel.Width, DrawPanel.Height) / 2d;
            double halfradius        = radius / 2;
            double scale             = resultPaint.Average() / halfradius / 1 + 1;
            int    resultPaintLength = resultPaint.Length;

            PointF[] points = Enumerable.Range(0, resultPaintLength).Select((v) =>
            {
                double deg = (double)v / resultPaintLength * Math.PI * 2 + piOffset,
                value      = dftDataFilter((float)resultPaint[v] * circleMultiple),
                sin        = Math.Sin(deg),
                cos        = Math.Cos(deg);
                PointF p   = new PointF(
                    (float)(centerX + halfradius * cos * scale + value * cos) + offsetXPix,
                    (float)(centerY + halfradius * sin * scale + value * sin) + offsetYPix);
                return(p);
            }).ToArray();

            circleCurOffset += circleOffsetPerFrame;

            try
            {
                g.DrawClosedCurve(globalDrawPen, points);
            }
            catch (Exception) { }
        }