public void setPoints(CGPoint[] points) { pathSet = true; path.AddLines(points); pointsList = points; SetNeedsDisplay(); }
/// <summary> /// Called when the fingers move /// </summary> public override void TouchesMoved (NSSet touches, UIEvent evt) { base.TouchesMoved (touches, evt); // if we haven't already failed if (base.State != UIGestureRecognizerState.Failed) { // get the current and previous touch point CGPoint newPoint = (touches.AnyObject as UITouch).LocationInView (View); CGPoint previousPoint = (touches.AnyObject as UITouch).PreviousLocationInView (View); // if we're not already on the upstroke if (!strokeUp) { // if we're moving down, just continue to set the midpoint at // whatever point we're at. when we start to stroke up, it'll stick // as the last point before we upticked if (newPoint.X >= previousPoint.X && newPoint.Y >= previousPoint.Y) { midpoint = newPoint; } // if we're stroking up (moving right x and up y [y axis is flipped]) else if (newPoint.X >= previousPoint.X && newPoint.Y <= previousPoint.Y) { strokeUp = true; } // otherwise, we fail the recognizer else { base.State = UIGestureRecognizerState.Failed; } } } Console.WriteLine (base.State.ToString ()); }
public CalloutAnnotation(int count, CGRect rect, nfloat lineWidth, UIColor color) { Path = UIBezierPath.FromOval(rect); Path.LineWidth = lineWidth; var center = new CGPoint (rect.GetMidX(), rect.GetMidY()); Center = center; nfloat startAngle = (nfloat)(Math.PI * 0.75); nfloat endAngle = (nfloat)(Math.PI * 0.60); Clip = UIBezierPath.FromArc(center, center.X + lineWidth, startAngle, endAngle, true); Clip.AddLineTo(center); Clip.ClosePath(); Clip.LineWidth = lineWidth; Tail = new UIBezierPath (); Tail.MoveTo(new CGPoint (center.X - 11, center.Y + 9)); Tail.AddLineTo(new CGPoint (center.X - 11, center.Y + 18)); Tail.AddLineTo(new CGPoint (center.X - 3, center.Y + 13)); Tail.LineWidth = lineWidth; Rect = rect; Color = color; Count = count; }
private double GetSlope (CGPoint p1, CGPoint p2) { if ((p2.Y - p1.Y) != 0) return (p1.X - p2.X) / (p2.Y - p1.Y); else return double.PositiveInfinity; }
public BMarkerImageView(WeakReference parentView, CGPoint location) { WeakParent = parentView; _location = location; UserInteractionEnabled = true; Frame = new CGRect (Location.X - 22, Location.Y - 22, 44, 44); using (var image = UIImage.FromFile ("Images/icon_marker.png")) { Image = image; } _pan = new UIPanGestureRecognizer (() => { if ((_pan.State == UIGestureRecognizerState.Began || _pan.State == UIGestureRecognizerState.Changed) && (_pan.NumberOfTouches == 1)) { Center = _pan.LocationInView (_parent); Location = Center; _parent.SetNeedsDisplay (); } else if (_pan.State == UIGestureRecognizerState.Ended) { } }); _doubleTap = new UITapGestureRecognizer ((gesture) => Crop ()) { NumberOfTapsRequired = 2, NumberOfTouchesRequired = 1 }; AddGestureRecognizer (_pan); AddGestureRecognizer (_doubleTap); }
public override void ViewDidLoad () { base.ViewDidLoad (); var gravityBehavior = new UIGravityBehavior (square); var collisionBehavior = new UICollisionBehavior (square) { TranslatesReferenceBoundsIntoBoundary = true }; collisionBehavior.BeganBoundaryContact += (sender, e) => { ((UIView)e.DynamicItem).BackgroundColor = UIColor.LightGray; }; collisionBehavior.EndedBoundaryContact += (sender, e) => { ((UIView)e.DynamicItem).BackgroundColor = UIColor.Gray; }; var squareCenterPoint = new CGPoint (square.Center.X, square.Center.Y - 100); var attachmentBehavior = new UIAttachmentBehavior (square, squareCenterPoint) { Frequency = 1.0f, Damping = 0.1f }; redSquare.Center = attachmentBehavior.AnchorPoint; blueSquare.Center = new CGPoint (50.0f, 50.0f); Animator = new UIDynamicAnimator (View); Animator.AddBehaviors (attachmentBehavior, gravityBehavior, collisionBehavior); View.AddGestureRecognizer (new UIPanGestureRecognizer ((gesture) => { attachmentBehavior.AnchorPoint = gesture.LocationInView (View); redSquare.Center = attachmentBehavior.AnchorPoint; })); }
/// <summary> /// Called when the touches end or the recognizer state fails /// </summary> public override void Reset () { base.Reset (); strokeUp = false; midpoint = CGPoint.Empty; }
void Init (Tuple<GeoAnchor, GeoAnchor> anchors) { // To compute the distance between two geographical co-ordinates, we first need to // convert to MapKit co-ordinates fromAnchorFloorplanPoint = anchors.Item1.Pixel; fromAnchorMKPoint = MKMapPoint.FromCoordinate (anchors.Item1.LatitudeLongitude); MKMapPoint toAnchorMKPoint = MKMapPoint.FromCoordinate (anchors.Item2.LatitudeLongitude); // So that we can use MapKit's helper function to compute distance. // this helper function takes into account the curvature of the earth. var distanceBetweenPointsMeters = (nfloat)MKGeometry.MetersBetweenMapPoints (fromAnchorMKPoint, toAnchorMKPoint); var dx = anchors.Item1.Pixel.X - anchors.Item2.Pixel.X; var dy = anchors.Item1.Pixel.Y - anchors.Item2.Pixel.Y; // Distance between two points in pixels (on the floorplan image) var distanceBetweenPointsPixels = Hypot (dx, dy); // This gives us pixels/meter PixelsPerMeter = distanceBetweenPointsPixels / distanceBetweenPointsMeters; // Get the 2nd anchor's eastward/southward distance in meters from the first anchor point. var hyp = FetchRect (fromAnchorMKPoint, toAnchorMKPoint); // Angle of diagonal to east (in geographic) nfloat angleFromEastAndHypo = NMath.Atan2 (hyp.South, hyp.East); // Angle of diagonal to horizontal (in floorplan) nfloat angleFromXAndHypo = NMath.Atan2 (dy, dx); // Rotation amount from the geographic anchor line segment // to the floorplan anchor line segment // This is angle between X axis and East direction. This angle shows how you floor plan exists in real world radiansRotated = angleFromXAndHypo - angleFromEastAndHypo; }
public static NSLayoutConstraint[] SetCenter(UIView refView, UIView view, CGPoint centerPoint) { return new NSLayoutConstraint[] { NSLayoutConstraint.Create (view, NSLayoutAttribute.CenterX, NSLayoutRelation.Equal, refView, NSLayoutAttribute.Left, 1, centerPoint.X), NSLayoutConstraint.Create (view, NSLayoutAttribute.CenterY, NSLayoutRelation.Equal, refView, NSLayoutAttribute.Top, 1, centerPoint.Y) }; }
protected override bool CheckLimit (CGPoint contentOffset) { if (Subviews.Length == 0) return false; return Math.Abs (contentOffset.X) > Math.Abs (Limit); }
public Character(SKTexture texture, CGPoint position) : base(texture) { // standard sprite - there's no parallax UsesParallaxEffect = false; Initialize (position); }
protected internal override void NativeInit() { if (Parent != null) { if (this.NativeUIElement == null) { var scroll = new UIScrollView(); scroll.BackgroundColor = UIColor.Clear; this.NativeUIElement = scroll; this.NativeUIElement.ClipsToBounds = true; this.lastContentOfset = CGPoint.Empty; scroll.Scrolled += (sender, e) => { this.OnScrollChanged(new ScrollChangedEventArgs { VerticalOffset = scroll.ContentOffset.Y, HorizontalOffset = scroll.ContentOffset.X, VerticalChange = scroll.ContentOffset.Y - this.lastContentOfset.Y, HorizontalChange = scroll.ContentOffset.X - this.lastContentOfset.X, }); this.lastContentOfset = scroll.ContentOffset; }; } base.NativeInit(); } }
private void PlaceFeature (string message, CGPoint p, float offset) { // Create and configure a node with a text geometry, and add it to the scene var text = SCNText.Create (message, 5); text.Font = Font; text.Flatness = 0.4f; text.Materials = Materials; var textNode = SCNNode.Create (); textNode.Geometry = text; textNode.Position = new SCNVector3 (p.X, p.Y + Altitude, 0); textNode.Scale = new SCNVector3 (0.02f, 0.02f, 0.02f); ContentNode.AddChildNode (textNode); // Animation the node's position and opacity var positionAnimation = CABasicAnimation.FromKeyPath ("position.z"); positionAnimation.From = NSNumber.FromInt16 (-10); positionAnimation.To = NSNumber.FromInt16 (10); positionAnimation.Duration = 5.0f; positionAnimation.TimeOffset = -offset * positionAnimation.Duration; positionAnimation.RepeatCount = float.MaxValue; textNode.AddAnimation (positionAnimation, new NSString ("positionAnimation")); var opacityAnimation = CAKeyFrameAnimation.GetFromKeyPath ("opacity"); opacityAnimation.KeyTimes = new NSNumber[] { 0.0f, 0.2f, 0.9f, 1.0f }; opacityAnimation.Values = new NSNumber[] { 0.0f, 1.0f, 1.0f, 0.0f }; opacityAnimation.Duration = positionAnimation.Duration; opacityAnimation.TimeOffset = positionAnimation.TimeOffset; opacityAnimation.RepeatCount = float.MaxValue; textNode.AddAnimation (opacityAnimation, new NSString ("opacityAnimation")); }
/// <summary> /// Adds the text. /// </summary> /// <param name="image">The image.</param> /// <param name="text">The text.</param> /// <param name="point">The point.</param> /// <param name="font">The font.</param> /// <param name="color">The color.</param> /// <param name="alignment">The alignment.</param> /// <returns>UIImage.</returns> public static UIImage AddText( this UIImage image, string text, CGPoint point, UIFont font, UIColor color, UITextAlignment alignment = UITextAlignment.Left) { //var labelRect = new RectangleF(point, new SizeF(image.Size.Width - point.X, image.Size.Height - point.Y)); var h = text.StringHeight(font, image.Size.Width); var labelRect = new CGRect(point, new CGSize(image.Size.Width - point.X, h)); var label = new UILabel(labelRect) { Font = font, Text = text, TextColor = color, TextAlignment = alignment, BackgroundColor = UIColor.Clear }; var labelImage = label.ToNativeImage(); using (var context = image.Size.ToBitmapContext()) { var rect = new CGRect(new CGPoint(0, 0), image.Size); context.DrawImage(rect, image.CGImage); context.DrawImage(labelRect, labelImage.CGImage); context.StrokePath(); return UIImage.FromImage(context.ToImage()); } }
void HandlePanGesture (UIPanGestureRecognizer gesture) { if (gesture.State == UIGestureRecognizerState.Began) { gestureStartingPoint = gesture.TranslationInView (textView); gestureStartingCenter = imageView.Center; } else if (gesture.State == UIGestureRecognizerState.Changed) { CGPoint currentPoint = gesture.TranslationInView(textView); nfloat distanceX = currentPoint.X - gestureStartingPoint.X; nfloat distanceY = currentPoint.Y - gestureStartingPoint.Y; CGPoint newCenter = gestureStartingCenter; newCenter.X += distanceX; newCenter.Y += distanceY; imageView.Center = newCenter; textView.TextContainer.ExclusionPaths = TranslatedBezierPath (); } else if (gesture.State == UIGestureRecognizerState.Ended) { gestureStartingPoint = new CGPoint (0, 0); gestureStartingCenter = new CGPoint (0, 0); } }
// Use CGPoint.TryParse (NSDictionary, out CGPoint) instead in the Unified API. // Not sure how to best advice Classic API users here, since the method does // not exist in the Classic API (so an Obsolete method can't point anywhere). public static bool ToPoint(this NSDictionary dictionary, out CGPoint point) { if (dictionary == null) throw new ArgumentNullException ("dictionary"); return CGPointMakeWithDictionaryRepresentation (dictionary.Handle, out point); }
public override void ViewDidLoad () { base.ViewDidLoad (); // set the background color of the view to white View.BackgroundColor = UIColor.White; // instantiate a new image view that takes up the whole screen and add it to // the view hierarchy CGRect imageViewFrame = new CGRect (0, -NavigationController.NavigationBar.Frame.Height, View.Frame.Width, View.Frame.Height); imageView = new UIImageView (imageViewFrame); View.AddSubview (imageView); // create our offscreen bitmap context // size CGSize bitmapSize = new CGSize (View.Frame.Size); using (CGBitmapContext context = new CGBitmapContext (IntPtr.Zero, (int)bitmapSize.Width, (int)bitmapSize.Height, 8, (int)(4 * bitmapSize.Width), CGColorSpace.CreateDeviceRGB (), CGImageAlphaInfo.PremultipliedFirst)) { // declare vars UIImage apressImage = UIImage.FromFile ("icon-114.png"); CGPoint imageOrigin = new CGPoint ((imageView.Frame.Width / 2) - (apressImage.CGImage.Width / 2), (imageView.Frame.Height / 2) - (apressImage.CGImage.Height / 2)); CGRect imageRect = new CGRect (imageOrigin.X, imageOrigin.Y, apressImage.CGImage.Width, apressImage.CGImage.Height); // draw the image context.DrawImage (imageRect, apressImage.CGImage); // output the drawing to the view imageView.Image = UIImage.FromImage (context.ToImage ()); } }
public override UIView HitTest(CGPoint point, UIEvent uievent) { var hitView = base.HitTest(point, uievent); if (hitView == RootViewController.View) hitView = null; return hitView; }
public static SKShapeNode FromSplinePoints(CGPoint [] points) { if (points == null) throw new ArgumentNullException (nameof (points)); return FromSplinePoints (ref points[0], (nuint) points.Length); }
public override void ViewDidLoad () { base.ViewDidLoad (); var squareCenterPoint = new CGPoint (square.Center.X, square.Center.Y - 100.0f); var attachmentOffset = new UIOffset (-25.0f, -25.0f); /* By default, an attachment behavior uses the center of a view. By using a small offset, we get a more interesting effect which will cause the view to have rotation movement when dragging the attachment. */ var attachmentBehavior = new UIAttachmentBehavior (square, attachmentOffset, squareCenterPoint); // Show visually the attachment points redSquare.Center = attachmentBehavior.AnchorPoint; blueSquare.Center = new CGPoint (25.0f, 25.0f); Animator = new UIDynamicAnimator (View); Animator.AddBehavior (attachmentBehavior); View.AddGestureRecognizer (new UIPanGestureRecognizer ((gesture) => { attachmentBehavior.AnchorPoint = gesture.LocationInView (View); redSquare.Center = attachmentBehavior.AnchorPoint; })); }
private UIColor GetPixelColor(CGPoint point, UIImage image) { var rawData = new byte[4]; var handle = GCHandle.Alloc(rawData); UIColor resultColor = null; try { using (var colorSpace = CGColorSpace.CreateDeviceRGB()) { using (var context = new CGBitmapContext(rawData, 1, 1, 8, 4, colorSpace, CGImageAlphaInfo.PremultipliedLast)) { context.DrawImage(new CGRect(-point.X, point.Y - image.Size.Height, image.Size.Width, image.Size.Height), image.CGImage); float red = (rawData[0]) / 255.0f; float green = (rawData[1]) / 255.0f; float blue = (rawData[2]) / 255.0f; float alpha = (rawData[3]) / 255.0f; resultColor = UIColor.FromRGBA(red, green, blue, alpha); } } } finally { handle.Free(); } return resultColor; }
public override void Draw(CGRect rect) { using (CGContext context = UIGraphics.GetCurrentContext()) { switch (_Style) { case SIAlertViewBackgroundStyle.Gradient: { nfloat[] locations = { 0.0f, 1.0f }; nfloat[] colors = { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.75f }; CGGradient gradient = new CGGradient(CGColorSpace.CreateDeviceRGB(), colors, locations); CGPoint center = new CGPoint(Bounds.Size.Width / 2, Bounds.Size.Height / 2); nfloat radius = (nfloat)Math.Min(Bounds.Size.Width, Bounds.Size.Height); context.DrawRadialGradient(gradient, center, 0, center, radius, CGGradientDrawingOptions.DrawsAfterEndLocation); break; } case SIAlertViewBackgroundStyle.Solid: { UIColor.FromWhiteAlpha(0f, 0.5f).SetColor(); context.SetFillColor(UIColor.FromWhiteAlpha(0f, 0.5f).CGColor); context.FillRect(Bounds); break; } } } }
public override void AnimateTransition (IUIViewControllerContextTransitioning transitionContext) { _transitionContext = transitionContext; var containerView = transitionContext.ContainerView; FlashCardViewController toViewController; UIViewController fromViewController; if (Presenting) { fromViewController = transitionContext.GetViewControllerForKey (UITransitionContext.FromViewControllerKey) as UIViewController; toViewController = transitionContext.GetViewControllerForKey (UITransitionContext.ToViewControllerKey) as FlashCardViewController; } else { toViewController = transitionContext.GetViewControllerForKey (UITransitionContext.FromViewControllerKey) as FlashCardViewController; fromViewController = transitionContext.GetViewControllerForKey (UITransitionContext.ToViewControllerKey) as UIViewController; } if(Presenting) containerView.AddSubview(toViewController.View); var originRect = toViewController.SourceFrame; var circleRect = new CGRect (originRect.GetMidX(), originRect.GetMidY(), 10, 10); var circleMaskPathInitial = UIBezierPath.FromOval(circleRect); //(ovalInRect: button.frame); var extremePoint = new CGPoint(circleRect.X - toViewController.View.Bounds.Width, circleRect.Y - toViewController.View.Bounds.Height ); //CGRect.GetHeight (toViewController.view.bounds)); var radius = (float)Math.Sqrt((extremePoint.X * extremePoint.X) + (extremePoint.Y * extremePoint.Y)); var largeCircleRect = circleRect.Inset (-radius, -radius); var circleMaskPathFinal = UIBezierPath.FromOval (largeCircleRect); CGPath fromPath; CGPath toPath; if (Presenting) { fromPath = circleMaskPathInitial.CGPath; toPath = circleMaskPathFinal.CGPath; } else { var path = new CGPath (); fromPath = circleMaskPathFinal.CGPath; toPath = circleMaskPathInitial.CGPath; } var maskLayer = new CAShapeLayer(); maskLayer.Path = fromPath; if (Presenting) { toViewController.View.Layer.Mask = maskLayer; } else { toViewController.View.Layer.Mask = maskLayer; } var maskLayerAnimation = CABasicAnimation.FromKeyPath("path"); maskLayerAnimation.From = ObjCRuntime.Runtime.GetNSObject(fromPath.Handle); maskLayerAnimation.To = ObjCRuntime.Runtime.GetNSObject(toPath.Handle); maskLayerAnimation.Duration = this.TransitionDuration(transitionContext); _animDoneDelegate = new AnimDoneDelegate (transitionContext); maskLayerAnimation.Delegate = _animDoneDelegate; maskLayer.AddAnimation(maskLayerAnimation, "path"); }
public override UIView HitTest (CGPoint point, UIEvent uievent) { var view = base.HitTest (point, uievent); if (OnHitTest != null) { OnHitTest (view); } return view; }
// Конструктор по имени public BaseBeloteControl(String Name) { AnchorPoint = new CGPoint (0, 0); parent = null; Sprite = null; Enabled = true; this.Name = Name; }
private double GetIntersect (CGPoint p1, CGPoint p2) { double slope = GetSlope (p1, p2); CGPoint center = GetCenterPoint (p1, p2); if (double.IsPositiveInfinity (slope)) return 0; return center.Y - (slope * center.X); }
public override UIView HitTest (CGPoint point, UIEvent uievent) { UIView hitView = base.HitTest (point, uievent); if (hitView != null) Superview.BringSubviewToFront (this); return hitView; }
public static unsafe SCNGeometrySource FromTextureCoordinates(CGPoint [] texcoords) { if (texcoords == null) throw new ArgumentNullException ("texcoords"); fixed (CGPoint *ptr = &texcoords[0]) return FromTextureCoordinates ((IntPtr)ptr, texcoords.Length); }
private void OnSoloTap(UIGestureRecognizer gesture) { CGPoint touchPoint = new CGPoint (gesture.LocationInView(scrollView)); if(imageView.Frame.Contains(touchPoint)) { Console.WriteLine ("збс"); } }
public override bool PointInside (CGPoint point, UIEvent uievent) { // Quadrance as the square of the length requires less computation and cases var quadrance = Vector(Bounds.GetCenter (), point).Quadrance (); var maxQuadrance = NMath.Pow (Bounds.Width / 2, 2); return quadrance < maxQuadrance; }
public override void AwakeFromNib() { // center our fire horizontally on the view and 15px from the bottom var firePosition = new CGPoint(view.Bounds.Width / 2, 15); rootLayer = new CALayer { BackgroundColor = new CGColor(0, 0, 0) }; fireEmitter = new CAEmitterLayer { Position = firePosition, Mode = CAEmitterLayer.ModeOutline, Shape = CAEmitterLayer.ShapeLine, RenderMode = CAEmitterLayer.RenderAdditive, Size = CGSize.Empty, Cells = new [] { new CAEmitterCell { Name = "fire", // name the cell so that it can be animated later using keypaths EmissionLongitude = (float)Math.PI, BirthRate = 0, Velocity = 80, VelocityRange = 30, EmissionRange = 1.1f, AccelerationY = 200, ScaleSpeed = 0.3f, Color = new CGColor(0.8f, 0.4f, 0.2f, 0.10f), Contents = NSImage.ImageNamed("fire.png").CGImage } } }; smokeEmitter = new CAEmitterLayer { Position = firePosition, Mode = CAEmitterLayer.ModePoints, Cells = new [] { new CAEmitterCell { Name = "smoke", // name the cell so that it can be animated later using keypaths BirthRate = 11, EmissionLongitude = (float)Math.PI / 2, LifeTime = 0, Velocity = 40, VelocityRange = 20, EmissionRange = (float)Math.PI / 4, Spin = 1, SpinRange = 6, AccelerationY = 160, Scale = 0.1f, AlphaSpeed = -0.12f, ScaleSpeed = 0.7f, Contents = NSImage.ImageNamed("smoke.png").CGImage } } }; rootLayer.AddSublayer(smokeEmitter); rootLayer.AddSublayer(fireEmitter); view.Layer = rootLayer; view.WantsLayer = true; // Set the fire simulation to reflect the intial slider postion slidersChanged(this); // Force the view to update view.NeedsDisplay = true; }
public virtual NSObject GetAccessibilityHitTest(CGPoint pointOnScreen) { var gdkWindow = parent.GdkWindow; if (gdkWindow == null) { return(this); } var ptr = gdk_quartz_window_get_nswindow(gdkWindow.Handle); if (ptr == IntPtr.Zero) { return(this); } NSWindow nsWin = Runtime.GetNSObject <NSWindow> (ptr); CGRect screenRect = new CGRect(pointOnScreen.X, pointOnScreen.Y, 1, 1); CGRect windowRect = nsWin.ConvertRectFromScreen(screenRect); CGPoint pointInWindow = new CGPoint(windowRect.X, windowRect.Y); // Flip the y coords to Gtk origin nfloat halfWindowHeight = nsWin.ContentView.Frame.Height / 2; nfloat dy = pointInWindow.Y - halfWindowHeight; CGPoint pointInGtkWindow = new CGPoint(pointInWindow.X, halfWindowHeight - dy); int parentInWindowX, parentInWindowY; GetCoordsInWindow(parent, out parentInWindowX, out parentInWindowY); if (AccessibilityChildren == null) { return(this); } foreach (var o in AccessibilityChildren) { var proxy = o as RealAccessibilityElementProxy; if (proxy == null) { throw new Exception($"Unsupported type {o.GetType ()} inside AccessibilityElementProxy"); } if (proxy.AccessibilityHidden) { continue; } var frameInRealParent = proxy.realFrame; if (frameInRealParent.X + parentInWindowX < pointInGtkWindow.X && frameInRealParent.X + parentInWindowX + frameInRealParent.Width >= pointInGtkWindow.X && frameInRealParent.Y + parentInWindowY < pointInGtkWindow.Y && frameInRealParent.Y + parentInWindowY + frameInRealParent.Height >= pointInGtkWindow.Y) { return(proxy.GetAccessibilityHitTest(pointOnScreen)); } } return(this); }
/// <summary> /// Called when sliding has started on this Panel /// </summary> /// <param name="touchPosition">Touch position.</param> /// <param name="topViewCurrentFrame">Top view current frame.</param> public override void SlidingStarted(CGPoint touchPosition, CGRect topViewCurrentFrame) { _touchPositionStartXPosition = touchPosition.X; _topViewStartXPosition = topViewCurrentFrame.X; }
public virtual void AddAnnotation(global::CoreLocation.CLLocationCoordinate2D location, string name, CGPoint offset) { throw new PlatformNotSupportedException(Constants.WatchKitRemoved); }
UIEdgeInsets CenterPointEdgeInsetsForImageSize(CGSize size) { CGPoint p = new CGPoint(size.Width / 2f, size.Height / 2f); return(new UIEdgeInsets(p.Y, p.X, p.Y, p.X)); }
static Tuple <ControlCorner, CGPoint> Tuple(ControlCorner corner, CGPoint point) { return(new Tuple <ControlCorner, CGPoint> (corner, point)); }
void DisplayLayout( ) { // scale the image to match the view's width ScreenToImageScalar = (float)SourceImage.Size.Width / (float)ImageView.Bounds.Width; // get the scaled dimensions, maintaining aspect ratio float scaledImageWidth = (float)SourceImage.Size.Width * (1.0f / ScreenToImageScalar); float scaledImageHeight = (float)SourceImage.Size.Height * (1.0f / ScreenToImageScalar); // if the image's scaled down height would be greater than the device height, // recalc based on the height. if (scaledImageHeight > ImageView.Frame.Height) { ScreenToImageScalar = (float)SourceImage.Size.Height / (float)ImageView.Bounds.Height; scaledImageWidth = (float)SourceImage.Size.Width * (1.0f / ScreenToImageScalar); scaledImageHeight = (float)SourceImage.Size.Height * (1.0f / ScreenToImageScalar); } // calculate the image's starting X / Y location nfloat imageStartX = (ImageView.Frame.Width - scaledImageWidth) / 2; nfloat imageStartY = (ImageView.Frame.Height - scaledImageHeight) / 2; // now calculate the size of the cropper nfloat cropperWidth = scaledImageWidth; nfloat cropperHeight = scaledImageHeight; // get the image's aspect ratio so we can shrink down the cropper correctly nfloat aspectRatio = SourceImage.Size.Width / SourceImage.Size.Height; // if the cropper should be wider than it is tall (or square) if (CropAspectRatio <= 1.0f) { // then if the image is wider than it is tall, scale down the cropper's width if (aspectRatio > 1.0f) { cropperWidth *= 1 / aspectRatio; } // and the height should be scaled down from the width cropperHeight = cropperWidth * CropAspectRatio; } else { // the cropper should be taller than it is wide // so if the image is taller than it is wide, scale down the cropper's height if (aspectRatio < 1.0f) { cropperWidth *= 1 / aspectRatio; } // and the width should be scaled down from the height. (Invert CropAspectRatio since it was Width based) cropperWidth = cropperHeight * (1 / CropAspectRatio); } // set the crop bounds CropView.Frame = new CGRect(ImageView.Frame.X, ImageView.Frame.Y, cropperWidth, cropperHeight); // Now set the min / max movement bounds for the cropper CropViewMinPos = new CGPoint(imageStartX, imageStartY); CropViewMaxPos = new CGPoint((imageStartX + scaledImageWidth) - cropperWidth, (imageStartY + scaledImageHeight) - cropperHeight); // center the cropview CropView.Layer.Position = new CGPoint(0, 0); MoveCropView(new CGPoint(ImageView.Bounds.Width / 2, ImageView.Bounds.Height / 2)); // setup the mask that will reveal only the part of the image that will be cropped FullscreenBlocker.Layer.Opacity = 0.00f; UIBezierPath viewFill = UIBezierPath.FromRect(FullscreenBlocker.Bounds); UIBezierPath cropMask = UIBezierPath.FromRoundedRect(new CGRect((FullscreenBlocker.Bounds.Width - CropView.Bounds.Width) / 2, (FullscreenBlocker.Bounds.Height - CropView.Bounds.Height) / 2, CropView.Bounds.Width, CropView.Bounds.Height), 4); viewFill.AppendPath(cropMask); FullscreenBlockerMask.Path = viewFill.CGPath; // and set our source image ImageView.Image = SourceImage; }
private UIBezierPath CreatePath(int interval = 0) { var path = new UIBezierPath(); var gridLinesHorizontal = Bounds.Width / HorizontalItemSize; var gridLinesVertical = Bounds.Height / VerticalItemSize; if (GridOrigin == DebugGridOrigin.TopLeft) { for (int i = 0; i < gridLinesHorizontal; i++) { if (interval == 0 || i % interval == 0) { var start = new CGPoint(x: (nfloat)i * HorizontalItemSize, y: 0); var end = new CGPoint(x: (nfloat)i * HorizontalItemSize, y: Bounds.Height); path.MoveTo(start); path.AddLineTo(end); } } for (int i = 0; i < gridLinesVertical; i++) { if (interval == 0 || i % interval == 0) { var start = new CGPoint(x: 0, y: (nfloat)i * VerticalItemSize); var end = new CGPoint(x: Bounds.Width, y: (nfloat)i * VerticalItemSize); path.MoveTo(start); path.AddLineTo(end); } } path.ClosePath(); } else if (GridOrigin == DebugGridOrigin.Center) { var gridLinesHorizontalCenter = Bounds.Width / 2; var gridLinesVerticalCenter = Bounds.Height / 2; for (int i = 0; i < (gridLinesHorizontal / 2); i++) { if (interval == 0 || i % interval == 0) { var startRight = new CGPoint(x: gridLinesHorizontalCenter + ((nfloat)i * HorizontalItemSize), y: 0); var endRight = new CGPoint(x: gridLinesHorizontalCenter + ((nfloat)i * HorizontalItemSize), y: Bounds.Height); path.MoveTo(startRight); path.AddLineTo(endRight); var startLeft = new CGPoint(x: gridLinesHorizontalCenter - ((nfloat)i * HorizontalItemSize), y: 0); var endLeft = new CGPoint(x: gridLinesHorizontalCenter - ((nfloat)i * HorizontalItemSize), y: Bounds.Height); path.MoveTo(startLeft); path.AddLineTo(endLeft); } } for (int i = 0; i < (gridLinesVertical / 2); i++) { if (interval == 0 || i % interval == 0) { var startBottom = new CGPoint(x: 0, y: gridLinesVerticalCenter + ((nfloat)i * VerticalItemSize)); var endBottom = new CGPoint(x: Bounds.Width, y: gridLinesVerticalCenter + ((nfloat)i * VerticalItemSize)); path.MoveTo(startBottom); path.AddLineTo(endBottom); var startTop = new CGPoint(x: 0, y: gridLinesVerticalCenter - ((nfloat)i * VerticalItemSize)); var endTop = new CGPoint(x: Bounds.Width, y: gridLinesVerticalCenter - ((nfloat)i * VerticalItemSize)); path.MoveTo(startTop); path.AddLineTo(endTop); } } } return(path); }
void focus(CGPoint point) { CGPoint convertedFocusPoint = previewLayer.CaptureDevicePointOfInterestForPoint(point); sessionManager.AutoFocus(convertedFocusPoint); }
public static void ShowAnimationEffect(NSAnimationEffect animationEffect, CGPoint centerLocation, CGSize size, NSObject animationDelegate, Selector didEndSelector, IntPtr contextInfo) { NSShowAnimationEffect((nuint)(ulong)animationEffect, centerLocation, size, animationDelegate, didEndSelector, contextInfo); }
public override void TouchesBegan(NSSet touches, UIEvent evt) { isInertiaing = false; velocity = CGPoint.Empty; }
public static UIImage OverlayRectangles(UIImage uiImage, CGSize imageSize, VNFaceObservation[] observations) { nfloat fWidth = uiImage.Size.Width; nfloat fHeight = uiImage.Size.Height; CGColorSpace colorSpace = CGColorSpace.CreateDeviceRGB(); using (CGBitmapContext ctx = new CGBitmapContext(IntPtr.Zero, (nint)fWidth, (nint)fHeight, 8, 4 * (nint)fWidth, CGColorSpace.CreateDeviceRGB(), CGImageAlphaInfo.PremultipliedFirst)) { Console.WriteLine("Orientation:" + uiImage.Orientation); if (uiImage.Orientation == UIImageOrientation.Up) { // correct orientation ctx.DrawImage(new CGRect(0, 0, (double)fWidth, (double)fHeight), uiImage.CGImage); } else { // need to rotate image so that rectangle overlays match UIGraphics.BeginImageContextWithOptions(uiImage.Size, false, 0); uiImage.Draw(new CGRect(0, 0, (double)fWidth, (double)fHeight)); var img = UIGraphics.GetImageFromCurrentImageContext(); UIGraphics.EndImageContext(); ctx.DrawImage(new CGRect(0, 0, (double)fWidth, (double)fHeight), img.CGImage); } var count = 0; foreach (var o in observations) { // Draw rectangle var text = "Face: " + count++.ToString(); Console.WriteLine(o.BoundingBox + " " + o.Confidence); // Fudge/switch coordinates to match UIImage var topLeft = new CGPoint(o.BoundingBox.Left, o.BoundingBox.Top).Scaled(imageSize); var topRight = new CGPoint(o.BoundingBox.Left, o.BoundingBox.Bottom).Scaled(imageSize); var bottomLeft = new CGPoint(o.BoundingBox.Right, o.BoundingBox.Top).Scaled(imageSize); var bottomRight = new CGPoint(o.BoundingBox.Right, o.BoundingBox.Bottom).Scaled(imageSize); //set up drawing attributes ctx.SetStrokeColor(UIColor.Red.CGColor); ctx.SetLineWidth(10); //create geometry var path = new CGPath(); path.AddLines(new CGPoint[] { topLeft, topRight, bottomRight, bottomLeft }); path.CloseSubpath(); //add geometry to graphics context and draw it ctx.AddPath(path); ctx.DrawPath(CGPathDrawingMode.Stroke); // Draw text ctx.SelectFont("Helvetica", 60, CGTextEncoding.MacRoman); //Measure the text's width - This involves drawing an invisible string to calculate the X position difference float start, end, textWidth; //Get the texts current position start = (float)ctx.TextPosition.X; //Set the drawing mode to invisible ctx.SetTextDrawingMode(CGTextDrawingMode.Invisible); //Draw the text at the current position ctx.ShowText(text); //Get the end position end = (float)ctx.TextPosition.X; //Subtract start from end to get the text's width textWidth = end - start; ctx.SetFillColor(UIColor.Red.CGColor); //Set the drawing mode back to something that will actually draw Fill for example ctx.SetTextDrawingMode(CGTextDrawingMode.Fill); //Draw the text at given coords. ctx.ShowTextAtPoint(topLeft.X, topLeft.Y - 60, text); } return(UIImage.FromImage(ctx.ToImage())); } }
public override void DidFinishSwipeCell(TKListView listView, TKListViewCell cell, NSIndexPath indexPath, CGPoint offset) { Console.WriteLine("Did swipe cell at index: {0}", indexPath.Row); }
public override void DidSwipeCell(TKListView listView, TKListViewCell cell, NSIndexPath indexPath, CGPoint offset) { this.owner.AnimateButtonInCell(cell, offset); }
private CGPoint GetCenterPoint (CGPoint p1, CGPoint p2) { return new CGPoint ((p2.X + p1.X) / 2, (p2.Y + p1.Y) / 2); }
/// <summary> /// Determines if a slide is complete /// </summary> /// <returns>true</returns> /// <c>false</c> /// <param name="touchPosition">Touch position.</param> /// <param name="topViewCurrentFrame">Top view current frame.</param> public override bool SlidingEnded(CGPoint touchPosition, CGRect topViewCurrentFrame) { return(topViewCurrentFrame.X > (Size.Width / 2)); }
public override void Draw (CGRect rect) { float x = 105; float y = 105; float r = 100; float twopi = (2f * (float)Math.PI) * -1f; CGContext ctx = UIGraphics.GetCurrentContext (); //base circle UIColor.FromRGB (137, 136, 133).SetColor (); ctx.AddArc (x, y, r + 3, 0, twopi, true); ctx.FillPath (); //border circle UIColor.FromRGB (231, 231, 231).SetColor (); ctx.AddArc (x, y, r, 0, twopi, true); ctx.FillPath (); //Center circle UIColor.White.SetColor (); ctx.AddArc (x, y, r / 1.2f, 0, twopi, true); ctx.FillPath (); UIColor.Black.SetFill (); //fast NSString text = new NSString("Fast"); CGSize stringSize = text.GetSizeUsingAttributes(new UIStringAttributes { Font = font10 }); text.DrawString (new CGPoint (105 - r + 7, 105 + r / 2 - 28), stringSize.Width, font10, UILineBreakMode.TailTruncation); //Slow text = new NSString("Slow"); stringSize = text.GetSizeUsingAttributes(new UIStringAttributes { Font = font10 }); text.DrawString (new CGPoint (105 + r - 25, 105 - r / 2 + 20), stringSize.Width, font10, UILineBreakMode.TailTruncation); //pubnub UIColor.Red.SetFill (); text = new NSString("PubNub"); stringSize = text.GetSizeUsingAttributes(new UIStringAttributes { Font = font18b }); text.DrawString (new CGPoint ((r * 2 - stringSize.Width) / 2 + 5, y - r / 2f), stringSize.Width, font18b, UILineBreakMode.TailTruncation); //needle //double percentFromMaxValue = max / 100.0d; max = 1000; double percentFromMaxValue = max / 100.0d; if (lag > max) { lag = max; } //angle double invertLag = ((max - min) / 2 - lag) * 2 + lag; //Debug.WriteLine("lag: "+ lag.ToString() + " invlag:" + invLag.ToString()); double angle = 360 - Math.Round ((double)invertLag / percentFromMaxValue * (90 / 100.0f)) * Math.PI / 180.0; //double angle2 = 360 - Math.Round((double)lag / percentFromMaxValue* (90 / 100.0f)) * Math.PI / 180.0;; //Debug.WriteLine("lagangle: "+ angle.ToString() + " invLagangle" + angle2.ToString()); //double angle = WrapValue(lag, max); float distance = 80; CGPoint p = new CGPoint (distance * (float)Math.Cos (angle), distance * (float)Math.Sin (angle)); UIColor.Brown.SetStroke (); CGPath path1 = new CGPath (); ctx.SetLineWidth (3); CGPoint newPoint = new CGPoint (105 - p.X, 105 - p.Y); CGPoint[] linePoints = new CGPoint[] { newPoint, new CGPoint (105, 105) }; path1.AddLines (linePoints); path1.CloseSubpath (); ctx.AddPath (path1); ctx.DrawPath (CGPathDrawingMode.FillStroke); //caliberate UIColor.Brown.SetColor (); double theta = 0.0; for (int i = 0; i < 360; i++) { float bx4 = (float)(x - 4 + (r - 10) * (Math.Cos (theta * Math.PI / 180))); float by4 = (float)(y - 15 + (r - 10) * (Math.Sin (theta * Math.PI / 180))); NSString dotText = new NSString("."); if ((theta > 160) && (theta < 350)) { UIColor.Black.SetColor (); dotText.DrawString (new CGPoint (bx4, by4), (dotText.GetSizeUsingAttributes(new UIStringAttributes { Font = font18b })).Width, font18b, UILineBreakMode.TailTruncation); } else if (((theta >= 0) && (theta < 40)) || ((theta >= 350) && (theta <= 360))) { //redline UIColor.Red.SetColor (); dotText.DrawString (new CGPoint (bx4, by4), (dotText.GetSizeUsingAttributes(new UIStringAttributes { Font = font18b })).Width, font18b, UILineBreakMode.TailTruncation); } theta += 10.0; } //small circle UIColor.FromRGB (220, 214, 194).SetColor (); //ctx.AddArc (x, y+y*.33f, r/1.5f, 0, twopi, true ); ctx.AddArc (x, y + r / 2f, r / 2f, 0, twopi, true); ctx.FillPath (); //speed in small circle UIColor.Black.SetFill (); NSString lagText = new NSString (Convert.ToInt32 (lag).ToString ()); stringSize = lagText.GetSizeUsingAttributes(new UIStringAttributes { Font = font18b }); lagText.DrawString (new CGPoint ((r * 2 - stringSize.Width) / 2 + 4, y + r / 2f - 15), stringSize.Width, font18b, UILineBreakMode.TailTruncation); //ms UIColor.Black.SetFill (); NSString msText = new NSString ("MS"); stringSize = msText.GetSizeUsingAttributes(new UIStringAttributes { Font = font18b }); msText.DrawString (new CGPoint ((r - stringSize.Width) / 2 + 55, y + r / 2f + 10), stringSize.Width, font18b, UILineBreakMode.TailTruncation); }
public static Point ToTogglPoint(this CGPoint point) => new Point { X = point.X, Y = point.Y };
private void OnPan(UIPanGestureRecognizer recognizer) { if (recognizer.State == UIGestureRecognizerState.Began || recognizer.State == UIGestureRecognizerState.Changed) { _isInitialized = true; var stepLength = _background.Frame.Width / ((MaxValue - MinValue) / Step); var touchPoint = recognizer.LocationInView(this); UIView indicator = null; UIView touchArea = null; //Is this a slide to left or right? if (recognizer == _leftIndicatorGesture) { indicator = _leftIndicator; touchArea = _leftTouchArea; } else if (recognizer == _rightIndicatorGesture) { indicator = _rightIndicator; touchArea = _rightTouchArena; } if (recognizer.State == UIGestureRecognizerState.Began) { _startX = (float)indicator.Center.X; } var cumulativeManipulation = touchPoint.X - _startX; var deltaManipulation = touchPoint.X - indicator.Center.X; if (deltaManipulation > 0 && cumulativeManipulation / stepLength > _lastStep || deltaManipulation < 0 && cumulativeManipulation / stepLength < _lastStep) { if (deltaManipulation > 0) { _lastStep++; } else { _lastStep--; } var numberOfSteps = Math.Ceiling(deltaManipulation / stepLength); var newPosition = new CGPoint(indicator.Center.X + stepLength * numberOfSteps, indicator.Center.Y); var pixelStep = (MaxValue - MinValue) / Frame.Width; if (touchPoint.X >= 0 && touchPoint.X <= _background.Frame.Width - 10) { if (recognizer == _leftIndicatorGesture) { var newLeftValue = Round(MinValue + (pixelStep * newPosition.X)); if (newLeftValue >= RightValue) { return; } } else if (recognizer == _rightIndicatorGesture) { var newRightValue = Round(MinValue + (pixelStep * newPosition.X)); if (newRightValue <= LeftValue) { return; } } if (recognizer == _leftIndicatorGesture) { indicator.Center = newPosition; touchArea.Center = newPosition; var width = _rightIndicator.Center.X - _leftIndicator.Center.X; _range.Frame = new CoreGraphics.CGRect(newPosition.X, _range.Frame.Y, width, _range.Frame.Height); } else if (recognizer == _rightIndicatorGesture) { indicator.Center = newPosition; touchArea.Center = newPosition; var width = _rightIndicator.Center.X - _leftIndicator.Center.X; _range.Frame = new CoreGraphics.CGRect(_range.Frame.X, _range.Frame.Y, width, _range.Frame.Height); } LeftValue = Round(MinValue + (pixelStep * _leftIndicator.Center.X)); RightValue = Round(MinValue + (pixelStep * _rightIndicator.Center.X)); if (ValueChanging != null) { ValueChanging(this, new EventArgs()); } } } } else if (recognizer.State == UIGestureRecognizerState.Ended) { if (ValueChanged != null) { ValueChanged(this, new EventArgs()); } _lastStep = 0; } }
public CGSize DrawString(CGPoint point, nfloat width, XamCore.UIKit.UIFont font, nfloat minFontSize, nfloat actualFontSize, XamCore.UIKit.UILineBreakMode breakMode, XamCore.UIKit.UIBaselineAdjustment adjustment) { nfloat temp = actualFontSize; return(DrawString(point, width, font, minFontSize, ref temp, breakMode, adjustment)); }
Point GetPositionFromEvent(NSEvent theEvent) { CGPoint p = theEvent.LocationInWindow; return(new Point((int)p.X, (int)View.Frame.Height - (int)p.Y)); }
public void ScrollToTop() { var point = new CGPoint(0, -ReportsTableView.ContentInset.Top); ReportsTableView.SetContentOffset(point, true); }
public override void TouchesMoved(Foundation.NSSet touches, UIEvent evt) { if (touches.Count == 1) { var touch = touches.First() as UITouch; var point = touch.LocationInView(this); var currentScrollOrientation = Math.Abs(GetTouchDistance(touch.Timestamp, point.X, _previousTouchPosition.X)) > Math.Abs(GetTouchDistance(touch.Timestamp, point.Y, _previousTouchPosition.Y)) ? ARNotificationScrollOrientation.FromRightToLeft : (point.Y < _previousTouchPosition.Y ? ARNotificationScrollOrientation.FromBottomToTop : ARNotificationScrollOrientation.FromTopToBottom); //if (_scrollOrientation == ARNotificationScrollOrientation.Unknown) // _scrollOrientation = currentScrollOrientation; //else if ((_scrollOrientation == ARNotificationScrollOrientation.FromLeftToRight || _scrollOrientation == ARNotificationScrollOrientation.FromRightToLeft) // && (currentScrollOrientation == ARNotificationScrollOrientation.FromLeftToRight || currentScrollOrientation == ARNotificationScrollOrientation.FromRightToLeft)) // _scrollOrientation = currentScrollOrientation; //else if ((_scrollOrientation == ARNotificationScrollOrientation.FromBottomToTop || _scrollOrientation == ARNotificationScrollOrientation.FromTopToBottom) // && (currentScrollOrientation == ARNotificationScrollOrientation.FromBottomToTop || currentScrollOrientation == ARNotificationScrollOrientation.FromTopToBottom)) //_scrollOrientation = currentScrollOrientation; Debug.WriteLine(point); Debug.WriteLine(_scrollOrientation); Debug.WriteLine(_previousTouchPosition); if (Frame.Y == 0 && point.X < _previousTouchPosition.X && currentScrollOrientation == ARNotificationScrollOrientation.FromRightToLeft) { var delta = _previousTouchPosition.X - point.X; this.ChangeFrame(x: Frame.X - delta); _scrollOrientation = currentScrollOrientation; } else if (Frame.X == 0 && point.Y < _previousTouchPosition.Y && currentScrollOrientation == ARNotificationScrollOrientation.FromBottomToTop) { var delta = _previousTouchPosition.Y - point.Y; this.ChangeFrame(y: Frame.Y - delta); _scrollOrientation = currentScrollOrientation; } else if (Frame.X == 0 && _alertType == ARNotificationType.Error && point.Y > _previousTouchPosition.Y && currentScrollOrientation == ARNotificationScrollOrientation.FromTopToBottom) { var delta = point.Y - _previousTouchPosition.Y; if (_realTextSize.Height > TEXT_VIEW_HEIGHT) { var newHeight = Frame.Height + delta; var maxHeight = (nfloat)Math.Min(_realTextSize.Height + TEXT_VIEW_OFFSET, DeviceInfo.ScreenHeight); this.ChangeFrame(h: newHeight > maxHeight ? maxHeight : newHeight); } _scrollOrientation = currentScrollOrientation; } _previousTouchPosition = point; } base.TouchesMoved(touches, evt); }
public override void LayoutSubviews() { if (_Collapsed) { _TitleButton.Frame = new CGRect(0, 0, Bounds.Width, _TopButtonSize); } else { _TitleButton.Frame = new CGRect(0, 0, Bounds.Width * 2.0f / 3.0f, _TopButtonSize); } _ClearHtmlButton.Frame = new CGRect(Bounds.Width * 2.0f / 3.0f, 0, Bounds.Width / 3.0f, _TopButtonSize); _OutputView.Frame = new CGRect(0, _TopButtonSize, Bounds.Width, Bounds.Height - _BottomSize - 1 - _TopButtonSize); _BottomView.Frame = new CGRect(0, Bounds.Height - _BottomSize, Bounds.Width, _BottomSize); CGSize sideSize = new CGSize(_BottomView.Bounds.Height, _SideButtonSize); _RollButton.Bounds = sideSize.OriginRect(); _RollButton.Center = new CGPoint(_SideButtonSize / 2.0f, _BottomView.Bounds.Height / 2.0f); _RollButton.Transform = CGAffineTransform.MakeRotation((float)Math.PI / 2.0f); _ClearButton.Bounds = sideSize.OriginRect(); _ClearButton.Center = new CGPoint(_BottomView.Bounds.Width - _SideButtonSize / 2.0f, _BottomView.Bounds.Height / 2.0f); _ClearButton.Transform = CGAffineTransform.MakeRotation((float)Math.PI / 2.0f); CGRect dieSpace = new CGRect(_SideButtonSize, 0, _BottomView.Bounds.Size.Width - _SideButtonSize * 2, _BottomView.Bounds.Size.Height - _TextHeight); CGSize dieSize = new CGSize(dieSpace.Width / 4, dieSpace.Height / 2); for (int i = 0; i < _DieButtons.Count; i++) { GradientButton b = (GradientButton)_DieButtons[i]; int column = i % 4; int row = i / 4; CGPoint p = new CGPoint(dieSpace.X + column * dieSize.Width, dieSpace.Y + dieSize.Height * row); CGSize s = dieSize; s.Width -= 2; p.X += 1; s.Height -= 2; p.Y += 1; b.Frame = new CGRect(p, s); if (b.BonusImage != null) { CGRect rect = b.BonusImage.Size.OriginRect(); rect.X = (b.Frame.Width - rect.Width) / 2.0f; rect.Y = 5; b.BonusImageRect = rect; } } _DieTextButton.Frame = new CGRect(_SideButtonSize, _BottomView.Bounds.Height - _TextHeight, dieSpace.Width, _TextHeight); }
public PostGameMenu(CGSize frameSize, IGameUIState gameStateDelegate) { GameStateDelegate = gameStateDelegate; nfloat menuHeight = frameSize.Height * 0.8f; var background = new SKSpriteNode(AppKit.NSColor.Black, new CGSize(frameSize.Width * 0.8f, menuHeight)); background.ZPosition = -1; background.Alpha = 0.5f; background.Position = new CGPoint(0, -0.2f * menuHeight); myLabel = InGameScene.LabelWithText("Final Score", 65); myLabel.Position = new CGPoint(Frame.GetMidX(), Frame.GetMidY()); Position = new CGPoint(frameSize.Width * 0.5f, frameSize.Height * 0.5f); UserInteractionEnabled = true; myLabel.UserInteractionEnabled = true; AddChild(myLabel); InGameScene.DropShadowOnLabel(myLabel); var bananaLocation = new CGPoint(frameSize.Width * -0.4f, Frame.GetMidY() * -0.4f); var coinLocation = new CGPoint(frameSize.Width * -0.4f, Frame.GetMidY() * -0.6f); var totalLocation = new CGPoint(frameSize.Width * -0.4f, Frame.GetMidY() * -0.8f); var bananaScoreLocation = new CGPoint(frameSize.Width * +0.4f, Frame.GetMidY() * -0.4f); var coinScoreLocation = new CGPoint(frameSize.Width * +0.4f, Frame.GetMidY() * -0.6f); var totalScoreLocation = new CGPoint(frameSize.Width * +0.4f, Frame.GetMidY() * -0.8f); bananaText = (SKLabelNode)myLabel.Copy(); bananaText.Text = "Bananas"; bananaText.FontSize = 0.1f * menuHeight; bananaText.Scale = 0.8f; bananaLocation.X += bananaText.CalculateAccumulatedFrame().Width * 0.5f + frameSize.Width * 0.1f; bananaText.Position = new CGPoint(bananaLocation.X, -2000); AddChild(bananaText); InGameScene.DropShadowOnLabel(bananaText); bananaScore = (SKLabelNode)bananaText.Copy(); bananaScore.Text = "000"; bananaScoreLocation.X -= bananaScore.CalculateAccumulatedFrame().Width * 0.5f + frameSize.Width * 0.1f; bananaScore.Position = new CGPoint(bananaScoreLocation.X, -2000); AddChild(bananaScore); coinText = (SKLabelNode)bananaText.Copy(); coinText.Text = "Large Bananas"; coinLocation.X += coinText.CalculateAccumulatedFrame().Width * 0.5f + frameSize.Width * 0.1f; coinText.Position = new CGPoint(coinLocation.X, -2000f); AddChild(coinText); InGameScene.DropShadowOnLabel(coinText); coinScore = (SKLabelNode)coinText.Copy(); coinScore.Text = "000"; coinScoreLocation.X -= coinScore.CalculateAccumulatedFrame().Width * 0.5f + frameSize.Width * 0.1f; coinScore.Position = new CGPoint(coinScoreLocation.X, -2000f); AddChild(coinScore); totalText = (SKLabelNode)bananaText.Copy(); totalText.Text = "Total"; totalLocation.X += totalText.CalculateAccumulatedFrame().Width * 0.5f + frameSize.Width * 0.1f; totalText.Position = new CGPoint(totalLocation.X, -2000f); AddChild(totalText); InGameScene.DropShadowOnLabel(totalText); totalScore = (SKLabelNode)totalText.Copy(); totalScore.Text = "000"; totalScoreLocation.X -= totalScore.CalculateAccumulatedFrame().Width * 0.5f + frameSize.Width * 0.1f; totalScore.Position = new CGPoint(totalScoreLocation.X, -2000f); AddChild(totalScore); SKAction flyup = SKAction.MoveTo(new CGPoint(frameSize.Width * 0.5f, frameSize.Height - 100), 0.25); flyup.TimingMode = SKActionTimingMode.EaseInEaseOut; SKAction flyupBananas = SKAction.MoveTo(bananaLocation, 0.25); flyupBananas.TimingMode = SKActionTimingMode.EaseInEaseOut; SKAction flyupBananasScore = SKAction.MoveTo(bananaScoreLocation, 0.25f); flyupBananasScore.TimingMode = SKActionTimingMode.EaseInEaseOut; SKAction flyupCoins = SKAction.MoveTo(coinLocation, 0.25); flyupCoins.TimingMode = SKActionTimingMode.EaseInEaseOut; SKAction flyupCoinsScore = SKAction.MoveTo(coinScoreLocation, 0.25); flyupCoinsScore.TimingMode = SKActionTimingMode.EaseInEaseOut; SKAction flyupTotal = SKAction.MoveTo(totalLocation, 0.25); flyupTotal.TimingMode = SKActionTimingMode.EaseInEaseOut; SKAction flyupTotalScore = SKAction.MoveTo(totalScoreLocation, 0.25); flyupTotalScore.TimingMode = SKActionTimingMode.EaseInEaseOut; int bananasCollected = gameStateDelegate.BananasCollected; int coinsCollected = gameStateDelegate.CoinsCollected; int totalCollected = bananasCollected + (coinsCollected * 100); SKAction countUpBananas = SKAction.CustomActionWithDuration(bananasCollected / 100f, ((node, elapsedTime) => { if (bananasCollected > 0) { SKLabelNode label = (SKLabelNode)node; nint total = (nint)(elapsedTime / (bananasCollected / 100.0f) * bananasCollected); label.Text = total.ToString(); if (total % 10 == 0) { GameSimulation.Sim.PlaySound("deposit.caf"); } } })); SKAction countUpCoins = SKAction.CustomActionWithDuration(coinsCollected / 100f, ((node, elapsedTime) => { if (coinsCollected > 0) { SKLabelNode label = (SKLabelNode)node; nint total = (nint)((elapsedTime / (coinsCollected / 100.0f)) * coinsCollected); label.Text = total.ToString(); if (total % 10 == 0) { GameSimulation.Sim.PlaySound("deposit.caf"); } } })); SKAction countUpTotal = SKAction.CustomActionWithDuration(totalCollected / 500.0f, ((node, elapsedTime) => { if (totalCollected > 0) { SKLabelNode label = (SKLabelNode)node; nint total = (nint)((elapsedTime / (totalCollected / 500.0f)) * totalCollected); label.Text = total.ToString(); if (total % 25 == 0) { GameSimulation.Sim.PlaySound("deposit.caf"); } } })); RunAction(flyup, () => { bananaText.RunAction(flyupBananas); bananaScore.RunAction(flyupBananasScore, () => { bananaScore.RunAction(countUpBananas, () => { bananaScore.Text = bananasCollected.ToString(); coinText.RunAction(flyupCoins); coinScore.RunAction(flyupCoinsScore, () => { coinScore.RunAction(countUpCoins, () => { coinScore.Text = coinsCollected.ToString(); totalText.RunAction(flyupTotal); totalScore.RunAction(flyupTotalScore, () => { totalScore.RunAction(countUpTotal, () => { totalScore.Text = totalCollected.ToString(); }); }); }); }); }); }); }); }
void drawLines() { layer.RemoveAllAnimations(); var dot = new CGRect(0, 0, lineWidth, lineWidth); nfloat x, y; CGPoint start = CGPoint.Empty; CGPoint end = CGPoint.Empty; // Draw curved graph line using (UIColor color = UIColor.White.ColorWithAlpha(0.25f), dotColor = UIColor.White.ColorWithAlpha(0.70f)) { //color.SetStroke (); //dotColor.SetFill (); //ctx.SetLineWidth (lineWidth); using (CGPath path = new CGPath()) { var count = hourly ? HourlyTemps.Count : (Forecasts.Count * 2); for (int i = 0; i < count; i++) { // adjusted index var ai = i; double temp; if (hourly) { temp = HourlyTemps [ai]; } else { // reset start when switching from highs to lows if (i == Forecasts.Count) { start = CGPoint.Empty; } var highs = i < Forecasts.Count; ai = highs ? i : i - Forecasts.Count; temp = highs ? HighTemps [ai] : LowTemps [ai]; } var percent = ((nfloat)temp - scaleLow) / scaleRange; x = padding + inset + (ai * scaleX); y = graphRect.GetMaxY() - (graphRect.Height * percent); end = new CGPoint(x, y); if (!hourly) { dot.X = end.X - (lineWidth / 2); dot.Y = end.Y - (lineWidth / 2); path.AddEllipseInRect(dot); //ctx.AddEllipseInRect (dot); } if (start == CGPoint.Empty) { path.MoveToPoint(end); } else { path.MoveToPoint(start); if (hourly) { path.AddLineToPoint(end); } else { var diff = (end.X - start.X) / 2; path.AddCurveToPoint(end.X - diff, start.Y, start.X + diff, end.Y, end.X, end.Y); } } start = end; } // draw all dots to context //if (!hourly) ctx.DrawPath (CGPathDrawingMode.Fill); // add line path to context layer.Path = path; //ctx.AddPath (path); // draw lines //ctx.DrawPath (CGPathDrawingMode.Stroke); layer.LineWidth = lineWidth; layer.StrokeColor = color.CGColor; layer.FillColor = dotColor.CGColor; CABasicAnimation pathAnimation = new CABasicAnimation { KeyPath = "strokeEnd" }; pathAnimation.Duration = 1.0; pathAnimation.From = NSNumber.FromNFloat(0); pathAnimation.To = NSNumber.FromNFloat(1); layer.AddAnimation(pathAnimation, "strokeEndAnimation"); } } }
extern static void NSShowAnimationEffect(nuint animationEffect, CGPoint centerLocation, CGSize size, NSObject animationDelegate, Selector didEndSelector, IntPtr contextInfo);
public static CGPoint Scaled(this CGPoint self, CGSize size) { return(new CGPoint(self.X * size.Width, self.Y * size.Height)); }
protected HeroCharacter(CGPoint position, Player player) : this(null, position, player) { }
public FixedPastProblemsOverlay(CGRect frame) : base(frame) { int fontSizeForSolicitLabel = UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Pad ? 18 : 10; int fontSizeForRegisterButton = UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Pad ? 30 : 18; int fontSizeForLaterButton = UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Pad ? 15 : 10; // configurable bits BackgroundColor = UIColor.White.ColorWithAlpha(.7f); var centerPoint = new CGPoint(frame.Size.Width / 2, frame.Size.Height / 2); UIView backgroundModalView = new UIView(new CGRect(0, 0, UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Pad ? frame.Size.Width * .5 : frame.Size.Width * .6, UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Pad ? frame.Size.Height * .25 : frame.Size.Height * .3)); backgroundModalView.BackgroundColor = UIColor.White; backgroundModalView.Center = centerPoint; backgroundModalView.Layer.CornerRadius = (float)(frame.Size.Height * .45) / 4; backgroundModalView.ClipsToBounds = true; this.AddSubview(backgroundModalView); AutoresizingMask = UIViewAutoresizing.All; nfloat labelHeight = backgroundModalView.Frame.Height / 2.75f; nfloat labelWidth = (System.nfloat)(backgroundModalView.Frame.Width * .75); // derive the center x and y nfloat centerX = backgroundModalView.Frame.Width / 2; nfloat centerY = backgroundModalView.Frame.Height / 2; solicitLabel = new UILabel(new CGRect( centerX - (labelWidth / 2), centerY - (centerY / 1.5), labelWidth, labelHeight )); solicitLabel.Lines = 0; solicitLabel.TextColor = UIColor.Black; //Clay Martin 1/1/18: Change app name to BuyPlane solicitLabel.Text = "Welcome Back"; solicitLabel.TextAlignment = UITextAlignment.Center; solicitLabel.Font = UIFont.BoldSystemFontOfSize(fontSizeForSolicitLabel); solicitLabel.AutoresizingMask = UIViewAutoresizing.All; solicitLabel.LineBreakMode = UILineBreakMode.WordWrap; solicitLabel.AdjustsFontSizeToFitWidth = false; backgroundModalView.AddSubview(solicitLabel); registerButton = new UIButton(UIButtonType.RoundedRect); registerButton.SetTitle("REGISTER NOW!", UIControlState.Normal); registerButton.Frame = new CGRect( centerX - (labelWidth / 2), centerY, labelWidth, labelHeight ); registerButton.Font = UIFont.BoldSystemFontOfSize(fontSizeForRegisterButton); registerButton.AutoresizingMask = UIViewAutoresizing.All; registerButton.TouchUpInside += (sender, e) => { if (ParentViewController != null) { FavoriteClassificationsViewController favClassificationsVC = new FavoriteClassificationsViewController(new AircraftGridLayout(ParentViewController)); ParentViewController.ShowViewController(new UINavigationController(favClassificationsVC), this); Hide(); } }; backgroundModalView.AddSubview(registerButton); laterButton = new UIButton(UIButtonType.RoundedRect); laterButton.SetTitle("I'LL REGISTER LATER", UIControlState.Normal); laterButton.Frame = new CGRect( centerX - (labelWidth / 2), centerY + (centerY / 2.5), labelWidth, labelHeight ); laterButton.Font = UIFont.BoldSystemFontOfSize(fontSizeForLaterButton); laterButton.AutoresizingMask = UIViewAutoresizing.All; laterButton.TouchUpInside += (sender, e) => { Hide(); }; backgroundModalView.AddSubview(laterButton); }