remove keyboard autorepeat and change IsKeyDown -> IsKeyPressed

This commit is contained in:
Colin McMillen 2023-07-26 16:57:32 -04:00
parent 42ea309794
commit 067b54a77d

View File

@ -551,10 +551,6 @@ public class Game : GameWindow {
UiGeometry geometry = new();
FpsCounter fpsCounter = new();
// Input handling.
long downTimer = Int64.MaxValue;
long upTimer = Int64.MaxValue;
// Four points, each consisting of (x, y, z, tex_x, tex_y).
float[] vertices = new float[20];
@ -577,25 +573,15 @@ public class Game : GameWindow {
protected override void OnUpdateFrame(FrameEventArgs e) {
base.OnUpdateFrame(e);
long now = DateTime.Now.Ticks;
KeyboardState input = KeyboardState;
// FIXME: add a confirm dialog before closing. (Also for the window-close button.)
// Close when Escape is pressed.
if (input.IsKeyDown(Keys.Escape)) {
if (input.IsKeyPressed(Keys.Escape)) {
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 or stars.
//
// Note that we don't bounds-check photoIndex until after all the possible
@ -632,13 +618,10 @@ public class Game : GameWindow {
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;
if (input.IsKeyPressed(Keys.Down)) {
photoIndex++;
}
if (input.IsKeyPressed(Keys.Up) || now > upTimer) {
upTimer = now + 10000 * 200;
if (input.IsKeyPressed(Keys.Up)) {
photoIndex--;
}
@ -651,61 +634,61 @@ public class Game : GameWindow {
}
if (input.IsKeyPressed(Keys.PageDown)) {
photoIndex += 10;
photoIndex += 5;
}
if (input.IsKeyPressed(Keys.PageUp)) {
photoIndex -= 10;
photoIndex -= 5;
}
// 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.IsKeyPressed(Keys.D0) || input.IsKeyPressed(Keys.GraveAccent)) {
photos[photoIndex].Rating = 0;
}
if (input.IsKeyDown(Keys.D1)) {
if (input.IsKeyPressed(Keys.D1)) {
photos[photoIndex].Rating = 1;
}
if (input.IsKeyDown(Keys.D2)) {
if (input.IsKeyPressed(Keys.D2)) {
photos[photoIndex].Rating = 2;
}
if (input.IsKeyDown(Keys.D3)) {
if (input.IsKeyPressed(Keys.D3)) {
photos[photoIndex].Rating = 3;
}
if (input.IsKeyDown(Keys.D4)) {
if (input.IsKeyPressed(Keys.D4)) {
photos[photoIndex].Rating = 4;
}
if (input.IsKeyDown(Keys.D5)) {
if (input.IsKeyPressed(Keys.D5)) {
photos[photoIndex].Rating = 5;
}
if (input.IsKeyDown(Keys.Q)) {
if (input.IsKeyPressed(Keys.Q)) {
zoomLevel = 0f;
}
if (input.IsKeyDown(Keys.W)) {
if (input.IsKeyPressed(Keys.W)) {
zoomLevel = 1f;
}
if (input.IsKeyDown(Keys.E)) {
if (input.IsKeyPressed(Keys.E)) {
zoomLevel = 2f;
}
if (input.IsKeyDown(Keys.R)) {
if (input.IsKeyPressed(Keys.R)) {
zoomLevel = 4f;
}
if (input.IsKeyDown(Keys.T)) {
if (input.IsKeyPressed(Keys.T)) {
zoomLevel = 8f;
}
if (input.IsKeyDown(Keys.Y)) {
if (input.IsKeyPressed(Keys.Y)) {
zoomLevel = 16f;
}
}
@ -749,10 +732,10 @@ public class Game : GameWindow {
// Load photos from a directory.
// 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(@"G:\DCIM\100EOSR6\");
// string[] files = Directory.GetFiles(@"G:\DCIM\100EOSR6\");
// 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\many-birds\");
string[] files = Directory.GetFiles(@"C:\Users\colin\Desktop\many-birds\");
for (int i = 0; i < files.Count(); i++) {
string file = files[i];