Search Results for

    Show / Hide Table of Contents

    RenderContext API

    The secret to SciChart’s speed is a bespoke, immediate-mode raster drawing engine. This means that all drawing in SciChart is done ‘immediately’ to the screen, and is cleared and redrawn each time the chart is updated.

    Now in SciChart you can take advantage of our immediate-mode drawing API, to create custom RenderableSeries, custom Point-Markers, Draw on top of the chart, or even create your own immediate-mode drawing applications.

    The IRenderContext2D Interface

    All the drawing to the separate layer is achieved with the IRenderContext2D interface. All drawing is done to the IRenderSurface, using either a Canvas API, or OpenGL depending on your RenderSurface.

    Using this interface, you can:

    • draw line of variable stroke width
    • draw a rectangle
    • draw an ellipse shape
    • draw triangles Strip with a brush
    • fill an area with a brush area
    • draw some text to the render surface
    • draw sprite
    • set clip rect which prevents drawing outside specified bounds
    • rotate, scale and translate RenderContext Believe it or not, you can achieve a lot with just those!

    The IAssetManager2D interface

    The second part RenderContext API is IAssetManager2D interface which is responsible for creation and storing of RenderSurface specific resources from Style classes.

    Using this interface, you can

    • create pens to draw stroke with
    • create brushes to fill rects, ellipses with
    • create textures from Bitmap
    • store and get some heavy resources which should be reused during drawing (e.g. textures, sprites)

    Example of using RenderContext API

    For example we'll create a simple example of IRenderSurfaceRenderer which can be set as renderer for RenderSurface:

    • Java
    • Java with Builders API
    • Kotlin
    class TestRenderSurfaceRenderer implements IRenderSurfaceRenderer{
        private final RectF sprite2Rect = new RectF(0,0, 0.5f, 0.5f);
        private final RectF sprite3Rect = new RectF(0.25f,0.25f, 0.75f, 0.75f);
    
        private final BrushStyle solidStyle;
        private final BrushStyle linearGradient;
        private final BrushStyle radialGradient;
        private final TextureBrushStyle textureStyle;
    
        private final PenStyle simpleLine;
        private final PenStyle aaLine;
        private final PenStyle texturedLine;
        private final PenStyle texturedAaLine;
    
        private final PenStyle dashedSimpleLine;
        private final PenStyle dashedAaLine;
        private final PenStyle dashedTexturedLine;
        private final PenStyle dashedTexturedAaLine;
    
        private final PenStyle thickSimpleLine;
        private final PenStyle thickAaLine;
        private final PenStyle thickTexturedLine;
        private final PenStyle thickTexturedAaLine;
    
        private final PenStyle dashedThickSimpleLine;
        private final PenStyle dashedThickAaLine;
        private final PenStyle dashedThickTexturedLine;
        private final PenStyle dashedThickTexturedAaLine;
    
        private final FontStyle fontStyle;
        private final FontStyle customFontStyle;
    
        private final Bitmap texture;
    
        private final float[] xAxisArrow = {0,0, 50, 0, 30, -10, 50, 0, 30, 10, 50, 0};
        private final float[] yAxisArrow = {0,0, 0, 50, -10, 30, 0, 50, 10, 30, 0, 50};
    
        private float degrees, dx, dy, opacity;
    
        public TestRenderSurfaceRenderer(Bitmap texture) {
            solidStyle = new SolidBrushStyle(ColorUtil.argb(0xEE, 0xFF, 0xC9, 0xA8));
            linearGradient = new LinearGradientBrushStyle(0, 0, 1, 1, ColorUtil.argb(0xEE, 0xFF, 0xC9, 0xA8), ColorUtil.argb(0xEE, 0x13, 0x24, 0xA5));
            radialGradient = new RadialGradientBrushStyle(0.5f, 0.5f, 0.5f, 0.5f, ColorUtil.argb(0xEE, 0xFF, 0xC9, 0xA8), ColorUtil.argb(0xEE, 0x13, 0x24, 0xA5));
            textureStyle = new TextureBrushStyle(texture);
    
            fontStyle = new FontStyle(32, ColorUtil.Red);
            customFontStyle = new FontStyle(Typeface.create(Typeface.SANS_SERIF, Typeface.BOLD_ITALIC), 23, ColorUtil.Yellow, false);
    
            simpleLine = new SolidPenStyle(ColorUtil.Red, false, 1f, null);
            aaLine = new SolidPenStyle(ColorUtil.Green, true, 1f, null);
            texturedLine = new TexturePenStyle(textureStyle, false, 1f, null);
            texturedAaLine = new TexturePenStyle(textureStyle, true, 1f, null);
    
            dashedSimpleLine = new SolidPenStyle(ColorUtil.Blue, false, 1f, new float[]{5, 10, 5, 10});
            dashedAaLine = new SolidPenStyle(ColorUtil.Magenta, true, 1f, new float[]{10, 5, 10, 5});
            dashedTexturedLine = new TexturePenStyle(textureStyle, false, 1f, new float[]{5, 10, 5, 10});
            dashedTexturedAaLine = new TexturePenStyle(textureStyle, true, 1f, new float[]{10, 5, 10, 5});
    
            thickSimpleLine = new SolidPenStyle(ColorUtil.Red, false, 10f, null);
            thickAaLine = new SolidPenStyle(ColorUtil.Green, true, 10f, null);
            thickTexturedLine = new TexturePenStyle(textureStyle, false, 10f, null);
            thickTexturedAaLine = new TexturePenStyle(textureStyle, true, 10f, null);
    
            dashedThickSimpleLine = new SolidPenStyle(ColorUtil.Blue, false, 20f, new float[]{5, 10, 5, 10});
            dashedThickAaLine = new SolidPenStyle(ColorUtil.Magenta, true, 20f, new float[]{0, 20, 10, 5});
            dashedThickTexturedLine = new TexturePenStyle(textureStyle, false, 20f, new float[]{5, 10, 5, 10});
            dashedThickTexturedAaLine = new TexturePenStyle(textureStyle, true, 20f, new float[]{0, 20, 10, 5});
    
            this.texture = texture;
        }
    
        @Override
        public void onSurfaceAttached(IRenderSurface surface) { }
    
        @Override
        public void onSurfaceDetached(IRenderSurface surface) { }
    
        @Override
        public void onSurfaceSizeChanged(int width, int height, int oldWidth, int oldHeight) { }
    
        public void setTransform(float degrees, float dx, float dy, float opacity){
            this.degrees = degrees;
            this.dx = dx  - binding.translateX.getMax() / 2f;
            this.dy = dy - binding.translateY.getMax() / 2f;
            this.opacity = opacity;
        }
    
        @Override
        public void onDraw(IRenderContext2D renderContext, IAssetManager2D assetManager) {
            renderContext.translate(dx, dy);
            renderContext.rotate(degrees);
    
            final IBrush2D solidBrushPerScreen = assetManager.createBrush(solidStyle, TextureMappingMode.PerScreen, opacity);
            final IBrush2D radialGradientBrushPerScreen = assetManager.createBrush(radialGradient, TextureMappingMode.PerScreen, opacity);
            final IBrush2D linearGradientBrushPerScreen = assetManager.createBrush(linearGradient, TextureMappingMode.PerScreen, opacity);
            final IBrush2D textureBrushPerScreen = assetManager.createBrush(textureStyle, TextureMappingMode.PerScreen, opacity);
    
            final IBrush2D solidBrushPerPrimitive = assetManager.createBrush(solidStyle, TextureMappingMode.PerPrimitive, opacity);
            final IBrush2D radialGradientBrushPerPrimitive = assetManager.createBrush(radialGradient, TextureMappingMode.PerPrimitive, opacity);
            final IBrush2D linearGradientBrushPerPrimitive = assetManager.createBrush(linearGradient, TextureMappingMode.PerPrimitive, opacity);
            final IBrush2D textureBrushPerPrimitive = assetManager.createBrush(textureStyle, TextureMappingMode.PerPrimitive, opacity);
    
            final IPen2D simpleLine = assetManager.createPen(this.simpleLine, opacity);
            final IPen2D aaLine = assetManager.createPen(this.aaLine, opacity);
            final IPen2D dashedSimpleLine = assetManager.createPen(this.dashedSimpleLine, opacity);
            final IPen2D dashedAaLine = assetManager.createPen(this.dashedAaLine, opacity);
            final IPen2D thickSimpleLine = assetManager.createPen(this.thickSimpleLine, opacity);
            final IPen2D thickAaLine = assetManager.createPen(this.thickAaLine, opacity);
            final IPen2D dashedThickSimpleLine = assetManager.createPen(this.dashedThickSimpleLine, opacity);
            final IPen2D dashedThickAaLine = assetManager.createPen(this.dashedThickAaLine, opacity);
    
            final IPen2D texturedLine = assetManager.createPen(this.texturedLine, opacity);
            final IPen2D texturedAaLine = assetManager.createPen(this.texturedAaLine, opacity);
            final IPen2D dashedTexturedLine = assetManager.createPen(this.dashedTexturedLine, opacity);
            final IPen2D dashedTexturedAaLine = assetManager.createPen(this.dashedTexturedAaLine, opacity);
            final IPen2D thickTexturedLine = assetManager.createPen(this.thickTexturedLine, opacity);
            final IPen2D thickTexturedAaLine = assetManager.createPen(this.thickTexturedAaLine, opacity);
            final IPen2D dashedThickTexturedLine = assetManager.createPen(this.dashedThickTexturedLine, opacity);
            final IPen2D dashedThickTexturedAaLine = assetManager.createPen(this.dashedThickTexturedAaLine, opacity);
    
            final IFont font = assetManager.createFont(this.fontStyle);
            final IFont customFont = assetManager.createFont(this.customFontStyle);
    
            final ITexture2D sprite1 = assetManager.createTexture(texture);
            final ITexture2D sprite2 = assetManager.createTexture(texture, sprite2Rect);
            final ITexture2D sprite3 = assetManager.createTexture(texture, sprite3Rect);
    
            renderContext.drawLines(xAxisArrow, 0, xAxisArrow.length, simpleLine);
            renderContext.drawLines(yAxisArrow, 0, yAxisArrow.length, aaLine);
    
            renderContext.save();
            renderContext.translate(10, 10);
    
            renderContext.drawLine(0, 0, 80, 80, simpleLine);
            renderContext.drawLine(100, 0, 180, 80, aaLine);
            renderContext.drawLine(200, 0, 280, 80, dashedSimpleLine);
            renderContext.drawLine(300, 0, 380, 80, dashedAaLine);
    
            renderContext.drawLine(0, 100, 80, 180, thickSimpleLine);
            renderContext.drawLine(100, 100, 180, 180, thickAaLine);
            renderContext.drawLine(200, 100, 280, 180, dashedThickSimpleLine);
            renderContext.drawLine(300, 100, 380, 180, dashedThickAaLine);
    
            renderContext.translate(0, 200);
    
            renderContext.drawLine(0, 0, 80, 80, texturedLine);
            renderContext.drawLine(100, 0, 180, 80, texturedAaLine);
            renderContext.drawLine(200, 0, 280, 80, dashedTexturedLine);
            renderContext.drawLine(300, 0, 380, 80, dashedTexturedAaLine);
    
            renderContext.drawLine(0, 100, 80, 180, thickTexturedLine);
            renderContext.drawLine(100, 100, 180, 180, thickTexturedAaLine);
            renderContext.drawLine(200, 100, 280, 180, dashedThickTexturedLine);
            renderContext.drawLine(300, 100, 380, 180, dashedThickTexturedAaLine);
    
            renderContext.translate(0, 200);
    
            renderContext.drawRect(0, 0, 80, 80, simpleLine);
            renderContext.drawRect(100, 0, 180, 80, aaLine);
            renderContext.drawRect(200, 0, 280, 80, dashedSimpleLine);
            renderContext.drawRect(300, 0, 380, 80, dashedAaLine);
    
            renderContext.drawRect(0, 100, 80, 180, thickSimpleLine);
            renderContext.drawRect(100, 100, 180, 180, thickAaLine);
            renderContext.drawRect(200, 100, 280, 180, dashedThickSimpleLine);
            renderContext.drawRect(300, 100, 380, 180, dashedThickAaLine);
    
            renderContext.translate(0, 200);
    
            renderContext.fillRect(0, 0, 80, 80, solidBrushPerScreen);
            renderContext.fillRect(100, 0, 180, 80, linearGradientBrushPerScreen);
            renderContext.fillRect(200, 0, 280, 80, radialGradientBrushPerScreen);
            renderContext.fillRect(300, 0, 380, 80, textureBrushPerScreen);
    
            renderContext.fillRect(0, 100, 80, 180, solidBrushPerPrimitive);
            renderContext.fillRect(100, 100, 180, 180, linearGradientBrushPerPrimitive);
            renderContext.fillRect(200, 100, 280, 180, radialGradientBrushPerPrimitive);
            renderContext.fillRect(300, 100, 380, 180, textureBrushPerPrimitive);
    
            renderContext.translate(0, 200);
    
            renderContext.drawEllipse(50, 50, 80, 80, simpleLine, solidBrushPerScreen);
            renderContext.drawEllipse(150, 50, 80, 80, aaLine, linearGradientBrushPerScreen);
            renderContext.drawEllipse(250, 50, 80, 80, dashedSimpleLine, radialGradientBrushPerScreen);
            renderContext.drawEllipse(350, 50, 80, 80, dashedAaLine, textureBrushPerScreen);
    
            renderContext.drawEllipse(50, 150, 80, 80, thickSimpleLine, solidBrushPerPrimitive);
            renderContext.drawEllipse(150, 150, 80, 80, thickAaLine, linearGradientBrushPerPrimitive);
            renderContext.drawEllipse(250, 150, 80, 80, dashedThickSimpleLine, radialGradientBrushPerPrimitive);
            renderContext.drawEllipse(350, 150, 80, 80, dashedThickAaLine, textureBrushPerPrimitive);
    
            renderContext.restore();
            renderContext.save();
            renderContext.translate(500, 0);
    
            renderContext.drawText(font, 0, 0, fontStyle.textColor, "ABCDEFGHIJKLMNOPQRSTUVWXYZ");
            renderContext.drawText(font, 0, 50, fontStyle.textColor, "abcdefghijklmnopqrstuvwxyz");
            renderContext.drawText(font, 0, 100, fontStyle.textColor, "1234567890~!@#$%^&*()-+=/|\\'\"");
    
            renderContext.drawText(customFont, 0, 150, customFontStyle.textColor, "ABCDEFGHIJKLMNOPQRSTUVWXYZ");
            renderContext.drawText(customFont, 0, 200, customFontStyle.textColor, "abcdefghijklmnopqrstuvwxyz");
            renderContext.drawText(customFont, 0, 250, customFontStyle.textColor, "1234567890~!@#$%^&*()-+=/|\\'\"");
    
            renderContext.translate(0, 300);
    
            renderContext.drawSprite(sprite1, 0, 0, opacity);
            renderContext.translate(0, sprite1.getHeight() + 10);
    
            renderContext.drawSprite(sprite2, 0, 0, opacity);
            renderContext.translate(0, sprite2.getHeight() + 10);
    
            renderContext.drawSprite(sprite3, 0, 0, opacity);
            renderContext.translate(0, sprite3.getHeight() + 10);
    
            final float[] triangles = new float[8];
            triangles[0] = 0; triangles[1] = 0;
            triangles[2] = 100; triangles[3] = 0;
            triangles[4] = 100; triangles[5] = 200;
            triangles[6] = 200; triangles[7] = 200;
    
            renderContext.save();
    
            renderContext.drawTrianglesStrip(triangles, 0, 8, solidBrushPerScreen);
            renderContext.translate(210, 0);
    
            renderContext.drawTrianglesStrip(triangles, 0, 8, linearGradientBrushPerScreen);
            renderContext.translate(210, 0);
    
            renderContext.drawTrianglesStrip(triangles, 0, 8, radialGradientBrushPerScreen);
            renderContext.translate(210, 0);
    
            renderContext.drawTrianglesStrip(triangles, 0, 8, textureBrushPerScreen);
            renderContext.translate(210, 0);
    
            renderContext.restore();
            renderContext.save();
            renderContext.translate(0, 210);
    
            renderContext.drawTrianglesStrip(triangles, 0, 8, solidBrushPerPrimitive);
            renderContext.translate(210, 0);
    
            renderContext.drawTrianglesStrip(triangles, 0, 8, linearGradientBrushPerPrimitive);
            renderContext.translate(210, 0);
    
            renderContext.drawTrianglesStrip(triangles, 0, 8, radialGradientBrushPerPrimitive);
            renderContext.translate(210, 0);
    
            renderContext.drawTrianglesStrip(triangles, 0, 8, textureBrushPerPrimitive);
            renderContext.translate(210, 0);
    
            sprite1.dispose();
            sprite2.dispose();
            sprite3.dispose();
        }
    }
    
    class TestRenderSurfaceRenderer implements IRenderSurfaceRenderer{
        private final RectF sprite2Rect = new RectF(0,0, 0.5f, 0.5f);
        private final RectF sprite3Rect = new RectF(0.25f,0.25f, 0.75f, 0.75f);
    
        private final BrushStyle solidStyle;
        private final BrushStyle linearGradient;
        private final BrushStyle radialGradient;
        private final TextureBrushStyle textureStyle;
    
        private final PenStyle simpleLine;
        private final PenStyle aaLine;
        private final PenStyle texturedLine;
        private final PenStyle texturedAaLine;
    
        private final PenStyle dashedSimpleLine;
        private final PenStyle dashedAaLine;
        private final PenStyle dashedTexturedLine;
        private final PenStyle dashedTexturedAaLine;
    
        private final PenStyle thickSimpleLine;
        private final PenStyle thickAaLine;
        private final PenStyle thickTexturedLine;
        private final PenStyle thickTexturedAaLine;
    
        private final PenStyle dashedThickSimpleLine;
        private final PenStyle dashedThickAaLine;
        private final PenStyle dashedThickTexturedLine;
        private final PenStyle dashedThickTexturedAaLine;
    
        private final FontStyle fontStyle;
        private final FontStyle customFontStyle;
    
        private final Bitmap texture;
    
        private final float[] xAxisArrow = {0,0, 50, 0, 30, -10, 50, 0, 30, 10, 50, 0};
        private final float[] yAxisArrow = {0,0, 0, 50, -10, 30, 0, 50, 10, 30, 0, 50};
    
        private float degrees, dx, dy, opacity;
    
        public TestRenderSurfaceRenderer(Bitmap texture) {
            solidStyle = new SolidBrushStyle(ColorUtil.argb(0xEE, 0xFF, 0xC9, 0xA8));
            linearGradient = new LinearGradientBrushStyle(0, 0, 1, 1, ColorUtil.argb(0xEE, 0xFF, 0xC9, 0xA8), ColorUtil.argb(0xEE, 0x13, 0x24, 0xA5));
            radialGradient = new RadialGradientBrushStyle(0.5f, 0.5f, 0.5f, 0.5f, ColorUtil.argb(0xEE, 0xFF, 0xC9, 0xA8), ColorUtil.argb(0xEE, 0x13, 0x24, 0xA5));
            textureStyle = new TextureBrushStyle(texture);
    
            fontStyle = new FontStyleBuilder(requireContext()).withTextSize(32).withTextColor(ColorUtil.Red).build();
            customFontStyle = new FontStyleBuilder(requireContext()).withTypeface(Typeface.create(Typeface.SANS_SERIF, Typeface.BOLD_ITALIC)).withTextSize(23).withTextColor(ColorUtil.Yellow).build();
    
            simpleLine = new PenStyleBuilder.SolidPenStyleBuilder(requireContext()).withColor(ColorUtil.Red).withAntiAliasing(false).withThickness(1f).build();
            aaLine = new PenStyleBuilder.SolidPenStyleBuilder(requireContext()).withColor(ColorUtil.Green).withAntiAliasing(true).withThickness(1f).build();
            texturedLine = new PenStyleBuilder.TexturePenStyleBuilder(requireContext()).withTextureBrush(textureStyle).withAntiAliasing(false).withThickness(1f).build();
            texturedAaLine = new PenStyleBuilder.TexturePenStyleBuilder(requireContext()).withTextureBrush(textureStyle).withAntiAliasing(true).withThickness(1f).build();
    
            dashedSimpleLine = new PenStyleBuilder.SolidPenStyleBuilder(requireContext()).withColor(ColorUtil.Blue).withAntiAliasing(false).withThickness(1f).withStrokeDashArray(new float[]{5, 10, 5, 10}).build();
            dashedAaLine = new PenStyleBuilder.SolidPenStyleBuilder(requireContext()).withColor(ColorUtil.Magenta).withAntiAliasing(true).withThickness(1f).withStrokeDashArray(new float[]{10, 5, 10, 5}).build();
            dashedTexturedLine = new PenStyleBuilder.TexturePenStyleBuilder(requireContext()).withTextureBrush(textureStyle).withAntiAliasing(false).withStrokeDashArray(new float[]{5, 10, 5, 10}).withThickness(1f).build();
            dashedTexturedAaLine = new PenStyleBuilder.TexturePenStyleBuilder(requireContext()).withTextureBrush(textureStyle).withAntiAliasing(true).withStrokeDashArray(new float[]{10, 5, 10, 5}).withThickness(1f).build();
    
            thickSimpleLine = new PenStyleBuilder.SolidPenStyleBuilder(requireContext()).withColor(ColorUtil.Red).withAntiAliasing(false).withThickness(10f).build();
            thickAaLine = new PenStyleBuilder.SolidPenStyleBuilder(requireContext()).withColor(ColorUtil.Green).withAntiAliasing(true).withThickness(10f).build();
            thickTexturedLine = new PenStyleBuilder.TexturePenStyleBuilder(requireContext()).withTextureBrush(textureStyle).withAntiAliasing(false).withThickness(10f).build();
            thickTexturedAaLine = new PenStyleBuilder.TexturePenStyleBuilder(requireContext()).withTextureBrush(textureStyle).withAntiAliasing(true).withThickness(10f).build();
    
            dashedThickSimpleLine = new PenStyleBuilder.SolidPenStyleBuilder(requireContext()).withColor(ColorUtil.Blue).withAntiAliasing(false).withThickness(20f).withStrokeDashArray(new float[]{5, 10, 5, 10}).build();
            dashedThickAaLine = new PenStyleBuilder.SolidPenStyleBuilder(requireContext()).withColor(ColorUtil.Magenta).withAntiAliasing(true).withThickness(20f).withStrokeDashArray(new float[]{0, 20, 10, 5}).build();
            dashedThickTexturedLine = new PenStyleBuilder.TexturePenStyleBuilder(requireContext()).withTextureBrush(textureStyle).withAntiAliasing(false).withThickness(20f).withStrokeDashArray(new float[]{5, 10, 5, 10}).build();
            dashedThickTexturedAaLine = new PenStyleBuilder.TexturePenStyleBuilder(requireContext()).withTextureBrush(textureStyle).withAntiAliasing(true).withThickness(20).withStrokeDashArray(new float[]{0, 20, 10, 5}).build();
    
            this.texture = texture;
        }
    
        @Override
        public void onSurfaceAttached(IRenderSurface surface) { }
    
        @Override
        public void onSurfaceDetached(IRenderSurface surface) { }
    
        @Override
        public void onSurfaceSizeChanged(int width, int height, int oldWidth, int oldHeight) { }
    
        public void setTransform(float degrees, float dx, float dy, float opacity){
            this.degrees = degrees;
            this.dx = dx  - binding.translateX.getMax() / 2f;
            this.dy = dy - binding.translateY.getMax() / 2f;
            this.opacity = opacity;
        }
    
        @Override
        public void onDraw(IRenderContext2D renderContext, IAssetManager2D assetManager) {
            renderContext.translate(dx, dy);
            renderContext.rotate(degrees);
    
            final IBrush2D solidBrushPerScreen = assetManager.createBrush(solidStyle, TextureMappingMode.PerScreen, opacity);
            final IBrush2D radialGradientBrushPerScreen = assetManager.createBrush(radialGradient, TextureMappingMode.PerScreen, opacity);
            final IBrush2D linearGradientBrushPerScreen = assetManager.createBrush(linearGradient, TextureMappingMode.PerScreen, opacity);
            final IBrush2D textureBrushPerScreen = assetManager.createBrush(textureStyle, TextureMappingMode.PerScreen, opacity);
    
            final IBrush2D solidBrushPerPrimitive = assetManager.createBrush(solidStyle, TextureMappingMode.PerPrimitive, opacity);
            final IBrush2D radialGradientBrushPerPrimitive = assetManager.createBrush(radialGradient, TextureMappingMode.PerPrimitive, opacity);
            final IBrush2D linearGradientBrushPerPrimitive = assetManager.createBrush(linearGradient, TextureMappingMode.PerPrimitive, opacity);
            final IBrush2D textureBrushPerPrimitive = assetManager.createBrush(textureStyle, TextureMappingMode.PerPrimitive, opacity);
    
            final IPen2D simpleLine = assetManager.createPen(this.simpleLine, opacity);
            final IPen2D aaLine = assetManager.createPen(this.aaLine, opacity);
            final IPen2D dashedSimpleLine = assetManager.createPen(this.dashedSimpleLine, opacity);
            final IPen2D dashedAaLine = assetManager.createPen(this.dashedAaLine, opacity);
            final IPen2D thickSimpleLine = assetManager.createPen(this.thickSimpleLine, opacity);
            final IPen2D thickAaLine = assetManager.createPen(this.thickAaLine, opacity);
            final IPen2D dashedThickSimpleLine = assetManager.createPen(this.dashedThickSimpleLine, opacity);
            final IPen2D dashedThickAaLine = assetManager.createPen(this.dashedThickAaLine, opacity);
    
            final IPen2D texturedLine = assetManager.createPen(this.texturedLine, opacity);
            final IPen2D texturedAaLine = assetManager.createPen(this.texturedAaLine, opacity);
            final IPen2D dashedTexturedLine = assetManager.createPen(this.dashedTexturedLine, opacity);
            final IPen2D dashedTexturedAaLine = assetManager.createPen(this.dashedTexturedAaLine, opacity);
            final IPen2D thickTexturedLine = assetManager.createPen(this.thickTexturedLine, opacity);
            final IPen2D thickTexturedAaLine = assetManager.createPen(this.thickTexturedAaLine, opacity);
            final IPen2D dashedThickTexturedLine = assetManager.createPen(this.dashedThickTexturedLine, opacity);
            final IPen2D dashedThickTexturedAaLine = assetManager.createPen(this.dashedThickTexturedAaLine, opacity);
    
            final IFont font = assetManager.createFont(this.fontStyle);
            final IFont customFont = assetManager.createFont(this.customFontStyle);
    
            final ITexture2D sprite1 = assetManager.createTexture(texture);
            final ITexture2D sprite2 = assetManager.createTexture(texture, sprite2Rect);
            final ITexture2D sprite3 = assetManager.createTexture(texture, sprite3Rect);
    
            renderContext.drawLines(xAxisArrow, 0, xAxisArrow.length, simpleLine);
            renderContext.drawLines(yAxisArrow, 0, yAxisArrow.length, aaLine);
    
            renderContext.save();
            renderContext.translate(10, 10);
    
            renderContext.drawLine(0, 0, 80, 80, simpleLine);
            renderContext.drawLine(100, 0, 180, 80, aaLine);
            renderContext.drawLine(200, 0, 280, 80, dashedSimpleLine);
            renderContext.drawLine(300, 0, 380, 80, dashedAaLine);
    
            renderContext.drawLine(0, 100, 80, 180, thickSimpleLine);
            renderContext.drawLine(100, 100, 180, 180, thickAaLine);
            renderContext.drawLine(200, 100, 280, 180, dashedThickSimpleLine);
            renderContext.drawLine(300, 100, 380, 180, dashedThickAaLine);
    
            renderContext.translate(0, 200);
    
            renderContext.drawLine(0, 0, 80, 80, texturedLine);
            renderContext.drawLine(100, 0, 180, 80, texturedAaLine);
            renderContext.drawLine(200, 0, 280, 80, dashedTexturedLine);
            renderContext.drawLine(300, 0, 380, 80, dashedTexturedAaLine);
    
            renderContext.drawLine(0, 100, 80, 180, thickTexturedLine);
            renderContext.drawLine(100, 100, 180, 180, thickTexturedAaLine);
            renderContext.drawLine(200, 100, 280, 180, dashedThickTexturedLine);
            renderContext.drawLine(300, 100, 380, 180, dashedThickTexturedAaLine);
    
            renderContext.translate(0, 200);
    
            renderContext.drawRect(0, 0, 80, 80, simpleLine);
            renderContext.drawRect(100, 0, 180, 80, aaLine);
            renderContext.drawRect(200, 0, 280, 80, dashedSimpleLine);
            renderContext.drawRect(300, 0, 380, 80, dashedAaLine);
    
            renderContext.drawRect(0, 100, 80, 180, thickSimpleLine);
            renderContext.drawRect(100, 100, 180, 180, thickAaLine);
            renderContext.drawRect(200, 100, 280, 180, dashedThickSimpleLine);
            renderContext.drawRect(300, 100, 380, 180, dashedThickAaLine);
    
            renderContext.translate(0, 200);
    
            renderContext.fillRect(0, 0, 80, 80, solidBrushPerScreen);
            renderContext.fillRect(100, 0, 180, 80, linearGradientBrushPerScreen);
            renderContext.fillRect(200, 0, 280, 80, radialGradientBrushPerScreen);
            renderContext.fillRect(300, 0, 380, 80, textureBrushPerScreen);
    
            renderContext.fillRect(0, 100, 80, 180, solidBrushPerPrimitive);
            renderContext.fillRect(100, 100, 180, 180, linearGradientBrushPerPrimitive);
            renderContext.fillRect(200, 100, 280, 180, radialGradientBrushPerPrimitive);
            renderContext.fillRect(300, 100, 380, 180, textureBrushPerPrimitive);
    
            renderContext.translate(0, 200);
    
            renderContext.drawEllipse(50, 50, 80, 80, simpleLine, solidBrushPerScreen);
            renderContext.drawEllipse(150, 50, 80, 80, aaLine, linearGradientBrushPerScreen);
            renderContext.drawEllipse(250, 50, 80, 80, dashedSimpleLine, radialGradientBrushPerScreen);
            renderContext.drawEllipse(350, 50, 80, 80, dashedAaLine, textureBrushPerScreen);
    
            renderContext.drawEllipse(50, 150, 80, 80, thickSimpleLine, solidBrushPerPrimitive);
            renderContext.drawEllipse(150, 150, 80, 80, thickAaLine, linearGradientBrushPerPrimitive);
            renderContext.drawEllipse(250, 150, 80, 80, dashedThickSimpleLine, radialGradientBrushPerPrimitive);
            renderContext.drawEllipse(350, 150, 80, 80, dashedThickAaLine, textureBrushPerPrimitive);
    
            renderContext.restore();
            renderContext.save();
            renderContext.translate(500, 0);
    
            renderContext.drawText(font, 0, 0, fontStyle.textColor, "ABCDEFGHIJKLMNOPQRSTUVWXYZ");
            renderContext.drawText(font, 0, 50, fontStyle.textColor, "abcdefghijklmnopqrstuvwxyz");
            renderContext.drawText(font, 0, 100, fontStyle.textColor, "1234567890~!@#$%^&*()-+=/|\\'\"");
    
            renderContext.drawText(customFont, 0, 150, customFontStyle.textColor, "ABCDEFGHIJKLMNOPQRSTUVWXYZ");
            renderContext.drawText(customFont, 0, 200, customFontStyle.textColor, "abcdefghijklmnopqrstuvwxyz");
            renderContext.drawText(customFont, 0, 250, customFontStyle.textColor, "1234567890~!@#$%^&*()-+=/|\\'\"");
    
            renderContext.translate(0, 300);
    
            renderContext.drawSprite(sprite1, 0, 0, opacity);
            renderContext.translate(0, sprite1.getHeight() + 10);
    
            renderContext.drawSprite(sprite2, 0, 0, opacity);
            renderContext.translate(0, sprite2.getHeight() + 10);
    
            renderContext.drawSprite(sprite3, 0, 0, opacity);
            renderContext.translate(0, sprite3.getHeight() + 10);
    
            final float[] triangles = new float[8];
            triangles[0] = 0; triangles[1] = 0;
            triangles[2] = 100; triangles[3] = 0;
            triangles[4] = 100; triangles[5] = 200;
            triangles[6] = 200; triangles[7] = 200;
    
            renderContext.save();
    
            renderContext.drawTrianglesStrip(triangles, 0, 8, solidBrushPerScreen);
            renderContext.translate(210, 0);
    
            renderContext.drawTrianglesStrip(triangles, 0, 8, linearGradientBrushPerScreen);
            renderContext.translate(210, 0);
    
            renderContext.drawTrianglesStrip(triangles, 0, 8, radialGradientBrushPerScreen);
            renderContext.translate(210, 0);
    
            renderContext.drawTrianglesStrip(triangles, 0, 8, textureBrushPerScreen);
            renderContext.translate(210, 0);
    
            renderContext.restore();
            renderContext.save();
            renderContext.translate(0, 210);
    
            renderContext.drawTrianglesStrip(triangles, 0, 8, solidBrushPerPrimitive);
            renderContext.translate(210, 0);
    
            renderContext.drawTrianglesStrip(triangles, 0, 8, linearGradientBrushPerPrimitive);
            renderContext.translate(210, 0);
    
            renderContext.drawTrianglesStrip(triangles, 0, 8, radialGradientBrushPerPrimitive);
            renderContext.translate(210, 0);
    
            renderContext.drawTrianglesStrip(triangles, 0, 8, textureBrushPerPrimitive);
            renderContext.translate(210, 0);
    
            sprite1.dispose();
            sprite2.dispose();
            sprite3.dispose();
        }
    }
    
    class TestRenderSurfaceRenderer(texture: Bitmap) :
        IRenderSurfaceRenderer {
        private val sprite2Rect = RectF(0f, 0f, 0.5f, 0.5f)
        private val sprite3Rect = RectF(0.25f, 0.25f, 0.75f, 0.75f)
    
        private val solidStyle: BrushStyle
        private val linearGradient: BrushStyle
        private val radialGradient: BrushStyle
        private val textureStyle: TextureBrushStyle
    
        private val simpleLine: PenStyle
        private val aaLine: PenStyle
        private val texturedLine: PenStyle
        private val texturedAaLine: PenStyle
    
        private val dashedSimpleLine: PenStyle
        private val dashedAaLine: PenStyle
        private val dashedTexturedLine: PenStyle
        private val dashedTexturedAaLine: PenStyle
    
        private val thickSimpleLine: PenStyle
        private val thickAaLine: PenStyle
        private val thickTexturedLine: PenStyle
        private val thickTexturedAaLine: PenStyle
    
        private val dashedThickSimpleLine: PenStyle
        private val dashedThickAaLine: PenStyle
        private val dashedThickTexturedLine: PenStyle
        private val dashedThickTexturedAaLine: PenStyle
    
        private val fontStyle: FontStyle
        private val customFontStyle: FontStyle
    
        private val texture: Bitmap
    
        private val xAxisArrow = floatArrayOf(0f, 0f, 50f, 0f, 30f, -10f, 50f, 0f, 30f, 10f, 50f, 0f)
        private val yAxisArrow = floatArrayOf(0f, 0f, 0f, 50f, -10f, 30f, 0f, 50f, 10f, 30f, 0f, 50f)
    
        private var degrees = 0f
        private var dx = 0f
        private var dy = 0f
        private var opacity = 0f
    
        init {
            solidStyle = SolidBrushStyle(ColorUtil.argb(0xEE, 0xFF, 0xC9, 0xA8))
            linearGradient = LinearGradientBrushStyle(0f, 0f, 1f, 1f, ColorUtil.argb(0xEE, 0xFF, 0xC9, 0xA8), ColorUtil.argb(0xEE, 0x13, 0x24, 0xA5))
            radialGradient = RadialGradientBrushStyle(0.5f, 0.5f, 0.5f, 0.5f, ColorUtil.argb(0xEE, 0xFF, 0xC9, 0xA8), ColorUtil.argb(0xEE, 0x13, 0x24, 0xA5))
            textureStyle = TextureBrushStyle(texture)
    
            fontStyle = FontStyle(32f, ColorUtil.Red)
            customFontStyle = FontStyle(Typeface.create(Typeface.SANS_SERIF, Typeface.BOLD_ITALIC), 23f, ColorUtil.Yellow, false)
    
            simpleLine = SolidPenStyle(ColorUtil.Red, false, 1f, null)
            aaLine = SolidPenStyle(ColorUtil.Green, true, 1f, null)
            texturedLine = TexturePenStyle(textureStyle, false, 1f, null)
            texturedAaLine = TexturePenStyle(textureStyle, true, 1f, null)
    
            dashedSimpleLine = SolidPenStyle(ColorUtil.Blue, false, 1f, floatArrayOf(5f, 10f, 5f, 10f))
            dashedAaLine = SolidPenStyle(ColorUtil.Magenta, true, 1f, floatArrayOf(10f, 5f, 10f, 5f))
            dashedTexturedLine = TexturePenStyle(textureStyle, false, 1f, floatArrayOf(5f, 10f, 5f, 10f))
            dashedTexturedAaLine = TexturePenStyle(textureStyle, true, 1f, floatArrayOf(10f, 5f, 10f, 5f))
    
            thickSimpleLine = SolidPenStyle(ColorUtil.Red, false, 10f, null)
            thickAaLine = SolidPenStyle(ColorUtil.Green, true, 10f, null)
            thickTexturedLine = TexturePenStyle(textureStyle, false, 10f, null)
            thickTexturedAaLine = TexturePenStyle(textureStyle, true, 10f, null)
    
            dashedThickSimpleLine = SolidPenStyle(ColorUtil.Blue, false, 20f, floatArrayOf(5f, 10f, 5f, 10f))
            dashedThickAaLine = SolidPenStyle(ColorUtil.Magenta, true, 20f, floatArrayOf(0f, 20f, 10f, 5f))
            dashedThickTexturedLine = TexturePenStyle(textureStyle, false, 20f, floatArrayOf(5f, 10f, 5f, 10f))
            dashedThickTexturedAaLine = TexturePenStyle(textureStyle, true, 20f, floatArrayOf(0f, 20f, 10f, 5f))
    
            this.texture = texture
        }
    
        override fun onSurfaceAttached(surface: IRenderSurface) {}
        override fun onSurfaceDetached(surface: IRenderSurface) {}
        override fun onSurfaceSizeChanged(width: Int, height: Int, oldWidth: Int, oldHeight: Int) {}
    
        fun setTransform(degrees: Float, dx: Float, dy: Float, opacity: Float) {
            this.degrees = degrees
            this.dx = dx - binding.translateX.max / 2f
            this.dy = dy - binding.translateY.max / 2f
            this.opacity = opacity
        }
    
        override fun onDraw(renderContext: IRenderContext2D, assetManager: IAssetManager2D) {
            renderContext.translate(dx, dy)
            renderContext.rotate(degrees)
    
            val solidBrushPerScreen = assetManager.createBrush(solidStyle, TextureMappingMode.PerScreen, opacity)
            val radialGradientBrushPerScreen = assetManager.createBrush(radialGradient, TextureMappingMode.PerScreen, opacity)
            val linearGradientBrushPerScreen = assetManager.createBrush(linearGradient, TextureMappingMode.PerScreen, opacity)
            val textureBrushPerScreen = assetManager.createBrush(textureStyle, TextureMappingMode.PerScreen, opacity)
    
            val solidBrushPerPrimitive = assetManager.createBrush(solidStyle, TextureMappingMode.PerPrimitive, opacity)
            val radialGradientBrushPerPrimitive = assetManager.createBrush(radialGradient, TextureMappingMode.PerPrimitive, opacity)
            val linearGradientBrushPerPrimitive = assetManager.createBrush(linearGradient, TextureMappingMode.PerPrimitive, opacity)
            val textureBrushPerPrimitive = assetManager.createBrush(textureStyle, TextureMappingMode.PerPrimitive, opacity)
    
            val simpleLine = assetManager.createPen(simpleLine, opacity)
            val aaLine = assetManager.createPen(aaLine, opacity)
            val dashedSimpleLine = assetManager.createPen(dashedSimpleLine, opacity)
            val dashedAaLine = assetManager.createPen(dashedAaLine, opacity)
            val thickSimpleLine = assetManager.createPen(thickSimpleLine, opacity)
            val thickAaLine = assetManager.createPen(thickAaLine, opacity)
            val dashedThickSimpleLine = assetManager.createPen(dashedThickSimpleLine, opacity)
            val dashedThickAaLine = assetManager.createPen(dashedThickAaLine, opacity)
    
            val texturedLine = assetManager.createPen(texturedLine, opacity)
            val texturedAaLine = assetManager.createPen(texturedAaLine, opacity)
            val dashedTexturedLine = assetManager.createPen(dashedTexturedLine, opacity)
            val dashedTexturedAaLine = assetManager.createPen(dashedTexturedAaLine, opacity)
            val thickTexturedLine = assetManager.createPen(thickTexturedLine, opacity)
            val thickTexturedAaLine = assetManager.createPen(thickTexturedAaLine, opacity)
            val dashedThickTexturedLine = assetManager.createPen(dashedThickTexturedLine, opacity)
            val dashedThickTexturedAaLine = assetManager.createPen(dashedThickTexturedAaLine, opacity)
    
            val font = assetManager.createFont(fontStyle)
            val customFont = assetManager.createFont(customFontStyle)
    
            val sprite1: ITexture2D = assetManager.createTexture(texture)
            val sprite2: ITexture2D = assetManager.createTexture(texture, sprite2Rect)
            val sprite3: ITexture2D = assetManager.createTexture(texture, sprite3Rect)
    
            renderContext.drawLines(xAxisArrow, 0, xAxisArrow.size, simpleLine)
            renderContext.drawLines(yAxisArrow, 0, yAxisArrow.size, aaLine)
    
            renderContext.save()
            renderContext.translate(10f, 10f)
    
            renderContext.drawLine(0f, 0f, 80f, 80f, simpleLine)
            renderContext.drawLine(100f, 0f, 180f, 80f, aaLine)
            renderContext.drawLine(200f, 0f, 280f, 80f, dashedSimpleLine)
            renderContext.drawLine(300f, 0f, 380f, 80f, dashedAaLine)
    
            renderContext.drawLine(0f, 100f, 80f, 180f, thickSimpleLine)
            renderContext.drawLine(100f, 100f, 180f, 180f, thickAaLine)
            renderContext.drawLine(200f, 100f, 280f, 180f, dashedThickSimpleLine)
            renderContext.drawLine(300f, 100f, 380f, 180f, dashedThickAaLine)
    
            renderContext.translate(0f, 200f)
    
            renderContext.drawLine(0f, 0f, 80f, 80f, texturedLine)
            renderContext.drawLine(100f, 0f, 180f, 80f, texturedAaLine)
            renderContext.drawLine(200f, 0f, 280f, 80f, dashedTexturedLine)
            renderContext.drawLine(300f, 0f, 380f, 80f, dashedTexturedAaLine)
    
            renderContext.drawLine(0f, 100f, 80f, 180f, thickTexturedLine)
            renderContext.drawLine(100f, 100f, 180f, 180f, thickTexturedAaLine)
            renderContext.drawLine(200f, 100f, 280f, 180f, dashedThickTexturedLine)
            renderContext.drawLine(300f, 100f, 380f, 180f, dashedThickTexturedAaLine)
    
            renderContext.translate(0f, 200f)
    
            renderContext.drawRect(0f, 0f, 80f, 80f, simpleLine)
            renderContext.drawRect(100f, 0f, 180f, 80f, aaLine)
            renderContext.drawRect(200f, 0f, 280f, 80f, dashedSimpleLine)
            renderContext.drawRect(300f, 0f, 380f, 80f, dashedAaLine)
    
            renderContext.drawRect(0f, 100f, 80f, 180f, thickSimpleLine)
            renderContext.drawRect(100f, 100f, 180f, 180f, thickAaLine)
            renderContext.drawRect(200f, 100f, 280f, 180f, dashedThickSimpleLine)
            renderContext.drawRect(300f, 100f, 380f, 180f, dashedThickAaLine)
    
            renderContext.translate(0f, 200f)
    
            renderContext.fillRect(0f, 0f, 80f, 80f, solidBrushPerScreen)
            renderContext.fillRect(100f, 0f, 180f, 80f, linearGradientBrushPerScreen)
            renderContext.fillRect(200f, 0f, 280f, 80f, radialGradientBrushPerScreen)
            renderContext.fillRect(300f, 0f, 380f, 80f, textureBrushPerScreen)
    
            renderContext.fillRect(0f, 100f, 80f, 180f, solidBrushPerPrimitive)
            renderContext.fillRect(100f, 100f, 180f, 180f, linearGradientBrushPerPrimitive)
            renderContext.fillRect(200f, 100f, 280f, 180f, radialGradientBrushPerPrimitive)
            renderContext.fillRect(300f, 100f, 380f, 180f, textureBrushPerPrimitive)
    
            renderContext.translate(0f, 200f)
    
            renderContext.drawEllipse(50f, 50f, 80f, 80f, simpleLine, solidBrushPerScreen)
            renderContext.drawEllipse(150f, 50f, 80f, 80f, aaLine, linearGradientBrushPerScreen)
            renderContext.drawEllipse(250f, 50f, 80f, 80f, dashedSimpleLine, radialGradientBrushPerScreen)
            renderContext.drawEllipse(350f, 50f, 80f, 80f, dashedAaLine, textureBrushPerScreen)
    
            renderContext.drawEllipse(50f, 150f, 80f, 80f, thickSimpleLine, solidBrushPerPrimitive)
            renderContext.drawEllipse(150f, 150f, 80f, 80f, thickAaLine, linearGradientBrushPerPrimitive)
            renderContext.drawEllipse(250f, 150f, 80f, 80f, dashedThickSimpleLine, radialGradientBrushPerPrimitive)
            renderContext.drawEllipse(350f, 150f, 80f, 80f, dashedThickAaLine, textureBrushPerPrimitive)
    
            renderContext.restore()
            renderContext.save()
            renderContext.translate(500f, 0f)
    
            renderContext.drawText(font, 0f, 0f, fontStyle.textColor, "ABCDEFGHIJKLMNOPQRSTUVWXYZ")
            renderContext.drawText(font, 0f, 50f, fontStyle.textColor, "abcdefghijklmnopqrstuvwxyz")
            renderContext.drawText(font, 0f, 100f, fontStyle.textColor, "1234567890~!@#$%^&*()-+=/|\\'\"")
    
            renderContext.drawText(customFont, 0f, 150f, customFontStyle.textColor, "ABCDEFGHIJKLMNOPQRSTUVWXYZ")
            renderContext.drawText(customFont, 0f, 200f, customFontStyle.textColor, "abcdefghijklmnopqrstuvwxyz")
            renderContext.drawText(customFont, 0f, 250f, customFontStyle.textColor, "1234567890~!@#$%^&*()-+=/|\\'\"")
    
            renderContext.translate(0f, 300f)
    
            renderContext.drawSprite(sprite1, 0f, 0f, opacity)
            renderContext.translate(0f, (sprite1.height + 10).toFloat())
    
            renderContext.drawSprite(sprite2, 0f, 0f, opacity)
            renderContext.translate(0f, (sprite2.height + 10).toFloat())
    
            renderContext.drawSprite(sprite3, 0f, 0f, opacity)
            renderContext.translate(0f, (sprite3.height + 10).toFloat())
    
            val triangles = FloatArray(8)
            triangles[0] = 0f; triangles[1] = 0f
            triangles[2] = 100f; triangles[3] = 0f
            triangles[4] = 100f; triangles[5] = 200f
            triangles[6] = 200f; triangles[7] = 200f
    
            renderContext.save()
    
            renderContext.drawTrianglesStrip(triangles, 0, 8, solidBrushPerScreen)
            renderContext.translate(210f, 0f)
    
            renderContext.drawTrianglesStrip(triangles, 0, 8, linearGradientBrushPerScreen)
            renderContext.translate(210f, 0f)
    
            renderContext.drawTrianglesStrip(triangles, 0, 8, radialGradientBrushPerScreen)
            renderContext.translate(210f, 0f)
    
            renderContext.drawTrianglesStrip(triangles, 0, 8, textureBrushPerScreen)
            renderContext.translate(210f, 0f)
    
            renderContext.restore()
            renderContext.save()
            renderContext.translate(0f, 210f)
    
            renderContext.drawTrianglesStrip(triangles, 0, 8, solidBrushPerPrimitive)
            renderContext.translate(210f, 0f)
    
            renderContext.drawTrianglesStrip(triangles, 0, 8, linearGradientBrushPerPrimitive)
            renderContext.translate(210f, 0f)
    
            renderContext.drawTrianglesStrip(triangles, 0, 8, radialGradientBrushPerPrimitive)
            renderContext.translate(210f, 0f)
    
            renderContext.drawTrianglesStrip(triangles, 0, 8, textureBrushPerPrimitive)
            renderContext.translate(210f, 0f)
    
            sprite1.dispose()
            sprite2.dispose()
            sprite3.dispose()
        }
    }
    
    Back to top © 2011-2025 SciChart. All rights reserved. | sitemap.xml