Example #1
0
        public Tile(string filename, XElement properties)
        {
            ImageName  = Path.GetFileNameWithoutExtension(filename);
            BaseOffset = 15.0f;

            int centreX = 50, centreY = 30;

            if (properties != null)
            {
                foreach (var propElement in properties.Elements())
                {
                    switch (propElement.Attribute("name").Value)
                    {
                    case "centre-x":
                        centreX = Convert.ToInt32(propElement.Attribute("value").Value);
                        break;

                    case "centre-y":
                        centreY = Convert.ToInt32(propElement.Attribute("value").Value);
                        break;

                    case "exits":
                        ValidExits = ParseExits(propElement.Attribute("value").Value);
                        Console.WriteLine("Exits: {0} {1}", ImageName, ValidExits);
                        break;

                    default:
                        break;
                    }
                }
            }

            Centre = new CoreGraphics.CGPoint(centreX, centreY);
        }
Example #2
0
        /// <summary>
        /// Sets the location of the root view.
        /// </summary>
        /// <param name="frame">Frame.</param>
        private void SetLocation(RectangleF frame)
        {
            frame.Y = 0;
            _contentAreaView.Layer.AnchorPoint = new PointF(.5f, .5f);

            // exit if we're already at the desired location
            if (_contentAreaView.Frame.Location == frame.Location)
            {
                return;
            }

            frame.Size = _contentAreaView.Frame.Size;

            // set the root views cetner
            var center = new PointF(frame.Left + frame.Width / 2,
                                    frame.Top + frame.Height / 2);

            _contentAreaView.Center = center;

            // if x is greater than 0 then position the status view
            if (Math.Abs(frame.X - 0) > float.Epsilon)
            {
                GetStatusImage();
                var statusFrame = _statusImage.Frame;
                statusFrame.X      = _contentAreaView.Frame.X;
                _statusImage.Frame = statusFrame;
            }
        }
Example #3
0
 public override void ViewDidAppear(bool animated)
 {
     base.ViewDidAppear(animated);
     viewCenter = ViewHazne.Center;
     ViewAnimation();
     SetBackGround();
 }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            ((MasterDetailPage)Element).PropertyChanged += HandlePropertyChanged;

            var model = (MasterDetailPage)Element;

            if (!model.IsGestureEnabled)
            {
                if (_panGesture != null)
                {
                    View.RemoveGestureRecognizer(_panGesture);
                }
                return;
            }

            if (_panGesture != null)
            {
                View.AddGestureRecognizer(_panGesture);
                return;
            }

            UITouchEventArgs shouldReceive = (g, t) => !(t.View is UISlider);
            var center = new PointF();

            _panGesture = new UIPanGestureRecognizer(g =>
            {
                var detailRenderer  = Platform.GetRenderer(((MasterDetailPage)Element).Detail);
                var masterRenderer  = Platform.GetRenderer(((MasterDetailPage)Element).Master);
                var translation     = g.TranslationInView(View).X;
                var presented       = ((MasterDetailPage)Element).IsPresented;
                double openProgress = 0;
                double openLimit    = masterRenderer.ViewController.View.Frame.Width;

                if (presented)
                {
                    openProgress = 1 - (-translation / openLimit);
                }
                else
                {
                    openProgress = translation / openLimit;
                }

                openProgress = Math.Min(Math.Max(openProgress, 0.0), 1.0);
                switch (g.State)
                {
                case UIGestureRecognizerState.Changed:
                    LayoutViews(View.Bounds, (nfloat)openProgress, detailRenderer.ViewController.View);
                    break;
                }
            })
            {
                ShouldReceiveTouch     = shouldReceive,
                MaximumNumberOfTouches = 2
            };
            _panGesture.ShouldRecognizeSimultaneously = (gesture1, gesture2) => true;
            View.AddGestureRecognizer(_panGesture);
        }
Example #5
0
        public override void ViewDidAppear(bool animated)
        {
            base.ViewDidAppear(animated);
            viewCenter = ViewHazne.Center;

            //ViewAnimation();
            FillDataModel();
        }
