Intersect() private method

private Intersect ( RectangleF a, RectangleF b ) : RectangleF
a RectangleF
b RectangleF
return RectangleF
コード例 #1
0
        public static float CalculateIntersectPercentage(RectangleF rect, RectangleF referenceRect)
        {
            if (rect.IsEmpty || referenceRect.IsEmpty) return 0;

            referenceRect.Intersect(rect); // replace referenceRect with intersect
            return referenceRect.IsEmpty ? 0 : (referenceRect.Width * referenceRect.Height) / (rect.Width * rect.Height);
        }
コード例 #2
0
ファイル: ColorRect.cs プロジェクト: jamiebriant/monomac
		public void DrawRect(RectangleF aRect, bool selected)
		{
			NSGraphics.RectClip (aRect);
			
			aRect.Intersect (Frame);
			
			Color.Set ();
			NSGraphics.RectFill (aRect);
			
		    if (selected) {
		        NSColor.Black.Set ();
		        NSGraphics.FrameRectWithWidth (Frame, 4.0f);
		    }
			
			if (IsLocked){
				float xSize = (Frame.Width > 10.0f) ? 5.0f : 3.0f;
				
				NSBezierPath path = NSBezierPath.CreateBezierPath ();
				
				NSColor.Black.Set ();
				path.LineWidth = 3.0f;
				path.MoveTo (new PointF (MidX (Frame) - xSize, MidY (Frame) - xSize));
				path.LineTo (new PointF (MidX (Frame) + xSize, MidY (Frame) + xSize));
				path.MoveTo (new PointF (MidX (Frame) - xSize, MidY (Frame) + xSize));
				path.LineTo (new PointF (MidX (Frame) + xSize, MidY (Frame) - xSize));
				path.Stroke ();
				
			}
	
		}
コード例 #3
0
        /// <include file='doc\RectangleF.uex' path='docs/doc[@for="RectangleF.Intersect"]/*' />
        /// <devdoc> Creates a Rectangle that represents the intersection between this Rectangle and rect.
        /// </devdoc>
        public void Intersect(RectangleF rect)
        {
            RectangleF result = RectangleF.Intersect(rect, this);

            this.X      = result.X;
            this.Y      = result.Y;
            this.Width  = result.Width;
            this.Height = result.Height;
        }
コード例 #4
0
ファイル: RectangleF.cs プロジェクト: x11us/corefx
        /// <summary> Creates a Rectangle that represents the intersection between this Rectangle and rect.
        /// </summary>
        public void Intersect(RectangleF rect)
        {
            RectangleF result = RectangleF.Intersect(rect, this);

            X      = result.X;
            Y      = result.Y;
            Width  = result.Width;
            Height = result.Height;
        }
コード例 #5
0
		public override void Draw (RectangleF rect)
		{
			using (var context = UIGraphics.GetCurrentContext ()) {

				// get the scale from the context by getting the current transform matrix, then asking for
				// its "a" component, which is one of the two scale components. We could also ask for "d".
				// This assumes (safely) that the view is being scaled equally in both dimensions.
				var scale = context.GetCTM ().xx;
				CATiledLayer tiledLayer = (CATiledLayer)this.Layer; 
				var tileSize = tiledLayer.TileSize;

				// Even at scales lower than 100%, we are drawing into a rect in the coordinate system of the full
				// image. One tile at 50% covers the width (in original image coordinates) of two tiles at 100%. 
				// So at 50% we need to stretch our tiles to double the width and height; at 25% we need to stretch 
				// them to quadruple the width and height; and so on.
				// (Note that this means that we are drawing very blurry images as the scale gets low. At 12.5%, 
				// our lowest scale, we are stretching about 6 small tiles to fill the entire original image area. 
				// But this is okay, because the big blurry image we're drawing here will be scaled way down before 
				// it is displayed.)
				tileSize.Width /= scale;
				tileSize.Height /= scale;

				// calculate the rows and columns of tiles that intersect the rect we have been asked to draw
				int firstCol = (int)Math.Floor (rect.GetMinX () / tileSize.Width);
				int lastCol = (int)Math.Floor ((rect.GetMaxX () - 1) / tileSize.Width);
				int firstRow = (int)Math.Floor (rect.GetMinY () / tileSize.Height);
				int lastRow = (int)Math.Floor ((rect.GetMaxY () - 1) / tileSize.Height);

				for (int row = firstRow; row <= lastRow; row++) {
					for (int col = firstCol; col <= lastCol; col++) {
					 
						UIImage tile = TileForScale (scale, row, col);
						var tileRect = new RectangleF (tileSize.Width * col, tileSize.Height * row, tileSize.Width, tileSize.Height);
						// if the tile would stick outside of our bounds, we need to truncate it so as to avoid
						// stretching out the partial tiles at the right and bottom edges
						tileRect.Intersect (this.Bounds);
						tile.Draw (tileRect);
					}
				}
			}
		}
