aboutsummaryrefslogtreecommitdiff
path: root/mwe/events/src/inputSystem.cpp
diff options
context:
space:
mode:
authorLoek Le Blansch <loek@pipeframe.xyz>2024-11-03 13:34:27 +0100
committerLoek Le Blansch <loek@pipeframe.xyz>2024-11-03 13:34:27 +0100
commit2585dc3cab48ccad0cfa0c63354662d656c86c46 (patch)
tree579851837f35842e5ed682c912c470d68df79183 /mwe/events/src/inputSystem.cpp
parent5deb950619dff9dde8b49520b23e3ce4001afbee (diff)
`make format`
Diffstat (limited to 'mwe/events/src/inputSystem.cpp')
-rw-r--r--mwe/events/src/inputSystem.cpp162
1 files changed, 79 insertions, 83 deletions
diff --git a/mwe/events/src/inputSystem.cpp b/mwe/events/src/inputSystem.cpp
index bb26e8b..b87b12e 100644
--- a/mwe/events/src/inputSystem.cpp
+++ b/mwe/events/src/inputSystem.cpp
@@ -2,98 +2,94 @@
InputSystem::InputSystem() {}
-void InputSystem::registerButton(Button* button) {
- buttons.push_back(button);
-}
-void InputSystem::registerTextInput(TextInput* input) {
- textInputs.push_back(input);
-}
-void InputSystem::registerText(Text* label) {
- texts.push_back(label);
+void InputSystem::registerButton(Button * button) { buttons.push_back(button); }
+void InputSystem::registerTextInput(TextInput * input) {
+ textInputs.push_back(input);
}
+void InputSystem::registerText(Text * label) { texts.push_back(label); }
void InputSystem::processInput() {
- SDL_Event event;
- while (SDL_PollEvent(&event)) {
- switch (event.type) {
- case SDL_QUIT:
- triggerEvent(ShutDownEvent());
- break;
- case SDL_KEYDOWN:
- triggerEvent(KeyPressedEvent(getCustomKey(event.key.keysym.sym)));
- processKeyPress(event.key.keysym.sym);
- break;
- case SDL_TEXTINPUT:
- // Process typed characters
- processTextInput(event.text.text);
- break;
- case SDL_MOUSEBUTTONDOWN: {
- int mouseX, mouseY;
- SDL_GetMouseState(&mouseX, &mouseY);
- processMouseClick(mouseX, mouseY);
- triggerEvent(MousePressedEvent(mouseX, mouseY));
- break;
- }
- }
- }
+ SDL_Event event;
+ while (SDL_PollEvent(&event)) {
+ switch (event.type) {
+ case SDL_QUIT:
+ triggerEvent(ShutDownEvent());
+ break;
+ case SDL_KEYDOWN:
+ triggerEvent(
+ KeyPressedEvent(getCustomKey(event.key.keysym.sym)));
+ processKeyPress(event.key.keysym.sym);
+ break;
+ case SDL_TEXTINPUT:
+ // Process typed characters
+ processTextInput(event.text.text);
+ break;
+ case SDL_MOUSEBUTTONDOWN: {
+ int mouseX, mouseY;
+ SDL_GetMouseState(&mouseX, &mouseY);
+ processMouseClick(mouseX, mouseY);
+ triggerEvent(MousePressedEvent(mouseX, mouseY));
+ break;
+ }
+ }
+ }
}
-
void InputSystem::processMouseClick(int mouseX, int mouseY) {
- for (auto* button : buttons) {
- if (mouseX >= button->x && mouseX <= (button->x + button->width) &&
- mouseY >= button->y && mouseY <= (button->y + button->height)) {
- button->onClick();
- }
- }
- for(auto* textInput : textInputs){
- if (mouseX >= textInput->x && mouseX <= textInput->x + textInput->width &&
- mouseY >= textInput->y && mouseY <= textInput->y + textInput->height) {
- textInput->isActive = true;
- } else {
- textInput->isActive = false;
- }
+ for (auto * button : buttons) {
+ if (mouseX >= button->x && mouseX <= (button->x + button->width)
+ && mouseY >= button->y && mouseY <= (button->y + button->height)) {
+ button->onClick();
+ }
+ }
+ for (auto * textInput : textInputs) {
+ if (mouseX >= textInput->x && mouseX <= textInput->x + textInput->width
+ && mouseY >= textInput->y
+ && mouseY <= textInput->y + textInput->height) {
+ textInput->isActive = true;
+ } else {
+ textInput->isActive = false;
+ }
}
}
void InputSystem::processKeyPress(Keycode key) {
- // for (auto* textInput : textInputs) {
- // if (textInput->isActive) {
- // if (key == SDLK_RETURN || key == SDLK_KP_ENTER) {
- // // Submit the text
- // if (textInput->onSubmit) {
- // textInput->onSubmit();
- // }
- // }
- // else if (key == SDLK_BACKSPACE) {
- // // Handle backspace
- // if (!textInput->textBuffer.empty() && textInput->caretPosition > 0) {
- // textInput->textBuffer.erase(textInput->caretPosition - 1, 1);
- // textInput->caretPosition--;
- // }
- // }
- // else if (key == SDLK_LEFT) {
- // // Move caret left
- // if (textInput->caretPosition > 0) {
- // textInput->caretPosition--;
- // }
- // }
- // else if (key == SDLK_RIGHT) {
- // // Move caret right
- // if (textInput->caretPosition < textInput->textBuffer.size()) {
- // textInput->caretPosition++;
- // }
- // }
- // }
- // }
+ // for (auto* textInput : textInputs) {
+ // if (textInput->isActive) {
+ // if (key == SDLK_RETURN || key == SDLK_KP_ENTER) {
+ // // Submit the text
+ // if (textInput->onSubmit) {
+ // textInput->onSubmit();
+ // }
+ // }
+ // else if (key == SDLK_BACKSPACE) {
+ // // Handle backspace
+ // if (!textInput->textBuffer.empty() && textInput->caretPosition > 0) {
+ // textInput->textBuffer.erase(textInput->caretPosition - 1, 1);
+ // textInput->caretPosition--;
+ // }
+ // }
+ // else if (key == SDLK_LEFT) {
+ // // Move caret left
+ // if (textInput->caretPosition > 0) {
+ // textInput->caretPosition--;
+ // }
+ // }
+ // else if (key == SDLK_RIGHT) {
+ // // Move caret right
+ // if (textInput->caretPosition < textInput->textBuffer.size()) {
+ // textInput->caretPosition++;
+ // }
+ // }
+ // }
+ // }
}
-void InputSystem::processTextInput(const std::string& text) {
- // for (auto* textInput : textInputs) {
- // if (textInput->isActive) {
- // // Insert text at caret position
- // textInput->textBuffer.insert(textInput->caretPosition, text);
- // textInput->caretPosition += text.length();
- // }
- // }
+void InputSystem::processTextInput(const std::string & text) {
+ // for (auto* textInput : textInputs) {
+ // if (textInput->isActive) {
+ // // Insert text at caret position
+ // textInput->textBuffer.insert(textInput->caretPosition, text);
+ // textInput->caretPosition += text.length();
+ // }
+ // }
}
-