diff --git a/src/Editor/bar.cpp b/src/Editor/bar.cpp index 08aee5a..ed436a5 100644 --- a/src/Editor/bar.cpp +++ b/src/Editor/bar.cpp @@ -81,6 +81,19 @@ void Bar::updateBarScrollPos(int xPos) barScrollRect.x += BAR_HEIGHT + 18; } +void Bar::moveScrollBar(int moveLocationInWindow) +{ + int x = moveLocationInWindow - BAR_HEIGHT - 18; + int xMax = window_ptr->width - BAR_HEIGHT - 33; + if (x < 0) + x = 0; + if (x > xMax - barScrollRect.w) + x = xMax - barScrollRect.w; + int factor = x * 1000 / xMax; + barScrollX = (barMax * factor) / 1000; + scroll(0); +} + void Bar::changeType(int t) { if (type == t) diff --git a/src/Editor/bar.hpp b/src/Editor/bar.hpp index 45967de..91c3b2c 100644 --- a/src/Editor/bar.hpp +++ b/src/Editor/bar.hpp @@ -55,6 +55,7 @@ class Bar void resizeBarScrollRect(int windowWidth, int windowHeight); void scroll(signed int moveAmount); void updateBarScrollPos(int xPos); + void moveScrollBar(int moveLocationInWindow); void changeType( int t); diff --git a/src/Editor/input.cpp b/src/Editor/input.cpp index 2b806d2..fb94967 100644 --- a/src/Editor/input.cpp +++ b/src/Editor/input.cpp @@ -48,6 +48,8 @@ void Editor_input::load(void) dragging = false; leftScrollButtonHolding = false; rightScrollButtonHolding = false; + scrollBarHolding = false; + scrollBarHoldingOffset = 0; holdingID = -1; holdingType = -1; } @@ -86,6 +88,8 @@ void Editor_input::handleEvents(SDL_Event event) if (e.state & SDL_BUTTON(SDL_BUTTON_LEFT) && dragging) editor_ptr->move_selected(mouse_x_window - mouse_prev_x, mouse_y_window - mouse_prev_y); + if (e.state & SDL_BUTTON(SDL_BUTTON_LEFT) && scrollBarHolding) + bar_ptr->moveScrollBar(mouse_x_window - scrollBarHoldingOffset); mouse_prev_x = mouse_x_window; mouse_prev_y = mouse_y_window; @@ -157,10 +161,11 @@ void Editor_input::handleEvents(SDL_Event event) else if (mouse_x_window > bar_ptr->barScrollRect.x && mouse_x_window < (bar_ptr->barScrollRect.x + bar_ptr->barScrollRect.w)) // piece browser scroll bar bar { - + scrollBarHolding = true; + scrollBarHoldingOffset = mouse_x_window - bar_ptr->barScrollRect.x; } else - // // piece browser scroll bar area + // piece browser scroll bar area { } @@ -177,6 +182,7 @@ void Editor_input::handleEvents(SDL_Event event) dragging = false; leftScrollButtonHolding = false; rightScrollButtonHolding = false; + scrollBarHolding = false; } break; } diff --git a/src/Editor/input.hpp b/src/Editor/input.hpp index e12300d..f4e265e 100644 --- a/src/Editor/input.hpp +++ b/src/Editor/input.hpp @@ -44,7 +44,8 @@ class Editor_input bool redraw; Sint32 mouse_prev_x, mouse_prev_y; - bool dragging, leftScrollButtonHolding, rightScrollButtonHolding; + bool dragging, leftScrollButtonHolding, rightScrollButtonHolding, scrollBarHolding; + int scrollBarHoldingOffset; int holdingID, holdingType;