Viewport? Some advice needed

Hi all,

Just looking for some advice here. I’m working on a table editor at the moment. These tables can contain pretty much anything - audio files, envelopes etc. I’ve got a rough version working which paints the amplitude values (y) over time (x)…just like a normal editor.
However, I’m looking to get a zoom and scrollbar going. Would using the viewport class be the best for this? Would I need to make my table component a child component of viewport and then viewport would automatically display the correct data depending on the scrollbar’s location?

Thanks…

Hi omen,
I think the answer is pretty much yes. The scrollbars will update your editor’s position.
As for the zoom, well, you’ll need to come up with an algorithm to calculate the size of your editor and then the Viewport will adapt the scrollbars automatically.

Thanks. I’ve got the horizontal scroll working. The repainting is extremely intensive on the CPU though. What would be the most efficient way of doing this? I don’t think caching would work since the window will be displaying different information depending on the scrollbar’s position?

Maybe this could help you:
http://www.rawmaterialsoftware.com/viewtopic.php?f=2&t=5615&hilit=viewport

Basically you should display (repaint) just the stuff that’s visible.
My approach usually is this:

[code]//Inside the paint callback in your Component
Viewport* const viewport = findParentComponentOfClass ((Viewport*) nullptr); //Get the parent viewport
if(viewport != nullptr) //Check for nullness
{
Rectangle viewRect(viewport->getViewPositionX(), viewport->getViewPositionY(), viewport->getViewWidth(), viewport->getViewHeight()); //Get the current displayed area in the viewport

// … based on the displayed area, paint just what’s visible … //
}
[/code]

Thanks for your help. That works better. I’ve also tried putting the whole image to cache and it scrolls much better.
My main issue now is getting the zoom to be faster as I’m constantly updating arrays with amp values. For instance, when I zoom in the block samples that each x-axis pixel represents get smaller, and therefore my arrays get bigger, if that makes sense?!