public void TestEquals()
 {
     Assert.AreEqual(sz11_99, sz11_99, "EQ#1");
     Assert.AreEqual(sz11_99, new SizeF(1.1F, 9.9F), "EQ#2");
     Assert.IsFalse(sz11_99.Equals(sz11_0), "EQ#3");
     Assert.IsFalse(sz11_99.Equals(sz0_11), "EQ#4");
     Assert.IsFalse(sz11_0.Equals(sz0_11), "EQ#5");
 }
示例#2
0
        public static void EqualityTest_NotSizeF()
        {
            var size = new SizeF(0, 0);

            Assert.False(size.Equals(null));
            Assert.False(size.Equals(0));
            Assert.False(size.Equals(new Size(0, 0)));
        }
示例#3
0
        public static void EqualityTest_NotSizeF()
        {
            var size = new SizeF(0, 0);

            Assert.False(size.Equals(null));
            Assert.False(size.Equals(0));
            Assert.True(size.Equals(new Size(0, 0)));          // Implicit cast
            Assert.False(size.Equals((object)new Size(0, 0))); // No implicit cast
        }
示例#4
0
 private void DrawScrollbar(Graphics gr)
 {
     if ((this.m_bmpArrowPrevious != null) && this.IsAbleScroollToPrevious())
     {
         Bitmap bmpArrowPrevious = this.m_bmpArrowPrevious;
         if (!m_ScaleFactor.Equals(new SizeF(1f, 1f)))
         {
             if (this.m_bmpArrowPreviousVGA == null)
             {
                 Size size = new Size((int)(this.m_bmpArrowPrevious.Width * m_ScaleFactor.Width), (int)(this.m_bmpArrowPrevious.Height * m_ScaleFactor.Height));
                 this.m_bmpArrowPreviousVGA = DrawingHelper.ResizeBitmap(this.m_bmpArrowPrevious, size);
             }
             bmpArrowPrevious = this.m_bmpArrowPreviousVGA;
         }
         if ((Environment.OSVersion.Platform == PlatformID.WinCE) && this.m_EnableArrowsTransparency)
         {
             DrawingHelper.DrawAlpha(gr, bmpArrowPrevious, this.m_ArrowsTransparency, 0, 0);
         }
         else
         {
             gr.DrawImage(bmpArrowPrevious, 0, 0);
         }
     }
     if ((this.m_bmpArrowNext != null) && this.IsAbleScroollToNext())
     {
         int    x            = 0;
         int    y            = 0;
         Bitmap bmpArrowNext = this.m_bmpArrowNext;
         if (!m_ScaleFactor.Equals(new SizeF(1f, 1f)))
         {
             if (this.m_bmpArrowNextVGA == null)
             {
                 Size size2 = new Size((int)(this.m_bmpArrowNext.Width * m_ScaleFactor.Width), (int)(this.m_bmpArrowNext.Height * m_ScaleFactor.Height));
                 this.m_bmpArrowNextVGA = DrawingHelper.ResizeBitmap(this.m_bmpArrowNext, size2);
             }
             bmpArrowNext = this.m_bmpArrowNextVGA;
         }
         if (this.m_DockType == ToolbarDockType.Horizontal)
         {
             x = base.Width - bmpArrowNext.Width;
         }
         else
         {
             y = base.Height - bmpArrowNext.Height;
         }
         if (this.m_EnableArrowsTransparency)
         {
             DrawingHelper.DrawAlpha(gr, bmpArrowNext, this.m_ArrowsTransparency, x, y);
         }
         else
         {
             gr.DrawImage(bmpArrowNext, x, y);
         }
     }
 }
示例#5
0
        public static void EqualityTest_NotSizeF()
        {
            var size = new SizeF(0, 0);

            Assert.False(size.Equals(null));
            Assert.False(size.Equals(0));

            // If SizeF implements IEquatable<SizeF> (e.g in .NET Core), then classes that are implicitly
            // convertible to SizeF can potentially be equal.
            // See https://github.com/dotnet/runtime/issues/16050.
            bool expectsImplicitCastToSizeF = typeof(IEquatable <SizeF>).IsAssignableFrom(size.GetType());

            Assert.Equal(expectsImplicitCastToSizeF, size.Equals(new Size(0, 0)));

            Assert.False(size.Equals((object)new Size(0, 0))); // No implicit cast
        }
示例#6
0
文件: Helper.cs 项目: taucode/keeker
        internal static bool IsMonospace(this Font font)
        {
            SizeF sizeM   = font.GetCharSize('M');
            SizeF sizeDot = font.GetCharSize('.');

            return(sizeM.Equals(sizeDot));
        }
