コード例 #1
0
		protected override void OnRender(DrawingContext drawingContext) {
			// draw everything except the reflection
			base.OnRender(drawingContext);

			// set opacity
			drawingContext.PushOpacityMask(opacityMask);

			reflection.Visual = Child;
			var group = new TransformGroup();


			if (Child.RenderTransform is TransformGroup) {
				foreach (var child in ((TransformGroup)Child.RenderTransform).Children) {
					group.Children.Add(child);
				}
			}
			else {
				group.Children.Add(Child.RenderTransform);
			}

			scaleTransform.CenterY = (ActualHeight / 1.5) + ((ActualHeight / 1.5) / 4);
			scaleTransform.CenterX = ActualWidth / 2;
			group.Children.Add(scaleTransform);

			reflection.Transform = group;

			// draw the reflection
			drawingContext.DrawRectangle(
					reflection, null,
					new Rect(0, ActualHeight / 1.5, ActualWidth, ActualHeight / 3));

			// cleanup
			drawingContext.Pop();
		}
コード例 #2
0
ファイル: TileSet.cs プロジェクト: treytomes/wpf-console
		public void Render(DrawingContext dc, Point location, Brush tint, int tileIndex)
		{
			var dstRect = new Rect(location, new Size(TileWidth, TileHeight));

			dc.PushOpacityMask(new ImageBrush(_tiles[tileIndex]));
			dc.DrawRectangle(tint, null, dstRect);

			dc.Pop();
		}
コード例 #3
0
        protected override void OnRender(DrawingContext drawingContext)
        {
            // draw everything except the reflection
            base.OnRender(drawingContext);

            // set opacity
            drawingContext.PushOpacityMask(_opacityMask);
            drawingContext.PushOpacity(0.4);

            // set reflection parameters based on content size
            _reflection.Visual = Child;

            // draw the reflection
            drawingContext.DrawRectangle(_reflection, null, new Rect(0, ActualHeight + _gap, ActualWidth, ActualHeight));

            // cleanup
            drawingContext.Pop();
            drawingContext.Pop();
        }
コード例 #4
0
        protected override void ApplyFilter(FastBitmap source, DrawingContext dc, int width, int height)
        {
            var gradientStops = new GradientStopCollection();
            gradientStops.Add(new GradientStop(SWMColor.FromArgb(0, 0, 0, 0), 0));
            gradientStops.Add(new GradientStop(SWMColor.FromArgb(0, 0, 0, 0), 0.5));
            gradientStops.Add(new GradientStop(SWMColor.FromArgb(180, 0, 0, 0), 1.3));
            gradientStops.Add(new GradientStop(SWMColor.FromArgb(230, 0, 0, 0), 1.7));

            var brush = new RadialGradientBrush(gradientStops)
            {
                GradientOrigin = new Point(0.5, 0.5),
                Center = new Point(0.5, 0.45),
                RadiusX = 0.5,
                RadiusY = 0.5
            };

            dc.DrawImage(source.InnerBitmap, new Rect(0, 0, width, height));

            dc.PushOpacityMask(brush);
            dc.DrawRectangle(new SolidColorBrush(SWMColors.Black), null, new Rect(0, 0, width, height));
            dc.Pop();
        }
コード例 #5
0
        protected override void OnRender(DrawingContext drawingContext)
        {
            // draw everything except the reflection
            base.OnRender(drawingContext);

            // set opacity
            drawingContext.PushOpacityMask(_opacityMask);
            drawingContext.PushOpacity(0.3);

            // set reflection parameters based on content size
            _reflection.Visual = Child;
            ((ScaleTransform)_reflection.Transform).CenterY = 3 * ActualHeight / 4;
            ((ScaleTransform)_reflection.Transform).CenterX = ActualWidth / 2;

            // draw the reflection
            drawingContext.DrawRectangle(
                _reflection, null,
                new Rect(0, ActualHeight / 2, ActualWidth, ActualHeight / 2));

            // cleanup
            drawingContext.Pop();
            drawingContext.Pop();
        }
