Browse Source

bug fixes and performance improvements

main
Colin McMillen 11 months ago
parent
commit
8d4bf9c69f
  1. 32
      Program.cs

32
Program.cs

@ -77,7 +77,7 @@ public class ViewTool : ITool {
}
public string Status() {
return "view";
return "";
}
public void Draw(UiGeometry geometry, Game game) {
@ -88,12 +88,19 @@ public class ViewTool : ITool {
// FIXME: remove unneeded dependencies on "Game" or at least refactor them a bit.
public class CropTool : ITool {
Photo? activePhoto;
Photo activePhoto;
Vector2i mouseDragStart;
Vector2i mouseDragEnd;
string status = "";
public CropTool(Photo photo) {
activePhoto = photo;
}
public void SetActivePhoto(Photo photo) {
if (photo != activePhoto) {
// FIXME: handle this sensibly.
}
activePhoto = photo;
}
@ -139,6 +146,8 @@ public class CropTool : ITool {
// in other direction work well.
Vector2i start = mouseDragStart;
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;
int left = Math.Min(start.X, end.X);
@ -160,9 +169,7 @@ public class CropTool : ITool {
Rectangle crop = Rectangle.FromLTRB(leftTop.X, leftTop.Y, rightBottom.X, rightBottom.Y);
// FIXME: make sure this doesn't exceed image.Bounds.
// FIXME: once set, display it properly in the PhotoBox.
if (activePhoto != null) {
activePhoto.CropRectangle = crop;
}
activePhoto.CropRectangle = crop;
Console.WriteLine(crop);
}
@ -587,7 +594,7 @@ public static class Util {
}
// FIXME: I'm not convinced that all of these are correct, especially the
// cases that involve flipping (because whether you're flipping before or
// after rotation matters.).
// after rotation matters.)
var operations = new Dictionary<ushort, (RotateMode, FlipMode)> {
{ 2, (RotateMode.None, FlipMode.Horizontal) },
{ 3, (RotateMode.Rotate180, FlipMode.None) },
@ -606,6 +613,11 @@ public static class Util {
}
public static Texture RenderText(string text, int size) {
// Make sure that 0-length text doesn't end up as a 0-size texture, which
// might cause problems.
if (text.Length == 0) {
text = " ";
}
Font font = SystemFonts.CreateFont("Consolas", size, FontStyle.Bold);
TextOptions options = new(font);
FontRectangle rect = TextMeasurer.Measure(text, new TextOptions(font));
@ -713,8 +725,6 @@ public class Game : GameWindow {
Close();
}
int lastPhotoIndex = photoIndex;
mousePosition = (Vector2i) MouseState.Position;
// Look for mouse clicks on thumbnails or stars.
@ -786,10 +796,6 @@ public class Game : GameWindow {
photoIndex = Math.Clamp(photoIndex, 0, photos.Count - 1);
}
if (photoIndex != lastPhotoIndex) {
// FIXME!!!: do something to reset tool state here
}
// Handle presses of the "rating" keys -- 0-5 and `.
// A normal press just sets the rating of the current photo.
// If the user is holding "shift", we instead filter to only show photos of that rating or higher.
@ -856,7 +862,7 @@ public class Game : GameWindow {
// Handle tool switching.
if (activeTool == viewTool) {
if (input.IsKeyPressed(Keys.C)) {
activeTool = new CropTool();
activeTool = new CropTool(photos[photoIndex]);
}
}

Loading…
Cancel
Save