diff --git a/dependencies/subprojects/animationwindow/include/AnimationWindow.h b/dependencies/subprojects/animationwindow/include/AnimationWindow.h index e0c56482f5d9b8dcba9decbcb3c81bee0416dfe6..a3811ae0e5e7620d0779c2ffc3fe2c4f0a00dbd5 100644 --- a/dependencies/subprojects/animationwindow/include/AnimationWindow.h +++ b/dependencies/subprojects/animationwindow/include/AnimationWindow.h @@ -69,6 +69,7 @@ class AnimationWindow { std::unordered_map<KeyboardKey, bool> currentKeyStates; bool currentLeftMouseButtonState = false; bool currentRightMouseButtonState = false; + float deltaMouseWheel = 0; public: explicit AnimationWindow(int x = 50, int y = 50, int width = 1024, int height = 768, const std::string& title = "Animation Window"); @@ -105,8 +106,8 @@ class AnimationWindow { void draw_arc(TDT4102::Point center, int width, int height, int start_degree, int end_degree, TDT4102::Color color = TDT4102::Color::black); // And these functions are for handling input - bool is_key_down(KeyboardKey key); - TDT4102::Point get_mouse_coordinates(); + bool is_key_down(KeyboardKey key) const; + TDT4102::Point get_mouse_coordinates() const; bool is_left_mouse_button_down() const; bool is_right_mouse_button_down() const; @@ -119,9 +120,11 @@ class AnimationWindow { void show_error_dialog(const std::string& message) const; // Getters for the window dimensions - int width(); - int height(); + int windowWidth() const; + int windowHeight() const; void setBackgroundColor(TDT4102::Color newBackgroundColor); + + float get_delta_mouse_wheel() const; }; } // namespace TDT4102 diff --git a/dependencies/subprojects/animationwindow/src/AnimationWindow.cpp b/dependencies/subprojects/animationwindow/src/AnimationWindow.cpp index 2013c1963668f610bb0c12b7def230ff28328747..2e09093a92cd0e12a5f051b8eb9066e2b6b86d8a 100644 --- a/dependencies/subprojects/animationwindow/src/AnimationWindow.cpp +++ b/dependencies/subprojects/animationwindow/src/AnimationWindow.cpp @@ -77,6 +77,7 @@ void TDT4102::AnimationWindow::destroy() { void TDT4102::AnimationWindow::show_frame() { SDL_RenderPresent(rendererHandle); + deltaMouseWheel = 0; SDL_Event event; nk_input_begin(context); @@ -102,6 +103,8 @@ void TDT4102::AnimationWindow::show_frame() { } else if (event.button.button == SDL_BUTTON_RIGHT) { currentRightMouseButtonState = false; } + } else if (event.type == SDL_MOUSEWHEEL) { + deltaMouseWheel = event.wheel.preciseY; // The amount scrolled vertically, positive away from the user and negative toward the user } nk_sdl_handle_event(&event); @@ -302,14 +305,14 @@ void TDT4102::AnimationWindow::draw_arc(TDT4102::Point center, int width, int he SDL_RenderDrawLines(rendererHandle, internal::circleBorderBuffer.data(), internal::SLICES_PER_CIRCLE); } -bool TDT4102::AnimationWindow::is_key_down(KeyboardKey key) { +bool TDT4102::AnimationWindow::is_key_down(KeyboardKey key) const { if (currentKeyStates.count(key) == 0) { return false; } return currentKeyStates.at(key); } -TDT4102::Point TDT4102::AnimationWindow::get_mouse_coordinates() { +TDT4102::Point TDT4102::AnimationWindow::get_mouse_coordinates() const { int mouseX, mouseY; SDL_GetMouseState(&mouseX, &mouseY); return {mouseX, mouseY}; @@ -334,11 +337,11 @@ TDT4102::Point TDT4102::AnimationWindow::getWindowDimensions() { return dimensions; } -int TDT4102::AnimationWindow::width() { +int TDT4102::AnimationWindow::windowWidth() const { return getWindowDimensions().x; } -int TDT4102::AnimationWindow::height() { +int TDT4102::AnimationWindow::windowHeight() const { return getWindowDimensions().y; } @@ -350,6 +353,10 @@ bool TDT4102::AnimationWindow::is_right_mouse_button_down() const { return currentRightMouseButtonState; } +float TDT4102::AnimationWindow::get_delta_mouse_wheel() const { + return deltaMouseWheel; +} + void TDT4102::AnimationWindow::startNuklearDraw(TDT4102::Point location, std::string uniqueWindowName, unsigned int width, unsigned int height) { // Make window transparent; we just want to see individual GUI elements struct nk_style* s = &context->style;