« Windows Live - do they know where they'll go tomorrow?Be careful when installing VS add-ins in localized Windows versions »

Scrolling an InkCollector

31/01/06

Permalink 07:24:28 pm
Categories: General, Programming, .NET, Tablet PC

Scrolling an InkCollector

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 feedback yet

Leave a comment


Your email address will not be revealed on this site.

Your URL will be displayed.
(Line breaks become <br />)
(Name, email & website)
(Allow users to contact you through a message form (your email will not be revealed.)
Please complete the song title below. Hint: enter 'h', 'e', 'a', 'v', 'e', 'n'
antispam test

Enter your email address:

Search

Oliver
MVP logo
March 2010
Sun Mon Tue Wed Thu Fri Sat
 << <   > >>
  1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31