Skip to content

Commit

Permalink
Shift scroll bar by clicking and holding in empty scroll bar area
Browse files Browse the repository at this point in the history
  • Loading branch information
kieranmillar committed Nov 20, 2017
1 parent ad3a96e commit 92c4f33
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 13 deletions.
1 change: 1 addition & 0 deletions src/Editor/editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ bool Editor::load( int n, Window * w )
bar.load();
canvas.load();
editor_input.load();
gameFrameCount = 0;

return canvas.redraw = true;
}
Expand Down
2 changes: 2 additions & 0 deletions src/Editor/editor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ class Editor

typedef std::vector< std::pair<Level::Object::Index, Level::Object> > Clipboard;
Clipboard clipboard;

Uint32 gameFrameCount;

void resize(int w, int h);

Expand Down
42 changes: 30 additions & 12 deletions src/Editor/input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ void Editor_input::load(void)
rightScrollButtonHolding = false;
scrollBarHolding = false;
scrollBarHoldingOffset = 0;
scrollBarShifting = false;
holdingID = -1;
holdingType = -1;
}
Expand Down Expand Up @@ -167,7 +168,7 @@ void Editor_input::handleEvents(SDL_Event event)
else
// piece browser scroll bar area
{

scrollBarShifting = true;
}
}
break;
Expand All @@ -183,6 +184,7 @@ void Editor_input::handleEvents(SDL_Event event)
leftScrollButtonHolding = false;
rightScrollButtonHolding = false;
scrollBarHolding = false;
scrollBarShifting = false;
}
break;
}
Expand Down Expand Up @@ -304,18 +306,32 @@ void Editor_input::handleEvents(SDL_Event event)

if (mouse_state & SDL_BUTTON(SDL_BUTTON_LEFT))
{
if (leftScrollButtonHolding
&& mouse_x_window > BAR_HEIGHT
&& mouse_x_window < BAR_HEIGHT + 16
&& mouse_y_window > window_ptr->height - 16)
{
bar_ptr->scroll(-50);
}
if (rightScrollButtonHolding
&& mouse_x_window > window_ptr->width - 16
&& mouse_y_window > window_ptr->height - 16)
if (mouse_y_window > window_ptr->height - 16) // scroll bar area
{
bar_ptr->scroll(50);
if (leftScrollButtonHolding
&& mouse_x_window > BAR_HEIGHT
&& mouse_x_window < BAR_HEIGHT + 16)
{
bar_ptr->scroll(-50);
}
if (rightScrollButtonHolding
&& mouse_x_window > window_ptr->width - 16)
{
bar_ptr->scroll(50);
}
if (scrollBarShifting
&& mouse_x_window < window_ptr->width - 16
&& mouse_x_window > BAR_HEIGHT + 16)
{
if (bar_ptr->barScrollRect.x > mouse_x_window)
{
bar_ptr->moveScrollBar(bar_ptr->barScrollRect.x - (bar_ptr->barScrollRect.w / 2));
}
else if (bar_ptr->barScrollRect.x + bar_ptr->barScrollRect.w < mouse_x_window)
{
bar_ptr->moveScrollBar(bar_ptr->barScrollRect.x + (bar_ptr->barScrollRect.w / 2));
}
}
}
}
}
Expand All @@ -326,6 +342,8 @@ void Editor_input::handleEvents(SDL_Event event)

SDL_RenderPresent(window_ptr->screen_renderer);

editor_ptr->gameFrameCount++;

break;
}
default:
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, scrollBarHolding;
bool dragging, leftScrollButtonHolding, rightScrollButtonHolding;
bool scrollBarHolding, scrollBarShifting;
int scrollBarHoldingOffset;

int holdingID, holdingType;
Expand Down

0 comments on commit 92c4f33

Please sign in to comment.