Jump to content

Map zoom


Recoil

Recommended Posts

I have a NumericUpDown control (nudZoomFactor).  It is set at 1.0.  Minimum is 0.5.  Maximum is 2.0

In it's value changed event, it sets a double variable (ZoomFactor) to its value, then calls to adjust the scroll bars on bottom and right side of the panel that holds the picturebox for the map:

    Private Sub nudZoomFactor_ValueChanged(sender As Object, e As EventArgs) Handles nudZoomFactor.ValueChanged

        If InGame = False Then Exit Sub

        ZoomFactor = nudZoomFactor.Value

        AdjustMapScrollbars()

    End Sub

This same sub is called when the form maximizes, to either show or hide the scrollbars depending on the maps picturebox size in relation to the parent panel's size.  If they are to show, it will set the max value of the scrollbar, because of the various resolutions this app will go up to:

Public Sub AdjustMapScrollbars()

        DmScreen.picDmScreen.Location = New Point(0, 0)
        DmScreen.picDmScreen.Size = New Size(((Map(CurrentMap).MaxX) * PicX), ((Map(CurrentMap).MaxY) * PicY))
        If DmScreen.picDmScreen.Width > DmScreen.panDmScreenBack.Width Then
            DmScreen.scrlBottomScreen.Visible = True
            DmScreen.scrlBottomScreen.Maximum = (DmScreen.picDmScreen.Width / PicX - (DmScreen.panDmScreenBack.Width / PicX))
        Else
            DmScreen.scrlBottomScreen.Visible = False
            DmScreen.scrlBottomScreen.Maximum = (DmScreen.picDmScreen.Width / PicX)
        End If

        If DmScreen.picDmScreen.Height > DmScreen.panDmScreenBack.Height Then
            DmScreen.scrlRightScreen.Visible = True
            DmScreen.scrlRightScreen.Maximum = (DmScreen.picDmScreen.Height / PicY - (DmScreen.panDmScreenBack.Height / PicY))
        Else
            DmScreen.scrlRightScreen.Visible = False
            DmScreen.scrlRightScreen.Maximum = (DmScreen.picDmScreen.Height / PicY)
        End If

    End Sub

In Render_Graphics() I am setting the amount to zoom in:

DmWindow.SetView(New View(New FloatRect(0, 0, (MaxMapX * PicX) / ZoomFactor, (MaxMapY * PicY) / ZoomFactor)))

Now, when I change the value of nudZoomFactor, it resets the view back to 0,0 from the SetView, until I move a scroll bar.  Now, when I scroll all the way to the right, or all the way to the bottom it will show a big black area over the right and bottom of the map.  The more I zoom in, the wider the black areas are.

The goal here is when I zoom in, still be able to scroll the full width and height of the map without the black bars.  I have tried adjusting the settings in the UpdateCamera sub, but changing those values to either multiply or divide by the ZoomFactor, they do nothing to the viewable ares of the window.

Link to comment
Share on other sites

Okay, so the solution is stupid...posting this here just in case anyone runs into it...but doubtful.

This key bit of code adjust the size of my map window depending on how large the map width and height are.  This is because my app supports various resolutions:

DmScreen.picDmScreen.Size = New Size(((Map(CurrentMap).MaxX) * PicX), ((Map(CurrentMap).MaxY) * PicY))

This is what I have been trying because I need to window size to scale, so the scrollbars work properly.  It needs to scale by the double value of the nudZoomFactor:

DmScreen.picDmScreen.Size = New Size(((Map(CurrentMap).MaxX) * PicX) * ZoomFactor, ((Map(CurrentMap).MaxY) * PicY) * ZoomFactor)

I have also been dividing by the ZoomFactor variable.  I pulled this bit of insight from the SFML tutorials, thinking this would work...it DID appear to work at first:

DmWindow.SetView(New View(New FloatRect(0, 0, (MaxMapX * PicX) / ZoomFactor, (MaxMapY * PicY) / ZoomFactor)))

But the reason I kept running into my issue with the black bars WAS because of that last nugget of wisdom.  Since I am already scaling the width and height of the map window by the ZoomFactor, that is all it took and I did not have to include this...which would have saved me several hours.  In the examples for SFML the were not changing the size of the window...they were scaling IN on the window they had already.

In short, if you are changing the size of the map window, you do not need to scale the SetView of the TextureWindow.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...