/// <summary> /// Draw selection handles on the given placement /// </summary> /// <param name="e"></param> /// <param name="placement"></param> private void DrawSelectionBoxes(ItemPaintEventArgs e, VCItemPlacement placement) { if (!container.SelectedItems.Contains(placement)) { return; } var g = e.Graphics; using (var pen = new Pen(Color.Red, 2.0f / e.ZoomFactor)) { g.DrawRectangle(pen, new Rectangle(Point.Empty, placement.Item.Size)); } }
/// <summary> /// Draw in the context of the container using the given draw handler. /// The graphics provided to the draw handler is adjust for the /// zoom factor and position of the container. /// </summary> /// <param name="g"></param> public void DrawContainer(ItemPaintEventArgs e, DrawContainerHandler drawHandler) { var g = e.Graphics; var savedTx = g.Transform; try { drawHandler(new ItemPaintEventArgs(g, e.VisibleRectangle)); } finally { g.Transform = savedTx; } }
/// <summary> /// Draw this item on the given graphics. /// The graphics is transformed such that this item can draw starting at (0, 0). /// </summary> public virtual void Draw(ItemPaintEventArgs e) { if (keyboardHandler != null) { keyboardHandler.OnPostPaint(this, e); } if (mouseHandler != null) { mouseHandler.OnPostPaint(this, e); } if (dragDropHandler != null) { dragDropHandler.OnPostPaint(this, e); } }
/// <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); } } }
/// <summary> /// Draw selection /// </summary> public void Paint(VCItem sender, ItemPaintEventArgs e) { if (selecting) { var rect = SelectionBounds; if (!rect.IsEmpty) { using (var pen = new Pen(Color.Black)) { pen.DashStyle = DashStyle.Dot; e.Graphics.DrawRectangle(pen, SelectionBounds.Round()); } } } // Draw selection boxes (if any) if (container.SelectedItems.Count > 0) { container.DrawItems(e, DrawSelectionBoxes); } }
/// <summary> /// Draw this item and all child items /// </summary> /// <param name="g"></param> public override void Draw(ItemPaintEventArgs e) { List <VCItem> nowVisible = new List <VCItem>(); DrawItems(e, delegate(ItemPaintEventArgs ie, VCItemPlacement placement) { placement.Item.Draw(ie); nowVisible.Add(placement.Item); }); // Notify all items that are no longer visible foreach (VCItem item in this.visibleItems) { if (!nowVisible.Contains(item)) { item.OnLostVisibility(); } } this.visibleItems = nowVisible; base.Draw(e); }
/// <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); }