Browse Source

Re-added arrow key adjustment during drags.

naelstrof 7 years ago
parent
commit
ccb020ce29
3 changed files with 32 additions and 4 deletions
  1. 11
    4
      src/slop.cpp
  2. 18
    0
      src/slopstates.cpp
  3. 3
    0
      src/slopstates.hpp

+ 11
- 4
src/slop.cpp View File

@@ -126,13 +126,17 @@ slop::SlopSelection slop::XShapeSlopSelect( slop::SlopOptions* options, bool* ca
126 126
     // We have no GL context, so the matrix is useless...
127 127
     glm::mat4 fake;
128 128
     // This is where we'll run through all of our stuffs
129
+    auto last = std::chrono::high_resolution_clock::now();
129 130
     while( memory.running ) {
130 131
         slop::mouse->update();
131 132
         if ( !options->nokeyboard ) {
132 133
             slop::keyboard->update();
133 134
         }
134 135
         // We move our statemachine forward.
135
-        memory.update( 1 );
136
+        auto current = std::chrono::high_resolution_clock::now();
137
+        std::chrono::duration<double, std::milli> frametime = current-last;
138
+        last = current;
139
+        memory.update( frametime.count()/1000.f );
136 140
 
137 141
         // We don't actually draw anything, but the state machine uses
138 142
         // this to know when to spawn the window.
@@ -189,13 +193,17 @@ slop::SlopSelection slop::GLSlopSelect( slop::SlopOptions* options, bool* cancel
189 193
 
190 194
     // This is where we'll run through all of our stuffs
191 195
     auto start = std::chrono::high_resolution_clock::now();
196
+    auto last = start;
192 197
     while( memory.running ) {
193 198
         slop::mouse->update();
194 199
         if ( !options->nokeyboard ) {
195 200
             slop::keyboard->update();
196 201
         }
197 202
         // We move our statemachine forward.
198
-        memory.update( 1 );
203
+        auto current = std::chrono::high_resolution_clock::now();
204
+        std::chrono::duration<double, std::milli> frametime = current-last;
205
+        last = current;
206
+        memory.update( frametime.count()/1000.f );
199 207
 
200 208
         // Then we draw our junk to a framebuffer.
201 209
         window->framebuffer->setShader( textured );
@@ -205,8 +213,7 @@ slop::SlopSelection slop::GLSlopSelect( slop::SlopOptions* options, bool* cancel
205 213
         memory.draw( window->camera );
206 214
         window->framebuffer->unbind();
207 215
 
208
-        auto end = std::chrono::high_resolution_clock::now();
209
-        std::chrono::duration<double, std::milli> elapsed = end-start;
216
+        std::chrono::duration<double, std::milli> elapsed = current-start;
210 217
         if ( shaders.size() > 1 ) {
211 218
             int i;
212 219
             // We have our clean buffer, now to slather it with some juicy shader chains.

+ 18
- 0
src/slopstates.cpp View File

@@ -88,6 +88,8 @@ slop::SlopStartDrag::SlopStartDrag( glm::vec2 point ) {
88 88
 
89 89
 void slop::SlopStartDrag::onEnter( SlopMemory& memory ) {
90 90
     memory.rectangle->setPoints(startPoint, startPoint);
91
+    repeatTimer = 0;
92
+    multiplier = 1;
91 93
 }
92 94
 
93 95
 void slop::SlopStartDrag::update( SlopMemory& memory, double dt ) {
@@ -113,6 +115,22 @@ void slop::SlopStartDrag::update( SlopMemory& memory, double dt ) {
113 115
     if ( !mouse->getButton( 1 ) ) {
114 116
         memory.setState( (SlopState*)new SlopEndDrag() );
115 117
     }
118
+    int arrows[2];
119
+    arrows[0] = keyboard->getKey(XK_Down)-keyboard->getKey(XK_Up);
120
+    arrows[1] = keyboard->getKey(XK_Right)-keyboard->getKey(XK_Left);
121
+    if ( arrows[0] || arrows[1] ) {
122
+        if ( repeatTimer == 0 || repeatTimer > .4 ) {
123
+            startPoint.y += arrows[0]*multiplier;
124
+            startPoint.x += arrows[1]*multiplier;
125
+        }
126
+        if ( repeatTimer > 1 ) {
127
+            multiplier += dt*2;
128
+        }
129
+        repeatTimer += dt;
130
+    } else {
131
+        repeatTimer = 0;
132
+        multiplier = 1;
133
+    }
116 134
 }
117 135
 
118 136
 void slop::SlopStartDrag::draw( SlopMemory& memory, glm::mat4 matrix ) {

+ 3
- 0
src/slopstates.hpp View File

@@ -22,6 +22,7 @@
22 22
 #define N_SLOPSTATES_H_
23 23
 
24 24
 #include "mouse.hpp"
25
+#include "keyboard.hpp"
25 26
 #include "slop.hpp"
26 27
 
27 28
 #include "rectangle.hpp"
@@ -53,6 +54,8 @@ public:
53 54
 class SlopStartDrag : SlopState {
54 55
 private:
55 56
     glm::vec2 startPoint;
57
+    float repeatTimer;
58
+    float multiplier;
56 59
 public:
57 60
     SlopStartDrag( glm::vec2 point );
58 61
     virtual void onEnter( SlopMemory& memory );