X-Axis Offset?

Z

Zach Nelson

I'm working on a control that simulates a timeline and it supports "zooming"
so you can drill down and get finer detail along the timeline. I accomplish
this by always drawing the same tick marks starting at 0 on the x axis, but
I use Graphics.ScaleTransform(zoomfactorX, 1F) to scale the entire drawing
along the x axis (the y axis remains at 1x magnification).

The problem I'm running into is when you apply a zoom factor of let's say
2X. If there were 100 tick marks at 1X zoom then there should be 50 tick
marks visible at 2X zoom and you should have to scroll to the right to see
the other 50 tick marks.

sidenote: I was using the Autoscroll properties of the Panel object but they
didn't give me enough control and they wouldn't invalidate the panel during
or after the scroll (no scrollstart or scrolling or scrollend events). Also,
the zooming functionality works great, I'm just trying to simulate a scroll
effect.

So on the windows form I have this timeline control and a horizontal scroll
control. My thinking was that each time you zoomed into the timeline, I
could scale the scrollbar's smallchange property according to the zoom
factor, and also shift the entire timeline panel to the left. I'm looking
for a way to offset the X axis to give me this effect.

I tried a rough approach where I scaled the width of the panel by the zoom
factor and also shifted the left property as well. But as the width
increased the entire algorithm slowed down to a crawl because of all the
extra pixels involved.

So I really only want to deal with a drawable area that is say 800 pixels
wide, and then inside that area, draw the timeline, but start drawing
according to the offset on the X axis. I guess what is throwing me off is
the ScaleTransformation. It is behaving as expected but when it scales at 2X
or higher, I need to be able to scroll and see the same range of tick marks
as if it was scaling at 1X.

Does that make sense?

TIA!

Zach
 
J

James Westgate

When zooming into the timeline by say 2x, you need to double the
AutoScrollMinSize property - this will effectively double the area inside
the scrollable control. To check if a scroll has occurred, store the
AutoScrollPosition in a variable and compare it in every paint event. When
the scrollable control raises a paint event, the area to be repainted is
only the newly scrolled area. So you can either paint the whole control
every time, or draw to a bitmap and paint the requested rectangle from the
bitmap onto the control when scrolling - sort of a do it yourself double
buffering.

James
 
Z

Zach Nelson

Thanks guys. What I ended up doing was to not use the AutoScroll
functionality, and instead I have a Scroll-Left and Scroll-Right button.
When those are pressed I either add +100 or -100 to an Offset variable which
then gets passed to TranslateTransform(). The end result is that it appears
the timeline is scrolling to the right or the left. I just have to go back
and add logic to only allow you to scroll left or right to a certain extent
that is within the logical bounds of the timeline, otherwise you can scroll
too far in either direction.

Thanks for the input!

Zach
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top