clean some comments and anchor -> textAlignment

This commit is contained in:
jrkb 2023-09-06 18:54:22 +02:00
parent d97ed744d9
commit f25225182e

View file

@ -225,8 +225,8 @@ void GPUFontAtlasLayerCombo::draw(int width, int height){
vertices.resize(totalCharacters * 4); vertices.resize(totalCharacters * 4);
indices.resize(totalCharacters * 6); indices.resize(totalCharacters * 6);
std::vector <ofVboMesh> outerBoundingBoxes; //std::vector <ofVboMesh> outerBoundingBoxes;
ofRectangle r; //ofRectangle r;
for(const auto & layer : layers){ for(const auto & layer : layers){
OFX_PROFILER_SCOPE("draw layer"); OFX_PROFILER_SCOPE("draw layer");
float ascender = font->getAscender(layer->getProps().fontSize_px); float ascender = font->getAscender(layer->getProps().fontSize_px);
@ -279,23 +279,23 @@ void GPUFontAtlasLayerCombo::draw(int width, int height){
mirror_bbs.push_back(std::move(bb_mirror_none)); mirror_bbs.push_back(std::move(bb_mirror_none));
//layer->setBoundingBox(bb); //layer->setBoundingBox(bb);
ofVboMesh mesh; //ofVboMesh mesh;
mesh.addVertices({bb_mirror_none.p0, //mesh.addVertices({bb_mirror_none.p0,
bb_mirror_none.p1, //bb_mirror_none.p1,
bb_mirror_none.p2, //bb_mirror_none.p2,
bb_mirror_none.p3, //bb_mirror_none.p3,
glm::vec4(layer->getProps().x, layer->getProps().y, 0, 1), //glm::vec4(layer->getProps().x, layer->getProps().y, 0, 1),
transformOrigin //transformOrigin
}); //});
mesh.addColors({ //mesh.addColors({
ofColor::red, //ofColor::red,
ofColor::red, //ofColor::red,
ofColor::red, //ofColor::red,
ofColor::red, //ofColor::red,
ofColor::white, //ofColor::white,
ofColor::green, //ofColor::green,
}); //});
outerBoundingBoxes.push_back(mesh); //outerBoundingBoxes.push_back(mesh);
if(layer->getProps().mirror_x){ if(layer->getProps().mirror_x){
auto bbs_mirror_x = bbs; auto bbs_mirror_x = bbs;
@ -378,7 +378,7 @@ void GPUFontAtlasLayerCombo::draw(int width, int height){
float layerHeight = max_y - min_y; float layerHeight = max_y - min_y;
layer->setBoundingBox(Layer::BoundingBox{min_x, min_y, layerWidth, layerHeight}); layer->setBoundingBox(Layer::BoundingBox{min_x, min_y, layerWidth, layerHeight});
r = ofRectangle(layer->getProps().x, layer->getProps().y, layer->getProps().width, 800); //r = ofRectangle(layer->getProps().x, layer->getProps().y, layer->getProps().width, 800);
// culling // culling
deque <int> removeMe; deque <int> removeMe;
@ -490,8 +490,8 @@ void GPUFontAtlasLayerCombo::draw(int width,
vertices.resize(totalCharacters * 4); vertices.resize(totalCharacters * 4);
indices.resize(totalCharacters * 6); indices.resize(totalCharacters * 6);
std::vector <ofVboMesh> outerBoundingBoxes; //std::vector <ofVboMesh> outerBoundingBoxes;
ofRectangle r; //ofRectangle r;
{ {
OFX_PROFILER_SCOPE("draw layer"); OFX_PROFILER_SCOPE("draw layer");
@ -545,23 +545,23 @@ void GPUFontAtlasLayerCombo::draw(int width,
bb_mirror_none.multiply(layer->getInnerNode().getGlobalTransformMatrix()); bb_mirror_none.multiply(layer->getInnerNode().getGlobalTransformMatrix());
mirror_bbs.push_back(std::move(bb_mirror_none)); mirror_bbs.push_back(std::move(bb_mirror_none));
ofVboMesh mesh; //ofVboMesh mesh;
mesh.addVertices({bb_mirror_none.p0, //mesh.addVertices({bb_mirror_none.p0,
bb_mirror_none.p1, //bb_mirror_none.p1,
bb_mirror_none.p2, //bb_mirror_none.p2,
bb_mirror_none.p3, //bb_mirror_none.p3,
glm::vec4(layer->getProps().x, layer->getProps().y, 0, 1), //glm::vec4(layer->getProps().x, layer->getProps().y, 0, 1),
transformOrigin //transformOrigin
}); //});
mesh.addColors({ //mesh.addColors({
ofColor::red, //ofColor::red,
ofColor::red, //ofColor::red,
ofColor::red, //ofColor::red,
ofColor::red, //ofColor::red,
ofColor::white, //ofColor::white,
ofColor::green, //ofColor::green,
}); //});
outerBoundingBoxes.push_back(mesh); //outerBoundingBoxes.push_back(mesh);
if(layer->getProps().mirror_x){ if(layer->getProps().mirror_x){
auto bbs_mirror_x = bbs; auto bbs_mirror_x = bbs;
@ -644,7 +644,7 @@ void GPUFontAtlasLayerCombo::draw(int width,
float layerHeight = max_y - min_y; float layerHeight = max_y - min_y;
layer->setBoundingBox(Layer::BoundingBox{min_x, min_y, layerWidth, layerHeight}); layer->setBoundingBox(Layer::BoundingBox{min_x, min_y, layerWidth, layerHeight});
r = ofRectangle(layer->getProps().x, layer->getProps().y, layer->getProps().width, 800); //r = ofRectangle(layer->getProps().x, layer->getProps().y, layer->getProps().width, 800);
//cout << vertices.size() << " / " << indices.size() << endl; //cout << vertices.size() << " / " << indices.size() << endl;
// culling // culling
@ -754,6 +754,12 @@ void GPUFontAtlasLayerCombo::getAndApplyTransformOrigin(glm::vec4 & transformOri
break; break;
} }
} }
glm::vec2 anchor = glm::vec2(props.textAlignment,
0.5);
transformOrigin.x -= anchor.x * abs(bb.p1.x - bb.p0.x);
transformOrigin.y -= anchor.y * abs(bb.p1.y - bb.p0.y);
momNode.setOrientation(glm::quat(1, 0, 0, 0)); momNode.setOrientation(glm::quat(1, 0, 0, 0));
momNode.rotateDeg(props.rotation, glm::vec3(0, 0, 1)); momNode.rotateDeg(props.rotation, glm::vec3(0, 0, 1));
momNode.setPosition(transformOrigin); momNode.setPosition(transformOrigin);