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

- Add option to scale Ninepatch #1801

Closed
wants to merge 1 commit into from
Closed

- Add option to scale Ninepatch #1801

wants to merge 1 commit into from

Conversation

@obigu
Copy link
Contributor

obigu commented May 4, 2014

See #1800

@obigu
Copy link
Contributor Author

obigu commented May 4, 2014

Duplicated issue

@obigu obigu closed this May 4, 2014
@NathanSweet NathanSweet reopened this May 4, 2014
@NathanSweet
Copy link
Member

NathanSweet commented May 4, 2014

NinePatch has two parts: 1) the regions that it will draw and 2) the size at which they are drawn. Instead of scaleX/Y fields, you can just set the size the regions are drawn, eg:

NinePatch ninePatch = new NinePatch(texture, 24, 24, 24, 24);
ninePatch.setLeftWidth(24 * 0.3f);
ninePatch.setRightWidth(24 * 0.3f);
ninePatch.setTopHeight(24 * 0.3f);
ninePatch.setBottomHeight(24 * 0.3f);

This also means we avoid a few multiplies for each draw.

@obigu
Copy link
Contributor Author

obigu commented May 4, 2014

Thanks Nate, that solves the problem in a much more elegant way.

Maybe, as a suggestion, we could add a setScale(float scale) method to NinePatch to provide an easy way to apply a change to all sizes.

Usually NinePatch regions will be generated by an Atlas and the size of the regions may be unknow so, intead of writing:

ninePatch.setLeftWidth(ninePatch.getLeftWidth() * 0.3f);
ninePatch.setRightWidth(ninePatch.getRightWidth() * 0.3f);
ninePatch.setTopHeight(ninePatch.getTopHeight() * 0.3f);
ninePatch.setBottomHeight(ninePatch.getBottomHeight() * 0.3f);

we can just call

ninePatch.setScale(0,3f);
@NathanSweet
Copy link
Member

NathanSweet commented May 5, 2014

Done! Forgot to link the commit.

@NathanSweet NathanSweet closed this May 5, 2014
@dylanritter
Copy link

dylanritter commented Feb 9, 2015

Hi, is there a convenient way to set a ninepatch scale without having to manually construct and then pass in the drawable to an actor ? For example, when creating a TextButton it's very convenient to specify a style name and then leave it at that, however with the 'setScale' method on the ninepatch itself it seems that it would require instantiating each of the possible drawables (up, down, etc.) and scaling those then setting them up in the button, thus destroying the elegance of using the style in the TextButton constructor.

I guess what i'm looking for is that the setScale method on the button instance would apply itself to the backgrounds in the style being used.

so something like this:

TextButton btn = new TextButton("title", myStyle);
btn.setScale(.5f, .5f);

While we are here, i haven't found any effect of using the setScale method on an actor, everything seems to draw at the same size regardless and have always had to resort to manually scaling actors in setSize or .width().height() when using a table.

Thank you,

Dylan

@NathanSweet
Copy link
Member

NathanSweet commented Feb 9, 2015

This is an issue tracker, IRC or the forums are more appropriate for questions.
https://github.com/libgdx/libgdx/wiki/Getting-help
https://github.com/libgdx/libgdx/wiki/Scene2d.ui#rotation-and-scale
It sounds like you want to create a scaled up style, then use that for your buttons. Most people use multiple ninepatch regions each of the desired size rather than scaling their images.

@dylanritter
Copy link

dylanritter commented Feb 9, 2015

Thank you for your reply. I have further questions on this so will go to the forums as you suggest.
Dylan

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

3 participants
You can’t perform that action at this time.