protected override void OnMouseMove(MouseEventArgs e) { base.OnMouseMove(e); mouseX = e.X; mouseY = e.Y; using (var g = CreateGraphics()) { var handler = new DrawItemHandler(g, -1, -1, this); DrawItems(handler); handler.Evaluate(this); } if (e.Button != MouseButtons.Left) { return; } if (hovered.Index == -1) { return; } if (selecting) { selectRangeEnd = hovered.Index; } if (e.Y < 0) { marginScrollSpeed = e.Y; if (!marginScrollTimer.Enabled) { smoothScrollY = VerticalScroll.Value; } marginScrollTimer.Start(); } else if (e.Y > Height) { marginScrollSpeed = e.Y - Height; if (!marginScrollTimer.Enabled) { smoothScrollY = VerticalScroll.Value; } marginScrollTimer.Start(); } else { marginScrollTimer.Stop(); } Invalidate(); }
protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); var min = Math.Min(selectRangeStart, selectRangeEnd); var max = Math.Max(selectRangeStart, selectRangeEnd); var handler = new DrawItemHandler(e.Graphics, min, max, this); DrawItems(handler); handler.Evaluate(this); }
/// <summary> /// Draw this item and all child items /// </summary> /// <param name="g"></param> public void DrawItems(ItemPaintEventArgs e, DrawItemHandler drawHandler) { Graphics g = e.Graphics; GraphicsState saved = g.Save(); try { var visibleRect = e.VisibleRectangle; SetupDrawItemsTransform(g, ref visibleRect); foreach (VCItemPlacement placement in items.OrderBy(x => x.Item.Priority)) { if (placement.Item.Visible) { var placementBounds = placement.Bounds; if (placementBounds.IntersectsWith(visibleRect)) { // Save transformation matrix Matrix tx = g.Transform; try { // Translate graphics g.MultiplyTransform(placement.Transform); // Calculate visible rectangle of placement var placementVisRect = Rectangle.Intersect(placementBounds, visibleRect); var localVisRect = placement.ToLocal(placementVisRect); // Draw placement drawHandler(new ItemPaintEventArgs(g, localVisRect), placement); } finally { g.Transform = tx; } } } } } finally { if (null != saved) { g.Restore(saved); } } }
public void SetDrawItemDelegate(DrawItemHandler func) { DrawItemDelegate = func; }
/// <summary> /// Draw all child items using the given draw handler. /// </summary> /// <param name="g"></param> void IVCItemContainer.DrawItems(ItemPaintEventArgs e, DrawItemHandler drawHandler) { rootContainer.DrawItems(e, drawHandler); }
protected abstract void DrawItems(DrawItemHandler handler);