Example #6
0
 public iOSPanEventArgs(UIPanGestureRecognizer gr, PanEventArgs previous, CoreGraphics.CGPoint locationAtStart)
 {
     Cancelled    = (gr.State == UIGestureRecognizerState.Cancelled || gr.State == UIGestureRecognizerState.Failed);
     ViewPosition = iOSEventArgsHelper.GetViewPosition(gr.View.Frame);
     Touches      = iOSEventArgsHelper.GetTouches(gr, locationAtStart);
     base.CalculateDistances(previous);
     Velocity = GetVelocity(gr);
 }
Example #7
0
        public override bool PointInside(CoreGraphics.CGPoint point, UIEvent uievent)
        {
            var margin       = -10f;
            var area         = this.Bounds;
            var expandedArea = area.Inset(margin, margin);

            return(expandedArea.Contains(point));
        }
        public override void WillEndDragging(UIScrollView scrollView, CoreGraphics.CGPoint velocity, ref CoreGraphics.CGPoint targetContentOffset)
        {
            var hv = appBar.HeaderViewController.HeaderView;

            if (scrollView == hv.TrackingScrollView)
            {
                hv.TrackingScrollViewWillEndDraggingWithVelocity(velocity, targetContentOffset);
            }
        }
 public void RaisePointerEvent(NSSet touches, PointerEventArgs.PointerEventType Type, bool PointerDown)
 {
     var touch = (UITouch)touches.AnyObject;
     PreviousPoint = touch.PreviousLocationInView(this);
     var newPoint = touch.LocationInView(this);
     InvokeOnMainThread(SetNeedsDisplay);
     PointerEvent?.Invoke(this, new PointerEventArgs(Type,
         PreviousPoint.ToPoint(), newPoint.ToPoint(), PointerDown));
 }
Example #10
0
        public ClusterView(IMKAnnotation annotation, string reuseIdentifier) : base(annotation, reuseIdentifier)
        {
            // Initialize
            DisplayPriority = MKFeatureDisplayPriority.DefaultHigh;
            CollisionMode   = MKAnnotationViewCollisionMode.Circle;

            // Offset center point to animate better with marker annotations
            CenterOffset = new CoreGraphics.CGPoint(0, -10);
        }
Example #11
0
        public override void SetContentOffset(CoreGraphics.CGPoint contentOffset, bool animated)
        {
            if (contentOffset.Y == -64)
            {
                contentOffset.Y = 0;
            }

            base.SetContentOffset(contentOffset, animated);
        }
Example #12
0
        public static void ShowContextMenu(Gtk.Widget parent, int x, int y, NSMenu menu, bool selectFirstItem = false)
        {
            if (parent == null)
            {
                throw new ArgumentNullException("parent");
            }
            if (menu == null)
            {
                throw new ArgumentNullException("menu");
            }

            parent.GrabFocus();

            Gtk.Application.Invoke((o, args) => {
                // Explicitly release the grab because the menu is shown on the mouse position, and the widget doesn't get the mouse release event
                Gdk.Pointer.Ungrab(Gtk.Global.CurrentEventTime);
                var nsview   = MonoDevelop.Components.Mac.GtkMacInterop.GetNSView(parent);
                var toplevel = parent.Toplevel as Gtk.Window;

                var nswindow = MonoDevelop.Components.Mac.GtkMacInterop.GetNSWindow(toplevel);

                int titleBarOffset;
                if (toplevel.TypeHint == Gdk.WindowTypeHint.Toolbar && toplevel.Type == Gtk.WindowType.Toplevel && toplevel.Decorated == false)
                {
                    // Undecorated toplevel toolbars are used for auto-hide pad windows. Don't add a titlebar offset for them.
                    titleBarOffset = 0;
                }
                else if (MonoDevelop.Ide.DesktopService.GetIsFullscreen(toplevel))
                {
                    titleBarOffset = 0;
                }
                else
                {
                    titleBarOffset = MonoDevelop.Components.Mac.GtkMacInterop.GetTitleBarHeight() + 12;
                }

                parent.TranslateCoordinates(parent.Toplevel, x, y, out x, out y);

                if (selectFirstItem)
                {
                    var pt = new CoreGraphics.CGPoint(x, y);
                    menu.PopUpMenu(menu.ItemAt(0), pt, nsview);
                }
                else
                {
                    var pt        = new CoreGraphics.CGPoint(x, nswindow.Frame.Height - y - titleBarOffset);
                    var tmp_event = NSEvent.MouseEvent(NSEventType.LeftMouseDown,
                                                       pt,
                                                       0, 0,
                                                       nswindow.WindowNumber,
                                                       null, 0, 0, 0);
                    NSMenu.PopUpContextMenu(menu, tmp_event, nsview);
                }
            });
        }
