コード例 #1
0
ファイル: NSView.cs プロジェクト: smartmobili/CocoaBuilder
        public virtual id InitWithFrame(NSRect frameRect)
        {
            id self = this;

            if (base.Init() == null)
                return null;

            if (frameRect.Size.Width < 0)
            {
                frameRect.Size = new NSSize(0, frameRect.Size.Height);
            }
            if (frameRect.Size.Height < 0)
            {
                frameRect.Size = new NSSize(frameRect.Size.Width, 0);
            }

            _frame = frameRect;			// Set frame rectangle
            _bounds.Origin = NSPoint.Zero;		// Set bounds rectangle
            _bounds.Size = _frame.Size;

            // _frameMatrix = [NSAffineTransform new];    // Map fromsuperview to frame
            // _boundsMatrix = [NSAffineTransform new];   // Map from superview to bounds
            _matrixToWindow = (NSAffineTransform)NSAffineTransform.Alloc().Init();   // Map to window coordinates
            _matrixFromWindow = (NSAffineTransform)NSAffineTransform.Alloc().Init(); // Map from window coordinates

            _sub_views = (NSMutableArray)NSMutableArray.Alloc().Init();
            _tracking_rects = (NSMutableArray)NSMutableArray.Alloc().Init();
            _cursor_rects = (NSMutableArray)NSMutableArray.Alloc().Init();

            // Some values are already set by initialisation
            //_super_view = nil;
            //_window = nil;
            //_is_rotated_from_base = NO;
            //_is_rotated_or_scaled_from_base = NO;
            _rFlags.needs_display = 1;
            _post_bounds_changes = true;
            _post_frame_changes = true;
            _autoresizes_subviews = true;
            _autoresizingMask = (uint)NSViewAutoresizingMasks.NSViewNotSizable;
            //_coordinates_valid = NO;
            //_nextKeyView = 0;
            //_previousKeyView = 0;

            return self;
        }