コード例 #6
0
ファイル: FwGraphics.cs プロジェクト: sillsdev/WorldPad
		/// -----------------------------------------------------------------------------------
		/// <summary>Member FwInvertRect</summary>
		/// <param name='xLeft'>xLeft</param>
		/// <param name='yTop'>yTop</param>
		/// <param name='xRight'>xRight</param>
		/// <param name='yBottom'>yBottom</param>
		/// -----------------------------------------------------------------------------------
		public void FwInvertRect(int xLeft, int yTop, int xRight, int yBottom)
		{
			Debug.Assert(m_bitmapGraphics != null);
			RectangleF rc = new RectangleF(xLeft, yTop, xRight - xLeft,
				yBottom - yTop);

			if (!rc.IntersectsWith(m_bitmapGraphics.VisibleClipBounds))
				return;
			rc.Intersect(m_bitmapGraphics.VisibleClipBounds);

			//RectangleF rect = new RectangleF(xLeft, yTop, xRight - xLeft + 1, yBottom - yTop + 1);
			//rect.Intersect(m_bitmapGraphics.VisibleClipBounds);
			//Rectangle rc = new Rectangle(
			//	m_parent.PointToScreen(new Point((int)rect.X, (int)rect.Y)),
			//	new Size((int)rect.Width, (int)rect.Height));

			//ControlPaint.FillReversibleRectangle(rc, m_backColor);


			m_backColor = Color.FromArgb(150, SystemColors.Highlight);
			m_bitmapGraphics.FillRectangle(new SolidBrush(m_backColor), rc);
		}
コード例 #7
0
ファイル: Session.cs プロジェクト: xyfgit/salem-map-tool
		public void Draw(Graphics g)
		{
			RectangleF dst;
			RectangleF src;

			foreach (Tile tile in tiles)
			{
				src = new RectangleF(tile.X, tile.Y, tile.Width, tile.Height);
				src.Intersect(fov);
				
				if (src.Width.Equals(0) || src.Height.Equals(0))
					continue;

				dst = new RectangleF(p0.X + (tile.X - fov.Left) * zoom, p0.Y + (tile.Y - fov.Top) * zoom, tile.Width * zoom, tile.Height * zoom);
				dst.Intersect(p);

				src = new RectangleF(src.Left - tile.X, src.Top - tile.Y, src.Width, src.Height);

				g.DrawImage(tile.Image, dst, src, GraphicsUnit.Pixel);
			}

			if (chosen != null)
			{
				dst = new RectangleF(p0.X + (chosen.X - fov.Left) * zoom, 
					p0.Y + (chosen.Y - fov.Top) * zoom, 
					chosen.Width * zoom, chosen.Height * zoom);
				dst.Intersect(p);

				if (zoom > 0.2)
				{
					g.DrawRectangle(Pens.White, dst.Left, dst.Top, dst.Width - 1, dst.Height - 1);
					g.FillRectangle(new HatchBrush(HatchStyle.DiagonalCross, Color.White, Color.Transparent),
						dst.Left, dst.Top, dst.Width - 1, dst.Height - 1);
				}
				else
				{
					g.FillRectangle(Brushes.White, dst.Left, dst.Top, dst.Width - 1, dst.Height - 1);
				}
			}

			if (!selection.Width.Equals(r.Width) || !selection.Height.Equals(r.Height))
			{
				dst = new RectangleF(p0.X + (selection.Left - fov.Left) * zoom,
						p0.Y + (selection.Top - fov.Top) * zoom,
						selection.Width * zoom - 1, selection.Height * zoom - 1);
				dst.Intersect(p);
				g.DrawRectangle(new Pen(Brushes.Yellow, 3), dst.Left, dst.Top, dst.Width, dst.Height);
			}
		}
コード例 #8
0
ファイル: Session.cs プロジェクト: xyfgit/salem-map-tool
		public void Move(int x, int y)
		{ 
			if (selecting)
			{
				float xx = fov.Left + (x - p0.X) / zoom;
				float yy = fov.Top + (y - p0.Y) / zoom;

				selection = new RectangleF(xx > s0.X ? s0.X : xx, 
					yy > s0.Y ? s0.Y : yy,
					Math.Abs(xx - s0.X), Math.Abs(yy - s0.Y));

				selection = new RectangleF((float)Math.Floor(selection.Left / tileSize) * tileSize,
					(float)Math.Floor(selection.Top / tileSize) * tileSize,
					(float)(Math.Ceiling(selection.Right / tileSize) - Math.Floor(selection.Left / tileSize)) * tileSize, 
					(float)(Math.Ceiling(selection.Bottom / tileSize) - Math.Floor(selection.Top / tileSize)) * tileSize);

				selection.Intersect(r);
			}
			else 
			{
				fov = new RectangleF(
					Math.Max(0, Math.Min(fov.Left - x / zoom, r.Right - fov.Width)),
					Math.Max(0, Math.Min(fov.Top - y / zoom, r.Bottom - fov.Height)), 
					fov.Width, fov.Height);
			}
		}
