public static SRectF Scale(this SRectF rect, float scale) { return(new SRectF( rect.X - rect.W * (scale - 1f) * 0.5f, rect.Y - rect.H * (scale - 1f) * 0.5f, rect.W * scale, rect.H * scale, rect.Z)); }
public static SRectF Scale(this SRectF rect, float scale) { return(new SRectF( rect.X - rect.W * (scale - 1f), rect.Y - rect.H * (scale - 1f), rect.W + 2 * rect.W * (scale - 1f), rect.H + 2 * rect.H * (scale - 1f), rect.Z)); }
public static bool IsInBounds(SRectF bounds, int x, int y) { return(((float)x).IsInRange(bounds.X, bounds.X + bounds.W) && ((float)y).IsInRange(bounds.Y, bounds.Y + bounds.H)); }
public static bool IsInBounds(SRectF bounds, SMouseEvent mouseEvent) { return(IsInBounds(bounds, mouseEvent.X, mouseEvent.Y)); }
/// <summary> /// Places a rect within the bounds maintaining the aspectRatio and using the given aspect /// </summary> /// <param name="bounds">Bounds to fit the rect in</param> /// <param name="aspectRatio">The original aspectRatio of the rect/image/...</param> /// <param name="aspect"> /// Crop: No empty space in bounds but has overhanging parts (same on both sides)<br /> /// LetterBox: Fit the long side possibly leaving some space on the other (rect will be centered)<br /> /// StretcH: Just fit the rect in the bounds (rect=bounds) /// </param> public static SRectF FitInBounds(SRectF bounds, float aspectRatio, EAspect aspect) { if (aspect == EAspect.Stretch) { return(bounds); } float boundsAspectRatio = bounds.W / bounds.H; float scaledWidth, scaledHeight; switch (aspect) { case EAspect.Automatic: case EAspect.Crop: if (boundsAspectRatio >= aspectRatio) { scaledWidth = bounds.W; scaledHeight = bounds.W / aspectRatio; } else { scaledHeight = bounds.H; scaledWidth = bounds.H * aspectRatio; } break; case EAspect.Zoom1: if (boundsAspectRatio >= aspectRatio) { scaledWidth = bounds.W * 1.33f; scaledHeight = bounds.W * 1.33f / aspectRatio; } else { scaledHeight = bounds.H / 1.33f; scaledWidth = bounds.H / 1.33f * aspectRatio; } break; case EAspect.Zoom2: if (boundsAspectRatio >= aspectRatio) { scaledWidth = bounds.W * 1.17f; scaledHeight = bounds.W * 1.17f / aspectRatio; } else { scaledHeight = bounds.H / 1.17f; scaledWidth = bounds.H / 1.17f * aspectRatio; } break; case EAspect.LetterBox: if (boundsAspectRatio < aspectRatio) { scaledWidth = bounds.W; scaledHeight = bounds.W / aspectRatio; } else { scaledHeight = bounds.H; scaledWidth = bounds.H * aspectRatio; } break; case EAspect.PillarBox: scaledWidth = bounds.W * 0.77f; scaledHeight = bounds.W / aspectRatio; break; default: return(bounds); } float left = (bounds.W - scaledWidth) / 2 + bounds.X; float top = (bounds.H - scaledHeight) / 2 + bounds.Y; return(new SRectF(left, top, scaledWidth, scaledHeight, bounds.Z)); }