Skip to content

Commit

Permalink
Scroll view with right mouse button
Browse files Browse the repository at this point in the history
  • Loading branch information
kieranmillar committed Nov 22, 2017
1 parent 71095dc commit 0dc27cf
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/Editor/input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ void Editor_input::load(void)
scrollBarHolding = false;
scrollBarHoldingOffset = 0;
scrollBarShifting = false;
movingView = false;
holdingID = -1;
holdingType = -1;
}
Expand Down Expand Up @@ -88,9 +89,17 @@ void Editor_input::handleEvents(SDL_Event event)
SDL_MouseMotionEvent &e = event.motion;

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);
}
if (e.state & SDL_BUTTON(SDL_BUTTON_RIGHT) && movingView)
{
canvas_ptr->scroll(mouse_prev_x - mouse_x_window, mouse_prev_y - mouse_y_window, false);
}

mouse_prev_x = mouse_x_window;
mouse_prev_y = mouse_y_window;
Expand Down Expand Up @@ -171,6 +180,14 @@ void Editor_input::handleEvents(SDL_Event event)
scrollBarShifting = true;
}
}
if (e.button == SDL_BUTTON_RIGHT)
{
if (mouse_y_window < canvas_ptr->height)
// canvas
{
movingView = true;
}
}
break;
}
case SDL_MOUSEBUTTONUP://when released
Expand All @@ -186,6 +203,10 @@ void Editor_input::handleEvents(SDL_Event event)
scrollBarHolding = false;
scrollBarShifting = false;
}
if (e.button == SDL_BUTTON_RIGHT)
{
movingView = false;
}
break;
}
case SDL_MOUSEWHEEL:
Expand Down
1 change: 1 addition & 0 deletions src/Editor/input.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class Editor_input
bool dragging, leftScrollButtonHolding, rightScrollButtonHolding;
bool scrollBarHolding, scrollBarShifting;
int scrollBarHoldingOffset;
bool movingView;

int holdingID, holdingType;

Expand Down

0 comments on commit 0dc27cf

Please sign in to comment.