Ejemplo n.º 1
0
        protected virtual void UpdateNativeWidget()
        {
            if (layer == null)
            {
                layer = Layer;
            }

            if (inputTransparent != node.InputTransparent)
            {
                UserInteractionEnabled = !node.InputTransparent;
                inputTransparent       = node.InputTransparent;
            }

            Frame             = new RectangleF((float)node.X, (float)node.Y, (float)node.Width, (float)node.Height);
            layer.AnchorPoint = new PointF((float)node.AnchorX, (float)node.AnchorY);
            layer.Opacity     = (float)node.Opacity;

            CATransform3D transform = CATransform3D.Identity;

            transform       = transform.Scale((float)node.Scale);
            transform.m34   = 1.0f / -400f;
            transform       = transform.Rotate((float)node.Rotation * (float)Math.PI / 180.0f, 0.0f, 0.0f, 1.0f);
            transform       = transform.Rotate((float)node.RotationX * (float)Math.PI / 180.0f, 1.0f, 0.0f, 0.0f);
            transform       = transform.Rotate((float)node.RotationY * (float)Math.PI / 180.0f, 0.0f, 1.0f, 0.0f);
            layer.Transform = transform;

            SetNeedsDisplay();
        }
        void ApplyRotation(UIView view, int factor)
        {
            CATransform3D rotationAndPerspectiveTransform = CATransform3D.Identity;

            rotationAndPerspectiveTransform.m34 = (nfloat)(1.0 / -5000);
            //view.Layer.AnchorPoint = new CGPoint(0.5, 0);
            double angle = Math.Sqrt((factor * factor)) * 45.0 / 50.0;

            rotationAndPerspectiveTransform = rotationAndPerspectiveTransform.Rotate((nfloat)(-(angle <= 45 ? angle : 45.0) * Math.PI / 180.0f), 1.0f, 0.0f, 0.0f);
            rotationAndPerspectiveTransform = rotationAndPerspectiveTransform.Scale(0.9f);
            view.Layer.Transform            = rotationAndPerspectiveTransform;
        }
Ejemplo n.º 3
0
            void ApplyMaskScale(float scale)
            {
                // ultimately this scales the layer from the center out (rather than top/left)

                // create a transform that translates the layer by half its width/height
                // and then scales it
                CATransform3D translateScale = new CATransform3D();

                translateScale = CATransform3D.Identity;
                translateScale = translateScale.Scale(scale);
                translateScale = translateScale.Translate(-(Label.Layer.Mask.Bounds.Width / 2), -(Label.Layer.Mask.Bounds.Height / 2), 0);

                // now apply a transform that puts it back by its width/height, effectively re-centering it.
                CATransform3D postScale = new CATransform3D();

                postScale = CATransform3D.Identity;
                postScale = postScale.Translate((Label.Layer.Mask.Bounds.Width / 2), (Label.Layer.Mask.Bounds.Height / 2), 0);

                // and now concat the post scale and apply
                Label.Layer.Mask.Transform = translateScale.Concat(postScale);
            }
