Browse Source

Revert "Use GLFW sticky key implementation"

This reverts commit a5dac7d877.
tags/v0.6.1
Andrew Belt 7 years ago
parent
commit
d6d1df0930
1 changed files with 24 additions and 3 deletions
  1. +24
    -3
      src/window.cpp

+ 24
- 3
src/window.cpp View File

@@ -129,6 +129,28 @@ void mouseButtonCallback(GLFWwindow *window, int button, int action, int mods) {
} }
} }


struct MouseButtonArguments {
GLFWwindow *window;
int button;
int action;
int mods;
};

static std::queue<MouseButtonArguments> mouseButtonQueue;
void mouseButtonStickyPop() {
if (!mouseButtonQueue.empty()) {
MouseButtonArguments args = mouseButtonQueue.front();
mouseButtonQueue.pop();
mouseButtonCallback(args.window, args.button, args.action, args.mods);
}
}

void mouseButtonStickyCallback(GLFWwindow *window, int button, int action, int mods) {
// Defer multiple clicks per frame to future frames
MouseButtonArguments args = {window, button, action, mods};
mouseButtonQueue.push(args);
}

void cursorPosCallback(GLFWwindow* window, double xpos, double ypos) { void cursorPosCallback(GLFWwindow* window, double xpos, double ypos) {
Vec mousePos = Vec(xpos, ypos).div(gPixelRatio / gWindowRatio).round(); Vec mousePos = Vec(xpos, ypos).div(gPixelRatio / gWindowRatio).round();
Vec mouseRel = mousePos.minus(gMousePos); Vec mouseRel = mousePos.minus(gMousePos);
@@ -333,12 +355,10 @@ void windowInit() {


glfwSwapInterval(1); glfwSwapInterval(1);


glfwSetInputMode(gWindow, GLFW_STICKY_MOUSE_BUTTONS, 1);
glfwSetInputMode(gWindow, GLFW_STICKY_KEYS, 1);
glfwSetInputMode(gWindow, GLFW_LOCK_KEY_MODS, 1); glfwSetInputMode(gWindow, GLFW_LOCK_KEY_MODS, 1);


glfwSetWindowSizeCallback(gWindow, windowSizeCallback); glfwSetWindowSizeCallback(gWindow, windowSizeCallback);
glfwSetMouseButtonCallback(gWindow, mouseButtonCallback);
glfwSetMouseButtonCallback(gWindow, mouseButtonStickyCallback);
// Call this ourselves, but on every frame instead of only when the mouse moves // Call this ourselves, but on every frame instead of only when the mouse moves
// glfwSetCursorPosCallback(gWindow, cursorPosCallback); // glfwSetCursorPosCallback(gWindow, cursorPosCallback);
glfwSetCursorEnterCallback(gWindow, cursorEnterCallback); glfwSetCursorEnterCallback(gWindow, cursorEnterCallback);
@@ -424,6 +444,7 @@ void windowRun() {
glfwGetCursorPos(gWindow, &xpos, &ypos); glfwGetCursorPos(gWindow, &xpos, &ypos);
cursorPosCallback(gWindow, xpos, ypos); cursorPosCallback(gWindow, xpos, ypos);
} }
mouseButtonStickyPop();
gamepadStep(); gamepadStep();


// Set window title // Set window title


Loading…
Cancel
Save