コード例 #2
0
ファイル: NSView.cs プロジェクト: smartmobili/CocoaBuilder
        /* 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;
        }
コード例 #3
0
ファイル: NSView.cs プロジェクト: smartmobili/CocoaBuilder
        public override id InitWithCoder(NSCoder aDecoder)
        {
            id self = this;

            NSEnumerator e;
            NSView sub;
            NSArray subs;

            if (base.InitWithCoder(aDecoder) == null)
                return null;

            _matrixToWindow = (NSAffineTransform)NSAffineTransform.Alloc().Init();  // Map to window coordinates
            _matrixFromWindow = (NSAffineTransform)NSAffineTransform.Alloc().Init();// Map from window coordinates

            if (aDecoder.AllowsKeyedCoding)
            {
                NSView prevKeyView = null;
                NSView nextKeyView = null;

                if (aDecoder.ContainsValueForKey("NSFrame"))
                {
                    _frame = aDecoder.DecodeRectForKey("NSFrame");
                }
                else
                {
                    _frame = NSRect.Zero;
                    if (aDecoder.ContainsValueForKey("NSFrameSize"))
                    {
                        _frame = aDecoder.DecodeSizeForKey("NSFrameSize");
                    }
                }

                // Set bounds rectangle
                _bounds.Origin = NSPoint.Zero;
                _bounds.Size = _frame.Size;
                if (aDecoder.ContainsValueForKey("NSBounds"))
                {
                    this.SetBounds(aDecoder.DecodeRectForKey(@"NSBounds"));
                }

                _sub_views = (NSMutableArray)NSMutableArray.Alloc().Init();
                _tracking_rects = (NSMutableArray)NSMutableArray.Alloc().Init();
                _cursor_rects = (NSMutableArray)NSMutableArray.Alloc().Init();

                _is_rotated_from_base = false;
                _is_rotated_or_scaled_from_base = false;
                _rFlags.needs_display = Convert.ToUInt32(true);
                _post_bounds_changes = true;
                _post_frame_changes = true;
                _autoresizes_subviews = true;
                _autoresizingMask =(uint) NSViewAutoresizingMasks.NSViewNotSizable;
                _coordinates_valid = false;
                /*
                 * Note: don't zero _nextKeyView and _previousKeyView, as the key view
                 * chain may already have been established by super's initWithCoder:
                 *
                 * _nextKeyView = 0;
                 * _previousKeyView = 0;
                 */

                // previous and next key views...
                 prevKeyView = (NSView)aDecoder.DecodeObjectForKey("NSPreviousKeyView");
                 nextKeyView = (NSView)aDecoder.DecodeObjectForKey("NSNextKeyView");
                if (nextKeyView != null)
                {
                    NextKeyView = nextKeyView;
                }
                if (prevKeyView != null)
                {
                    PreviousKeyView = prevKeyView;
                }
                if (aDecoder.ContainsValueForKey("NSvFlags"))
                {
                    uint vFlags = (uint)aDecoder.DecodeIntForKey("NSvFlags");
                    //2013-06-02 10:40:22.872 Gorm[26233] NSvFlags: 0x112 (274) (274)
                    //2013-06-02 10:40:22.872 Gorm[26233] NSvFlags: 0x80000100 (-2147483392) (-2147483392)
                    //2013-06-02 10:40:22.873 Gorm[26233] NSvFlags: 0x80000100 (-2147483392) (-2147483392)
                    //2013-06-02 10:40:22.873 Gorm[26233] NSvFlags: 0x136 (310) (310)
                    //2013-06-02 10:40:22.873 Gorm[26233] NSvFlags: 0x900 (2304) (2304)
                    //2013-06-02 10:40:22.873 Gorm[26233] NSvFlags: 0x8000010a (-2147483382) (-2147483382)
                    //2013-06-02 10:40:22.873 Gorm[26233] NSvFlags: 0x10a (266) (266)
                    //2013-06-02 10:40:22.873 Gorm[26233] NSvFlags: 0x10c (268) (268)
                    //2013-06-02 10:40:22.873 Gorm[26233] NSvFlags: 0x10a (266) (266)
                    //2013-06-02 10:40:22.874 Gorm[26233] NSvFlags: 0x10c (268) (268)
                    //2013-06-02 10:40:22.874 Gorm[26233] NSvFlags: 0x10a (266) (266)
                    //2013-06-02 10:40:22.874 Gorm[26233] NSvFlags: 0x10c (268) (268)
                    //2013-06-02 10:40:22.874 Gorm[26233] NSvFlags: 0x112 (274) (274)
                    //2013-06-02 10:40:22.874 Gorm[26233] NSvFlags: 0x8000010a (-2147483382) (-2147483382)
                    //2013-06-02 10:40:22.874 Gorm[26233] NSvFlags: 0x100 (256) (256)
                    //2013-06-02 10:40:22.875 Gorm[26233] NSvFlags: 0x10c (268) (268)
                    //2013-06-02 10:40:22.875 Gorm[26233] NSvFlags: 0x10c (268) (268)
                    //2013-06-02 10:40:22.875 Gorm[26233] NSvFlags: 0x10c (268) (268)
                    //2013-06-02 10:40:22.875 Gorm[26233] NSvFlags: 0x102 (258) (258)
                    //2013-06-02 10:40:22.876 Gorm[26233] NSvFlags: 0x104 (260) (260)
                    //2013-06-02 10:40:22.876 Gorm[26233] NSvFlags: 0x102 (258) (258)
                    //2013-06-02 10:40:22.876 Gorm[26233] NSvFlags: 0x10c (268) (268)
                    //2013-06-02 10:40:22.879 Gorm[26233] NSvFlags: 0x10c (268) (268)
                    //2013-06-02 10:40:22.885 Gorm[26233] NSvFlags: 0x10c (268) (268)
                    //2013-06-02 10:40:22.893 Gorm[26233] NSvFlags: 0x10c (268) (268)
                    //2013-06-02 10:40:22.901 Gorm[26233] NSvFlags: 0x10c (268) (268)
                    //2013-06-02 10:40:22.902 Gorm[26233] NSvFlags: 0x10c (268) (268)
                    //2013-06-02 10:40:22.902 Gorm[26233] NSvFlags: 0x12d (301) (301)
                    //2013-06-02 10:40:22.903 Gorm[26233] NSvFlags: 0x112 (274) (274)

                    // We are lucky here, Apple use the same constants
                    // in the lower bits of the flags
                   this.SetAutoresizingMask(vFlags & 0x3F);
                   this.SetAutoresizesSubviews((vFlags & 0x100) == 0x100);
                   this.SetHidden((vFlags & 0x80000000) == 0x80000000);
                }

                 // iterate over subviews and put them into the view...
                subs = (NSArray)aDecoder.DecodeObjectForKey("NSSubviews");
                if (subs != null)
                {
                    e = subs.ObjectEnumerator();
                    while ((sub = (NSView)e.NextObject()) != null)
                    {
                        System.Diagnostics.Debug.Assert(sub.GetClass() != NSCustomView.Class);
                        System.Diagnostics.Debug.Assert(sub.Window == null);
                        System.Diagnostics.Debug.Assert(sub.Superview == null);

                        sub._ViewWillMoveToWindow(_window);
                        sub._ViewWillMoveToSuperview(this);
                        sub.SetNextResponder(this);
                        _sub_views.AddObject(sub);
                        _rFlags.has_subviews = 1;
                        sub.ResetCursorRects();
                        sub.SetNeedsDisplay(true);
                        sub._ViewDidMoveToWindow();
                        sub.ViewDidMoveToSuperview();
                        this.DidAddSubview(sub);

                    }
                }

                //NSvFlags = aDecoder.DecodeIntForKey("NSvFlags");
                //_sub_views = (NSArray)aDecoder.DecodeObjectForKey("NSSubviews");

                //Window = aDecoder.DecodeObjectForKey("NSWindow");
                //ClassName = (NSString)aDecoder.DecodeObjectForKey("NSWindow");

                //Offsets = aDecoder.DecodePointForKey("NSOffsets");

                //Superview = aDecoder.DecodeObjectForKey("NSSuperview");
            }

            return self;
        }
