From 244d20073db4f5017a38580f777a030a3389b9fc Mon Sep 17 00:00:00 2001 From: sam Date: Mon, 6 Oct 2008 21:33:30 +0000 Subject: [PATCH] ThePimp: middle mouse drag now scrolls the image. git-svn-id: file:///srv/caca.zoy.org/var/lib/svn/libpipi/trunk@2889 92316355-f0b4-4df1-b90c-862c8a59935f --- ThePimp/PictureView.cs | 58 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/ThePimp/PictureView.cs b/ThePimp/PictureView.cs index 8958ee1..dfba9e8 100644 --- a/ThePimp/PictureView.cs +++ b/ThePimp/PictureView.cs @@ -22,6 +22,8 @@ namespace ThePimp { private Pipi.Picture _p; private Adjustment _hadj = null, _vadj = null; + private bool _drag = false; + private double _xdrag, _ydrag; void HAdjust(object sender, EventArgs args) { @@ -37,6 +39,9 @@ namespace ThePimp { bool ret = base.OnExposeEvent(e); + if(_hadj == null || _vadj == null) + return ret; + using (Gdk.GC gc = new Gdk.GC(GdkWindow)) { int w = e.Area.Width; @@ -61,6 +66,55 @@ namespace ThePimp base.OnRealized(); } + protected override bool OnButtonPressEvent(Gdk.EventButton e) + { + if(e.Button == 2) + { + GdkWindow.Cursor = new Gdk.Cursor(Gdk.CursorType.Hand1); + _drag = true; + _xdrag = e.X; + _ydrag = e.Y; + } + + return base.OnButtonPressEvent(e); + } + + protected override bool OnButtonReleaseEvent(Gdk.EventButton e) + { + if(e.Button == 2) + { + GdkWindow.Cursor = null; + _drag = false; + } + + return base.OnButtonReleaseEvent(e); + } + + protected override bool OnMotionNotifyEvent(Gdk.EventMotion e) + { + if(_drag) + { + if(_hadj != null && e.X != _xdrag) + { + _hadj.Value += _xdrag - e.X; + _xdrag = e.X; + if(_hadj.Value + Allocation.Width > _p.Width) + _hadj.Value = _p.Width - Allocation.Width; + _hadj.ChangeValue(); + } + if(_vadj != null && e.Y != _ydrag) + { + _vadj.Value += _ydrag - e.Y; + _ydrag = e.Y; + if(_vadj.Value + Allocation.Height > _p.Height) + _vadj.Value = _p.Height - Allocation.Height; + _vadj.ChangeValue(); + } + } + + return base.OnMotionNotifyEvent(e); + } + protected override void OnSetScrollAdjustments(Adjustment hadj, Adjustment vadj) { @@ -115,6 +169,10 @@ namespace ThePimp public PictureArea(Picture p) { _p = p; + + AddEvents((int)Gdk.EventMask.ButtonPressMask); + AddEvents((int)Gdk.EventMask.ButtonReleaseMask); + AddEvents((int)Gdk.EventMask.PointerMotionMask); } }