Przeglądaj źródła

added grace period for keypresses

naelstrof 10 lat temu
rodzic
commit
c6fdf5ef90
1 zmienionych plików z 14 dodań i 8 usunięć
  1. 14
    8
      main.cpp

+ 14
- 8
main.cpp Wyświetl plik

@@ -20,6 +20,7 @@ int main( int argc, char** argv ) {
20 20
     float r = options->m_red;
21 21
     float g = options->m_green;
22 22
     float b = options->m_blue;
23
+    timespec start,time;
23 24
 
24 25
     // First we set up the x interface and grab the mouse,
25 26
     // if we fail for either we exit immediately.
@@ -35,18 +36,23 @@ int main( int argc, char** argv ) {
35 36
     if ( err ) {
36 37
         return err;
37 38
     }
39
+    clock_gettime( CLOCK_REALTIME, &start );
38 40
     while ( running ) {
41
+        clock_gettime( CLOCK_REALTIME, &time );
39 42
         // "ticking" the xengine makes it process all queued events.
40 43
         xengine->tick();
41 44
         // If the user presses any key on the keyboard, exit the application.
42
-        if ( xengine->m_keypressed ) {
43
-            printf( "X=0\n" );
44
-            printf( "Y=0\n" );
45
-            printf( "W=0\n" );
46
-            printf( "H=0\n" );
47
-            fprintf( stderr, "User pressed key. Canceled selection.\n" );
48
-            state = -1;
49
-            running = false;
45
+        // Make sure a second has passed before allowing canceling
46
+        if ( time.tv_sec - start.tv_sec > 1 ) {
47
+            if ( xengine->m_keypressed ) {
48
+                printf( "X=0\n" );
49
+                printf( "Y=0\n" );
50
+                printf( "W=0\n" );
51
+                printf( "H=0\n" );
52
+                fprintf( stderr, "User pressed key. Canceled selection.\n" );
53
+                state = -1;
54
+                running = false;
55
+            }
50 56
         }
51 57
         if ( xengine->mouseDown( 3 ) ) {
52 58
             printf( "X=0\n" );