From 79aee9aa7cd48dee1660e3b1bf50142ceda7ae34 Mon Sep 17 00:00:00 2001 From: Tametomo Date: Wed, 20 May 2009 12:47:39 -0600 Subject: Fixed ScrollAreas to allow for continual scrolling, as long as the mouse button is pressed, instead of just moving one tick for each press. Signed-off-by: Tametomo --- src/gui/widgets/scrollarea.cpp | 38 ++++++++++++++++++++++++++++++++++++-- src/gui/widgets/scrollarea.h | 2 ++ 2 files changed, 38 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/gui/widgets/scrollarea.cpp b/src/gui/widgets/scrollarea.cpp index 71f1a1a8..6754b00c 100644 --- a/src/gui/widgets/scrollarea.cpp +++ b/src/gui/widgets/scrollarea.cpp @@ -24,6 +24,7 @@ #include "configuration.h" #include "graphics.h" +#include "gui/gui.h" #include "gui/skin.h" #include "resources/image.h" @@ -159,13 +160,18 @@ void ScrollArea::init() resman->getImage("graphics/gui/hscroll_right_pressed.png"); } + mLastUpdate = tick_time; + instances++; } void ScrollArea::logic() { if (!isVisible()) + { + mLastUpdate = tick_time; return; + } gcn::ScrollArea::logic(); gcn::Widget *content = getContent(); @@ -185,6 +191,34 @@ void ScrollArea::logic() 2 * content->getFrameSize()); } } + + const int updateTicks = get_elapsed_time(mLastUpdate) / 100; + + if (updateTicks > 0) + { + if (mUpButtonPressed) + { + setVerticalScrollAmount(getVerticalScrollAmount() - + mUpButtonScrollAmount); + } + else if (mDownButtonPressed) + { + setVerticalScrollAmount(getVerticalScrollAmount() + + mDownButtonScrollAmount); + } + else if (mLeftButtonPressed) + { + setHorizontalScrollAmount(getHorizontalScrollAmount() - + mLeftButtonScrollAmount); + } + else if (mRightButtonPressed) + { + setHorizontalScrollAmount(getHorizontalScrollAmount() + + mRightButtonScrollAmount); + } + + mLastUpdate = tick_time; + } } void ScrollArea::updateAlpha() @@ -346,8 +380,8 @@ void ScrollArea::drawHMarker(gcn::Graphics *graphics) void ScrollArea::mouseMoved(gcn::MouseEvent& event) { -mX = event.getX(); -mY = event.getY(); + mX = event.getX(); + mY = event.getY(); } void ScrollArea::mouseEntered(gcn::MouseEvent& event) diff --git a/src/gui/widgets/scrollarea.h b/src/gui/widgets/scrollarea.h index 42e0923e..aa7b71a0 100644 --- a/src/gui/widgets/scrollarea.h +++ b/src/gui/widgets/scrollarea.h @@ -139,6 +139,8 @@ class ScrollArea : public gcn::ScrollArea, public gcn::WidgetListener int mX,mY; bool mHasMouse; bool mOpaque; + + int mLastUpdate; }; #endif -- cgit v1.2.3-70-g09d2