コード例 #4
0
ファイル: NSView.cs プロジェクト: smartmobili/CocoaBuilder
        public virtual void SetFrameRotation(double angle)
        {
            double oldAngle = this.GetFrameRotation();

            if (oldAngle != angle)
            {
                /* no frame matrix, create one since it is needed for rotation */
                if (_frameMatrix == null)
                {
                    // Map from superview to frame
                    _frameMatrix = (NSAffineTransform)NSAffineTransform.Alloc().Init();
                }

                _frameMatrix.RotateByDegrees(angle - oldAngle);
                _is_rotated_from_base = _is_rotated_or_scaled_from_base = true;

                if (_coordinates_valid)
                {
                    //FIXME
                    //(*invalidateImp)(self, invalidateSel);
                }
                this.ResetCursorRects();
                if (_post_frame_changes)
                {
                    //[nc postNotificationName: NSViewFrameDidChangeNotification object: self];
                }
            }
        }
コード例 #5
0
ファイル: NSView.cs プロジェクト: smartmobili/CocoaBuilder
        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];
                }
            }
        }
コード例 #6
0
ファイル: NSView.cs プロジェクト: smartmobili/CocoaBuilder
        public virtual void SetBounds(NSRect aRect)
        {
            //NSDebugLLog(@"NSView", @"setBounds %@", NSStringFromRect(aRect));
            if (aRect.Size.Width < 0)
            {
                //NSWarnMLog(@"given negative width", 0);
                //aRect.Size.Width = 0;
                aRect.Size = NS.MakeSize(0, aRect.Size.Height);
            }
            if (aRect.Size.Height < 0)
            {
                //NSWarnMLog(@"given negative height", 0);
                //aRect.Size.Height = 0;
                aRect.Size = NS.MakeSize(aRect.Size.Width, 0);
            }

            if (_is_rotated_from_base || (NS.EqualRects(_bounds, aRect) == false))
            {
                NSAffineTransform matrix;
                NSPoint oldOrigin;
                NSSize scale;

                if (_boundsMatrix == null)
                {
                    _boundsMatrix = (NSAffineTransform)NSAffineTransform.Alloc().Init();
                }

                // Adjust scale
                scale = _computeScale(_frame.Size, aRect.Size);
                if (scale.Width != 1 || scale.Height != 1)
                {
                    _is_rotated_or_scaled_from_base = true;
                }
                _boundsMatrix.ScaleTo(scale.Width, scale.Height);
                {
                    matrix = (NSAffineTransform)_boundsMatrix.Copy();
                    matrix.Invert();
                    oldOrigin = matrix.TransformPoint(NS.MakePoint(0, 0));
                    //RELEASE(matrix);
                }
                _boundsMatrix.TranslateXByYBy(oldOrigin.X - aRect.Origin.X, oldOrigin.Y - aRect.Origin.Y);
                if (!_is_rotated_from_base)
                {
                    // Adjust bounds
                    _bounds = aRect;
                }
                else
                {
                    // Adjust bounds
                    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];
                }
            }
        }
