Last active
August 29, 2015 14:02
-
-
Save benjaminbojko/f38e88daab3a10b5ee7c to your computer and use it in GitHub Desktop.
[Cinder] Different Image Sizing Snippets
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using namespace ci; | |
enum Sizing { | |
//! Native resolution with no scaling | |
Native, | |
//! Fit exactly by scaling x/y independently | |
Fit, | |
//! Resize to fit at least mSize while maintaining aspect ratio | |
Aspect, | |
//! Resize to fit at most mSize while maintaining aspect ratio | |
AspectFit, | |
//! Resize to fit at least mSize while maintaining aspect ratio and cropping outside of mSize | |
AspectFill | |
}; | |
// ... | |
const void drawTexture(const gl::Texture& aTexture, const Rectf& aTargetRect, const Sizing aSizing = Native) { | |
switch (aSizing) { | |
case AspectFit: | |
gl::draw(aTexture, Rectf(aTexture.getBounds()).getCenteredFit(aTargetRect, true)); | |
break; | |
case AspectFill: | |
gl::draw(aTexture, Area(aTargetRect.getCenteredFit(aTexture.getBounds(), true)), aTargetRect); | |
break; | |
case Aspect: | |
gl::draw(aTexture, Area(aTargetRect.getCenteredFit(aTexture.getBounds(), true))); | |
break; | |
case Fit: | |
gl::draw(aTexture, aTargetRect); | |
break; | |
default: | |
case Native: | |
gl::draw(aTexture); | |
break; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment