Browse Source

Add windowIsKeyPressed() function

pull/720/head
luckyxxl 7 years ago
parent
commit
3120cd9695
6 changed files with 11 additions and 10 deletions
  1. +1
    -0
      include/window.hpp
  2. +0
    -2
      src/app/Knob.cpp
  3. +2
    -2
      src/app/ModuleWidget.cpp
  4. +4
    -4
      src/ui/ScrollWidget.cpp
  5. +0
    -2
      src/ui/TextField.cpp
  6. +4
    -0
      src/window.cpp

+ 1
- 0
include/window.hpp View File

@@ -38,6 +38,7 @@ void windowCursorLock();
void windowCursorUnlock();
bool windowIsModPressed();
bool windowIsShiftPressed();
bool windowIsKeyPressed(int key);
Vec windowGetWindowSize();
void windowSetWindowSize(Vec size);
Vec windowGetWindowPos();


+ 0
- 2
src/app/Knob.cpp View File

@@ -1,8 +1,6 @@
#include "app.hpp"
#include "window.hpp"
#include "engine.hpp"
// For GLFW_KEY_LEFT_CONTROL, etc.
#include <GLFW/glfw3.h>


namespace rack {


+ 2
- 2
src/app/ModuleWidget.cpp View File

@@ -219,7 +219,7 @@ void ModuleWidget::onMouseMove(EventMouseMove &e) {
// Don't delete the ModuleWidget if a TextField is focused
if (!gFocusedWidget) {
// Instead of checking key-down events, delete the module even if key-repeat hasn't fired yet and the cursor is hovering over the widget.
if (glfwGetKey(gWindow, GLFW_KEY_DELETE) == GLFW_PRESS || glfwGetKey(gWindow, GLFW_KEY_BACKSPACE) == GLFW_PRESS) {
if (windowIsKeyPressed(GLFW_KEY_DELETE) || windowIsKeyPressed(GLFW_KEY_BACKSPACE)) {
if (!windowIsModPressed() && !windowIsShiftPressed()) {
gRackWidget->deleteModule(this);
this->finalizeEvents();
@@ -350,4 +350,4 @@ Menu *ModuleWidget::createContextMenu() {
}


} // namespace rack
} // namespace rack

+ 4
- 4
src/ui/ScrollWidget.cpp View File

@@ -68,16 +68,16 @@ void ScrollWidget::onMouseMove(EventMouseMove &e) {
else if (windowIsModPressed())
arrowSpeed /= 4.0;

if (glfwGetKey(gWindow, GLFW_KEY_LEFT) == GLFW_PRESS) {
if (windowIsKeyPressed(GLFW_KEY_LEFT)) {
offset.x -= arrowSpeed;
}
if (glfwGetKey(gWindow, GLFW_KEY_RIGHT) == GLFW_PRESS) {
if (windowIsKeyPressed(GLFW_KEY_RIGHT)) {
offset.x += arrowSpeed;
}
if (glfwGetKey(gWindow, GLFW_KEY_UP) == GLFW_PRESS) {
if (windowIsKeyPressed(GLFW_KEY_UP)) {
offset.y -= arrowSpeed;
}
if (glfwGetKey(gWindow, GLFW_KEY_DOWN) == GLFW_PRESS) {
if (windowIsKeyPressed(GLFW_KEY_DOWN)) {
offset.y += arrowSpeed;
}
}


+ 0
- 2
src/ui/TextField.cpp View File

@@ -1,8 +1,6 @@
#include "ui.hpp"
// for gVg
#include "window.hpp"
// for key codes
#include <GLFW/glfw3.h>


namespace rack {


+ 4
- 0
src/window.cpp View File

@@ -516,6 +516,10 @@ bool windowIsShiftPressed() {
return glfwGetKey(gWindow, GLFW_KEY_LEFT_SHIFT) == GLFW_PRESS || glfwGetKey(gWindow, GLFW_KEY_RIGHT_SHIFT) == GLFW_PRESS;
}

bool windowIsKeyPressed(int key) {
return glfwGetKey(gWindow, key) == GLFW_PRESS;
}

Vec windowGetWindowSize() {
int width, height;
glfwGetWindowSize(gWindow, &width, &height);


Loading…
Cancel
Save