Move callbacks ti InputData
This commit is contained in:
parent
bdfa5f16dd
commit
8acf6ec363
@ -180,7 +180,7 @@ int start() {
|
|||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
glViewport(0, 0, kekData.screenWidth, kekData.screenHeight);
|
glViewport(0, 0, kekData.screenWidth, kekData.screenHeight);
|
||||||
|
|
||||||
for(std::pair<InputListener, PeriodicCallback> cb : kekData.periodicCallbacks) {
|
for(auto cb : kekData.input->periodicCallbacks) {
|
||||||
cb.second(kekData.window);
|
cb.second(kekData.window);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@ void destroy() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void onCursorPosCallback(GLFWwindow *window, double x, double y) {
|
void onCursorPosCallback(GLFWwindow *window, double x, double y) {
|
||||||
for(auto cb : kekData.mouseCallbacks) {
|
for(auto cb : kekData.input->mouseCallbacks) {
|
||||||
cb.second(window, x, y);
|
cb.second(window, x, y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -39,7 +39,7 @@ void onKeyCallback(GLFWwindow *window, int key, int scancode, int action, int mo
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for(auto cb : kekData.keyCallbacks) {
|
for(auto cb : kekData.input->keyCallbacks) {
|
||||||
cb.second(window, key, scancode, action, mods);
|
cb.second(window, key, scancode, action, mods);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -50,65 +50,65 @@ void onKeyCharCallback(GLFWwindow *window, unsigned int codepoint) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for(auto cb : kekData.keyCharCallbacks) {
|
for(auto cb : kekData.input->keyCharCallbacks) {
|
||||||
cb.second(window, codepoint);
|
cb.second(window, codepoint);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void onMouseButtonCallback(GLFWwindow* window, int button, int action, int mods) {
|
void onMouseButtonCallback(GLFWwindow* window, int button, int action, int mods) {
|
||||||
for(auto cb : kekData.mouseButtonCallbacks) {
|
for(auto cb : kekData.input->mouseButtonCallbacks) {
|
||||||
cb.second(window, button, action, mods);
|
cb.second(window, button, action, mods);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
InputListener addPeriodicCallback(PeriodicCallback callback) {
|
InputListener addPeriodicCallback(PeriodicCallback callback) {
|
||||||
InputListener id = nextID++;
|
InputListener id = nextID++;
|
||||||
kekData.periodicCallbacks.emplace(id, callback);
|
kekData.input->periodicCallbacks.emplace(id, callback);
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
void removePeriodicCallback(InputListener listener) {
|
void removePeriodicCallback(InputListener listener) {
|
||||||
kekData.periodicCallbacks.erase(listener);
|
kekData.input->periodicCallbacks.erase(listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
InputListener addKeyListener(KeyCallback callback) {
|
InputListener addKeyListener(KeyCallback callback) {
|
||||||
InputListener id = nextID++;
|
InputListener id = nextID++;
|
||||||
kekData.keyCallbacks.emplace(id, callback);
|
kekData.input->keyCallbacks.emplace(id, callback);
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
void removeKeyListener(InputListener listener) {
|
void removeKeyListener(InputListener listener) {
|
||||||
kekData.keyCallbacks.erase(listener);
|
kekData.input->keyCallbacks.erase(listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
InputListener addKeyCharListener(KeyCharCallback callback) {
|
InputListener addKeyCharListener(KeyCharCallback callback) {
|
||||||
InputListener id = nextID++;
|
InputListener id = nextID++;
|
||||||
kekData.keyCharCallbacks.emplace(id, callback);
|
kekData.input->keyCharCallbacks.emplace(id, callback);
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
void removeKeyCharListener(InputListener listener) {
|
void removeKeyCharListener(InputListener listener) {
|
||||||
kekData.keyCharCallbacks.erase(listener);
|
kekData.input->keyCharCallbacks.erase(listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
InputListener addMouseListener(MouseCallback callback) {
|
InputListener addMouseListener(MouseCallback callback) {
|
||||||
InputListener id = nextID++;
|
InputListener id = nextID++;
|
||||||
kekData.mouseCallbacks.emplace(id, callback);
|
kekData.input->mouseCallbacks.emplace(id, callback);
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
void removeMouseListener(InputListener listener) {
|
void removeMouseListener(InputListener listener) {
|
||||||
kekData.mouseCallbacks.erase(listener);
|
kekData.input->mouseCallbacks.erase(listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
InputListener addMouseButtonListener(MouseButtonCallback callback) {
|
InputListener addMouseButtonListener(MouseButtonCallback callback) {
|
||||||
InputListener id = nextID++;
|
InputListener id = nextID++;
|
||||||
kekData.mouseButtonCallbacks.emplace(id, callback);
|
kekData.input->mouseButtonCallbacks.emplace(id, callback);
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
void removeMouseButtonListener(InputListener listener) {
|
void removeMouseButtonListener(InputListener listener) {
|
||||||
kekData.mouseButtonCallbacks.erase(listener);
|
kekData.input->mouseButtonCallbacks.erase(listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
KeyBinding createKeyBinding(std::string name, GLFWKey defaultKey) {
|
KeyBinding createKeyBinding(std::string name, GLFWKey defaultKey) {
|
||||||
@ -117,28 +117,28 @@ KeyBinding createKeyBinding(std::string name, GLFWKey defaultKey) {
|
|||||||
KeyBindingData d;
|
KeyBindingData d;
|
||||||
d.name = name;
|
d.name = name;
|
||||||
d.key = defaultKey;
|
d.key = defaultKey;
|
||||||
kekData.keyBindings.emplace(id, d);
|
kekData.input->keyBindings.emplace(id, d);
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
void reassignKeyBinding(KeyBinding binding, GLFWKey key) {
|
void reassignKeyBinding(KeyBinding binding, GLFWKey key) {
|
||||||
if(binding == KEK_INVALID_ID) return;
|
if(binding == KEK_INVALID_ID) return;
|
||||||
auto it = kekData.keyBindings.find(binding);
|
auto it = kekData.input->keyBindings.find(binding);
|
||||||
if(it == kekData.keyBindings.end()) return;
|
if(it == kekData.input->keyBindings.end()) return;
|
||||||
KeyBindingData d = it->second;
|
KeyBindingData d = it->second;
|
||||||
d.key = key;
|
d.key = key;
|
||||||
it->second = d;
|
it->second = d;
|
||||||
}
|
}
|
||||||
|
|
||||||
KeyBindingData getKeyBinding(KeyBinding binding) {
|
KeyBindingData getKeyBinding(KeyBinding binding) {
|
||||||
auto it = kekData.keyBindings.find(binding);
|
auto it = kekData.input->keyBindings.find(binding);
|
||||||
if(it == kekData.keyBindings.end()) return {.name = KEK_INVALID_KEY_BINDING_NAME};
|
if(it == kekData.input->keyBindings.end()) return {.name = KEK_INVALID_KEY_BINDING_NAME};
|
||||||
return it->second;
|
return it->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
GLFWKeyState getKeyState(KeyBinding binding) {
|
GLFWKeyState getKeyState(KeyBinding binding) {
|
||||||
auto it = kekData.keyBindings.find(binding);
|
auto it = kekData.input->keyBindings.find(binding);
|
||||||
if(it == kekData.keyBindings.end()) return -1;
|
if(it == kekData.input->keyBindings.end()) return -1;
|
||||||
return glfwGetKey(kekData.window, it->second.key);
|
return glfwGetKey(kekData.window, it->second.key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,13 +18,6 @@ struct UIData;
|
|||||||
struct InputData;
|
struct InputData;
|
||||||
|
|
||||||
struct KekData {
|
struct KekData {
|
||||||
std::map<InputListener, PeriodicCallback> periodicCallbacks;
|
|
||||||
std::map<InputListener, KeyCallback> keyCallbacks;
|
|
||||||
std::map<InputListener, KeyCharCallback> keyCharCallbacks;
|
|
||||||
std::map<InputListener, MouseCallback> mouseCallbacks;
|
|
||||||
std::map<InputListener, MouseButtonCallback> mouseButtonCallbacks;
|
|
||||||
std::map<KeyBinding, KeyBindingData> keyBindings;
|
|
||||||
|
|
||||||
GLFWwindow *window;
|
GLFWwindow *window;
|
||||||
Shader *shader;
|
Shader *shader;
|
||||||
|
|
||||||
|
@ -10,6 +10,13 @@ struct ActiveKeyboardCapture {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct InputData {
|
struct InputData {
|
||||||
|
std::map<InputListener, PeriodicCallback> periodicCallbacks;
|
||||||
|
std::map<InputListener, KeyCallback> keyCallbacks;
|
||||||
|
std::map<InputListener, KeyCharCallback> keyCharCallbacks;
|
||||||
|
std::map<InputListener, MouseCallback> mouseCallbacks;
|
||||||
|
std::map<InputListener, MouseButtonCallback> mouseButtonCallbacks;
|
||||||
|
std::map<KeyBinding, KeyBindingData> keyBindings;
|
||||||
|
|
||||||
ActiveKeyboardCapture activeKeyboardCapture;
|
ActiveKeyboardCapture activeKeyboardCapture;
|
||||||
GLFWCursorMode cursorMode;
|
GLFWCursorMode cursorMode;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user