예제 #1
0
        protected override void OnMouseUp(MouseEventArgs e)
        {
            base.OnMouseUp(e);

            if (ArchiveMaintainer == null || ArchiveMaintainer.LoadingInitialData)
            {
                return;
            }

            // Do the same thing for everything here for consistency
            DataTimeRange everything = CurrentArchiveRange;

            if (MouseDragging == DragMode.New && e.X == MouseDragStart)
            {
                LongPoint virtualclicked = LongPoint.DeTranslateFromScreen(new LongPoint(e.Location), everything, DataRange.UnitRange, new LongRectangle(ScrollViewRectangle));
                long      proposedoffset = ArchiveMaintainer.GraphNow.Ticks - (virtualclicked.X + (GraphWidth.Ticks / 2));

                GraphOffset = TimeSpan.FromTicks(proposedoffset > 0 ? proposedoffset : 0);
            }

            TimerScroll = ScrollMode.None;
            Scroller.Stop();

            AutoScaleGraph();

            GridSpacing = BodgeSpacing(GraphWidth);
            RefreshXRange(false);

            MouseDragging = DragMode.None;
            MouseResizing = ResizeMode.None;
        }
예제 #2
0
        public DataPoint OnMouseMove(MouseActionArgs args)
        {
            if (Deselected)
            {
                return(null);
            }
            LongPoint p = LongPoint.DeTranslateFromScreen(new LongPoint(args.Point), args.XRange, args.YRange, new LongRectangle(args.Rectangle));

            return(ClosestPointTo(p));
        }
