diff options
author | Andrei Karas <akaras@inbox.ru> | 2011-09-26 20:17:08 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2011-09-26 20:17:08 +0300 |
commit | 2ca54be098398e50bb9aa482f78d1f302e372fd5 (patch) | |
tree | 83058cae8148cadaef2922b32618b27b3b6fc316 /src/gui/widgets/scrollarea.cpp | |
parent | a1cd5307497bfc754f157a3e22bfa98fc126137a (diff) | |
download | manaverse-2ca54be098398e50bb9aa482f78d1f302e372fd5.tar.gz manaverse-2ca54be098398e50bb9aa482f78d1f302e372fd5.tar.bz2 manaverse-2ca54be098398e50bb9aa482f78d1f302e372fd5.tar.xz manaverse-2ca54be098398e50bb9aa482f78d1f302e372fd5.zip |
Add ability to scrolling in scrollareas like chat by mouse draging.
Diffstat (limited to 'src/gui/widgets/scrollarea.cpp')
-rw-r--r-- | src/gui/widgets/scrollarea.cpp | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/src/gui/widgets/scrollarea.cpp b/src/gui/widgets/scrollarea.cpp index 2796d3ab2..3204028dc 100644 --- a/src/gui/widgets/scrollarea.cpp +++ b/src/gui/widgets/scrollarea.cpp @@ -47,6 +47,8 @@ ScrollArea::ScrollArea(): gcn::ScrollArea(), mX(0), mY(0), + mClickX(0), + mClickY(0), mHasMouse(false), mOpaque(true), mVertexes(new GraphicsVertexes()), @@ -64,6 +66,8 @@ ScrollArea::ScrollArea(gcn::Widget *widget): gcn::ScrollArea(widget), mX(0), mY(0), + mClickX(0), + mClickY(0), mHasMouse(false), mOpaque(true), mVertexes(new GraphicsVertexes()), @@ -513,3 +517,56 @@ void ScrollArea::widgetMoved(const gcn::Event& event A_UNUSED) { mRedraw = true; } + +void ScrollArea::mousePressed(gcn::MouseEvent& event) +{ + gcn::ScrollArea::mousePressed(event); + if (event.getButton() == gcn::MouseEvent::LEFT) + { + mClickX = event.getX(); + mClickY = event.getY(); + } +} + +void ScrollArea::mouseReleased(gcn::MouseEvent& event) +{ + if (event.getButton() == gcn::MouseEvent::LEFT && mClickX && mClickY) + { + if (!event.isConsumed()) + { + int dx = event.getX() - mClickX; + int dy = event.getY() - mClickY; + + if ((dx < 10 && dx > 0) || (dx > -10 && dx < 0)) + dx = 0; + + if ((dy < 10 && dy > 0) || (dy > -10 && dy < 0)) + dy = 0; + + if (dx) + { + int s = getHorizontalScrollAmount() + dx; + if (s < 0) + s = 0; + else if (s > getHorizontalMaxScroll()) + s = getHorizontalMaxScroll(); + + setHorizontalScrollAmount(s); + } + if (dy) + { + int s = getVerticalScrollAmount() + dy; + if (s < 0) + s = 0; + else if (s > getVerticalMaxScroll()) + s = getVerticalMaxScroll(); + + setVerticalScrollAmount(s); + } + mClickX = 0; + mClickY = 0; + event.consume(); + } + } + gcn::ScrollArea::mouseReleased(event); +} |