Ejemplo n.º 4
0
        private void OnUpdateNativeControl(CALayer caLayer)
        {
            VisualElement view       = this.Renderer.Element;
            NSView        nativeView = this.Renderer.NativeView;

            if (view == null || view.Batched)
            {
                return;
            }
            if (this.inputTransparent != view.InputTransparent)
            {
                // TODO: WT.?
                //nativeView.UserInteractionEnabled = !view.InputTransparent;
                this.inputTransparent = view.InputTransparent;
            }
            bool   boundsChanged = this.lastBounds != view.Bounds;
            int    num           = boundsChanged ? 0 : (!caLayer.Frame.IsEmpty ? 1 : 0);
            float  anchorX       = (float)view.AnchorX;
            float  anchorY       = (float)view.AnchorY;
            float  translationX  = (float)view.TranslationX;
            float  translationY  = (float)view.TranslationY;
            float  rotationX     = (float)view.RotationX;
            float  rotationY     = (float)view.RotationY;
            float  rotation      = (float)view.Rotation;
            float  scale         = (float)view.Scale;
            float  width         = (float)view.Width;
            float  height        = (float)view.Height;
            float  x             = (float)view.X;
            float  y             = (float)view.Y;
            float  opacity       = (float)view.Opacity;
            bool   isVisible     = (view.IsVisible ? 1 : 0) != 0;
            int    updateTarget  = Interlocked.Increment(ref this.updateCount);
            Action action        = (Action)(() =>
            {
                if (updateTarget != this.updateCount)
                {
                    return;
                }
                VisualElement visualElement = view;
                Element parent = view.Parent;
                bool flag = false;
                if (isVisible && caLayer.Hidden)
                {
                    caLayer.Hidden = false;
                    if (!caLayer.Frame.IsEmpty)
                    {
                        flag = true;
                    }
                }
                if (!isVisible && !caLayer.Hidden)
                {
                    caLayer.Hidden = true;
                    flag = true;
                }
                CATransform3D caTransform3D = CATransform3D.Identity;
                if (((visualElement is Page && !(visualElement is ContentPage) || ((double)width <= 0.0 || (double)height <= 0.0) ? 0 : (parent != null ? 1 : 0)) & (boundsChanged ? 1 : 0)) != 0)
                {
                    RectangleF rectangleF = new RectangleF(x, y, width, height);
                    caLayer.Transform = caTransform3D;
                    caLayer.Frame = (CGRect)rectangleF;
                    if (flag)
                    {
                        caLayer.LayoutSublayers();
                    }
                }
                else if ((double)width <= 0.0 || (double)height <= 0.0)
                {
                    caLayer.Hidden = true;
                    return;
                }
                caLayer.AnchorPoint = (CGPoint) new PointF(anchorX, anchorY);
                caLayer.Opacity = opacity;
                if (Math.Abs((double)anchorX - 0.5) > 0.001)
                {
                    caTransform3D = caTransform3D.Translate((nfloat)((anchorX - 0.5f) * width), (nfloat)0, (nfloat)0);
                }
                if (Math.Abs((double)anchorY - 0.5) > 0.001)
                {
                    caTransform3D = caTransform3D.Translate((nfloat)0, (nfloat)((anchorY - 0.5f) * height), (nfloat)0);
                }
                if ((double)Math.Abs(translationX) > 0.001 || (double)Math.Abs(translationY) > 0.001)
                {
                    caTransform3D = caTransform3D.Translate((nfloat)translationX, (nfloat)translationY, (nfloat)0);
                }
                if ((double)Math.Abs(scale - 1f) > 0.001)
                {
                    caTransform3D = caTransform3D.Scale((nfloat)scale);
                }
                if ((double)Math.Abs(rotationY % 180f) > 0.001 || (double)Math.Abs(rotationX % 180f) > 0.001)
                {
                    caTransform3D.m34 = (nfloat)(-1.0 / 400.0);
                }
                if ((double)Math.Abs(rotationX % 360f) > 0.001)
                {
                    caTransform3D = caTransform3D.Rotate((nfloat)((float)((double)rotationX * 3.14159274101257 / 180.0)), (nfloat)1f, (nfloat)0.0f, (nfloat)0.0f);
                }
                if ((double)Math.Abs(rotationY % 360f) > 0.001)
                {
                    caTransform3D = caTransform3D.Rotate((nfloat)((float)((double)rotationY * 3.14159274101257 / 180.0)), (nfloat)0.0f, (nfloat)1f, (nfloat)0.0f);
                }
                caTransform3D = caTransform3D.Rotate((nfloat)((float)((double)rotation * 3.14159274101257 / 180.0)), (nfloat)0.0f, (nfloat)0.0f, (nfloat)1f);
                caLayer.Transform = caTransform3D;
            });

            // TODO: Figure this out

            /*
             * if (num != 0)
             *      CADisplayLinkTicker.Default.Invoke (action);
             * else
             */
            action();
            this.lastBounds = view.Bounds;
        }