Example #13
0
        /// <summary>
        /// GestoreOrbit performs a gesture-based orbit about an anchorLocation to a location.
        /// </summary>
        public static void GestureOrbit(this ViewportInfo viewport, CGSize viewSize, CoreGraphics.CGPoint anchorLocation, CoreGraphics.CGPoint location)
        {
            var    screenWidth    = viewSize.Width;
            nfloat f              = (float)(Math.PI / screenWidth);
            nfloat horizontalDiff = anchorLocation.X - location.X;

            RotateLeftRight(viewport, (horizontalDiff * f));
            nfloat verticalDiff = anchorLocation.Y - location.Y;

            RotateUpDown(viewport, (verticalDiff * f));
        }
        private NSData CreatePdfFile(UIViewPrintFormatter printFormatter)
        {
            var renderer = new UIPrintPageRenderer();

            renderer.AddPrintFormatter(printFormatter, 0);
            var point = new CoreGraphics.CGPoint(0, 0);

            var paperSize     = new CoreGraphics.CGSize(this.Frame.Size.Width, this.Frame.Size.Height);
            var printableRect = new CoreGraphics.CGRect(point, new CoreGraphics.CGSize(paperSize.Width, paperSize.Height));
            var paperRect     = new CoreGraphics.CGRect(point, new CoreGraphics.CGSize(paperSize.Width, paperSize.Height));

            renderer.SetValueForKey(NSValue.FromCGRect(paperRect), new NSString("paperRect"));
            renderer.SetValueForKey(NSValue.FromCGRect(printableRect), new NSString("printableRect"));

            return(renderer.PrintToPDF(paperRect));
        }
Example #15
0
        void OnScrollToRequested(object sender, ScrollToRequestedEventArgs e)
        {
            _checkedForRtlScroll = true;

            if (Superview == null)
            {
                _requestedScroll = e;
                return;
            }

            PointF newOffset = PointF.Empty;

            if (e.Mode == ScrollToMode.Position)
            {
                newOffset = new PointF((nfloat)e.ScrollX, (nfloat)e.ScrollY);
            }
            else
            {
                var positionOnScroll = ScrollView.GetScrollPositionForElement(e.Element as VisualElement, e.Position);

                positionOnScroll.X = positionOnScroll.X.Clamp(0, ContentSize.Width - Bounds.Size.Width);
                positionOnScroll.Y = positionOnScroll.Y.Clamp(0, ContentSize.Height - Bounds.Size.Height);

                switch (ScrollView.Orientation)
                {
                case ScrollOrientation.Horizontal:
                    newOffset = new PointF((nfloat)positionOnScroll.X, ContentOffset.Y);
                    break;

                case ScrollOrientation.Vertical:
                    newOffset = new PointF(ContentOffset.X, (nfloat)positionOnScroll.Y);
                    break;

                case ScrollOrientation.Both:
                    newOffset = new PointF((nfloat)positionOnScroll.X, (nfloat)positionOnScroll.Y);
                    break;
                }
            }
            var sameOffset = newOffset == ContentOffset;

            SetContentOffset(newOffset, e.ShouldAnimate);

            if (!e.ShouldAnimate || sameOffset)
            {
                ScrollView.SendScrollFinished();
            }
        }
