public virtual NSSize ConvertSizeToView(NSSize aSize, NSView aView) { NSSize inBase = this._MatrixToWindow().TransformSize(aSize); if (inBase.Height < 0.0) { inBase.Height = -inBase.Height; } if (aView != null) { NSSize inOther; //NS.Assert(_window == aView.Window, @"NSInvalidArgumentException"); inOther = aView._MatrixFromWindow().TransformSize(inBase); if (inOther.Height < 0.0) { inOther.Height = -inOther.Height; } return inOther; } else { return inBase; } }
static NSSize _computeScale(NSSize fs, NSSize bs) { NSSize scale = NS.MakeSize (0, 0); if (bs.Width == 0) { if (fs.Width == 0) scale.Width = 1; else scale.Width = Int64.MaxValue; } else { scale.Width = fs.Width / bs.Width; } if (bs.Height == 0) { if (fs.Height == 0) scale.Height = 1; else scale.Height = Int64.MaxValue; } else { scale.Height = fs.Height / bs.Height; } return scale; }
public virtual NSSize ConvertSizeToBase(NSSize aSize) { return this.ConvertSizeToView(aSize, null); }
public virtual void SetBoundsSize(NSSize newSize) { NSSize scale; //NSDebugLLog(@"NSView", @"%@ setBoundsSize: %@", self, NSStringFromSize(newSize)); if (newSize.Width < 0) { //NSWarnMLog(@"given negative width", 0); newSize.Width = 0; } if (newSize.Height < 0) { //NSWarnMLog(@"given negative height", 0); newSize.Height = 0; } scale = _computeScale(_frame.Size, newSize); if (scale.Width != 1 || scale.Height != 1) { _is_rotated_or_scaled_from_base = true; } if (_boundsMatrix == null) { _boundsMatrix = (NSAffineTransform)NSAffineTransform.Alloc().Init(); } _boundsMatrix.ScaleTo(scale.Width, scale.Height); if (!_is_rotated_from_base) { scale = _computeScale(_bounds.Size, newSize); _bounds.Origin = NS.MakePoint(_bounds.Origin.X / scale.Width, _bounds.Origin.Y / scale.Height); //_bounds.Origin.X = _bounds.Origin.X / scale.Width; //_bounds.Origin.Y = _bounds.Origin.Y / scale.Height; _bounds.Size = newSize; } else { NSAffineTransform matrix; NSRect frame = _frame; frame.Origin = NS.MakePoint(0, 0); matrix = (NSAffineTransform)_boundsMatrix.Copy(); matrix.Invert(); matrix.BoundingRectFor(frame, ref _bounds); //RELEASE(matrix); } if (_coordinates_valid) { //FIXME //(*invalidateImp)(self, invalidateSel); } this.ResetCursorRects(); if (_post_bounds_changes) { //[nc postNotificationName: NSViewBoundsDidChangeNotification object: self]; } }
public virtual void SetFrameSize(NSSize newSize) { NSRect newFrame = _frame; if (newSize.Width < 0) { //NSWarnMLog(@"given negative width", 0); newSize.Width = 0; } if (newSize.Width < 0) { //NSWarnMLog(@"given negative height", 0); newSize.Height = 0; } if (NS.EqualSizes(_frame.Size, newSize) == false) { NSSize old_size = _frame.Size; if (_is_rotated_or_scaled_from_base) { if (_boundsMatrix == null) { double sx = _bounds.Size.Width / _frame.Size.Width; double sy = _bounds.Size.Height / _frame.Size.Height; newFrame.Size = newSize; this._SetFrameAndClearAutoresizingError(newFrame); _bounds.Size = NS.MakeSize(_frame.Size.Width * sx, _frame.Size.Height * sy); //_bounds.Size.Width = _frame.Size.Width * sx; //_bounds.Size.Height = _frame.Size.Height * sy; } else { NSAffineTransform matrix; NSRect frame; newFrame.Size = newSize; this._SetFrameAndClearAutoresizingError(newFrame); frame = _frame; frame.Origin = NS.MakePoint(0, 0); matrix = (NSAffineTransform)_boundsMatrix.Copy(); matrix.Invert(); matrix.BoundingRectFor(frame ,ref _bounds); //RELEASE(matrix); } } else { newFrame.Size = _bounds.Size = newSize; this._SetFrameAndClearAutoresizingError(newFrame); } if (_coordinates_valid) { //FIXME //(*invalidateImp)(self, invalidateSel); } this.ResetCursorRects(); this.ResizeSubviewsWithOldSize(old_size); if (_post_frame_changes) { //FIXME //[nc postNotificationName: NSViewFrameDidChangeNotification object: self]; } } }
public virtual void ResizeWithOldSuperviewSize(NSSize oldSize) { NSSize superViewFrameSize; NSRect newFrame = _frame; NSRect newFrameRounded; if (_autoresizingMask == (uint)NSViewAutoresizingMasks.NSViewNotSizable) return; if (!NS.EqualRects(NS.ZeroRect, _autoresizingFrameError)) { newFrame.Origin = NS.MakePoint(newFrame.Origin.X -_autoresizingFrameError.Origin.X, newFrame.Origin.Y - _autoresizingFrameError.Origin.Y); //newFrame.Origin.X -= _autoresizingFrameError.Origin.X; //newFrame.Origin.Y -= _autoresizingFrameError.Origin.Y; newFrame.Size = NS.MakeSize(newFrame.Size.Width - _autoresizingFrameError.Size.Width, newFrame.Size.Height - _autoresizingFrameError.Size.Height); //newFrame.Size.Width -= _autoresizingFrameError.Size.Width; //newFrame.Size.Height -= _autoresizingFrameError.Size.Height; } superViewFrameSize = NS.MakeSize(0,0); if (_super_view != null) superViewFrameSize = _super_view.Frame.Size; double orgX = newFrame.Origin.X; double sizeW = newFrame.Size.Width; Autoresize(oldSize.Width,superViewFrameSize.Width, ref orgX, ref sizeW, (_autoresizingMask & (uint)NSViewAutoresizingMasks.NSViewMinXMargin) != 0, (_autoresizingMask & (uint)NSViewAutoresizingMasks.NSViewWidthSizable) != 0, (_autoresizingMask & (uint)NSViewAutoresizingMasks.NSViewMaxXMargin) != 0); newFrame.Origin = NS.MakePoint(orgX, newFrame.Origin.Y); newFrame.Size = NS.MakeSize(sizeW, newFrame.Size.Height); { bool flipped = ((_super_view != null) && _super_view.IsFlipped()); double orgY = newFrame.Origin.Y; double sizeH = newFrame.Size.Height; Autoresize(oldSize.Height, superViewFrameSize.Height, ref orgY, ref sizeH, flipped ? NS.IsBitSet(_autoresizingMask, (uint)NSViewAutoresizingMasks.NSViewMaxYMargin) : NS.IsBitSet(_autoresizingMask, (uint)NSViewAutoresizingMasks.NSViewMinYMargin), NS.IsBitSet(_autoresizingMask, (uint)NSViewAutoresizingMasks.NSViewHeightSizable), flipped ? NS.IsBitSet(_autoresizingMask, (uint)NSViewAutoresizingMasks.NSViewMinYMargin) : NS.IsBitSet(_autoresizingMask, (uint)NSViewAutoresizingMasks.NSViewMaxYMargin)); } newFrameRounded = newFrame; /** * Perform rounding to pixel-align the frame if we are not rotated */ if (!this.IsRotatedFromBase() && this.Superview != null) { newFrameRounded = ((NSView)this.Superview).CenterScanRect(newFrameRounded); } this.SetFrame(newFrameRounded); _autoresizingFrameError.Origin = NS.MakePoint(newFrameRounded.Origin.X - newFrame.Origin.X, newFrameRounded.Origin.Y - newFrame.Origin.Y); //_autoresizingFrameError.Origin.X = (newFrameRounded.Origin.X - newFrame.Origin.X); //_autoresizingFrameError.Origin.Y = (newFrameRounded.Origin.Y - newFrame.Origin.Y); _autoresizingFrameError.Size = NS.MakeSize(newFrameRounded.Size.Width - newFrame.Size.Width, newFrameRounded.Size.Height - newFrame.Size.Height); //_autoresizingFrameError.Size.Width = (newFrameRounded.Size.Width - newFrame.Size.Width); //_autoresizingFrameError.Size.Height = (newFrameRounded.Size.Height - newFrame.Size.Height); }
public virtual void ScaleUnitSquareToSize(NSSize newSize) { if (newSize.Width != 1.0 || newSize.Height != 1.0) { if (newSize.Width < 0) { //NSWarnMLog(@"given negative width", 0); newSize.Width = 0; } if (newSize.Height < 0) { //NSWarnMLog(@"given negative height", 0); newSize.Height = 0; } if (_boundsMatrix == null) { _boundsMatrix = (NSAffineTransform)NSAffineTransform.Alloc().Init(); } _boundsMatrix.ScaleXByYBy(newSize.Width, newSize.Height); // Adjust bounds _bounds.Origin = NS.MakePoint(_bounds.Origin.X / newSize.Width, _bounds.Origin.Y / newSize.Height); _bounds.Size = NS.MakeSize(_bounds.Size.Width / newSize.Width, _bounds.Size.Height / newSize.Height); //_bounds.Origin.X = _bounds.Origin.X / newSize.Width; //_bounds.Origin.Y = _bounds.Origin.Y / newSize.Height; //_bounds.Size.Width = _bounds.Size.Width / newSize.Width; //_bounds.Size.Height = _bounds.Size.Height / newSize.Height; _is_rotated_or_scaled_from_base = true; if (_coordinates_valid) { //FIXME //(*invalidateImp)(self, invalidateSel); } this.ResetCursorRects(); if (_post_bounds_changes) { //[nc postNotificationName: NSViewBoundsDidChangeNotification object: self]; } } }
public override id InitWithCoder(NSCoder aDecoder) { base.InitWithCoder(aDecoder); if (aDecoder.AllowsKeyedCoding) { if (aDecoder.ContainsValueForKey("NSViewClass")) { _viewClass = (id)aDecoder.DecodeObjectForKey("NSViewClass"); } if (aDecoder.ContainsValueForKey("NSWindowClass")) { _windowClass = (NSString)aDecoder.DecodeObjectForKey("NSWindowClass"); } if (aDecoder.ContainsValueForKey("NSWindowStyleMask")) { _windowStyle = (uint)aDecoder.DecodeIntForKey("NSWindowStyleMask"); } if (aDecoder.ContainsValueForKey("NSWindowBacking")) { _backingStoreType = (NSBackingStoreType)aDecoder.DecodeIntForKey("NSWindowBacking"); } if (aDecoder.ContainsValueForKey("NSWindowView")) { _view = (id)aDecoder.DecodeObjectForKey("NSWindowView"); } if (aDecoder.ContainsValueForKey("NSWTFlags")) { uint flags = (uint)aDecoder.DecodeIntForKey("NSWTFlags"); _flags = PrimitiveConversion.FromLong<GSWindowTemplateFlags>(flags); } if (aDecoder.ContainsValueForKey("NSMinSize")) { _minSize = aDecoder.DecodeSizeForKey("NSMinSize"); } if (aDecoder.ContainsValueForKey("NSMaxSize")) { _maxSize = aDecoder.DecodeSizeForKey("NSMaxSize"); } else { _maxSize = new NSSize((float)10e+4, (float)10e+4); } if (aDecoder.ContainsValueForKey("NSWindowRect")) { _windowRect = aDecoder.DecodeRectForKey("NSWindowRect"); } if (aDecoder.ContainsValueForKey("NSFrameAutosaveName")) { _autosaveName = (NSString)aDecoder.DecodeObjectForKey("NSFrameAutosaveName"); } if (aDecoder.ContainsValueForKey("NSWindowTitle")) { _title = (NSString)aDecoder.DecodeObjectForKey("NSWindowTitle"); _windowStyle |= (uint)NSWindowStyleMasks.NSTitledWindowMask; } //_baseWindowClass = [NSWindow class]; } else { //[NSException raise: NSInvalidArgumentException // format: @"Can't decode %@ with %@.",NSStringFromClass([self class]), // NSStringFromClass([coder class])]; } //if (aDecoder.AllowsKeyedCoding) //{ // StyleMask = (NSWindowStyleMasks)aDecoder.DecodeIntForKey("NSWindowStyleMask"); // Backing = aDecoder.DecodeIntForKey("NSWindowBacking"); // WindowRect = aDecoder.DecodeRectForKey("NSWindowRect"); // NSWTFlags = (uint)aDecoder.DecodeIntForKey("NSWTFlags"); // if (aDecoder.ContainsValueForKey("NSWindowTitle")) // { // Title = (NSString)aDecoder.DecodeObjectForKey("NSWindowTitle"); // StyleMask |= NSWindowStyleMasks.NSTitledWindowMask; // } // WindowClass = (NSString)aDecoder.DecodeObjectForKey("NSWindowClass"); // Toolbar = (NSToolbar)aDecoder.DecodeObjectForKey("NSViewClass"); // WindowView = (NSView)aDecoder.DecodeObjectForKey("NSWindowView"); // ScreenRect = (NSRect)aDecoder.DecodeRectForKey("NSScreenRect"); // IsRestorable = aDecoder.DecodeBoolForKey("NSWindowIsRestorable"); // MinSize = aDecoder.DecodeSizeForKey("NSMinSize"); // if (aDecoder.ContainsValueForKey("NSMaxSize")) // { // MaxSize = aDecoder.DecodeSizeForKey("NSMaxSize"); // } // else // { // MaxSize = new NSSize((float)10e+4, (float)10e+4); // } //} return this; }
public virtual void ResizeSubviewsWithOldSize(NSSize oldSize) { if (_rFlags.has_subviews != 0) { NSEnumerator e; NSView o; if (_autoresizes_subviews == false || _is_rotated_from_base == true) return; e = _sub_views.ObjectEnumerator(); o = (NSView)e.NextObject(); while (o != null) { o.ResizeWithOldSuperviewSize(oldSize); o = (NSView)e.NextObject(); } } }
public virtual NSSize TransformSize(NSSize aSize) { if (_isIdentity) { return aSize; } else { NSSize newSize = new NSSize(0, 0); if (_isFlipY) { newSize.Width = aSize.Width; newSize.Height = -aSize.Height; } else { newSize.Width = _matrix.m11 * aSize.Width + _matrix.m21 * aSize.Height; newSize.Height = _matrix.m12 * aSize.Width + _matrix.m22 * aSize.Height; } return newSize; } }
public NSSize DecodeSizeForKey(string keyName) { NSSize nsSize = new NSSize(); XElement xElm = _classDict.Find(i => (string)i.Attribute("key") == keyName); if (xElm != null) { nsSize = (NSSize)(NSString)this.Create(xElm); } return nsSize; }
public override void SetFrameSize(NSSize newSize) { base.FrameSize = newSize; if (_content_view != null) ((NSView)_content_view).Frame = CalcSizesAllowingNegative(false); }
public virtual void SetContentViewMargins(NSSize offsetSize) { _offsets = offsetSize; if (_content_view != null) ((NSView)_content_view).Frame = CalcSizesAllowingNegative(false); this.SetNeedsDisplay(true); }
public static NSSize Create(NSString nsSizeText) { NSSize nsSize = new NSSize(); //[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)? //[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)? //var matches = Regex.Match(nsSizeText, @"{([-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?),\s*([-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?)}"); //var matches = Regex.Match(nsSizeText, @"{([+-]?\d+[eE][-+]?\d+),\s*([+-]?\d+[eE][-+]?\d+)}"); //if (matches.Groups.Count != 3) // throw new Exception("Invalid xElement for NSSize"); //var culture = CultureInfo.CreateSpecificCulture("en-US"); //nsPoint.Width = Single.Parse(matches.Groups[1].Value, NumberStyles.AllowExponent, culture); //nsPoint.Height = Single.Parse(matches.Groups[2].Value, NumberStyles.AllowExponent, culture); var parts = nsSizeText.Value.Split(',').ToList(); if (parts.Count != 2) throw new Exception("Invalid format for NSSize"); string w = parts[0].TrimStart('{').Trim(); string h = parts[1].TrimEnd('}').Trim(); var culture = CultureInfo.CreateSpecificCulture("en-US"); nsSize.Width = Double.Parse(w, NumberStyles.Any, culture); nsSize.Height = Double.Parse(h, NumberStyles.Any, culture); //if (w.Equals("1.79769e+308", StringComparison.CurrentCultureIgnoreCase)) // nsSize.Width = double.MaxValue; //else // nsSize.Width = Double.Parse(w, NumberStyles.AllowExponent, culture); //if (h.Equals("1.79769e+308", StringComparison.CurrentCultureIgnoreCase)) // nsSize.Height = double.MaxValue; //else // nsSize.Height = Double.Parse(h, NumberStyles.AllowExponent, culture); return nsSize; }
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); }