bug fixes and performance improvements
This commit is contained in:
parent
6df7f1e53b
commit
8d4bf9c69f
30
Program.cs
30
Program.cs
@ -77,7 +77,7 @@ public class ViewTool : ITool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public string Status() {
|
public string Status() {
|
||||||
return "view";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Draw(UiGeometry geometry, Game game) {
|
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.
|
// FIXME: remove unneeded dependencies on "Game" or at least refactor them a bit.
|
||||||
public class CropTool : ITool {
|
public class CropTool : ITool {
|
||||||
|
|
||||||
Photo? activePhoto;
|
Photo activePhoto;
|
||||||
Vector2i mouseDragStart;
|
Vector2i mouseDragStart;
|
||||||
Vector2i mouseDragEnd;
|
Vector2i mouseDragEnd;
|
||||||
string status = "";
|
string status = "";
|
||||||
|
|
||||||
|
public CropTool(Photo photo) {
|
||||||
|
activePhoto = photo;
|
||||||
|
}
|
||||||
|
|
||||||
public void SetActivePhoto(Photo photo) {
|
public void SetActivePhoto(Photo photo) {
|
||||||
|
if (photo != activePhoto) {
|
||||||
|
// FIXME: handle this sensibly.
|
||||||
|
}
|
||||||
activePhoto = photo;
|
activePhoto = photo;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -139,6 +146,8 @@ public class CropTool : ITool {
|
|||||||
// in other direction work well.
|
// in other direction work well.
|
||||||
Vector2i start = mouseDragStart;
|
Vector2i start = mouseDragStart;
|
||||||
Vector2i end = mouseDragEnd;
|
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.Y = Math.Min(end.Y, start.Y + (end.X - start.X) * 4 / 6);
|
||||||
end.X = start.X + (end.Y - start.Y) * 6 / 4;
|
end.X = start.X + (end.Y - start.Y) * 6 / 4;
|
||||||
int left = Math.Min(start.X, end.X);
|
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);
|
Rectangle crop = Rectangle.FromLTRB(leftTop.X, leftTop.Y, rightBottom.X, rightBottom.Y);
|
||||||
// FIXME: make sure this doesn't exceed image.Bounds.
|
// FIXME: make sure this doesn't exceed image.Bounds.
|
||||||
// FIXME: once set, display it properly in the PhotoBox.
|
// FIXME: once set, display it properly in the PhotoBox.
|
||||||
if (activePhoto != null) {
|
|
||||||
activePhoto.CropRectangle = crop;
|
activePhoto.CropRectangle = crop;
|
||||||
}
|
|
||||||
Console.WriteLine(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
|
// FIXME: I'm not convinced that all of these are correct, especially the
|
||||||
// cases that involve flipping (because whether you're flipping before or
|
// cases that involve flipping (because whether you're flipping before or
|
||||||
// after rotation matters.).
|
// after rotation matters.)
|
||||||
var operations = new Dictionary<ushort, (RotateMode, FlipMode)> {
|
var operations = new Dictionary<ushort, (RotateMode, FlipMode)> {
|
||||||
{ 2, (RotateMode.None, FlipMode.Horizontal) },
|
{ 2, (RotateMode.None, FlipMode.Horizontal) },
|
||||||
{ 3, (RotateMode.Rotate180, FlipMode.None) },
|
{ 3, (RotateMode.Rotate180, FlipMode.None) },
|
||||||
@ -606,6 +613,11 @@ public static class Util {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static Texture RenderText(string text, int size) {
|
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);
|
Font font = SystemFonts.CreateFont("Consolas", size, FontStyle.Bold);
|
||||||
TextOptions options = new(font);
|
TextOptions options = new(font);
|
||||||
FontRectangle rect = TextMeasurer.Measure(text, new TextOptions(font));
|
FontRectangle rect = TextMeasurer.Measure(text, new TextOptions(font));
|
||||||
@ -713,8 +725,6 @@ public class Game : GameWindow {
|
|||||||
Close();
|
Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
int lastPhotoIndex = photoIndex;
|
|
||||||
|
|
||||||
mousePosition = (Vector2i) MouseState.Position;
|
mousePosition = (Vector2i) MouseState.Position;
|
||||||
|
|
||||||
// Look for mouse clicks on thumbnails or stars.
|
// Look for mouse clicks on thumbnails or stars.
|
||||||
@ -786,10 +796,6 @@ public class Game : GameWindow {
|
|||||||
photoIndex = Math.Clamp(photoIndex, 0, photos.Count - 1);
|
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 `.
|
// Handle presses of the "rating" keys -- 0-5 and `.
|
||||||
// A normal press just sets the rating of the current photo.
|
// 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.
|
// 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.
|
// Handle tool switching.
|
||||||
if (activeTool == viewTool) {
|
if (activeTool == viewTool) {
|
||||||
if (input.IsKeyPressed(Keys.C)) {
|
if (input.IsKeyPressed(Keys.C)) {
|
||||||
activeTool = new CropTool();
|
activeTool = new CropTool(photos[photoIndex]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user