コード例 #7
0
ファイル: NSView.cs プロジェクト: smartmobili/CocoaBuilder
        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];
            }
        }
コード例 #8
0
ファイル: NSView.cs プロジェクト: smartmobili/CocoaBuilder
        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];
                }
            }
        }
コード例 #9
0
ファイル: NSView.cs プロジェクト: smartmobili/CocoaBuilder
        public void RotateByAngle(double angle)
        {
            if (angle != 0.0)
            {
                NSAffineTransform matrix;
                NSRect frame = _frame;

                frame.Origin = NS.MakePoint(0, 0);
                if (_boundsMatrix == null)
                {
                    _boundsMatrix = (NSAffineTransform)NSAffineTransform.Alloc().Init();
                }
                _boundsMatrix.RotateByDegrees(angle);
                // Adjust bounds
                matrix = (NSAffineTransform)_boundsMatrix.Copy();
                matrix.Invert();
                matrix.BoundingRectFor(frame, ref _bounds);
                //RELEASE(matrix);

                _is_rotated_from_base = _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];
                }
            }
        }
コード例 #10
0
        public virtual void PrependTransform(ref NSAffineTransform aTransform)
        {
            //valid(aTransform);

            if (aTransform._isIdentity)
            {
                double newTX;

                newTX = aTransform._matrix.tX * _matrix.m11 + aTransform._matrix.tY * _matrix.m21 + _matrix.tX;
                _matrix.tY = aTransform._matrix.tX * _matrix.m12 + aTransform._matrix.tY * _matrix.m22 + _matrix.tY;
                _matrix.tX = newTX;
                //check();
                return;
            }

            if (aTransform._isFlipY)
            {
                double newTX;

                newTX = aTransform._matrix.tX * _matrix.m11 + aTransform._matrix.tY * _matrix.m21 + _matrix.tX;
                _matrix.tY = aTransform._matrix.tX * _matrix.m12 + aTransform._matrix.tY * _matrix.m22 + _matrix.tY;
                _matrix.tX = newTX;
                _matrix.m21 = -_matrix.m21;
                _matrix.m22 = -_matrix.m22;
                if (_isIdentity)
                {
                    _isFlipY = true;
                    _isIdentity = false;
                }
                else if (_isFlipY)
                {
                    _isFlipY = false;
                    _isIdentity = true;
                }
                //check();
                return;
            }

            if (_isIdentity)
            {
                _matrix.m11 = aTransform._matrix.m11;
                _matrix.m12 = aTransform._matrix.m12;
                _matrix.m21 = aTransform._matrix.m21;
                _matrix.m22 = aTransform._matrix.m22;
                _matrix.tX += aTransform._matrix.tX;
                _matrix.tY += aTransform._matrix.tY;
                _isIdentity = false;
                _isFlipY = aTransform._isFlipY;
                //check();
                return;
            }

            if (_isFlipY)
            {
                _matrix.m11 = aTransform._matrix.m11;
                _matrix.m12 = -aTransform._matrix.m12;
                _matrix.m21 = aTransform._matrix.m21;
                _matrix.m22 = -aTransform._matrix.m22;
                _matrix.tX += aTransform._matrix.tX;
                _matrix.tY -= aTransform._matrix.tY;
                _isIdentity = false;
                _isFlipY = false;
                //check();
                return;
            }

            _matrix = matrix_multiply(aTransform._matrix, _matrix);
            _isIdentity = false;
            _isFlipY = false;
            //check();
        }
コード例 #11
0
 public virtual id InitWithTransform(ref NSAffineTransform aTransform)
 {
     id self = this;
     _matrix = aTransform._matrix;
     _isIdentity = aTransform._isIdentity;
     _isFlipY = aTransform._isFlipY;
     return self;
 }
コード例 #12
0
        public virtual id Copy()
        {
            NSAffineTransform transform = new NSAffineTransform();
            transform._matrix = this._matrix;
            transform._isIdentity = this._isIdentity;
            transform._isFlipY = this._isFlipY;

            return transform;
        }