Make Widgets clickable

This commit is contained in:
2021-01-16 21:58:42 +01:00
parent 7e9702431f
commit f187a25e9e
13 changed files with 156 additions and 30 deletions

View File

@@ -2,8 +2,9 @@
#include <iostream>
bool EventHandler::cameraActionRegister[CAMERA_ACTION_NUM_ITEMS] = {0};
double EventHandler::cameraMouseActionRegister[CAMERA_MOUSE_ACTION_NUM_ITEMS] = {0.0, 0.0};
bool EventHandler::cameraActionRegister[CAMERA_ACTION_NUM_ITEMS] = {0};
bool EventHandler::mouseButtonActionRegister[MOUSE_BUTTON_ACTION_NUM_ITEMS] = {0};
bool EventHandler::windowActionRegister[WINDOW_ACTION_NUM_ITEMS] = {0};
bool EventHandler::firstMouseInput = 1;
@@ -15,6 +16,7 @@ EventHandler::EventHandler(GLFWwindow *p_window) :
{
glfwSetKeyCallback(window, key_callback);
glfwSetCursorPosCallback(window, mouse_callback);
glfwSetMouseButtonCallback(window, mouse_button_callback);
}
void EventHandler::handleEvents()
@@ -28,6 +30,7 @@ void EventHandler::clearActionRegisters()
//std::fill_n(cameraActionRegister, CAMERA_ACTION_NUM_ITEMS, 0);
std::fill_n(cameraMouseActionRegister, CAMERA_MOUSE_ACTION_NUM_ITEMS, 0.0);
std::fill_n(windowActionRegister, WINDOW_ACTION_NUM_ITEMS, 0);
std::fill_n(mouseButtonActionRegister, MOUSE_BUTTON_ACTION_NUM_ITEMS, 0);
}
void EventHandler::key_callback(GLFWwindow *window, int key, int scancode, int action, int mods)
@@ -42,51 +45,51 @@ void EventHandler::key_callback(GLFWwindow *window, int key, int scancode, int a
}
if (key == GLFW_KEY_O && action == GLFW_PRESS) {
windowActionRegister[wireFrameToggle] = 1;
windowActionRegister[windowActions::wireFrameToggle] = 1;
}
if (key == GLFW_KEY_LEFT_CONTROL && action == GLFW_PRESS) {
windowActionRegister[mouseCatchToggle] = 1;
windowActionRegister[windowActions::mouseCatchToggle] = 1;
firstMouseInput = 1;
}
// Movement press
if (key == GLFW_KEY_W && action == GLFW_PRESS) {
cameraActionRegister[cameraForward] = 1;
cameraActionRegister[cameraActions::cameraForward] = 1;
}
if (key == GLFW_KEY_S && action == GLFW_PRESS) {
cameraActionRegister[cameraBackward] = 1;
cameraActionRegister[cameraActions::cameraBackward] = 1;
}
if (key == GLFW_KEY_SPACE && action == GLFW_PRESS) {
cameraActionRegister[cameraUp] = 1;
cameraActionRegister[cameraActions::cameraUp] = 1;
}
if (key == GLFW_KEY_LEFT_SHIFT && action == GLFW_PRESS) {
cameraActionRegister[cameraDown] = 1;
cameraActionRegister[cameraActions::cameraDown] = 1;
}
if (key == GLFW_KEY_A && action == GLFW_PRESS) {
cameraActionRegister[cameraLeft] = 1;
cameraActionRegister[cameraActions::cameraLeft] = 1;
}
if (key == GLFW_KEY_D && action == GLFW_PRESS) {
cameraActionRegister[cameraRight] = 1;
cameraActionRegister[cameraActions::cameraRight] = 1;
}
// Movement release
if (key == GLFW_KEY_W && action == GLFW_RELEASE) {
cameraActionRegister[cameraForward] = 0;
cameraActionRegister[cameraActions::cameraForward] = 0;
}
if (key == GLFW_KEY_S && action == GLFW_RELEASE) {
cameraActionRegister[cameraBackward] = 0;
cameraActionRegister[cameraActions::cameraBackward] = 0;
}
if (key == GLFW_KEY_SPACE && action == GLFW_RELEASE) {
cameraActionRegister[cameraUp] = 0;
cameraActionRegister[cameraActions::cameraUp] = 0;
}
if (key == GLFW_KEY_LEFT_SHIFT && action == GLFW_RELEASE) {
cameraActionRegister[cameraDown] = 0;
cameraActionRegister[cameraActions::cameraDown] = 0;
}
if (key == GLFW_KEY_A && action == GLFW_RELEASE) {
cameraActionRegister[cameraLeft] = 0;
cameraActionRegister[cameraActions::cameraLeft] = 0;
}
if (key == GLFW_KEY_D && action == GLFW_RELEASE) {
cameraActionRegister[cameraRight] = 0;
cameraActionRegister[cameraActions::cameraRight] = 0;
}
}
@@ -113,8 +116,20 @@ void EventHandler::mouse_callback(GLFWwindow *window, double xpos, double ypos)
deltaCursorPosX *= mouseSensitivity;
deltaCursorPosY *= mouseSensitivity;
cameraMouseActionRegister[cameraMouseDeltaX] += deltaCursorPosX;
cameraMouseActionRegister[cameraMouseDeltaY] += deltaCursorPosY;
cameraMouseActionRegister[cameraMouseActions::cameraMouseDeltaX] += deltaCursorPosX;
cameraMouseActionRegister[cameraMouseActions::cameraMouseDeltaY] += deltaCursorPosY;
}
void EventHandler::mouse_button_callback(GLFWwindow* window, int button, int action, int mods)
{
(void) window; (void) mods;
if (button == GLFW_MOUSE_BUTTON_LEFT && action == GLFW_PRESS)
mouseButtonActionRegister[mouseButtonActions::leftClicked] = true;
if (button == GLFW_MOUSE_BUTTON_RIGHT && action == GLFW_PRESS)
mouseButtonActionRegister[mouseButtonActions::rightClicked] = true;
if (button == GLFW_MOUSE_BUTTON_MIDDLE && action == GLFW_PRESS)
mouseButtonActionRegister[mouseButtonActions::middleClicked] = true;
}
bool * EventHandler::getCameraActionRegister()
@@ -127,6 +142,11 @@ bool * EventHandler::getWindowActionRegister()
return windowActionRegister;
}
bool * EventHandler::getMouseButtonActionRegister()
{
return mouseButtonActionRegister;
}
double * EventHandler::getCursorDelta()
{
return cameraMouseActionRegister;