public override void Render(IGameContext gameContext, IRenderContext renderContext)
 {
     if (renderContext.IsFirstRenderPass())
     {
         renderContext.AppendTransientRenderPass(_renderPass);
     }
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="HtmlReportWriter"/> class.
 /// </summary>
 /// <param name="stream">
 /// The stream.
 /// </param>
 /// <param name="textMeasurer">
 /// The text measurer.
 /// </param>
 public HtmlReportWriter(Stream stream, IRenderContext textMeasurer = null)
     : base(stream)
 {
     this.textMeasurer = textMeasurer;
     this.WriteHtmlElement();
     this.PlotElementType = HtmlPlotElementType.Svg;
 }
예제 #3
0
 public Dof(IRenderContext renderContext)
     : base(renderContext)
 {
     depthMapFormat = DefaultDepthMapFormat;
     Settings = DofSettings.Default;
     cameraFrustum = new BoundingFrustum(Matrix.Identity);
 }
        public Response RenderView(ViewLocationResult viewLocationResult, dynamic model, IRenderContext renderContext)
        {
            var response = new HtmlResponse();

            var html = renderContext.ViewCache.GetOrAdd(viewLocationResult, result =>
                                                                                {
                                                                                    string markDown =
                                                                                        viewLocationResult.Contents()
                                                                                                          .ReadToEnd();


                                                                                    var parser = new Markdown();
                                                                                    return parser.Transform(markDown);
                                                                                });


            var serverHtml = ParagraphSubstitution.Replace(html, "$1");

            var renderHtml = this.engineWrapper.Render(serverHtml, model, new MarkdownViewEngineHost(new NancyViewEngineHost(renderContext), renderContext));

            response.Contents = stream =>
            {
                var writer = new StreamWriter(stream);
                writer.Write(renderHtml);
                writer.Flush();
            };

            return response;
        }
예제 #5
0
        public RazorViewEngineFixture()
        {
            this.configuration = A.Fake<IRazorConfiguration>();
            this.engine = new RazorViewEngine(this.configuration);

            var cache = A.Fake<IViewCache>();
            A.CallTo(() => cache.GetOrAdd(A<ViewLocationResult>.Ignored, A<Func<ViewLocationResult, Func<NancyRazorViewBase>>>.Ignored))
                .ReturnsLazily(x =>
                {
                    var result = x.GetArgument<ViewLocationResult>(0);
                    return x.GetArgument<Func<ViewLocationResult, Func<NancyRazorViewBase>>>(1).Invoke(result);
                });

            this.renderContext = A.Fake<IRenderContext>();
            A.CallTo(() => this.renderContext.ViewCache).Returns(cache);
            A.CallTo(() => this.renderContext.LocateView(A<string>.Ignored, A<object>.Ignored))
                .ReturnsLazily(x =>
                {
                    var viewName = x.GetArgument<string>(0);
                    return FindView(viewName); ;
                });

            this.rootPathProvider = A.Fake<IRootPathProvider>();
            A.CallTo(() => this.rootPathProvider.GetRootPath()).Returns(Path.Combine(Environment.CurrentDirectory, "TestViews"));

            this.fileSystemViewLocationProvider = new FileSystemViewLocationProvider(this.rootPathProvider, new DefaultFileSystemReader());
        }
예제 #6
0
        public RazorViewEngineFixture()
        {
            var environment = new DefaultNancyEnvironment();
            environment.Tracing(
                enabled: true,
                displayErrorTraces: true);

            this.configuration = A.Fake<IRazorConfiguration>();
            this.engine = new RazorViewEngine(this.configuration, environment);

            var cache = A.Fake<IViewCache>();
            A.CallTo(() => cache.GetOrAdd(A<ViewLocationResult>.Ignored, A<Func<ViewLocationResult, Func<INancyRazorView>>>.Ignored))
                .ReturnsLazily(x =>
                {
                    var result = x.GetArgument<ViewLocationResult>(0);
                    return x.GetArgument<Func<ViewLocationResult, Func<INancyRazorView>>>(1).Invoke(result);
                });

            this.renderContext = A.Fake<IRenderContext>();
            A.CallTo(() => this.renderContext.ViewCache).Returns(cache);
            A.CallTo(() => this.renderContext.LocateView(A<string>.Ignored, A<object>.Ignored))
                .ReturnsLazily(x =>
                {
                    var viewName = x.GetArgument<string>(0);
                    return FindView(viewName);
                });

            this.rootPathProvider = A.Fake<IRootPathProvider>();
            A.CallTo(() => this.rootPathProvider.GetRootPath()).Returns(Path.Combine(Environment.CurrentDirectory, "TestViews"));

            this.fileSystemViewLocationProvider = new FileSystemViewLocationProvider(this.rootPathProvider, new DefaultFileSystemReader());

            AppDomainAssemblyTypeScanner.AddAssembliesToScan("Nancy.ViewEngines.Razor.Tests.Models.dll");
        }
예제 #7
0
        /// <summary>
        /// Renders the view.
        /// </summary>
        /// <param name="viewLocationResult">A <see cref="ViewLocationResult"/> instance, containing information on how to get the view template.</param>
        /// <param name="model">The model that should be passed into the view</param>
        /// <param name="renderContext"></param>
        /// <returns>A delegate that can be invoked with the <see cref="Stream"/> that the view should be rendered to.</returns>
        public Action<Stream> RenderView(ViewLocationResult viewLocationResult, dynamic model, IRenderContext renderContext)
        {
            return stream =>{

                var templateManagerProvider =
                    new TemplateManagerProvider()
                        .WithLoader(new TemplateLoader(viewLocationResult.Contents.Invoke()));

                var templateManager =
                    templateManagerProvider.GetNewManager();

                var template = renderContext.ViewCache.GetOrAdd(
                    viewLocationResult,
                    x => templateManager.GetTemplate(string.Empty));

                var context = new Dictionary<string, object> { { "Model", model } };
                var reader = template.Walk(templateManager, context);

                var writer =
                    new StreamWriter(stream);

                writer.Write(reader.ReadToEnd());
                writer.Flush();
            };
        }
예제 #8
0
        public Response RenderView(ViewLocationResult viewLocationResult, dynamic model, IRenderContext renderContext)
        {
            var template = renderContext.ViewCache.GetOrAdd(viewLocationResult, result =>
            {
                try
                {
                    var context = new NancyVeilContext(renderContext, Extensions);
                    var engine = new VeilEngine(context);
                    Type modelType = model == null ? typeof(object) : model.GetType();
                    return engine.CompileNonGeneric(viewLocationResult.Extension, result.Contents(), modelType);
                }
                catch (Exception e)
                {
                    return CreateErrorPage(e);
                }
            });

            var response = new HtmlResponse();
            response.ContentType = "text/html; charset=utf-8";
            response.Contents = s =>
            {
                var writer = new StreamWriter(s, Encoding.UTF8);
                template(writer, model);
                writer.Flush();
            };
            return response;
        }
예제 #9
0
        public override void Render(IGameContext gameContext, IRenderContext renderContext)
        {
            base.Render(gameContext, renderContext);

            // For each of the chunk AIs, process them.  It's not ideal to have this in
            // the Render() call, but some AIs need access to the render context so that
            // they can do bounding frustum checks to find out what's on screen.
            using (this.m_Profiler.Measure("tychaia-chunk_ai"))
            {
                foreach (var ai in this.m_ChunkAI)
                {
                    var result = ai.Process(this.m_World, this, gameContext, renderContext);
                    if (result != null)
                    {
                        this.m_ChunksToRenderNext = result;
                    }
                }
            }

            // Find the chunk that belongs at this position.
            using (this.m_Profiler.Measure("tychaia-chunk_render"))
            {
                foreach (var chunk in this.m_ChunksToRenderNext)
                {
                    if (chunk != null)
                    {
                        this.m_ChunkRenderer.Render(renderContext, chunk);
                    }
                }
            }
        }
        public void Render(IGameContext gameContext, IRenderContext renderContext, Rectangle rectangle)
        {
            if (!_networkEngine.GetRecentFrames().Any())
            {
                return;
            }

            var recent = _networkEngine.GetRecentFrames().Last();

            _sentSampler.Sample(
                recent.BytesSentByMessageType,
                recent.MessagesSentByMessageType,
                rectangle.Width);

            _receivedSampler.Sample(
                recent.BytesReceivedByMessageType,
                recent.MessagesReceivedByMessageType,
                rectangle.Width);
            
            _sentSampler.Render(
                renderContext,
                new Rectangle(
                    rectangle.X,
                    rectangle.Y,
                    rectangle.Width,
                    _sentSampler.Height));

            _receivedSampler.Render(
                renderContext,
                new Rectangle(
                    rectangle.X,
                    rectangle.Y + _sentSampler.Height,
                    rectangle.Width,
                    _receivedSampler.Height));
        }
예제 #11
0
        private void DXControlBase_Load(object sender, EventArgs e)
        {
            if (DesignMode) return;

            this.Disposed += DXControlBase_Disposed;
            context = new RenderContext(DeviceManager.Instance, this);
        }
 public SingleScreenSpaceShadow(IRenderContext context)
     : base(context)
 {
     lspsmLightCamera = new LspsmLightCamera();
     lightCameraFrustum = new BoundingFrustum(Matrix.Identity);
     shadowCasters = new List<Actor>();
 }
        public override void Render(IGameContext gameContext, IRenderContext renderContext)
        {
            base.Render(gameContext, renderContext);

            if (renderContext.IsCurrentRenderPass<I2DDirectRenderPass>())
            {
                if (_analyzerEntity.TopLeftNormalized != null && _analyzerEntity.TopRightNormalized != null &&
                    _analyzerEntity.BottomLeftNormalized != null && _analyzerEntity.BottomRightNormalized != null)
                {
                    _cachedTopLeft = _analyzerEntity.TopLeftNormalized;
                    _cachedTopRight = _analyzerEntity.TopRightNormalized;
                    _cachedBottomLeft = _analyzerEntity.BottomLeftNormalized;
                    _cachedBottomRight = _analyzerEntity.BottomRightNormalized;
                }

                if (_cachedTopLeft != null && _cachedTopRight != null &&
                    _cachedBottomLeft != null && _cachedBottomRight != null)
                { 
                    _warpFromPolygonEffect.Effect.Parameters["TopLeft"].SetValue(_cachedTopLeft.Value);
                    _warpFromPolygonEffect.Effect.Parameters["TopRight"].SetValue(_cachedTopRight.Value);
                    _warpFromPolygonEffect.Effect.Parameters["BottomLeft"].SetValue(_cachedBottomLeft.Value);
                    _warpFromPolygonEffect.Effect.Parameters["BottomRight"].SetValue(_cachedBottomRight.Value);
                    _warpFromPolygonEffect.Effect.Parameters["Alpha"].SetValue(_alpha);

                    _graphicsBlit.Blit(
                        renderContext,
                        _webcamEntity.VideoCaptureFrame,
                        null,
                        _warpFromPolygonEffect.Effect,
                        BlendState.AlphaBlend);
                }
            }
        }
 public void RenderText(IRenderContext context, IEffect effect, IEffectParameterSet effectParameterSet, Matrix matrix,
     string text, FontAsset font, HorizontalAlignment horizontalAlignment = HorizontalAlignment.Left,
     VerticalAlignment verticalAlignment = VerticalAlignment.Top, Color? textColor = null, bool renderShadow = true,
     Color? shadowColor = null)
 {
     throw new NotSupportedException();
 }
        /// <summary>
        /// Renders the ocean
        /// </summary>
        /// <param name="context">Rendering context</param>
        public override void Render( IRenderContext context )
        {
            if ( Planet == null || Planet.PlanetModel.OceanModel == null )
            {
                return;
            }

            GameProfiles.Game.Rendering.PlanetRendering.OceanRendering.Begin( );

            float seaLevel = ( SpherePlanet.PlanetModel.Radius + Planet.PlanetModel.OceanModel.SeaLevel ).ToRenderUnits;
            seaLevel /= 10.0f;
            Graphics.Renderer.PushTransform( TransformType.LocalToWorld );
            Graphics.Renderer.Scale( TransformType.LocalToWorld, seaLevel, seaLevel, seaLevel );

            m_WaveAnimation.UpdateAnimation( context.RenderTime );
            m_Technique.Effect.Parameters[ "OceanTexture0" ].Set( m_WaveAnimation.SourceTexture );
            m_Technique.Effect.Parameters[ "OceanTexture1" ].Set( m_WaveAnimation.DestinationTexture );
            m_Technique.Effect.Parameters[ "OceanTextureT" ].Set( m_WaveAnimation.LocalT );

            context.ApplyTechnique( m_Technique, m_OceanGeometry );

            Graphics.Renderer.PopTransform( TransformType.LocalToWorld );

            GameProfiles.Game.Rendering.PlanetRendering.OceanRendering.End( );
        }
        private void renderTargetDisplay_OnRender( IRenderContext context )
        {
            if ( renderTargetListView.SelectedItems.Count == 0 )
            {
                return;
            }
            IRenderTarget renderTarget = ( IRenderTarget )renderTargetListView.SelectedItems[ 0 ].Tag;

            m_Sampler.Texture = renderTarget.Texture;
            m_Sampler.Begin( );

            float w = renderTargetDisplay.Width;
            float h = renderTargetDisplay.Height;

            Graphics.Renderer.Push2d( );
            Graphics.Draw.BeginPrimitiveList( PrimitiveType.QuadList );
            Graphics.Draw.AddVertexData( VertexFieldSemantic.Texture0, 0, 1 );
            Graphics.Draw.AddVertexData( VertexFieldSemantic.Position, 0, 0 );

            Graphics.Draw.AddVertexData( VertexFieldSemantic.Texture0, 1, 1 );
            Graphics.Draw.AddVertexData( VertexFieldSemantic.Position, w, 0 );

            Graphics.Draw.AddVertexData( VertexFieldSemantic.Texture0, 1, 0 );
            Graphics.Draw.AddVertexData( VertexFieldSemantic.Position, w, h );

            Graphics.Draw.AddVertexData( VertexFieldSemantic.Texture0, 0, 0 );
            Graphics.Draw.AddVertexData( VertexFieldSemantic.Position, 0, h );

            Graphics.Draw.EndPrimitiveList( );
            Graphics.Renderer.Pop2d( );

            m_Sampler.End( );
        }
 public void RenderText(IRenderContext context, Vector2 position, string text, FontAsset font,
     HorizontalAlignment horizontalAlignment = HorizontalAlignment.Left,
     VerticalAlignment verticalAlignment = VerticalAlignment.Top, Color? textColor = null, bool renderShadow = true,
     Color? shadowColor = null)
 {
     throw new NotSupportedException();
 }
        public override void Render(IGameContext gameContext, IRenderContext renderContext)
        {
            base.Render(gameContext, renderContext);

            if (renderContext.IsCurrentRenderPass<I2DBatchedRenderPass>())
            {
                var recogArray = _currentColor.RecognisedArray;

                if (recogArray == null)
                {
                    return;
                }

                WidthScale = (int) Math.Ceiling(renderContext.GraphicsDevice.PresentationParameters.BackBufferWidth/
                                                (float) recogArray.GetLength(0));
                HeightScale = (int) Math.Ceiling(renderContext.GraphicsDevice.PresentationParameters.BackBufferHeight/
                                                 (float) recogArray.GetLength(1));

                for (var x = 0; x < recogArray.GetLength(0); x++)
                {
                    for (var y = 0; y < recogArray.GetLength(1); y++)
                    {
                        Color col;
                        var score = recogArray[x, y]/_currentColor.Sensitivity;

                        //var scoreCapped = MathHelper.Clamp(score, 0f, 255f) / 255f;
                        //col = new Color(scoreCapped, scoreCapped, scoreCapped);

                        if (score < 0)
                        {
                            var scoreCapped = Math.Min(255, -score);
                            col = new Color(scoreCapped/255f, scoreCapped/255f, scoreCapped/255f, 1f);
                        }
                        else
                        {
                            var scoreCapped = Math.Max(0, score);
                            col = new Color(
                                scoreCapped/255f*(_currentColor.Color.R/255f),
                                scoreCapped/255f*(_currentColor.Color.G/255f),
                                scoreCapped/255f*(_currentColor.Color.B/255f),
                                1f);
                        }

                        _renderUtilities.RenderRectangle(
                            renderContext,
                            new Rectangle(
                                (int) (X + x*WidthScale), (int) (Y + y*HeightScale), WidthScale, HeightScale),
                            col, true);
                    }
                }

                _renderUtilities.RenderText(
                    renderContext,
                    new Vector2(
                        renderContext.GraphicsDevice.PresentationParameters.BackBufferWidth/2,
                        40),
                    "Total " + _currentColor.Name + ": " + _currentColor.TotalDetected,
                    _defaultFont);
            }
        }
예제 #19
0
        public override void Render(IGameContext gameContext, IRenderContext renderContext)
        {
            if (!CanvasesEnabled)
            {
                return;
            }

            if (renderContext.IsCurrentRenderPass<ICanvasRenderPass>())
            {
                var bounds = gameContext.Window.ClientBounds;
                bounds.X = 0;
                bounds.Y = 0;

                _lastRenderBounds = bounds;

                base.Render(gameContext, renderContext);

                Canvas?.Render(renderContext, _skinLayout, _skinDelegator, bounds);

                foreach (var window in Windows.OrderBy(x => x.Order))
                {
                    window.Render(renderContext, _skinLayout, _skinDelegator, window.Bounds);
                }
            }
        }
예제 #20
0
        public void RenderDebug(IGameContext gameContext, IRenderContext renderContext, Agent agent, I2DRenderUtilities twoDRenderUtilities)
        {
            var wndPos = new Vector2(this.WanderDistance, 0);
            var wldPos = agent.Project(wndPos);

            for (var i = 0; i < 10; i++)
            {
                var r = MathHelper.ToRadians(36 * i);
                var r2 = MathHelper.ToRadians(36 * (i + 1));
                twoDRenderUtilities.RenderLine(
                    renderContext,
                    wldPos + (new Vector2((float)Math.Sin(r), (float)Math.Cos(r)) * this.WanderRadius),
                    wldPos + (new Vector2((float)Math.Sin(r2), (float)Math.Cos(r2)) * this.WanderRadius),
                    Color.Green);
            }

            wndPos = this.m_WanderTarget + new Vector2(this.WanderDistance, 0);
            wldPos = agent.Project(wndPos);

            for (var i = 0; i < 10; i++)
            {
                var r = MathHelper.ToRadians(36 * i);
                var r2 = MathHelper.ToRadians(36 * (i + 1));
                twoDRenderUtilities.RenderLine(
                    renderContext,
                    wldPos + (new Vector2((float)Math.Sin(r), (float)Math.Cos(r)) * 3),
                    wldPos + (new Vector2((float)Math.Sin(r2), (float)Math.Cos(r2)) * 3),
                    Color.Red);
            }
        }
예제 #21
0
        /// <summary>
        /// Renders the Series on the specified rendering context.
        /// </summary>
        /// <param name="rc">
        /// The rendering context.
        /// </param>
        /// <param name="model">
        /// The model.
        /// </param>
        public override void Render(IRenderContext rc, PlotModel model)
        {
            this.MovePointsToItems();

            // Let the base class draw the rectanges.
            base.Render(rc, model);
        }
 public void RenderBelow(IGameContext gameContext, IRenderContext renderContext)
 {
     using (this.m_Profiler.Measure("clear"))
     {
         gameContext.Graphics.GraphicsDevice.Clear(Color.CornflowerBlue);
     }
 }
 public override void RenderRow (IRenderContext context, int rowIndex, StatusType statusType, int width, int height)
 {
     if (statusType == StatusType.Normal && rowIndex % 2 != 0) {
         context.Theme.RenderRule (context.Context, width, height);
     }
     base.RenderRow (context, rowIndex, statusType);
 }
예제 #24
0
 public void RenderWireframeCube(
     IRenderContext renderContext,
     Microsoft.Xna.Framework.BoundingBox boundingBox,
     Color? color = null)
 {
     this.RenderWireframeCube(renderContext, boundingBox.ToProtogame(), color);
 }
예제 #25
0
        /// <summary>
        /// Renders the polygon annotation.
        /// </summary>
        /// <param name="rc">The render context.</param>
        /// <param name="model">The plot model.</param>
        public override void Render(IRenderContext rc, PlotModel model)
        {
            base.Render(rc, model);

            this.screenPosition = this.Transform(this.X, this.Y);

            // clip to the area defined by the axes
            var clippingRectangle = this.GetClippingRect();

            rc.DrawMarker(clippingRectangle, this.screenPosition, this.Shape, this.CustomOutline, this.Size, this.Fill, this.Stroke, this.StrokeThickness);

            if (!string.IsNullOrEmpty(this.Text))
            {
                var dx = -(int)this.TextHorizontalAlignment * (this.Size + this.TextMargin);
                var dy = -(int)this.TextVerticalAlignment * (this.Size + this.TextMargin);
                var textPosition = this.screenPosition + new ScreenVector(dx, dy);
                rc.DrawClippedText(
                    clippingRectangle,
                    textPosition,
                    this.Text,
                    this.ActualTextColor,
                    this.ActualFont,
                    this.ActualFontSize,
                    this.ActualFontWeight,
                    this.TextRotation,
                    this.TextHorizontalAlignment,
                    this.TextVerticalAlignment);
            }
        }
예제 #26
0
        /// <summary>
        /// Generates some script tags that you insert into your view.
        /// You should probably call this from a helper depending on your view engine.
        /// </summary>
        /// <param name="renderContext">The current Nancy Render Context</param>
        /// <returns></returns>
        public static string CurrentRequestSessions(IRenderContext renderContext)
        {
            var rootUrl = renderContext.ParsePath("~" + ModulePath) + "/";
            var sessionIdList = GetCurrentSessionIdList(renderContext.Context);

            return CurrentRequestSessions(rootUrl, sessionIdList);
        }
예제 #27
0
        public ClientChunk[] Process(
            TychaiaGameWorld world, 
            ChunkManagerEntity manager, 
            IGameContext gameContext, 
            IRenderContext renderContext)
        {
            foreach (
                var position in
                    this.m_PredeterminedChunkPositions.GetPurgableAbsolutePositions(
                        new Vector3(
                            world.IsometricCamera.Chunk.X,
                            world.IsometricCamera.Chunk.Y,
                            world.IsometricCamera.Chunk.Z)))
            {
                var chunk = world.ChunkOctree.Get((long)position.X, (long)position.Y, (long)position.Z);
                if (chunk != null)
                {
                    Console.WriteLine("FIXME: PURGING CHUNK");

                    // chunk.Purge();
                }
            }

            return null;
        }
예제 #28
0
 /// <summary>
 /// Internally called by <see cref="SensorEngineHook"/> to update sensors
 /// during the render step.
 /// </summary>
 /// <param name="gameContext">The current game context.</param>
 /// <param name="renderContext">The current render context.</param>
 public void Render(IGameContext gameContext, IRenderContext renderContext)
 {
     foreach (var sensor in _sensors)
     {
         sensor.Render(gameContext, renderContext);
     }
 }
예제 #29
0
 /// <summary>
 /// When overridden in a derived class, is invoked whenever application code or internal processes call <see cref="M:System.Windows.FrameworkElement.ApplyTemplate" />.
 /// </summary>
 public override void OnApplyTemplate()
 {
     base.OnApplyTemplate();
     this.canvas = this.GetTemplateChild(PartCanvas) as Canvas;
     this.renderContext = new CanvasRenderContext(this.canvas);
     this.SizeChanged += this.HandleSizeChanged;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="SvgRenderContext"/> class.
 /// </summary>
 /// <param name="path">The path.</param>
 /// <param name="width">The width.</param>
 /// <param name="height">The height.</param>
 /// <param name="textMeasurer">The text measurer.</param>
 public SvgRenderContext(string path, double width, double height, IRenderContext textMeasurer)
 {
     this.w = new SvgWriter(path, width, height);
     this.Width = width;
     this.Height = height;
     this.TextMeasurer = textMeasurer;
 }
예제 #31
0
 /// <summary>
 /// Renders a list of block elements.
 /// </summary>
 protected virtual void RenderBlocks(IEnumerable <MarkdownBlock> blockElements, IRenderContext context)
 {
     foreach (MarkdownBlock element in blockElements)
     {
         RenderBlock(element, context);
     }
 }
예제 #32
0
 public void RenderCube(IRenderContext context, IEffect effect, IEffectParameterSet effectParameterSet, Matrix transform,
                        Color color)
 {
     throw new NotSupportedException();
 }
예제 #33
0
 public void RenderTexture(IRenderContext context, IEffect effect, IEffectParameterSet effectParameterSet, Matrix matrix,
                           IAssetReference <TextureAsset> texture, Color?color = null, bool flipHorizontally = false, bool flipVertically = false,
                           Rectangle?sourceArea = null)
 {
     throw new NotSupportedException();
 }
예제 #34
0
 public void RenderRectangle(IRenderContext context, IEffect effect, IEffectParameterSet effectParameterSet, Vector3 start,
                             Vector3 end, Color color, bool filled = false)
 {
     throw new NotSupportedException();
 }
예제 #35
0
 public void RenderLine(IRenderContext context, IEffect effect, IEffectParameterSet effectParameterSet, Vector3 start,
                        Vector3 end, TextureAsset texture, Vector2 startUV, Vector2 endUV)
 {
     throw new NotSupportedException();
 }
예제 #36
0
 public void RenderLine(IRenderContext context, IEffect effect, IEffectParameterSet effectParameterSet, Vector3 start,
                        Vector3 end, Color color)
 {
     throw new NotSupportedException();
 }
예제 #37
0
        /// <summary>
        /// Renders the view.
        /// </summary>
        /// <param name="viewLocationResult">A <see cref="ViewLocationResult"/> instance, containing information on how to get the view template.</param>
        /// <param name="model">The model to be passed into the view</param>
        /// <param name="renderContext"></param>
        /// <returns>A response</returns>
        public Response RenderView(ViewLocationResult viewLocationResult, dynamic model, IRenderContext renderContext)
        {
            return(new HtmlResponse
            {
                Contents = stream =>
                {
                    var templateName = viewLocationResult.Name;

                    var handlebars = threadLocalHandlebars.Value;
                    handlebars.RegisterTemplate(templateName, () =>
                    {
                        using (var textReader = viewLocationResult.Contents())
                        {
                            return textReader.ReadToEnd();
                        }
                    });
                    foreach (var partial in viewLocator.GetAllCurrentlyDiscoveredViews().Where(x => x.Name.StartsWith("_")))
                    {
                        var partialName = partial.Name.TrimStart('_');
                        handlebars.RegisterPartial(partialName, () =>
                        {
                            using (var textReader = partial.Contents())
                            {
                                return textReader.ReadToEnd();
                            }
                        });
                    }
                    using (var writer = new StreamWriter(stream))
                    {
                        dynamic output;
                        try
                        {
                            output = handlebars.Transform(templateName, model);
                        }
                        catch (Exception)
                        {
                            //TODO: remove this exception handling after a few versions
                            var templateContents = viewLocationResult.Contents().ReadToEnd();
                            if (templateContents.Contains("{{> _") || templateContents.Contains("{{>_"))
                            {
                                throw new Exception(string.Format("Template '{0}' contains and underscore prefixed partial name. This is no longer required. Search for the string '{{>_' or '{{> _' in your template and remove the '_'.", templateName));
                            }
                            throw;
                        }
                        writer.Write(output);
                    }
                }
            });
        }
예제 #38
0
 /// <summary>
 /// Renders the legend symbol on the specified rendering context.
 /// </summary>
 /// <param name="rc">The rendering context.</param>
 /// <param name="legendBox">The legend rectangle.</param>
 public override void RenderLegend(IRenderContext rc, OxyRect legendBox)
 {
 }
예제 #39
0
        public void RenderCircle(IRenderContext context,
                                 Matrix transform, Vector2 center, int radius, Color color, bool filled = false)
        {
            if (!context.Is3DContext)
            {
                throw new InvalidOperationException("Can't use 3D rendering utilities in 2D context.");
            }

            var points = 8;

            double angle = MathHelper.TwoPi / points;

            var vertexesList = new List <VertexPositionColor>();
            var indicesList  = new List <short>();

            vertexesList.Add(new VertexPositionColor(new Vector3(center, 0), color));

            for (int i = 1; i <= points; i++)
            {
                var pos = new Vector2(
                    (float)Math.Round(Math.Sin(angle * i), 4) * radius,
                    (float)Math.Round(Math.Cos(angle * i), 4) * radius);

                vertexesList.Add(new VertexPositionColor(new Vector3(center + pos, 0), color));
            }

            if (filled)
            {
                for (int i = 1; i < points; i++)
                {
                    indicesList.Add(0);
                    indicesList.Add((short)(i + 1));
                    indicesList.Add((short)i);
                }
                indicesList.Add(0);
                indicesList.Add(1);
                indicesList.Add((short)points);
            }
            else
            {
                for (int i = 1; i <= points; i++)
                {
                    indicesList.Add((short)i);
                }
                indicesList.Add((short)1);
            }

            var vertexes = vertexesList.ToArray();
            var indicies = indicesList.ToArray();

            context.EnableVertexColors();

            var world = context.World;

            context.World = transform;

            foreach (var pass in context.Effect.CurrentTechnique.Passes)
            {
                pass.Apply();

                context.GraphicsDevice.DrawUserIndexedPrimitives(
                    filled ? PrimitiveType.TriangleList : PrimitiveType.LineStrip,
                    vertexes,
                    0,
                    vertexes.Length,
                    indicies,
                    0,
                    indicies.Length / 3);
            }

            context.World = world;
        }
예제 #40
0
 /// <summary>
 /// Renders all Content to the Provided Parent UI.
 /// </summary>
 /// <param name="context">UI Context</param>
 public virtual void Render(IRenderContext context)
 {
     RenderBlocks(Document.Blocks, context);
 }
예제 #41
0
 /// <summary>
 /// The measure text.
 /// </summary>
 /// <param name="context">
 /// The context.
 /// </param>
 /// <param name="text">
 /// The text.
 /// </param>
 /// <param name="font">
 /// The font.
 /// </param>
 /// <returns>
 /// The <see cref="Vector2"/>.
 /// </returns>
 public Vector2 MeasureText(IRenderContext context, string text, FontAsset font)
 {
     return(this.m_2DRenderUtilities.MeasureText(context, text, font));
 }
예제 #42
0
        /// <summary>
        /// Renders the Series on the specified rendering context.
        /// </summary>
        /// <param name="rc">The rendering context.</param>
        public override void Render(IRenderContext rc)
        {
            this.ActualMinimumBarRectangles = new List <OxyRect>();
            this.ActualMaximumBarRectangles = new List <OxyRect>();

            if (this.ValidItems.Count == 0)
            {
                return;
            }

            var clippingRect   = this.GetClippingRect();
            var categoryAxis   = this.GetCategoryAxis();
            var actualBarWidth = this.GetActualBarWidth();

            for (var i = 0; i < this.ValidItems.Count; i++)
            {
                var item = this.ValidItems[i];

                var categoryIndex = item.GetCategoryIndex(i);

                var baseValue = double.IsNaN(item.BaseValue) ? this.BaseValue : item.BaseValue;
                var barOffset = categoryAxis.GetCurrentBarOffset(categoryIndex);
                var p0        = this.Transform(item.Minimum, categoryIndex - 0.5 + barOffset);
                var p1        = this.Transform(item.Maximum, categoryIndex - 0.5 + barOffset + actualBarWidth);
                var p2        = this.Transform(baseValue, categoryIndex - 0.5 + barOffset);
                p2 = new ScreenPoint((int)p2.X, p2.Y);

                var minimumRectangle = OxyRect.Create(p0.X, p0.Y, p2.X, p1.Y);
                var maximumRectangle = OxyRect.Create(p2.X, p0.Y, p1.X, p1.Y);

                this.ActualMinimumBarRectangles.Add(minimumRectangle);
                this.ActualMaximumBarRectangles.Add(maximumRectangle);

                rc.DrawClippedRectangleAsPolygon(
                    clippingRect,
                    minimumRectangle,
                    item.MinimumColor.GetActualColor(this.ActualMinimumFillColor),
                    this.StrokeColor,
                    this.StrokeThickness);
                rc.DrawClippedRectangleAsPolygon(
                    clippingRect,
                    maximumRectangle,
                    item.MaximumColor.GetActualColor(this.ActualMaximumFillColor),
                    this.StrokeColor,
                    this.StrokeThickness);

                if (this.MinimumLabelFormatString != null)
                {
                    var s = StringHelper.Format(
                        this.ActualCulture,
                        this.MinimumLabelFormatString,
                        this.GetItem(this.ValidItemsIndexInversion[i]),
                        item.Minimum);
                    var pt = new ScreenPoint(
                        minimumRectangle.Left - this.LabelMargin, (minimumRectangle.Top + minimumRectangle.Bottom) / 2);

                    rc.DrawClippedText(
                        clippingRect,
                        pt,
                        s,
                        this.ActualTextColor,
                        this.ActualFont,
                        this.ActualFontSize,
                        this.ActualFontWeight,
                        0,
                        HorizontalAlignment.Right,
                        VerticalAlignment.Middle);
                }

                if (this.MaximumLabelFormatString != null)
                {
                    var s = StringHelper.Format(
                        this.ActualCulture,
                        this.MaximumLabelFormatString,
                        this.GetItem(this.ValidItemsIndexInversion[i]),
                        item.Maximum);
                    var pt = new ScreenPoint(
                        maximumRectangle.Right + this.LabelMargin, (maximumRectangle.Top + maximumRectangle.Bottom) / 2);

                    rc.DrawClippedText(
                        clippingRect,
                        pt,
                        s,
                        this.ActualTextColor,
                        this.ActualFont,
                        this.ActualFontSize,
                        this.ActualFontWeight,
                        0,
                        HorizontalAlignment.Left,
                        VerticalAlignment.Middle);
                }
            }
        }
예제 #43
0
        /// <summary>
        /// Measures the size of the specified text.
        /// </summary>
        /// <param name="rc">The render context.</param>
        /// <param name="text">The text.</param>
        /// <param name="fontFamily">The font family.</param>
        /// <param name="fontSize">Size of the font (in device independent units, 1/96 inch).</param>
        /// <param name="fontWeight">The font weight.</param>
        /// <param name="angle">The angle of measured text (degrees).</param>
        /// <returns>The size of the text (in device independent units, 1/96 inch).</returns>
        public static OxySize MeasureText(this IRenderContext rc, string text, string fontFamily, double fontSize, double fontWeight, double angle)
        {
            var bounds = rc.MeasureText(text, fontFamily, fontSize, fontWeight);

            return(MeasureRotatedRectangleBound(bounds, angle));
        }
예제 #44
0
        /// <summary>
        /// Renders a 3D cube from 0, 0, 0 to 1, 1, 1, applying the specified transformation, with the
        /// given texture and using the specified UV coordinates for each face of the cube.
        /// </summary>
        /// <param name="context">
        /// The rendering context.
        /// </param>
        /// <param name="transform">
        /// The transformation to apply.
        /// </param>
        /// <param name="texture">
        /// The texture to render on the cube.
        /// </param>
        /// <param name="topLeftUV">
        /// The top-left UV coordinate.
        /// </param>
        /// <param name="bottomRightUV">
        /// The bottom-right UV coordinate.
        /// </param>
        public void RenderCube(IRenderContext context, Matrix transform, TextureAsset texture, Vector2 topLeftUV, Vector2 bottomRightUV)
        {
            if (!context.Is3DContext)
            {
                throw new InvalidOperationException("Can't use 3D rendering utilities in 2D context.");
            }

            var vertexes = new[]
            {
                new VertexPositionNormalTexture(new Vector3(0, 0, 0), new Vector3(-1, 0, 0), new Vector2(topLeftUV.X, topLeftUV.Y)),
                new VertexPositionNormalTexture(new Vector3(0, 0, 1), new Vector3(-1, 0, 0), new Vector2(topLeftUV.X, bottomRightUV.Y)),
                new VertexPositionNormalTexture(new Vector3(0, 1, 0), new Vector3(-1, 0, 0), new Vector2(bottomRightUV.X, topLeftUV.Y)),
                new VertexPositionNormalTexture(new Vector3(0, 1, 1), new Vector3(-1, 0, 0), new Vector2(bottomRightUV.X, bottomRightUV.Y)),

                new VertexPositionNormalTexture(new Vector3(1, 0, 0), new Vector3(1, 0, 0), new Vector2(topLeftUV.X, topLeftUV.Y)),
                new VertexPositionNormalTexture(new Vector3(1, 0, 1), new Vector3(1, 0, 0), new Vector2(topLeftUV.X, bottomRightUV.Y)),
                new VertexPositionNormalTexture(new Vector3(1, 1, 0), new Vector3(1, 0, 0), new Vector2(bottomRightUV.X, topLeftUV.Y)),
                new VertexPositionNormalTexture(new Vector3(1, 1, 1), new Vector3(1, 0, 0), new Vector2(bottomRightUV.X, bottomRightUV.Y)),

                new VertexPositionNormalTexture(new Vector3(0, 0, 0), new Vector3(0, -1, 0), new Vector2(topLeftUV.X, topLeftUV.Y)),
                new VertexPositionNormalTexture(new Vector3(0, 0, 1), new Vector3(0, -1, 0), new Vector2(topLeftUV.X, bottomRightUV.Y)),
                new VertexPositionNormalTexture(new Vector3(0, 1, 0), new Vector3(0, 1, 0), new Vector2(topLeftUV.X, topLeftUV.Y)),
                new VertexPositionNormalTexture(new Vector3(0, 1, 1), new Vector3(0, 1, 0), new Vector2(topLeftUV.X, bottomRightUV.Y)),

                new VertexPositionNormalTexture(new Vector3(1, 0, 0), new Vector3(0, -1, 0), new Vector2(bottomRightUV.X, topLeftUV.Y)),
                new VertexPositionNormalTexture(new Vector3(1, 0, 1), new Vector3(0, -1, 0), new Vector2(bottomRightUV.X, bottomRightUV.Y)),
                new VertexPositionNormalTexture(new Vector3(1, 1, 0), new Vector3(0, 1, 0), new Vector2(bottomRightUV.X, topLeftUV.Y)),
                new VertexPositionNormalTexture(new Vector3(1, 1, 1), new Vector3(0, 1, 0), new Vector2(bottomRightUV.X, bottomRightUV.Y)),

                new VertexPositionNormalTexture(new Vector3(0, 0, 0), new Vector3(0, 0, -1), new Vector2(topLeftUV.X, topLeftUV.Y)),
                new VertexPositionNormalTexture(new Vector3(0, 0, 1), new Vector3(0, 0, 1), new Vector2(topLeftUV.X, topLeftUV.Y)),
                new VertexPositionNormalTexture(new Vector3(0, 1, 0), new Vector3(0, 0, -1), new Vector2(topLeftUV.X, bottomRightUV.Y)),
                new VertexPositionNormalTexture(new Vector3(0, 1, 1), new Vector3(0, 0, 1), new Vector2(topLeftUV.X, bottomRightUV.Y)),

                new VertexPositionNormalTexture(new Vector3(1, 0, 0), new Vector3(0, 0, -1), new Vector2(bottomRightUV.X, topLeftUV.Y)),
                new VertexPositionNormalTexture(new Vector3(1, 0, 1), new Vector3(0, 0, 1), new Vector2(bottomRightUV.X, topLeftUV.Y)),
                new VertexPositionNormalTexture(new Vector3(1, 1, 0), new Vector3(0, 0, -1), new Vector2(bottomRightUV.X, bottomRightUV.Y)),
                new VertexPositionNormalTexture(new Vector3(1, 1, 1), new Vector3(0, 0, 1), new Vector2(bottomRightUV.X, bottomRightUV.Y)),
            };

            var indicies = new short[]
            {
                0, 2, 1,
                3, 1, 2,

                4, 5, 6,
                7, 6, 5,

                0 + 8, 1 + 8, 4 + 8,
                5 + 8, 4 + 8, 1 + 8,

                2 + 8, 6 + 8, 3 + 8,
                7 + 8, 3 + 8, 6 + 8,

                0 + 16, 4 + 16, 2 + 16,
                6 + 16, 2 + 16, 4 + 16,

                1 + 16, 3 + 16, 5 + 16,
                7 + 16, 5 + 16, 3 + 16
            };

            context.EnableTextures();
            context.SetActiveTexture(texture.Texture);

            var world = context.World;

            context.World = transform;

            foreach (var pass in context.Effect.CurrentTechnique.Passes)
            {
                pass.Apply();

                context.GraphicsDevice.DrawUserIndexedPrimitives(
                    PrimitiveType.TriangleList,
                    vertexes,
                    0,
                    vertexes.Length,
                    indicies,
                    0,
                    indicies.Length / 3);
            }

            context.World = world;
        }
예제 #45
0
 /// <summary>
 /// Fills a circle at the specified position.
 /// </summary>
 /// <param name="rc">The render context.</param>
 /// <param name="center">The center.</param>
 /// <param name="r">The radius.</param>
 /// <param name="fill">The fill color.</param>
 public static void FillCircle(this IRenderContext rc, ScreenPoint center, double r, OxyColor fill)
 {
     DrawCircle(rc, center.X, center.Y, r, fill, OxyColors.Undefined, 0d);
 }
예제 #46
0
        /// <summary>
        /// Renders a 3D cube from 0, 0, 0 to 1, 1, 1, applying the specified transformation.
        /// </summary>
        /// <param name="context">
        /// The rendering context.
        /// </param>
        /// <param name="transform">
        /// The transformation to apply.
        /// </param>
        /// <param name="color">
        /// The color of the cube.
        /// </param>
        public void RenderCube(IRenderContext context, Matrix transform, Color color)
        {
            if (!context.Is3DContext)
            {
                throw new InvalidOperationException("Can't use 3D rendering utilities in 2D context.");
            }

            var vertexes = new[]
            {
                new VertexPositionColor(new Vector3(0, 0, 0), color),
                new VertexPositionColor(new Vector3(0, 0, 1), color),
                new VertexPositionColor(new Vector3(0, 1, 0), color),
                new VertexPositionColor(new Vector3(0, 1, 1), color),

                new VertexPositionColor(new Vector3(1, 0, 0), color),
                new VertexPositionColor(new Vector3(1, 0, 1), color),
                new VertexPositionColor(new Vector3(1, 1, 0), color),
                new VertexPositionColor(new Vector3(1, 1, 1), color),

                new VertexPositionColor(new Vector3(0, 0, 0), color),
                new VertexPositionColor(new Vector3(0, 0, 1), color),
                new VertexPositionColor(new Vector3(0, 1, 0), color),
                new VertexPositionColor(new Vector3(0, 1, 1), color),

                new VertexPositionColor(new Vector3(1, 0, 0), color),
                new VertexPositionColor(new Vector3(1, 0, 1), color),
                new VertexPositionColor(new Vector3(1, 1, 0), color),
                new VertexPositionColor(new Vector3(1, 1, 1), color),

                new VertexPositionColor(new Vector3(0, 0, 0), color),
                new VertexPositionColor(new Vector3(0, 0, 1), color),
                new VertexPositionColor(new Vector3(0, 1, 0), color),
                new VertexPositionColor(new Vector3(0, 1, 1), color),

                new VertexPositionColor(new Vector3(1, 0, 0), color),
                new VertexPositionColor(new Vector3(1, 0, 1), color),
                new VertexPositionColor(new Vector3(1, 1, 0), color),
                new VertexPositionColor(new Vector3(1, 1, 1), color),
            };

            var indicies = new short[]
            {
                0, 2, 1,
                3, 1, 2,

                4, 5, 6,
                7, 6, 5,

                0 + 8, 1 + 8, 4 + 8,
                5 + 8, 4 + 8, 1 + 8,

                2 + 8, 6 + 8, 3 + 8,
                7 + 8, 3 + 8, 6 + 8,

                0 + 16, 4 + 16, 2 + 16,
                6 + 16, 2 + 16, 4 + 16,

                1 + 16, 3 + 16, 5 + 16,
                7 + 16, 5 + 16, 3 + 16
            };

            context.EnableVertexColors();

            var world = context.World;

            context.World = transform;

            foreach (var pass in context.Effect.CurrentTechnique.Passes)
            {
                pass.Apply();

                context.GraphicsDevice.DrawUserIndexedPrimitives(
                    PrimitiveType.TriangleList,
                    vertexes,
                    0,
                    vertexes.Length,
                    indicies,
                    0,
                    indicies.Length / 3);
            }

            context.World = world;
        }
예제 #47
0
 /// <summary>
 /// Draws a circle at the specified position.
 /// </summary>
 /// <param name="rc">The render context.</param>
 /// <param name="x">The center x-coordinate.</param>
 /// <param name="y">The center y-coordinate.</param>
 /// <param name="r">The radius.</param>
 /// <param name="fill">The fill color.</param>
 /// <param name="stroke">The stroke color.</param>
 /// <param name="thickness">The thickness.</param>
 public static void DrawCircle(this IRenderContext rc, double x, double y, double r, OxyColor fill, OxyColor stroke, double thickness = 1)
 {
     rc.DrawEllipse(new OxyRect(x - r, y - r, r * 2, r * 2), fill, stroke, thickness);
 }
예제 #48
0
 /// <summary>
 /// Fills a rectangle at the specified position.
 /// </summary>
 /// <param name="rc">The render context.</param>
 /// <param name="rectangle">The rectangle.</param>
 /// <param name="fill">The fill color.</param>
 public static void FillRectangle(this IRenderContext rc, OxyRect rectangle, OxyColor fill)
 {
     rc.DrawRectangle(rectangle, fill, OxyColors.Undefined, 0d);
 }
예제 #49
0
        /// <summary>
        /// Draws a list of markers.
        /// </summary>
        /// <param name="rc">The render context.</param>
        /// <param name="clippingRectangle">The clipping rectangle.</param>
        /// <param name="markerPoints">The marker points.</param>
        /// <param name="markerType">Type of the marker.</param>
        /// <param name="markerOutline">The marker outline.</param>
        /// <param name="markerSize">Size of the markers.</param>
        /// <param name="markerFill">The marker fill.</param>
        /// <param name="markerStroke">The marker stroke.</param>
        /// <param name="markerStrokeThickness">The marker stroke thickness.</param>
        /// <param name="resolution">The resolution.</param>
        /// <param name="binOffset">The bin Offset.</param>
        public static void DrawMarkers(
            this IRenderContext rc,
            OxyRect clippingRectangle,
            IList <ScreenPoint> markerPoints,
            MarkerType markerType,
            IList <ScreenPoint> markerOutline,
            IList <double> markerSize,
            OxyColor markerFill,
            OxyColor markerStroke,
            double markerStrokeThickness,
            int resolution        = 0,
            ScreenPoint binOffset = new ScreenPoint())
        {
            if (markerType == MarkerType.None)
            {
                return;
            }

            int n        = markerPoints.Count;
            var ellipses = new List <OxyRect>(n);
            var rects    = new List <OxyRect>(n);
            var polygons = new List <IList <ScreenPoint> >(n);
            var lines    = new List <ScreenPoint>(n);

            var hashset = new Dictionary <uint, bool>();

            int i = 0;

            double minx = clippingRectangle.Left;
            double maxx = clippingRectangle.Right;
            double miny = clippingRectangle.Top;
            double maxy = clippingRectangle.Bottom;

            foreach (var p in markerPoints)
            {
                if (resolution > 1)
                {
                    var  x    = (int)((p.X - binOffset.X) / resolution);
                    var  y    = (int)((p.Y - binOffset.Y) / resolution);
                    uint hash = (uint)(x << 16) + (uint)y;
                    if (hashset.ContainsKey(hash))
                    {
                        i++;
                        continue;
                    }

                    hashset.Add(hash, true);
                }

                bool outside = p.x <minx || p.x> maxx || p.y <miny || p.y> maxy;
                if (!outside)
                {
                    int j = i < markerSize.Count ? i : 0;
                    AddMarkerGeometry(p, markerType, markerOutline, markerSize[j], ellipses, rects, polygons, lines);
                }

                i++;
            }

            if (ellipses.Count > 0)
            {
                rc.DrawEllipses(ellipses, markerFill, markerStroke, markerStrokeThickness);
            }

            if (rects.Count > 0)
            {
                rc.DrawRectangles(rects, markerFill, markerStroke, markerStrokeThickness);
            }

            if (polygons.Count > 0)
            {
                rc.DrawPolygons(polygons, markerFill, markerStroke, markerStrokeThickness);
            }

            if (lines.Count > 0)
            {
                rc.DrawLineSegments(lines, markerStroke, markerStrokeThickness);
            }
        }
예제 #50
0
 /// <summary>
 /// Draws a circle at the specified position.
 /// </summary>
 /// <param name="rc">The render context.</param>
 /// <param name="center">The center.</param>
 /// <param name="r">The radius.</param>
 /// <param name="fill">The fill color.</param>
 /// <param name="stroke">The stroke color.</param>
 /// <param name="thickness">The thickness.</param>
 public static void DrawCircle(this IRenderContext rc, ScreenPoint center, double r, OxyColor fill, OxyColor stroke, double thickness = 1)
 {
     DrawCircle(rc, center.X, center.Y, r, fill, stroke, thickness);
 }
예제 #51
0
        /// <summary>
        /// Renders the series on the specified rendering context.
        /// </summary>
        /// <param name="rc">
        /// The rendering context.
        /// </param>
        /// <param name="model">
        /// The owner plot model.
        /// </param>
        public override void Render(IRenderContext rc, PlotModel model)
        {
            if (this.Points.Count == 0)
            {
                return;
            }

            OxyRect clippingRect = this.GetClippingRect();

            var points      = this.Points;
            int n           = points.Count;
            var groupPoints = new Dictionary <int, IList <ScreenPoint> >();
            var groupSizes  = new Dictionary <int, IList <double> >();

            ScreenPoint[] allPoints   = null;
            double[]      markerSizes = null;

            if (this.ColorAxis == null)
            {
                allPoints   = new ScreenPoint[n];
                markerSizes = new double[n];
            }

            // Transform all points to screen coordinates
            for (int i = 0; i < n; i++)
            {
                var    dp    = new DataPoint(points[i].X, points[i].Y);
                double size  = double.NaN;
                double value = double.NaN;

                var scatterPoint = points[i] as ScatterPoint;
                if (scatterPoint != null)
                {
                    size  = scatterPoint.Size;
                    value = scatterPoint.Value;
                }

                if (double.IsNaN(size))
                {
                    size = this.MarkerSize;
                }

                var screenPoint = this.XAxis.Transform(dp.X, dp.Y, this.YAxis);

                if (this.ColorAxis != null)
                {
                    if (!double.IsNaN(value))
                    {
                        int group = this.ColorAxis.GetPaletteIndex(value);
                        if (!groupPoints.ContainsKey(group))
                        {
                            groupPoints.Add(group, new List <ScreenPoint>());
                            groupSizes.Add(group, new List <double>());
                        }

                        groupPoints[group].Add(screenPoint);
                        groupSizes[group].Add(size);
                    }
                }
                else
                {
// ReSharper disable PossibleNullReferenceException
                    allPoints[i]   = screenPoint;
                    markerSizes[i] = size;
// ReSharper restore PossibleNullReferenceException
                }
            }

            var binOffset = this.XAxis.Transform(this.MinX, this.MaxY, this.YAxis);

            // Draw the markers
            if (this.ColorAxis != null)
            {
                var markerIsStrokedOnly = this.MarkerType == MarkerType.Plus || this.MarkerType == MarkerType.Star ||
                                          this.MarkerType == MarkerType.Cross;
                foreach (var group in groupPoints)
                {
                    var color = this.ColorAxis.GetColor(group.Key);
                    rc.DrawMarkers(
                        group.Value,
                        clippingRect,
                        this.MarkerType,
                        this.MarkerOutline,
                        groupSizes[group.Key],
                        color,
                        markerIsStrokedOnly ? color : this.MarkerStroke,
                        this.MarkerStrokeThickness,
                        this.BinSize,
                        binOffset);
                }
            }
            else
            {
                rc.DrawMarkers(
                    allPoints,
                    clippingRect,
                    this.MarkerType,
                    this.MarkerOutline,
                    markerSizes,
                    this.ActualMarkerFillColor,
                    this.MarkerStroke,
                    this.MarkerStrokeThickness,
                    this.BinSize,
                    binOffset);
            }
        }
예제 #52
0
        /// <summary>
        /// Draws a clipped polyline through the specified points.
        /// </summary>
        /// <param name="rc">The render context.</param>
        /// <param name="clippingRectangle">The clipping rectangle.</param>
        /// <param name="points">The points.</param>
        /// <param name="minDistSquared">The minimum line segment length (squared).</param>
        /// <param name="stroke">The stroke color.</param>
        /// <param name="strokeThickness">The stroke thickness.</param>
        /// <param name="dashArray">The dash array (in device independent units, 1/96 inch).</param>
        /// <param name="lineJoin">The line join.</param>
        /// <param name="aliased">Set to <c>true</c> to draw as an aliased line.</param>
        /// <param name="outputBuffer">The output buffer.</param>
        /// <param name="pointsRendered">The points rendered callback.</param>
        public static void DrawClippedLine(
            this IRenderContext rc,
            OxyRect clippingRectangle,
            IList <ScreenPoint> points,
            double minDistSquared,
            OxyColor stroke,
            double strokeThickness,
            double[] dashArray,
            LineJoin lineJoin,
            bool aliased,
            List <ScreenPoint> outputBuffer = null,
            Action <IList <ScreenPoint> > pointsRendered = null)
        {
            var n = points.Count;

            if (n == 0)
            {
                return;
            }

            if (outputBuffer != null)
            {
                outputBuffer.Clear();
            }
            else
            {
                outputBuffer = new List <ScreenPoint>(n);
            }

            // draws the points in the output buffer and calls the callback (if specified)
            Action drawLine = () =>
            {
                EnsureNonEmptyLineIsVisible(outputBuffer);
                rc.DrawLine(outputBuffer, stroke, strokeThickness, dashArray, lineJoin, aliased);

                // Execute the 'callback'
                if (pointsRendered != null)
                {
                    pointsRendered(outputBuffer);
                }
            };

            var clipping = new CohenSutherlandClipping(clippingRectangle);

            if (n == 1 && clipping.IsInside(points[0]))
            {
                outputBuffer.Add(points[0]);
            }

            int lastPointIndex = 0;

            for (int i = 1; i < n; i++)
            {
                // Calculate the clipped version of previous and this point.
                var  sc0      = points[i - 1];
                var  sc1      = points[i];
                bool isInside = clipping.ClipLine(ref sc0, ref sc1);

                if (!isInside)
                {
                    // the line segment is outside the clipping rectangle
                    // keep the previous coordinate for minimum distance comparison
                    continue;
                }

                // length calculation (inlined for performance)
                var dx = sc1.X - points[lastPointIndex].X;
                var dy = sc1.Y - points[lastPointIndex].Y;

                if ((dx * dx) + (dy * dy) > minDistSquared || outputBuffer.Count == 0 || i == n - 1)
                {
                    // point comparison inlined for performance
                    // ReSharper disable CompareOfFloatsByEqualityOperator
                    if (sc0.X != points[lastPointIndex].X || sc0.Y != points[lastPointIndex].Y || outputBuffer.Count == 0)
                    // ReSharper restore disable CompareOfFloatsByEqualityOperator
                    {
                        outputBuffer.Add(new ScreenPoint(sc0.X, sc0.Y));
                    }

                    outputBuffer.Add(new ScreenPoint(sc1.X, sc1.Y));
                    lastPointIndex = i;
                }

                if (clipping.IsInside(points[i]) || outputBuffer.Count == 0)
                {
                    continue;
                }

                // we are leaving the clipping region - render the line
                drawLine();
                outputBuffer.Clear();
            }

            if (outputBuffer.Count > 0)
            {
                drawLine();
            }
        }
예제 #53
0
        /// <summary>
        /// Renders the points as line, broken line and markers.
        /// </summary>
        /// <param name="rc">The rendering context.</param>
        /// <param name="clippingRect">The clipping rectangle.</param>
        /// <param name="points">The points to render.</param>
        protected void RenderPoints(IRenderContext rc, OxyRect clippingRect, IList <DataPoint> points)
        {
            var lastValidPoint         = new ScreenPoint?();
            var areBrokenLinesRendered = this.BrokenLineThickness > 0 && this.BrokenLineStyle != LineStyle.None;
            var dashArray = areBrokenLinesRendered ? this.BrokenLineStyle.GetDashArray() : null;
            var broken    = areBrokenLinesRendered ? new List <ScreenPoint>(2) : null;

            if (this.contiguousScreenPointsBuffer == null)
            {
                this.contiguousScreenPointsBuffer = new List <ScreenPoint>(points.Count);
            }

            int    startIdx = 0;
            double xmax     = double.MaxValue;

            if (this.IsXMonotonic)
            {
                // determine render range
                var xmin = this.XAxis.ActualMinimum;
                xmax = this.XAxis.ActualMaximum;
                this.WindowStartIndex = this.UpdateWindowStartIndex(points, point => point.X, xmin, this.WindowStartIndex);

                startIdx = this.WindowStartIndex;
            }

            for (int i = startIdx; i < points.Count; i++)
            {
                if (!this.ExtractNextContiguousLineSegment(points, ref i, ref lastValidPoint, xmax, broken, this.contiguousScreenPointsBuffer))
                {
                    break;
                }

                if (areBrokenLinesRendered)
                {
                    if (broken.Count > 0)
                    {
                        var actualBrokenLineColor = this.BrokenLineColor.IsAutomatic()
                                                                                                                ? this.ActualColor
                                                                                                                : this.BrokenLineColor;

                        rc.DrawClippedLineSegments(
                            clippingRect,
                            broken,
                            actualBrokenLineColor,
                            this.BrokenLineThickness,
                            dashArray,
                            this.LineJoin,
                            false);
                        broken.Clear();
                    }
                }
                else
                {
                    lastValidPoint = null;
                }

                if (this.Decimator != null)
                {
                    if (this.decimatorBuffer == null)
                    {
                        this.decimatorBuffer = new List <ScreenPoint>(this.contiguousScreenPointsBuffer.Count);
                    }
                    else
                    {
                        this.decimatorBuffer.Clear();
                    }

                    this.Decimator(this.contiguousScreenPointsBuffer, this.decimatorBuffer);
                    this.RenderLineAndMarkers(rc, clippingRect, this.decimatorBuffer);
                }
                else
                {
                    this.RenderLineAndMarkers(rc, clippingRect, this.contiguousScreenPointsBuffer);
                }

                this.contiguousScreenPointsBuffer.Clear();
            }
        }
예제 #54
0
        /// <summary>
        /// Renders the LineSeries on the specified rendering context.
        /// </summary>
        /// <param name="rc">The rendering context.</param>
        /// <param name="model">The owner plot model.</param>
        public override void Render(IRenderContext rc, PlotModel model)
        {
            if (this.ActualPoints.Count == 0)
            {
                return;
            }

            this.VerifyAxes();

            var clippingRect            = this.GetClippingRect();
            var dashArray               = this.ActualDashArray;
            var verticalLineDashArray   = this.VerticalLineStyle.GetDashArray();
            var lineStyle               = this.ActualLineStyle;
            var verticalStrokeThickness = double.IsNaN(this.VerticalStrokeThickness)
                                              ? this.StrokeThickness
                                              : this.VerticalStrokeThickness;

            var actualColor = this.GetSelectableColor(this.ActualColor);

            Action <IList <ScreenPoint>, IList <ScreenPoint> > renderPoints = (lpts, mpts) =>
            {
                // clip the line segments with the clipping rectangle
                if (this.StrokeThickness > 0 && lineStyle != LineStyle.None)
                {
                    if (!verticalStrokeThickness.Equals(this.StrokeThickness) || this.VerticalLineStyle != lineStyle)
                    {
                        // TODO: change to array
                        var hlpts = new List <ScreenPoint>();
                        var vlpts = new List <ScreenPoint>();
                        for (int i = 0; i + 2 < lpts.Count; i += 2)
                        {
                            hlpts.Add(lpts[i]);
                            hlpts.Add(lpts[i + 1]);
                            vlpts.Add(lpts[i + 1]);
                            vlpts.Add(lpts[i + 2]);
                        }

                        rc.DrawClippedLineSegments(
                            clippingRect,
                            hlpts,
                            actualColor,
                            this.StrokeThickness,
                            dashArray,
                            this.LineJoin,
                            false);
                        rc.DrawClippedLineSegments(
                            clippingRect,
                            vlpts,
                            actualColor,
                            verticalStrokeThickness,
                            verticalLineDashArray,
                            this.LineJoin,
                            false);
                    }
                    else
                    {
                        rc.DrawClippedLine(
                            clippingRect,
                            lpts,
                            0,
                            actualColor,
                            this.StrokeThickness,
                            dashArray,
                            this.LineJoin,
                            false);
                    }
                }

                if (this.MarkerType != MarkerType.None)
                {
                    rc.DrawMarkers(
                        clippingRect,
                        mpts,
                        this.MarkerType,
                        this.MarkerOutline,
                        new[] { this.MarkerSize },
                        this.MarkerFill,
                        this.MarkerStroke,
                        this.MarkerStrokeThickness);
                }
            };

            // Transform all points to screen coordinates
            // Render the line when invalid points occur
            var    linePoints   = new List <ScreenPoint>();
            var    markerPoints = new List <ScreenPoint>();
            double previousY    = double.NaN;

            foreach (var point in this.ActualPoints)
            {
                if (!this.IsValidPoint(point))
                {
                    renderPoints(linePoints, markerPoints);
                    linePoints.Clear();
                    markerPoints.Clear();
                    previousY = double.NaN;
                    continue;
                }

                var transformedPoint = this.Transform(point);
                if (!double.IsNaN(previousY))
                {
                    // Horizontal line from the previous point to the current x-coordinate
                    linePoints.Add(new ScreenPoint(transformedPoint.X, previousY));
                }

                linePoints.Add(transformedPoint);
                markerPoints.Add(transformedPoint);
                previousY = transformedPoint.Y;
            }

            renderPoints(linePoints, markerPoints);

            if (this.LabelFormatString != null)
            {
                // render point labels (not optimized for performance)
                this.RenderPointLabels(rc, clippingRect);
            }
        }
예제 #55
0
 /// <summary>
 /// Renders a text run element.
 /// </summary>
 /// <param name="element"> The parsed inline element to render. </param>
 /// <param name="context"> Persistent state. </param>
 protected override void RenderTextRun(TextRunInline element, IRenderContext context)
 {
     InternalRenderTextRun(element, context);
 }
예제 #56
0
        /// <summary>
        /// Renders the point labels.
        /// </summary>
        /// <param name="rc">The render context.</param>
        /// <param name="clippingRect">The clipping rectangle.</param>
        protected void RenderPointLabels(IRenderContext rc, OxyRect clippingRect)
        {
            int index = -1;

            foreach (var point in this.ActualPoints)
            {
                index++;

                if (!this.IsValidPoint(point))
                {
                    continue;
                }

                var pt = this.Transform(point) + new ScreenVector(0, -this.LabelMargin);

                if (!clippingRect.Contains(pt))
                {
                    continue;
                }

                var item = this.GetItem(index);
                var s    = StringHelper.Format(this.ActualCulture, this.LabelFormatString, item, point.X, point.Y);

#if SUPPORTLABELPLACEMENT
                switch (this.LabelPlacement)
                {
                case LabelPlacement.Inside:
                    pt = new ScreenPoint(rect.Right - this.LabelMargin, (rect.Top + rect.Bottom) / 2);
                    ha = HorizontalAlignment.Right;
                    break;

                case LabelPlacement.Middle:
                    pt = new ScreenPoint((rect.Left + rect.Right) / 2, (rect.Top + rect.Bottom) / 2);
                    ha = HorizontalAlignment.Center;
                    break;

                case LabelPlacement.Base:
                    pt = new ScreenPoint(rect.Left + this.LabelMargin, (rect.Top + rect.Bottom) / 2);
                    ha = HorizontalAlignment.Left;
                    break;

                default:         // Outside
                    pt = new ScreenPoint(rect.Right + this.LabelMargin, (rect.Top + rect.Bottom) / 2);
                    ha = HorizontalAlignment.Left;
                    break;
                }
#endif

                rc.DrawClippedText(
                    clippingRect,
                    pt,
                    s,
                    this.ActualTextColor,
                    this.ActualFont,
                    this.ActualFontSize,
                    this.ActualFontWeight,
                    0,
                    HorizontalAlignment.Center,
                    VerticalAlignment.Bottom);
            }
        }
예제 #57
0
        /// <summary>
        /// Renders an image element.
        /// </summary>
        /// <param name="element"> The parsed inline element to render. </param>
        /// <param name="context"> Persistent state. </param>
        protected override async void RenderImage(ImageInline element, IRenderContext context)
        {
            var localContext = context as InlineRenderContext;

            if (localContext == null)
            {
                throw new RenderContextIncorrectException();
            }

            var inlineCollection = localContext.InlineCollection;

            var placeholder = InternalRenderTextRun(new TextRunInline {
                Text = element.Text, Type = MarkdownInlineType.TextRun
            }, context);
            var resolvedImage = await ImageResolver.ResolveImageAsync(element.RenderUrl, element.Tooltip);

            // if image can not be resolved we have to return
            if (resolvedImage == null)
            {
                return;
            }

            var image = new Image
            {
                Source = resolvedImage,
                HorizontalAlignment = HorizontalAlignment.Left,
                VerticalAlignment   = VerticalAlignment.Top,
                Stretch             = ImageStretch
            };

            HyperlinkButton hyperlinkButton = new HyperlinkButton()
            {
                Content = image
            };

            var viewbox = new Viewbox
            {
                Child            = hyperlinkButton,
                StretchDirection = StretchDirection.DownOnly
            };

            viewbox.PointerWheelChanged += Preventative_PointerWheelChanged;

            var scrollViewer = new ScrollViewer
            {
                Content                     = viewbox,
                VerticalScrollMode          = ScrollMode.Disabled,
                VerticalScrollBarVisibility = ScrollBarVisibility.Disabled
            };

            var imageContainer = new InlineUIContainer()
            {
                Child = scrollViewer
            };

            bool ishyperlink = false;

            if (element.RenderUrl != element.Url)
            {
                ishyperlink = true;
            }

            LinkRegister.RegisterNewHyperLink(image, element.Url, ishyperlink);

            if (ImageMaxHeight > 0)
            {
                viewbox.MaxHeight = ImageMaxHeight;
            }

            if (ImageMaxWidth > 0)
            {
                viewbox.MaxWidth = ImageMaxWidth;
            }

            if (element.ImageWidth > 0)
            {
                image.Width   = element.ImageWidth;
                image.Stretch = Stretch.UniformToFill;
            }

            if (element.ImageHeight > 0)
            {
                if (element.ImageWidth == 0)
                {
                    image.Width = element.ImageHeight;
                }

                image.Height  = element.ImageHeight;
                image.Stretch = Stretch.UniformToFill;
            }

            if (element.ImageHeight > 0 && element.ImageWidth > 0)
            {
                image.Stretch = Stretch.Fill;
            }

            // If image size is given then scroll to view overflown part
            if (element.ImageHeight > 0 || element.ImageWidth > 0)
            {
                scrollViewer.HorizontalScrollMode          = ScrollMode.Auto;
                scrollViewer.HorizontalScrollBarVisibility = ScrollBarVisibility.Auto;
            }

            // Else resize the image
            else
            {
                scrollViewer.HorizontalScrollMode          = ScrollMode.Disabled;
                scrollViewer.HorizontalScrollBarVisibility = ScrollBarVisibility.Disabled;
            }

            ToolTipService.SetToolTip(image, element.Tooltip);

            // Try to add it to the current inlines
            // Could fail because some containers like Hyperlink cannot have inlined images
            try
            {
                var placeholderIndex = inlineCollection.IndexOf(placeholder);
                inlineCollection.Remove(placeholder);
                inlineCollection.Insert(placeholderIndex, imageContainer);
            }
            catch
            {
                // Ignore error
            }
        }
예제 #58
0
        /// <summary>
        /// Renders a code element
        /// </summary>
        /// <param name="element"> The parsed inline element to render. </param>
        /// <param name="context"> Persistent state. </param>
        protected override void RenderCodeRun(CodeInline element, IRenderContext context)
        {
            var localContext = context as InlineRenderContext;

            if (localContext == null)
            {
                throw new RenderContextIncorrectException();
            }

            var text = CollapseWhitespace(context, element.Text);

            // Avoid a crash if the current inline is inside an hyperline.
            // This happens when using inline code blocks like [`SomeCode`](https://www.foo.bar).
            if (localContext.Parent is Hyperlink)
            {
                // Fallback span
                Run run = new Run
                {
                    Text       = text,
                    FontFamily = InlineCodeFontFamily ?? FontFamily,
                    Foreground = InlineCodeForeground ?? Foreground
                };

                // Additional formatting
                if (localContext.WithinItalics)
                {
                    run.FontStyle = FontStyle.Italic;
                }

                if (localContext.WithinBold)
                {
                    run.FontWeight = FontWeights.Bold;
                }

                // Add the fallback block
                localContext.InlineCollection.Add(run);
            }
            else
            {
                var textBlock = CreateTextBlock(localContext);
                textBlock.Text       = text;
                textBlock.FontFamily = InlineCodeFontFamily ?? FontFamily;
                textBlock.Foreground = InlineCodeForeground ?? Foreground;

                if (localContext.WithinItalics)
                {
                    textBlock.FontStyle = FontStyle.Italic;
                }

                if (localContext.WithinBold)
                {
                    textBlock.FontWeight = FontWeights.Bold;
                }

                var inlineUIContainer = new InlineUIContainer
                {
                    Child = new Border
                    {
                        BorderThickness = InlineCodeBorderThickness,
                        BorderBrush     = InlineCodeBorderBrush,
                        Background      = InlineCodeBackground,
                        Child           = textBlock,
                        Padding         = InlineCodePadding,
                        Margin          = InlineCodeMargin,

                        // Aligns content in InlineUI, see https://social.msdn.microsoft.com/Forums/silverlight/en-US/48b5e91e-efc5-4768-8eaf-f897849fcf0b/richtextbox-inlineuicontainer-vertical-alignment-issue?forum=silverlightarchieve
                        RenderTransform = new TranslateTransform {
                            Y = 4
                        }
                    }
                };

                // Add it to the current inlines
                localContext.InlineCollection.Add(inlineUIContainer);
            }
        }
예제 #59
0
        /// <summary>
        /// Renders a link element
        /// </summary>
        /// <param name="element"> The parsed inline element to render. </param>
        /// <param name="context"> Persistent state. </param>
        protected override void RenderMarkdownLink(MarkdownLinkInline element, IRenderContext context)
        {
            var localContext = context as InlineRenderContext;

            if (localContext == null)
            {
                throw new RenderContextIncorrectException();
            }

            // HACK: Superscript is not allowed within a hyperlink.  But if we switch it around, so
            // that the superscript is outside the hyperlink, then it will render correctly.
            // This assumes that the entire hyperlink is to be rendered as superscript.
            if (AllTextIsSuperscript(element) == false)
            {
                // Regular ol' hyperlink.
                var link = new Hyperlink();

                // Register the link
                LinkRegister.RegisterNewHyperLink(link, element.Url);

                // Remove superscripts.
                RemoveSuperscriptRuns(element, insertCaret: true);

                // Render the children into the link inline.
                var childContext = new InlineRenderContext(link.Inlines, context)
                {
                    Parent          = link,
                    WithinHyperlink = true
                };

                if (localContext.OverrideForeground)
                {
                    link.Foreground = localContext.Foreground;
                }
                else if (LinkForeground != null)
                {
                    link.Foreground = LinkForeground;
                }

                RenderInlineChildren(element.Inlines, childContext);
                context.TrimLeadingWhitespace = childContext.TrimLeadingWhitespace;

                ToolTipService.SetToolTip(link, element.Tooltip ?? element.Url);

                // Add it to the current inlines
                localContext.InlineCollection.Add(link);
            }
            else
            {
                // THE HACK IS ON!

                // Create a fake superscript element.
                var fakeSuperscript = new SuperscriptTextInline
                {
                    Inlines = new List <MarkdownInline>
                    {
                        element
                    }
                };

                // Remove superscripts.
                RemoveSuperscriptRuns(element, insertCaret: false);

                // Now render it.
                RenderSuperscriptRun(fakeSuperscript, context);
            }
        }
예제 #60
0
        /// <summary>
        /// Renders a strikethrough element.
        /// </summary>
        /// <param name="element"> The parsed inline element to render. </param>
        /// <param name="context"> Persistent state. </param>
        protected override void RenderStrikethroughRun(StrikethroughTextInline element, IRenderContext context)
        {
            var localContext = context as InlineRenderContext;

            if (localContext == null)
            {
                throw new RenderContextIncorrectException();
            }

            Span span = new Span();

            if (TextDecorationsSupported)
            {
                span.TextDecorations = TextDecorations.Strikethrough;
            }
            else
            {
                span.FontFamily = new FontFamily("Consolas");
            }

            var childContext = new InlineRenderContext(span.Inlines, context)
            {
                Parent = span
            };

            // Render the children into the inline.
            RenderInlineChildren(element.Inlines, childContext);

            if (!TextDecorationsSupported)
            {
                AlterChildRuns(span, (parentSpan, run) =>
                {
                    var text    = run.Text;
                    var builder = new StringBuilder(text.Length * 2);
                    foreach (var c in text)
                    {
                        builder.Append((char)0x0336);
                        builder.Append(c);
                    }

                    run.Text = builder.ToString();
                });
            }

            // Add it to the current inlines
            localContext.InlineCollection.Add(span);
        }