/// <summary> /// Construct new SelectionRectVisual object for the given rectangle /// </summary> public SelectionRectVisual(Point firstPointP, Point secondPointP, double zoomP) { DrawingGroup drawing = new DrawingGroup(); DrawingContext context = drawing.Open(); context.DrawRectangle(Brushes.White, null, new Rect(-1, -1, 3, 3)); context.DrawRectangle(Brushes.Black, null, new Rect(0.25, -1, 0.5, 3)); context.Close(); drawing.Freeze(); // Create a drawing brush that tiles the unit square from the drawing created above. // The size of the viewport and the rotation angle will be updated as we use the // dashed pen. DrawingBrush drawingBrush = new DrawingBrush(drawing); drawingBrush.ViewportUnits = BrushMappingMode.Absolute; drawingBrush.Viewport = new Rect(0, 0, _dashRepeatLength, _dashRepeatLength); drawingBrush.ViewboxUnits = BrushMappingMode.Absolute; drawingBrush.Viewbox = new Rect(0, 0, 1, 1); drawingBrush.Stretch = Stretch.Uniform; drawingBrush.TileMode = TileMode.Tile; // Store the drawing brush and a copy that's rotated by 90 degrees. _horizontalDashBrush = drawingBrush; _verticalDashBrush = drawingBrush.Clone(); _verticalDashBrush.Transform = new RotateTransform(90); this._firstPoint = firstPointP; this._secondPoint = secondPointP; this._zoom = zoomP; _visualForRect = new DrawingVisual(); this.AddVisualChild(_visualForRect); this.AddLogicalChild(_visualForRect); }
protected override void OnUpdate(double[] values) { const double space = 3; const double barwidth = 8; int pts = values.Length / 2; int width = 1000;//pts * (space + barwidth) - space; int height = width / 4; if (_bmp == null || width != _bmp.PixelWidth) { _bmp = new RenderTargetBitmap(width, height, 120, 96, PixelFormats.Pbgra32); } DrawingVisual drawingVisual = new DrawingVisual(); DrawingContext drawingContext = drawingVisual.RenderOpen(); Brush brush = DrawingBrush.Clone(); brush.Freeze(); double totalWidth = width / pts; double totalBarWidth = totalWidth * ((barwidth) / (barwidth + space)); double totalSpace = totalWidth * ((space) / (barwidth + space)); for (int i = 0; i < pts; i++) { double x = i * totalWidth; double y1 = height; double y2 = y1 - values[i] * height; drawingContext.DrawRectangle(brush, null, new Rect(x, y2, totalBarWidth, y1)); } drawingContext.Close(); _bmp.Clear(); _bmp.Render(drawingVisual); PART_visualationDisplay.Source = _bmp; }
static FeedbackHelper() { FeedbackHelper.DefaultAdornerBrush.Freeze(); FeedbackHelper.DefaultThinPen = new Pen((Brush)Brushes.CornflowerBlue, 1.0); FeedbackHelper.DefaultThinPen.Freeze(); FeedbackHelper.DefaultMediumPen = new Pen((Brush)Brushes.CornflowerBlue, 2.0); FeedbackHelper.DefaultMediumPen.Freeze(); FeedbackHelper.DefaultThickPen = new Pen((Brush)Brushes.CornflowerBlue, 3.0); FeedbackHelper.DefaultThickPen.Freeze(); FeedbackHelper.InactiveBrush = (Brush) new SolidColorBrush(Color.FromArgb(byte.MaxValue, (byte)150, (byte)150, (byte)150)); FeedbackHelper.InactiveBrush.Freeze(); FeedbackHelper.InactiveThinPen = new Pen(FeedbackHelper.InactiveBrush, 1.0); FeedbackHelper.InactiveThinPen.Freeze(); FeedbackHelper.MultipleElementThinPen = new Pen((Brush)Brushes.CornflowerBlue, 1.0); FeedbackHelper.MultipleElementThinPen.Freeze(); FeedbackHelper.MultipleElementMediumPen = new Pen((Brush)Brushes.CornflowerBlue, 2.0); FeedbackHelper.MultipleElementMediumPen.Freeze(); FeedbackHelper.ClipPathBrush = (Brush) new SolidColorBrush(Color.FromArgb(byte.MaxValue, (byte)173, (byte)42, (byte)140)); FeedbackHelper.ClipPathBrush.Freeze(); FeedbackHelper.ClipPathThinPen = new Pen(FeedbackHelper.ClipPathBrush, 1.0); FeedbackHelper.ClipPathThinPen.Freeze(); FeedbackHelper.ClipPathThickPen = new Pen(FeedbackHelper.ClipPathBrush, 3.0); FeedbackHelper.ClipPathThickPen.Freeze(); FeedbackHelper.MotionPathThinPen = new Pen((Brush)Brushes.CornflowerBlue, 1.0); FeedbackHelper.MotionPathThinPen.Freeze(); FeedbackHelper.WhiteBrush = (Brush) new SolidColorBrush(Color.FromArgb(byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue)); FeedbackHelper.WhiteBrush.Freeze(); FeedbackHelper.MotionPathSegmentThinPen = new Pen((Brush)Brushes.CornflowerBlue, 1.0); FeedbackHelper.MotionPathSegmentThinPen.DashStyle = new DashStyle((IEnumerable <double>) new double[2] { 6.0, 6.0 }, 1.0); FeedbackHelper.MotionPathSegmentThinPen.Freeze(); FeedbackHelper.MotionPathThickPen = new Pen((Brush)Brushes.CornflowerBlue, 3.0); FeedbackHelper.MotionPathThickPen.Freeze(); FeedbackHelper.MotionPathSegmentThickPen = new Pen((Brush)Brushes.CornflowerBlue, 3.0); FeedbackHelper.MotionPathSegmentThickPen.DashStyle = new DashStyle((IEnumerable <double>) new double[2] { 2.0, 2.0 }, 1.0); FeedbackHelper.MotionPathSegmentThickPen.Freeze(); FeedbackHelper.DefaultThinPenZoomCache = new PenZoomCache(FeedbackHelper.GetThinPen(AdornerType.Default)); DrawingGroup drawingGroup = new DrawingGroup(); DrawingContext drawingContext = drawingGroup.Open(); drawingContext.DrawRectangle((Brush)Brushes.White, (Pen)null, new Rect(-1.0, -1.0, 3.0, 3.0)); drawingContext.DrawRectangle((Brush)Brushes.Black, (Pen)null, new Rect(0.25, -1.0, 0.5, 3.0)); drawingContext.Close(); drawingGroup.Freeze(); DrawingBrush drawingBrush = new DrawingBrush((Drawing)drawingGroup); drawingBrush.ViewportUnits = BrushMappingMode.Absolute; drawingBrush.Viewport = new Rect(0.0, 0.0, 8.0, 8.0); drawingBrush.ViewboxUnits = BrushMappingMode.Absolute; drawingBrush.Viewbox = new Rect(0.0, 0.0, 1.0, 1.0); drawingBrush.Stretch = Stretch.Uniform; drawingBrush.TileMode = TileMode.Tile; FeedbackHelper.horizontalDashBrush = (TileBrush)drawingBrush; FeedbackHelper.verticalDashBrush = (TileBrush)drawingBrush.Clone(); FeedbackHelper.verticalDashBrush.Transform = (Transform) new RotateTransform(90.0); }