Browse Source

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

main
Colin McMillen 12 months ago
parent
commit
50445dbe59
  1. 60
      Program.cs

60
Program.cs

@ -487,25 +487,57 @@ public class Game : GameWindow {
Close();
}
// Track keyboard repeat times for advancing up/down.
if (!input.IsKeyDown(Keys.Down)) {
downTimer = Int64.MaxValue;
}
if (!input.IsKeyDown(Keys.Up)) {
upTimer = Int64.MaxValue;
}
// Look for mouse clicks on thumbnails.
if (MouseState.IsButtonPressed(0)) {
//
// 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 = Math.Clamp(ribbonIndex + i, 0, photos.Count - 1);
photoIndex = ribbonIndex + i;
}
}
}
// Track keyboard repeat times for advancing up/down.
if (!input.IsKeyDown(Keys.Down)) {
downTimer = Int64.MaxValue;
if (MouseState.IsButtonPressed(MouseButton.Button4)) {
photoIndex--;
}
if (!input.IsKeyDown(Keys.Up)) {
upTimer = Int64.MaxValue;
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)) {
zoomLevel = 0f;
}
@ -529,20 +561,6 @@ public class Game : GameWindow {
if (input.IsKeyDown(Keys.D5)) {
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() {

Loading…
Cancel
Save