コード例 #6
0
        /// <summary>
        /// Applies the <see cref="ShinyFloorFilter" /> to the specified <paramref name="source"/>.
        /// </summary>
        /// <param name="source">The source image.</param>
        /// <param name="dc"></param>
        /// <param name="width"></param>
        /// <param name="height"></param>
        protected override void ApplyFilter(FastBitmap source, DrawingContext dc, int width, int height)
        {
            // First, draw reflected image with an opacity mask.
            int reflectionHeight = (int)(source.Height * (ReflectionPercentage / 100.0f));
            dc.PushTransform(new TransformGroup
            {
                Children = new TransformCollection
                {
                    new ScaleTransform {ScaleY = -1},
                    new TranslateTransform {Y = GetReflectionOffsetY(source) + reflectionHeight}
                }
            });
            dc.PushOpacityMask(new LinearGradientBrush(
                Colors.Transparent,
                Color.FromArgb((byte)(255.0f * (ReflectionOpacity / 100.0f)), 0, 0, 0),
                new Point(0, 0),
                new Point(0, 1)));

            dc.DrawImage(new CroppedBitmap(source.InnerBitmap, new Int32Rect(0, source.Height - reflectionHeight, source.Width, reflectionHeight)),
                new Rect(0, 0, source.Width, reflectionHeight));

            dc.Pop();
            dc.Pop();

            // Draw original image.
            dc.DrawImage(source.InnerBitmap, new Rect(0, 0, source.Width, source.Height));
        }
コード例 #7
0
        protected override void OnRender(DrawingContext drawingContext)
        {
            var child = Child;
            if (child == null)
            {
                return;
            }

            if (m_brush == null)
            {
                return;
            }

            var renderSize = RenderSize;
            var childRenderSize = child.RenderSize;
            var reflectionSize = ReflectionSize;
            var reflectionSeparation = ReflectionSeparation;

            var matrix = Matrix.Identity;
            matrix.Scale(1,-1);
            matrix.Translate (0, childRenderSize.Height + reflectionSize + reflectionSeparation);

            m_transform.Matrix = matrix;

            drawingContext.PushTransform (m_transform);
            drawingContext.PushOpacityMask (m_opacityMask);

            var rectangle = new Rect(
                0,
                0,
                renderSize.Width,
                reflectionSize
                );

            drawingContext.DrawRectangle (
                m_brush,
                null,
                rectangle
                );

            drawingContext.Pop();
            drawingContext.Pop();
        }
コード例 #8
0
        protected override void OnRender(DrawingContext drawingContext)
        {
            // Draw non-reflection controls
            base.OnRender(drawingContext);

            double halfHeight = ActualHeight / 2;

            // Create fading opacity mask
            drawingContext.PushOpacityMask(opacityMask);
            drawingContext.PushOpacity(0.15);

            // Create the reflection mirror transform.
            reflection.Visual = Child;
            ((ScaleTransform)reflection.Transform).CenterY = ActualHeight * 3/4;
            ((ScaleTransform)reflection.Transform).CenterX = ActualWidth / 2;

            // Draw the reflection visual with opacity mask applied
            drawingContext.DrawRectangle(
                reflection, null,
                new Rect(0, halfHeight, ActualWidth, halfHeight));

            // Remove opacity masks for next drawing
            drawingContext.Pop();
            drawingContext.Pop();
        }
