Skip to content

Commit

Permalink
Re-added arrow key adjustment during drags.
Browse files Browse the repository at this point in the history
  • Loading branch information
naelstrof committed May 30, 2017
1 parent dcb9364 commit ccb020c
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/slop.cpp
Expand Up @@ -126,13 +126,17 @@ slop::SlopSelection slop::XShapeSlopSelect( slop::SlopOptions* options, bool* ca
// We have no GL context, so the matrix is useless...
glm::mat4 fake;
// This is where we'll run through all of our stuffs
auto last = std::chrono::high_resolution_clock::now();
while( memory.running ) {
slop::mouse->update();
if ( !options->nokeyboard ) {
slop::keyboard->update();
}
// We move our statemachine forward.
memory.update( 1 );
auto current = std::chrono::high_resolution_clock::now();
std::chrono::duration<double, std::milli> frametime = current-last;
last = current;
memory.update( frametime.count()/1000.f );

// We don't actually draw anything, but the state machine uses
// this to know when to spawn the window.
Expand Down Expand Up @@ -189,13 +193,17 @@ slop::SlopSelection slop::GLSlopSelect( slop::SlopOptions* options, bool* cancel

// This is where we'll run through all of our stuffs
auto start = std::chrono::high_resolution_clock::now();
auto last = start;
while( memory.running ) {
slop::mouse->update();
if ( !options->nokeyboard ) {
slop::keyboard->update();
}
// We move our statemachine forward.
memory.update( 1 );
auto current = std::chrono::high_resolution_clock::now();
std::chrono::duration<double, std::milli> frametime = current-last;
last = current;
memory.update( frametime.count()/1000.f );

// Then we draw our junk to a framebuffer.
window->framebuffer->setShader( textured );
Expand All @@ -205,8 +213,7 @@ slop::SlopSelection slop::GLSlopSelect( slop::SlopOptions* options, bool* cancel
memory.draw( window->camera );
window->framebuffer->unbind();

auto end = std::chrono::high_resolution_clock::now();
std::chrono::duration<double, std::milli> elapsed = end-start;
std::chrono::duration<double, std::milli> elapsed = current-start;
if ( shaders.size() > 1 ) {
int i;
// We have our clean buffer, now to slather it with some juicy shader chains.
Expand Down
18 changes: 18 additions & 0 deletions src/slopstates.cpp
Expand Up @@ -88,6 +88,8 @@ slop::SlopStartDrag::SlopStartDrag( glm::vec2 point ) {

void slop::SlopStartDrag::onEnter( SlopMemory& memory ) {
memory.rectangle->setPoints(startPoint, startPoint);
repeatTimer = 0;
multiplier = 1;
}

void slop::SlopStartDrag::update( SlopMemory& memory, double dt ) {
Expand All @@ -113,6 +115,22 @@ void slop::SlopStartDrag::update( SlopMemory& memory, double dt ) {
if ( !mouse->getButton( 1 ) ) {
memory.setState( (SlopState*)new SlopEndDrag() );
}
int arrows[2];
arrows[0] = keyboard->getKey(XK_Down)-keyboard->getKey(XK_Up);
arrows[1] = keyboard->getKey(XK_Right)-keyboard->getKey(XK_Left);
if ( arrows[0] || arrows[1] ) {
if ( repeatTimer == 0 || repeatTimer > .4 ) {
startPoint.y += arrows[0]*multiplier;
startPoint.x += arrows[1]*multiplier;
}
if ( repeatTimer > 1 ) {
multiplier += dt*2;
}
repeatTimer += dt;
} else {
repeatTimer = 0;
multiplier = 1;
}
}

void slop::SlopStartDrag::draw( SlopMemory& memory, glm::mat4 matrix ) {
Expand Down
3 changes: 3 additions & 0 deletions src/slopstates.hpp
Expand Up @@ -22,6 +22,7 @@
#define N_SLOPSTATES_H_

#include "mouse.hpp"
#include "keyboard.hpp"
#include "slop.hpp"

#include "rectangle.hpp"
Expand Down Expand Up @@ -53,6 +54,8 @@ class SlopStart : SlopState {
class SlopStartDrag : SlopState {
private:
glm::vec2 startPoint;
float repeatTimer;
float multiplier;
public:
SlopStartDrag( glm::vec2 point );
virtual void onEnter( SlopMemory& memory );
Expand Down

0 comments on commit ccb020c

Please sign in to comment.