summaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2011-09-26 20:17:08 +0300
committerAndrei Karas <akaras@inbox.ru>2011-09-26 20:17:08 +0300
commit2ca54be098398e50bb9aa482f78d1f302e372fd5 (patch)
tree83058cae8148cadaef2922b32618b27b3b6fc316 /src/gui
parenta1cd5307497bfc754f157a3e22bfa98fc126137a (diff)
downloadmanaplus-2ca54be098398e50bb9aa482f78d1f302e372fd5.tar.gz
manaplus-2ca54be098398e50bb9aa482f78d1f302e372fd5.tar.bz2
manaplus-2ca54be098398e50bb9aa482f78d1f302e372fd5.tar.xz
manaplus-2ca54be098398e50bb9aa482f78d1f302e372fd5.zip
Add ability to scrolling in scrollareas like chat by mouse draging.
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/widgets/scrollarea.cpp57
-rw-r--r--src/gui/widgets/scrollarea.h5
2 files changed, 62 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);
+}
diff --git a/src/gui/widgets/scrollarea.h b/src/gui/widgets/scrollarea.h
index 095010f3c..56e21c58c 100644
--- a/src/gui/widgets/scrollarea.h
+++ b/src/gui/widgets/scrollarea.h
@@ -112,6 +112,10 @@ class ScrollArea : public gcn::ScrollArea, public gcn::WidgetListener
*/
void mouseExited(gcn::MouseEvent& event);
+ void mousePressed(gcn::MouseEvent& event);
+
+ void mouseReleased(gcn::MouseEvent& event);
+
void widgetResized(const gcn::Event &event);
void widgetMoved(const gcn::Event &event);
@@ -148,6 +152,7 @@ class ScrollArea : public gcn::ScrollArea, public gcn::WidgetListener
static Image *buttons[4][2];
int mX, mY;
+ int mClickX, mClickY;
bool mHasMouse;
bool mOpaque;
GraphicsVertexes *mVertexes;