remove most of CameraInfo, just use an AspectRatio instead

This commit is contained in:
Colin McMillen 2023-08-05 15:10:10 -04:00
parent 82e9f59f5e
commit e736d2db5f

View File

@ -38,15 +38,7 @@ public class FpsCounter {
public class CameraInfo {
public readonly Vector2i Resolution;
private CameraInfo(Vector2i resolution) {
Resolution = resolution;
}
public static readonly CameraInfo NIKON_D7000 = new(new Vector2i(4928, 3264));
public static readonly CameraInfo CANON_EOS_R6M2 = new(new Vector2i(6000, 4000));
public static readonly CameraInfo IPHONE_12_MINI = new(new Vector2i(4032, 3024));
public static float AspectRatio = 6000f / 4000f;
}
@ -61,12 +53,12 @@ public class Transform {
// FIXME: move scale and offset into Photo itself?
float activeScale;
Vector2i activeOffset;
Photo photo;
Vector2i photoSize;
public Transform(float scale, Vector2i offset, Photo photo) {
public Transform(float scale, Vector2i offset, Vector2i photoSize) {
activeScale = scale;
activeOffset = offset;
this.photo = photo;
this.photoSize = photoSize;
}
public Vector2i ScreenToImageDelta(int x, int y) {
@ -76,8 +68,8 @@ public class Transform {
public Vector2i ScreenToImage(int x, int y) {
int rx = (int) ((x - activeOffset.X) / activeScale);
int ry = (int) ((y - activeOffset.Y) / activeScale);
rx = Math.Clamp(rx, 0, photo.Size.X);
ry = Math.Clamp(ry, 0, photo.Size.Y);
rx = Math.Clamp(rx, 0, photoSize.X);
ry = Math.Clamp(ry, 0, photoSize.Y);
return new(rx, ry);
}
@ -199,8 +191,8 @@ public class CropTool : ITool {
Vector2i end = mouseDragEnd;
// FIXME: choose the aspect ratio based on the original image aspect ratio.
// FIXME: allow for unconstrained crop, 1:1, etc.
end.Y = Math.Min(end.Y, start.Y + (end.X - start.X) * 4 / 6);
end.X = start.X + (end.Y - start.Y) * 6 / 4;
end.Y = Math.Min(end.Y, (int) (start.Y + (end.X - start.X) / CameraInfo.AspectRatio));
end.X = (int) (start.X + (end.Y - start.Y) * CameraInfo.AspectRatio);
int left = Math.Min(start.X, end.X);
int right = Math.Max(start.X, end.X);
int top = Math.Min(start.Y, end.Y);
@ -270,7 +262,6 @@ public class Texture : IDisposable {
public class UiGeometry {
public static Vector2i MIN_WINDOW_SIZE = new(1024, 768);
private static CameraInfo activeCamera = CameraInfo.CANON_EOS_R6M2;
public readonly Vector2i WindowSize;
public readonly Box2i ThumbnailBox;
@ -286,7 +277,7 @@ public class UiGeometry {
int numThumbnails = Math.Max(WindowSize.Y / 100, 1);
int thumbnailHeight = WindowSize.Y / numThumbnails;
int thumbnailWidth = (int) 1.0 * thumbnailHeight * activeCamera.Resolution.X / activeCamera.Resolution.Y;
int thumbnailWidth = (int) (1.0 * thumbnailHeight * CameraInfo.AspectRatio);
Console.WriteLine($"thumbnail size: {thumbnailWidth} x {thumbnailHeight}");
for (int i = 0; i < numThumbnails; i++) {
@ -444,7 +435,7 @@ public class Game : GameWindow {
Vector2i mousePosition;
float activeScale = 1f;
Vector2i activeOffset;
Transform transform = new(1f, Vector2i.Zero, null);
Transform transform = new(1f, Vector2i.Zero, Vector2i.Zero);
Shader shader = new();
Matrix4 projection;
float zoomLevel = 0f;
@ -816,7 +807,7 @@ public class Game : GameWindow {
Vector2i center = (Vector2i) geometry.PhotoBox.Center;
Box2i photoBox = Util.MakeBox(center.X - renderSize.X / 2, center.Y - renderSize.Y / 2, renderSize.X, renderSize.Y);
activeOffset = new(photoBox.Min.X, photoBox.Min.Y);
transform = new Transform(activeScale, activeOffset, activePhoto);
transform = new Transform(activeScale, activeOffset, activePhoto.Size);
DrawTexture(active, photoBox);
for (int i = 0; i < 5; i++) {
Texture star = (activePhoto.Rating > i) ? STAR_FILLED : STAR_EMPTY;