openframeworks/openFrameworks — pull request #1513 by bakercp (2012-08-27 22:13:37+00:00)
Title: Proposed update to ofRectangle::ScaleIntoMe - now with more scaling modes. 

Since implementing @ofzach's suggestion for the recently added `ofRectangle::ScaleIntoMe()` method (see PR #1332), I have started using it quite extensively.

In using it, I have found a lot of other situations where other scaling modes based on an existing rectangle would be quite useful. While there are other ways to do it, this would be useful when scaling an image into an FBO like this:

```c++
void Layer::drawFrameIntoFbo(ofImage* image, ofFbo* fbo, ofRectScaleMode mode) {
fbo->begin();
ofClear(0,0,0,0);

ofRectangle fboRect(0,0,fbo->getWidth(),fbo->getHeight());
ofRectangle imageRect(0,0,image->getWidth(),image->getHeight());

ofRectangle scaledRect = fboRect.scaleToMe(imageRect,mode);

image->draw(scaledRect);

fbo->end(); // end the fbo
}
```

This PR proposes the addition of an enum called `ofRectScaleMode`. And a change from `ofRectangle::ScaleIntoMe()` to `ofRectangle::ScaleToMe()` to capture the idea that `ofRectangle` can be scaled by other `ofRectangle`s in a variety of ways. It would be nice to get this method name change in before the next release so we won't have to worry about backward compatibility.

The original `ofRectangle::ScaleIntoMe()` might best be described as a "fit" scaling operation. The new `ofRectangle::ScaleToMe()` uses `OF_RECTSCALEMODE_FIT` by default.

Below is the new enum with comments. Comments are also included in the commit, and should possibly be removed before any merges.

```c++
enum ofRectScaleMode{
// fits the SUBJECT rect INSIDE the TARGET rect.
// Preserves SUBJECTS's aspect ratio.
// Final Subject's Area <= Target's Area.
// Subject's Center == Target's Center
OF_RECTSCALEMODE_FIT = 0,
// FILLS the TARGET rect with the SUBJECT rect.
// Preserves the SUBJECT's aspect ratio.
// Subject's Area >= Target's Area.
// Subject's Center == Target's Center
OF_RECTSCALEMODE_FILL = 1,
// Preserves the SUBJECT's aspect ratio.
// Subject's Area is Unchanged
// Subject's Center == Target's Center
OF_RECTSCALEMODE_CENTER = 2, // centers the subject
// Can CHANGE the SUBJECT's aspect ratio.
// Subject's Area == Target's Area
// Subject's Center == Target's Center
OF_RECTSCALEMODE_STRETCH = 3, // simply matches the target dims
};
```

If you would like to see it in action and try it out, here is a test app https://gist.github.com/3492711.

If you want to compare it to a another familiar paradigm, on a mac go to System Preferences -> Desktop & Screensaver -> Desktop and you can scale your desktop image similarly. I believe there is a similar option in windows + Linux, but I don't have it in front of me.