コード例 #9
0
        /// <summary>
        /// Draws the contours against a horizontal and vertical axis.
        /// </summary>
        /// <param name="dc">The drawing context on which to draw.</param>
        /// <param name="hAxis">The horizontal physical axis to draw against.</param>
        /// <param name="vAxis">The vertical physical axis to draw against.</param>
        public void Draw(System.Windows.Media.DrawingContext dc, HorizontalPhysicalAxis hAxis, VerticalPhysicalAxis vAxis)
        {
            double worldHorizontalRange = hAxis.Axis.WorldMax - hAxis.Axis.WorldMin;
            double worldVerticalRange   = vAxis.Axis.WorldMax - vAxis.Axis.WorldMin;

            for (int i = 0; i < _internalGridSize.Rows; ++i)
            {
                for (int j = 0; j < _internalGridSize.Columns; ++j)
                {
                    double worldY = (double)i / (double)(_internalGridSize.Rows - 1) * worldVerticalRange + vAxis.Axis.WorldMin;
                    double worldX = (double)j / (double)(_internalGridSize.Columns - 1) * worldHorizontalRange + hAxis.Axis.WorldMin;
                    _grid[i, j] = _fieldMethod(worldX, worldY);
                }
            }

            Pair <List <double>, List <List <LineSegment> > > contourGroups = ContourUtils.ContourGenCore.Generate(_grid, _levels);

            double physicalHorizontalRange = hAxis.PhysicalMaxX - hAxis.PhysicalMinX;
            double physicalVerticalRange   = vAxis.PhysicalMaxY - vAxis.PhysicalMinY;

            Pen p = new Pen(_stroke, _strokeThickness);

            for (int i = 0; i < contourGroups.First.Count; ++i)
            {
                List <LineSegment> lineSegments = contourGroups.Second[i];

                // find best index to put label.
                int bestJ = DetermineBestLabelPosition(lineSegments, 0, _internalGridSize.Columns - 1, 0, _internalGridSize.Rows - 1);

                // see if line segment sequence is reasonably long. If so, put a contour label on it.
                bool drawingLabel = false;
                if (_showContourLabels)
                {
                    double sum = 0.0;
                    for (int k = 0; k < lineSegments.Count; ++k)
                    {
                        sum += Math.Abs(lineSegments[k].X1 - lineSegments[k].X2) + Math.Abs(lineSegments[k].Y1 - lineSegments[k].Y2);
                        if (sum > _internalGridSize.Rows / 6.0)
                        {
                            drawingLabel = true;
                            break;
                        }
                    }
                }

                if (drawingLabel)
                {
                    LineSegment ls = lineSegments[bestJ];

                    double x1 = ls.X1 / (double)(_internalGridSize.Columns - 1) * physicalHorizontalRange + hAxis.PhysicalMinX;
                    double x2 = ls.X2 / (double)(_internalGridSize.Columns - 1) * physicalHorizontalRange + hAxis.PhysicalMinX;
                    double y1 = ls.Y1 / (double)(_internalGridSize.Rows - 1) * physicalVerticalRange + vAxis.PhysicalMinY;
                    double y2 = ls.Y2 / (double)(_internalGridSize.Rows - 1) * physicalVerticalRange + vAxis.PhysicalMinY;

                    FormattedText ft = new FormattedText(contourGroups.First[i].ToString(_contourLabelFormat),
                                                         System.Globalization.CultureInfo.CurrentCulture,
                                                         FlowDirection.LeftToRight, new Typeface("Arial"), 11, _stroke);

                    double angle = Math.Atan2(
                        contourGroups.Second[i][bestJ].Y1 - contourGroups.Second[i][bestJ].Y2,
                        contourGroups.Second[i][bestJ].X2 - contourGroups.Second[i][bestJ].X1) / Math.PI * 180.0;

                    if (angle > 90)
                    {
                        angle -= 180;
                    }
                    if (angle < -90)
                    {
                        angle += 180;
                    }

                    RotateTransform rt = new RotateTransform(angle);

                    dc.PushTransform(new TranslateTransform((x1 + x2) / 2.0, (y1 + y2) / 2.0));
                    dc.PushTransform(rt);
                    dc.DrawText(ft, new Point(-ft.Width / 2.0, -ft.Height / 2.0));
                    dc.Pop();
                    dc.Pop();

                    Rect r1 = new Rect(hAxis.PhysicalMinX, vAxis.PhysicalMaxY, hAxis.PhysicalMaxX - hAxis.PhysicalMinX, vAxis.PhysicalMinY - vAxis.PhysicalMaxY);
                    Rect r2 = new Rect((x1 + x2) / 2.0 - ft.Width * 1.6 / 2.0, (y1 + y2) / 2.0 - ft.Height * 1.6 / 2.0, ft.Width * 1.6, ft.Height * 1.6);

                    DrawingBrush db = new DrawingBrush();
                    db.ViewboxUnits  = BrushMappingMode.Absolute;
                    db.ViewportUnits = BrushMappingMode.Absolute;
                    db.Viewport      = r1;
                    db.Viewbox       = r1;

                    GeometryGroup gg = new GeometryGroup();
                    gg.FillRule = FillRule.Nonzero;

                    if (r2.Left - r1.Left > 0)
                    {
                        RectangleGeometry rg = new RectangleGeometry(new Rect(r1.Left, r1.Top, r2.Left - r1.Left, r1.Height));
                        gg.Children.Add(rg);
                    }
                    if (r1.Right - r2.Right > 0)
                    {
                        RectangleGeometry rg = new RectangleGeometry(new Rect(r2.Right, r1.Top, r1.Right - r2.Right, r1.Height));
                        gg.Children.Add(rg);
                    }
                    if (r2.Top - r1.Top > 0)
                    {
                        RectangleGeometry rg = new RectangleGeometry(new Rect(r1.Left, r1.Top, r1.Width, r2.Top - r1.Top));
                        gg.Children.Add(rg);
                    }
                    if (r1.Bottom - r2.Bottom > 0)
                    {
                        RectangleGeometry rg = new RectangleGeometry(new Rect(r1.Left, r2.Bottom, r1.Width, r1.Bottom - r2.Bottom));
                        gg.Children.Add(rg);
                    }

                    SolidColorBrush scb = new SolidColorBrush(Color.FromArgb(255, 0, 0, 0));
                    GeometryDrawing gd  = new GeometryDrawing(scb, null, gg);
                    db.Drawing = gd;

                    dc.PushOpacityMask(db);
                }

                for (int j = 0; j < lineSegments.Count; ++j)
                {
                    LineSegment ls = lineSegments[j];

                    double x1 = ls.X1 / (double)(_internalGridSize.Columns - 1) * physicalHorizontalRange + hAxis.PhysicalMinX;
                    double x2 = ls.X2 / (double)(_internalGridSize.Columns - 1) * physicalHorizontalRange + hAxis.PhysicalMinX;
                    double y1 = ls.Y1 / (double)(_internalGridSize.Rows - 1) * physicalVerticalRange + vAxis.PhysicalMinY;
                    double y2 = ls.Y2 / (double)(_internalGridSize.Rows - 1) * physicalVerticalRange + vAxis.PhysicalMinY;

                    dc.DrawLine(p, new Point(x1, y1), new Point(x2, y2));
                }

                if (drawingLabel)
                {
                    // pop opacity mask.
                    dc.Pop();
                }
            }
        }
