/// <summary> /// Returns all elements located at the given point in client coordinates /// </summary> /// <param name="p">Client coordinates.</param> /// <returns>Elements at given point, or null if none exists.</returns> private Mark MarkAt(Point p) { // First figure out which row we are in MarkRow containingRow = RowAt(p); if (containingRow == null) { return(null); } // Now figure out which element we are on foreach (Mark mark in containingRow) { Single x = timeToPixels(mark.StartTime); if (x > p.X) { break; //The rest of them are beyond our point. } Single width = timeToPixels(mark.Duration); MarkRow.MarkStack ms = containingRow.GetStackForMark(mark); var displayHeight = containingRow.Height / containingRow.StackCount; var rowTopOffset = displayHeight * ms.StackIndex; if (p.X >= x && p.X <= x + width && p.Y >= containingRow.DisplayTop + rowTopOffset && p.Y < containingRow.DisplayTop + rowTopOffset + displayHeight) { return(mark); } } return(null); }
private void DrawMark(Graphics g, MarkRow row, IMark mark, int top, Brush b) { int width; //Sanity check - it is possible for .DisplayHeight to become zero if there are too many marks stacked. //We set the DisplayHeight to the row height for the mark, and change the border to red. var markStack = row.GetStackForMark(mark); var displayHeight = (markStack.StackCount > 1) ? ((row.Height - 2) / row.StackCount) : row.Height - 2; var displayTop = top + displayHeight * markStack.StackIndex; if (displayHeight == 0) { displayHeight = row.Height; } width = (int)timeToPixels(mark.Duration); if (width <= 0) { return; } Size size = new Size(width, displayHeight); Point finalDrawLocation = new Point((int)Math.Floor(timeToPixels(mark.StartTime)), displayTop); Rectangle destRect = new Rectangle(finalDrawLocation.X, finalDrawLocation.Y, size.Width, displayHeight); g.FillRectangle(b, destRect); var isSelected = _marksSelectionManager.SelectedMarks.Contains(mark); using (Pen bp = new Pen(Color.Black, isSelected?3:1)) { g.DrawRectangle(bp, destRect); } if (isSelected) { using (Pen bp = new Pen(ThemeColorTable.ForeColor, 1)) { bp.Alignment = PenAlignment.Inset; bp.DashPattern = new [] { 1.0F, 2.0F }; g.DrawRectangle(bp, destRect); } } //Draw the text SolidBrush drawBrush = new SolidBrush(IdealTextColor(row.MarkDecorator.Color)); StringFormat drawFormat = new StringFormat(); g.DrawString(mark.Text, _textFont, drawBrush, destRect, drawFormat); }
/// <summary> /// Returns the row located at the current point in client coordinates /// </summary> /// <param name="p">Client coordinates.</param> /// <returns>Row at given point, or null if none exists.</returns> private MarkRow RowAt(Point p) { MarkRow containingRow = null; int curheight = 0; foreach (MarkRow row in _rows.Where(x => x.Visible)) { if (p.Y < curheight + row.Height) { containingRow = row; break; } curheight += row.Height; } return(containingRow); }
private void CreateMarkRow(IMarkCollection markCollection) { MarkRow row = new MarkRow(markCollection); _rows.Add(row); }