private void calculateSnapPoints() { if (!EnableSnapTo) { return; } // build up a full set of snap points/details, from (a) the static snap points for the grid, and // (b) calculated snap points for this move (ie. other elements in the row[s]). CurrentDragSnapPoints = new SortedDictionary <TimeSpan, List <SnapDetails> >(StaticSnapPoints); // iterate through the rows, calculating snap points for every single element in each row that has any selected elements foreach (Row row in Rows) { // This would skip generating snap points for elements on any rows that have nothing selected. // However, we still need to do that; as we might be dragging elements vertically into rows that // (currently) have nothing selected. So we'll generate for everything, but that's going to be // quite overkill. So, the big TODO: here is to regenerate element snap points for only rows with // selected elements, but also regenerate them whenever we move vertically. //if (row.SelectedElements.Count == 0) // continue; // skip any elements in rows that aren't visible. if (!row.Visible) { continue; } foreach (Element element in row) { // skip it if it's a selected element; we don't want to snap to them, as they'll be moving as well if (element.Selected) { continue; } // if it's a non-selected element, generate snap points for it; for the start and end times. Also record the // row its from in the generated point, so when snapping we can check against only elements from this row. SnapDetails details = CalculateSnapDetailsForPoint(element.StartTime, SnapPriorityForElements, Color.Empty); details.SnapRow = row; if (!CurrentDragSnapPoints.ContainsKey(details.SnapTime)) { CurrentDragSnapPoints[details.SnapTime] = new List <SnapDetails>(); } CurrentDragSnapPoints[details.SnapTime].Add(details); details = CalculateSnapDetailsForPoint(element.EndTime, SnapPriorityForElements, Color.Empty); details.SnapRow = row; if (!CurrentDragSnapPoints.ContainsKey(details.SnapTime)) { CurrentDragSnapPoints[details.SnapTime] = new List <SnapDetails>(); } CurrentDragSnapPoints[details.SnapTime].Add(details); } } }
private SnapDetails CalculateSnapDetailsForPoint(TimeSpan snapTime, int level, Color color) { SnapDetails result = new SnapDetails(); result.SnapLevel = level; result.SnapTime = snapTime; result.SnapColor = color; // the start time and end times for specified points are 2 pixels // per snap level away from the snap time. result.SnapStart = snapTime - TimeSpan.FromTicks(TimePerPixel.Ticks * level * SnapStrength); result.SnapEnd = snapTime + TimeSpan.FromTicks(TimePerPixel.Ticks * level * SnapStrength); return(result); }
private void _drawMarks(Graphics g) { Pen p; // iterate through all snap points, and if it's visible, draw it foreach (KeyValuePair <TimeSpan, List <SnapDetails> > kvp in StaticSnapPoints.ToArray()) { if (kvp.Key >= VisibleTimeEnd) { break; } if (kvp.Key >= VisibleTimeStart) { SnapDetails details = null; foreach (SnapDetails d in kvp.Value) { if (details == null || (d.SnapLevel > details.SnapLevel && d.SnapColor != Color.Empty)) { details = d; } } p = new Pen(details.SnapColor); Single x = timeToPixels(kvp.Key); p.DashPattern = new float[] { details.SnapLevel, details.SnapLevel }; if (selectedMarks.ContainsKey(kvp.Key)) { p.Width = 3; } g.DrawLine(p, x, 0, x, Height); p.Dispose(); } } if (m_button == MouseButtons.Left && m_mark != TimeSpan.Zero) { p = new Pen(Brushes.Yellow) { DashPattern = new float[] { 2, 2 } }; TimeSpan newMarkPosition = pixelsToTime(PointToClient(new Point(MousePosition.X, MousePosition.Y)).X) + VisibleTimeStart; Single x = timeToPixels(newMarkPosition); g.DrawLine(p, x, 0, x, Height); p.Dispose(); } }
protected override void OnMouseDown(MouseEventArgs e) { //Console.WriteLine("Clicks: " + e.Clicks); m_button = e.Button; m_mouseDownX = e.X; if (e.Button != MouseButtons.Left) { return; } // If we're hovering over a mark when left button is clicked, then select/move the mark m_mark = PointTimeToMark(pixelsToTime(e.X) + VisibleTimeStart); if (m_mark != TimeSpan.Zero) { foreach (SnapDetails d in StaticSnapPoints[m_mark]) { if (m_markDetails == null || (d.SnapLevel > m_markDetails.SnapLevel && d.SnapColor != Color.Empty)) { m_markDetails = d; } } m_mouseState = MouseState.DraggingMark; _mouseUp = false; //Lets the undo manager know not to check that the Mark is being used and we don't need to store every mark movement, just the start and end time. _originalMarkTime = m_mark; //Will store the selected Mark time before the move, to use in the under manager. } else if (Cursor == Cursors.HSplit) { m_mouseState = MouseState.ResizeRuler; } else { ClearSelectedMarks(); m_mouseState = MouseState.DragWait; } }
private void _drawMarks(Graphics g) { Pen p; // iterate through all snap points, and if it's visible, draw it foreach (KeyValuePair <TimeSpan, List <SnapDetails> > kvp in StaticSnapPoints.ToArray()) { if (kvp.Key >= VisibleTimeEnd) { break; } if (kvp.Key >= VisibleTimeStart) { SnapDetails details = null; foreach (SnapDetails d in kvp.Value) { if (details == null || (d.SnapLevel > details.SnapLevel && d.SnapColor != Color.Empty)) { details = d; } } int lineBold = 1; if (details.SnapBold) { lineBold = 3; } p = new Pen(details.SnapColor, lineBold); Single x = timeToPixels(kvp.Key); if (!details.SnapSolidLine) { p.DashPattern = new float[] { details.SnapLevel, details.SnapLevel } } ; if (selectedMarks.ContainsKey(kvp.Key)) { p.Width = 3; } g.DrawLine(p, x, 0, x, Height); p.Dispose(); } } if (m_button == MouseButtons.Left && m_mark != TimeSpan.Zero) { p = new Pen(Brushes.Yellow) { DashPattern = new float[] { 2, 2 } }; TimeSpan newMarkPosition = pixelsToTime(PointToClient(new Point(MousePosition.X, MousePosition.Y)).X) + VisibleTimeStart; Single x = timeToPixels(newMarkPosition); g.DrawLine(p, x, 0, x, Height); p.Dispose(); //Draws the time next to the selected mark that is being moved. Font drawFont = new Font("Arial", 8, FontStyle.Bold); SolidBrush drawBrush = new SolidBrush(Color.White); StringFormat drawFormat = new StringFormat(); g.TextRenderingHint = TextRenderingHint.AntiAlias; g.DrawString(markTime, drawFont, drawBrush, x, 0, drawFormat); drawFont.Dispose(); drawBrush.Dispose(); drawFormat.Dispose(); } }
public MarkMovedEventArgs(TimeSpan originalMark, TimeSpan newMark, SnapDetails details) { OriginalMark = originalMark; NewMark = newMark; SnapDetails = details; }
private SnapDetails CalculateSnapDetailsForPoint(TimeSpan snapTime, int level, Color color, bool lineBold, bool solidLine) { SnapDetails result = new SnapDetails(); result.SnapLevel = level; result.SnapTime = snapTime; result.SnapColor = color; result.SnapBold = lineBold; result.SnapSolidLine = solidLine; // the start time and end times for specified points are 2 pixels // per snap level away from the snap time. result.SnapStart = snapTime - TimeSpan.FromTicks(TimePerPixel.Ticks * level * SnapStrength); result.SnapEnd = snapTime + TimeSpan.FromTicks(TimePerPixel.Ticks * level * SnapStrength); return result; }
public MarkMovedEventArgs(TimeSpan originalMark, TimeSpan newMark, SnapDetails details) { OriginalMark = originalMark; NewMark = newMark; SnapDetails = details; }
protected override void OnMouseDown(MouseEventArgs e) { //Console.WriteLine("Clicks: " + e.Clicks); m_button = e.Button; m_mouseDownX = e.X; if (e.Button != MouseButtons.Left) return; // If we're hovering over a mark when left button is clicked, then select/move the mark m_mark = PointTimeToMark(pixelsToTime(e.X) + VisibleTimeStart); if (m_mark != TimeSpan.Zero) { foreach (SnapDetails d in StaticSnapPoints[m_mark]) { if (m_markDetails == null || (d.SnapLevel > m_markDetails.SnapLevel && d.SnapColor != Color.Empty)) m_markDetails = d; } m_mouseState = MouseState.DraggingMark; } else if (Cursor == Cursors.HSplit) m_mouseState = MouseState.ResizeRuler; else { ClearSelectedMarks(); m_mouseState = MouseState.DragWait; } }