From 22aa1e0d88ea898cdabde9d6eccc6dce2ed3560f Mon Sep 17 00:00:00 2001 From: Colin McMillen Date: Sat, 8 Jul 2023 00:30:05 -0400 Subject: [PATCH] clean up photo / letterbox centering code --- Program.cs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/Program.cs b/Program.cs index 69bb03b..e745111 100644 --- a/Program.cs +++ b/Program.cs @@ -328,12 +328,13 @@ public class Game : GameWindow { Texture active = textures[textureIndex]; // FIXME: make a function for scaling & centering one box on another. - double scaleX = 1.0 * geometry.PhotoBox.Size.X / active.Size.X; - double scaleY = 1.0 * geometry.PhotoBox.Size.Y / active.Size.Y; - double scale = Math.Min(scaleX, scaleY); - int renderWidth = (int) (active.Size.X * scale); - int renderHeight = (int) (active.Size.Y * scale); - Box2i photoBox = Util.makeBox((int) geometry.PhotoBox.Center.X - renderWidth / 2, (int) geometry.PhotoBox.Center.Y - renderHeight / 2, renderWidth, renderHeight); + float scaleX = 1f * geometry.PhotoBox.Size.X / active.Size.X; + float scaleY = 1f * geometry.PhotoBox.Size.Y / active.Size.Y; + float scale = Math.Min(scaleX, scaleY); + + Vector2i renderSize = (Vector2i) (((Vector2) active.Size) * scale); + Vector2i center = (Vector2i) geometry.PhotoBox.Center; + Box2i photoBox = Util.makeBox(center.X - renderSize.X / 2, center.Y - renderSize.Y / 2, renderSize.X, renderSize.Y); DrawTexture(active, photoBox); for (int i = 0; i < textures.Count; i++) { Box2i box = geometry.ThumbnailBoxes[i];