Cyotek Forums

Source Code => Source Code => Topic started by: fdcnred on May 16, 2014, 06:36:15 PM

Title: ZoomIn
Post by: fdcnred on May 16, 2014, 06:36:15 PM
I'm trying to integrate ImageBox in a quick viewer.  It's a great control.  The only problem I'm currently having is that the ZoomIn and ZoomOut always resets the scroll bars to top left.  Is there a way to zoom in with these functions and not reset the scroll bars?

Thanks,
Darren
Title: Re: ZoomIn
Post by: Richard Moss on May 17, 2014, 12:25:01 PM
Darren,

Thanks for your message! Are you using the NuGet package or the source version? If it's the source, try adding a new method similar to the following:

    public void ZoomInEx()
    {
      Point currentPixel;
      int currentZoom;
      Point relativePoint;

      relativePoint = this.CenterPoint;
      currentPixel = this.PointToImage(relativePoint);
      currentZoom = this.Zoom;

      this.ZoomIn();

      if (this.Zoom != currentZoom)
      {
        this.ScrollTo(currentPixel, relativePoint);
      }
    }


This will store the current position, apply the zoom, then reset the position to match - it's how the control does this in various places. You could then add a similar method for zooming out.

If you're using the package, you could add an extension method or stack method to do the same thing.

I do plan on addressing this properly in the next update as it's a bit daft that it's not exposed for programmatic access as opposed to user input.

Hope this helps!

Regards;
Richard Moss
Title: Re: ZoomIn
Post by: fdcnred on May 19, 2014, 01:52:03 PM
Perfect.  Thank you.  I have the source code but am using NuGet for my current project and got this to work.

Darren
Title: Re: ZoomIn
Post by: fdcnred on January 22, 2015, 01:58:13 PM
Richard,
Where to I make this fix in the latest Github version?  The code has changed fairly significantly and zoomin/out doesn't work right.

Thanks,
Darren
Title: Re: ZoomIn
Post by: Richard Moss on January 22, 2015, 06:26:54 PM
Hello,

What exactly are you trying to change and how is the zoom in/out not working correctly?

Regards;
Richard Moss
Title: Re: ZoomIn
Post by: fdcnred on January 22, 2015, 06:53:04 PM
Sorry I didn't make myself clear.  As discussed previously in this thread, if I zoom in with a rectangle zoom and then I zoom out with the magnifying glass icon the view/image always resets to the top left corner.  I'm like to see the ImageBox control modified so that it doesn't reset to the top left on zoom in or zoom out. 

I use the ZoomInEx() method as described above but what always happens is I get the latest code from one of your repositories then I try and run it and notice it's "broke" and have to figure out what I did to fix it last time.  Last time could be many moons ago and the code base could be completely different so it's more difficult to figure out.

I love ImageBox.

Thanks,
Darren
Title: Re: ZoomIn
Post by: Richard Moss on January 23, 2015, 05:36:27 PM
Darren,

Thanks for the clarification. I don't recall making any drastic changes that would break it, but I'll take a look and let you know what's up!

Regards;
Richard Moss
Title: Re: ZoomIn
Post by: Richard Moss on January 24, 2015, 09:02:43 AM
Darren,

I've just pushed a new update to GitHub. I haven't updated to the NuGet package yet, should probably wait until I am sure I haven't broken anything!

I've refactored the zoom code so that by default it will always try and preserve the original center point  (along with new ZoomIn and ZoomOut overloads that let you specify how you want the operation to behave if required). Regardless of if using the keyboard or mouse (or custom actions via ZoomIn/ZoomOut) it now goes through the same place.

You shouldn't need to use your custom "Ex" methods any more.

Give this update a whirl and let me know if it solves your problem - I didn't see anything obvious, but who knows.
Title: Re: ZoomIn
Post by: fdcnred on January 27, 2015, 02:35:19 PM
Looks good.  Thanks so much for the work.  This will make incorporating ImageBox much easier in future projects.