コード例 #9
0
ファイル: DayPanel.cs プロジェクト: kjburns31/vixen-modules
        private void _DrawTimes(Graphics g)
        {
            RectangleF rect = new RectangleF(0, 0, TimeGutter, Height);
            rect.Intersect(g.VisibleClipBounds);
            g.FillRectangle(_backgroundBrush, rect);

            // Times
            int startHalfHour = _GetHalfHourAt((int)g.VisibleClipBounds.Y) / 2 * 2;
            int hour = startHalfHour / 2;
            int topHour = (_TopHalfHour % 2 == 1) ? _TopHalfHour / 2 + 1 : _TopHalfHour / 2;
            string hourString;
            int midPoint = TimeGutter >> 1;
            string meridianString;

            for(int y = startHalfHour * HalfHourHeight; y < g.VisibleClipBounds.Bottom && hour < 24; y += HalfHourHeight * 2) {
                if(hour == 0) {
                    hourString = "12";
                } else if(hour > 12) {
                    hourString = (hour - 12).ToString();
                } else {
                    hourString = hour.ToString();
                }

                g.DrawLine(_timeLinePen, 5, y, TimeGutter - 5, y);
                g.DrawString(hourString, TimeLargeFont, Brushes.Black, midPoint - (int)(g.MeasureString(hourString, TimeLargeFont).Width) + 6, y + 3);

                // AM/PM
                if(hour == topHour) {
                    meridianString = topHour / 12 == 0 ? "am" : "pm";
                } else {
                    meridianString = "00";
                }

                g.DrawString(meridianString, TimeSmallFont, Brushes.Black, midPoint + 2, y + 3);
                hour++;
            }
        }
