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

Fixes for ofBitmapFont getBoundingBox(); #5611

Merged

Conversation

roymacdonald
Copy link
Member

  • incorrect use of numeric_limits::min() caused wrong results. Replaced for numeric_limits::lowest()
  • Added ofDrawBitmapMode mode = ofGetStyle().drawBitmapMode, bool vFlipped = ofIsVFlipped() arguments to getBoundingBox. This allows to get the correct mesh and doesn't break previous way of use of this function.

- incorrect use of numeric_limits<float>::min() caused wrong results. Replaced for numeric_limits<float>::lowest()
- Added  ofDrawBitmapMode mode, bool vFlipped arguments to getBounding.
@@ -418,11 +418,11 @@ ofMesh ofBitmapFont::getMesh(const string & text, int x, int y, ofDrawBitmapMode
if(text[c] == '\n'){

sy += lineHeight*newLineDirection;
if(mode == OF_BITMAPMODE_SIMPLE) {
// if(mode == OF_BITMAPMODE_SIMPLE) {
Copy link
Member

Choose a reason for hiding this comment

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

Can we remove of the commented parts?

Copy link
Member Author

Choose a reason for hiding this comment

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

I didn't remove this because I really don't understand why it it is there in first place although the most logical thing is that it shouldn't be there. If there's no problem removing it I will.

const ofMesh & mesh = getMesh(text,x,y);
glm::vec2 max(numeric_limits<float>::min(),numeric_limits<float>::min());
const ofMesh & mesh = getMesh(text,x,y, mode, vFlipped);
glm::vec2 max(numeric_limits<float>::lowest(),numeric_limits<float>::lowest());
Copy link
Member

Choose a reason for hiding this comment

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

Nice find.

Copy link
Member Author

Choose a reason for hiding this comment

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

:)

@@ -22,7 +23,7 @@ class ofBitmapFont{
~ofBitmapFont();
ofMesh getMesh(const string & text, int x, int y, ofDrawBitmapMode mode=OF_BITMAPMODE_MODEL_BILLBOARD, bool vFlipped=true) const;
const ofTexture & getTexture() const;
ofRectangle getBoundingBox(const string & text, int x, int y) const;
ofRectangle getBoundingBox(const string & text, int x, int y, ofDrawBitmapMode mode = ofGetStyle().drawBitmapMode, bool vFlipped = ofIsVFlipped()) const;
Copy link
Member

Choose a reason for hiding this comment

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

ofGetStyle().drawBitmapMode looks funny, but I'm assuming it's the only way to do this to preserve backward compatibility right?

Copy link
Member

Choose a reason for hiding this comment

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

... to clarify "looks funny" .. to call a member variable of a global instance as a default parameter in a function. Typically I avoid non-constant default parameters because they are ... not constant :)

Copy link
Member

Choose a reason for hiding this comment

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

... and therefore the idea of a "default" gets murky.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ha, right. There seems to be no other way to get the current bitmap mode. And right, it also looked funny to me, but it is there to keep backwards compatibility.

@roymacdonald
Copy link
Member Author

@arturoc @bakercp any chance to merge this PR?

@arturoc arturoc merged commit 111c89d into openframeworks:master Jul 4, 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.

None yet

3 participants