From 895389c009da308c4a1f01d0f17d8304ea12c915 Mon Sep 17 00:00:00 2001 From: Tim Redfern Date: Sun, 14 Aug 2022 23:18:51 +0100 Subject: check in lasertest --- lasertext/src/main.cpp | 22 +++++++ lasertext/src/ofApp.cpp | 135 +++++++++++++++++++++++++++++++++++++++ lasertext/src/ofApp.h | 166 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 323 insertions(+) create mode 100644 lasertext/src/main.cpp create mode 100644 lasertext/src/ofApp.cpp create mode 100644 lasertext/src/ofApp.h (limited to 'lasertext/src') diff --git a/lasertext/src/main.cpp b/lasertext/src/main.cpp new file mode 100644 index 0000000..3e20ab7 --- /dev/null +++ b/lasertext/src/main.cpp @@ -0,0 +1,22 @@ +#include "ofMain.h" +#include "ofApp.h" + + +//======================================================================== +int main(int argc, char *argv[]){ + + + ofGLFWWindowSettings settings; + + settings.setSize(1200,900); + + //1200 = 13.2° = 42898 pts theoretical + + shared_ptr mainWindow = ofCreateWindow(settings); + + shared_ptr mainApp(new ofApp); + + ofRunApp(mainWindow, mainApp); + ofRunMainLoop(); +} + \ No newline at end of file diff --git a/lasertext/src/ofApp.cpp b/lasertext/src/ofApp.cpp new file mode 100644 index 0000000..b6f4061 --- /dev/null +++ b/lasertext/src/ofApp.cpp @@ -0,0 +1,135 @@ +#include "ofApp.h" +#include "glew.h" + +/* +what do we want to store/control per letter? +*/ + + +int MAX_POINTS=40000; +int LASER_INTENSITY=128; + +//-------------------------------------------------------------- +void ofApp::setup(){ + fonts.open("fonts/"); + fonts.allowExt("svg"); + fonts.listDir(); + ofLogNotice()<<"found "< shapes = banner.getOutlines(); + + int num = laser.draw(shapes); + + //banner.draw(); + + ofPushMatrix(); + ofTranslate(ofGetWidth()/2,ofGetHeight()/2); + //ofScale(0.05,-0.05,0.05); + for (auto& s: shapes) s.draw(); + ofPopMatrix(); + + if (num>0){ + ofSetWindowTitle(ofToString(ofGetFrameRate(), 2)+" fps laser points: "+ofToString(num)); + } + else { + ofSetWindowTitle(ofToString(ofGetFrameRate(), 2)+" fps laser error "); + } + +} + + +//-------------------------------------------------------------- +void ofApp::exit() { + +} + + + +//-------------------------------------------------------------- +void ofApp::keyPressed(ofKeyEventArgs &args){ + + + +} + + + +//-------------------------------------------------------------- +void ofApp::keyReleased(int key){ + if (key>=' '&&key<='~'){ + banner.addGlyph(key,ofColor::fromHsb(ofRandom(255.0),225,255)); + } + else if (key==OF_KEY_BACKSPACE||key==OF_KEY_DEL) { //DEL + banner.removeGlyph(); + } + ofLog()< lines){ + glyph(c,w,lines,ofColor(0,0,0)); + } + glyph(char c,float w,vector lines,ofColor col){ + code=c; + width=w; + outline=lines; + colour=col; + } + void draw(float x, float y){ + ofSetColor(colour); + ofPushMatrix(); + ofTranslate(x,y); + for (auto& v:outline) v.draw(); + ofPopMatrix(); + } + char code; + float width; + vector outline; + ofColor colour; +}; + +class glyphbanner{ + ofXml SVGFont; + vector glyphs; + vector outlines; + ofVec2f centre; +public: + glyphbanner(){}; + void init(vector message){ + for (auto& word: message){ + for (auto& c: word){ + addGlyph(c,ofColor::fromHsb(ofRandom(255.0),225,255)); + } + addGlyph(' '); + } + } + int length(){return glyphs.size();} + float width(){ + float w=0.0f; + for (auto& i:glyphs) w+=i.width; + return w; + } + string text(){ + string s; + for (auto& i:glyphs) s+=ofToString(i.code); + return s; + } + vector colours(){ + vector c; + for (auto& i:glyphs) c.push_back(i.colour); + return c; + } + void loadFont(filesystem::path path){ + if( SVGFont.load(path) ){ + vector g=glyphs; + clear(); + createGlyphs(g); + ofLog()<<"loaded "< _g){ + for (auto& g:_g) addGlyph(g.code,g.colour); + } + void addGlyph(char c,ofColor col=ofColor(255,255,255)){ + vector shapes; + ofPolyline shape; + string elementPath = "/svg/defs/font/glyph[@unicode='"+ofToString(c)+"']"; + + if(SVGFont.findFirst(elementPath) == 0 ){ + elementPath = "/svg/defs/font/glyph[@unicode='?']"; + } + + ofXml xmlElement = SVGFont.findFirst(elementPath); + + float charWidth = ofToFloat(xmlElement.getAttribute("horiz-adv-x").getValue()); + + vector splitGlyphPath = ofSplitString(xmlElement.getAttribute("d").getValue(), " ");//glyph path data in SVG looks like this: "M 139 -9.45 L 230 18.9 L 299 22.1 L 227 25.2" + + for(int i=0; i& getOutlines(){ + outlines.clear(); + float p=(-width())/2; + for (auto& i:glyphs){ + for (auto& o:i.outline){ + auto q=o; + q.scale(.05,-.05); + q.translate(glm::vec3(p*.05,0,0)); + outlines.push_back(colourPolyline(q,i.colour)); + } + p+=i.width; + } + return outlines; + } +}; + +class ofApp : public ofBaseApp{ + + public: + void setup(); + void update(); + void draw(); + void exit(); + void keyPressed(ofKeyEventArgs &keyargs); + void keyReleased(int key); + void mouseMoved(int x, int y ); + void mouseDragged(int x, int y, int button); + void mousePressed(int x, int y, int button); + void mouseReleased(int x, int y, int button); + void mouseEntered(int x, int y); + void mouseExited(int x, int y); + void windowResized(int w, int h); + void dragEvent(ofDragInfo dragInfo); + void gotMessage(ofMessage msg); + + ofxHelios laser; + + ofDirectory fonts; + int currentFont; + string displaytext; + glyphbanner banner; + +}; -- cgit v1.2.3