コード例 #10
0
ファイル: GameObject.cs プロジェクト: maestun/wonderboy
 public void CheckCollisions(TileMap tileMap)
 {
     bool flag = base.type == ObjectType.Mouse;
     bool flag2 = false;
     bool flag3 = true;
     bool flag4 = true;
     PointF tf = new PointF();
     PointF tf2 = new PointF();
     PointF tf3 = new PointF();
     RectangleF collisionRectangle = this.GetCollisionRectangle(true);
     RectangleF ef2 = this.GetCollisionRectangle(false);
     RectangleF block = new RectangleF((PointF) new Point(0, 0), (SizeF) GameMap.TileSize);
     RectangleF ef4 = new RectangleF((PointF) new Point(0, 0), (SizeF) GameMap.TileSize);
     bool flag5 = false;
     bool flag6 = false;
     float num = 0f;
     float num2 = 0f;
     float num3 = 0f;
     float num4 = 0f;
     Rectangle tilesAroundObject = tileMap.GetTilesAroundObject(collisionRectangle);
     for (int i = tilesAroundObject.X; i < (tilesAroundObject.X + tilesAroundObject.Width); i++)
     {
         for (int j = tilesAroundObject.Y; j < (tilesAroundObject.Y + tilesAroundObject.Height); j++)
         {
             flag3 = true;
             flag4 = true;
             tf.X = collisionRectangle.X + (collisionRectangle.Width / 2f);
             tf.Y = collisionRectangle.Y + (collisionRectangle.Height / 2f);
             tf2.X = ef2.X + (ef2.Width / 2f);
             tf2.Y = ef2.Y + (ef2.Height / 2f);
             num = collisionRectangle.X - ef2.X;
             num2 = collisionRectangle.Y - ef2.Y;
             SurfaceType surfaceType = GameEngine.Game.CurrentMap.GetSurfaceType(i, j, this.aquatic);
             SurfaceType type4 = GameEngine.Game.CurrentMap.GetSurfaceType(i, j - 1, this.aquatic);
             SurfaceType type5 = GameEngine.Game.CurrentMap.GetSurfaceType(i, j + 1, this.aquatic);
             SurfaceType type2 = GameEngine.Game.CurrentMap.GetSurfaceType(i - 1, j, this.aquatic);
             SurfaceType type3 = GameEngine.Game.CurrentMap.GetSurfaceType(i + 1, j, this.aquatic);
             if (surfaceType != SurfaceType.None)
             {
                 flag6 = false;
                 num3 = 0f;
                 num4 = 0f;
                 block.X = i * block.Width;
                 block.Y = j * block.Height;
                 tf3.X = block.X + (block.Width / 2f);
                 tf3.Y = block.Y + (block.Height / 2f);
                 ef4.X = block.X;
                 ef4.Y = block.Y;
                 ef4.Width = block.Width;
                 ef4.Height = block.Height;
                 ef4.Intersect(collisionRectangle);
                 if ((ef4.Width > 0f) || (ef4.Height > 0f))
                 {
                     num3 = 0f;
                     num4 = 0f;
                     if (ef4.Height <= ef4.Width)
                     {
                         if ((num2 >= 0f) && (tf.Y < tf3.Y))
                         {
                             if (type4 == SurfaceType.None)
                             {
                                 flag2 = true;
                                 flag6 = this.ySpeed.CurrentSpeed >= 0f;
                                 if (this.CurrentAnimation == AnimType.Jump)
                                 {
                                     this.CurrentAnimation = AnimType.Stopped;
                                 }
                                 if ((surfaceType == SurfaceType.Spring) || ((tf.X > block.Left) && (tf.X <= block.Right)))
                                 {
                                     if ((surfaceType != SurfaceType.MouseBlock) || (base.objectClass == ObjectClass.Item))
                                     {
                                         flag6 = false;
                                     }
                                     this.behavior.HandleHitSurface(surfaceType, block, Direction.Up);
                                 }
                                 num4 = block.Top - collisionRectangle.Bottom;
                             }
                         }
                         else if (((num2 <= 0f) && (tf.Y > tf3.Y)) && (type5 == SurfaceType.None))
                         {
                             num4 = block.Bottom - collisionRectangle.Top;
                             flag6 = this.ySpeed.CurrentSpeed <= 0f;
                             if ((tf.X > block.Left) && (tf.X < block.Right))
                             {
                                 this.behavior.HandleHitSurface(surfaceType, block, Direction.Down);
                             }
                         }
                     }
                     if (ef4.Height >= ef4.Width)
                     {
                         if ((num >= 0f) && (tf.X < tf3.X))
                         {
                             if (type2 == SurfaceType.None)
                             {
                                 num3 = block.Left - collisionRectangle.Right;
                                 if ((tf.Y >= block.Top) && (tf.Y <= block.Bottom))
                                 {
                                     this.behavior.HandleHitSurface(surfaceType, block, Direction.Left);
                                 }
                                 flag5 = this.xSpeed.CurrentSpeed >= 0f;
                             }
                         }
                         else if (((num <= 0f) && (tf.X > tf3.X)) && (type3 == SurfaceType.None))
                         {
                             num3 = block.Right - collisionRectangle.Left;
                             if ((tf.Y >= block.Top) && (tf.Y <= block.Bottom))
                             {
                                 this.behavior.HandleHitSurface(surfaceType, block, Direction.Right);
                             }
                             flag5 = this.xSpeed.CurrentSpeed <= 0f;
                         }
                     }
                     if (this.stopsAtLedges && ((base.objectClass == ObjectClass.Enemy) || (surfaceType == SurfaceType.MouseBlock)))
                     {
                         if (flag6)
                         {
                             if (tf.X > tf3.X)
                             {
                                 if (((flag && (type3 != SurfaceType.MouseBlock)) || (!flag && (type3 == SurfaceType.None))) && (((this.xSpeed.CurrentSpeed >= 0f) && (tf.X >= block.Right)) && (tf2.X <= block.Right)))
                                 {
                                     if (type3 == SurfaceType.None)
                                     {
                                         if ((tf.Y < tf3.Y) && (this.currentRotation == Direction.Up))
                                         {
                                             this.behavior.HandleOnLedge(surfaceType, block, Corner.TopRight);
                                         }
                                         else if ((tf.Y >= tf3.Y) && (this.currentRotation == Direction.Down))
                                         {
                                             this.behavior.HandleOnLedge(surfaceType, block, Corner.BottomRight);
                                         }
                                         else
                                         {
                                             flag6 = false;
                                         }
                                     }
                                     if (flag6)
                                     {
                                         this.xSpeed.CurrentSpeed = 0f;
                                         this.newLocation.X = block.Right;
                                         collisionRectangle.X = block.Right;
                                         flag3 = false;
                                     }
                                 }
                             }
                             else if (((flag && (type2 != SurfaceType.MouseBlock)) || (!flag && (type2 == SurfaceType.None))) && (((this.xSpeed.CurrentSpeed <= 0f) && (tf.X <= block.Left)) && (tf2.X >= block.Left)))
                             {
                                 if (type2 == SurfaceType.None)
                                 {
                                     if ((tf.Y < tf3.Y) && (this.currentRotation == Direction.Up))
                                     {
                                         this.behavior.HandleOnLedge(surfaceType, block, Corner.TopLeft);
                                     }
                                     else if ((tf.Y >= tf3.Y) && (this.currentRotation == Direction.Down))
                                     {
                                         this.behavior.HandleOnLedge(surfaceType, block, Corner.BottomLeft);
                                     }
                                     else
                                     {
                                         flag6 = false;
                                     }
                                 }
                                 if (flag6)
                                 {
                                     this.xSpeed.CurrentSpeed = 0f;
                                     this.newLocation.X = block.Left;
                                     collisionRectangle.X = block.Left;
                                     flag3 = false;
                                 }
                             }
                         }
                         else if (flag5)
                         {
                             if (tf.Y > tf3.Y)
                             {
                                 if (((flag && (type5 != SurfaceType.MouseBlock)) || (!flag && (type5 == SurfaceType.None))) && (((this.ySpeed.CurrentSpeed >= 0f) && (tf.Y >= block.Bottom)) && (tf2.Y <= block.Bottom)))
                                 {
                                     if (type5 == SurfaceType.None)
                                     {
                                         if ((tf.X < tf3.X) && (this.currentRotation == Direction.Left))
                                         {
                                             this.behavior.HandleOnLedge(surfaceType, block, Corner.LeftBottom);
                                         }
                                         else if ((tf.X >= tf3.X) && (this.currentRotation == Direction.Right))
                                         {
                                             this.behavior.HandleOnLedge(surfaceType, block, Corner.RightBottom);
                                         }
                                         else
                                         {
                                             flag5 = false;
                                         }
                                     }
                                     if (flag5)
                                     {
                                         this.ySpeed.CurrentSpeed = 0f;
                                         this.newLocation.Y = block.Bottom;
                                         collisionRectangle.Y = block.Bottom;
                                         flag4 = false;
                                     }
                                 }
                             }
                             else if (((flag && (type4 != SurfaceType.MouseBlock)) || (!flag && (type4 == SurfaceType.None))) && (((this.ySpeed.CurrentSpeed <= 0f) && (tf.Y <= block.Top)) && (tf2.Y >= block.Top)))
                             {
                                 if (type4 == SurfaceType.None)
                                 {
                                     if ((tf.X < tf3.X) && (this.currentRotation == Direction.Left))
                                     {
                                         this.behavior.HandleOnLedge(surfaceType, block, Corner.LeftTop);
                                     }
                                     else if ((tf.X >= tf3.X) && (this.currentRotation == Direction.Right))
                                     {
                                         this.behavior.HandleOnLedge(surfaceType, block, Corner.RightTop);
                                     }
                                     else
                                     {
                                         flag5 = false;
                                     }
                                 }
                                 if (flag5)
                                 {
                                     this.ySpeed.CurrentSpeed = 0f;
                                     this.newLocation.Y = block.Top;
                                     collisionRectangle.Y = block.Top;
                                     flag4 = false;
                                 }
                             }
                         }
                     }
                     if (flag5)
                     {
                         this.xSpeed.CurrentSpeed = 0f;
                     }
                     if (flag6)
                     {
                         this.ySpeed.CurrentSpeed = 0f;
                     }
                     if (flag3)
                     {
                         this.newLocation.X += num3;
                     }
                     if (flag4)
                     {
                         this.newLocation.Y += num4;
                     }
                     if (flag3)
                     {
                         collisionRectangle.X += num3;
                     }
                     if (flag4)
                     {
                         collisionRectangle.Y += num4;
                     }
                 }
             }
         }
     }
     this.onGround = flag2;
 }
