don't grad the photo around unless the drag starts in the photobox

This commit is contained in:
Colin McMillen 2023-08-31 23:40:35 -04:00
parent e612429298
commit 4a84774855

View File

@ -87,20 +87,26 @@ public class Transform {
}
public interface ITool {
ToolStatus HandleInput(KeyboardState input, MouseState mouse, Transform transform, Game game, Photo photo);
ToolStatus HandleInput(KeyboardState input, MouseState mouse, Transform transform, Game game, Photo photo, UiGeometry geometry);
string Status();
void Draw(UiGeometry geometry, Game game);
}
public class ViewTool : ITool {
public ToolStatus HandleInput(KeyboardState input, MouseState mouse, Transform transform, Game game, Photo photo) {
private bool dragging = false;
public ToolStatus HandleInput(KeyboardState input, MouseState mouse, Transform transform, Game game, Photo photo, UiGeometry geometry) {
Vector2i mousePosition = (Vector2i) mouse.Position;
if (mouse.IsButtonDown(MouseButton.Button1)) {
if (mouse.IsButtonPressed(MouseButton.Button1) && geometry.PhotoBox.ContainsInclusive(mousePosition)) {
dragging = true;
}
if (!mouse.IsButtonDown(MouseButton.Button1)) {
dragging = false;
}
if (dragging) {
Vector2 delta = mouse.Delta;
Vector2i imageDelta = transform.ScreenToImageDelta((int) delta.X, (int) delta.Y);
photo.ViewOffset = Vector2i.Add(photo.ViewOffset, imageDelta);
Console.WriteLine("+++ " + photo.ViewOffset);
}
return ToolStatus.Active;
@ -129,7 +135,7 @@ public class CropTool : ITool {
mouseDragEnd = new(photo.CropRectangle.Right, photo.CropRectangle.Bottom);
}
public ToolStatus HandleInput(KeyboardState input, MouseState mouse, Transform transform, Game game, Photo photo) {
public ToolStatus HandleInput(KeyboardState input, MouseState mouse, Transform transform, Game game, Photo photo, UiGeometry geometry) {
Vector2i mousePosition = (Vector2i) mouse.Position;
Vector2i imagePosition = transform.ScreenToImage(mousePosition);
@ -630,7 +636,7 @@ public class Game : GameWindow {
// Delegate input to the active tool.
ToolStatus status = activeTool.HandleInput(
KeyboardState, MouseState, transform, this, photos[photoIndex]);
KeyboardState, MouseState, transform, this, photos[photoIndex], geometry);
// Change back to the default tool if the active tool is done.
if (status != ToolStatus.Active) {