示例#7
0
        private void ApplyAutoScaling(SizeF baseVar, Form form)
        {
            // We also don't do this if the property is empty.  Otherwise we will perform
            // two GetAutoScaleBaseSize calls only to find that they returned the same
            // value.
            //
            if (!baseVar.IsEmpty)
            {
                SizeF newVarF = Form.GetAutoScaleSize(form.Font);
                Size  newVar  = new Size((int)Math.Round(newVarF.Width), (int)Math.Round(newVarF.Height));

                // We save a significant amount of time by bailing early if there's no work to be done
                if (baseVar.Equals(newVar))
                {
                    return;
                }

                float percY = ((float)newVar.Height) / ((float)baseVar.Height);
                float percX = ((float)newVar.Width) / ((float)baseVar.Width);
                try {
                    inAutoscale = true;
                    form.Scale(percX, percY);
                }
                finally {
                    inAutoscale = false;
                }
            }
        }
示例#8
0
        public override bool Tidy(SnapModes mode, Page page)
        {
            PointF newPoint = m_Centre;

            switch (mode)
            {
            case SnapModes.Grid:
                newPoint = page.Paper.SnapPoint2(newPoint);
                break;

            case SnapModes.Shape:
                newPoint = Lined.TidyPointToShapes(newPoint, page, this);
                break;

            case SnapModes.Angle:
                SizeF newVector = Geometry.AngleSnapVector(m_Exit);
                if (newVector.Equals(m_Exit))
                {
                    return(false);
                }
                m_Exit = newVector;
                return(true);

            default:
                Debug.Fail("Bad Tidy mode");
                break;
            }
            if (newPoint == m_Centre)
            {
                return(false);
            }
            m_Centre = newPoint;
            return(true);
        }
示例#9
0
        public SizeF Measure(AbstractLayout layout, SizeF available)
        {
            if (_constraints.Count == 0)
            {
                var maxRow    = 0;
                var maxColumn = 0;

                for (var index = 0; index < layout.Count; index++)
                {
                    var view       = layout[index];
                    var constraint = view.LayoutConstraints as GridConstraints ?? GridConstraints.Default;
                    _constraints.Add(constraint);

                    maxRow    = Math.Max(maxRow, constraint.Row + constraint.RowSpan - 1);
                    maxColumn = Math.Max(maxColumn, constraint.Column + constraint.ColumnSpan - 1);
                }

                while (maxRow >= _definedRows.Count)
                {
                    _definedRows.Add(DefaultRowHeight);
                }

                while (maxColumn >= _definedColumns.Count)
                {
                    _definedColumns.Add(DefaultColumnWidth);
                }
            }

            if (_gridX == null || !_lastSize.Equals(available))
            {
                ComputeGrid(available.Width, available.Height);
                _lastSize = available;
            }

            for (var index = 0; index < _constraints.Count; index++)
            {
                var view = layout[index];

                if (!view.MeasurementValid)
                {
                    view.MeasuredSize     = view.Measure(available);
                    view.MeasurementValid = true;
                }
            }

            return(new SizeF(_width, _height));
        }
示例#10
0
        public void EqualityTest(float width, float height)
        {
            SizeF sLeft  = new SizeF(width, height);
            SizeF sRight = new SizeF(height, width);

            if (width == height)
            {
                Assert.True(sLeft == sRight);
                Assert.False(sLeft != sRight);
                Assert.True(sLeft.Equals(sRight));
                Assert.Equal(sLeft.GetHashCode(), sRight.GetHashCode());
                return;
            }

            Assert.True(sLeft != sRight);
            Assert.False(sLeft == sRight);
            Assert.False(sLeft.Equals(sRight));
        }
示例#11
0
        public bool SetProperties(SizeF baseSize, string text = null, ITextConfig config = null, int?maxWidth = null,
                                  PointF?scaleUp = null, PointF?scaleDown  = null, int caretPosition          = 0, int caretXOffset = 0, bool renderCaret = false,
                                  bool cropText  = false, bool measureOnly = false)
        {
            bool configIsDifferent = config != null && !config.Equals(_config);
            bool changeNeeded      =
                (text != null && text != _text) ||
                configIsDifferent ||
                (maxWidth != null && maxWidth.Value != _maxWidth) ||
                !baseSize.Equals(_baseSize) ||
                _caretPosition != caretPosition ||
                _renderCaret != renderCaret ||
                _caretXOffset != caretXOffset ||
                cropText != _cropText ||
                measureOnly != _measureOnly ||
                (scaleUp != null && !scaleUp.Value.Equals(_scaleUp)) ||
                (scaleDown != null && !scaleDown.Value.Equals(_scaleDown));

            if (!changeNeeded)
            {
                return(false);
            }

            _text = text;
            if (configIsDifferent)
            {
                _config     = AGSTextConfig.Clone(config);
                _spaceWidth = measureSpace();
            }
            if (maxWidth != null)
            {
                _maxWidth = maxWidth.Value;
            }
            _cropText    = cropText;
            _measureOnly = measureOnly;
            if (scaleUp != null)
            {
                _scaleUp = scaleUp.Value;
            }
            if (scaleDown != null)
            {
                _scaleDown = scaleDown.Value;
            }

            _baseSize      = baseSize;
            _caretPosition = caretPosition;
            _caretXOffset  = caretXOffset;
            _renderCaret   = renderCaret;

            prepareBitmapDraw();

            return(true);
        }
