void OnCanvasPrePaint(NCanvasPaintEventArgs args) { NCanvas canvas = args.TargetNode as NCanvas; if (canvas == null) { return; } PaintPrimitiveDelegate paintDelegate = canvas.Tag as PaintPrimitiveDelegate; if (paintDelegate == null) { throw new Exception("The canvas has no assigned paint delegate."); } // Clear all styles and set the shadow args.PaintVisitor.ClearStyles(); args.PaintVisitor.SetShadow(m_Shadow); // Paint the scene for the current canvas paintDelegate(args.PaintVisitor, canvas.Width, canvas.Height); // Paint a bounding rectangle for the canvas args.PaintVisitor.ClearStyles(); args.PaintVisitor.SetStroke(NColor.Red, 1); args.PaintVisitor.PaintRectangle(0, 0, canvas.Width, canvas.Height); }
protected override NWidget CreateExampleContent() { m_Shadow = new NShadow(new NColor(160, 160, 160), 20, 20); string[] names = new string[] { "Line", "Polyline", "Rectangle", "Ellipse", "Triangle", "Quad", "Polygon", "Graphics Path" }; PaintPrimitiveDelegate[] delegates = new PaintPrimitiveDelegate[] { new PaintPrimitiveDelegate(PaintLine), new PaintPrimitiveDelegate(PaintPolyline), new PaintPrimitiveDelegate(PaintRectangle), new PaintPrimitiveDelegate(PaintEllipse), new PaintPrimitiveDelegate(PaintTriangle), new PaintPrimitiveDelegate(PaintQuadrangle), new PaintPrimitiveDelegate(PaintPolygon), new PaintPrimitiveDelegate(PaintPath), }; int count = delegates.Length; // Create a table panel to hold the canvases and the labels m_Table = new NTableFlowPanel(); m_Table.HorizontalPlacement = ENHorizontalPlacement.Left; m_Table.VerticalPlacement = ENVerticalPlacement.Top; m_Table.Padding = new NMargins(30); m_Table.HorizontalSpacing = 30; m_Table.VerticalSpacing = 30; m_Table.MaxOrdinal = 4; for (int i = 0; i < count; i++) { NStackPanel stack = new NStackPanel(); m_Table.Add(stack); stack.VerticalSpacing = 5; // Create a canvas to draw in NCanvas canvas = new NCanvas(); canvas.PreferredSize = new NSize(defaultCanvasWidth, defaultCanvasHeight); canvas.Tag = delegates[i]; canvas.BackgroundFill = new NColorFill(NColor.White); canvas.PrePaint += new Function <NCanvasPaintEventArgs>(OnCanvasPrePaint); stack.Add(canvas); // Create a label for the geometry primitive's name NLabel label = new NLabel(names[i]); label.HorizontalPlacement = ENHorizontalPlacement.Center; stack.Add(label); } // The table must be scrollable NScrollContent scroll = new NScrollContent(); scroll.Content = m_Table; return(scroll); }
private void OnCanvasPrePaint(NCanvasPaintEventArgs args) { NCanvas canvas = args.TargetNode as NCanvas; if (canvas == null) { return; } PaintPrimitiveDelegate paintDelegate = canvas.Tag as PaintPrimitiveDelegate; if (paintDelegate == null) { throw new Exception("The canvas has no assigned paint delegate."); } args.PaintVisitor.ClearStyles(); args.PaintVisitor.SetStroke(m_Stroke); args.PaintVisitor.SetFill(Fill); paintDelegate(args.PaintVisitor, canvas.Width, canvas.Height); }