Last active
February 25, 2016 17:50
-
-
Save roymacdonald/98f07ca6ad66d76f2272 to your computer and use it in GitHub Desktop.
Testing ofDrawBitmapString bounding box
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
#pragma once | |
#include "ofMain.h" | |
class ofApp : public ofBaseApp{ | |
public: | |
void setup(){ | |
mode = OF_BITMAPMODE_SIMPLE; | |
clic.set(200,200); | |
} | |
void draw(){ | |
string modeText; | |
switch (mode) { | |
case OF_BITMAPMODE_SIMPLE: | |
modeText += "OF_BITMAPMODE_SIMPLE"; | |
break; | |
case OF_BITMAPMODE_SCREEN: | |
modeText += "OF_BITMAPMODE_SCREEN"; | |
break; | |
case OF_BITMAPMODE_VIEWPORT: | |
modeText += "OF_BITMAPMODE_VIEWPORT"; | |
break; | |
case OF_BITMAPMODE_MODEL: | |
modeText += "OF_BITMAPMODE_MODEL"; | |
break; | |
case OF_BITMAPMODE_MODEL_BILLBOARD: | |
modeText += "OF_BITMAPMODE_MODEL_BILLBOARD"; | |
break; | |
default: | |
break; | |
} | |
string drawText; | |
if(!text.empty()){ | |
drawText = text + "\n\n" + modeText; | |
}else{ | |
drawText = modeText; | |
} | |
ofSetColor(ofColor::red); | |
ofDrawRectangle(f.getBoundingBox(drawText, clic.x, clic.y)); | |
ofSetColor(ofColor::black); | |
ofDrawBitmapString(drawText, clic.x, clic.y); | |
ofSetColor(255); | |
f.getMesh(drawText, clic.x, clic.y, mode).drawWireframe(); | |
string info = "Click somewhere to set the positon of the text\n"; | |
info += "Type something to add it to the text\n"; | |
info += "Press the return key to add new line\n"; | |
info += "Press the delete key to delete the last character\n"; | |
info += "Pres keys 0 to 4 to change the bitmap rendering mode"; | |
ofDrawBitmapStringHighlight(info, 20,20); | |
} | |
void keyPressed(int key){ | |
if(key == OF_KEY_RETURN){ | |
text += "\n"; | |
}else if(key >= '0' && key <= '4'){ | |
mode = ofDrawBitmapMode(key -'0'); | |
}else{ | |
text += key; | |
} | |
} | |
void mouseReleased(int x, int y, int button){ | |
clic.set(x,y); | |
} | |
ofBitmapFont f; | |
ofVec2f clic; | |
string text; | |
ofDrawBitmapMode mode; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment