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