예제 #3
0
        protected override void OnMouseMove(MouseEventArgs e)
        {
            base.OnMouseMove(e);

            if (ArchiveMaintainer == null || ArchiveMaintainer.LoadingInitialData)
            {
                return;
            }

            DataTimeRange everything     = CurrentArchiveRange;
            LongPoint     virtualclicked = LongPoint.DeTranslateFromScreen(new LongPoint(e.Location), everything, DataRange.UnitRange, new LongRectangle(ScrollViewRectangle));
            long          selectedleft   = LongPoint.TranslateToScreen(new LongPoint(GraphLeft.Ticks, 1), everything, DataRange.UnitRange, new LongRectangle(ScrollViewRectangle)).X;
            long          selectedright  = LongPoint.TranslateToScreen(new LongPoint(GraphRight.Ticks, 1), everything, DataRange.UnitRange, new LongRectangle(ScrollViewRectangle)).X;

            if (MouseDragging == DragMode.Existing)
            {
                long proposedoffset = ArchiveMaintainer.GraphNow.Ticks - (virtualclicked.X + (GraphWidth.Ticks / 2));

                if (proposedoffset + GraphWidth.Ticks > ScrollViewOffset.Ticks + ScrollViewWidth.Ticks)
                {
                    //  -------------------------
                    // |  _______________________|____________________________________
                    // | |      -------------    |           _______--------          |
                    // | |     /             \___|__________/               \         |
                    // | |----                   |                           ----    -|
                    // | |_______________________|_______________________________\__/_|
                    //  -------------------------
                    //
                    // we have scrolled too far left (off the scroll view)

                    GraphOffset = TimeSpan.FromTicks(ScrollViewWidth.Ticks + ScrollViewOffset.Ticks - GraphWidth.Ticks);
                }
                else if (proposedoffset < ScrollViewOffset.Ticks)
                {
                    //                                       -------------------------
                    //   ___________________________________|_______________________  |
                    // |      -------------                _|_____--------          | |
                    // |     /             \______________/ |             \         | |
                    // |----                                |              ----    -| |
                    // |____________________________________|__________________\__/_| |
                    //                                       -------------------------
                    //
                    // we have scrolled too far right (off the scroll view)
                    if (GraphOffset == ScrollViewOffset)
                    {
                        return;
                    }
                    GraphOffset = ScrollViewOffset;
                }
                else
                {
                    //              -------------------------
                    //  ___________|_________________________|______________________
                    // |      -----|-------                __|____--------          |
                    // |     /     |       \______________/  |            \         |
                    // |----       |                         |             ----    -|
                    // |___________|_________________________|_________________\__/_|
                    //              -------------------------
                    //
                    // everything is fine, we are in the middle

                    GraphOffset = TimeSpan.FromTicks(proposedoffset > 0 ? proposedoffset : 0);
                }

                if (GraphOffset.Ticks + GraphWidth.Ticks - ScrollViewOffset.Ticks > 0.90 * ScrollViewWidth.Ticks)
                {
                    ScrollStrength = TimeSpan.FromTicks(GraphOffset.Ticks + GraphWidth.Ticks - (ScrollViewOffset.Ticks + (long)(0.90 * ScrollViewWidth.Ticks)));
                    TimerScroll    = ScrollMode.Left;
                    Scroller.Start();
                }
                else if (GraphOffset.Ticks - ScrollViewOffset.Ticks < 0.1 * ScrollViewWidth.Ticks)
                {
                    ScrollStrength = TimeSpan.FromTicks((long)(0.1 * ScrollViewWidth.Ticks) - (GraphOffset.Ticks - ScrollViewOffset.Ticks));
                    TimerScroll    = ScrollMode.Right;
                    Scroller.Start();
                }
                else
                {
                    TimerScroll = ScrollMode.None;
                }
            }
            else if (MouseDragging == DragMode.New)
            {
                LongPoint virtualstart = LongPoint.DeTranslateFromScreen(new LongPoint(MouseDragStart, 1), everything, DataRange.UnitRange, new LongRectangle(ScrollViewRectangle));
                if (e.X > MouseDragStart && e.X < ScrollViewRectangle.Width)
                {
                    GraphOffset = new TimeSpan(ArchiveMaintainer.GraphNow.Ticks - virtualclicked.X);
                    GraphWidth  = new TimeSpan(virtualclicked.X - virtualstart.X);
                }
                else if (e.X < MouseDragStart && e.X > 0)
                {
                    GraphOffset = new TimeSpan(ArchiveMaintainer.GraphNow.Ticks - virtualstart.X);
                    GraphWidth  = new TimeSpan(virtualstart.X - virtualclicked.X);
                }
                else if (e.X < MouseDragStart)
                {
                    GraphOffset = new TimeSpan(ArchiveMaintainer.GraphNow.Ticks - virtualstart.X);
                    GraphWidth  = ScrollViewOffset + ScrollViewWidth - GraphOffset;
                }
                else if (e.X > MouseDragStart)
                {
                    GraphOffset = ScrollViewOffset;
                    GraphWidth  = new TimeSpan(ScrollViewRight.Ticks - virtualstart.X);
                }
            }
            else if (MouseResizing == ResizeMode.Left)
            {
                long proposedwidth = ArchiveMaintainer.GraphNow.Ticks - (virtualclicked.X + GraphOffset.Ticks);
                if (((proposedwidth * ScrollViewRectangle.Width) / ScrollViewWidth.Ticks) > 2)
                {
                    GraphWidth = proposedwidth + GraphOffset.Ticks < ScrollViewWidth.Ticks + ScrollViewOffset.Ticks ? TimeSpan.FromTicks(proposedwidth) : ScrollViewWidth + ScrollViewOffset - GraphOffset;
                }
                else
                {
                    GraphWidth = TimeSpan.FromTicks((2 * ScrollViewWidth.Ticks) / ScrollViewRectangle.Width);
                }
            }
            else if (MouseResizing == ResizeMode.Right)
            {
                long proposedwidth = virtualclicked.X - GraphRight.Ticks;
                if (ArchiveMaintainer.GraphNow.Ticks - virtualclicked.X < ScrollViewOffset.Ticks)
                {
                    GraphWidth += GraphOffset - ScrollViewOffset;
                    GraphOffset = ScrollViewOffset;
                }
                else if ((((GraphWidth.Ticks + proposedwidth) * ScrollViewRectangle.Width) / ScrollViewWidth.Ticks) > 2)
                {
                    GraphWidth += TimeSpan.FromTicks(virtualclicked.X - GraphRight.Ticks);
                    GraphOffset = TimeSpan.FromTicks(ArchiveMaintainer.GraphNow.Ticks - virtualclicked.X);
                }
                else
                {
                    long oldwidth = GraphWidth.Ticks;
                    GraphWidth   = TimeSpan.FromTicks((2 * ScrollViewWidth.Ticks) / ScrollViewRectangle.Width);
                    GraphOffset += TimeSpan.FromTicks(oldwidth - GraphWidth.Ticks);
                }
            }
            else if (e.Location.X > selectedleft - 3 && e.Location.X < selectedleft + 3)
            {
                Cursor = Cursors.SizeWE;
                return;
            }
            else if (e.Location.X > selectedright - 3 && e.Location.X < selectedright + 3)
            {
                Cursor = Cursors.SizeWE;
                return;
            }
            else if (e.Location.X > selectedleft - 3 && e.Location.X < selectedright + 3)
            {
                Cursor = Cursors.SizeAll;
                return;
            }
            else
            {
                Cursor = Cursors.Cross;
                return;
            }

            GridSpacing = BodgeSpacing(GraphWidth);
            RefreshXRange(false);
        }