コード例 #11
0
        /// <returns>Returns the loci which describes the intersection. WARNING: Where points are concerned it is assumed the point does intersect so the point simply gets returned. This is to prevent multiple calls to DoesLocusIntersect.</returns>
        public Loci GetLocusIntersection(Loci pobjTarget)
        {
            switch (this.Type)
            {
                case LociType.Line:
                    switch (pobjTarget.Type)
                    {
                        case LociType.Line:
                            PointF objReturn = PointF.Empty;
                            IntersectionHelpers.DoLinesIntersect(this.Line, pobjTarget.Line, ref objReturn);
                            return new Loci(objReturn);
                        case LociType.Point:
                            // Need to change this to return New Loci() if not intersecting.
                            return new Loci(pobjTarget.Point);
                        case LociType.Rectangle:
                            Line objReturn2 = null;
                            if (IntersectionHelpers.DoesLineIntersectRectangle(pobjTarget.Rectangle, this.Line, ref objReturn2))
                            {
                                return new Loci(objReturn2);
                            }
                            else
                            {
                                return new Loci();
                            }
                    }
                    break;
                case LociType.Point:
                    switch (pobjTarget.Type)
                    {
                        case LociType.Line:
                            return new Loci(this.Point);
                        case LociType.Point:
                            return new Loci(this.Point);
                        case LociType.Rectangle:
                            return new Loci(this.Point);
                    }
                    break;
                case LociType.Rectangle:
                    switch (pobjTarget.Type)
                    {
                        case LociType.Line:
                            Line objReturn = null;
                            if (IntersectionHelpers.DoesLineIntersectRectangle(this.Rectangle, pobjTarget.Line, ref objReturn))
                            {
                                return new Loci(objReturn);
                            }
                            else
                            {
                                return new Loci();
                            }
                        case LociType.Point:
                            return new Loci(pobjTarget.Point);
                        case LociType.Rectangle:
                            RectangleF objRectangle = new RectangleF(pobjTarget.Rectangle.Location, pobjTarget.Rectangle.Size);
                            objRectangle.Intersect(this.Rectangle);
                            return new Loci(objRectangle);
                    }
                    break;
            }

            throw new NotSupportedException();
        }
コード例 #12
0
ファイル: TestRectangleF.cs プロジェクト: nlhepler/mono
		public void EdgeIntersection ()
		{
			// https://bugzilla.novell.com/show_bug.cgi?id=431587
			RectangleF one = new RectangleF(10, 10, 10, 10);
			RectangleF two = new RectangleF(20, 10, 10, 10);

			one.Intersect(two);
			Assert.IsTrue (one.IsEmpty, "Empty");
			Assert.AreEqual (20f, one.X, "X");
			Assert.AreEqual (10f, one.Y, "Y");
			Assert.AreEqual (0f, one.Width, "Width");
			Assert.AreEqual (10f, one.Height, "Height");
		}
