boundingbox for the complete layer
This commit is contained in:
parent
28d6a59ef2
commit
29d9b44140
6 changed files with 75 additions and 2 deletions
|
@ -204,6 +204,7 @@ void GPUFontAtlasLayerCombo::draw(int width, int height){
|
||||||
float ascender = font->getAscender(layer->getProps().fontSize_px);
|
float ascender = font->getAscender(layer->getProps().fontSize_px);
|
||||||
ofxGPUFont::Font::BoundingBox bb;
|
ofxGPUFont::Font::BoundingBox bb;
|
||||||
std::vector <ofxGPUFont::Font::BoundingBox> bbs;
|
std::vector <ofxGPUFont::Font::BoundingBox> bbs;
|
||||||
|
std::vector <ofxGPUFont::Font::BoundingBox> mirror_bbs;
|
||||||
float advanceY = 0;
|
float advanceY = 0;
|
||||||
font->collectBoundingBoxes(layer->getVariationText(),
|
font->collectBoundingBoxes(layer->getVariationText(),
|
||||||
layer->getVariationTextAppearance(),
|
layer->getVariationTextAppearance(),
|
||||||
|
@ -218,9 +219,16 @@ void GPUFontAtlasLayerCombo::draw(int width, int height){
|
||||||
ascender,
|
ascender,
|
||||||
advanceY,
|
advanceY,
|
||||||
layer->getProps());
|
layer->getProps());
|
||||||
bb.multiply(layer->getInnerNode().getGlobalTransformMatrix());
|
auto bb_mirror_none = bb;
|
||||||
|
bb_mirror_none.multiply(layer->getInnerNode().getGlobalTransformMatrix());
|
||||||
|
|
||||||
|
mirror_bbs.push_back(std::move(bb_mirror_none));
|
||||||
|
//layer->setBoundingBox(bb);
|
||||||
ofVboMesh mesh;
|
ofVboMesh mesh;
|
||||||
mesh.addVertices({bb.p0, bb.p1, bb.p2, bb.p3,
|
mesh.addVertices({bb_mirror_none.p0,
|
||||||
|
bb_mirror_none.p1,
|
||||||
|
bb_mirror_none.p2,
|
||||||
|
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
|
||||||
});
|
});
|
||||||
|
@ -244,6 +252,10 @@ void GPUFontAtlasLayerCombo::draw(int width, int height){
|
||||||
mirrorOuterNode.setPosition(transformOrigin);
|
mirrorOuterNode.setPosition(transformOrigin);
|
||||||
mirrorOuterNode.move(layer->getProps().mirror_x_distance * -1, 0, 0);
|
mirrorOuterNode.move(layer->getProps().mirror_x_distance * -1, 0, 0);
|
||||||
mirrorOuterNode.setScale(-1, 1, 1);
|
mirrorOuterNode.setScale(-1, 1, 1);
|
||||||
|
|
||||||
|
auto bb_mirror_x = bb;
|
||||||
|
bb_mirror_x.multiply(mirrorInnerNode.getGlobalTransformMatrix());
|
||||||
|
mirror_bbs.push_back(std::move(bb_mirror_x));
|
||||||
font->collectVerticesAndIndices(mirrorInnerNode,
|
font->collectVerticesAndIndices(mirrorInnerNode,
|
||||||
layer->getVariationTextAppearance(),
|
layer->getVariationTextAppearance(),
|
||||||
bbs_mirror_x,
|
bbs_mirror_x,
|
||||||
|
@ -260,6 +272,10 @@ void GPUFontAtlasLayerCombo::draw(int width, int height){
|
||||||
mirrorOuterNode.setPosition(transformOrigin);
|
mirrorOuterNode.setPosition(transformOrigin);
|
||||||
mirrorOuterNode.move(0, layer->getProps().mirror_y_distance * -1, 0);
|
mirrorOuterNode.move(0, layer->getProps().mirror_y_distance * -1, 0);
|
||||||
mirrorOuterNode.setScale(1, -1, 1);
|
mirrorOuterNode.setScale(1, -1, 1);
|
||||||
|
|
||||||
|
auto bb_mirror_y = bb;
|
||||||
|
bb_mirror_y.multiply(mirrorInnerNode.getGlobalTransformMatrix());
|
||||||
|
mirror_bbs.push_back(std::move(bb_mirror_y));
|
||||||
font->collectVerticesAndIndices(mirrorInnerNode,
|
font->collectVerticesAndIndices(mirrorInnerNode,
|
||||||
layer->getVariationTextAppearance(),
|
layer->getVariationTextAppearance(),
|
||||||
bbs_mirror_y,
|
bbs_mirror_y,
|
||||||
|
@ -277,6 +293,10 @@ void GPUFontAtlasLayerCombo::draw(int width, int height){
|
||||||
mirrorOuterNode.move(layer->getProps().mirror_x_distance * -1,
|
mirrorOuterNode.move(layer->getProps().mirror_x_distance * -1,
|
||||||
layer->getProps().mirror_y_distance * -1, 0);
|
layer->getProps().mirror_y_distance * -1, 0);
|
||||||
mirrorOuterNode.setScale(-1, -1, 1);
|
mirrorOuterNode.setScale(-1, -1, 1);
|
||||||
|
|
||||||
|
auto bb_mirror_xy = bb;
|
||||||
|
bb_mirror_xy.multiply(mirrorInnerNode.getGlobalTransformMatrix());
|
||||||
|
mirror_bbs.push_back(std::move(bb_mirror_xy));
|
||||||
font->collectVerticesAndIndices(mirrorInnerNode,
|
font->collectVerticesAndIndices(mirrorInnerNode,
|
||||||
layer->getVariationTextAppearance(),
|
layer->getVariationTextAppearance(),
|
||||||
bbs_mirror_xy,
|
bbs_mirror_xy,
|
||||||
|
@ -288,6 +308,20 @@ void GPUFontAtlasLayerCombo::draw(int width, int height){
|
||||||
bbs,
|
bbs,
|
||||||
vertices,
|
vertices,
|
||||||
indices);
|
indices);
|
||||||
|
|
||||||
|
float min_x = FLT_MAX;
|
||||||
|
float max_x = -FLT_MAX;
|
||||||
|
float min_y = FLT_MAX;
|
||||||
|
float max_y = -FLT_MAX;
|
||||||
|
for(const auto & mbb : mirror_bbs){
|
||||||
|
min_x = min(min_x, min(mbb.p0.x, min(mbb.p1.x, min(mbb.p2.x, mbb.p3.x))));
|
||||||
|
max_x = max(max_x, max(mbb.p0.x, max(mbb.p1.x, max(mbb.p2.x, mbb.p3.x))));
|
||||||
|
min_y = min(min_y, min(mbb.p0.y, min(mbb.p1.y, min(mbb.p2.y, mbb.p3.y))));
|
||||||
|
max_y = max(max_y, max(mbb.p0.y, max(mbb.p1.y, max(mbb.p2.y, mbb.p3.y))));
|
||||||
|
}
|
||||||
|
float width = max_x - min_x;
|
||||||
|
float height = max_y - min_y;
|
||||||
|
layer->setBoundingBox(Layer::BoundingBox{min_x, min_y, width, height});
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
|
|
|
@ -147,6 +147,23 @@ ofNode & GPUFontLayer::getOuterNode(){
|
||||||
ofNode & GPUFontLayer::getInnerNode(){
|
ofNode & GPUFontLayer::getInnerNode(){
|
||||||
return innerNode;
|
return innerNode;
|
||||||
}
|
}
|
||||||
|
const Layer::BoundingBox & GPUFontLayer::getBoundingBox(){
|
||||||
|
return this->boundingBox;
|
||||||
|
}
|
||||||
|
void GPUFontLayer::setBoundingBox(const Layer::BoundingBox & boundingBox){
|
||||||
|
this->boundingBox = boundingBox;
|
||||||
|
}
|
||||||
|
void GPUFontLayer::setBoundingBox(const ofxGPUFont::Font::BoundingBox & bb){
|
||||||
|
float min_x = min(bb.p0.x, min(bb.p1.x, min(bb.p2.x, bb.p3.x)));
|
||||||
|
float max_x = max(bb.p0.x, max(bb.p1.x, max(bb.p2.x, bb.p3.x)));
|
||||||
|
float min_y = min(bb.p0.y, min(bb.p1.y, min(bb.p2.y, bb.p3.y)));
|
||||||
|
float max_y = max(bb.p0.y, max(bb.p1.y, max(bb.p2.y, bb.p3.y)));
|
||||||
|
float width = max_x - min_x;
|
||||||
|
float height = max_y - min_y;
|
||||||
|
setBoundingBox(Layer::BoundingBox{
|
||||||
|
min_x, min_y, width, height
|
||||||
|
});
|
||||||
|
}
|
||||||
void GPUFontLayer::clearPropsBuffer(){
|
void GPUFontLayer::clearPropsBuffer(){
|
||||||
propsBuffer.clear();
|
propsBuffer.clear();
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,6 +45,9 @@ class GPUFontLayer : public Layer {
|
||||||
void setMomsComboIdentifier(const ComboIdentifier & identifier) override;
|
void setMomsComboIdentifier(const ComboIdentifier & identifier) override;
|
||||||
ofNode & getOuterNode() override;
|
ofNode & getOuterNode() override;
|
||||||
ofNode & getInnerNode() override;
|
ofNode & getInnerNode() override;
|
||||||
|
const Layer::BoundingBox & getBoundingBox() override;
|
||||||
|
void setBoundingBox(const Layer::BoundingBox & boundingBox) override;
|
||||||
|
void setBoundingBox(const ofxGPUFont::Font::BoundingBox & boundingBox);
|
||||||
|
|
||||||
const vector <ofxGPUFont::GlyphIdentity> & getVariationText();
|
const vector <ofxGPUFont::GlyphIdentity> & getVariationText();
|
||||||
const vector <ofxGPUFont::GlyphAppearance> & getVariationTextAppearance();
|
const vector <ofxGPUFont::GlyphAppearance> & getVariationTextAppearance();
|
||||||
|
@ -67,5 +70,6 @@ class GPUFontLayer : public Layer {
|
||||||
ofNode outerNode;
|
ofNode outerNode;
|
||||||
ofNode innerNode;
|
ofNode innerNode;
|
||||||
int letterDelayBufferSize = 0;
|
int letterDelayBufferSize = 0;
|
||||||
|
Layer::BoundingBox boundingBox;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
#include "ofMain.h"
|
#include "ofMain.h"
|
||||||
|
|
||||||
//uuid
|
//uuid
|
||||||
|
#include "ofRectangle.h"
|
||||||
#include "random_id.h"
|
#include "random_id.h"
|
||||||
|
|
||||||
#include "ofxMsdfgen.h"
|
#include "ofxMsdfgen.h"
|
||||||
|
@ -60,6 +61,12 @@ class Layer {
|
||||||
//text,
|
//text,
|
||||||
//fontPath)
|
//fontPath)
|
||||||
};
|
};
|
||||||
|
struct BoundingBox {
|
||||||
|
float x;
|
||||||
|
float y;
|
||||||
|
float w;
|
||||||
|
float h;
|
||||||
|
};
|
||||||
|
|
||||||
static std::string asString(const ofxVariableLab::Layer::Props & props){
|
static std::string asString(const ofxVariableLab::Layer::Props & props){
|
||||||
stringstream s;
|
stringstream s;
|
||||||
|
@ -115,6 +122,8 @@ class Layer {
|
||||||
virtual void setMomsComboIdentifier(const ComboIdentifier & identifier) = 0;
|
virtual void setMomsComboIdentifier(const ComboIdentifier & identifier) = 0;
|
||||||
virtual ofNode & getOuterNode() = 0;
|
virtual ofNode & getOuterNode() = 0;
|
||||||
virtual ofNode & getInnerNode() = 0;
|
virtual ofNode & getInnerNode() = 0;
|
||||||
|
virtual const Layer::BoundingBox & getBoundingBox() = 0;
|
||||||
|
virtual void setBoundingBox(const Layer::BoundingBox & boundingBox) = 0;
|
||||||
static int n_layers;
|
static int n_layers;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -299,6 +299,12 @@ ofNode & MsdfLayer::getOuterNode(){
|
||||||
ofNode & MsdfLayer::getInnerNode(){
|
ofNode & MsdfLayer::getInnerNode(){
|
||||||
return innerNode;
|
return innerNode;
|
||||||
}
|
}
|
||||||
|
const Layer::BoundingBox & MsdfLayer::getBoundingBox(){
|
||||||
|
return this->boundingBox;
|
||||||
|
}
|
||||||
|
void MsdfLayer::setBoundingBox(const Layer::BoundingBox & boundingBox){
|
||||||
|
this->boundingBox = boundingBox;
|
||||||
|
}
|
||||||
void MsdfLayer::setAtlas(shared_ptr <ofxMsdfgen::Atlas> _atlas){
|
void MsdfLayer::setAtlas(shared_ptr <ofxMsdfgen::Atlas> _atlas){
|
||||||
atlas = _atlas;
|
atlas = _atlas;
|
||||||
// TODO: this does not seem proper
|
// TODO: this does not seem proper
|
||||||
|
|
|
@ -37,6 +37,8 @@ class MsdfLayer : public Layer {
|
||||||
void setMomsComboIdentifier(const ComboIdentifier & identifier) override;
|
void setMomsComboIdentifier(const ComboIdentifier & identifier) override;
|
||||||
ofNode & getOuterNode() override;
|
ofNode & getOuterNode() override;
|
||||||
ofNode & getInnerNode() override;
|
ofNode & getInnerNode() override;
|
||||||
|
const Layer::BoundingBox & getBoundingBox() override;
|
||||||
|
void setBoundingBox(const Layer::BoundingBox & boundingBox) override;
|
||||||
|
|
||||||
void setAtlas(shared_ptr <ofxMsdfgen::Atlas> _atlas);
|
void setAtlas(shared_ptr <ofxMsdfgen::Atlas> _atlas);
|
||||||
shared_ptr <ofxMsdfgen::Atlas> getAtlas() const;
|
shared_ptr <ofxMsdfgen::Atlas> getAtlas() const;
|
||||||
|
@ -59,5 +61,6 @@ class MsdfLayer : public Layer {
|
||||||
LayerType type = MSDFGEN;
|
LayerType type = MSDFGEN;
|
||||||
ofNode outerNode;
|
ofNode outerNode;
|
||||||
ofNode innerNode;
|
ofNode innerNode;
|
||||||
|
Layer::BoundingBox boundingBox;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue