Pārlūkot izejas kodu

Re-added arrow key adjustment during drags.

naelstrof 7 gadus atpakaļ
vecāks
revīzija
ccb020ce29
3 mainītis faili ar 32 papildinājumiem un 4 dzēšanām
  1. 11
    4
      src/slop.cpp
  2. 18
    0
      src/slopstates.cpp
  3. 3
    0
      src/slopstates.hpp

+ 11
- 4
src/slop.cpp Parādīt failu

126
     // We have no GL context, so the matrix is useless...
126
     // We have no GL context, so the matrix is useless...
127
     glm::mat4 fake;
127
     glm::mat4 fake;
128
     // This is where we'll run through all of our stuffs
128
     // This is where we'll run through all of our stuffs
129
+    auto last = std::chrono::high_resolution_clock::now();
129
     while( memory.running ) {
130
     while( memory.running ) {
130
         slop::mouse->update();
131
         slop::mouse->update();
131
         if ( !options->nokeyboard ) {
132
         if ( !options->nokeyboard ) {
132
             slop::keyboard->update();
133
             slop::keyboard->update();
133
         }
134
         }
134
         // We move our statemachine forward.
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
         // We don't actually draw anything, but the state machine uses
141
         // We don't actually draw anything, but the state machine uses
138
         // this to know when to spawn the window.
142
         // this to know when to spawn the window.
189
 
193
 
190
     // This is where we'll run through all of our stuffs
194
     // This is where we'll run through all of our stuffs
191
     auto start = std::chrono::high_resolution_clock::now();
195
     auto start = std::chrono::high_resolution_clock::now();
196
+    auto last = start;
192
     while( memory.running ) {
197
     while( memory.running ) {
193
         slop::mouse->update();
198
         slop::mouse->update();
194
         if ( !options->nokeyboard ) {
199
         if ( !options->nokeyboard ) {
195
             slop::keyboard->update();
200
             slop::keyboard->update();
196
         }
201
         }
197
         // We move our statemachine forward.
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
         // Then we draw our junk to a framebuffer.
208
         // Then we draw our junk to a framebuffer.
201
         window->framebuffer->setShader( textured );
209
         window->framebuffer->setShader( textured );
205
         memory.draw( window->camera );
213
         memory.draw( window->camera );
206
         window->framebuffer->unbind();
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
         if ( shaders.size() > 1 ) {
217
         if ( shaders.size() > 1 ) {
211
             int i;
218
             int i;
212
             // We have our clean buffer, now to slather it with some juicy shader chains.
219
             // We have our clean buffer, now to slather it with some juicy shader chains.

+ 18
- 0
src/slopstates.cpp Parādīt failu

88
 
88
 
89
 void slop::SlopStartDrag::onEnter( SlopMemory& memory ) {
89
 void slop::SlopStartDrag::onEnter( SlopMemory& memory ) {
90
     memory.rectangle->setPoints(startPoint, startPoint);
90
     memory.rectangle->setPoints(startPoint, startPoint);
91
+    repeatTimer = 0;
92
+    multiplier = 1;
91
 }
93
 }
92
 
94
 
93
 void slop::SlopStartDrag::update( SlopMemory& memory, double dt ) {
95
 void slop::SlopStartDrag::update( SlopMemory& memory, double dt ) {
113
     if ( !mouse->getButton( 1 ) ) {
115
     if ( !mouse->getButton( 1 ) ) {
114
         memory.setState( (SlopState*)new SlopEndDrag() );
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
 void slop::SlopStartDrag::draw( SlopMemory& memory, glm::mat4 matrix ) {
136
 void slop::SlopStartDrag::draw( SlopMemory& memory, glm::mat4 matrix ) {

+ 3
- 0
src/slopstates.hpp Parādīt failu

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