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

Adds Autocrop feature #1574

Merged
merged 4 commits into from
Jun 3, 2017
Merged

Adds Autocrop feature #1574

merged 4 commits into from
Jun 3, 2017

Conversation

ketanhwr
Copy link
Contributor

This addresses #642. The option is available in the 'Map' menu and is available only when a Tile Layer is selected. The implementation is pretty straightforward:

  • First compute the (minX, minY) and (maxX, maxY) by checking all the cells of the current layer.
  • Resize the map using this region.
  • Works similar to Crop to Selection, except, the region is calculated using TileLayer::computeAutocropRegion()

Copy link
Contributor

@Ablu Ablu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added some comments for now

src/libtiled/tilelayer.cpp Outdated Show resolved Hide resolved
src/tiled/mainwindow.cpp Outdated Show resolved Hide resolved
if (bounds.isNull())
return;

resizeMap(bounds.size(), -bounds.topLeft(), true);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm... The boundary check only considers tiles... @bjorn Is it fine to silently delete objects (the third parameter) which are not in the area here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The option of Crop to Selection behaves in a similar way. It also deletes the objects outside the selected region. I took that under consideration.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I think it's reasonable for this to be consistent with "Crop to Selection". There isn't really an opportunity to ask the user here, unless we'd introduce a popup, which I don't really want to.

src/tiled/mapdocument.cpp Outdated Show resolved Hide resolved
src/tiled/mapdocument.cpp Outdated Show resolved Hide resolved
src/tiled/mapdocument.cpp Outdated Show resolved Hide resolved
src/tiled/mapdocumentactionhandler.cpp Outdated Show resolved Hide resolved
}
} else {
mActionSelectNone->setEnabled(false);
mActionAutocrop->setEnabled(false);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will be more readable to put one line below together with mActionCropToSelection like this:

mActionAutocrop->setEnabled(currentLayer && currentLayer->isTileLayer());

The mActionSelectNone needed all this special code only because the condition on whether it should be enabled or not varies depending on the type of the selected layer, but let's not "abuse" all those cases for setting the state of mActionAutocrop.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice idea 🙂

src/tiled/mapdocumentactionhandler.h Outdated Show resolved Hide resolved
Copy link
Member

@bjorn bjorn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apart from two small nitpicks about whitespace, this change is ready to go in.

I will wait with merging it until I have created the 1.0 branch, since due to the string freeze this feature will go to Tiled 1.1.

Thanks!

src/tiled/mainwindow.cpp Outdated Show resolved Hide resolved
src/tiled/mapdocument.cpp Outdated Show resolved Hide resolved
@ketanhwr
Copy link
Contributor Author

ketanhwr commented Jun 3, 2017

@bjorn I think you forgot this one 🙂

@bjorn bjorn merged commit ac307f1 into mapeditor:master Jun 3, 2017
@bjorn
Copy link
Member

bjorn commented Jun 3, 2017

@ketanhwr Indeed, I haven't created an 1.0 branch yet, but I implicitly ended the string freeze by merging #1580, so this one can go in now as well. Thanks for the reminder! :-)

thabetx pushed a commit to thabetx/tiled that referenced this pull request Jun 7, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants