Exemple #1
0
        public void TestStaticCreation()
        {
            NSPoint refPoint = new NSPoint(1, 2);
            NSValue val = NSValue.ValueWithPoint(refPoint);
            Check(val);
            NSPoint point = val.PointValue;
            Assert.AreEqual(refPoint, point, "Points must be equal");

            NSRange refRange = new NSRange(3, 4);
            val = NSValue.ValueWithRange(refRange);
            Check(val);
            NSRange range = val.RangeValue;
            Assert.AreEqual(refRange, range, "Ranges must be equal");

            NSRect refRect = new NSRect(5, 6, 789, 789);
            val = NSValue.ValueWithRect(refRect);
            Check(val);
            NSRect rect = val.RectValue;
            Assert.AreEqual(refRect, rect, "Rectangles must be equal");

            NSSize refSize = new NSSize(456, 789);
            val = NSValue.ValueWithSize(refSize);
            Check(val);
            NSSize size = val.SizeValue;
            Assert.AreEqual(refSize, size, "Sizes must be equal");
        }
 // Given two corners, make an NSRect.
 public static NSRect RectFromPoints(NSPoint p1, NSPoint p2)
 {
     return NSRect.NSMakeRect(Math.Min(p1.x, p2.x),
                              Math.Min(p1.y, p2.y),
                              Math.Abs(p1.x - p2.x),
                              Math.Abs(p1.y - p2.y));
 }
 public override void continueMovingAtPoint(NSPoint where)
 {
     NSAffineTransform transform = NSAffineTransform.Transform;
     transform.TranslateXByYBy(where.x - this.lastLocation.x, where.y - this.lastLocation.y);
     this.SelectedPath.TransformUsingAffineTransform(transform);
     this.lastLocation = where;
 }
        public override void startSelectingAtPoint(NSPoint where)
        {
            this.lastLocation = where;
            this.trackingMode = SelectionTrackingMode.TrackSelecting;

            this.SelectedPath.RemoveAllPoints();
            this.SelectedPath.MoveToPoint(where);
        }
Exemple #5
0
 public static extern NSString NSStringFromPoint(NSPoint aPoint);
Exemple #6
0
 /// <summary>
 /// Tests two points for equality.
 /// </summary>
 /// <remarks>Original declaration is : BOOL NSEqualPoints(NSPoint aPoint, NSPoint bPoint)</remarks>
 public static bool NSEqualPoints(NSPoint aPoint,
                                  NSPoint bPoint)
 {
     return Equals(aPoint, bPoint);
 }
Exemple #7
0
 /// <summary>
 /// Translates the point by the specified size.
 /// </summary>
 /// <param name="nsPoint">A point.</param>
 /// <param name="nsSize">A size.</param>
 /// <returns></returns>
 public static NSPoint Substract(NSPoint nsPoint, NSSize nsSize)
 {
     return new NSPoint(nsPoint.x - nsSize.width, nsPoint.y - nsSize.height);
 }
Exemple #8
0
 /// <summary>
 /// Returns a Boolean value that indicates whether a given point is in a specified rectangle.
 /// </summary>
 public bool PointInRect(NSPoint aPoint)
 {
     return this.MouseInRect(aPoint, false);
 }
 public int IndexOfCircleAtPoint(NSPoint point)
 {
     uint count = this.circles.Count;
     for (uint k = 0; k < count; k++)
     {
         Circle circle = this.circles.ObjectAtIndex(count - 1 - k).CastTo<Circle>();
         NSPoint center = circle.Center;
         float radius = circle.Radius;
         float dx = point.x - center.x;
         float dy = point.y - center.y;
         if (dx*dx + dy*dy < radius*radius)
         {
             return (int) (count - 1 - k);
         }
     }
     return -1;
 }
Exemple #10
0
 /// <summary>
 /// Returns a Boolean value that indicates whether the point is in the specified rectangle.
 /// </summary>
 /// <remarks>Original declaration is : BOOL NSMouseInRect(NSPoint aPoint, NSRect aRect, BOOL isFlipped)</remarks>
 public static bool NSMouseInRect(NSPoint aPoint, NSRect aRect, bool isFlipped)
 {
     return isFlipped
                ? (aPoint.x >= NSMinX(aRect)) &&
                  (aPoint.x < NSMaxX(aRect)) &&
                  (aPoint.y > NSMinY(aRect)) &&
                  (aPoint.y <= NSMaxY(aRect))
                : (aPoint.x >= NSMinX(aRect)) &&
                  (aPoint.x < NSMaxX(aRect)) &&
                  (aPoint.y >= NSMinY(aRect)) &&
                  (aPoint.y < NSMaxY(aRect));
 }
Exemple #11
0
 public virtual void stopSelectingAtPoint(NSPoint where)
 {
     this.selectedRect = RectFromPoints(this.lastLocation, where);
     this.trackingMode = SelectionTrackingMode.TrackNone;
 }
Exemple #12
0
 public virtual void stopMovingAtPoint(NSPoint where)
 {
     this.continueMovingAtPoint(where);
     this.trackingMode = SelectionTrackingMode.TrackNone;
 }
Exemple #13
0
 public virtual void startSelectingAtPoint(NSPoint where)
 {
     this.trackingMode = SelectionTrackingMode.TrackSelecting;
     this.lastLocation = where;
 }
