Ejemplo n.º 1
0
        public static System.Numerics.Matrix3x2 ToMatrix3x2(this RawMatrix3x2 matrix)
        {
            Union u = _union;

            u.RawMatrix3x2 = matrix;
            return(u.Matrix3x2);
        }
Ejemplo n.º 2
0
        static public RawMatrix3x2 TransMatrixToRawMatrix3x2(System.Drawing.Drawing2D.Matrix m)
        {
            float[]      val       = m.Elements;
            RawMatrix3x2 rawMatrix = new RawMatrix3x2(val[0], val[1], val[2], val[3], val[4], val[5]);

            return(rawMatrix);
        }
Ejemplo n.º 3
0
        public Result DrawUnderline(object clientDrawingContext, float baselineOriginX, float baselineOriginY, ref Underline underline, ComObject clientDrawingEffect)
        {
            var rect = new SharpDX.RectangleF(0, underline.Offset, underline.Width, underline.Offset + underline.Thickness);
            var rectangleGeometry = new RectangleGeometry(_d2DFactory, rect);

            RawMatrix3x2 matrix = new RawMatrix3x2(
                1.0f, 0.0f,
                0.0f, 1.0f,
                baselineOriginX, baselineOriginY
                );


            var transformedGeometry = new TransformedGeometry(_d2DFactory, rectangleGeometry, matrix);

            var brushColor = (Color4)Color.Black;

            if (clientDrawingEffect != null && clientDrawingEffect is ColorDrawingEffect)
            {
                brushColor = (Color4)(clientDrawingEffect as ColorDrawingEffect).Color;
            }

            var brush = new SolidColorBrush(_renderTarget, brushColor);

            _renderTarget.DrawGeometry(transformedGeometry, brush);
            _renderTarget.FillGeometry(transformedGeometry, brush);

            rectangleGeometry.Dispose();
            transformedGeometry.Dispose();
            brush.Dispose();

            return(SharpDX.Result.Ok);
        }
