Equals() 공개 메소드

Tests whether obj is a with the same location and size of this .

public Equals ( object obj ) : bool
obj object
리턴 bool
예제 #1
0
		/// <summary>
		/// Returns new dimensions of the image's bounding rect according to its parameters
		/// </summary>
		/// <param name="pict">Image reference</param>
		/// <param name="rect">Image bounding rect</param>
		/// <param name="ppos">Image alignment</param>
		/// <param name="picw">New image's width value</param>
		/// <param name="pich">New image's height value</param>
		/// <param name="xoff">Image's X offset</param>
		/// <param name="yoff">Image's Y offset</param>
		/// <returns>true if successfull otherwise false</returns>
		public bool GetImageDim(Image pict, RectangleF rect, ImageAlign ppos, ref float  picw, ref float pich , ref float xoff , ref float yoff)
		{
			bool bOk = false;
			int xc = 0, yc = 0;

			try
			{
			
				if ( rect.Equals(RectangleF.Empty))
					return false;

				picw = 0;
				pich = 0;
				xoff =0;
				yoff =0;

				Graphics g = System.Drawing.Graphics.FromHwnd(GetActiveWindow());
				setTransforms(g);

				// get image logical size in document coordinates
				RectangleF sizeDev = RectangleF.FromLTRB(0, 0,
					(float)pict.Size.Width / pict.HorizontalResolution * g.DpiX * g.PageScale,
					(float)pict.Size.Height / pict.VerticalResolution * g.DpiY * g.PageScale);
				RectangleF sizeDoc = deviceToDoc(g, sizeDev);
				picw = sizeDoc.Width;
				pich = sizeDoc.Height;

				
				switch (ppos)
				{
					case ImageAlign.TopLeft:
						xoff = rect.Left;
						yoff = rect.Top;
						break;
					case ImageAlign.BottomLeft:
						xoff = rect.Left;
						yoff = rect.Bottom - pich;
						break;
					case ImageAlign.TopRight:
						xoff = rect.Right - picw;
						yoff = rect.Top;
						break;
					case ImageAlign.BottomRight:
						xoff = rect.Right - picw;
						yoff = rect.Bottom - pich;
						break;
					case ImageAlign.Center:
						xoff = (rect.Right + rect.Left - picw) / 2;
						yoff = (rect.Bottom + rect.Top - pich) / 2;
						break;
					case ImageAlign.TopCenter:
						xoff = rect.X + rect.Width / 2 - picw / 2;
						yoff = rect.Y;
						break;
					case ImageAlign.BottomCenter:
						xoff = rect.X + rect.Width / 2 - picw / 2;
						yoff = rect.Bottom - pich;
						break;
					case ImageAlign.MiddleLeft:
						xoff = rect.X;
						yoff = rect.Y + rect.Height / 2 - pich / 2;
						break;
					case ImageAlign.MiddleRight:
						xoff = rect.Right - picw;
						yoff = rect.Y + rect.Height / 2 - pich / 2;
						break;
					case ImageAlign.Fit:
					{
						float h = rect.Bottom - rect.Top;
						float w = rect.Right - rect.Left;
						if (h == 0) break;

						float ratioCtrl = w / h;
						float ratioPic = picw / pich;

						if (ratioCtrl > ratioPic)
						{
							//stretch vertically
							pich = (int)h;
							picw = (int)(ratioPic * pich);
							yoff = rect.Top;
							xoff = (rect.Right + rect.Left - picw) / 2;
						}
						else
						{
							//stretch horizontally
							picw = (int)w;
							if (ratioPic == 0) break;
							pich = (int)(picw / ratioPic);
							xoff = rect.Left;
							yoff = (rect.Bottom + rect.Top - pich) / 2;
						}
					}
						break;
					case ImageAlign.Stretch:
					{
						picw = rect.Right - rect.Left;
						pich = rect.Bottom - rect.Top;
						xoff = rect.Left; yoff = rect.Top;
					}
						break;
					case ImageAlign.Tile:
					{
						xoff = rect.Left; yoff = rect.Top;
						xc = (int)((rect.Right - rect.Left) / picw) + 1;
						yc = (int)((rect.Bottom - rect.Top) / pich) + 1;
					}
						break;

					default:
						return false;
				}

				PointF center = new PointF(
					rect.X + rect.Width / 2,
					rect.Y + rect.Height / 2);
				bOk = true;
			}
		
			catch ( Exception ex )
			{
				Trace.WriteLine(String.Format("{0} error {1}\n","SvgManager.GetImageDim",ex.Message));
				bOk = false;
			}
			
			return bOk;
		}
예제 #2
0
파일: Graphics.cs 프로젝트: kumpera/mono
		public void ClipBoundsTest() {
			Region r = new Region();
			Assert.IsTrue(t.Graphics.ClipBounds.Equals(r.GetBounds(t.Graphics)));

			RectangleF rf = new RectangleF(10, 10, 60, 60);
			r = new Region(rf);
			t.Graphics.Clip = r;
			Assert.IsTrue(rf.Equals(t.Graphics.ClipBounds));
		}
예제 #3
0
 internal void drawingCanvas_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
 {
     if (e.Button == System.Windows.Forms.MouseButtons.Left)
     {
         Visible = false;
     }
     else
     {
         PointF[] ptArr = { new PointF(e.X, e.Y) };
         canvas.CreateGraphicsWithWorldTransform().TransformPoints(CoordinateSpace.World, CoordinateSpace.Page, ptArr);
         //canvas.MouseLocation = ptArr[0];
         float gridSize = grid.GridSize;
         PointF pos = new PointF((float)Math.Floor(ptArr[0].X / gridSize) * gridSize, (float)Math.Floor(ptArr[0].Y / gridSize) * gridSize);
         RectangleF newMouseRectangle = new RectangleF(pos, new SizeF(gridSize, gridSize));
         if (!newMouseRectangle.Equals(HighlightRectangle))
         {
             HighlightRectangle = newMouseRectangle;
             ((PictureBox)sender).Invalidate();
         }
     }
 }
