Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fit map in view does not work when tile size is 1 #3524

Open
NworbLegin opened this issue Nov 14, 2022 · 9 comments
Open

Fit map in view does not work when tile size is 1 #3524

NworbLegin opened this issue Nov 14, 2022 · 9 comments
Labels
bug Broken behavior.

Comments

@NworbLegin
Copy link

Describe the bug
The "Fit Map In View" function does not work when there is a high tile count. (e.g. 600 x 400 tiles at a tile width height of 8x8)

To Reproduce
Steps to reproduce the behavior:

  1. From the menu select File->New->New Map...
  2. Set the settings to a tile size of 8px x 8px and a Fixed number of tiles to be Width 600 and Height 400.
  3. Press OK
  4. The map is initially now shown filling the view
  5. Press ctrl+/ or Menu->View->Fit Map In View
  6. Observe that the map is not sized to fit in the view

Expected behavior
I would expect that any configuration of map tile size and width/height would be able to be scaled to fit within the view when Fit Map To View is actioned.

Specifications:

  • OS: Windows 10 x64
  • Tiled Version: 1.9.2 - but I don't think this has ever worked correctly ;-)
@NworbLegin NworbLegin added the bug Broken behavior. label Nov 14, 2022
@eishiya
Copy link
Contributor

eishiya commented Nov 14, 2022

Looking at the code, this behaviour is intentional:

tiled/src/tiled/mapview.cpp

Lines 157 to 165 in 48c4f85

// Scale and center map to fit in view, while avoiding to go below the
// minimum scale. For extremely large maps, avoid putting more than about
// 256 * 256 tiles within the view for performance reasons.
qreal desiredScale = std::min(width() / rect.width(),
height() / rect.height()) * 0.95;
auto tileSize = mMapDocument->map()->tileSize();
qreal scale256 = std::min(width() / (256.0 * tileSize.width()),
height() / (256.0 * tileSize.height()));

However, I'd also rather see the map zoomed out, even if that means lag. The main use of Fit Map in View is to deal with large maps, I feel. A performance hit is an acceptable price, especially since users who find this feature not working as expected for large maps are likely to zoom out anyway.

@NworbLegin
Copy link
Author

Yep - I would agree that the performance hit is acceptable. Maybe this could be on a user preference setting? "Allow large fit in view"

@NworbLegin
Copy link
Author

I have implemented this on a local build and will generate a branch and pull-request when I have time.

NworbLegin added a commit to ImpromptuSoftware/tiled that referenced this issue Nov 15, 2022
- The discussion here mapeditor#3524
- An additional check box has been added to the preferences.ui view and preferencesdialog.cpp
- The parameter is exposed within mapview.h as noZoomLimitEnabled
- The new parameter is used in mapview.cpp to enable or disable the use of scale limiting
@eishiya
Copy link
Contributor

eishiya commented Nov 29, 2022

I'm not even sure this needs to be a user preference, it seems like clutter to me. I think users working with large maps expect some performance hitches sometimes, and all this option does is make Fit Map in View not do what it says. I think users for who this performance optimization might make a positive difference would quickly learn not to use Fit Map in View at all :'D

@NworbLegin
Copy link
Author

NworbLegin commented Nov 29, 2022

Yep - I'm tempted to agree. Is the Fit Map in View ever called outside of user control? e.g. when opening a map for the first time?

@eishiya
Copy link
Contributor

eishiya commented Nov 29, 2022

Not that I can find. fitInView() and fitMapInView() are only called via the action. When creating or opening new maps, Tiled seems to use 100% zoom centred on 0,0.

@NworbLegin
Copy link
Author

Okay - Shall I amend my commit request to remove the user settings and make the feature work without restrictions?

@eishiya
Copy link
Contributor

eishiya commented Nov 29, 2022

I think it would be good to hear @bjorn's opinion, perhaps there's some reason for the performance mindfulness that we've both overlooked.

@bjorn
Copy link
Member

bjorn commented Dec 4, 2022

Is the Fit Map in View ever called outside of user control? e.g. when opening a map for the first time?

Yes, in this piece of code:

tiled/src/tiled/mapview.cpp

Lines 461 to 468 in 7fa253f

if (!mViewInitialized) {
mViewInitialized = true;
if (mHasInitialCenterPos)
forceCenterOn(mInitialCenterPos);
else
fitMapInView();
}

If needed, we can of course differentiate between the automatic version and the manual action, such that only the automatic case has a minimum zoom level.

I would personally also like to avoid adding an option for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Broken behavior.
Projects
None yet
Development

No branches or pull requests

3 participants