allow mouse forward/back buttons to advance photoIndex. simplify photoIndex logic a bit

This commit is contained in:
Colin McMillen 2023-07-25 18:38:21 -04:00
parent 3cf125fba7
commit 50445dbe59

View File

@ -487,16 +487,6 @@ public class Game : GameWindow {
Close(); Close();
} }
// Look for mouse clicks on thumbnails.
if (MouseState.IsButtonPressed(0)) {
for (int i = 0; i < geometry.ThumbnailBoxes.Count; i++) {
Box2i box = geometry.ThumbnailBoxes[i];
if (box.ContainsInclusive((Vector2i) MouseState.Position)) {
photoIndex = Math.Clamp(ribbonIndex + i, 0, photos.Count - 1);
}
}
}
// Track keyboard repeat times for advancing up/down. // Track keyboard repeat times for advancing up/down.
if (!input.IsKeyDown(Keys.Down)) { if (!input.IsKeyDown(Keys.Down)) {
downTimer = Int64.MaxValue; downTimer = Int64.MaxValue;
@ -506,6 +496,48 @@ public class Game : GameWindow {
upTimer = Int64.MaxValue; upTimer = Int64.MaxValue;
} }
// Look for mouse clicks on thumbnails.
//
// Note that we don't bounds-check photoIndex until after all the possible
// inputs that might affect it. That simplifies this logic significantly.
if (MouseState.IsButtonPressed(MouseButton.Button1)) {
for (int i = 0; i < geometry.ThumbnailBoxes.Count; i++) {
Box2i box = geometry.ThumbnailBoxes[i];
if (box.ContainsInclusive((Vector2i) MouseState.Position)) {
photoIndex = ribbonIndex + i;
}
}
}
if (MouseState.IsButtonPressed(MouseButton.Button4)) {
photoIndex--;
}
if (MouseState.IsButtonPressed(MouseButton.Button5)) {
photoIndex++;
}
if (MouseState.ScrollDelta.Y < 0) {
photoIndex++;
}
if (MouseState.ScrollDelta.Y > 0) {
photoIndex--;
}
// FIXME: make a proper Model class for tracking the state of the controls?
if (input.IsKeyPressed(Keys.Down) || now > downTimer) {
downTimer = now + 10000 * 200;
photoIndex++;
}
if (input.IsKeyPressed(Keys.Up) || now > upTimer) {
upTimer = now + 10000 * 200;
photoIndex--;
}
// Make sure the photoIndex is actually valid.
photoIndex = Math.Clamp(photoIndex, 0, photos.Count - 1);
if (input.IsKeyDown(Keys.D0) || input.IsKeyDown(Keys.GraveAccent)) { if (input.IsKeyDown(Keys.D0) || input.IsKeyDown(Keys.GraveAccent)) {
zoomLevel = 0f; zoomLevel = 0f;
} }
@ -529,20 +561,6 @@ public class Game : GameWindow {
if (input.IsKeyDown(Keys.D5)) { if (input.IsKeyDown(Keys.D5)) {
zoomLevel = 16f; zoomLevel = 16f;
} }
// FIXME: make a proper Model class for tracking the state of the controls?
if (input.IsKeyPressed(Keys.Down) || now > downTimer) {
if (photoIndex < photos.Count - 1) {
downTimer = now + 10000 * 200;
photoIndex++;
}
}
if (input.IsKeyPressed(Keys.Up) || now > upTimer) {
if (photoIndex > 0) {
upTimer = now + 10000 * 200;
photoIndex--;
}
}
} }
protected override async void OnLoad() { protected override async void OnLoad() {