示例#12
0
        public override void LayoutSubviews()
        {
            if (_size.Equals(Bounds.Size))
            {
                return;
            }

            _size = Bounds.Size;

            float scale = _size.Width / _dialView.Image.Size.Width;

            _dialView.Frame = Bounds;

            _needleView.Frame  = new RectangleF(0, 0, _needleView.Image.Size.Width * scale, _needleView.Image.Size.Height * scale);
            _needleView.Center = new PointF(_size.Width / 2, _size.Height / 2);
        }
示例#13
0
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
            SizeF      size  = this._textLabel.Bounds.Size;
            SolidBrush brush = new SolidBrush(Color.WhiteSmoke);

            this._textLabel.Draw(e.Graphics, brush);
            if (!size.Equals(this._textLabel.Bounds.Size))
            {
                base.ClientSize = new Size((int)this._textLabel.Bounds.Width + 70, (int)this._textLabel.Bounds.Height + 70);
                Rectangle bounds = Screen.FromControl(this).Bounds;
                int       x      = bounds.Left + (bounds.Width - base.ClientSize.Width) / 2;
                int       y      = bounds.Top + (bounds.Height - base.ClientSize.Height) / 2;
                base.Location = new Point(x, y);
                base.Invalidate();
            }
        }
示例#14
0
        public void EqualityTest(float width, float height)
        {
            SizeF sLeft = new SizeF(width, height);
            SizeF sRight = new SizeF(height, width);

            if (width == height)
            {
                Assert.True(sLeft == sRight);
                Assert.False(sLeft != sRight);
                Assert.True(sLeft.Equals(sRight));
                Assert.Equal(sLeft.GetHashCode(), sRight.GetHashCode());
                return;
            }

            Assert.True(sLeft != sRight);
            Assert.False(sLeft == sRight);
            Assert.False(sLeft.Equals(sRight));
        }
示例#15
0
文件: Score.cs 项目: cbeihl/pong
        public void Render(SlimDX.Direct2D.Factory factory, SlimDX.DirectWrite.Factory dwFactory, RenderTarget renderTarget)
        {
            if (this.brush == null)
            {
                brush     = new SolidColorBrush(renderTarget, new Color4(1.0f, 1.0f, 1.0f));
                txtFormat = dwFactory.CreateTextFormat("lcd phone", FontWeight.Regular, SlimDX.DirectWrite.FontStyle.Normal, FontStretch.Normal, 60, "en-us");
            }

            SizeF newWindowSize = renderTarget.Size;

            if (windowSize == null || !windowSize.Equals(newWindowSize))
            {
                windowSize = newWindowSize;
                float centerX = windowSize.Width / 2;
                rect = new RectangleF(new PointF(centerX + posOffset.X, posOffset.Y), textLayoutSize);
            }

            renderTarget.DrawText(val.ToString(), txtFormat, rect, brush);
        }
 private void ApplyAutoScaling(SizeF baseVar, Form form)
 {
     if (!baseVar.IsEmpty)
     {
         // This is obsolete:
         //SizeF autoScaleSize = Form.GetAutoScaleSize(form.Font);
         SizeF autoScaleSize = form.AutoScaleDimensions;
         Size  size          = new Size((int)Math.Round((double)autoScaleSize.Width), (int)Math.Round((double)autoScaleSize.Height));
         if (!baseVar.Equals(size))
         {
             var ratio = new SizeF(
                 ((float)size.Height) / baseVar.Height,
                 ((float)size.Width) / baseVar.Width);
             try
             {
                 inAutoscale = true;
                 form.Scale(ratio);
             }
             finally { inAutoscale = false; }
         }
     }
 }
