change mouse cursor when inside crop box

This commit is contained in:
Colin McMillen 2023-08-26 15:37:57 -04:00
parent bcb2e7be7d
commit 7c7976a82d

View File

@ -87,14 +87,14 @@ public class Transform {
} }
public interface ITool { public interface ITool {
ToolStatus HandleInput(KeyboardState input, MouseState mouse, Transform transform); ToolStatus HandleInput(KeyboardState input, MouseState mouse, Transform transform, Game game);
string Status(); string Status();
void Draw(UiGeometry geometry, Game game); void Draw(UiGeometry geometry, Game game);
} }
public class ViewTool : ITool { public class ViewTool : ITool {
public ToolStatus HandleInput(KeyboardState input, MouseState mouse, Transform transform) { public ToolStatus HandleInput(KeyboardState input, MouseState mouse, Transform transform, Game game) {
return ToolStatus.Active; return ToolStatus.Active;
} }
@ -121,13 +121,15 @@ public class CropTool : ITool {
mouseDragEnd = new(photo.CropRectangle.Right, photo.CropRectangle.Bottom); mouseDragEnd = new(photo.CropRectangle.Right, photo.CropRectangle.Bottom);
} }
public ToolStatus HandleInput(KeyboardState input, MouseState mouse, Transform transform) { public ToolStatus HandleInput(KeyboardState input, MouseState mouse, Transform transform, Game game) {
Vector2i mousePosition = (Vector2i) mouse.Position; Vector2i mousePosition = (Vector2i) mouse.Position;
Vector2i imagePosition = transform.ScreenToImage(mousePosition); Vector2i imagePosition = transform.ScreenToImage(mousePosition);
bool mouseInRectangle = photo.CropRectangle.Contains(imagePosition.X, imagePosition.Y);
if (mouse.IsButtonPressed(MouseButton.Button1)) { if (mouse.IsButtonPressed(MouseButton.Button1)) {
dragging = photo.CropRectangle.Contains(imagePosition.X, imagePosition.Y); dragging = mouseInRectangle;
} }
game.Cursor = mouseInRectangle ? MouseCursor.Default : MouseCursor.Crosshair;
if (!dragging) { if (!dragging) {
if (mouse.IsButtonPressed(MouseButton.Button1)) { if (mouse.IsButtonPressed(MouseButton.Button1)) {
@ -169,10 +171,12 @@ public class CropTool : ITool {
status = $"({r.Left}, {r.Top}, {r.Right}, {r.Bottom}) {r.Width}x{r.Height}"; status = $"({r.Left}, {r.Top}, {r.Right}, {r.Bottom}) {r.Width}x{r.Height}";
if (input.IsKeyPressed(Keys.Enter)) { if (input.IsKeyPressed(Keys.Enter)) {
game.Cursor = MouseCursor.Default;
return ToolStatus.Done; return ToolStatus.Done;
} }
if (input.IsKeyPressed(Keys.Escape)) { if (input.IsKeyPressed(Keys.Escape)) {
game.Cursor = MouseCursor.Default;
photo.CropRectangle = Rectangle.Empty; photo.CropRectangle = Rectangle.Empty;
return ToolStatus.Canceled; return ToolStatus.Canceled;
} }
@ -437,8 +441,8 @@ public class Game : GameWindow {
RenderFrequency = 30; RenderFrequency = 30;
UpdateFrequency = 30; UpdateFrequency = 30;
} else { } else {
RenderFrequency = 2; RenderFrequency = 5;
UpdateFrequency = 2; UpdateFrequency = 5;
} }
Photo previousPhoto = photos[photoIndex]; Photo previousPhoto = photos[photoIndex];
@ -601,7 +605,7 @@ public class Game : GameWindow {
} }
// Delegate input to the active tool. // Delegate input to the active tool.
ToolStatus status = activeTool.HandleInput(KeyboardState, MouseState, transform); ToolStatus status = activeTool.HandleInput(KeyboardState, MouseState, transform, this);
// Change back to the default tool if the active tool is done. // Change back to the default tool if the active tool is done.
if (status != ToolStatus.Active) { if (status != ToolStatus.Active) {
@ -673,7 +677,7 @@ public class Game : GameWindow {
false, 5 * sizeof(float), 3 * sizeof(float)); false, 5 * sizeof(float), 3 * sizeof(float));
// Load photos from a directory. // Load photos from a directory.
// string[] files = Directory.GetFiles(@"c:\users\colin\desktop\photos-test\"); string[] files = Directory.GetFiles(@"c:\users\colin\desktop\photos-test\");
// string[] files = Directory.GetFiles(@"c:\users\colin\pictures\photos\2023\07\14\"); // string[] files = Directory.GetFiles(@"c:\users\colin\pictures\photos\2023\07\14\");
// string[] files = Directory.GetFiles(@"c:\users\colin\pictures\photos\2023\07\23\"); // string[] files = Directory.GetFiles(@"c:\users\colin\pictures\photos\2023\07\23\");
// string[] files = Directory.GetFiles(@"G:\DCIM\100EOSR6\"); // string[] files = Directory.GetFiles(@"G:\DCIM\100EOSR6\");
@ -681,7 +685,7 @@ public class Game : GameWindow {
// string[] files = Directory.GetFiles(@"c:\users\colin\desktop\import"); // string[] files = Directory.GetFiles(@"c:\users\colin\desktop\import");
// string[] files = Directory.GetFiles(@"C:\Users\colin\Pictures\photos\2018\06\23"); // string[] files = Directory.GetFiles(@"C:\Users\colin\Pictures\photos\2018\06\23");
// string[] files = Directory.GetFiles(@"C:\Users\colin\Desktop\Germany all\104D7000"); // string[] files = Directory.GetFiles(@"C:\Users\colin\Desktop\Germany all\104D7000");
string[] files = Directory.GetFiles(@"C:\Users\colin\Desktop\many-birds\"); // string[] files = Directory.GetFiles(@"C:\Users\colin\Desktop\many-birds\");
for (int i = 0; i < files.Count(); i++) { for (int i = 0; i < files.Count(); i++) {
string file = files[i]; string file = files[i];