remove most of CameraInfo, just use an AspectRatio instead
This commit is contained in:
parent
82e9f59f5e
commit
e736d2db5f
31
Program.cs
31
Program.cs
@ -38,15 +38,7 @@ public class FpsCounter {
|
|||||||
|
|
||||||
|
|
||||||
public class CameraInfo {
|
public class CameraInfo {
|
||||||
public readonly Vector2i Resolution;
|
public static float AspectRatio = 6000f / 4000f;
|
||||||
|
|
||||||
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));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -61,12 +53,12 @@ public class Transform {
|
|||||||
// FIXME: move scale and offset into Photo itself?
|
// FIXME: move scale and offset into Photo itself?
|
||||||
float activeScale;
|
float activeScale;
|
||||||
Vector2i activeOffset;
|
Vector2i activeOffset;
|
||||||
Photo photo;
|
Vector2i photoSize;
|
||||||
|
|
||||||
public Transform(float scale, Vector2i offset, Photo photo) {
|
public Transform(float scale, Vector2i offset, Vector2i photoSize) {
|
||||||
activeScale = scale;
|
activeScale = scale;
|
||||||
activeOffset = offset;
|
activeOffset = offset;
|
||||||
this.photo = photo;
|
this.photoSize = photoSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Vector2i ScreenToImageDelta(int x, int y) {
|
public Vector2i ScreenToImageDelta(int x, int y) {
|
||||||
@ -76,8 +68,8 @@ public class Transform {
|
|||||||
public Vector2i ScreenToImage(int x, int y) {
|
public Vector2i ScreenToImage(int x, int y) {
|
||||||
int rx = (int) ((x - activeOffset.X) / activeScale);
|
int rx = (int) ((x - activeOffset.X) / activeScale);
|
||||||
int ry = (int) ((y - activeOffset.Y) / activeScale);
|
int ry = (int) ((y - activeOffset.Y) / activeScale);
|
||||||
rx = Math.Clamp(rx, 0, photo.Size.X);
|
rx = Math.Clamp(rx, 0, photoSize.X);
|
||||||
ry = Math.Clamp(ry, 0, photo.Size.Y);
|
ry = Math.Clamp(ry, 0, photoSize.Y);
|
||||||
return new(rx, ry);
|
return new(rx, ry);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -199,8 +191,8 @@ public class CropTool : ITool {
|
|||||||
Vector2i end = mouseDragEnd;
|
Vector2i end = mouseDragEnd;
|
||||||
// FIXME: choose the aspect ratio based on the original image aspect ratio.
|
// FIXME: choose the aspect ratio based on the original image aspect ratio.
|
||||||
// FIXME: allow for unconstrained crop, 1:1, etc.
|
// FIXME: allow for unconstrained crop, 1:1, etc.
|
||||||
end.Y = Math.Min(end.Y, start.Y + (end.X - start.X) * 4 / 6);
|
end.Y = Math.Min(end.Y, (int) (start.Y + (end.X - start.X) / CameraInfo.AspectRatio));
|
||||||
end.X = start.X + (end.Y - start.Y) * 6 / 4;
|
end.X = (int) (start.X + (end.Y - start.Y) * CameraInfo.AspectRatio);
|
||||||
int left = Math.Min(start.X, end.X);
|
int left = Math.Min(start.X, end.X);
|
||||||
int right = Math.Max(start.X, end.X);
|
int right = Math.Max(start.X, end.X);
|
||||||
int top = Math.Min(start.Y, end.Y);
|
int top = Math.Min(start.Y, end.Y);
|
||||||
@ -270,7 +262,6 @@ public class Texture : IDisposable {
|
|||||||
|
|
||||||
public class UiGeometry {
|
public class UiGeometry {
|
||||||
public static Vector2i MIN_WINDOW_SIZE = new(1024, 768);
|
public static Vector2i MIN_WINDOW_SIZE = new(1024, 768);
|
||||||
private static CameraInfo activeCamera = CameraInfo.CANON_EOS_R6M2;
|
|
||||||
|
|
||||||
public readonly Vector2i WindowSize;
|
public readonly Vector2i WindowSize;
|
||||||
public readonly Box2i ThumbnailBox;
|
public readonly Box2i ThumbnailBox;
|
||||||
@ -286,7 +277,7 @@ public class UiGeometry {
|
|||||||
|
|
||||||
int numThumbnails = Math.Max(WindowSize.Y / 100, 1);
|
int numThumbnails = Math.Max(WindowSize.Y / 100, 1);
|
||||||
int thumbnailHeight = WindowSize.Y / numThumbnails;
|
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}");
|
Console.WriteLine($"thumbnail size: {thumbnailWidth} x {thumbnailHeight}");
|
||||||
for (int i = 0; i < numThumbnails; i++) {
|
for (int i = 0; i < numThumbnails; i++) {
|
||||||
@ -444,7 +435,7 @@ public class Game : GameWindow {
|
|||||||
Vector2i mousePosition;
|
Vector2i mousePosition;
|
||||||
float activeScale = 1f;
|
float activeScale = 1f;
|
||||||
Vector2i activeOffset;
|
Vector2i activeOffset;
|
||||||
Transform transform = new(1f, Vector2i.Zero, null);
|
Transform transform = new(1f, Vector2i.Zero, Vector2i.Zero);
|
||||||
Shader shader = new();
|
Shader shader = new();
|
||||||
Matrix4 projection;
|
Matrix4 projection;
|
||||||
float zoomLevel = 0f;
|
float zoomLevel = 0f;
|
||||||
@ -816,7 +807,7 @@ public class Game : GameWindow {
|
|||||||
Vector2i center = (Vector2i) geometry.PhotoBox.Center;
|
Vector2i center = (Vector2i) geometry.PhotoBox.Center;
|
||||||
Box2i photoBox = Util.MakeBox(center.X - renderSize.X / 2, center.Y - renderSize.Y / 2, renderSize.X, renderSize.Y);
|
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);
|
activeOffset = new(photoBox.Min.X, photoBox.Min.Y);
|
||||||
transform = new Transform(activeScale, activeOffset, activePhoto);
|
transform = new Transform(activeScale, activeOffset, activePhoto.Size);
|
||||||
DrawTexture(active, photoBox);
|
DrawTexture(active, photoBox);
|
||||||
for (int i = 0; i < 5; i++) {
|
for (int i = 0; i < 5; i++) {
|
||||||
Texture star = (activePhoto.Rating > i) ? STAR_FILLED : STAR_EMPTY;
|
Texture star = (activePhoto.Rating > i) ? STAR_FILLED : STAR_EMPTY;
|
||||||
|
Loading…
Reference in New Issue
Block a user