Skip to content

Commit

Permalink
Implement mouse wheel for scrollbars (buggy)
Browse files Browse the repository at this point in the history
  • Loading branch information
aybe committed Jul 10, 2024
1 parent 854da8e commit e5058a8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/libs/gui_tk/gui_tk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1024,6 +1024,12 @@ bool Window::mouseDoubleClicked(int x, int y, MouseButton button)
return mouseChild->mouseDoubleClicked(x-mouseChild->x, y-mouseChild->y, button);
}

bool Window::mouseWheel(int wheel)
{
if (mouseChild == NULL) return false;
return mouseChild->mouseWheel(wheel);
}

bool BorderedWindow::mouseDown(int x, int y, MouseButton button)
{
mouseChild = NULL;
Expand Down Expand Up @@ -2327,7 +2333,9 @@ bool ScreenSDL::event(SDL_Event &event) {
}
lastdown = 0;
return rc;
}
case SDL_MOUSEWHEEL:
return mouseWheel(event.wheel.y);
}

return false;
}
Expand Down Expand Up @@ -2866,6 +2874,13 @@ bool WindowInWindow::mouseDoubleClicked(int x, int y, MouseButton button) {
return Window::mouseDoubleClicked(x-xadj,y-xadj,button);
}

bool WindowInWindow::mouseWheel(int wheel)
{
// BUG requires to click at least once in window for it to work
scroll_pos_y = min(max(scroll_pos_y - wheel * 15, 0), scroll_pos_h);
return Window::mouseWheel(wheel);
}

void WindowInWindow::resize(int w, int h) {
int mw = 0,mh = 0;
int cmpw = w;
Expand Down
2 changes: 2 additions & 0 deletions src/libs/gui_tk/gui_tk.h
Original file line number Diff line number Diff line change
Expand Up @@ -743,6 +743,7 @@ class Window : public Refcount {
/// Transient windows by default should disappear.
virtual bool mouseDownOutside(MouseButton button);

virtual bool mouseWheel(int wheel);
/// Key was pressed. Returns true if event was handled.
virtual bool keyDown(const Key &key);
/// Key was released. Returns true if event was handled.
Expand Down Expand Up @@ -882,6 +883,7 @@ class WindowInWindow : public Window {
/// Mouse was double-clicked. Returns true if event was handled.
bool mouseDoubleClicked(int x, int y, MouseButton button) override;

bool mouseWheel(int wheel) override;
/// Key was pressed. Returns true if event was handled.
bool keyDown(const Key &key) override;

Expand Down

0 comments on commit e5058a8

Please sign in to comment.