コード例 #10
0
 protected virtual void CreatePageVisual(Rect pageBounds, DrawingVisual source, bool isFooterPage, DrawingContext drawingContext)
 {
     drawingContext.DrawRectangle(null, FramePen, new Rect { X = FrameRect.X, Y = FrameRect.Y, Width = FrameRect.Width, Height = FrameRect.Height });
     var offsetX = PageMargins.Left - pageBounds.X - 1;
     var offsetY = PageMargins.Top - pageBounds.Y;
     drawingContext.PushTransform(new TranslateTransform(offsetX, offsetY + HeaderHeight));
     var pg = new Rect(new Point(pageBounds.X, pageBounds.Y), new Size(pageBounds.Width, pageBounds.Height));
     drawingContext.PushClip(new RectangleGeometry(pg));
     drawingContext.PushOpacityMask(Brushes.White);
     drawingContext.DrawDrawing(source.Drawing);
 }
コード例 #11
0
        protected override void OnRender(DrawingContext drawingContext)
        {
            base.OnRender(drawingContext);

            drawingContext.PushOpacityMask(ReflectionMask);
            drawingContext.PushOpacity(ReflectionOpacity);

            _mReflection.Visual = Child;

            ((ScaleTransform)_mReflection.Transform).CenterY = 3 * ActualHeight / 4;
            ((ScaleTransform)_mReflection.Transform).CenterX = ActualWidth / 2;

            drawingContext.DrawRectangle(_mReflection, null, new Rect(0, ActualHeight / 2, ActualWidth, ActualHeight / 2));

            drawingContext.Pop();
            drawingContext.Pop();
        }
