Exemplo n.º 1
0
        protected override void render(ITextureView swapChainRgb, ITextureView swapChainDepthStencil)
        {
            iDrawDevice dev  = context.drawDevice;
            Rect        rect = new Rect(Vector2.Zero, dev.viewportSize);

            rect = rect.deflate(32, 32);

            using (var dc = dev.begin(swapChainRgb, swapChainDepthStencil, backgroundColor))
            {
                Matrix3x2 imageRotation = rotationMatrix(dev.viewportSize, -0.11f);
                Matrix3x2 trans         = Matrix3x2.CreateTranslation(0, -70);
                dc.transform.push(imageRotation * trans);
                dc.drawText("Hello World", comicSans.font, rect, black, background);
                dc.transform.pop();

                // rect.top += dev.dpiScaling.mulUnits * comicSans.font.lineHeightPixels + 12;
                rect.top += dev.dpiScaling.mulUnits * comicSans.font.lineHeightPixels + 24;

                CSize lipsumSize = dc.measureText(lipsum, rect.width, defaultSerif.font);
                dc.fillRectangle(pixelsRectangle(dev, rect.topLeft, lipsumSize), white);
                dc.drawText(lipsum, defaultSerif.font, rect, black, white); return;

                CSize consoleSize = dc.measureConsoleText(lipsum, 80, 14);

                // Apparently, when FreeType measures fonts it allocates height on the top for diacritic combining characters.
                Vector2 paddingTopLeft     = new Vector2(12, 2);
                Vector2 paddingBottomRight = new Vector2(12, 12);
                Vector2 size        = consoleSize.asFloat * dev.dpiScaling.mulUnits;
                Rect    consoleRect = new Rect(rect.topLeft, rect.topLeft + size + paddingTopLeft + paddingBottomRight);

                dc.fillRectangle(consoleRect, black);

                dc.drawConsoleText(lipsum, 80, 14, rect.topLeft + paddingTopLeft, green, black);
            }
        }
Exemplo n.º 2
0
        /// <summary>Create brush for console color.</summary>
        /// <remarks>Most named values are very different from createSolidBrush, the console colors are from CGA.
        /// For example, parsing "Green" string will get you #008000, ConsoleColor.Green returns #00FF00.</remarks>
        /// <seealso href="https://en.wikipedia.org/wiki/Color_Graphics_Adapter#With_an_RGBI_monitor" />
        /// <seealso href="https://docs.microsoft.com/en-us/dotnet/api/system.drawing.color?view=netcore-2.1" />
        public static iBrush createSolidBrush(this iDrawDevice device, ConsoleColor color)
        {
            if (device is DrawDevice vrmac)
            {
                return(new SolidColorBrush(color));
            }

            if (null == consoleColors)
            {
                consoleColors = PredefinedPaletteEntries.readPalette();
            }
            Vector4 vals = consoleColors[(int)color];

            return(device.createSolidColorBrush(vals));
        }
Exemplo n.º 3
0
 /// <summary>Create solid color brush from premultiplied RGBA values</summary>
 public static iSolidColorBrush createSolidBrush(this iDrawDevice device, Vector4 color)
 {
     return(device.createSolidColorBrush(ref color));
 }
Exemplo n.º 4
0
 /// <summary>Upload path data to VRAM</summary>
 public static iPathGeometry createPathGeometry(this iDrawDevice device, iPathData data)
 {
     return(data.createPathGeometry(device));
 }
Exemplo n.º 5
0
        /// <summary>Create solid color brush from color string like "blue" or "#ffccff44"</summary>
        public static iSolidColorBrush createSolidBrush(this iDrawDevice device, string colorString)
        {
            Vector4 color = Color.parseNonPremultiplied(colorString);

            return(device.createSolidColorBrush(ref color));
        }
Exemplo n.º 6
0
        /// <summary>Creates a D2D mesh from a pair of readonly spans</summary>
        public static id2Mesh createMesh(this iDrawDevice device, ReadOnlySpan <Vector2> vertices, ReadOnlySpan <ushort> indices)
        {
            sMeshDataSize mds = new sMeshDataSize(vertices.Length, indices.Length / 3);

            return(device.createMesh(ref MemoryMarshal.GetReference(vertices), ref MemoryMarshal.GetReference(indices), mds));
        }
Exemplo n.º 7
0
 public DrawContext(Draw.iDrawDevice vrmacDevice, iDrawDevice d2dDevice)
 {
     this.vrmacDevice = vrmacDevice;
     device           = d2dDevice;
 }
Exemplo n.º 8
0
 /// <summary>Parse string to color, and create a new solid color brush of that color.</summary>
 public static iBrush createSolidBrush(this iDrawDevice device, string colorString)
 {
     return(device.createSolidColorBrush(device.parseBrushColor(colorString)));
 }
Exemplo n.º 9
0
 /// <summary>Parse brush color from string</summary>
 public static Vector4 parseBrushColor(this iDrawDevice device, string colorString)
 {
     return(device.premultipliedAlphaBrushes ? Color.parse(colorString) : Color.parseNonPremultiplied(colorString));;
 }
Exemplo n.º 10
0
        Rect pixelsRectangle(iDrawDevice dev, Vector2 topLeft, CSize sizePx, Vector2 padding = default)
        {
            Vector2 size = sizePx.asFloat * dev.dpiScaling.mulUnits;

            return(new Rect(topLeft, topLeft + size + padding));
        }