Example #16
0
        private static CALayer RenderImage(MultiPolygon multiPolygon, IStyle style, IViewport viewport)
        {
            var geom = new CAShapeLayer();

            if (!(style is VectorStyle))
            {
                throw new ArgumentException("Style is not of type VectorStyle");
            }
            var vectorStyle = style as VectorStyle;

            float strokeAlpha = (float)vectorStyle.Outline.Color.A / 255;
            float fillAlpha   = (float)vectorStyle.Fill.Color.A / 255;
            var   strokeColor = new CGColor(new CGColor(vectorStyle.Outline.Color.R, vectorStyle.Outline.Color.G,
                                                        vectorStyle.Outline.Color.B), strokeAlpha);
            var fillColor = new CGColor(new CGColor(vectorStyle.Fill.Color.R, vectorStyle.Fill.Color.G,
                                                    vectorStyle.Fill.Color.B), fillAlpha);

            geom.StrokeColor = strokeColor;
            geom.FillColor   = fillColor;
            geom.LineWidth   = (float)vectorStyle.Outline.Width;

            var bbRect = GeometryRenderer.ConvertBoundingBox(multiPolygon.GetBoundingBox(), viewport);
            var offset = new CoreGraphics.CGPoint((int)bbRect.GetMinX(), (int)bbRect.GetMinY());

            GeometryExtension.OffSet = offset;

            var path  = multiPolygon.ToUIKit(viewport);
            var frame = new CGRect(0, 0, (int)((float)bbRect.GetMaxX() - (float)bbRect.GetMinX()), (int)((float)bbRect.GetMaxY() - (float)bbRect.GetMinY()));
            var size  = frame.Size;

            geom.Path = path.CGPath;

            UIGraphics.BeginImageContext((CGSize)size);

            var context = UIGraphics.GetCurrentContext();

            context.SetBlendMode(CGBlendMode.Multiply);
            geom.RenderInContext(context);

            var image     = UIGraphics.GetImageFromCurrentImageContext();
            var imageTile = new CALayer {
                Contents = image.CGImage, Frame = frame
            };

            return(imageTile);
        }
Example #17
0
			public unsafe override void Draw (RectangleF rect)
			{
				var start = new PointF (rect.Left, rect.Bottom);
				var end = new PointF (rect.Left, rect.Top);

				var domain = new nfloat[] {0f, 1f};
				var range = new nfloat[] {0f, 1f, 0f, 1f};
				using (var context = UIGraphics.GetCurrentContext ())
				using (var rgb = CGColorSpace.CreateDeviceGray())
				using (var shadingFunction = new CGFunction(domain, range, Shading))
				using (var shading = CGShading.CreateAxial (rgb, start, end, shadingFunction, true, false))
				{
					context.DrawShading (shading);
				}

				base.Draw (rect);
			}
Example #18
0
        private void SetContentViewPosition()
        {
            var sidebarBounds = View.Bounds;

            if (IsOpen)
            {
                sidebarBounds.X = MenuWidth;
            }
            ContentAreaController.View.Layer.AnchorPoint = new PointF(.5f, .5f);
            if (ContentAreaController.View.Frame.Location.Equals(sidebarBounds.Location))
            {
                return;
            }
            var sidebarCenter = new PointF(sidebarBounds.Left + sidebarBounds.Width / 2, sidebarBounds.Top + sidebarBounds.Height / 2);

            ContentAreaController.View.Center = sidebarCenter;
        }