예제 #4
0
        /// <summary>
        /// Compares the imput rectangles and caculates the portion of the new rctangle not included in the old.
        /// </summary>
        /// <param name="current"> The current rectangle</param>
        /// <param name="previous">The previous rectangle</param>
        /// <returns>An array of rectangles describing the difference between the input rectangles.</returns>
        /// <remarks>
        /// This funtion is a liner exclusive OR on 2 rectangles. It is catagorized by specifying the order of the 
        /// rectangles in a linear fashion so that the xor'd intersection is directional. A natural XOR intersection
        /// would include the portions of both rectangles not found the intersction of the two. A Linear XOR includes 
        /// only the portion of the current rectangle not found in the intersection of the two.
        /// </remarks>
        public static RectangleF[] GetRegionScans(RectangleF current, RectangleF previous)
        {
            // If the extents are equal, or one contains the other, or they're not intersecting there's nothing
            // to do. Return the current rectangle. 
            if (
                !current.Equals(previous) &&
                !Contains(current, previous) &&
                !Contains(previous, current) &&
                IntersectsWith(current, previous))
            {
                // Get the horizontal rectangle, uncovered from a north or south pan 
                RectangleF h = RectangleFHelper.FromLTRB(
                    current.Left, //current.Left < previous.Left ? current.Left : previous.Left,
                    current.Top < previous.Top ? current.Top : previous.Bottom,
                    current.Right, //current.Left < previous.Left ? previous.Right : current.Right,
                    current.Top < previous.Top ? previous.Top : current.Bottom
                    );

                // Get the vertical rectangle, uncovered from an east or west pan 
                RectangleF v = RectangleFHelper.FromLTRB(
                    current.Left < previous.Left ? current.Left : previous.Right,
                    current.Top < previous.Top ? previous.Top : current.Top,
                    current.Left < previous.Left ? previous.Left : current.Right,
                    current.Top < previous.Top ? current.Bottom : previous.Bottom
                    );

                // Retangles with no width or height are excluded
                if ((h.Height <= 0 || h.Width <= 0) && (v.Height <= 0 || v.Width <= 0))
                    return new RectangleF[] { current };

                // Retangles with no width or height are excluded
                if (h.Height <= 0 || h.Width <= 0)
                    return new RectangleF[] { v };
                if (v.Height <= 0 || v.Width <= 0)
                    return new RectangleF[] { h };

                return new RectangleF[] { h, v };
            }

            return new RectangleF[] { current };
        }
예제 #5
0
        public static UIImage ButtonImage(UIColor color, float cornerRadius, UIColor shadowColor, UIEdgeInsets shadowInsets)
        {
            UIImage topImage = FlatUI.Image(color, cornerRadius);
            UIImage bottomImage = FlatUI.Image(shadowColor, cornerRadius);
            float totalHeight = FlatUI.EdgeSize(cornerRadius) + shadowInsets.Top + shadowInsets.Bottom;
            float totalWidth = FlatUI.EdgeSize(cornerRadius) + shadowInsets.Left + shadowInsets.Right;
            float topWidth = FlatUI.EdgeSize(cornerRadius);
            float topHeight = FlatUI.EdgeSize(cornerRadius);
            RectangleF topRect = new RectangleF(shadowInsets.Left, shadowInsets.Top, topWidth, topHeight);
            RectangleF bottomRect = new RectangleF(0, 0, totalWidth, totalHeight);

            UIGraphics.BeginImageContextWithOptions(new SizeF(totalWidth, totalHeight), false, 0f);
            if (!bottomRect.Equals(topRect))
                bottomImage.Draw(bottomRect);
            topImage.Draw(topRect);
            UIImage buttonImage = UIGraphics.GetImageFromCurrentImageContext();
            UIEdgeInsets resizeableInsets = new UIEdgeInsets(cornerRadius + shadowInsets.Top,
                                                             cornerRadius + shadowInsets.Left,
                                                             cornerRadius + shadowInsets.Bottom,
                                                             cornerRadius + shadowInsets.Right);
            UIGraphics.EndImageContext();
            return buttonImage.CreateResizableImage(resizeableInsets);
        }
예제 #6
0
        private void RelayoutItemsAnimated(bool animated)
        {
            //Console.WriteLine ("Relayout animated " + animated);

            RelayoutBlock layoutBlock = delegate
            {
                ItemSubviews.EnumerateGridCells(delegate(GridViewCell view,out bool stop)
                {
                    stop=false;
                    if (view != sortMovingItem && view != transformingItem)
                    {
                        int index = view.Tag - kTagOffset;
                        PointF origin = layoutStrategy.OriginForItemAtPosition(index);
                        RectangleF newFrame = new RectangleF(origin.X, origin.Y, itemSize.Width, itemSize.Height);

                        // IF statement added for performance reasons (Time Profiling in instruments)
                        if (!newFrame.Equals(view.Frame))
                        {
                            view.Frame = newFrame;
                        }
                    }
                });
            };

            if (animated)
            {
                UIView.Animate(kDefaultAnimationDuration,0,kDefaultAnimationOptions,
                delegate
                {
                    layoutBlock();
                },
                delegate
                {

                });
            }
            else
            {
                layoutBlock();
            }
        }