コード例 #12
0
        //DepthImagePixel[] depthPixels, byte[] colorPixels,DepthImageFormat depthFormat, ColorImageFormat colorFormat)
        public void Antialiasing(DrawingContext drawingContext)
        {
            // do our processing outside of the using block
            // so that we return resources to the kinect as soon as possible
            _sensor.CoordinateMapper.MapDepthFrameToColorFrame(
                _sensor.DepthStream.Format,
                _depthPixels,
                _sensor.ColorStream.Format,
                _colorCoordinates);

            Array.Clear(_greenScreenPixelData, 0, _greenScreenPixelData.Length);

            _borderCounter = 0;

            // loop over each row and column of the depth
            for (int y = 0; y < _depthHeight; ++y)
            {
                for (int x = 0; x < _depthWidth; ++x)
                {
                    // calculate index into depth array
                    int depthIndex = x + (y * _depthWidth);

                    DepthImagePixel depthPixel = _depthPixels[depthIndex];

                    int player = depthPixel.PlayerIndex;
                    int depthDist = depthPixel.Depth;
                    // if we're tracking a player for the current pixel, do green screen
                    if (player > 0 && (depthDist > 400 && depthDist < 3500))
                    {
                        //found = true;

                        // retrieve the depth to color mapping for the current depth pixel
                        ColorImagePoint colorImagePoint = _colorCoordinates[depthIndex];

                        // scale color coordinates to depth resolution
                        int colorInDepthX = colorImagePoint.X / _colorToDepthDivisor;
                        int colorInDepthY = colorImagePoint.Y / _colorToDepthDivisor;

                        // make sure the depth pixel maps to a valid point in color space
                        // check y > 0 and y < depthHeight to make sure we don't write outside of the array
                        // check x > 0 instead of >= 0 since to fill gaps we set opaque current pixel plus the one to the left
                        // because of how the sensor works it is more correct to do it this way than to set to the right
                        if (colorInDepthX > 0 && colorInDepthX < _depthWidth && colorInDepthY >= 0 && colorInDepthY < _depthHeight)
                        {
                            // calculate index into the green screen pixel array
                            int greenScreenIndex = colorInDepthX + (colorInDepthY * _depthWidth);

                            if (_antialiasing)
                            {
                                AddBorderPixels(greenScreenIndex);
                                _greenScreenPixelData[greenScreenIndex] = OpaquePoint;
                            }
                            else
                            {

                                _greenScreenPixelData[greenScreenIndex] = OpaquePoint;
                                _greenScreenPixelData[greenScreenIndex - 1] = OpaquePoint;
                            }
                        }
                    }
                }
            }

            if (_antialiasing)
            {
                Antialiasing();
                //HidePixels();
            }

            // do our processing outside of the using block
            // so that we return resources to the kinect as soon as possible
            // Write the pixel data into our bitmap
            _colorBitmap.WritePixels(
                new Int32Rect(0, 0, _colorBitmap.PixelWidth, _colorBitmap.PixelHeight),
                _colorPixels,
                _colorBitmap.PixelWidth * sizeof(int),
                0);

            if (_playerOpacityMaskImage == null)
            {
                _playerOpacityMaskImage = new WriteableBitmap(
                    _depthWidth,
                    _depthHeight,
                    96,
                    96,
                    PixelFormats.Bgra32,
                    null);
            }

            _playerOpacityMaskImage.WritePixels(
                new Int32Rect(0, 0, _depthWidth, _depthHeight),
                _greenScreenPixelData,
                _depthWidth * ((_playerOpacityMaskImage.Format.BitsPerPixel) / 8),
                0);

            drawingContext.PushOpacityMask(new ImageBrush { ImageSource = _playerOpacityMaskImage});
            drawingContext.DrawImage(_colorBitmap, new Rect(0, 0, ActualWidth, ActualHeight));
        }