Example #19
0
        private static CALayer RenderImage(MultiPolygon multiPolygon, IStyle style, IViewport viewport)
        {
            var geom = new CAShapeLayer();

            if (!(style is VectorStyle)) throw new ArgumentException("Style is not of type VectorStyle");
            var vectorStyle = style as VectorStyle;

            float strokeAlpha = (float)vectorStyle.Outline.Color.A / 255;
            float fillAlpha = (float)vectorStyle.Fill.Color.A / 255;
            var strokeColor = new CGColor(new CGColor(vectorStyle.Outline.Color.R, vectorStyle.Outline.Color.G,
                                                      vectorStyle.Outline.Color.B), strokeAlpha);
            var fillColor = new CGColor(new CGColor(vectorStyle.Fill.Color.R, vectorStyle.Fill.Color.G,
                                                    vectorStyle.Fill.Color.B), fillAlpha);

            geom.StrokeColor = strokeColor;
            geom.FillColor = fillColor;
            geom.LineWidth = (float)vectorStyle.Outline.Width;

            var bbRect = GeometryRenderer.ConvertBoundingBox(multiPolygon.GetBoundingBox(), viewport);
            var offset = new CoreGraphics.CGPoint((int)bbRect.GetMinX(), (int)bbRect.GetMinY());

            GeometryExtension.OffSet = offset;

            var path = multiPolygon.ToUIKit(viewport);
            var frame = new CGRect(0, 0, (int)((float)bbRect.GetMaxX() - (float)bbRect.GetMinX()), (int)((float)bbRect.GetMaxY() - (float)bbRect.GetMinY()));
            var size = frame.Size;

            geom.Path = path.CGPath;

            UIGraphics.BeginImageContext((CGSize)size);

            var context = UIGraphics.GetCurrentContext();

            context.SetBlendMode(CGBlendMode.Multiply);
            geom.RenderInContext(context);

            var image = UIGraphics.GetImageFromCurrentImageContext();
            var imageTile = new CALayer { Contents = image.CGImage, Frame = frame };

            return imageTile;
        }
 public override void TouchesMoved(NSSet touches, UIEvent evt)
 {
     var touch = (UITouch)touches.AnyObject;
     var currentPoint = touch.LocationInView(this);
     if (Math.Abs(currentPoint.X - PreviousPoint.X) >= 4 ||
         Math.Abs(currentPoint.Y - PreviousPoint.Y) >= 4)
     {
         var newPoint = new PointF((currentPoint.X + PreviousPoint.X) / 2,
             (currentPoint.Y + PreviousPoint.Y) / 2);
         CurrentPath.AddQuadCurveToPoint(newPoint, PreviousPoint);
         PreviousPoint = currentPoint;
         InvokeOnMainThread(SetNeedsDisplay);
         PointerEvent?.Invoke(this, new PointerEventArgs(PointerEventArgs.
              PointerEventType.Move, PreviousPoint.ToPoint(), newPoint.ToPoint(), PointerDown));
     }
     else
     {
         CurrentPath.AddLineTo(currentPoint);
         InvokeOnMainThread(SetNeedsDisplay);
     }
 }
Example #21
0
File: Tile.cs Project: iainx/Walker
        public Tile(string filename, XElement properties)
        {
            ImageName = System.IO.Path.GetFileNameWithoutExtension (filename);

            Console.WriteLine ("filename: {0}", filename);
            Image = LoadImageAtCorrectSize (filename);
            if (Image == null) {
                Console.WriteLine ("Error loading image: {0}", filename);
            }
            // There's nowhere that we're going to draw this that isn't flipped
            //Image.Flipped = true;
            Console.WriteLine ("Tile size: {0}", Image.Size);
            BaseOffset = 15.0f;

            int centreX = 50, centreY = 30;
            if (properties != null) {
                foreach (var propElement in properties.Elements ()) {
                    switch (propElement.Attribute ("name").Value) {
                    case "centre-x":
                        centreX = Convert.ToInt32 (propElement.Attribute ("value").Value);
                        break;

                    case "centre-y":
                        centreY = Convert.ToInt32 (propElement.Attribute ("value").Value);
                        break;

                    case "exits":
                        ValidExits = ParseExits (propElement.Attribute ("value").Value);
                        Console.WriteLine ("Exits: {0}", ValidExits);
                        break;

                    default:
                        break;
                    }
                }
            }

            Centre = new CoreGraphics.CGPoint (centreX, centreY);
        }
 public override void TouchesBegan(NSSet touches, UIEvent evt)
 {
     IndexCount++;
     var path = new UIBezierPath
     {
         LineWidth = PenWidth
     };
     var touch = (UITouch)touches.AnyObject;
     PreviousPoint = touch.PreviousLocationInView(this);
     var newPoint = touch.LocationInView(this);
     path.MoveTo(newPoint);
     InvokeOnMainThread(SetNeedsDisplay);
     CurrentPath = path;
     var line = new VESLine
     {
         Path = CurrentPath,
         Color = CurrentLineColor,
         Index = IndexCount
     };
     Lines.Add(line);
     PointerDown = true;
     PointerEvent?.Invoke(this, new PointerEventArgs(PointerEventArgs.
          PointerEventType.Down, PreviousPoint.ToPoint(), newPoint.ToPoint(), PointerDown));
 }
Example #23
0
 public CGEvent(CGEventSource source, CGEventType mouseType, CGPoint mouseCursorPosition, CGMouseButton mouseButton)
 {
     handle = CGEventCreateMouseEvent(source == null ? IntPtr.Zero : source.Handle, mouseType, mouseCursorPosition, mouseButton);
 }