示例#17
0
 private void ApplyAutoScaling(SizeF baseVar, Form form)
 {
     if (!baseVar.IsEmpty)
     {
         SizeF autoScaleSize      = Form.GetAutoScaleSize(form.Font);
         System.Drawing.Size size = new System.Drawing.Size((int)Math.Round((double)autoScaleSize.Width), (int)Math.Round((double)autoScaleSize.Height));
         if (!baseVar.Equals(size))
         {
             float dy = ((float)size.Height) / baseVar.Height;
             float dx = ((float)size.Width) / baseVar.Width;
             try
             {
                 this.inAutoscale = true;
                 form.Scale(dx, dy);
             }
             finally
             {
                 this.inAutoscale = false;
             }
         }
     }
 }
示例#18
0
 public void EqualsEpsilon()
 {
     Assert.IsTrue(SizeD.Equals(sizeD, new SizeD(1.1, 1.9), 0.2));
     Assert.IsTrue(SizeF.Equals(sizeF, new SizeF(1.1f, 1.9f), 0.2f));
 }
示例#19
0
 /// <summary>
 /// Returns true if the two box are equal
 /// </summary>
 /// <param name="other">The other box to compare with</param>
 /// <returns>True if two boxes are equal</returns>
 public bool Equals(RotatedRect other)
 {
     return(Center.Equals(other.Center) &&
            Size.Equals(other.Size) &&
            Angle.Equals(other.Angle));
 }
示例#20
0
 public static void EqualityTest_NotSizeF()
 {
     var size = new SizeF(0, 0);
     Assert.False(size.Equals(null));
     Assert.False(size.Equals(0));
     Assert.False(size.Equals(new Size(0, 0)));
 }
示例#21
0
        public SizeF Measure(AbstractLayout layout, SizeF available)
        {
            if (_constraints.Count == 0)
            {
                var maxRow    = 0;
                var maxColumn = 0;

                for (var index = 0; index < layout.Count; index++)
                {
                    var view       = layout[index];
                    var constraint = view.GetLayoutConstraints() as GridConstraints ?? GridConstraints.Default;
                    _constraints.Add(constraint);

                    maxRow    = Math.Max(maxRow, constraint.Row + constraint.RowSpan - 1);
                    maxColumn = Math.Max(maxColumn, constraint.Column + constraint.ColumnSpan - 1);
                }

                while (maxRow >= _definedRows.Count)
                {
                    _definedRows.Add(DefaultRowHeight);
                }

                while (maxColumn >= _definedColumns.Count)
                {
                    _definedColumns.Add(DefaultColumnWidth);
                }
            }

            if (_gridX == null || !_lastSize.Equals(available))
            {
                ComputeGrid(available.Width, available.Height);
                _lastSize = available;
            }

            for (var index = 0; index < _constraints.Count; index++)
            {
                var position = _constraints[index];
                var view     = layout[index];

                var x = _gridX[position.Column];
                var y = _gridY[position.Row];

                var w = 0f;
                for (var i = 0; i < position.ColumnSpan; i++)
                {
                    w += GetColumnWidth(position.Column + i);
                }

                var h = 0f;
                for (var i = 0; i < position.RowSpan; i++)
                {
                    h += GetRowHeight(position.Row + i);
                }

                if (position.WeightX < 1 || position.WeightY < 1)
                {
                    var viewSize = view.MeasuredSize;

                    if (!view.MeasurementValid)
                    {
                        viewSize = view.Measure(available);
                    }

                    var cellWidth  = w;
                    var cellHeight = h;

                    if (position.WeightX <= 0)
                    {
                        w = viewSize.Width;
                    }
                    else
                    {
                        w *= position.WeightX;
                    }

                    if (position.WeightY <= 0)
                    {
                        h = viewSize.Height;
                    }
                    else
                    {
                        h *= position.WeightY;
                    }

                    if (position.PositionX > 0)
                    {
                        var availWidth = cellWidth - w;
                        x += (float)Math.Round(availWidth * position.PositionX);
                    }

                    if (position.PositionY > 0)
                    {
                        var availHeight = cellHeight - h;
                        y += (float)Math.Round(availHeight * position.PositionY);
                    }

                    view.MeasuredSize     = new SizeF(w, h);
                    view.MeasurementValid = true;
                }

                view.Frame = new RectangleF(x, y, w, h);
            }

            return(new SizeF(_width, _height));
        }
示例#22
0
 /// <summary>
 /// Returns true if the two box are equal
 /// </summary>
 /// <param name="other">The other box to compare with</param>
 /// <returns>True if two boxes are equal</returns>
 public bool Equals(MCvBox2D other)
 {
     return(center.Equals(other.center) &&
            size.Equals(other.size) &&
            angle == other.angle);
 }
