Please click this logo to help me get on their beta program:

Xobni outlook add-in for your inbox








31/1/2006

Scrolling an InkCollector

Filed under: General, Programming, .NET, Tablet PC — Oliver Sturm @ 7:24 pm - 2 years, 9 months ago

As I mentioned elsewhere, I’m working on a DXCore plugin to enable (Tablet PC) ink drawing on the Visual Studio editor surface. A problem I stumbled upon in this regard was the scrolling functionality. Generally this is really easy to implement, using a transformation with the ink renderer. So I had this method:

void UpdateScrollPosition(TextView textView) {
  Point p = new Point(textView.ColumnWidth * textView.HorizontalScrollPosition,
    textView.LineHeight * textView.VerticalScrollPosition);
	
  collector.Renderer.PixelToInkSpace(textView.Graphics, ref p);
  Matrix matrix = new Matrix();
  matrix.Translate(-p.X, -p.Y);
	
  collector.Renderer.SetViewTransform(matrix);
}

After wondering for a while why this didn’t work, I put in some logging and found that the value passed in as -p.Y was actually growing for every call into that method, regardless how I was dragging the vertical scrollbar. The explanation was simple in the end, as these explanations tend to be: the PixelToInkSpace method takes any current transformations into account, so that any calculation is relative to an origin set earlier - in the last update, in fact. So the solution was to use an offset for the calculation and everything started working:

void UpdateScrollPosition(TextView textView) {
  Point p = new Point(textView.ColumnWidth * textView.HorizontalScrollPosition,
    textView.LineHeight * textView.VerticalScrollPosition);
  Point origin = new Point(0, 0);
	
  collector.Renderer.PixelToInkSpace(textView.Graphics, ref p);
  collector.Renderer.PixelToInkSpace(textView.Graphics, ref origin);
  p.Offset(-origin.X, -origin.Y);
  Matrix matrix = new Matrix();
  matrix.Translate(-p.X, -p.Y);
	
  collector.Renderer.SetViewTransform(matrix);
}

No Comments »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>


Powered by WordPress
© Copyright 2005-2008 Oliver Sturm