public VisualElement(RectangleF area) { long ticks = stopWatch.ElapsedTicks; if (ticks <= m_lastTicks) ticks = m_lastTicks+1; m_random = new Random((int)ticks); m_lastTicks = ticks; m_originalPos = new PointF(area.Location.X, area.Location.Y); m_location = area; m_animationStep = m_random.Next(0, 40); float r = m_random.Next(90, 100) / 100f; float g = m_random.Next(90, 100) / 100f; float b = m_random.Next(90, 100) / 100f; //Color = new Color4(1, r, g, b); Color = new Color4(1, 1, 1, 1); m_currentPos = new PointF(m_originalPos.X, m_originalPos.Y); }
public RectangleF GetBounds() { var bounds = new RectangleF(Center.X - (RadiusX), Center.Y - (RadiusY), RadiusX * 2, RadiusY * 2); return bounds; }
/// <summary> /// Internal method to get the transform relative to a bounding box /// </summary> /// <param name="bounds">The bounding box to transform relative to</param> /// <returns>A transform that is relative to a bounding box</returns> internal override Matrix3x2 GetTransformRelative(RectangleF bounds) { /* Find the relative center on the X axis */ float centerX = bounds.X + (CenterX * bounds.Width); /* Find the relative center on the Y axis */ float centerY = bounds.Y + (CenterY * bounds.Height); /* Create the skew transform */ return Matrix3x2.Skew(AngleX, AngleY, new PointF(centerX, centerY)); }
/// <summary> /// Internal method to get the transform relative to a bounding box /// </summary> /// <param name="bounds">The bounding box to transform relative to</param> /// <returns>A transform that is relative to a bounding box</returns> internal override Matrix3x2 GetTransformRelative(RectangleF bounds) { /* Find the relative center on the X axis */ float centerX = bounds.X + (X * bounds.Width); /* Find the relative center on the Y axis */ float centerY = bounds.Y + (Y * bounds.Height); /* Create the translation transform matrix */ var transform = Matrix3x2.Translation(centerX, centerY); return transform; }
/// <summary> /// Internal method to get the transform relative to a bounding box /// </summary> /// <param name="bounds">The bounding box to transform relative to</param> /// <returns>A transform that is relative to a bounding box</returns> internal override Matrix3x2 GetTransformRelative(RectangleF bounds) { var xform = Matrix3x2.Identity; /* Loop over all of our child transforms */ for (int i = 0; i < m_transformChildren.Count; i++) { var transform = m_transformChildren[i].GetTransformRelative(bounds); /* Multiple the transforms together */ xform *= transform; } /* Return the composite result */ return xform; }
/// <summary> /// Internal method to get the transform relative to a bounding box /// </summary> /// <param name="bounds">The bounding box to transform relative to</param> /// <returns>A transform that is relative to a bounding box</returns> internal override Matrix3x2 GetTransformRelative(RectangleF bounds) { /* Get the relative scale on the X axis */ float scaleX = bounds.Width*ScaleX; /* Get the relative scale on the Y axis */ float scaleY = bounds.Height*ScaleY; /* Find the relative center on the X axis */ float centerX = bounds.X + (CenterX * bounds.Width); /* Find the relative center on the Y axis */ float centerY = bounds.Y + (CenterY * bounds.Height); /* Create the translation */ var transform = Matrix3x2.Translation(centerX, centerY); /* Multiply our last transform by the scale */ transform *= Matrix3x2.Scale(scaleX, scaleY); return transform; }
/// <summary> /// Composes a DrawingLayer with another DrawingLayer. /// This allows for things like scaling, blending, 2D and 3D transformations /// </summary> /// <param name="layer">The DrawingLayer that is used as the input</param> /// <param name="sourceArea">The area over the input DrawingLayer</param> /// <param name="destinationArea">The output area to draw the source area</param> /// <param name="rotationTransform">The rotation parameters</param> /// <param name="tint">The color to tint the source layer on to the output</param> public void ComposeDrawingLayer(DrawingLayer layer, ref RectangleF sourceArea, ref RectangleF destinationArea, ref RotationParameters rotationTransform, ref Color4 tint) { m_drawStateManagement.DrawPreamble(); /* Get the current draw data to fill. We avoid creating new object instances * for the GC to have to delete */ var spriteRenderData = m_spriteRenderer.GetCurrentRenderData(); /* Copy all the primitive transform data to the spriteRenderData */ float xDestination = destinationArea.X; float yDestination = destinationArea.Y; spriteRenderData.drawData.Translation.X = xDestination; spriteRenderData.drawData.Translation.Y = yDestination; spriteRenderData.drawData.Rotate.X = rotationTransform.RotateX; spriteRenderData.drawData.Rotate.Y = rotationTransform.RotateY; spriteRenderData.drawData.Rotate.Z = rotationTransform.RotateZ; spriteRenderData.drawData.Scale.X = destinationArea.Width / sourceArea.Width; spriteRenderData.drawData.Scale.Y = destinationArea.Height / sourceArea.Height; spriteRenderData.drawData.DrawRect.X = sourceArea.X; spriteRenderData.drawData.DrawRect.Y = sourceArea.Y; spriteRenderData.drawData.DrawRect.Z = sourceArea.Width; spriteRenderData.drawData.DrawRect.W = sourceArea.Height; spriteRenderData.drawData.RotationCenter = rotationTransform.RotationCenter.InternalVector2; spriteRenderData.drawData.Color = tint.InternalColor4; spriteRenderData.texture = layer.RenderTargetTexture; /* Add (queue) the drawing data to the sprite renderer */ m_spriteRenderer.AddRenderData(spriteRenderData); }
static RectangleF() { m_empty = new RectangleF(); }
internal RectangleF GetBounds() { var bounds = new RectangleF(); bounds.X = Left; bounds.Y = Top; bounds.Width = Right - Left; bounds.Height = Bottom - Top; return bounds; }
public void DrawRectangle(Brush brush, RectangleF rect, float strokeWidth, GeneralTransform transform) { var matrixTransform = transform.GetTransform(); DrawRectangle(brush, rect, strokeWidth, Matrix3x2.Identity, matrixTransform); }
public void DrawText(Brush brush, string text, float x, float y, float fontSize) { m_drawStateManagement.DrawPreamble(); if (m_directWriteFactory == null) { m_directWriteFactory = new Factory(FactoryType.Isolated); } if (m_textFormat == null || m_textFormat.FontSize != fontSize) { m_textFormat = new TextFormat(m_directWriteFactory, "Segoe UI", FontWeight.Bold, FontStyle.Normal, FontStretch.Normal, fontSize, ""); } PushState(); //var area2 = new RectangleF(0, 0, , ); if (x > Width - 1 || y > Height - 1) return; var area = new RectangleF(x, y, Width, Height); var matrix = Matrix3x2.Identity; BrushHelper.PrepareBrush(brush, this, area, matrix, Matrix3x2.Identity); D2DRenderTarget.InternalRenderTarget.DrawText(text, m_textFormat, area.InternalRectangleF, brush.InternalBrush); PopState(); }
/// <summary> /// Composes a DrawingLayer with another DrawingLayer. /// This allows for things like scaling, blending, 2D and 3D transformations /// </summary> /// <param name="layer">The DrawingLayer that is used as the input</param> /// <param name="sourceArea">The area over the input DrawingLayer</param> /// <param name="destinationArea">The output area to draw the source area</param> /// <param name="rotationTransform">The rotation parameters</param> /// <param name="tint">The color to tint the source layer on to the output</param> public void ComposeDrawingLayer(DrawingLayer layer, RectangleF sourceArea, RectangleF destinationArea, RotationParameters rotationTransform, Color4 tint) { ComposeDrawingLayer(layer, ref sourceArea, ref destinationArea, ref rotationTransform, ref tint); }
/// <summary> /// Composes a DrawingLayer with another DrawingLayer. /// This allows for things like scaling, blending, 2D and 3D transformations /// </summary> /// <param name="layer">The DrawingLayer that is used as the input</param> /// <param name="sourceArea">The area over the input DrawingLayer</param> /// <param name="destinationArea">The output area to draw the source area</param> /// <param name="rotationTransform">The rotation parameters</param> /// <param name="tint">The color to tint the source layer on to the output</param> public void ComposeLayer(DrawingLayer layer, RectangleF sourceArea, RectangleF destinationArea, RotationParameters rotationTransform, Color4 tint) { m_directCanvasFactory.Compose(layer, sourceArea, destinationArea, rotationTransform, tint); }
static public void PrepareBrush(Brush brush, DrawingLayer drawingLayer, RectangleF bounds, Matrix3x2 localTransform, Matrix3x2 worldTransform) { var alignment = brush.Alignment; var brushSize = brush.BrushSize; Matrix3x2 currentBrushTransform = Matrix3x2.Identity; if (brush.Transform != null) { switch (alignment) { case BrushAlignment.DrawingLayerAbsolute: currentBrushTransform = brush.Transform.GetTransform(); break; case BrushAlignment.DrawingLayerRelative: currentBrushTransform = brush.Transform.GetTransformRelative(new RectangleF(0,0, drawingLayer.Width, drawingLayer.Height)); break; case BrushAlignment.GeometryAbsolute: currentBrushTransform = brush.Transform.GetTransform(); break; case BrushAlignment.GeometryRelative: currentBrushTransform = brush.Transform.GetTransformRelative(bounds); break; default: throw new ArgumentOutOfRangeException(); } } switch (alignment) { case BrushAlignment.DrawingLayerAbsolute: brush.InternalBrush.Transform = currentBrushTransform * Matrix3x2.Invert(worldTransform); break; case BrushAlignment.DrawingLayerRelative: { var scaleMatrix = Matrix3x2.Scale(drawingLayer.Width / brushSize.Width, drawingLayer.Height / brushSize.Height); brush.InternalBrush.Transform = scaleMatrix * currentBrushTransform * Matrix3x2.Invert(worldTransform); } break; case BrushAlignment.GeometryAbsolute: { var translate = Matrix3x2.Translation(bounds.InternalRectangleF.Location); brush.InternalBrush.Transform = translate * localTransform * currentBrushTransform; } break; case BrushAlignment.GeometryRelative: { var scaleMatrix = Matrix3x2.Scale(bounds.Width / brushSize.Width, bounds.Height / brushSize.Height); var translate = Matrix3x2.Translation(bounds.InternalRectangleF.Location); brush.InternalBrush.Transform = scaleMatrix * translate * localTransform * currentBrushTransform; } break; default: throw new ArgumentOutOfRangeException(); } }
private void UpdateScreenVisualization(Dictionary<int, MotionTrackingDevice> devices, MotionTrackingScreen screen, WPFPresenter handPresenter) { handPresenter.Clear(); edgeEffect.Tint = new Color4(1, 1, 0, 0); edgeEffect.MinThreshold = 300f; edgeEffect.MaxThreshold = 10000f; edgeEffect.EdgeThreshold = 100f; edgeEffect.TexSize = new Size(intermediateLayer.Width, intermediateLayer.Height); foreach (var innerkvp in devices) { var session = innerkvp.Value.Session; var rectf = new RectangleF((float)(session.PositionProjective.X - 100), (float)(session.PositionProjective.Y - 100), 200, 200); if (!screen.IsSessionInBounds(session)) { continue; } var p = screen.MapPositionToScreen(session, handPresenter.Width, handPresenter.Height); var targetRectf = new RectangleF((float)(p.X - 100), (float)(p.Y - 100), 200, 200); if (innerkvp.Value.ShouldPromoteToTouch) thresholdEffect.Tint = new Color4(.8f, 0, 0, 0); else thresholdEffect.Tint = new Color4(.4f, 0, 0, 0); thresholdEffect.MinThreshold = (float)(session.PositionProjective.Z - 100); thresholdEffect.MaxThreshold = (float)(session.PositionProjective.Z + 100); rawDepthLayer.ApplyEffect(thresholdEffect, intermediateLayer, true); //intermediateLayer.ApplyEffect(unpackEffect, effectLayer, true); //handPresenter.BeginDraw(); //if (session.IsPromotedToTouch) //handPresenter.FillEllipse(contactBrush, new DirectCanvas.Shapes.Ellipse(new PointF((float)p.X, (float)p.Y), 20, 20)); //else // handPresenter.FillEllipse(hoverBrush, new DirectCanvas.Shapes.Ellipse(new PointF((float)p.X, (float)p.Y), 20, 20)); //handPresenter.EndDraw(); var tint = new Color4(1, 1, 1, 1); //if (innerkvp.Value.ShouldPromoteToTouch) //{ // tint.Alpha = 0.8f; //} handPresenter.BeginCompose(); handPresenter.ComposeLayer(intermediateLayer, rectf, targetRectf, new RotationParameters(), tint); handPresenter.EndCompose(); } handPresenter.Present(); }
/// <summary> /// Fills an opacity mask on the DrawingLayer /// </summary> /// <param name="brush">The brush containing the content to fill</param> /// <param name="mask">The opacity mask</param> /// <param name="sourceRect">The source rectangle to use</param> /// <param name="destinationRect">The destination rectangle to use</param> public void FillOpacityMask(Brush brush, DrawingLayer mask, RectangleF destinationRect, RectangleF sourceRect) { FillOpacityMaskInternal(brush, mask.D2DRenderTarget.InternalBitmap, destinationRect, sourceRect); }
/// <summary> /// Fills an opacity mask on the DrawingLayer /// </summary> /// <param name="brush">The brush containing the content to fill</param> /// <param name="mask">The opacity mask</param> /// <param name="sourceRect">The source rectangle to use</param> /// <param name="destinationRect">The destination rectangle to use</param> private void FillOpacityMaskInternal(Brush brush, SlimDX.Direct2D.Bitmap mask, RectangleF destinationRect, RectangleF sourceRect) { m_drawStateManagement.DrawPreamble(); /* Save our state */ PushState(); /* Prepare our brush to be used */ BrushHelper.PrepareBrush(brush, this, destinationRect, Matrix3x2.Identity, Matrix3x2.Identity); D2DRenderTarget.InternalRenderTarget.AntialiasMode = AntialiasMode.Aliased; D2DRenderTarget.InternalRenderTarget.FillOpacityMask(mask, brush.InternalBrush, OpacityMaskContent.Graphics, sourceRect.InternalRectangleF, destinationRect.InternalRectangleF); /* Restore our state */ PopState(); }
/// <summary> /// Draws a DrawingLayer on to another DrawingLayer /// </summary> /// <param name="drawingLayer">The DrawingLayer to draw</param> /// <param name="destinationRectangle">The destination rectangle</param> public void DrawLayer(DrawingLayer drawingLayer, RectangleF destinationRectangle) { m_drawStateManagement.DrawPreamble(); D2DRenderTarget.InternalRenderTarget.DrawBitmap(drawingLayer.D2DRenderTarget.InternalBitmap, destinationRectangle.InternalRectangleF, 1.0f, InterpolationMode.Linear); }
/// <summary> /// Draws a DrawingLayer on to another DrawingLayer /// </summary> /// <param name="drawingLayer">The DrawingLayer to draw</param> /// <param name="destinationRectangle">The destination rectangle</param> /// <param name="sourceRectangle">The source rectangle</param> /// <param name="opacity">The transparency level, 0 - 1</param> public void DrawLayer(DrawingLayer drawingLayer, RectangleF destinationRectangle, RectangleF sourceRectangle, float opacity) { m_drawStateManagement.DrawPreamble(); D2DRenderTarget.InternalRenderTarget.DrawBitmap(drawingLayer.D2DRenderTarget.InternalBitmap, destinationRectangle.InternalRectangleF, opacity, InterpolationMode.Linear, sourceRectangle.InternalRectangleF); }
/// <summary> /// Draws a MediaPlayer's video on to the DrawingLayer /// </summary> /// <param name="player">The MediaPlayer to draw</param> /// <param name="destinationRectangle">The destination rectangle</param> /// <param name="opacity">The transparency level, 0 - 1</param> public void DrawMediaPlayer(MediaPlayer player, RectangleF destinationRectangle, float opacity) { m_drawStateManagement.DrawPreamble(); if (player.InternalBitmap == null) return; D2DRenderTarget.InternalRenderTarget.DrawBitmap(player.InternalBitmap, destinationRectangle.InternalRectangleF, opacity, InterpolationMode.Linear); }
public RectangleF GetBoundsInverted() { var bounds = SlimDX.Direct2D.Geometry.GetBounds(GetCurrentGeometry(), Matrix3x2.Invert(GetCurrentTransform())); var ret = new RectangleF(bounds.X, bounds.Y, bounds.Width, bounds.Height); return ret; }
public bool Equals(RectangleF other) { return other.X.Equals(X) && other.Y.Equals(Y) && other.Width.Equals(Width) && other.Height.Equals(Height) && other.InternalRectangleF.Equals(InternalRectangleF); }
public RectangleF GetBoundsTransformed() { var bounds = SlimDX.Direct2D.Geometry.GetBounds(GetCurrentGeometry()); var ret = new RectangleF(bounds.X, bounds.Y, bounds.Width, bounds.Height); return ret; }
private void DrawRectangle(Brush brush, RectangleF rect, float strokeWidth, Matrix3x2 localTransform, Matrix3x2 worldTransform) { m_drawStateManagement.DrawPreamble(); /* Save our state */ PushState(); /* Set our D2D render target to use the transform */ D2DRenderTarget.InternalRenderTarget.Transform = worldTransform; /* Prepare our brush to be used */ BrushHelper.PrepareBrush(brush, this, rect, localTransform, worldTransform); D2DRenderTarget.InternalRenderTarget.DrawRectangle(brush.InternalBrush, rect.InternalRectangleF, strokeWidth); /* Restore our state */ PopState(); }
private DrawingLayer CreateOpacityMaskTemplate() { /* This is a temporary drawing layer that we will draw just a single shape to * but we will tile it with a bitmap brush on to the opacityMaskLayer */ var opacityMaskTemplateLayer = m_presenter.Factory.CreateDrawingLayer(COMPOSITED_ELEMENT_WIDTH, COMPOSITED_ELEMENT_HEIGHT); /* The brush we will use to fill a single shape on our template layer */ var solidColorBrush = m_presenter.Factory.CreateSolidColorBrush(new Color4(1, 1, 1, 1)); var shapeArea = new RectangleF(0, 0, COMPOSITED_ELEMENT_WIDTH, COMPOSITED_ELEMENT_HEIGHT); /* Queue the drawing */ opacityMaskTemplateLayer.BeginDraw(); opacityMaskTemplateLayer.FillEllipse(solidColorBrush, new Ellipse(shapeArea.Center, shapeArea.Width / 3, shapeArea.Height / 3)); /* Flush the drawing commands */ opacityMaskTemplateLayer.EndDraw(); solidColorBrush.Dispose(); return opacityMaskTemplateLayer; }
public void DrawRectangle(Brush brush, RectangleF rect, float strokeWidth) { DrawRectangle(brush, rect, strokeWidth, Matrix3x2.Identity, Matrix3x2.Identity); }
/// <summary> /// Fills a rectangle on the DrawingLayer with the given brush /// </summary> /// <param name="brush">The brush to fill</param> /// <param name="rectangle">The rectangle area</param> public void FillRectangle(Brush brush, RectangleF rectangle) { FillRectangle(brush, rectangle, Matrix3x2.Identity, Matrix3x2.Identity); }
protected override void DrawLayer(DrawingLayer outputLayer) { base.DrawLayer(outputLayer); DepthFrame.MinThreshold = (ushort)this.MinThreshold; DepthFrame.MaxThreshold = (ushort)this.MaxThreshold; ushort minValue; ushort maxValue; var img = DepthFrame.ToDirectCanvasImage(Factory, out minValue, out maxValue); effectLayer.CopyFromImage(img); Rect crop = DepthFrame.Crop; Rectangle rect = new Rectangle((int)crop.X, (int)crop.Y, (int)crop.Width, (int)crop.Height); RectangleF rectf = new RectangleF((float)crop.X, (float)crop.Y, (float)crop.Width, (float)crop.Height); colorMapEffect.MinThreshold = (float)MinThreshold; colorMapEffect.MaxThreshold = (float)MaxThreshold; colorMapEffect.MinValue = minValue; colorMapEffect.MaxValue = maxValue; unpackEffect.TexSize = new DirectCanvas.Misc.Size(effectLayer.Width, effectLayer.Height); effectLayer.ApplyEffect(unpackEffect, effectLayer2, true); effectLayer2.ApplyEffect(colorMapEffect, outputLayer, true); outputLayer.BeginDraw(); outputLayer.DrawRectangle(rectBrushBackground, rectf, 3f); outputLayer.DrawRectangle(rectBrushForeground, rectf, 1f); outputLayer.EndDraw(); }
private void InitD3DImage(int width, int height) { if (Application.Current == null || Application.Current.Dispatcher == null) return; var dispatcher = Application.Current.Dispatcher; if (!dispatcher.CheckAccess()) { dispatcher.Invoke((Action)delegate { InitD3DImage(width, height); }); return; } ReleaseResources(); m_width = width; m_height = height; rect = new RectangleF(0, 0, m_width, m_height); intRect = new Int32Rect(0, 0, m_width, m_height); if (m_d3dImage == null) { m_d3dImage = new D3DImageSlimDX(); m_d3dImage.IsFrontBufferAvailableChanged += OnIsFrontBufferAvailableChanged; } m_layer1 = new DrawingLayer(Factory, width, height, SlimDX.DXGI.Format.B8G8R8A8_UNorm, ResourceOptionFlags.Shared); m_layer2 = new DrawingLayer(Factory, width, height, SlimDX.DXGI.Format.B8G8R8A8_UNorm, ResourceOptionFlags.Shared); SetBackBuffer(); }
/// <summary> /// Fills a rectangle on the DrawingLayer with the given brush /// </summary> /// <param name="brush">The brush to fill</param> /// <param name="rectangle">The rectangle area</param> /// <param name="transform">The transformation to apply to the rectangle</param> public void FillRectangle(Brush brush, RectangleF rectangle, GeneralTransform transform) { var localTransform = transform.GetTransform(); FillRectangle(brush, rectangle, Matrix3x2.Identity, localTransform); }