示例#23
0
 /// <summary>
 /// Check if the two blobs are equal
 /// </summary>
 /// <param name="other">The blob to compares with</param>
 /// <returns>True if equals</returns>
 public bool Equals(MCvBlob other)
 {
     return(Center.Equals(other.Center) && Size.Equals(other.Size) && ID == other.ID);
 }
示例#24
0
        public override void Draw(CGRect rect)
        {
            var boundsRect = Bounds;

            boundsRect.Height = drawHeight;
            if (SizeF.Equals(boundsRect.Size, lastBoundsSize))
            {
                RegenerateImages();
                lastBoundsSize = boundsRect.Size;
            }

            nfloat width       = boundsRect.Size.Width;
            nfloat drawPercent = percent;

            if (((width - knobWidth) * drawPercent) < 3)
            {
                drawPercent = 0.0f;
            }
            if (((width - knobWidth) * drawPercent) > (width - knobWidth - 3))
            {
                drawPercent = 1.0f;
            }

            if (endDate != DateTime.MinValue)
            {
                var interval = (endDate - DateTime.Now).TotalSeconds;
                if (interval < 0.0)
                {
                    endDate = DateTime.MinValue;
                }
                else
                {
                    if (percent == 1f)
                    {
                        drawPercent = (float)Math.Cos((interval / animationDuration) * (Math.PI / 2.0));
                    }
                    else
                    {
                        drawPercent = 1.0f - (float)Math.Cos((interval / animationDuration) * (Math.PI / 2.0));
                    }
                    PerformSelector(new Selector("setNeedsDisplay"), null, 0.0);
                }
            }

            CGContext context = UIGraphics.GetCurrentContext();

            context.SaveState();
            UIGraphics.PushContext(context);

            if (drawPercent != 1.0)
            {
                var sliderOffRect = boundsRect;
                sliderOffRect.Height = sliderOff.Size.Height;
                sliderOff.Draw(sliderOffRect);
            }


            if (drawPercent > 0.0f && drawPercent < 1.0f)
            {
                nfloat  onWidth          = knobWidth / 2 + ((width - knobWidth / 2) - knobWidth / 2) * drawPercent;
                var     sourceRect       = new CGRect(0, 0, onWidth * scale, sliderOn.Size.Height * scale);
                var     drawOnRect       = new CGRect(0, 0, onWidth, sliderOn.Size.Height);
                CGImage sliderOnSubImage = sliderOn.CGImage.WithImageInRect(sourceRect);
                context.SaveState();
                context.ScaleCTM(1, -1);
                context.TranslateCTM(0, -drawOnRect.Height);
                context.DrawImage(drawOnRect, sliderOnSubImage);
                context.RestoreState();
            }

            if (drawPercent == 1.0)
            {
                nfloat  onWidth          = sliderOn.Size.Width;
                var     sourceRect       = new CGRect(0, 0, onWidth * scale, sliderOn.Size.Height * scale);
                var     drawOnRect       = new CGRect(0, 0, onWidth, sliderOn.Size.Height);
                CGImage sliderOnSubImage = sliderOn.CGImage.WithImageInRect(sourceRect);
                context.SaveState();
                context.ScaleCTM(1, -1);
                context.TranslateCTM(0, -drawOnRect.Height);
                context.DrawImage(drawOnRect, sliderOnSubImage);
                context.RestoreState();
            }


            context.SaveState();
            UIGraphics.PushContext(context);
            var insetClipRect = boundsRect.Inset(4, 4);

            UIGraphics.RectClip(insetClipRect);
            DrawUnderlayersInRect(rect, drawPercent * (boundsRect.Width - knobWidth), boundsRect.Width - knobWidth);
            UIGraphics.PopContext();
            context.RestoreState();

            context.ScaleCTM(1, -1);
            context.TranslateCTM(0, -boundsRect.Height);
            CGPoint location    = boundsRect.Location;
            UIImage imageToDraw = knobImage;

            if (this.Highlighted)
            {
                imageToDraw = knobImageOff;
            }

            nfloat xlocation;

            if (drawPercent == 0.0f)
            {
                xlocation = location.X + 3 + (nfloat)Math.Round(drawPercent * (boundsRect.Width - knobWidth + 2));
            }
            else
            {
                xlocation = location.X - 5 + (nfloat)Math.Round(drawPercent * (boundsRect.Width - knobWidth + 2));
                xlocation = xlocation < 0.0f ? 0.0f : xlocation;
            }

            var rectToDraw = new CGRect(xlocation, location.Y + 9.5f, knobWidth, knobImage.Size.Height);

            context.DrawImage(rectToDraw, imageToDraw.CGImage);

            UIGraphics.PopContext();
            context.RestoreState();
        }