Browse Source
git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@4353 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61shortcuts
4 changed files with 104 additions and 5 deletions
@ -0,0 +1,87 @@
@@ -0,0 +1,87 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Martin Koníček" email="martin.konicek@gmail.com"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
using System; |
||||
using System.Windows.Controls; |
||||
using System.Windows; |
||||
using System.Windows.Input; |
||||
|
||||
namespace Debugger.AddIn.Visualizers.Controls |
||||
{ |
||||
/// <summary>
|
||||
/// ScrollViewer with support for drag-scrolling.
|
||||
/// </summary>
|
||||
public class DragScrollViewer : ScrollViewer |
||||
{ |
||||
private bool isScrolling = false; |
||||
private Point startDragPos; |
||||
private Point scrollStartOffset; |
||||
|
||||
public DragScrollViewer() : base() |
||||
{ |
||||
this.PreviewMouseDown += new System.Windows.Input.MouseButtonEventHandler(DragScrollViewer_PreviewMouseDown); |
||||
this.PreviewMouseMove += new System.Windows.Input.MouseEventHandler(DragScrollViewer_PreviewMouseMove); |
||||
this.PreviewMouseUp += new System.Windows.Input.MouseButtonEventHandler(DragScrollViewer_PreviewMouseUp); |
||||
} |
||||
|
||||
void DragScrollViewer_PreviewMouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e) |
||||
{ |
||||
if (e.LeftButton == MouseButtonState.Pressed && this.IsMouseDirectlyOver) |
||||
{ |
||||
startDragPos = e.GetPosition(this); |
||||
scrollStartOffset.X = this.HorizontalOffset; |
||||
scrollStartOffset.Y = this.VerticalOffset; |
||||
|
||||
this.Cursor = this.canScroll() ? Cursors.ScrollAll : Cursors.Arrow; |
||||
|
||||
this.isScrolling = true; |
||||
this.CaptureMouse(); |
||||
base.OnPreviewMouseDown(e); |
||||
} |
||||
} |
||||
|
||||
void DragScrollViewer_PreviewMouseMove(object sender, System.Windows.Input.MouseEventArgs e) |
||||
{ |
||||
if (this.isScrolling) |
||||
{ |
||||
Point currentPos = e.GetPosition(this); |
||||
|
||||
Vector delta = getScrollDelta(this.startDragPos, currentPos); |
||||
|
||||
this.ScrollToHorizontalOffset(this.scrollStartOffset.X + delta.X); |
||||
this.ScrollToVerticalOffset(this.scrollStartOffset.Y + delta.Y); |
||||
} |
||||
base.OnPreviewMouseMove(e); |
||||
} |
||||
|
||||
void DragScrollViewer_PreviewMouseUp(object sender, System.Windows.Input.MouseButtonEventArgs e) |
||||
{ |
||||
if (e.LeftButton == MouseButtonState.Released) |
||||
{ |
||||
if (this.isScrolling) |
||||
{ |
||||
this.Cursor = Cursors.Arrow; |
||||
this.isScrolling = false; |
||||
this.ReleaseMouseCapture(); |
||||
} |
||||
base.OnPreviewMouseUp(e); |
||||
} |
||||
} |
||||
|
||||
private Vector getScrollDelta(Point startPos, Point currentPos) |
||||
{ |
||||
double dx = startPos.X - currentPos.X; |
||||
double dy = startPos.Y - currentPos.Y; |
||||
//return new Vector(Math.Sign(dx)*dx*dx*0.01, Math.Sign(dy)*dy*dy*0.01);
|
||||
return new Vector(dx, dy); |
||||
} |
||||
|
||||
private bool canScroll() |
||||
{ |
||||
return (this.ExtentWidth > this.ViewportWidth) || (this.ExtentHeight > this.ViewportHeight); |
||||
} |
||||
} |
||||
} |
||||
Loading…
Reference in new issue