/// <summary> /// Called when [render2 d]. /// </summary> /// <param name="time">The time.</param> protected override void OnRender2D(TimeSpan time) { viewportRenderable2D.Clear(); var d2dRoot = Viewport.D2DRenderables.FirstOrDefault(); bool renderD2D = false; if (d2dRoot != null && d2dRoot.Items.Count() > 0 && RenderConfiguration.RenderD2D) { renderD2D = true; d2dRoot.Measure(new Size2F((float)ActualWidth, (float)ActualHeight)); d2dRoot.Arrange(new RectangleF(0, 0, (float)ActualWidth, (float)ActualHeight)); } if (!renderD2D) { return; } viewportRenderable2D.AddRange(Viewport.D2DRenderables); renderer.UpdateSceneGraph2D(RenderContext2D, viewportRenderable2D); for (int i = 0; i < viewportRenderable2D.Count; ++i) { viewportRenderable2D[i].Render(RenderContext2D); } //Draw bitmap cache to render target RenderContext2D.PushRenderTarget(D2DTarget.D2DTarget, false); if (renderD2D || ShowRenderDetail != RenderDetail.None) { for (int i = 0; i < viewportRenderable2D.Count; ++i) { viewportRenderable2D[i].RenderBitmapCache(RenderContext2D); } } RenderContext2D.PopRenderTarget(); }
/// <summary> /// Ensures the bitmap cache. /// </summary> /// <param name="context">The context.</param> /// <param name="size">The size.</param> /// <param name="maxSize">The maximum size.</param> private void EnsureBitmapCache(RenderContext2D context, Size2 size, int maxSize) { IsBitmapCacheValid = false; if (size.Width <= 0 || size.Height <= 0 || !EnableBitmapCache || size.Width * size.Height < MinimumBitmapSize) { Disposer.RemoveAndDispose(ref bitmapCache); } else if (size.Width > maxSize || size.Height > maxSize) { return; } else if (bitmapCache == null || size.Width > bitmapCache.Size.Width || size.Height > bitmapCache.Size.Height) { #if DEBUGCACHECREATE Debug.WriteLine("Create new bitmap cache."); #endif Disposer.RemoveAndDispose(ref bitmapCache); bitmapCache = BitmapProxy.Create("Cache", context.DeviceContext, size, Format.B8G8R8A8_UNorm); IsBitmapCacheValid = true; IsVisualDirty = true; } else { IsBitmapCacheValid = true; } }
protected override void OnRender(RenderContext2D context) { if (isGeometryChanged) { RemoveAndDispose(ref geometry); if (Figures == null || Figures.Count == 0) { return; } geometry = Collect(new D2D.PathGeometry1(context.DeviceResources.Factory2D)); using (var sink = geometry.Open()) { sink.SetFillMode(FillMode); foreach (var figure in Figures) { figure.Create(sink); } sink.Close(); } isGeometryChanged = false; } if (StrokeBrush != null && StrokeWidth > 0 && StrokeStyle != null) { context.DeviceContext.DrawGeometry(geometry, StrokeBrush, StrokeWidth, StrokeStyle); } if (FillBrush != null) { context.DeviceContext.FillGeometry(geometry, FillBrush); } }
/// <summary> /// Renders the specified context. /// </summary> /// <param name="context">The context.</param> public override void Render(RenderContext2D context) { if (CanRender(context)) { context.DeviceContext.Transform = Transform; if (ShowDrawingBorder) { using (var borderBrush = new D2D.SolidColorBrush(context.DeviceContext, Color.Blue)) { using (var borderDotStyle = new D2D.StrokeStyle(context.DeviceContext.Factory, new D2D.StrokeStyleProperties() { DashStyle = D2D.DashStyle.DashDot })) { using (var borderLineStyle = new D2D.StrokeStyle(context.DeviceContext.Factory, new D2D.StrokeStyleProperties() { DashStyle = D2D.DashStyle.Solid })) { context.DeviceContext.DrawRectangle(LayoutBound, borderBrush, 1f, IsMouseOver ? borderLineStyle : borderDotStyle); context.DeviceContext.DrawRectangle(LayoutClippingBound, borderBrush, 0.5f, borderDotStyle); } } } } OnRender(context); } }
/// <summary> /// Gets the secondary scaler value of this Point Light 2D. /// </summary> /// <returns>The second scaler.</returns> public Vector2 GetSecondScaler(RenderContext2D rc) { float sc = (rc.Zoom * rc.ZoomMultiplier); float sc_over_str = sc / Strength; return(new Vector2(sc_over_str, sc_over_str)); }
/// <summary> /// Called when [render]. /// </summary> /// <param name="context">The context.</param> protected override void OnRender(RenderContext2D context) { if (background == null) { Background = new D2D.SolidColorBrush(context.DeviceContext, new Color4(0.8f, 0.8f, 0.8f, 0.6f)); } if (foreground == null) { Foreground = new D2D.SolidColorBrush(context.DeviceContext, Color.Blue); } var str = statistics.GetDetailString(); if (str != previousStr) { previousStr = str; RemoveAndDispose(ref textLayout); textLayout = Collect(new TextLayout(factory, str, format, float.MaxValue, float.MaxValue)); } var metrices = textLayout.Metrics; renderBound.Width = Math.Max(metrices.Width, renderBound.Width); renderBound.Height = metrices.Height; context.DeviceContext.Transform = Matrix3x2.Translation((float)context.ActualWidth - renderBound.Width, 0); context.DeviceContext.FillRectangle(renderBound, background); context.DeviceContext.DrawTextLayout(Vector2.Zero, textLayout, foreground); }
/// <summary> /// Renders a 2D rectangle. /// </summary> /// <param name="rc">The render context.</param> /// <param name="xmin">The lower bounds of the the rectangle: X coordinate.</param> /// <param name="ymin">The lower bounds of the the rectangle: Y coordinate.</param> /// <param name="xmax">The upper bounds of the the rectangle: X coordinate.</param> /// <param name="ymax">The upper bounds of the the rectangle: Y coordinate.</param> /// <param name="rot">The rotation, if any applies.</param> public void RenderRectangle(RenderContext2D rc, float xmin, float ymin, float xmax, float ymax, Vector3?rot = null) { Vector2 scaler = new Vector2(xmax - xmin, ymax - ymin); Vector2 invScaler = new Vector2(1.0f / scaler.X, 1.0f / scaler.Y); Vector2 adder = new Vector2(xmin, ymin); Vector2 tscaler = rc.Scaler * scaler; GL.Uniform3(ShaderLocations.Common2D.SCALER, new Vector3(tscaler.X, tscaler.Y, rc.AspectHelper)); Vector2 tadder = (rc.Adder + adder) * rc.Scaler; GL.Uniform2(ShaderLocations.Common2D.ADDER, tadder); if (rot != null) { GL.Uniform3(ShaderLocations.Common2D.ROTATION, rot.Value); } if (rc.CalcShadows && rc.Engine.OneDLights) { GL.BindVertexArray(SquareOfLines.Internal.VAO); GL.DrawElements(PrimitiveType.LineStrip, 5, DrawElementsType.UnsignedInt, IntPtr.Zero); } else { GL.BindVertexArray(Square.Internal.VAO); GL.DrawElements(PrimitiveType.TriangleStrip, 4, DrawElementsType.UnsignedInt, IntPtr.Zero); } if (rot != null) { GL.Uniform3(ShaderLocations.Common2D.ROTATION, Vector3.Zero); } }
protected override void OnUpdate(RenderContext2D context) { base.OnUpdate(context); if (backgroundChanged) { (SceneNode as ProgressBarNode2D).Background = Background.ToD2DBrush(SceneNode.RenderSize, context.DeviceContext); backgroundChanged = false; } if (fillChanged) { (SceneNode as ProgressBarNode2D).Fill = Fill.ToD2DBrush(SceneNode.RenderSize, context.DeviceContext); fillChanged = false; } if (strokeChanged) { (SceneNode as ProgressBarNode2D).Stroke = Stroke.ToD2DBrush(SceneNode.RenderSize, context.DeviceContext); strokeChanged = false; } if (maximumChanged) { (SceneNode as ProgressBarNode2D).Maximum = Maximum; maximumChanged = false; } if (minimumChanged) { (SceneNode as ProgressBarNode2D).Minimum = Minimum; minimumChanged = false; } if (orientationChanged) { var orientation = Orientation == Orientation.Horizontal ? Model.Scene2D.Orientation.Horizontal : Model.Scene2D.Orientation.Vertical; (SceneNode as ProgressBarNode2D).Orientation = orientation; orientationChanged = false; } }
/// <summary> /// Called when [render]. /// </summary> /// <param name="context">The context.</param> protected virtual void OnRender(RenderContext2D context) { RenderCore.Render(context); for (int i = 0; i < this.Items.Count; ++i) { Items[i].Render(context); } }
/// <summary> /// Called when [render]. /// </summary> /// <param name="context">The context.</param> protected virtual void OnRender(RenderContext2D context) { RenderCore.Render(context); for (var i = 0; i < this.ItemsInternal.Count; ++i) { ItemsInternal[i].Render(context); } }
/// <summary> /// Gets the secondary adder value of this Point Light 2D. /// </summary> /// <returns>The second adder.</returns> public Vector2 GetSecondAdder(RenderContext2D rc) { float one_over_str = 1f / Strength; float adx = (-rc.ViewCenter.X - Position.X) * one_over_str; float ady = (-rc.ViewCenter.Y - Position.Y) * one_over_str * rc.AspectHelper; return(new Vector2(adx, ady)); }
/// <summary> /// Updates the scene graph. /// </summary> /// <param name="context">The context.</param> /// <param name="renderables">The renderables.</param> /// <returns></returns> public void UpdateSceneGraph2D(RenderContext2D context, FastList <SceneNode2D> renderables) { renderables.PreorderDFTRun((x) => { x.Update(context); return(x.IsRenderable); }, stack2DCache1); }
/// <summary> /// <para>Renders the element in the specified context. To override Render, please override <see cref="OnRender"/></para> /// <para>Uses <see cref="CanRender"/> to call OnRender or not. </para> /// </summary> /// <param name="context">The context.</param> public void Render(RenderContext2D context) { if (!IsRenderable) { return; } if (IsTransformDirty) { RelativeMatrix = Matrix3x2.Translation(-RenderSize * RenderTransformOrigin) * ModelMatrix * Matrix3x2.Translation(RenderSize * RenderTransformOrigin) * LayoutTranslate; TotalModelMatrix = RelativeMatrix * ParentMatrix; IsTransformDirty = false; InvalidateVisual(); } LayoutBoundWithTransform = LayoutBound.Translate(TotalModelMatrix.TranslationVector); #if DISABLEBITMAPCACHE IsBitmapCacheValid = false; #else EnsureBitmapCache(context, new Size2((int)Math.Ceiling(LayoutClipBound.Width), (int)Math.Ceiling(LayoutClipBound.Height)), context.DeviceContext.MaximumBitmapSize); #endif if (EnableBitmapCache && IsBitmapCacheValid) { if (IsVisualDirty) { #if DEBUGDRAWING if (logger.IsEnabled(LogLevel.Debug)) { logger.LogDebug("Redraw bitmap cache"); } #endif context.PushRenderTarget(bitmapCache, true); context.DeviceContext.Transform = Matrix3x2.Identity; context.PushRelativeTransform(Matrix3x2.Identity); RenderCore.Transform = context.RelativeTransform; OnRender(context); context.PopRelativeTransform(); context.PopRenderTarget(); IsVisualDirty = false; } if (context.HasTarget) { context.DeviceContext.Transform = context.RelativeTransform * RelativeMatrix; context.DeviceContext.DrawImage(bitmapCache, new Vector2(0, 0), LayoutClipBound, InterpolationMode.Linear, global::SharpDX.Direct2D1.CompositeMode.SourceOver); } } else if (context.HasTarget) { context.PushRelativeTransform(context.RelativeTransform * RelativeMatrix); RenderCore.Transform = context.RelativeTransform; OnRender(context); context.PopRelativeTransform(); IsVisualDirty = false; } }
protected override void OnUpdate(RenderContext2D context) { base.OnUpdate(context); if (SceneNode is ArcNode2D arcNode) { arcNode.Fill = Fill; arcNode.Stroke = Stroke; } }
protected override void OnUpdate(RenderContext2D context) { base.OnUpdate(context); if (_opacityMaskChanged) { (SceneNode as PathNode2D).OpacityMask = OpacityMask.ToD2DBrush(SceneNode.RenderSize, context.DeviceContext); _opacityMaskChanged = false; } }
public override void Update(RenderContext2D context) { base.Update(context); if (bitmapChanged) { LoadBitmap(context, ImageStream); bitmapChanged = false; } }
protected override void OnRender(RenderContext2D context) { if (Background != null) { context.DeviceContext.FillRectangle(LayoutBound, Background); } UpdateTextLayout(); context.DeviceContext.DrawTextLayout(new Vector2(LayoutBound.Left, LayoutBound.Top), textLayout, Foreground, DrawingOptions); }
protected override void OnUpdate(RenderContext2D context) { base.OnUpdate(context); if (strokeChanged) { (SceneNode as BorderNode2D).BorderBrush = BorderBrush.ToD2DBrush(context.DeviceContext); strokeChanged = false; } }
/// <summary> /// Render2s the d. /// </summary> /// <param name="context">The context.</param> /// <param name="renderables">The renderables.</param> /// <param name="parameter">The parameter.</param> public virtual void RenderScene2D(RenderContext2D context, FastList <SceneNode2D> renderables, ref RenderParameter2D parameter) { var count = renderables.Count; for (var i = 0; i < count; ++i) { renderables[i].Render(context); } }
public override void Update(RenderContext2D context) { base.Update(context); if (BitmapChanged) { LoadBitmap(context, ImageStream); InvalidateMeasure(); InvalidateArrange(); BitmapChanged = false; } }
protected override void OnRender(RenderContext2D context) { if (FillBrush != null) { context.DeviceContext.FillRectangle(LayoutBound, FillBrush); } if (StrokeBrush != null && StrokeStyle != null) { context.DeviceContext.DrawRectangle(LayoutBound, StrokeBrush, StrokeWidth, StrokeStyle); } }
/// <summary> /// Renders the bitmap cache to a render target only. /// </summary> /// <param name="context">The context.</param> public void RenderBitmapCache(RenderContext2D context) { if (IsRenderable && EnableBitmapCache && IsBitmapCacheValid && !IsVisualDirty && context.HasTarget) { context.DeviceContext.Transform = RelativeMatrix; context.DeviceContext.DrawImage(bitmapCache, new Vector2(0, 0), new RectangleF(0, 0, RenderSize.X, RenderSize.Y), InterpolationMode.Linear, global::SharpDX.Direct2D1.CompositeMode.SourceOver); } else { Render(context); } }
protected override void OnUpdate(RenderContext2D context) { base.OnUpdate(context); if (foregroundChanged) { (SceneNode as TextNode2D).Foreground = Foreground?.ToD2DBrush(SceneNode.RenderSize, context.DeviceContext); foregroundChanged = false; } if (backgroundChanged) { (SceneNode as TextNode2D).Background = Background?.ToD2DBrush(SceneNode.RenderSize, context.DeviceContext); backgroundChanged = false; } }
protected override void OnUpdate(RenderContext2D context) { base.OnUpdate(context); if (fillChanged) { (SceneNode as ShapeNode2D).Fill = Fill.ToD2DBrush(SceneNode.RenderSize, context.DeviceContext); fillChanged = false; } if (strokeChanged) { (SceneNode as ShapeNode2D).Stroke = Stroke.ToD2DBrush(SceneNode.RenderSize, context.DeviceContext); strokeChanged = false; } }
/// <summary> /// Called when [render]. /// </summary> /// <param name="context">The context.</param> protected override void OnRender(RenderContext2D context) { ellipse.Point = LayoutBound.Center; ellipse.RadiusX = LayoutBound.Width / 2; ellipse.RadiusY = LayoutBound.Height / 2; if (FillBrush != null) { context.DeviceContext.FillEllipse(ellipse, FillBrush); } if (StrokeBrush != null && StrokeStyle != null) { context.DeviceContext.DrawEllipse(ellipse, StrokeBrush, StrokeWidth, StrokeStyle); } }
/// <summary> /// Render the entity as seen normally, in 2D. /// </summary> /// <param name="context">The render context.</param> public override void RenderStandard2D(RenderContext2D context) { if (context.CalcShadows && context.Engine.OneDLights) { context.Engine.Textures.White.Bind(); } else { CircleTexture.Bind(); } context.Engine.RenderHelper.SetColor(BoxColor); context.Engine.RenderHelper.RenderRectangle(context, (float)RenderAt.X - Radius, (float)RenderAt.Y + Radius, (float)RenderAt.X + Radius, (float)RenderAt.Y - Radius); }
/// <summary> /// Render the entity as seen normally, in 2D. /// </summary> /// <param name="context">The render context.</param> public override void RenderStandard2D(RenderContext2D context) { if (context.CalcShadows && context.Engine.OneDLights) { context.Engine.Textures.White.Bind(); } else { BoxTexture.Bind(); } context.Engine.RenderHelper.SetColor(BoxColor); Vector2 sz = BoxSize; context.Engine.RenderHelper.RenderRectangle(context, (float)RenderAt.X + BoxUpLeft.X, (float)RenderAt.Y + BoxUpLeft.Y, (float)RenderAt.X + BoxDownRight.X, (float)RenderAt.Y + BoxDownRight.Y, new Vector3(BoxUpLeft.X / sz.X, BoxDownRight.Y / sz.Y, RenderAngle)); }
protected virtual Bitmap OnLoadImage(RenderContext2D context, Stream stream) { stream.Position = 0; using (var decoder = new BitmapDecoder(context.DeviceResources.WICImgFactory, stream, DecodeOptions.CacheOnLoad)) { using (var frame = decoder.GetFrame(0)) { using (var converter = new FormatConverter(context.DeviceResources.WICImgFactory)) { converter.Initialize(frame, global::SharpDX.WIC.PixelFormat.Format32bppPBGRA); return(Bitmap1.FromWicBitmap(context.DeviceContext, converter)); } } } }
protected override void OnUpdate(RenderContext2D context) { base.OnUpdate(context); if (foregroundChanged) { (SceneNode as FrameStatisticsNode2D).Foreground = Foreground != null?Foreground.ToD2DBrush(context.DeviceContext) : null; foregroundChanged = false; } if (backgroundChanged) { (SceneNode as FrameStatisticsNode2D).Background = Background != null?Background.ToD2DBrush(context.DeviceContext) : null; backgroundChanged = false; } }
public override void Update(RenderContext2D context) { base.Update(context); if (strokeStyleChanged) { (RenderCore as BorderRenderCore2D).StrokeStyle = new StrokeStyle(context.DeviceResources.Factory2D, new StrokeStyleProperties() { DashCap = StrokeDashCap, StartCap = StrokeStartLineCap, EndCap = StrokeEndLineCap, DashOffset = StrokeDashOffset, LineJoin = StrokeLineJoin, MiterLimit = Math.Max(1, StrokeMiterLimit), DashStyle = StrokeDashStyle }); strokeStyleChanged = false; } }