コード例 #13
0
ファイル: ContainerBase.cs プロジェクト: wsrf2009/KnxUiEditor
        /// <summary>
        /// Utility function. Calculates the remaining empty area of a specified area and a given content.
        /// </summary>
        /// <returns></returns>
        public static RectangleF CalculateRemainingArea(RectangleF parentArea, AnchorArea contentAnchor, RectangleF contentArea)
        {
            if (contentAnchor != null)
            {
                float left, top, height, width;

                if (contentAnchor.HasTop && !contentAnchor.HasBottom)
                {
                    top = contentArea.Bottom;
                    height = parentArea.Height - contentArea.Height;
                }
                else if (contentAnchor.HasBottom && !contentAnchor.HasTop)
                {
                    top = parentArea.Top;
                    height = parentArea.Height - contentArea.Height;
                }
                else
                {
                    top = parentArea.Top;
                    height = parentArea.Height;
                }

                if (contentAnchor.HasLeft && !contentAnchor.HasRight)
                {
                    left = contentArea.Right;
                    width = parentArea.Width - contentArea.Width;
                }
                else if (contentAnchor.HasRight && !contentAnchor.HasLeft)
                {
                    left = parentArea.Left;
                    width = parentArea.Width - contentArea.Width;
                }
                else
                {
                    left = parentArea.Left;
                    width = parentArea.Width;
                }

                RectangleF newArea = new RectangleF(left, top, width, height);
                newArea.Intersect(parentArea);

                return newArea;
            }
            else
                return parentArea;
        }
コード例 #14
0
ファイル: AnchorArea.cs プロジェクト: wsrf2009/KnxUiEditor
        /// <summary>
        /// Calculate the destination area of 
        /// </summary>
        /// <param name="area"></param>
        /// <param name="content"></param>
        /// <param name="anchor"></param>
        /// <returns></returns>
        public static RectangleF CalculateArea(RectangleF area, SizeF content, AnchorArea anchor)
        {
            if (anchor.IsEmpty)
                return area;
            else
            {
                RectangleF destination = new RectangleF();

                //Left and width
                if (anchor.Center)
                {
                    //TODO Try in the future to use also Left and Right property when align the content.
                    destination.X = (area.X + area.Width / 2.0F) - content.Width / 2.0F;
                    destination.Width = content.Width;
                }
                else if (anchor.HasLeft && anchor.HasRight)
                {
                    destination.X = area.Left + anchor.Left;
                    destination.Width = area.Width - (anchor.Left + anchor.Right);
                }
                else if (anchor.HasLeft)
                {
                    destination.X = area.Left + anchor.Left;
                    destination.Width = content.Width;
                }
                else if (anchor.HasRight)
                {
                    destination.X = (area.Right - content.Width) - anchor.Right;
                    destination.Width = content.Width;
                }
                else
                {
                    destination.X = area.Left;
                    destination.Width = content.Width;
                }

                //Top and height
                if (anchor.Middle)
                {
                    //TODO Try in the future to use also Left and Right property when align the content.
                    destination.Y = (area.Y + area.Height / 2.0F) - content.Height / 2.0F;
                    destination.Height = content.Height;
                }
                else if (anchor.HasTop && anchor.HasBottom)
                {
                    destination.Y = area.Top + anchor.Top;
                    destination.Height = area.Height - (anchor.Top + anchor.Bottom);
                }
                else if (anchor.HasTop)
                {
                    destination.Y = area.Top + anchor.Top;
                    destination.Height = content.Height;
                }
                else if (anchor.HasBottom)
                {
                    destination.Y = (area.Bottom - content.Height) - anchor.Bottom;
                    destination.Height = content.Height;
                }
                else
                {
                    destination.Y = area.Top;
                    destination.Height = content.Height;
                }

                destination.Intersect(area);
                return destination;
            }
        }
コード例 #15
0
 /// <summary>
 /// Draws a single <see cref="LineNumberItem"/>.
 /// </summary>
 /// <param name="item"></param>
 /// <param name="graphics">The <see cref="Graphics"/> to draw on.</param>
 /// <param name="brush"></param>
 /// <param name="textFormat"></param>
 /// <param name="path">The <see cref="GraphicsPath"/> to update with the drawn data.</param>
 private void DrawLineNumber(LineNumberItem item, Graphics graphics, Brush brush, StringFormat textFormat, GraphicsPath path)
 {
   var text = _lineNumbersShowAsHexadecimal
                ? item.LineNumber.ToString("X")
                : _lineNumbersShowLeadingZeroes
                    ? item.LineNumber.ToString(_lineNumbersFormat)
                    : item.LineNumber.ToString();
   var textSize = graphics.MeasureString(text, Font, new Point(0, 0), textFormat);
   var point = GetLineNumberDrawingStartPoint(item, textSize);
   // TextClipping
   var itemClipRectangle = new RectangleF(point, textSize.ToSize());
   if (_lineNumbersClipByItemRectangle)
   {
     // If selected, the text will be clipped so that it doesn't spill out of its own LineNumberItem-area.
     // Only the part of the text inside the LineNumberItem.Rectangle should be visible, so intersect with the ItemRectangle
     // The SetClip method temporary restricts the drawing area of the control for whatever is drawn next.
     itemClipRectangle.Intersect(item.Rectangle);
     graphics.SetClip(itemClipRectangle);
   }
   // TextDrawing
   graphics.DrawString(text, Font, brush, point, textFormat);
   graphics.ResetClip();
   // The GraphicsPath for the LineNumber is just a rectangle behind the text, to keep the paintingspeed high and avoid ugly artifacts.
   path.AddRectangle(itemClipRectangle);
   path.CloseFigure();
 }
