Browse Source

keyboard paste and other clean up, setValue/getValue

master
Odilitime 4 years ago
parent
commit
5fcace28f7
1 changed files with 49 additions and 31 deletions
  1. 49
    31
      src/graphics/opengl/Window.cpp

+ 49
- 31
src/graphics/opengl/Window.cpp View File

@@ -366,6 +366,7 @@ bool Window::initGLFW() {
});
glfwSetScrollCallback(window, [](GLFWwindow *win, double xOffset, double yOffset) {
Window *thiz = reinterpret_cast<Window*>(glfwGetWindowUserPointer(win));
//std::cout << "glfwSetScrollCallback " << yOffset << " int" << (int)(yOffset * 10) << std::endl;
// yOffset is a delta vector
thiz->transformMatrix[13] += -yOffset * 0.1;
if (thiz->hoverComponent) {
@@ -448,13 +449,13 @@ bool Window::initGLFW() {
}
});

// works with utf-32 but we'll lkeep the low level for now
/*
// works with utf-32 and os keyboard layout but we'll lkeep the low level for now
glfwSetCharCallback(window, [](GLFWwindow* win, unsigned int codepoint) {
Window *thiz = reinterpret_cast<Window*>(glfwGetWindowUserPointer(win));
std::cout << "Window::glfwSetCharCallback - codepoint: " << codepoint << std::endl;
//std::cout << "Window::glfwSetCharCallback - codepoint: " << codepoint << std::endl;
// should be used for inputComponent
});
*/

glfwSetKeyCallback(window, [](GLFWwindow *win, int key, int scancode, int action, int mods) {
Window *thiz = reinterpret_cast<Window*>(glfwGetWindowUserPointer(win));
@@ -503,42 +504,59 @@ bool Window::initGLFW() {
if (inputComponent) {
//std::cout << "inputComponent is focsued, key pressed " << key << " action: " <<action << std::endl;
// action 1 is down, 0 is up, 2 is a repeat
if (action == 0 || action == 2) {
if (action == GLFW_RELEASE || action == GLFW_REPEAT) {
if (key == GLFW_KEY_V && action == GLFW_RELEASE && mods == attentionMod) {
const char* clipBoard = glfwGetClipboardString(thiz->window);
for(int i=0; i < strlen(clipBoard); i++) {
inputComponent->addChar(clipBoard[i]);
}
//inputComponent->setValue(std::string(clipBoard));
return;
}
// key up
// it's always uppercase...
if (key == 259) {
inputComponent->backSpace();
} else if (key == 257) {
return;
}
if (key == 257) {
std::cout << "enter!" << std::endl;
if (inputComponent->onEnter) {
inputComponent->onEnter(inputComponent->value);
inputComponent->onEnter(inputComponent->getValue());
}
} else {
if (key < 256) {
if (mods & GLFW_MOD_SHIFT) {
// SHIFT
if (key == GLFW_KEY_SLASH) key='?';
if (key == GLFW_KEY_APOSTROPHE) key='"';
if (key == GLFW_KEY_COMMA) key='<';
if (key == GLFW_KEY_MINUS) key='_';
if (key == GLFW_KEY_PERIOD) key='>';
if (key == GLFW_KEY_SEMICOLON) key=':';
if (key == GLFW_KEY_EQUAL) key='+';
if (key == GLFW_KEY_LEFT_BRACKET) key='{';
if (key == GLFW_KEY_BACKSLASH) key='|';
if (key == GLFW_KEY_RIGHT_BRACKET) key='}';
if (key == GLFW_KEY_GRAVE_ACCENT) key='~';

} else {
// no shift or caplocks
// basically: when SHIFT isn't pressed but key is in A-Z range, add ascii offset to make it lower case
if (key >= 'A' && key <= 'Z') {
key += 'a' - 'A';
}
return;
}
if (key < 256) {
if (mods & GLFW_MOD_SHIFT) {
// SHIFT
if (key >= '1' && key <= '9') {
key -= 16;
}
switch(key) {
case GLFW_KEY_SLASH: key='?'; break;
case GLFW_KEY_APOSTROPHE: key='"'; break;
case GLFW_KEY_COMMA: key='<'; break;
case GLFW_KEY_MINUS: key='_'; break;
case GLFW_KEY_PERIOD: key='>'; break;
case GLFW_KEY_SEMICOLON: key=':'; break;
case GLFW_KEY_EQUAL: key='+'; break;
case GLFW_KEY_LEFT_BRACKET: key='{'; break;
case GLFW_KEY_BACKSLASH: key='|'; break;
case GLFW_KEY_RIGHT_BRACKET: key='}'; break;
case GLFW_KEY_GRAVE_ACCENT: key='~'; break;
case GLFW_KEY_0: key=')'; break;
}
inputComponent->addChar(key);
} // otherwise I think it's some weird control char
} else {
// no shift or caplocks
// basically: when SHIFT isn't pressed but key is in A-Z range, add ascii offset to make it lower case
if (key >= 'A' && key <= 'Z') {
key += 'a' - 'A';
}
}
inputComponent->addChar(key);
return;
}
// otherwise I think it's some weird control char
}
return;
}

Loading…
Cancel
Save