Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Restricting zoom level  (Read 2933 times)

0 Members and 1 Guest are viewing this topic.

Torisuke

  • Newbie
  • *
  • Posts: 1
    • View Profile
Restricting zoom level
« on: February 15, 2011, 08:31:04 pm »
This is probably a newbie-ish issue, so I'm sorry for any wasted time this causes.

Anyways, I'm trying to limit the zoom of a view to never scale the view out farther than it's original size ( or zoomLevel zero as I've dubbed it).

 I currently have tried setting up a counter to increment on positive delta, and decrement on negative, with negative only affecting the zoom while the counter is above 0. No matter what way I write that, the zoom will never zoom out in the slightest with (zoomLevel > 0) requirement in place.

Thank you for your assistance.

Code: [Select]

unsigned int zoomLevel = 0;
while (App.GetEvent(Event))
        {
        if ((Event.Type == sf::Event::MouseWheelMoved) && (Event.MouseWheel.Delta > 0))
            {
                background.Zoom(1.1f);
                zoomLevel++;

            }
            else if((Event.Type == sf::Event::MouseWheelMoved) && (Event.MouseWheel.Delta < 0) && (zoomLevel > 0))
            {
                    background.Zoom(.9f);
                    zoomLevel--;
       
             };

};

lakunar

  • Newbie
  • *
  • Posts: 20
    • View Profile
Restricting zoom level
« Reply #1 on: February 20, 2011, 09:04:49 am »
Aren't you reseting zoomLevel every frame? ( Put it bevor while(App.IsOpen()) )

Code: [Select]

while (App.IsOpened()){
        unsigned int zoomLevel = 0;  <Reset
        while (App.GetEvent(Event))
        {  
              //events
        }
       //
}


You could also work with: sf::View::GetSize();

DoctorJ

  • Newbie
  • *
  • Posts: 21
    • View Profile
Restricting zoom level
« Reply #2 on: February 20, 2011, 05:09:33 pm »
Tori, when I try your code (with "background" being an sf::View which contains an image), it allows the user to zoom in (a smaller portion of the image fills the window) and zoom back out to the original size. Is that not what you were aiming to do?

A problem for you to tackle later is the inherent round off errors that creep in with zooming in and out: 1.1 is not the exact inverse of 0.9; and even if it were, round off errors will still creep in and eventually corrupt the view. Another way to handle the zooming is to use SetHalfSize and perform your own calculations based on zoomlevel.

 

anything