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

Added Scale3Bitmap and Scale9Bitmap display objects #281

Closed
wants to merge 2 commits into from
Closed

Added Scale3Bitmap and Scale9Bitmap display objects #281

wants to merge 2 commits into from

Conversation

joshtynjala
Copy link

Scale3Bitmap: Supports three regions, for a pill-shaped scaling bitmap. Can be horizontal or vertical. Center region stretches in both directions to fill available space. If outer regions are scaled, they will maintain aspect ratio.

Scale9Bitmap: Supports nine regions, similar to scale9Grid that is available to Flash display objects.

In both cases, scaling can be controlled by setting drawWidth and drawHeight or by calling setDrawSize(). These values will default to the width and height of the image that is passed into the constructor. I chose these names to avoid conflicts that may arise if EaselJS ever adds width, height, or setSize().

@gskinner
Copy link
Member

Quick question, just to understand the architecture - is there a significant benefit to having two classes versus just a single class with an extra property to define horizontal/vertical/both? Just curious if there is significant code/logic duplication with the current approach?

@joshtynjala
Copy link
Author

I guess you could simulate Scale3Bitmap with Scale9Bitmap, with a tweak to Scale9Bitmap. Scale3Bitmap has extra logic to scale its caps while maintaining their aspect ratio if the shorter edge is scaled. This keeps perfectly rounded caps from being stretched in only one direction. Scale9Bitmap could do the same thing when it sees that the inner rectangle has a width or height of 0.

A disadvantage of doing it that way is that Scale9Bitmap would draw to the canvas six times, while Scale3Bitmap is always three times. Maybe that could be optimized, though.

@gskinner
Copy link
Member

Just checking - always nice to have one class and less code if it still makes sense. Thanks Josh.

…ss. Scale3Bitmap features are now a special case when the scale9Grid width or height is zero.
@joshtynjala
Copy link
Author

Yeah, one class probably makes more sense. As I mentioned above, the Scale3Bitmap's behavior can be a special case if the scale9Grid width or height is zero. I was able to ensure that it only draws to the canvas three times when this special case arises.

@thejustinwalsh
Copy link

What is the status of this feature? Are we to see it in the master branch or a future version anytime soon?

@gskinner
Copy link
Member

Quick update: this is being looked at now, after a ridiculously long delay.

@lannymcnie
Copy link
Member

This has been manually added to EaselJS, but is currently in the "Extras" folder, along with a sample and a readme. We need to evaluate how this might work with SpriteSheets.

Thanks for the pull request, this is a great addition!

@lannymcnie lannymcnie closed this Oct 23, 2014
@joshtynjala
Copy link
Author

Cool. Thank you!

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

Successfully merging this pull request may close these issues.

None yet

4 participants