Example #24
0
 public static Point ToPoint(this PointF point)
 {
     return(new Point(point.X, point.Y));
 }
 private void SetContentViewPosition()
 {
     var sidebarBounds = View.Bounds;
     if (IsOpen)
         sidebarBounds.X = MenuWidth;
     ContentAreaController.View.Layer.AnchorPoint = new PointF(.5f, .5f);
     if (ContentAreaController.View.Frame.Location.Equals(sidebarBounds.Location))
         return;
     var sidebarCenter = new PointF(sidebarBounds.Left + sidebarBounds.Width / 2, sidebarBounds.Top + sidebarBounds.Height / 2);
     ContentAreaController.View.Center = sidebarCenter;
 }
Example #26
0
        /// <summary>
        /// Gets the view controller that will be displayed for a 3D Touch preview "peek".
        /// </summary>
        /// <returns>The view controller for preview.</returns>
        /// <param name="previewingContext">Previewing context.</param>
        /// <param name="location">Location.</param>
        public UIViewController GetViewControllerForPreview(IUIViewControllerPreviewing previewingContext, CoreGraphics.CGPoint location)
        {
            // Obtain the index path and the cell that was pressed.
            var indexPath = TableView.IndexPathForRowAtPoint(location);

            if (indexPath == null)
            {
                return(null);
            }

            // get the cell that is being pressed for preview "peeking"
            var cell = TableView.CellAt(indexPath);

            if (cell == null)
            {
                return(null);
            }

            // Create a detail view controller and set its properties.
            var detailViewController = Storyboard.InstantiateViewController("AcquaintanceDetailViewController") as AcquaintanceDetailViewController;

            if (detailViewController == null)
            {
                return(null);
            }

            // set the acquaintance on the view controller
            detailViewController.TeamMemberLite = _AcquaintanceTableViewSource.Acquaintances[indexPath.Row];

            // set the frame on the screen that will NOT be blurred out during the preview "peek"
            previewingContext.SourceRect = cell.Frame;

            return(detailViewController);
        }
Example #27
0
 public iOSDownUpEventArgs(DownUpGestureRecognizer gr, UITouch[] triggeringTouches, CoreGraphics.CGPoint viewLocationAtStart)
 {
     Cancelled         = (gr.State == UIGestureRecognizerState.Cancelled || gr.State == UIGestureRecognizerState.Failed);
     ViewPosition      = iOSEventArgsHelper.GetViewPosition(gr.View.Frame);
     Touches           = iOSEventArgsHelper.GetTouches(gr, viewLocationAtStart);
     TriggeringTouches = GetTriggeringTouches(gr, triggeringTouches, viewLocationAtStart);
 }
 public ClusterAnnotationView(IMKAnnotation annotation, string reuseIdentifier) : base(annotation, reuseIdentifier)
 {
     DisplayPriority = MKFeatureDisplayPriority.DefaultHigh;
     CollisionMode   = MKAnnotationViewCollisionMode.Circle;
     CenterOffset    = new CoreGraphics.CGPoint(0, -10);
 }
Example #29
0
#pragma warning disable IDE0060 // Remove unused parameter
        private int[] GetTriggeringTouches(DownUpGestureRecognizer gr, UITouch[] triggeringTouches, CoreGraphics.CGPoint locationAtStart)
#pragma warning restore IDE0060 // Remove unused parameter
        {
            Point[] array = Enumerable.ToArray <Point>(Enumerable.Select <UITouch, Point>(triggeringTouches, delegate(UITouch t) {
                CGPoint cGPoint = t.LocationInView(null);
                return(new Point(cGPoint.X - locationAtStart.X, cGPoint.Y - locationAtStart.Y));
            }));
            List <int> list = new List <int>();

            for (int i = 0; i < Touches.Length; i++)
            {
                Point t = Touches[i];
                if (Enumerable.Any <Point>(array, (Point p) => Math.Abs(p.X - t.X) < 0.1 && Math.Abs(p.Y - t.Y) < 0.1))
                {
                    list.Add(i);
                }
            }
            return(list.ToArray());
        }
