void ApplyTranslation(EvasMap map, ERect geometry, ref bool changed)
        {
            var shiftX = Forms.ConvertToScaledPixel(Element.TranslationX);
            var shiftY = Forms.ConvertToScaledPixel(Element.TranslationY);

            // apply translation, i.e. move/shift the object a little
            if (shiftX != 0 || shiftY != 0)
            {
                if (changed)
                {
                    // special care is taken to apply the translation last
                    Point3D p;
                    for (int i = 0; i < 4; i++)
                    {
                        p    = map.GetPointCoordinate(i);
                        p.X += shiftX;
                        p.Y += shiftY;
                        map.SetPointCoordinate(i, p);
                    }
                }
                else
                {
                    // in case when we only need translation, then construct the map in a simpler way
                    geometry.X += shiftX;
                    geometry.Y += shiftY;
                    map.PopulatePoints(geometry, 0);

                    changed = true;
                }
            }
        }
Beispiel #2
0
        void ApplyTransformation()
        {
            EvasMap map      = new EvasMap(4);
            Rect    geometry = _box1.Geometry;

            map.PopulatePoints(geometry, 0);

            map.Rotate3D(0, 0, _angle, (int)(geometry.X + geometry.Width * 0.5), (int)(geometry.Y + geometry.Height * 0.5), 0);

            Point3D p;

            for (int i = 0; i < 4; i++)
            {
                p    = map.GetPointCoordinate(i);
                p.X += _totalX;
                p.Y += _totalY;
                map.SetPointCoordinate(i, p);
            }
            _box1.EvasMap      = map;
            _box1.IsMapEnabled = true;
        }
Beispiel #3
0
        /*
         * void ApplyRotation(EvasMap map, Rect geometry, ref bool changed)
         * {
         *  var rotationX = Element.RotationX;
         *  var rotationY = Element.RotationY;
         *  var rotationZ = Element.Rotation;
         *  var anchorX = Element.AnchorX;
         *  var anchorY = Element.AnchorY;
         *
         *  // apply rotations
         *  if (rotationX != 0 || rotationY != 0 || rotationZ != 0)
         *  {
         *      map.Rotate3D(rotationX, rotationY, rotationZ, (int)(geometry.X + geometry.Width * anchorX),
         *                                                    (int)(geometry.Y + geometry.Height * anchorY), 0);
         *      changed = true;
         *  }
         * }
         *
         * void ApplyScale(EvasMap map, Rect geometry, ref bool changed)
         * {
         *  var scale = Element.Scale;
         *
         *  // apply scale factor
         *  if (scale != 1.0)
         *  {
         *      map.Zoom(scale, scale,
         *          geometry.X + (int)(geometry.Width * view.AnchorX),
         *          geometry.Y + (int)(geometry.Height * Element.AnchorY));
         *      changed = true;
         *  }
         * }
         *
         * void ApplyTranslation(EvasMap map, Rect geometry, ref bool changed)
         * {
         *  var shiftX = Forms.ConvertToScaledPixel(Element.TranslationX);
         *  var shiftY = Forms.ConvertToScaledPixel(Element.TranslationY);
         *
         *  // apply translation, i.e. move/shift the object a little
         *  if (shiftX != 0 || shiftY != 0)
         *  {
         *      if (changed)
         *      {
         *          // special care is taken to apply the translation last
         *          Point3D p;
         *          for (int i = 0; i < 4; i++)
         *          {
         *              p = map.GetPointCoordinate(i);
         *              p.X += shiftX;
         *              p.Y += shiftY;
         *              map.SetPointCoordinate(i, p);
         *          }
         *      }
         *      else
         *      {
         *          // in case when we only need translation, then construct the map in a simpler way
         *          geometry.X += shiftX;
         *          geometry.Y += shiftY;
         *          map.PopulatePoints(geometry, 0);
         *
         *          changed = true;
         *      }
         *  }
         * }
         */

        /// <summary>
        /// Set Matrix of view instance.
        /// </summary>
        internal static void SetMatrix(this EvasObject view, ReactNative.UIManager.MatrixMathHelper.MatrixDecompositionContext matrix, bool reset)
        {
            if (view == null)
            {
                throw new ArgumentNullException(nameof(view));
            }

            double TranslationX = 0;
            double TranslationY = 0;
            double rotationX    = 0;
            double rotationY    = 0;
            double rotationZ    = 0;
            double ScaleX       = 1;
            double ScaleY       = 1;

            if (matrix != null)
            {
                TranslationX = matrix.translation[0];
                TranslationY = matrix.translation[1];
                rotationX    = matrix.rotationDegrees[0];
                rotationY    = matrix.rotationDegrees[1];
                rotationZ    = matrix.rotationDegrees[2];
                ScaleX       = matrix.scale[0];
                ScaleY       = matrix.scale[1];
            }

            var map = new EvasMap(4);
            var g   = view.Geometry;

            map.PopulatePoints(g, 0);

            //setScale
            map.Zoom(ScaleX, ScaleY,
                     view.Geometry.X + (int)(view.Geometry.Width * 0.5),
                     view.Geometry.Y + (int)(view.Geometry.Height * 0.5));

            //setRotation
            map.Rotate3D(rotationX, rotationY, rotationZ,
                         (int)(view.Geometry.X + view.Geometry.Width * 0.5), (int)(view.Geometry.Y + view.Geometry.Height * 0.5), 0);

            //setTranslation
            var shiftX = TranslationX;
            var shiftY = TranslationY;

            Point3D p;

            for (int i = 0; i < 4; i++)
            {
                p    = map.GetPointCoordinate(i);
                p.X += (int)shiftX;
                p.Y += (int)shiftY;
                map.SetPointCoordinate(i, p);
            }

            view.EvasMap      = map;
            view.IsMapEnabled = true;

            if (!reset)
            {
                if (matrix != null)
                {
                    s_properties.GetOrCreateValue(view).matrix = matrix.Clone();
                }
            }
        }