public static NSPoint Create(string nsPointText) { NSPoint nsPoint = new NSPoint(); var parts = nsPointText.Split(',').ToList(); if (parts.Count != 2) throw new Exception("Invalid format for NSPoint"); string x = parts[0].TrimStart('{').Trim(); string y = parts[1].TrimEnd('}').Trim(); var culture = CultureInfo.CreateSpecificCulture("en-US"); nsPoint.X = Single.Parse(x, NumberStyles.Any, culture); nsPoint.Y = Single.Parse(y, NumberStyles.Any, culture); return nsPoint; }
public virtual NSPoint ConvertPointToView(NSPoint aPoint, NSView aView) { NSPoint inBase; if (aView == this) return aPoint; inBase = this._MatrixToWindow().TransformPoint(aPoint); if (aView != null) { //NS.Assert(_window == [aView window], NSInvalidArgumentException); return aView._matrixFromWindow.TransformPoint(inBase); } else { return inBase; } }
public virtual NSPoint ConvertPointToBase(NSPoint aPoint) { return this.ConvertPointToView(aPoint, null); }
public virtual NSPoint ConvertPointFromView(NSPoint aPoint, NSView aView) { NSPoint inBase; if (aView == this) { return aPoint; } if (aView != null) { //NS.Assert(_window == aView.Window, @"NSInvalidArgumentException"); inBase = aView._matrixToWindow.TransformPoint(aPoint); } else { inBase = aPoint; } return this._matrixFromWindow.TransformPoint(inBase); }
/* Helper for -convertRect:fromView: and -convertRect:toView:. */ private static NSRect convert_rect_using_matrices(NSRect aRect, NSAffineTransform matrix1, NSAffineTransform matrix2) { NSRect r = new NSRect(); NSPoint[] p = new NSPoint[4]; NSPoint min, max; int i; for (i = 0; i < 4; i++) p[i] = aRect.Origin; p[1].X += aRect.Size.Width; p[2].Y += aRect.Size.Height; p[3].X += aRect.Size.Width; p[3].Y += aRect.Size.Height; for (i = 0; i < 4; i++) p[i] = matrix1.TransformPoint(p[i]); min = max = p[0] = matrix2.TransformPoint(p[0]); for (i = 1; i < 4; i++) { p[i] = matrix2.TransformPoint(p[i]); min.X = Math.Min(min.X, p[i].X); min.Y = Math.Min(min.Y, p[i].Y); max.X = Math.Max(max.X, p[i].X); max.Y = Math.Max(max.Y, p[i].Y); } r.Origin = min; r.Size = NS.MakeSize(max.X - min.X, max.Y - min.Y); //r.Size.Width = max.X - min.X; //r.Size.Height = max.Y - min.Y; return r; }
public virtual void TranslateOriginToPoint(NSPoint point) { //NSDebugLLog(@"NSView", @"%@ translateOriginToPoint: %@", self, NSStringFromPoint(point)); if (NS.EqualPoints(NSPoint.Zero, point) == false) { if (_boundsMatrix == null) { _boundsMatrix = (NSAffineTransform)NSAffineTransform.Alloc().Init(); } _boundsMatrix.TranslateXByYBy(point.X, point.Y); // Adjust bounds _bounds.Origin = NS.MakePoint(_bounds.Origin.X - point.X, _bounds.Origin.Y - point.Y); //_bounds.Origin.X -= point.X; //_bounds.Origin.Y -= point.Y; if (_coordinates_valid) { //FIXME //(*invalidateImp)(self, invalidateSel); } this.ResetCursorRects(); if (_post_bounds_changes) { //[nc postNotificationName: NSViewBoundsDidChangeNotification object: self]; } } }
public virtual void SetFrameOrigin(NSPoint newOrigin) { if (NS.EqualPoints(_frame.Origin, newOrigin) == false) { NSRect newFrame = _frame; newFrame.Origin = newOrigin; if (_coordinates_valid) { //FIXME //(*invalidateImp)(self, invalidateSel); } this._SetFrameAndClearAutoresizingError(newFrame); this.ResetCursorRects(); if (_post_frame_changes) { //FIXME //[nc postNotificationName: NSViewFrameDidChangeNotification object: self]; } } }
public virtual void SetBoundsOrigin(NSPoint newOrigin) { NSPoint oldOrigin; if (_boundsMatrix == null) { oldOrigin = NS.MakePoint(NS.MinX(_bounds), NS.MinY(_bounds)); } else { NSAffineTransform matrix = (NSAffineTransform)_boundsMatrix.Copy(); matrix.Invert(); oldOrigin = matrix.TransformPoint(NS.MakePoint(0, 0)); //RELEASE(matrix); } this.TranslateOriginToPoint(NS.MakePoint(oldOrigin.X - newOrigin.X, oldOrigin.Y - newOrigin.Y)); }
public NSPoint DecodePointForKey(string keyName) { NSPoint nsPoint = new NSPoint(); XElement xElm = _classDict.Find(i => (string)i.Attribute("key") == keyName); if (xElm != null) { nsPoint = (NSPoint)(NSString)this.Create(xElm); } return nsPoint; }
public virtual NSPoint TransformPoint(NSPoint aPoint) { NSPoint newPoint = NSPoint.Zero; if (_isIdentity) { newPoint.X = _matrix.tX + aPoint.X; newPoint.Y = _matrix.tY + aPoint.Y; } else if (_isFlipY) { newPoint.X = _matrix.tX + aPoint.X; newPoint.Y = _matrix.tY - aPoint.Y; } else { newPoint.X = _matrix.m11 * aPoint.X + _matrix.m21 * aPoint.Y + _matrix.tX; newPoint.Y = _matrix.m12 * aPoint.X + _matrix.m22 * aPoint.Y + _matrix.tY; } return newPoint; }
public virtual void SetFrameOrigin(NSPoint point) { NSAffineTransformStruct matrix = this.GetTransformStruct(); double dx = point.X - _matrix.tX; double dy = point.Y - _matrix.tY; this.TranslateXByYBy(dx,dy); }
public NSRect(NSPoint origin, NSSize size) : this() { Origin = origin; Size = size; }
public NSRect(double x, double y, double w, double h) : this() { Origin = new NSPoint(x, y); Size = new NSSize(w, h); }