示例#1
0
        internal void DoPreviewMouseUp(object sender, MouseButtonEventArgs e)
        {
            double left = Canvas.GetLeft(activeRect); //left and right track the location of the marked region, ...
            double right = left + activeRect.Width; // this is increased in size as needed to account for overlaps with exisiting regions

            bool c;
            MarkerRectangle current = null; //this references the current region fow which we are looking for overlaps

            //The initial null value indicates that we're looking at the just-marked region, for which there is no MarkerRectangle yet.
            //If we find an overlap, we adjust the existing region and forget about the one we just marked.
            //However, we need to loop back through and ascertain that the newly increased region doesn't overlap some other one!
            do
            {
                c = false; //tracks if there is an overlap found
                foreach (MarkerRectangle mr in markedRegions)
                {
                    if (mr == current) continue;
                    if (mr.Contains(left) || mr.Contains(right) || mr.IsWithin(left, right)) //then we have an overlap
                    {
                        c = true;
                        left = Math.Min(left, mr.leftEdge);
                        right = Math.Max(right, mr.rightEdge);
                        if (current != null) //remove old region
                            Remove(current);
                        else //we can get rid of the marker rectangle, which is about to be subsumed into another region
                        {
                            this.Children.Remove(activeRect);
                            activeRect = null;
                        }
                        current = mr; //update current region
                        break;
                    }
                }
            } while (c == true); //keep going until there are no more overlaps

            if (current == null) //then this is a distinct, new region -- no overlaps found
            { //Make a new region/marker
                current = new MarkerRectangle();
                activeRect.Fill = Brushes.Blue;
                current.rect = activeRect;
                markedRegions.Add(current);
            }
            else
            { //Othwise update overlapped region
                Canvas.SetLeft(current.rect, left);
            }
            current.rect.Width = right - left;
            current.leftEdge = left;
            current.rightEdge = right;
        }
示例#2
0
 internal void Remove(MarkerRectangle mr)
 {
     markedRegions.Remove(mr);
     this.Children.Remove(mr.rect);
     mr.rect = null;
 }
示例#3
0
 //create new marker rectangle from scratch
 public void createMarkRegion(double left, double right)
 {
     activeRect = new Rectangle();
     activeRect.Opacity = 0.4;
     activeRect.Fill = Brushes.Blue;
     activeRect.Width = right - left;
     Binding b = new Binding("ActualHeight"); //create finding to panel height
     b.Source = this.Parent;
     activeRect.SetBinding(Rectangle.HeightProperty, b); //to control rectangle height
     Canvas.SetTop(activeRect, 0);
     Canvas.SetLeft(activeRect, left);
     Children.Add(activeRect); //add it to canvas
     MarkerRectangle current = new MarkerRectangle(); //now log it into marked regions
     current.rect = activeRect;
     current.leftEdge = left;
     current.rightEdge = right;
     markedRegions.Add(current);
 }