/// <summary> /// Process a RenderableObject when the GlobalLayerScaleType is set to Dynamic. /// </summary> /// <param name="obj"></param> /// <param name="isBaseRes"></param> /// <param name="crntRes"></param> /// <param name="resScale"></param> protected void ProcessDynamicallyScaledRenderable( RenderableObject obj, bool isBaseRes, Resolution crntRes, Vector2 resScale) { var maintainAspectRatio = obj.MaintainAspectRatio; var scaleType = obj.ScaleType; Vector2 scale; if (!isBaseRes) { switch (scaleType) { case ResolutionScaleType.Min: var min = MathHelper.Min(resScale.X, resScale.Y); if (maintainAspectRatio) { scale = new Vector2(min, min); } else if (min == resScale.X) { scale = new Vector2(min, 1f); } else { scale = new Vector2(1f, min); } break; case ResolutionScaleType.Max: var max = MathHelper.Max(resScale.X, resScale.Y); if (maintainAspectRatio) { scale = new Vector2(max, max); } else if (max == resScale.X) { scale = new Vector2(max, 1f); } else { scale = new Vector2(1f, max); } break; case ResolutionScaleType.Width: if (maintainAspectRatio) { scale = new Vector2(resScale.X, resScale.X); } else { scale = new Vector2(resScale.X, 1f); } break; case ResolutionScaleType.Height: if (maintainAspectRatio) { scale = new Vector2(resScale.Y, resScale.Y); } else { scale = new Vector2(1f, resScale.Y); } break; case ResolutionScaleType.WithRes: /* * if (maintainAspectRatio && resScale.X != resScale.Y) * // throw an error or log a warning or something... */ scale = new Vector2(resScale.X, resScale.Y); break; default: throw new RenderLayerException( String.Format( "Unknown ResolutionScaleType '{0}' received on object '{1}'.", scaleType, obj)); } } else { scale = Vector2.One; } bool hasOriginalScale = obj.SpriteProperties.Scale.HasValue; Vector2 originalScale = hasOriginalScale ? obj.SpriteProperties.Scale.Value : Vector2.One; var resultingScale = VectorUtils.ComponentwiseProduct(originalScale, scale); // Swap out the original scale for the newly calculated scale. obj.SpriteProperties.Scale = resultingScale; obj.InternalRender(SeenRenderables); obj.SpriteProperties.Scale = hasOriginalScale ? (Vector2?)originalScale : null; }
/// <summary> /// Process a RenderableObject when the GlobalLayerScaleType is set to Dynamic. /// </summary> /// <param name="obj"></param> /// <param name="isBaseRes"></param> /// <param name="crntRes"></param> /// <param name="resScale"></param> protected void ProcessDynamicallyScaledRenderable( RenderableObject obj, bool isBaseRes, Resolution crntRes, Vector2 resScale) { var maintainAspectRatio = obj.MaintainAspectRatio; var scaleType = obj.ScaleType; Vector2 scale; if (!isBaseRes) { switch (scaleType) { case ResolutionScaleType.Min: var min = MathHelper.Min(resScale.X, resScale.Y); if (maintainAspectRatio) scale = new Vector2(min, min); else if (min == resScale.X) scale = new Vector2(min, 1f); else scale = new Vector2(1f, min); break; case ResolutionScaleType.Max: var max = MathHelper.Max(resScale.X, resScale.Y); if (maintainAspectRatio) scale = new Vector2(max, max); else if (max == resScale.X) scale = new Vector2(max, 1f); else scale = new Vector2(1f, max); break; case ResolutionScaleType.Width: if (maintainAspectRatio) scale = new Vector2(resScale.X, resScale.X); else scale = new Vector2(resScale.X, 1f); break; case ResolutionScaleType.Height: if (maintainAspectRatio) scale = new Vector2(resScale.Y, resScale.Y); else scale = new Vector2(1f, resScale.Y); break; case ResolutionScaleType.WithRes: /* if (maintainAspectRatio && resScale.X != resScale.Y) // throw an error or log a warning or something... */ scale = new Vector2(resScale.X, resScale.Y); break; default: throw new RenderLayerException( String.Format( "Unknown ResolutionScaleType '{0}' received on object '{1}'.", scaleType, obj)); } } else { scale = Vector2.One; } bool hasOriginalScale = obj.SpriteProperties.Scale.HasValue; Vector2 originalScale = hasOriginalScale ? obj.SpriteProperties.Scale.Value : Vector2.One; var resultingScale = VectorUtils.ComponentwiseProduct(originalScale, scale); // Swap out the original scale for the newly calculated scale. obj.SpriteProperties.Scale = resultingScale; obj.InternalRender(SeenRenderables); obj.SpriteProperties.Scale = hasOriginalScale ? (Vector2?)originalScale : null; }