Skip to content

Commit

Permalink
Draggable scroll bar
Browse files Browse the repository at this point in the history
  • Loading branch information
kieranmillar committed Nov 20, 2017
1 parent 8ab1c23 commit ad3a96e
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 3 deletions.
13 changes: 13 additions & 0 deletions src/Editor/bar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions src/Editor/bar.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
10 changes: 8 additions & 2 deletions src/Editor/input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ void Editor_input::load(void)
dragging = false;
leftScrollButtonHolding = false;
rightScrollButtonHolding = false;
scrollBarHolding = false;
scrollBarHoldingOffset = 0;
holdingID = -1;
holdingType = -1;
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
{

}
Expand All @@ -177,6 +182,7 @@ void Editor_input::handleEvents(SDL_Event event)
dragging = false;
leftScrollButtonHolding = false;
rightScrollButtonHolding = false;
scrollBarHolding = false;
}
break;
}
Expand Down
3 changes: 2 additions & 1 deletion src/Editor/input.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit ad3a96e

Please sign in to comment.