コード例 #16
0
ファイル: mxUtils.cs プロジェクト: jaropolk2/mxgraph
        /// <summary>
        /// 
        /// </summary>
        /// <param name="g"></param>
        /// <param name="brush"></param>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="width"></param>
        /// <param name="height"></param>
        public static void FillClippedRect(Graphics g, Brush brush, int x, int y, int width, int height)
        {
            RectangleF bg = new RectangleF(x, y, width, height);

            if (g.ClipBounds != null)
            {
                bg.Intersect(g.ClipBounds);
            }

            g.FillRectangle(brush, bg.X, bg.Y, bg.Width, bg.Height);
        }
コード例 #17
0
ファイル: ResultsPanel.cs プロジェクト: cmrazek/ProbeNpp
        private void DrawContextSubItem(DrawListViewSubItemEventArgs e)
        {
            var match = e.Item.Tag as FindMatch;
            if (match == null) DrawSubItem(e);

            if (e.Item.Selected)
            {
                e.Graphics.FillRectangle(SystemBrushes.Highlight, e.Bounds);
            }
            else
            {
                e.Graphics.FillRectangle(SystemBrushes.Window, e.Bounds);
            }

            var lineText = match.LineText.Replace('\t', ' ');
            var spans = match.HighlightSpans;
            var pos = 0;
            var length = lineText.Length;
            var bounds = new RectangleF(e.Bounds.Left, e.Bounds.Top, e.Bounds.Width, e.Bounds.Height);
            var normalBrush = e.Item.Selected ? SystemBrushes.HighlightText : SystemBrushes.WindowText;
            var highlightBrush = Brushes.Yellow;
            var highlightTextBrush = SystemBrushes.WindowText;

            using (var sf = new StringFormat())
            {
                sf.FormatFlags = StringFormatFlags.NoWrap | StringFormatFlags.MeasureTrailingSpaces;
                sf.LineAlignment = StringAlignment.Center;

                while (pos < length && !bounds.IsEmpty)
                {
                    var nextSpan = (from s in spans where s.Start >= pos select s).FirstOrDefault();
                    if (nextSpan == null)
                    {
                        // No more highlight text to draw
                        e.Graphics.DrawString(lineText.Substring(pos), _contextFont, normalBrush, bounds, sf);
                        pos = length;
                    }
                    else
                    {
                        // Draw normal text before the highlight range
                        var drawNormal = false;
                        string normalText = "";
                        RectangleF normalBounds = new RectangleF();

                        if (nextSpan.Start > pos)
                        {
                            drawNormal = true;
                            normalText = lineText.Substring(pos, nextSpan.Start - pos);
                            normalBounds = bounds;

                            var normalSize = Util.MeasureString(e.Graphics, normalText, _contextFont, e.Bounds, sf);
                            bounds = new RectangleF(bounds.Left + normalSize.Width, bounds.Top, bounds.Width - normalSize.Width, bounds.Height);
                        }

                        // Draw highlight range
                        var text = lineText.Substring(nextSpan.Start, nextSpan.Length);

                        var highlightSize = e.Graphics.MeasureString(text, _contextFont, bounds.Location, sf);	// MeasureString() includes surrounding margins
                        var highlightRect = new RectangleF(bounds.Left, bounds.Top + (bounds.Height - highlightSize.Height) / 2, highlightSize.Width, highlightSize.Height);
                        highlightRect.Intersect(e.Bounds);
                        if (!highlightRect.IsEmpty) e.Graphics.FillRectangle(highlightBrush, highlightRect);

                        if (drawNormal)
                        {
                            e.Graphics.DrawString(normalText, _contextFont, normalBrush, normalBounds, sf);
                        }

                        e.Graphics.DrawString(text, _contextFont, highlightTextBrush, bounds, sf);
                        var size = Util.MeasureString(e.Graphics, text, _contextFont, e.Bounds, sf);
                        bounds = new RectangleF(bounds.Left + size.Width, bounds.Top, bounds.Width - size.Width, bounds.Height);

                        pos = nextSpan.Start + nextSpan.Length;
                    }
                }
            }
        }
コード例 #18
0
ファイル: RectangleF.cs プロジェクト: Tsalex71/mono-1
        /// <summary>
        ///	Intersect Method
        /// </summary>
        ///
        /// <remarks>
        ///	Replaces the RectangleF with the intersection of itself
        ///	and another RectangleF.
        /// </remarks>

        public void Intersect(RectangleF rect)
        {
            this = RectangleF.Intersect(this, rect);
        }
