From 92c4f33f3757ad8682f4ac9fb042fd974181f8c2 Mon Sep 17 00:00:00 2001 From: Kieran Millar Date: Mon, 20 Nov 2017 21:42:46 +0000 Subject: [PATCH] Shift scroll bar by clicking and holding in empty scroll bar area --- src/Editor/editor.cpp | 1 + src/Editor/editor.hpp | 2 ++ src/Editor/input.cpp | 42 ++++++++++++++++++++++++++++++------------ src/Editor/input.hpp | 3 ++- 4 files changed, 35 insertions(+), 13 deletions(-) diff --git a/src/Editor/editor.cpp b/src/Editor/editor.cpp index f3af33b..1fddb04 100644 --- a/src/Editor/editor.cpp +++ b/src/Editor/editor.cpp @@ -50,6 +50,7 @@ bool Editor::load( int n, Window * w ) bar.load(); canvas.load(); editor_input.load(); + gameFrameCount = 0; return canvas.redraw = true; } diff --git a/src/Editor/editor.hpp b/src/Editor/editor.hpp index 91d0533..db4f49b 100644 --- a/src/Editor/editor.hpp +++ b/src/Editor/editor.hpp @@ -53,6 +53,8 @@ class Editor typedef std::vector< std::pair > Clipboard; Clipboard clipboard; + + Uint32 gameFrameCount; void resize(int w, int h); diff --git a/src/Editor/input.cpp b/src/Editor/input.cpp index fb94967..64b2b14 100644 --- a/src/Editor/input.cpp +++ b/src/Editor/input.cpp @@ -50,6 +50,7 @@ void Editor_input::load(void) rightScrollButtonHolding = false; scrollBarHolding = false; scrollBarHoldingOffset = 0; + scrollBarShifting = false; holdingID = -1; holdingType = -1; } @@ -167,7 +168,7 @@ void Editor_input::handleEvents(SDL_Event event) else // piece browser scroll bar area { - + scrollBarShifting = true; } } break; @@ -183,6 +184,7 @@ void Editor_input::handleEvents(SDL_Event event) leftScrollButtonHolding = false; rightScrollButtonHolding = false; scrollBarHolding = false; + scrollBarShifting = false; } break; } @@ -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)); + } + } } } } @@ -326,6 +342,8 @@ void Editor_input::handleEvents(SDL_Event event) SDL_RenderPresent(window_ptr->screen_renderer); + editor_ptr->gameFrameCount++; + break; } default: diff --git a/src/Editor/input.hpp b/src/Editor/input.hpp index f4e265e..487c7f9 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, scrollBarHolding; + bool dragging, leftScrollButtonHolding, rightScrollButtonHolding; + bool scrollBarHolding, scrollBarShifting; int scrollBarHoldingOffset; int holdingID, holdingType;