Skip to content

Instantly share code, notes, and snippets.

@moebiussurfing
Created July 15, 2020 00:13
Show Gist options
  • Save moebiussurfing/3d7685ebfe9aa688197ea0003c7a3245 to your computer and use it in GitHub Desktop.
Save moebiussurfing/3d7685ebfe9aa688197ea0003c7a3245 to your computer and use it in GitHub Desktop.
openFrameworks / easy simple drawTextBoxed helper util
//ofApp.h
ofTrueTypeFont font;
float fontSize;
//--------------------------------------------------------------
void drawTextBoxed(string text, int x, int y, int alpha = 255)
{
ofPushStyle();
int pad = 20;
if (!font.isLoaded()) {
ofDrawBitmapStringHighlight(text, x, y);
}
else {
//bbox
ofSetColor(0, alpha);
ofFill();
ofRectangle _r(font.getStringBoundingBox(text, x, y));
_r.setWidth(_r.getWidth() + pad);
_r.setHeight(_r.getHeight() + pad);
_r.setX(_r.getPosition().x - pad / 2.);
_r.setY(_r.getPosition().y - pad / 2.);
ofDrawRectangle(_r);
//text
ofSetColor(255, 255);
ofNoFill();
font.drawString(text, x, y);
}
ofPopStyle();
}
//--------------------------------------------------------------
float getWidthBBtextBoxed(string text) {
return (font.getStringBoundingBox(text,0,0)).getWidth();
}
//--
//ofApp.cpp
//setup
fontSize = 15;
font.load(OF_TTF_MONO, fontSize);
//--------------------------------------------------------------
void ofxGpuLutCube::drawHelp()
{
//info
string str;
str += "PRESS UP/DOWN TO BROWSE '.cube' FILES\n";
str += "FROM FOLDER 'data/" + path_LUT_files + "/'\n";
str += "[" + ofToString(lutIndex) + "/" + ofToString(numLuts - 1) + "] " + ofToString(LUTname);
drawTextBoxed(str, 10, 20);
//debug filename
float w = getWidthBBtextBoxed(LUTname);
float x = ofGetWidth() * 0.5f - w * 0.5f;
float y = ofGetHeight() - 75;
drawTextBoxed(LUTname, x, y);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment