/// ------------------------------------------------------------------------------------
        private void DrawBackground(PaintEventArgs e, Rectangle rc)
        {
            var rcSegmentedArea = GetFullRectangleForTimeRange(new TimeRange(TimeSpan.Zero,
                                                                             SegmentBoundaries.LastOrDefault()));

            rcSegmentedArea.Intersect(rc);
            if (rcSegmentedArea.Width > 0)
            {
                using (var brush = new SolidBrush(SegmentedBackgroundColor))
                    e.Graphics.FillRectangle(brush, rcSegmentedArea);
            }

            FillIgnoredSegments(e, Color.White);

            var x = (!SegmentBoundaries.Any()) ? 0 : ConvertTimeToXCoordinate(SegmentBoundaries.Last()) + 1;

            if (x > rc.Right)
            {
                return;
            }

            if (x > rc.X)
            {
                rc.Width -= (x - rc.X);
                rc.X      = x;
            }
            using (var brush = new SolidBrush(UnsegmentedBackgroundColor))
                e.Graphics.FillRectangle(brush, rc);
        }
Exemplo n.º 2
0
 /// ------------------------------------------------------------------------------------
 public void SetSelectedBoundary(TimeSpan boundary)
 {
     if (boundary == TimeSpan.Zero || SegmentBoundaries.Any(b => b == boundary))
     {
         MyPainter.SetSelectedBoundary(boundary);
         EnsureTimeIsVisible(boundary, new TimeRange(boundary, boundary), false, false);
     }
 }
Exemplo n.º 3
0
        /// ------------------------------------------------------------------------------------
        private TimeSpan GetBoundaryNearX(int x)
        {
            if (SegmentBoundaries == null)
            {
                return(default(TimeSpan));
            }

            var timeAtMouseA = (x <= 4 ? TimeSpan.Zero : GetTimeFromX(x - 4));
            var timeAtMouseB = GetTimeFromX(x + 4);

            return(SegmentBoundaries.FirstOrDefault(b => b >= timeAtMouseA && b <= timeAtMouseB));
        }
Exemplo n.º 4
0
        /// ------------------------------------------------------------------------------------
        public int GetIndexOfLastBoundaryBeforeTime(TimeSpan time)
        {
            var segs = SegmentBoundaries.ToArray();

            for (var i = segs.Length; i >= 0; i--)
            {
                if (time >= segs[i])
                {
                    return(i);
                }
            }

            return(-1);
        }
Exemplo n.º 5
0
        /// ------------------------------------------------------------------------------------
        public virtual int GetBoundaryNearX(int x)
        {
            int i = 0;

            foreach (var boundaryX in SegmentBoundaries.Select(b => ConvertTimeToXCoordinate(b)))
            {
                if (x >= boundaryX - kBoundaryHotZoneHalfWidth && x <= boundaryX + kBoundaryHotZoneHalfWidth)
                {
                    return(i);
                }

                i++;
            }

            return(-1);
        }
Exemplo n.º 6
0
        /// ------------------------------------------------------------------------------------
        protected virtual bool OnInitiatiatingBoundaryMove(int mouseX, TimeSpan boundary)
        {
            if (CanBoundaryBeMoved != null && !CanBoundaryBeMoved(boundary, AllowMovingBoundariesWithAdjacetAnnotations))
            {
                return(false);
            }

            _scrollCalculator = new WaveControlScrollCalculator(this);

            // Figure out the limits within which the boundary may be moved. It's not allowed
            // to be moved to the left of the previous boundary or to the right of the next
            // boundary.
            _minXForBoundaryMove = Painter.ConvertTimeToXCoordinate(SegmentBoundaries.LastOrDefault(b => b < boundary));

            var  nextBoundary         = SegmentBoundaries.FirstOrDefault(b => b > boundary);
            bool limitedByEndOfStream = nextBoundary == default(TimeSpan);

            if (limitedByEndOfStream)
            {
                nextBoundary = WaveStream.TotalTime;
            }

            _maxXForBoundaryMove = Painter.ConvertTimeToXCoordinate(nextBoundary);

            if (_minXForBoundaryMove > 0)
            {
                _minXForBoundaryMove += WavePainterBasic.kBoundaryHotZoneHalfWidth;
            }

            if (_maxXForBoundaryMove == 0)
            {
                _maxXForBoundaryMove = ClientSize.Width - WavePainterBasic.kRightDisplayPadding + 1;
            }
            else if (!limitedByEndOfStream)
            {
                _maxXForBoundaryMove -= WavePainterBasic.kBoundaryHotZoneHalfWidth;
            }

            Painter.SetMovingAnchorTime(boundary);
            IsBoundaryMovingInProgress      = true;
            _mouseXAtBeginningOfSegmentMove = mouseX;

            return(true);
        }
Exemplo n.º 7
0
        /// ------------------------------------------------------------------------------------
        protected override void OnMouseMove(MouseEventArgs e)
        {
            base.OnMouseMove(e);

            if (!SelectSegmentOnMouseOver)
            {
                return;
            }

            var segNumber = GetSegmentForX(e.X);

            if (segNumber < 0)
            {
                ClearSelection();
                return;
            }

            var start = (segNumber == 0 ? TimeSpan.Zero : SegmentBoundaries.ElementAt(segNumber - 1));

            SetSelectionTimes(start, SegmentBoundaries.ElementAt(segNumber));
        }
Exemplo n.º 8
0
        /// ------------------------------------------------------------------------------------
        protected override void OnBoundaryMouseDown(int mouseX, TimeSpan boundaryClicked,
                                                    int indexOutOfBoundaryClicked)
        {
            var boundaries = SegmentBoundaries.ToArray();

            var startTime = (indexOutOfBoundaryClicked == 0 ? TimeSpan.Zero :
                             boundaries.ElementAt(indexOutOfBoundaryClicked - 1));

            MyPainter.SetSelectionTimes(startTime, boundaryClicked);

            _selectionColorsToLeftOfMovingBoundary = MyPainter.GetColorsOfAreaEndingAtTime(boundaryClicked);
            System.Diagnostics.Debug.Write("OnBoundaryMouseDown: Left colors = ");
            foreach (var color in _selectionColorsToLeftOfMovingBoundary)
            {
                System.Diagnostics.Debug.Write(color + "; ");
            }
            System.Diagnostics.Debug.WriteLine("");

            if (indexOutOfBoundaryClicked >= boundaries.Length - 1)
            {
                _selectionColorsToRightOfMovingBoundary = null;
            }
            else
            {
                _selectionColorsToRightOfMovingBoundary = MyPainter.GetColorsOfAreaStartingAtTime(boundaryClicked);
                _boundaryToRightOfMovingBoundary        = SegmentBoundaries.ElementAt(indexOutOfBoundaryClicked + 1);

                System.Diagnostics.Debug.Write("OnBoundaryMouseDown: Right colors = ");
                foreach (var color in _selectionColorsToRightOfMovingBoundary)
                {
                    System.Diagnostics.Debug.Write(color + "; ");
                }
                System.Diagnostics.Debug.WriteLine("");
            }
            base.OnBoundaryMouseDown(mouseX, boundaryClicked, indexOutOfBoundaryClicked);
        }