Ejemplo n.º 4
0
        public void ComputeTransLastHitGeometry()
        {
            switch (scMgr.GraphicsType)
            {
            case GraphicsType.GDIPLUS:

                if (hitGraphicsPath == null)
                {
                    return;
                }

                transLastHitGraphicsPath = (GraphicsPath)hitGraphicsPath.Clone();
                transLastHitGraphicsPath.Transform(globalMatrix);
                break;

            case GraphicsType.D2D:

                if (hitPathGeometry == null)
                {
                    return;
                }

                SharpDX.Direct2D1.Factory d2dFactory = D2DGraphics.d2dFactory;
                RawMatrix3x2 m32 = GDIDataD2DUtils.TransMatrixToRawMatrix3x2(globalMatrix);
                transLastHitPathGeometry = new TransformedGeometry(d2dFactory, hitPathGeometry, m32);
                break;
            }
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Gets a transform attribute
 /// </summary>
 /// <param name="name">Attribute name</param>
 /// <param name="matrix">When this returns , contains the attribute value</param>
 public unsafe void GetAttributeValue(string name, out RawMatrix3x2 matrix)
 {
     fixed(RawMatrix3x2 *ptr = &matrix)
     {
         GetAttributeValue(name, SvgAttributePodType.Matrix, new IntPtr(ptr), sizeof(RawMatrix3x2));
     }
 }
Ejemplo n.º 6
0
        public override void CreateRealizations(DeviceContext1 deviceContext)
        {
            var matrix    = new RawMatrix3x2(Matrix3x2.Identity.M11, Matrix3x2.Identity.M12, Matrix3x2.Identity.M21, Matrix3x2.Identity.M22, Matrix3x2.Identity.M31, Matrix3x2.Identity.M32);
            var tolerance = D2D1.ComputeFlatteningTolerance(ref matrix, maxZoomFactor: 4);

            FilledRealization  = new GeometryRealization(deviceContext, Geometry, tolerance);
            StrokedRealization = new GeometryRealization(deviceContext, Geometry, tolerance, 1f, null);
        }
 public TCM_GraphicsObject(TCM_Graphics g)
 {
     transform     = new RawMatrix3x2(1, 0, 0, 1, 0, 0);
     frontChildren = new List <TCM_GraphicsObject>();
     backChildren  = new List <TCM_GraphicsObject>();
     parent        = null;
     graphics      = g;
 }
        public static RawVector2 transformPoint(float x, float y, RawMatrix3x2 transform)
        {
            RawVector2 output = new RawVector2();

            output.X = x * transform.M11 + y * transform.M21 + transform.M31;
            output.Y = x * transform.M12 + y * transform.M22 + transform.M32;

            return(output);
        }
Ejemplo n.º 9
0
 /// <summary>
 /// Converts the <see cref="RawMatrix3x2"/> to the equivalend float array.
 /// </summary>
 /// <param name="matrix">The matrix to convert.</param>
 /// <returns>The converted result array.</returns>
 private static float[] ToArray(RawMatrix3x2 matrix)
 {
     return(new[]
     {
         matrix.M11, matrix.M12,
         matrix.M21, matrix.M22,
         matrix.M31, matrix.M32,
     });
 }
Ejemplo n.º 10
0
 public Frame()
 {
     transform     = new RawMatrix3x2(1, 0, 0, 1, 0, 0);
     frontChildren = new List <Frame>();
     backChildren  = new List <Frame>();
     visuals       = new List <Visual>();
     hitboxes      = new List <Hitbox>();
     parent        = null;
 }
Ejemplo n.º 11
0
        public override void Transform(Matrix3x3 m)
        {
            currentTransform.Multiply(m);
            RawMatrix3x2 mat = new RawMatrix3x2(currentTransform[0], currentTransform[1],
                                                currentTransform[2], currentTransform[3],
                                                currentTransform[4], currentTransform[5]);

            renderTarget.Transform = mat;
        }
Ejemplo n.º 12
0
        public virtual void Render(RawMatrix3x2 transform, RawColor4 color)
        {
            this.SetColor(color);

            this.RenderTarget.Transform = transform;
            this.RenderTarget.FillGeometry(this.Geometry, this.Brush);

            this.RenderTarget.Transform = Helpers.Matrix3x2Helper.Identity;
        }
Ejemplo n.º 13
0
 /// <summary>
 /// Converts a Direct2D <see cref="RawMatrix3x2"/> to a Perspex <see cref="Perspex.Matrix"/>.
 /// </summary>
 /// <param name="matrix">The matrix</param>
 /// <returns>a <see cref="Perspex.Matrix"/>.</returns>
 public static Matrix ToPerspex(this RawMatrix3x2 matrix)
 {
     return(new Matrix(
                matrix.M11,
                matrix.M12,
                matrix.M21,
                matrix.M22,
                matrix.M31,
                matrix.M32));
 }
Ejemplo n.º 14
0
 /// <summary>
 /// Converts a Direct2D <see cref="RawMatrix3x2"/> to a Avalonia <see cref="Avalonia.Matrix"/>.
 /// </summary>
 /// <param name="matrix">The matrix</param>
 /// <returns>a <see cref="Avalonia.Matrix"/>.</returns>
 public static Matrix ToAvalonia(this RawMatrix3x2 matrix)
 {
     return(new Matrix(
                matrix.M11,
                matrix.M12,
                matrix.M21,
                matrix.M22,
                matrix.M31,
                matrix.M32));
 }
Ejemplo n.º 15
0
            /// <summary>
            /// transforms the screen space coordinates into a canonical coordinate system [-1, 1] with y up
            /// </summary>
            /// <param name="start">screen space start</param>
            /// <param name="end">screen space end</param>
            /// <returns>canonical transform</returns>
            public Transform SetCanonical(Float2 start, Float2 end)
            {
                RawMatrix3x2 t = new RawMatrix3x2(
                    (end.X - start.X) * 0.5f, 0.0f,                                        // column 1
                    0.0f, -(end.Y - start.Y) * 0.5f,                                       // column 2
                    (end.X - start.X) * 0.5f + start.X, (end.Y - start.Y) * 0.5f + start.Y // column 3
                    );

                return(new Transform(parent, t));
            }
Ejemplo n.º 16
0
 /// <summary>
 /// Initializes a new instance of the <see cref="LayerParameters1"/> struct.
 /// </summary>
 /// <param name="contentBounds">The content bounds.</param>
 /// <param name="geometryMask">The geometry mask.</param>
 /// <param name="maskAntialiasMode">The mask antialias mode.</param>
 /// <param name="maskTransform">The mask transform.</param>
 /// <param name="opacity">The opacity.</param>
 /// <param name="opacityBrush">The opacity brush.</param>
 /// <param name="layerOptions">The layer options.</param>
 public LayerParameters1(RawRectangleF contentBounds, Geometry geometryMask, AntialiasMode maskAntialiasMode, RawMatrix3x2 maskTransform, float opacity, Brush opacityBrush, LayerOptions1 layerOptions)
     : this()
 {
     ContentBounds     = contentBounds;
     GeometricMask     = geometryMask;
     MaskAntialiasMode = maskAntialiasMode;
     MaskTransform     = maskTransform;
     Opacity           = opacity;
     OpacityBrush      = opacityBrush;
     LayerOptions      = layerOptions;
 }
Ejemplo n.º 17
0
        public RawVector2[] getGlobalCorners()
        {
            RawVector2[] output    = new RawVector2[4];
            RawMatrix3x2 transform = getFullTransform();

            output[0] = TCM_Matrix3x2.transformPoint(boundingBox.Left, boundingBox.Top, transform);
            output[1] = TCM_Matrix3x2.transformPoint(boundingBox.Right, boundingBox.Top, transform);
            output[2] = TCM_Matrix3x2.transformPoint(boundingBox.Right, boundingBox.Bottom, transform);
            output[3] = TCM_Matrix3x2.transformPoint(boundingBox.Left, boundingBox.Bottom, transform);
            return(output);
        }
Ejemplo n.º 18
0
        /// <summary>
        /// Multiplies two RawMatrix3x2 objects as if they were 3x3 matrices, with the final column being (0,0,1).
        /// Can apply a transform 'a' onto a transform 'b'.
        /// </summary>
        /// <param name="a">The first matrix</param>
        /// <param name="b">The second matrix</param>
        /// <returns></returns>
        public static RawMatrix3x2 multiply(RawMatrix3x2 a, RawMatrix3x2 b)
        {
            RawMatrix3x2 output = new RawMatrix3x2();

            output.M11 = a.M11 * b.M11 + a.M12 * b.M21;
            output.M12 = a.M11 * b.M12 + a.M12 * b.M22;
            output.M21 = a.M21 * b.M11 + a.M22 * b.M21;
            output.M22 = a.M21 * b.M12 + a.M22 * b.M22;
            output.M31 = a.M31 * b.M11 + a.M32 * b.M21 + b.M31;
            output.M32 = a.M31 * b.M12 + a.M32 * b.M22 + b.M32;
            return(output);
        }
Ejemplo n.º 19
0
        /// <summary>
        /// 座標の回転・平行移動
        /// </summary>
        /// <param name="x">xの平行移動</param>
        /// <param name="y">yの平行移動</param>
        /// <param name="theta">回転角</param>
        /// <returns>座標変換の行列</returns>
        private RawMatrix3x2 TransrationMatrix(float x, float y, double theta)
        {
            //自分で書かないといけないのにキレそう
            var matrix = new RawMatrix3x2();

            matrix.M11 = (float)Math.Cos(theta);
            matrix.M12 = (float)Math.Sin(theta);
            matrix.M21 = (float)Math.Sin(theta) * (-1);
            matrix.M22 = (float)Math.Cos(theta);
            matrix.M31 = x;
            matrix.M32 = y;

            return(matrix);
        }
Ejemplo n.º 20
0
        /// <summary>
        /// Extension method for Matrix3x2 to conver to RawMatrix3x2
        /// </summary>
        /// <param name="self"></param>
        /// <returns></returns>
        public static RawMatrix3x2 ToRawMatrix3x2(this Matrix3x2 self)
        {
            RawMatrix3x2 raw = new RawMatrix3x2();

            raw.M11 = self.M11;
            raw.M12 = self.M12;

            raw.M21 = self.M21;
            raw.M22 = self.M22;

            raw.M31 = self.M31;
            raw.M32 = self.M32;

            return(raw);
        }
Ejemplo n.º 21
0
        // Token: 0x0600019C RID: 412 RVA: 0x00014410 File Offset: 0x00012610
        public void DrawTexture(string textureKey, RectangleF rect, float rotation = 0f, float opacity = 1f)
        {
            D3D11Texture texture = this.textureManager.GetTexture(textureKey);

            if (rotation == 0f)
            {
                this.context.RenderTarget.DrawBitmap(texture.Bitmap, rect, opacity, BitmapInterpolationMode.Linear);
                return;
            }
            RawMatrix3x2 transform = this.context.RenderTarget.Transform;
            Vector2      vector;

            vector..ctor(rect.Width / texture.Bitmap.Size.Width, rect.Height / texture.Bitmap.Size.Height);
            this.context.RenderTarget.Transform = Matrix3x2.Translation(-texture.Center) * Matrix3x2.Rotation(rotation) * Matrix3x2.Translation(texture.Center) * Matrix3x2.Scaling(vector) * Matrix3x2.Translation(rect.Location);
            this.context.RenderTarget.DrawBitmap(texture.Bitmap, opacity, BitmapInterpolationMode.Linear);
            this.context.RenderTarget.Transform = transform;
        }
Ejemplo n.º 22
0
        /// <summary>
        /// Computes the appropriate flattening tolerance to pass to APIs that take a flattening tolerance (for instance, <see cref="DeviceContext.CreateFilledGeometryRealization"/>).
        /// </summary>
        /// <param name="matrix">The matrix that will be applied subsequently to the geometry being flattened.</param>
        /// <param name="dpiX">The horizontal DPI of the render target that the geometry will be rendered onto (a choice of 96 implies no DPI correction).</param>
        /// <param name="dpiY">The vertical DPI of the render target that the geometry will be rendered onto (a choice of 96 implies no DPI correction).</param>
        /// <param name="maxZoomFactor">The maximum amount of additional scaling (on top of any scaling implied by the matrix or the DPI) that will be applied to the geometry.</param>
        /// <returns>The flattening tolerance.</returns>
        public static float ComputeFlatteningTolerance(ref RawMatrix3x2 matrix, float dpiX = DefaultDpi, float dpiY = DefaultDpi, float maxZoomFactor = 1f)
        {
            var scaleX = dpiX / DefaultDpi;
            var scaleY = dpiY / DefaultDpi;

            var dpiDependentTransform = new RawMatrix3x2
            {
                M11 = matrix.M11 * scaleX,
                M12 = matrix.M12 * scaleY,
                M21 = matrix.M21 * scaleX,
                M22 = matrix.M22 * scaleY,
                M31 = matrix.M31 * scaleX,
                M32 = matrix.M32 * scaleY
            };

            var absMaxZoomFactor = maxZoomFactor > 0f ? maxZoomFactor : -maxZoomFactor;

            return(DefaultFlatteningTolerance / (absMaxZoomFactor * ComputeMaximumScaleFactor(ref dpiDependentTransform)));
        }
Ejemplo n.º 23
0
        void Init()
        {
            _oriTransform = _rt.Transform;

            brush    = new SolidColorBrush(_rt, new SharpDX.Color(0, 255, 255));
            brushRed = new SolidColorBrush(_rt, SharpDX.Color.Red);

            formatNear = new TextFormat(_fdw, FontName, 32 * Scale)
            {
                TextAlignment      = TextAlignment.Leading,
                ParagraphAlignment = ParagraphAlignment.Center
            };
            formatCenter = new TextFormat(_fdw, FontName, 65 * Scale)
            {
                TextAlignment      = TextAlignment.Center,
                ParagraphAlignment = ParagraphAlignment.Center
            };

            _tyNear   = new TextLayout(_fdw, "", formatNear, Width, Height);
            _tyCenter = new TextLayout(_fdw, "", formatCenter, Width, Height);
        }
Ejemplo n.º 24
0
        public MainWindow()
        {
            keyboard          = new Keyboard();
            keyboard.KeyDown += OnKeyboardKeyDown;

            clearColor = new RawColor4(0f, 0f, 0f, 1f);
            textColor  = new RawColor4(1f, 1f, 1f, 1f);

            zoom           = 1f;
            zoomFactor     = 2f;
            minZoom        = 1f;
            maxZoom        = 64f;
            translation    = Vector2.Zero;
            identityMatrix = Matrix3x2.Identity;

            ticksPerFrame = 1;
            framesPerTick = 1;

            performanceMonitor = new PerformanceMonitor(TimeSpan.FromMilliseconds(1000));
            performaceText     = "0 FPS | 0 TPS";

            //fileSystemWatcher = new FileSystemWatcher {NotifyFilter = NotifyFilters.LastWrite};
            //fileSystemWatcher.Changed += OnFileSystemWatcherChanged;
        }
Ejemplo n.º 25
0
        static private RawMatrix3x2 MatrixMultiplication(RawMatrix3x2 x1, RawMatrix3x2 x2)
        {
            var result = new RawMatrix3x2(x1.M11 * x2.M11 + x1.M21 + x2.M12, x1.M11 * x2.M21 + x1.M21 * x2.M22, x1.M12 * x2.M11 + x1.M22 * x2.M12, x1.M12 * x2.M21 + x1.M22 * x2.M22, 0f, 0f);

            return(result);
        }
Ejemplo n.º 26
0
        static private RawMatrix3x2 BuildOrientationMatrix(double Radian)
        {
            var result = new RawMatrix3x2((float)Math.Cos(Radian), (float)Math.Sin(Radian), (float)-Math.Sin(Radian), (float)Math.Cos(Radian), 0f, 0f);

            return(result);
        }
Ejemplo n.º 27
0
 /// <summary>
 /// Sets the named property to the given value.
 /// </summary>
 /// <param name="index">Index of the property</param>
 /// <param name="value">Value of the property</param>
 /// <unmanaged>HRESULT ID2D1Properties::SetValue([In] const wchar_t* name,[In] D2D1_PROPERTY_TYPE type,[In, Buffer] const void* data,[In] unsigned int dataSize)</unmanaged>
 public unsafe void SetValue(int index, RawMatrix3x2 value)
 {
     SetValue(index, PropertyType.Matrix3x2, new IntPtr(&value), sizeof(RawMatrix3x2));
 }
Ejemplo n.º 28
0
        private Glyph ImportGlyph(Factory factory, FontFace fontFace, char character, FontMetrics fontMetrics, float fontSize, FontAntiAliasMode antiAliasMode)
        {
            var indices = fontFace.GetGlyphIndices(new int[] { character });

            var metrics = fontFace.GetDesignGlyphMetrics(indices, false);
            var metric  = metrics[0];

            var width  = (float)(metric.AdvanceWidth - metric.LeftSideBearing - metric.RightSideBearing) / fontMetrics.DesignUnitsPerEm * fontSize;
            var height = (float)(metric.AdvanceHeight - metric.TopSideBearing - metric.BottomSideBearing) / fontMetrics.DesignUnitsPerEm * fontSize;

            var xOffset = (float)metric.LeftSideBearing / fontMetrics.DesignUnitsPerEm * fontSize;
            var yOffset = (float)(metric.TopSideBearing - metric.VerticalOriginY) / fontMetrics.DesignUnitsPerEm * fontSize;

            var advanceWidth = (float)metric.AdvanceWidth / fontMetrics.DesignUnitsPerEm * fontSize;
            //var advanceHeight = (float)metric.AdvanceHeight / fontMetrics.DesignUnitsPerEm * fontSize;

            var pixelWidth  = (int)Math.Ceiling(width + 4);
            var pixelHeight = (int)Math.Ceiling(height + 4);

            var matrix = new RawMatrix3x2
            {
                M11 = 1,
                M22 = 1,
                M31 = -(float)Math.Floor(xOffset) + 1,
                M32 = -(float)Math.Floor(yOffset) + 1
            };

            Bitmap bitmap;

            if (char.IsWhiteSpace(character))
            {
                bitmap = new Bitmap(1, 1, PixelFormat.Format32bppArgb);
            }
            else
            {
                var glyphRun = new GlyphRun
                {
                    FontFace   = fontFace,
                    Advances   = new[] { (float)Math.Ceiling(advanceWidth) },
                    FontSize   = fontSize,
                    BidiLevel  = 0,
                    Indices    = indices,
                    IsSideways = false,
                    Offsets    = new[] { new GlyphOffset() }
                };


                RenderingMode renderingMode;
                if (antiAliasMode != FontAntiAliasMode.Aliased)
                {
                    var rtParams = new RenderingParams(factory);
                    renderingMode = fontFace.GetRecommendedRenderingMode(fontSize, 1.0f, MeasuringMode.Natural, rtParams);
                    rtParams.Dispose();
                }
                else
                {
                    renderingMode = RenderingMode.Aliased;
                }

                using (var runAnalysis = new GlyphRunAnalysis(factory,
                                                              glyphRun,
                                                              1.0f,
                                                              matrix,
                                                              renderingMode,
                                                              MeasuringMode.Natural,
                                                              0.0f,
                                                              0.0f))
                {
                    var bounds = new RawRectangle(0, 0, pixelWidth, pixelHeight);
                    bitmap = new Bitmap(pixelWidth, pixelHeight, PixelFormat.Format32bppArgb);

                    if (renderingMode == RenderingMode.Aliased)
                    {
                        var texture = new byte[pixelWidth * pixelHeight];
                        runAnalysis.CreateAlphaTexture(TextureType.Aliased1x1, bounds, texture, texture.Length);
                        for (int y = 0; y < pixelHeight; y++)
                        {
                            for (int x = 0; x < pixelWidth; x++)
                            {
                                int pixelX = y * pixelWidth + x;
                                var grey   = texture[pixelX];
                                var color  = Color.FromArgb(grey, grey, grey);

                                bitmap.SetPixel(x, y, color);
                            }
                        }
                    }
                    else
                    {
                        var texture = new byte[pixelWidth * pixelHeight * 3];
                        runAnalysis.CreateAlphaTexture(TextureType.Cleartype3x1, bounds, texture, texture.Length);
                        for (int y = 0; y < pixelHeight; y++)
                        {
                            for (int x = 0; x < pixelWidth; x++)
                            {
                                int pixelX = (y * pixelWidth + x) * 3;
                                var red    = LinearToGamma(texture[pixelX]);
                                var green  = LinearToGamma(texture[pixelX + 1]);
                                var blue   = LinearToGamma(texture[pixelX + 2]);
                                var color  = Color.FromArgb(red, green, blue);

                                bitmap.SetPixel(x, y, color);
                            }
                        }
                    }
                }
            }

            var glyph = new Glyph(character, bitmap)
            {
                XOffset  = -matrix.M31,
                XAdvance = advanceWidth,
                YOffset  = -matrix.M32,
            };

            return(glyph);
        }
Ejemplo n.º 29
0
 public static void Translation(float x, float y, out RawMatrix3x2 result)
 {
     result     = Identity;
     result.M31 = x;
     result.M32 = y;
 }
Ejemplo n.º 30
0
 public Transform(Direct2D parent, RawMatrix3x2 transform)
 {
     this.parent             = parent;
     original                = parent.target.Transform;
     parent.target.Transform = transform;
 }