Example #30
0
        partial void pcIntrolValueChange(UIPageControl sender)
        {
            var offset = new CoreGraphics.CGPoint(View.Frame.Width * sender.CurrentPage, 0);

            sv_Intro.SetContentOffset(offset, true);
        }
Example #31
0
 extern static IntPtr CGEventCreateMouseEvent(IntPtr source, CGEventType mouseType, CGPoint mouseCursorPosition, CGMouseButton mouseButton);
Example #32
0
        /// <summary>
        /// <para>Magnify/Zoom the Camera in a viewport</para>
        /// <para>method =</para>
        /// <para>0 performs a "dolly" magnification by moving the
        ///   camera along the camera direction vector so that
        ///   the amount of the screen subtended by an object
        ///   changes.</para>
        /// <para>1 performs a "zoom" magnification by adjusting the
        ///   "lens" angle</para>
        /// </summary>
        public static bool Magnify(this ViewportInfo viewport, CGSize viewSize, double magnifcationFactor, int method, CoreGraphics.CGPoint fixedScreenPoint)
        {
            if (viewport.IsCameraLocationLocked)
            {
                return(false);
            }

            var screenWidth  = viewSize.Width;
            var screenHeight = viewSize.Height;

            if (1 > screenWidth || 1 > screenHeight)
            {
                return(false);
            }

            // move camera toward target to magnify
            if (magnifcationFactor > 0)
            {
                // if the screen point is not in the viewport, then ignore it.
                if (!fixedScreenPoint.IsEmpty)
                {
                    if (fixedScreenPoint.X <= 0 || fixedScreenPoint.X >= screenWidth - 1 || fixedScreenPoint.Y <= 0 || fixedScreenPoint.Y >= screenHeight - 1)
                    {
                        fixedScreenPoint.X = 0;
                        fixedScreenPoint.Y = 0;
                    }
                }
                double frustumLeft   = viewport.FrustumLeft;
                double frustumRight  = viewport.FrustumRight;
                double frustumBottom = viewport.FrustumBottom;
                double frustumTop    = viewport.FrustumTop;
                double frustumNear   = viewport.FrustumNear;
                double frustumFar    = viewport.FrustumFar;
                double frustumWidth  = viewport.FrustumWidth;
                double frustumHeight = viewport.FrustumHeight;
                double d             = 0.0;

                // dolly camera towards target point...
                if (viewport.IsPerspectiveProjection && method == 0)
                {
                    const double miniumumTargetDistance = 0.000001;
                    var          cameraZ        = viewport.CameraZ;
                    var          cameraLocation = viewport.CameraLocation;
                    var          target         = viewport.TargetPoint;
                    double       targetDistance = (cameraLocation - target) * cameraZ;
                    if (targetDistance >= 0.0)
                    {
                        double delta = (1.0 - (1.0 / magnifcationFactor)) * targetDistance;
                        if (targetDistance - delta > miniumumTargetDistance)
                        {
                            cameraLocation = cameraLocation - (delta * cameraZ);
                            viewport.SetCameraLocation(cameraLocation);
                            if (!fixedScreenPoint.IsEmpty)
                            {
                                d              = targetDistance / viewport.FrustumNear;
                                frustumWidth  *= d;
                                frustumHeight *= d;
                                d              = (targetDistance - delta) / targetDistance;
                            }
                        }
                    }
                }
                if (method == 1)
                {
                    // parallel proj or "true" zoom
                    // apply magnification to frustum
                    d              = 1.0 / magnifcationFactor;
                    frustumLeft   *= d;
                    frustumRight  *= d;
                    frustumBottom *= d;
                    frustumTop    *= d;
                    viewport.SetFrustum(frustumLeft, frustumRight, frustumBottom, frustumTop, frustumNear, frustumFar);
                }

                if (!fixedScreenPoint.IsEmpty && Math.Abs(d) > Double.Epsilon)
                {
                    // lateral dolly to keep fixed_screen_point in same location on screen
                    Rhino.Geometry.Vector3d scale = new Rhino.Geometry.Vector3d(1.0, 1.0, 1.0);
                    scale.X = viewport.ViewScale.Width;
                    scale.Y = viewport.ViewScale.Height;
                    double fx = ((double)fixedScreenPoint.X / (double)screenWidth);
                    double fy = ((double)fixedScreenPoint.Y / (double)screenHeight);
                    double dx = ((0.5 - fx) * (1.0 - d) * frustumWidth) / scale.X;
                    double dy = ((fy - 0.5) * (1.0 - d) * frustumHeight) / scale.Y;
                    Rhino.Geometry.Vector3d dollyVector = dx * viewport.CameraX + dy * viewport.CameraY;
                    var cameraLocation = viewport.CameraLocation;
                    var target         = viewport.TargetPoint;
                    viewport.TargetPoint = target - dollyVector;
                    viewport.SetCameraLocation(cameraLocation - dollyVector);
                }
            }
            return(true);
        }