Exemple #14
0
 public void setSelectedRectOrigin(NSPoint where)
 {
     this.selectedRect.origin = where;
 }
Exemple #15
0
 /// <summary>
 /// Computes the size between the two points. The values are always positives.
 /// </summary>
 /// <param name="nsPoint1">The point 1.</param>
 /// <param name="nsPoint2">The point 2.</param>
 /// <returns>A <see cref="NSSize"/> instance that contains the size between the two points.</returns>
 public static NSSize Substract(NSPoint nsPoint1, NSPoint nsPoint2)
 {
     return new NSSize(Math.Abs(nsPoint2.x - nsPoint1.x), Math.Abs(nsPoint2.y - nsPoint1.y));
 }
Exemple #16
0
 public virtual void continueMovingAtPoint(NSPoint where)
 {
     this.selectedRect.origin.x += where.x - this.lastLocation.x;
     this.selectedRect.origin.y += where.y - this.lastLocation.y;
     this.lastLocation = where;
 }
 public override void continueSelectingAtPoint(NSPoint where)
 {
     this.SelectedPath.LineToPoint(where);
 }
Exemple #18
0
 public virtual void continueSelectingAtPoint(NSPoint where)
 {
     this.selectedRect = RectFromPoints(this.lastLocation, where);
 }
 public override void stopSelectingAtPoint(NSPoint where)
 {
     this.SelectedPath.LineToPoint(where);
     this.SelectedPath.ClosePath();
     this.trackingMode = SelectionTrackingMode.TrackNone;
 }
Exemple #20
0
 public virtual void mouseDown(NSEvent theEvent)
 {
     this.lastLocation = this.target.ConvertPointFromView(theEvent.LocationInWindow, null);
     if (NSRect.NSPointInRect(this.lastLocation, this.selectedRect))
     {
         this.startMovingAtPoint(this.lastLocation);
         return;
     }
     this.startSelectingAtPoint(this.lastLocation);
 }
Exemple #21
0
 /// <summary>
 /// Returns a Boolean value that indicates whether a given point is in a given rectangle.
 /// </summary>
 /// <remarks>Original declaration is : BOOL NSPointInRect(NSPoint aPoint, NSRect aRect)</remarks>
 public static bool NSPointInRect(NSPoint aPoint, NSRect aRect)
 {
     return NSMouseInRect(aPoint, aRect, false);
 }
        public void SetOffsetFromPoint(NSPoint point)
        {
            CGSize offset;

            NSRect bounds = this.Bounds;
            offset.width = (point.x - NSRect.NSMidX(bounds))/(NSRect.NSWidth(bounds)/2);
            offset.height = (point.y - NSRect.NSMidY(bounds))/(NSRect.NSHeight(bounds)/2);
            float radius = (float) Math.Sqrt(offset.width*offset.width + offset.height*offset.height);
            if (radius > 1)
            {
                offset.width /= radius;
                offset.height /= radius;
            }
            if (CGSize.CGSizeEqualToSize(this._offset, offset) == 0)
            {
                this._offset = offset;
                this.NeedsDisplay = true;
                NSNotificationCenter.DefaultCenter.PostNotificationNameObject(ShadowOffsetChanged, this);
            }
        }
Exemple #23
0
 /// <summary>
 /// Returns a Boolean value that indicates whether the point is in the rectangle.
 /// </summary>
 public bool MouseInRect(NSPoint aPoint, bool isFlipped)
 {
     return NSMouseInRect(aPoint, this, isFlipped);
 }
Exemple #24
0
		/// <summary>
		/// Converts a <see cref="NSPoint"/> instance to a <see cref="CGPoint"/>
		/// </summary>
		/// <param name="nspoint">The <see cref="NSPoint"/> to convert.</param>
		/// <returns>A new <see cref="CGPoint"/> instance.</returns>
		public static CGPoint CGPointFromNSPoint(NSPoint nspoint)
		{
			return CGPoint.CGPointMake(nspoint.x, nspoint.y);
		}		
Exemple #25
0
        public NSInteger dividerIndexForPoint(NSPoint point)
        {
            NSInteger dividerIndex = -1;
            Action<Id, NSUInteger, IntPtr > enumerator = delegate(Id id, NSUInteger i, IntPtr stop) {
                NSView view = id.CastTo<NSView> ();
                NSRect subviewFrame = view.Frame;
                if (point.y > subviewFrame.MaxY) {
                    // the point is between us and the subview above
                    dividerIndex = i - 1;
                    Marshal.WriteByte (stop, 1);
                } else if (point.y > subviewFrame.MinY) {
                    // the point is in the interior of our view, not on a divider
                    dividerIndex = -1;
                    Marshal.WriteByte (stop, 1);
                }
            };
            this.Subviews.EnumerateObjectsUsingBlock (enumerator);

            return dividerIndex;
        }
Exemple #26
0
 /// <summary>
 /// Translates the point by the specified size.
 /// </summary>
 /// <param name="nsPoint">A point.</param>
 /// <param name="nsSize">A size.</param>
 /// <returns></returns>
 public static NSPoint Add(NSPoint nsPoint, NSSize nsSize)
 {
     return new NSPoint(nsPoint.x + nsSize.width, nsPoint.y + nsSize.height);
 }