コード例 #19
0
ファイル: BoxObj.cs プロジェクト: sntree/ZedGraph
        /// <summary>
        /// Render this object to the specified <see cref="Graphics"/> device.
        /// </summary>
        /// <remarks>
        /// This method is normally only called by the Draw method
        /// of the parent <see cref="GraphObjList"/> collection object.
        /// </remarks>
        /// <param name="g">
        /// A graphic device object to be drawn into.  This is normally e.Graphics from the
        /// PaintEventArgs argument to the Paint() method.
        /// </param>
        /// <param name="pane">
        /// A reference to the <see cref="PaneBase"/> object that is the parent or
        /// owner of this object.
        /// </param>
        /// <param name="scaleFactor">
        /// The scaling factor to be used for rendering objects.  This is calculated and
        /// passed down by the parent <see cref="GraphPane"/> object using the
        /// <see cref="PaneBase.CalcScaleFactor"/> method, and is used to proportionally adjust
        /// font sizes, etc. according to the actual size of the graph.
        /// </param>
        public override void Draw(Graphics g, PaneBase pane, float scaleFactor)
        {
            // Convert the arrow coordinates from the user coordinate system
            // to the screen coordinate system
            PointF pix1 = this.Location.TransformTopLeft(pane);
            PointF pix2 = this.Location.TransformBottomRight(pane);

            //RectangleF pixRect = this.Location.TransformRect(pane);
            RectangleF pixRect = new RectangleF(Math.Min(pix1.X, pix2.X), Math.Min(pix1.Y, pix2.Y),
                            Math.Abs(pix2.X - pix1.X), Math.Abs(pix2.Y - pix1.Y));

            //System.Diagnostics.Debug.WriteLine(string.Format("box {0} {1}", pix1, pix2));

            // Clip the rect to just outside the PaneRect so we don't end up with wild coordinates.
            RectangleF tmpRect = pane.Rect;
            tmpRect.Inflate(20, 20);
            pixRect.Intersect(tmpRect);

            if (Math.Abs(pixRect.Left) < 100000 &&
                Math.Abs(pixRect.Top) < 100000 &&
                Math.Abs(pixRect.Right) < 100000 &&
                Math.Abs(pixRect.Bottom) < 100000)
            {
                // If the box is to be filled, fill it
                _fill.Draw(g, pixRect);

                // Draw the border around the box if required
                //_border.Draw( g, pane, scaleFactor, pixRect );

                if (_border.IsVisible)
                {
                    var smode = g.SmoothingMode;
                    g.SmoothingMode = SmoothingMode.AntiAlias;

                    RectangleF tRect = pixRect;

                    float scaledInflate = (float)(_border.InflateFactor * scaleFactor);
                    tRect.Inflate(scaledInflate, scaledInflate);

                    using (Pen pen = _border.GetPen(pane, scaleFactor))
                    {
                        if (IsMoving)
                        {
                            // Set the DashCap to round.
                            pen.DashCap = DashCap.Round;

                            // Create a custom dash pattern.
                            pen.DashPattern = new float[] { 4.0F, 4.0F };
                        }

                        g.DrawRectangle(pen, tRect.X, tRect.Y, tRect.Width, tRect.Height);

                        if (IsSelected)
                        {
                            Brush brush = new SolidBrush(Color.White);

                            g.FillRectangles(brush, EdgeRects(pane));

                            pen.DashStyle = DashStyle.Solid;

                            g.DrawRectangles(pen, EdgeRects(pane));
                        }
                    }

                    g.SmoothingMode = smode;
                }
            }
        }
コード例 #20
0
ファイル: DayPanel.cs プロジェクト: kjburns31/vixen-modules
        private void _DrawLines(Graphics g)
        {
            RectangleF rect = new RectangleF(TimeGutter, 0, Width - TimeGutter, Height);
            rect.Intersect(g.VisibleClipBounds);
            g.FillRectangle(_backgroundBrush, rect);

            int startHalfHour = _GetHalfHourAt((int)g.VisibleClipBounds.Y);
            int hour = startHalfHour / 2;

            // Hour lines
            int y = hour * HalfHourHeight * 2;

            for(; y < g.VisibleClipBounds.Bottom && hour <= 24; y += HalfHourHeight * 2) {
                g.DrawLine(_hourPen, TimeGutter, y, Width, y);
                hour++;
            }

            // Half-hour lines
            hour = startHalfHour / 2;
            y = startHalfHour * HalfHourHeight;
            if(startHalfHour % 2 == 0) y += HalfHourHeight;

            for(; y < g.VisibleClipBounds.Bottom && hour < 24; y += HalfHourHeight * 2) {
                g.DrawLine(_halfHourPen, TimeGutter, y, Width, y);
                hour++;
            }
        }
コード例 #21
0
ファイル: FwGraphics.cs プロジェクト: sillsdev/WorldPad
		/// -----------------------------------------------------------------------------------
		/// <summary>Member FwDrawRectangle</summary>
		/// <param name='xLeft'>xLeft</param>
		/// <param name='yTop'>yTop</param>
		/// <param name='xRight'>xRight</param>
		/// <param name='yBottom'>yBottom</param>
		/// -----------------------------------------------------------------------------------
		public void FwDrawRectangle(int xLeft, int yTop, int xRight, int yBottom)
		{
			Debug.Assert(m_bitmapGraphics != null);
			RectangleF rect =
				new RectangleF(xLeft, yTop, xRight - xLeft, yBottom - yTop);

			///*
			// check whether the rectangle is visible
			if (!rect.IntersectsWith(m_bitmapGraphics.ClipBounds))
				return;

			rect.Intersect(m_bitmapGraphics.ClipBounds);
			//*/

			m_bitmapGraphics.FillRectangle(new SolidBrush(m_backColor), rect);
		}