cleanup, add getProps()

This commit is contained in:
jrkb 2023-03-29 20:46:54 +02:00
parent a838cfcaeb
commit 9728c288b5
2 changed files with 38 additions and 36 deletions

View file

@ -44,8 +44,6 @@ void MsdfLayer::draw(glm::vec3 position) const {
ofSetColor(ofColor::pink); ofSetColor(ofColor::pink);
ofDrawLine(glm::vec2(0, 0), glm::vec2(ofGetWidth(), 0)); ofDrawLine(glm::vec2(0, 0), glm::vec2(ofGetWidth(), 0));
ofPopStyle(); ofPopStyle();
//atlas->getAtlasImage().draw(0, 0);
//cout << "drawing letters (" << ofToString(propsBuffer.size()) << ")" << endl;
char previous_c; char previous_c;
bool firstLetter = true; bool firstLetter = true;
for(const char c : propsBuffer[0].text){ for(const char c : propsBuffer[0].text){
@ -67,7 +65,7 @@ void MsdfLayer::draw(glm::vec3 position) const {
float magic = ofMap(sin(ofGetElapsedTimeMicros() * 0.000001), -1, 1, 1, 200); float magic = ofMap(sin(ofGetElapsedTimeMicros() * 0.000001), -1, 1, 1, 200);
magic = atlas->settings.scale; magic = atlas->settings.scale;
auto fontMetrics = atlas->getFontGeometry().getMetrics(); auto fontMetrics = atlas->getFontGeometry().getMetrics();
float cender = (fontMetrics.ascenderY-fontMetrics.descenderY); float cender = (fontMetrics.ascenderY - fontMetrics.descenderY);
//magic *= cender; //magic *= cender;
//if(ofGetFrameNum() % 30 == 0){ //if(ofGetFrameNum() % 30 == 0){
//cout << "drawing letter " << c << endl //cout << "drawing letter " << c << endl
@ -80,36 +78,36 @@ void MsdfLayer::draw(glm::vec3 position) const {
//ofPushMatrix(); //ofPushMatrix();
//for(int i = 0; i < 2; i++){ //for(int i = 0; i < 2; i++){
//if(i == 1){ //if(i == 1){
//ofRotateDeg(90); //ofRotateDeg(90);
//ofTranslate(400, -150, 0); //ofTranslate(400, -150, 0);
//} //}
//ofNoFill(); //ofNoFill();
//ofSetColor(ofColor::white); //ofSetColor(ofColor::white);
//ofDrawLine(glm::vec2(0, 90), glm::vec2(0, 140)); //ofDrawLine(glm::vec2(0, 90), glm::vec2(0, 140));
//ofSetColor(ofColor::lightGray); //ofSetColor(ofColor::lightGray);
//for(int i = 1; i < 3; i++){ //for(int i = 1; i < 3; i++){
//ofDrawLine(glm::vec2(i * 20, 90), glm::vec2(i * 20, 140)); //ofDrawLine(glm::vec2(i * 20, 90), glm::vec2(i * 20, 140));
//} //}
//ofFill(); //ofFill();
//if(i == 0){ //if(i == 0){
//ofSetColor(ofColor::red); //ofSetColor(ofColor::red);
//ofDrawRectangle(0, 100, pl * 50, 10); //ofDrawRectangle(0, 100, pl * 50, 10);
//ofSetColor(ofColor::lightBlue); //ofSetColor(ofColor::lightBlue);
//ofDrawRectangle(0, 120, pr * 50, 10); //ofDrawRectangle(0, 120, pr * 50, 10);
//ofSetColor(ofColor::green); //ofSetColor(ofColor::green);
//ofDrawRectangle(0, 130, gg.getAdvance() * 50, 10); //ofDrawRectangle(0, 130, gg.getAdvance() * 50, 10);
//ofDrawBitmapStringHighlight(ofToString(gg.getAdvance()), 0, 150); //ofDrawBitmapStringHighlight(ofToString(gg.getAdvance()), 0, 150);
//ofDrawBitmapStringHighlight(ofToString(pl), 0, 170); //ofDrawBitmapStringHighlight(ofToString(pl), 0, 170);
//ofDrawBitmapStringHighlight(ofToString(pb), 0, 190); //ofDrawBitmapStringHighlight(ofToString(pb), 0, 190);
//ofDrawBitmapStringHighlight(ofToString(pr), 0, 210); //ofDrawBitmapStringHighlight(ofToString(pr), 0, 210);
//ofDrawBitmapStringHighlight(ofToString(pt), 0, 230); //ofDrawBitmapStringHighlight(ofToString(pt), 0, 230);
//}else{ //}else{
//ofSetColor(ofColor::green); //ofSetColor(ofColor::green);
//ofDrawRectangle(0, 110, pb * 50, 10); //ofDrawRectangle(0, 110, pb * 50, 10);
//ofSetColor(ofColor::yellow); //ofSetColor(ofColor::yellow);
//ofDrawRectangle(0, 130, pt * 50, 10); //ofDrawRectangle(0, 130, pt * 50, 10);
//} //}
//} //}
//ofPopMatrix(); //ofPopMatrix();
shader->begin(); shader->begin();
@ -127,8 +125,8 @@ void MsdfLayer::draw(glm::vec3 position) const {
std::map <std::pair <int, int>, double>::const_iterator it = kerning.find(std::make_pair <int, int>(gg_previous.getIndex(), gg.getIndex())); std::map <std::pair <int, int>, double>::const_iterator it = kerning.find(std::make_pair <int, int>(gg_previous.getIndex(), gg.getIndex()));
if(it != kerning.end()){ if(it != kerning.end()){
advance += it->second; advance += it->second;
ofDrawBitmapStringHighlight(ofToString(it->second), 0, 200, ofColor::black, ofColor::pink); ofDrawBitmapStringHighlight(ofToString(it->second), 0, 200, ofColor::black, ofColor::pink);
} }
ofPushStyle(); ofPushStyle();
ofFill(); ofFill();
@ -167,6 +165,9 @@ void Layer::setProps(const Props & props){
} }
propsBuffer.push_front(props); propsBuffer.push_front(props);
} }
const Layer::Props & Layer::getProps() const {
return propsBuffer[0];
}
void Layer::clearPropsBuffer(){ void Layer::clearPropsBuffer(){
propsBuffer.clear(); propsBuffer.clear();
} }

View file

@ -34,7 +34,7 @@ class Layer {
bool mirror_y = false; bool mirror_y = false;
float mirror_y_distance = 0; float mirror_y_distance = 0;
float letterDelay = 0; float letterDelay = 0;
string text = "quickmonkeythedogASYAHELLO"; string text = "ASYA is the best";
}; };
struct Settings { struct Settings {
uint32_t maxBufferSize = 100; uint32_t maxBufferSize = 100;
@ -43,6 +43,7 @@ class Layer {
void update(); void update();
virtual void draw(glm::vec3 position = glm::vec3(0, 0, 0)) const = 0; virtual void draw(glm::vec3 position = glm::vec3(0, 0, 0)) const = 0;
void setProps(const Props & props); void setProps(const Props & props);
const Props & getProps() const;
//void setProps(float _x, //void setProps(float _x,
//float _y, //float _y,
//float _rotation, //float _rotation,