don't grad the photo around unless the drag starts in the photobox
This commit is contained in:
parent
e612429298
commit
4a84774855
20
Program.cs
20
Program.cs
@ -87,20 +87,26 @@ public class Transform {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public interface ITool {
|
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();
|
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, 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;
|
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;
|
Vector2 delta = mouse.Delta;
|
||||||
Vector2i imageDelta = transform.ScreenToImageDelta((int) delta.X, (int) delta.Y);
|
Vector2i imageDelta = transform.ScreenToImageDelta((int) delta.X, (int) delta.Y);
|
||||||
photo.ViewOffset = Vector2i.Add(photo.ViewOffset, imageDelta);
|
photo.ViewOffset = Vector2i.Add(photo.ViewOffset, imageDelta);
|
||||||
Console.WriteLine("+++ " + photo.ViewOffset);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return ToolStatus.Active;
|
return ToolStatus.Active;
|
||||||
@ -129,7 +135,7 @@ 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, 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 mousePosition = (Vector2i) mouse.Position;
|
||||||
Vector2i imagePosition = transform.ScreenToImage(mousePosition);
|
Vector2i imagePosition = transform.ScreenToImage(mousePosition);
|
||||||
|
|
||||||
@ -630,7 +636,7 @@ public class Game : GameWindow {
|
|||||||
|
|
||||||
// Delegate input to the active tool.
|
// Delegate input to the active tool.
|
||||||
ToolStatus status = activeTool.HandleInput(
|
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.
|
// Change back to the default tool if the active tool is done.
|
||||||
if (status != ToolStatus.Active) {
|
if (status != ToolStatus.Active) {
|
||||||
|
Loading…
Reference in New Issue
Block a user