public static Equals ( RectangleF, &r1, RectangleF, &r2 ) : bool | ||
r1 | RectangleF, | |
r2 | RectangleF, | |
Résultat | bool |
public void RectangleF_EqualsObject() { var rectangle1 = new RectangleF(123.45f, 456.78f, 789.99f, 999.99f); var rectangle2 = new RectangleF(123.45f, 456.78f, 789.99f, 999.99f); TheResultingValue(rectangle1.Equals((Object)rectangle2)).ShouldBe(true); TheResultingValue(rectangle1.Equals("This is a test")).ShouldBe(false); }
public void RectangleF_EqualsRectangleF() { var rectangle1 = new RectangleF(123.45f, 456.78f, 789.99f, 999.99f); var rectangle2 = new RectangleF(123.45f, 456.78f, 789.99f, 999.99f); var rectangle3 = new RectangleF(222f, 456.78f, 789.99f, 999.99f); var rectangle4 = new RectangleF(123.45f, 333f, 789.99f, 999.99f); var rectangle5 = new RectangleF(123.45f, 456.78f, 444f, 999.99f); var rectangle6 = new RectangleF(123.45f, 456.78f, 789.99f, 555f); TheResultingValue(rectangle1.Equals(rectangle2)).ShouldBe(true); TheResultingValue(rectangle1.Equals(rectangle3)).ShouldBe(false); TheResultingValue(rectangle1.Equals(rectangle4)).ShouldBe(false); TheResultingValue(rectangle1.Equals(rectangle5)).ShouldBe(false); TheResultingValue(rectangle1.Equals(rectangle6)).ShouldBe(false); }
public override bool Equals(RadialGradientShadingColor other) { if (ReferenceEquals(other, null)) { return(false); } return(_placementRect.Equals(other._placementRect) && _circle0 == other._circle0 && _circle1 == other._circle1); }
protected override bool ValidateFullBounds() { comparisonBounds = UnionOfChildrenBounds; if (!cachedChildBounds.Equals(comparisonBounds)) { PaintInvalid = true; } return(base.ValidateFullBounds()); }
public bool Equals(MaskingInfo other) { return (ScreenSpaceAABB.Equals(other.ScreenSpaceAABB) && MaskingRect.Equals(other.MaskingRect) && ToMaskingSpace.Equals(other.ToMaskingSpace) && CornerRadius == other.CornerRadius && BorderThickness == other.BorderThickness && BorderColour.Equals(other.BorderColour) && BlendRange == other.BlendRange); }
/// <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 }); }
public override bool Equals(object obj) { return((obj is PathGradientBrush b) && pathPoints.Equals(b.pathPoints) && wrapMode.Equals(b.wrapMode) && gradientTransform.Equals(b.gradientTransform) && centerColor.Equals(b.centerColor) && focusScales.Equals(b.focusScales) && surroundColors.Equals(b.surroundColors) && colorBlend.Equals(b.colorBlend) && rectangle.Equals(b.rectangle) && centerPoint.Equals(b.centerPoint) && polygonWinding.Equals(b.polygonWinding) && blend.Equals(b.blend)); }
/// <summary>Unions the rectangles, but allows starting with an empty rectangle. Updates the given rectangle.</summary> internal static void Extend(ref RectangleF update, RectangleF add) { // the main motivation for this is that RectangleF.Union cannot union an empty rectangle with something else (it will include 0, 0) // whereas we would like to start with an empty rectangle and then add an arbitrary number of other rectangles to it // this function is also different in that we update the first parameter rather than returning a new rectangle; // just because this is the way that suits this code best if (update.Equals(RectangleF.Empty)) // not the same as IsEmpty ! { update = add; } else if (!add.Equals(RectangleF.Empty)) { update = RectangleF.Union(update, add); } }
public override bool Equals(object obj) { return((obj is LinearGradientBrush b) && wrapMode.Equals(b.wrapMode) && gammaCorrection.Equals(b.gammaCorrection) && gradientTransform.Equals(b.gradientTransform) && startPoint.Equals(b.startPoint) && endPoint.Equals(b.endPoint) && colors.Equals(b.colors) && blend.Equals(b.blend) && colorBlend.Equals(b.colorBlend) && blend.Equals(b.blend) && rectangle.Equals(b.rectangle) && angle.Equals(b.angle) && angleIsScalable == b.angleIsScalable); }
public static int Main() { int iRetVal = 100; var r = new RectangleF(1.2f, 3.4f, 5.6f, 7.8f); typeof(Test7685).GetTypeInfo().GetDeclaredMethod("DoStuff").Invoke(null, new object[] { r }); if (!RectangleF.Equals(ref argumentInDStuff, ref r)) { TestLibrary.Logging.WriteLine($"Error: passing struct with floats via reflection. Callee received {argumentInDStuff} instead of {r}"); iRetVal = 0; } return(iRetVal); }
/// <summary> /// Return the upper-left corner /// </summary> /// <returns>The boxes.</returns> /// <param name="rContent">R content.</param> /// <param name="rBoundingBox">R bounding box.</param> /// <param name="SF">S.</param> /// <param name="Ascender">Ascender.</param> /// <param name="Descender">Descender.</param> public static Point AlignBoxes(RectangleF rContent, RectangleF rBoundingBox, FontFormat SF, float Ascender, float Descender) { if (rContent.Equals(Rectangle.Empty) || rBoundingBox.Equals(Rectangle.Empty)) { return(Point.Empty); } float x = 0; float y = 0; switch (SF.HAlign) { case Alignment.Near: //x = 0; break; case Alignment.Center: x = Math.Max(0, (rBoundingBox.Width - rContent.Width) / 2f); break; case Alignment.Far: x = rBoundingBox.Width - rContent.Width; break; } switch (SF.VAlign) { case Alignment.Near: //y = 0; break; case Alignment.Center: y = Math.Max(0, (rBoundingBox.Height - rContent.Height) / 2); break; case Alignment.Baseline: y = Math.Max(0, (rBoundingBox.Height - (rContent.Height + Descender)) / 2); break; case Alignment.Far: y = rBoundingBox.Height - rContent.Height; break; } //return new Point ((int)(x + 0.5f), (int)(y + 0.5f)); return(new Point(x.Ceil(), y.Ceil())); }
/// <summary> /// Cuts the destination rectangle using top of the scissor stack. /// Source rectangle is modified using scaled change of destination /// as well. /// </summary> public void Cut(ref RectangleF destination, ref RectangleF source) { if (Empty) return; var originalDestination = destination; Rectangle top = m_rectangleStack.Peek(); var topF = new RectangleF(top.X, top.Y, top.Width, top.Height); RectangleF.Intersect(ref destination, ref topF, out destination); if (destination.Equals(originalDestination)) return; var scale = source.Size / originalDestination.Size; var sizeChange = destination.Size - originalDestination.Size; var positionChange = destination.Position - originalDestination.Position; var originalSource = source; source.Position += positionChange * scale; source.Size += sizeChange * scale; }
public static UIImage ImageFromColor(UIColor color, RectangleF rect = default(RectangleF)) { if (rect.Equals(default(RectangleF))) { rect = new RectangleF(0, 0, 1, 1); } UIGraphics.BeginImageContext(rect.Size); var ctx = UIGraphics.GetCurrentContext(); ctx.SetFillColor(color.CGColor); ctx.FillRect(rect); var img = UIGraphics.GetImageFromCurrentImageContext(); UIGraphics.EndImageContext(); return(img); }
public void DrawProc(GameplayGameState pState, IStateOwner pOwner, Graphics g, RectangleF Bounds) { if (useBackground == null || !StoredBackground.Equals(Bounds) || pState.DoRefreshBackground) { RefreshBackground(pState, Bounds); } g.DrawImage(useBackground, Bounds); var PlayField = pState.PlayField; if (PlayField != null) { PlayField.Draw(pOwner, g, Bounds); } foreach (var activeblock in PlayField.BlockGroups) { int dl = 0; var GrabGhost = pState.GetGhostDrop(pOwner, activeblock, out dl, 3); if (GrabGhost != null) { var BlockWidth = PlayField.GetBlockWidth(Bounds); var BlockHeight = PlayField.GetBlockHeight(Bounds); foreach (var iterateblock in activeblock) { RectangleF BlockBounds = new RectangleF(BlockWidth * (GrabGhost.X + iterateblock.X), BlockHeight * (GrabGhost.Y + iterateblock.Y - 2), PlayField.GetBlockWidth(Bounds), PlayField.GetBlockHeight(Bounds)); TetrisBlockDrawGDIPlusParameters tbd = new TetrisBlockDrawGDIPlusParameters(g, BlockBounds, GrabGhost, pOwner.Settings); ImageAttributes Shade = new ImageAttributes(); Shade.SetColorMatrix(ColorMatrices.GetFader(0.5f)); tbd.ApplyAttributes = Shade; //tbd.OverrideBrush = GhostBrush; var GetHandler = RenderingProvider.Static.GetHandler(typeof(Graphics), iterateblock.Block.GetType(), typeof(TetrisBlockDrawGDIPlusParameters)); GetHandler.Render(pOwner, tbd.g, iterateblock.Block, tbd); //iterateblock.Block.DrawBlock(tbd); } } } }
private void pictureBox1_MouseMove(object sender, MouseEventArgs e) { if (OriginalImage != null) { switch (interation) { case InterationType.TILE: { float cellSizeX = 4f * zoomFactor; float cellSizeY = 8f * zoomFactor; float TileCol = (float)Math.Floor((float)e.Location.X / cellSizeX); float TitleRow = (float)Math.Floor((float)e.Location.Y / cellSizeY); RectangleF newTileUnderMouse = new RectangleF(TileCol * cellSizeX, TitleRow * cellSizeY, cellSizeX, cellSizeY); if (!newTileUnderMouse.Equals(tileUnderMouse)) { tileUnderMouse = newTileUnderMouse; pictureBox1.Invalidate(); //refreshes the picturebox } }; break; } } }
private string PrepareMemoryImage(MemoryImage img, int imageKey, RectangleF source) { if (!img.IsSVG) { return(PrepareImage((Bitmap)img.GetNetImage(true), imageKey, source)); } // rest for SVG only, which partially repeats PrepareImage (above) string ID = "img" + imageKey.ToString("x"); RectangleF bounds = new RectangleF(PointF.Empty, img.Size); if (!source.IsEmpty && !source.Equals(bounds)) { ID += "_" + source.GetHashCode(); } if (!m_Images.Contains(ID)) { // for SVG images can just retrieve the data directly from the memory image (no need to worry about formats) Debug.Assert(img.Buffer != null); AddImageToDefinitions(img.Buffer, ID, img.Size, "svg+xml"); } return(ID); }
/// <summary>extends the rectangle to include this point (like RectangleF.Union, but using a PointF as the second parameter) /// modifies the rectangle it is applied to</summary> internal static void Extend(ref RectangleF rct, PointF pt) { if (rct.Equals(RectangleF.Empty)) // checking IsEmpty is not sufficient, because this returned rectangle is actually empty { if (pt.IsEmpty) // must give this some nominal size, because if we return rectangle (0, 0, 0, 0) it will be ignored next time this function is called // and treated as the empty rectangle { rct = new RectangleF(pt, new SizeF(NEGLIGIBLE, NEGLIGIBLE)); } else { rct = new RectangleF(pt, new SizeF(0, 0)); } return; } float difference; if (pt.X < rct.X) { difference = rct.X - pt.X; rct.Width += difference; rct.X -= difference; } else if (pt.X >= rct.Right) { rct.Width += pt.X - rct.Right; } if (pt.Y < rct.Y) { difference = rct.Y - pt.Y; rct.Height += difference; rct.Y -= difference; } else if (pt.Y >= rct.Bottom) { rct.Height += pt.Y - rct.Bottom; } }
/// <summary> /// Cuts the destination rectangle using top of the scissor stack. /// Source rectangle is modified using scaled change of destination /// as well. /// </summary> public void Cut(ref RectangleF destination, ref RectangleF source) { if (Empty) { return; } var originalDestination = destination; Rectangle top = m_rectangleStack.Peek(); var topF = new RectangleF(top.X, top.Y, top.Width, top.Height); RectangleF.Intersect(ref destination, ref topF, out destination); if (destination.Equals(originalDestination)) { return; } var scale = source.Size / originalDestination.Size; var sizeChange = destination.Size - originalDestination.Size; var positionChange = destination.Position - originalDestination.Position; var originalSource = source; source.Position += positionChange * scale; source.Size += sizeChange * scale; }
public void TestEqualsWithNullReference() { RectangleF testRectangle = new RectangleF(1.2f, 3.4f, 5.6f, 7.8f); Assert.IsFalse(testRectangle.Equals(null)); }
public void TestEqualsWithDifferentType() { RectangleF testRectangle = new RectangleF(1.2f, 3.4f, 5.6f, 7.8f); Assert.IsFalse(testRectangle.Equals(DateTime.MinValue)); }
public void TestEqualsWithDowncast() { RectangleF testRectangle = new RectangleF(1.2f, 3.4f, 5.6f, 7.8f); RectangleF equivalentRectangle = new RectangleF(1.2f, 3.4f, 5.6f, 7.8f); RectangleF differingRectangle = new RectangleF(3.0f, 6.0f, 3.7f, 5.2f); Assert.IsTrue(testRectangle.Equals((object)equivalentRectangle)); Assert.IsFalse(testRectangle.Equals((object)differingRectangle)); }
public static Bitmap ApplyDropShadowOutside(Bitmap bitmap, RectangleF?crop, Brush backgroundBrush, Color shadowColor, int shadowRatio, int offset, int borderTop, int borderRight, int borderBottom, int borderLeft) { RectangleF defaultCrop = new RectangleF(0, 0, bitmap.Width, bitmap.Height); RectangleF actualCrop = crop ?? defaultCrop; shadowRatio = Math.Max(shadowRatio, 1); // TODO: don't short circuit if a crop needs to be applied // Shadow ratio cannot be zero if (((offset | borderTop | borderRight | borderBottom | borderLeft) == 0 && actualCrop.Equals(defaultCrop))) { return(new Bitmap(bitmap)); } //Draw a drop shadow based on Bob Powell's text drop shadow technique, this lets GDI give us //"alpha blended shadows with delicious umbra and penumbra shadows". Thanks for the tip Bob! //http://www.bobpowell.net/dropshadowtext.htm //some constants that can be used to tweak the shadow //const int shadowRatio = 4; //increasing this value will lighten the color of the shadow const int shadowMargin = 1; //the amount of background color to include on the shadow's edges //Make a bitmap that is used to hold the shadow rectangle. To give the rectangle soft //edges, we draw it at reduced size, and then scale it up to large size so that GDI will //blend the shadow colors together to create softened edges. Bitmap shadowImage = new Bitmap(Math.Max(1, Convert.ToInt32(actualCrop.Width / shadowRatio)), Math.Max(1, Convert.ToInt32(actualCrop.Height / shadowRatio))); using (shadowImage) { // //Get a graphics object for it Graphics g = Graphics.FromImage(shadowImage); //Create the shadow rectangle. Note: the outer edge of the rectangle is the color of the background so that the background color //will be blended into the shadow rectangle when the image is enlarged onto the real bitmap. g.FillRectangle(backgroundBrush, new Rectangle(0, 0, shadowImage.Width, shadowImage.Height)); g.FillRectangle(new SolidBrush(Color.FromArgb(200, shadowColor)), new Rectangle(shadowMargin, shadowMargin, shadowImage.Width - shadowMargin, shadowImage.Height - shadowMargin)); g.Dispose(); //set the border color Color borderColor = Color.White; //create a version of the original bitmap that is reduced enough to make room for the dropshadow. Bitmap enlargedBitmap = new Bitmap( Convert.ToInt32(actualCrop.Width) + offset + borderLeft + borderRight, Convert.ToInt32(actualCrop.Height) + offset + borderTop + borderBottom); //Create a graphics object to draw on the original bitmap g = Graphics.FromImage(enlargedBitmap); using (g) { g.InterpolationMode = InterpolationMode.HighQualityBicubic; //draw the small shadow image onto the large bitmap image (adjusting for the offset) g.FillRectangle(backgroundBrush, new Rectangle(0, 0, enlargedBitmap.Width, enlargedBitmap.Height)); int shadowOffset = offset - shadowMargin * shadowRatio; g.DrawImage(shadowImage, new Rectangle(shadowOffset, shadowOffset, enlargedBitmap.Width - shadowOffset, enlargedBitmap.Height - shadowOffset), 0, 0, shadowImage.Width, shadowImage.Height, GraphicsUnit.Pixel); if (borderTop > 0 || borderRight > 0 || borderBottom > 0 || borderLeft > 0) { g.FillRectangle(new SolidBrush(borderColor), new Rectangle(0, 0, enlargedBitmap.Width - offset, enlargedBitmap.Height - offset)); g.DrawRectangle(new Pen(Color.FromArgb(50, shadowColor), 1), new Rectangle(0, 0, enlargedBitmap.Width - offset, enlargedBitmap.Height - offset)); } Rectangle destRect = new Rectangle(borderLeft, borderTop, Convert.ToInt32(actualCrop.Width), Convert.ToInt32(actualCrop.Height)); //draw the image on top of the bordered image if (!actualCrop.Equals(defaultCrop)) { g.DrawImage(bitmap, destRect, actualCrop.Left, actualCrop.Top, actualCrop.Width, actualCrop.Height, GraphicsUnit.Pixel); } else { g.DrawImage(bitmap, destRect.Left, destRect.Top, destRect.Width, destRect.Height); } } return(enlargedBitmap); } }
public bool Equals(AnimationFrame p) { return(_color.Equals(p._color) && _dimension.Equals(p._dimension) && _width.Equals(p._width)); }
public void EqualsTest1() { RectangleF target = new RectangleF(101f, 105f, 65f, 35f); object compareTrue = new RectangleF(101f, 105f, 65f, 35f); object compareFalse = new RectangleF(10f, 5f, 101f, 1000f); Assert.IsTrue(target.Equals(compareTrue)); Assert.IsFalse(target.Equals(compareFalse)); }
private static bool IsIntersectWithAnyAnotherRectangle(RectangleF rectangle, IEnumerable <RectangleF> rectangles) { return(rectangles.Where(rect => !rectangle.Equals(rect)) .Any(r => r.IntersectsWith(rectangle))); }
public override void RenderStats(IStateOwner pOwner, Graphics pRenderTarget, GameplayGameState Source, BaseDrawParameters Element) { var Bounds = Element.Bounds; var g = pRenderTarget; bool RedrawsNeeded = !LastDrawStat.Equals(Bounds); LastDrawStat = Bounds; if (StatisticsBackground == null || RedrawsNeeded || GeneratedImageTheme != Source.PlayField.Theme) { GenerateStatisticsBackground(Source); } g.DrawImage(StatisticsBackground, Bounds); //g.Clear(Color.Black); if (!Source.HasTetrominoImages() || RedrawsNeeded) { RedrawStatusbarTetrominoBitmaps(pOwner, Source, Bounds); } lock (Source.LockTetImageRedraw) { var useStats = Source.GameStats; double Factor = Bounds.Height / 644d; int DesiredFontPixelHeight = (int)(Bounds.Height * (23d / 644d)); using (Font standardFont = new Font(TetrisGame.RetroFont, DesiredFontPixelHeight, FontStyle.Bold, GraphicsUnit.Pixel)) { var LocalScores = Source.GetLocalScores(); var TopScore = LocalScores == null ? 0 : LocalScores.GetScores().First().Score; int MaxScoreLength = Math.Max(TopScore.ToString().Length, useStats.Score.ToString().Length); String CurrentScoreStr = useStats.Score.ToString().PadLeft(MaxScoreLength + 2); String TopScoreStr = TopScore.ToString().PadLeft(MaxScoreLength + 2); //TODO: redo this segment separately, so we can have the labels left-aligned and the values right-aligned. // String BuildStatString = "Time: " + FormatGameTime(pOwner).ToString().PadLeft(MaxScoreLength + 2) + "\n" + // "Score: " + CurrentScoreStr + "\n" + // "Top: " + TopScoreStr + " \n" + // "Lines: " + GameStats.LineCount.ToString().PadLeft(MaxScoreLength+2); g.FillRectangle(LightenBrush, 0, 5, Bounds.Width, (int)(450 * Factor)); String[] StatLabels = new string[] { "Time:", "Score:", "Top:", "Lines:" }; int LineCount = Source.GameStats is TetrisStatistics ? (Source.GameStats as TetrisStatistics).LineCount : 0; String[] StatValues = new string[] { FormatGameTime(pOwner), useStats.Score.ToString(), TopScore.ToString(), LineCount.ToString() }; Point StatPosition = new Point((int)(7 * Factor), (int)(7 * Factor)); int CurrentYPosition = StatPosition.Y; for (int statindex = 0; statindex < StatLabels.Length; statindex++) { var MeasureLabel = g.MeasureString(StatLabels[statindex], standardFont); var MeasureValue = g.MeasureString(StatValues[statindex], standardFont); float LargerHeight = Math.Max(MeasureLabel.Height, MeasureValue.Height); //we want to draw the current stat label at position StatPosition.X,CurrentYPosition... TetrisGame.DrawText(g, standardFont, StatLabels[statindex], Brushes.Black, Brushes.White, StatPosition.X, CurrentYPosition); //we want to draw the current stat value at Bounds.Width-ValueWidth. TetrisGame.DrawText(g, standardFont, StatValues[statindex], Brushes.Black, Brushes.White, (float)(Bounds.Width - MeasureValue.Width - (5 * Factor)), CurrentYPosition); //add the larger of the two heights to the current Y Position. CurrentYPosition += (int)LargerHeight; CurrentYPosition += 2; } Type[] useTypes = new Type[] { typeof(Tetromino_I), typeof(Tetromino_O), typeof(Tetromino_J), typeof(Tetromino_T), typeof(Tetromino_L), typeof(Tetromino_S), typeof(Tetromino_Z) }; int[] PieceCounts = null; if (useStats is TetrisStatistics ts) { PieceCounts = new int[] { ts.I_Piece_Count, ts.O_Piece_Count, ts.J_Piece_Count, ts.T_Piece_Count, ts.L_Piece_Count, ts.S_Piece_Count, ts.Z_Piece_Count }; } else { PieceCounts = new int[] { 0, 0, 0, 0, 0, 0, 0 }; } int StartYPos = (int)(140 * Factor); int useXPos = (int)(30 * Factor); ImageAttributes ShadowTet = TetrisGame.GetShadowAttributes(); if (Source.GameHandler is StandardTetrisHandler) { for (int i = 0; i < useTypes.Length; i++) { PointF BaseCoordinate = new PointF(useXPos, StartYPos + (int)((float)i * (40d * Factor))); PointF TextPos = new PointF(useXPos + (int)(100d * Factor), BaseCoordinate.Y); String StatText = "" + PieceCounts[i]; SizeF StatTextSize = g.MeasureString(StatText, standardFont); String sNomTypeKey = Source.PlayField.Theme.GetNominoTypeKey(useTypes[i], Source.GameHandler, Source.PlayField); Image TetrominoImage = TetrisGame.Choose(Source.NominoImages[sNomTypeKey]); PointF ImagePos = new PointF(BaseCoordinate.X, BaseCoordinate.Y + (StatTextSize.Height / 2 - TetrominoImage.Height / 2)); g.DrawImage(TetrominoImage, ImagePos); g.DrawString(StatText, standardFont, Brushes.White, new PointF(TextPos.X + 4, TextPos.Y + 4)); g.DrawString(StatText, standardFont, Brushes.Black, TextPos); } } Point NextDrawPosition = new Point((int)(40f * Factor), (int)(420 * Factor)); Size NextSize = new Size((int)(200f * Factor), (int)(200f * Factor)); Point CenterPoint = new Point(NextDrawPosition.X + NextSize.Width / 2, NextDrawPosition.Y + NextSize.Height / 2); //now draw the "Next" Queue. For now we'll just show one "next" item. if (Source.NextBlocks.Count > 0) { var QueueList = Source.NextBlocks.ToArray(); //(from t in QueueList select Source.GetTetrominoSKBitmap(pOwner,t)).ToArray() Image[] NextTetrominoes = (from t in QueueList select Source.GetTetrominoImage(pOwner, t)).ToArray(); // TetrisGame.Choose(Source.NominoImages[Source.PlayField.Theme.GetNominoKey(t,Source.GameHandler,Source.PlayField)])).ToArray(); Image DisplayBox = TetrisGame.Imageman["display_box"]; //draw it at 40,420. (Scaled). float ScaleDiff = 0; iActiveSoundObject PlayingMusic; if ((PlayingMusic = TetrisGame.Soundman.GetPlayingMusic_Active()) != null) { Source.StoredLevels.Enqueue(PlayingMusic.Level); } if (Source.StoredLevels.Count >= 4) { ScaleDiff = Math.Min(30, 10 * Source.StoredLevels.Dequeue()); } if (!TetrisGame.DJMode) { ScaleDiff = 0; } g.DrawImage (DisplayBox, new Rectangle(new Point((int)(NextDrawPosition.X - ScaleDiff), (int)(NextDrawPosition.Y - ScaleDiff)), new Size((int)(NextSize.Width + (ScaleDiff * 2)), (int)(NextSize.Height + (ScaleDiff * 2)))), 0, 0, DisplayBox.Width, DisplayBox.Height, GraphicsUnit.Pixel); g.FillEllipse(Brushes.Black, CenterPoint.X - 5, CenterPoint.Y - 5, 10, 10); for (int i = NextTetrominoes.Length - 1; i > -1; i--) { double StartAngle = Math.PI; double AngleIncrementSize = (Math.PI * 1.8) / (double)NextTetrominoes.Length; //we draw starting at StartAngle, in increments of AngleIncrementSize. //i is the index- we want to increase the angle by that amount (well, obviously, I suppose... double UseAngleCurrent = StartAngle + AngleIncrementSize * (float)i + Source.NextAngleOffset; double UseXPosition = CenterPoint.X + ((float)((NextSize.Width) / 2.2) * Math.Cos(UseAngleCurrent)); double UseYPosition = CenterPoint.Y + ((float)((NextSize.Height) / 2.2) * Math.Sin(UseAngleCurrent)); var NextTetromino = NextTetrominoes[i]; float Deviation = (i - NextTetrominoes.Length / 2); Point Deviate = new Point((int)(Deviation * 20 * Factor), (int)(Deviation * 20 * Factor)); Point DrawTetLocation = new Point((int)UseXPosition - (NextTetromino.Width / 2), (int)UseYPosition - NextTetromino.Height / 2); //Point DrawTetLocation = new Point(Deviate.X + (int)(NextDrawPosition.X + ((float)NextSize.Width / 2) - ((float)NextTetromino.Width / 2)), // Deviate.Y + (int)(NextDrawPosition.Y + ((float)NextSize.Height / 2) - ((float)NextTetromino.Height / 2))); double AngleMovePercent = Source.NextAngleOffset / AngleIncrementSize; double NumAffect = Source.NextAngleOffset == 0 ? 0 : AngleIncrementSize / Source.NextAngleOffset; Size DrawTetSize = new Size ( (int)((float)NextTetromino.Width * (0.3 + (1 - ((float)(i) * 0.15f) - .15f * AngleMovePercent))), (int)((float)NextTetromino.Height * (0.3 + (1 - ((float)(i) * 0.15f) - .15f * AngleMovePercent)))); //g.TranslateTransform(CenterPoint.X,CenterPoint.Y); g.TranslateTransform(DrawTetLocation.X + DrawTetSize.Width / 2, DrawTetLocation.Y + DrawTetSize.Width / 2); double DrawTetAngle = UseAngleCurrent; DrawTetAngle += (Math.PI * AngleMovePercent); float useDegrees = 180 + (float)(DrawTetAngle * (180 / Math.PI)); g.RotateTransform((float)useDegrees); g.TranslateTransform(-(DrawTetLocation.X + DrawTetSize.Width / 2), -(DrawTetLocation.Y + DrawTetSize.Height / 2)); //g.TranslateTransform(-CenterPoint.X,-CenterPoint.Y); if (DrawTetSize.Width > 0 && DrawTetSize.Height > 0) { //ImageAttributes Shade = GetShadowAttributes(1.0f - ((float)i * 0.3f)); ImageAttributes Shade = new ImageAttributes(); Shade.SetColorMatrix(ColorMatrices.GetFader(1.0f - ((float)i * 0.1f))); g.DrawImage (NextTetromino, new Rectangle((int)DrawTetLocation.X, (int)DrawTetLocation.Y, DrawTetSize.Width, DrawTetSize.Height), 0f, 0f, (float)NextTetromino.Width, (float)NextTetromino.Height, GraphicsUnit.Pixel, Shade); } g.ResetTransform(); } } if (Source.HoldBlock != null) { var GetKey = Source.PlayField.Theme.GetNominoKey(Source.HoldBlock, Source.GameHandler, Source.PlayField); Image HoldTetromino = Source.GetTetrominoImage(pOwner, Source.HoldBlock); g.DrawImage(HoldTetromino, CenterPoint.X - HoldTetromino.Width / 2, CenterPoint.Y - HoldTetromino.Height / 2); } } } }
public void EqualityTest(float x, float y, float width, float height) { RectangleF rect1 = new RectangleF(x, y, width, height); RectangleF rect2 = new RectangleF(width, height, x, y); Assert.True(rect1 != rect2); Assert.False(rect1 == rect2); Assert.False(rect1.Equals(rect2)); }
void renderLoop() { gpuRenderer.Init(); while (running) { if (redraw || fullredraw || targetTransform != null) { if (lockDraw) { waiting = true; continue; } try { Matrix3x3 mat = transform; if (targetTransform != null) { targetT += .03f; if (targetT < 1) { mat = Matrix3x3.Slerp(transform, targetTransform, -(float)Math.Cos(targetT * Math.PI) * .5f + .5f); } else { fullredraw = true; transform = mat = targetTransform; targetTransform = null; } if (Configuration.RefreshOnTransform) { fullredraw = true; } } Matrix3x3 tMat = mat.Clone(); Matrix3x3 dMat = (stableTransform.GetInverse() * mat).Clone(); waiting = false; redraw = false; //if (this.Height <= 0 || this.Width <= 0) return; int vW = (int)(this.Width * BufferSize); int vH = (int)(this.Height * BufferSize); if (rbmp == null || vW != gpuRenderer.Width || vH != gpuRenderer.Height) { gpuRenderer.Resize(new Size(vW, vH)); rbmp?.Dispose(); rbmp = gpuRenderer.CreateRenderTarget(); } if (!gpuRenderer.Begin(Style.Default.Background)) { return; } SizeF pSize = page.Format.GetPixelSize(); if (fullredraw) { stableTransform = transform; dMat = new Matrix3x3(); rbmp.Begin(); fullredraw = false; gpuRenderer.SetRenderTarget(rbmp); gpuRenderer.Begin(SystemColors.ControlDark); gpuRenderer.ResetTransform(); gpuRenderer.Transform(tMat); if (page.OriginalPage == null) { if (page.BackgroundImage == null) { gpuRenderer.FillRectangle(Util.ApplyFilter(Color.White, Page.Filter), new RectangleF( 0, 0, pSize.Width, pSize.Height)); } else { gpuRenderer.DrawImage(page.BackgroundImage, new RectangleF(0, 0, pSize.Width, pSize.Height)); } } else { gpuRenderer.FillRectangle(Color.White, new RectangleF( 0, 0, pSize.Width, pSize.Height)); } page.DrawBackground(gpuRenderer); if (page.OriginalPage != null && page.BackgroundImage != null) { gpuRenderer.DrawImage(page.BackgroundImage, new RectangleF(0, 0, pSize.Width, pSize.Height)); } page.Draw(gpuRenderer); rbmp.End(); gpuRenderer.SetRenderTarget(null); tmpLine = null; } gpuRenderer.ResetTransform(); gpuRenderer.Transform(dMat); gpuRenderer.DrawRenderBitmap(rbmp); gpuRenderer.ResetTransform(); gpuRenderer.Transform(tMat); gpuRenderer.DrawRect(Color.Black, 1, new RectangleF(0, 0, pSize.Width, pSize.Height)); if (tmpLine != null) { tmpLine.Render(gpuRenderer); } if (line != null) { line.Render(gpuRenderer); } if (selections != null) { lock (selections) { PointF[] pts = selections.ToArray(); transform.GetInverse().Transform(pts); gpuRenderer.DrawDashPolygon(pts); } } // Screen Objects foreach (BaseScreenObject bso in ScreenObjects) { gpuRenderer.ResetTransform(); bso.Draw(gpuRenderer, this.Width, this.Height); } gpuRenderer.ResetTransform(); gpuRenderer.Transform(Matrix3x3.Translation(0, 0)); gpuRenderer.DrawLine(Color.Black, 3, new PointF(0, 0), new PointF(this.Width, 0)); Renderer.Effects.DrawShadow(gpuRenderer, new RectangleF(0, 0, Width, 16)); if (Configuration.LeftHanded) { gpuRenderer.DrawLine(Color.Black, 3, new PointF(this.Width, 0), new PointF(this.Width, this.Height)); gpuRenderer.Transform(Matrix3x3.RotateD(-90)); gpuRenderer.Transform(Matrix3x3.Translation(Width, 0)); Renderer.Effects.DrawShadow(gpuRenderer, new RectangleF(0, 0, Height, 16)); gpuRenderer.ResetTransform(); } else { gpuRenderer.DrawLine(Color.Black, 3, new PointF(0, 0), new PointF(0, this.Height)); gpuRenderer.Transform(Matrix3x3.RotateD(90)); Renderer.Effects.DrawShadow(gpuRenderer, new RectangleF(0, 0, -Height, 16)); gpuRenderer.ResetTransform(); } Control _p = Parent; Form _parentForm; while (!(_p is Form)) { _p = _p.Parent; } _parentForm = (Form)_p; if (_parentForm.FormBorderStyle == FormBorderStyle.None) { string fullscreenInfo = ""; if (Configuration.ShowBattery) { fullscreenInfo += Language.GetText("Overlay.battery") + ": " + (int)(SystemInformation.PowerStatus.BatteryLifePercent * 100) + "%\n"; } if (Configuration.ShowTime) { fullscreenInfo += Language.GetText("Overlay.time") + ": " + DateTime.Now.ToShortTimeString() + "\n"; } if (Configuration.ShowDate) { fullscreenInfo += Language.GetText("Overlay.date") + ": " + DateTime.Now.ToShortDateString() + "\n"; } if (fullscreenInfo.Length > 1) { SizeF size = CreateGraphics().MeasureString(fullscreenInfo, new Font("Calibri", Util.MmToPoint(5))); RectangleF rect = new RectangleF(Width - size.Width - 16, Height - size.Height - 16, size.Width, size.Height); gpuRenderer.FillRectangle(Color.Black, rect); gpuRenderer.DrawText(fullscreenInfo, new PointF(Util.PointToMm(rect.X), Util.PointToMm(rect.Y)), 5, Color.White); } } if (rBounds.Equals(RectangleF.Empty)) { gpuRenderer.End(); } else { gpuRenderer.End(rBounds); } } catch (InvalidOperationException e) { Console.WriteLine(e.Message); } catch (FieldAccessException) { gpuRenderer.End(); } } Thread.Sleep(10); } gpuRenderer.Dispose(); }
public static void EqualityTest_NotRectangleF() { var rectangle = new RectangleF(0, 0, 0, 0); Assert.False(rectangle.Equals(null)); Assert.False(rectangle.Equals(0)); Assert.False(rectangle.Equals(new Rectangle(0, 0, 0, 0))); }
/// <summary> /// Converts Flowchart.NET arrow into SVG /// </summary> /// <param name="newArrow">Arrow reference</param> /// <returns>TRUE if successfull otherwise FALSE</returns> private bool CreateArrow(MindFusion.FlowChartX.Arrow newArrow) { bool bOk = false; string sPath = "", sPathPart = ""; int iCount = 0; try { if (newArrow.Origin != null) { if ((!newArrow.Origin.Visible) && (!InvisibleItems)) { return(true); } } if (newArrow.Destination != null) { if ((!newArrow.Destination.Visible) && (!InvisibleItems)) { return(true); } } if (newArrow.Style == ArrowStyle.Bezier) { sPath = String.Format("M{0},{1} C{2},{3} {4},{5} {6},{7} ", Unit2Pix(newArrow.ControlPoints[0].X), Unit2Pix(newArrow.ControlPoints[0].Y), Unit2Pix(newArrow.ControlPoints[1].X), Unit2Pix(newArrow.ControlPoints[1].Y), Unit2Pix(newArrow.ControlPoints[newArrow.ControlPoints.Count - 2].X), Unit2Pix(newArrow.ControlPoints[newArrow.ControlPoints.Count - 2].Y), Unit2Pix(newArrow.ControlPoints[newArrow.ControlPoints.Count - 1].X), Unit2Pix(newArrow.ControlPoints[newArrow.ControlPoints.Count - 1].Y)); } else { sPath = String.Format("M{0},{1} ", Unit2Pix(newArrow.ControlPoints[0].X), Unit2Pix(newArrow.ControlPoints[0].Y)); for (iCount = 1; iCount < newArrow.ControlPoints.Count; iCount++) { sPathPart = String.Format("L{0},{1} ", Unit2Pix(newArrow.ControlPoints[iCount].X), Unit2Pix(newArrow.ControlPoints[iCount].Y)); sPath += sPathPart; } } if (sPath == "") { return(false); } sPath = sPath.TrimEnd(); string sWidth = "1px"; if (newArrow.Pen.Width != 0) { String.Format("{0}px", Unit2Pix(newArrow.Pen.Width)); } sMan.AddPath(sPath, sWidth, newArrow.PenColor, Color.Transparent); sPath = ""; sPath = sMan.GetArrowHead(newArrow.HeadShape); XmlNode last_node = sMan.AddPath(sPath, sWidth, newArrow.PenColor, newArrow.PenColor); sPath = ""; sPath = sMan.GetArrowHead(newArrow.BaseShape); last_node = sMan.AddPath(sPath, sWidth, newArrow.PenColor, newArrow.PenColor); RectangleF rect = RectangleF.Empty; float angle = 0; rect = getTextRect(System.Drawing.Graphics.FromHwnd(SvgManager.GetActiveWindow()), newArrow.Style, newArrow.TextStyle, newArrow.ControlPoints, newArrow.TextColor, newArrow.SegmentCount, newArrow.Text, newArrow.Font, RectangleF.Empty, ref angle); if (!rect.Equals(RectangleF.Empty)) { StringFormat sf = new StringFormat(); sf.Alignment = StringAlignment.Center; XmlNode text_added = sMan.AddText(null, newArrow.Text, newArrow.Font, rect, newArrow.TextColor, sf, false, angle); } bOk = true; } catch (Exception ex) { Trace.WriteLine(String.Format("{0} error {1}\n", "CreateArrow", ex.Message)); bOk = false; } return(bOk); }