Example #33
0
        public override void WillEndDragging(UIScrollView scrollView, PointF velocity, ref PointF targetContentOffset)
        {
            if (ShouldIgnoreScrolling(scrollView))
            {
                return;
            }

            var rightwidth            = RightButtonsWidth;
            var leftwidth             = LeftButtonsWidth;
            var x                     = targetContentOffset.X;
            var parentThreshold       = scrollView.Frame.Width * .4f;
            var contentRightThreshold = rightwidth * .8f;
            var contentLeftThreshold  = leftwidth * .8f;

            if ((x >= parentThreshold || x >= contentRightThreshold) || (x <= -parentThreshold || x <= -contentLeftThreshold))
            {
                if (x >= parentThreshold || x >= contentRightThreshold)
                {
                    IsRightOpen         = true;
                    IsLeftOpen          = false;
                    targetContentOffset = new PointF(rightwidth, 0);
                }
                else if (x <= -parentThreshold || x <= -contentLeftThreshold)
                {
                    IsRightOpen         = false;
                    IsLeftOpen          = true;
                    targetContentOffset = new PointF(-leftwidth, 0);
                }

                RemoveHighlight(scrollView);

                if (_globalCloser == null)
                {
                    UIView view = scrollView;
                    while (view.Superview != null)
                    {
                        view = view.Superview;

                        NSAction close = () =>
                        {
                            if (UIDevice.CurrentDevice.CheckSystemVersion(8, 0))
                            {
                                RestoreHighlight(scrollView);
                            }

                            IsRightOpen = false;
                            IsLeftOpen  = false;

                            scrollView.SetContentOffset(new PointF(0, 0), true);

                            ClearCloserRecognizer(scrollView);
                        };

                        var table = view as UITableView;
                        if (table != null)
                        {
                            _table        = table;
                            _globalCloser = new GlobalCloseContextGestureRecognizer(scrollView, close);
                            _globalCloser.ShouldRecognizeSimultaneously = (recognizer, r) => r == _table.PanGestureRecognizer;
                            table.AddGestureRecognizer(_globalCloser);

                            _closer = new UITapGestureRecognizer(close);
                            var cell = GetContextCell(scrollView);
                            cell.AddGestureRecognizer(_closer);
                        }
                    }
                }
            }
            else
            {
                ClearCloserRecognizer(scrollView);

                IsRightOpen         = false;
                IsLeftOpen          = false;
                targetContentOffset = new PointF(0, 0);

                if (UIDevice.CurrentDevice.CheckSystemVersion(8, 0))
                {
                    RestoreHighlight(scrollView);
                }
            }
        }
		/// <summary>
		/// Sets the location of the root view.
		/// </summary>
		/// <param name="frame">Frame.</param>
		private void SetLocation(RectangleF frame)
		{
			frame.Y = 0;
			_contentAreaView.Layer.AnchorPoint = new PointF (.5f, .5f);

			// exit if we're already at the desired location
			if (_contentAreaView.Frame.Location == frame.Location)
				return;

			frame.Size = _contentAreaView.Frame.Size;

			// set the root views cetner
			var center = new PointF(frame.Left + frame.Width / 2,
				frame.Top + frame.Height / 2);
			_contentAreaView.Center = center;

			// if x is greater than 0 then position the status view
			if (Math.Abs(frame.X - 0) > float.Epsilon)
			{
				GetStatusImage();
				var statusFrame = _statusImage.Frame;
				statusFrame.X = _contentAreaView.Frame.X;
				_statusImage.Frame = statusFrame;
			}
		}