#include "ofApp.h" #define timtoken "3281768761.3dfcaf5.14ca9410c2aa4c00b9b60f36cd09d01a" #define hangdaitoken "3939854844.b31608d.a61a4e49a4dc40a688c22f4e0e81da3a" std::string replaceStrChar(std::string str, const std::string& replace, char ch) { // set our locator equal to the first appearance of any character in replace size_t found = str.find_first_of(replace); while (found != std::string::npos) { // While our position in the sting is in range. str[found] = ch; // Change the character at position. found = str.find_first_of(replace, found+1); // Relocate again. } return str; // return our new string. } bool ofApp::loadInstagramFeed(){ /* std::string test[5]; int testindex=0; for (int i=0;i<255;i++){ test[testindex]=" "+test[testindex]; test[testindex][0]=i; if (i==25||i==126||i==174||i==229) test[testindex]="\n"+test[testindex]; if (i==51||i==102||i==153||i==204) testindex++; } */ items.clear(); //items.resize(IMAGE_SLOTS); instagram.getUserRecentMedia("self",100); //instagram.getUserLikedMedia(12); ofLog(OF_LOG_NOTICE) << "instagram self feed -------------------> " << instagram.getImageURL().size() << " items "; //leave in verbose logging as ofxInstagram does anyway int slot=0; map newmenu; bool newInteresting=false; if (!instagram.getImageURL().empty()) { for ( int i = 0; i < instagram.getImageURL().size(); i++) { std::string str=replaceStrChar(instagram.getImageCaption()[i],"\n",' '); vector tokens = ofSplitString(str," ",true,true); //,ignoreEmpty=false,trim=false); std::string caption; std::string price; std::string tags; bool interesting=false; bool foundTags=false; bool foundPrice=false; for(auto it = tokens.begin(); it != tokens.end(); it++){ if((*it).at(0)=='#'){ if (!foundPrice){ price=""; foundPrice=true; } if (*it==menutag){ interesting=true; } tags+=*it; tags+=" "; foundTags=true; } else if(((uint8_t)(*it).at(0))==226){ price=*it; foundPrice=true; price[0]=36; //replace with dollar to use hacked truetype font ofLog(OF_LOG_NOTICE) << "price is "<0){ ofTranslate(1920*FACTOR,0*FACTOR); ofRotate(ROTATION); //ofTranslate(0*FACTOR,0*FACTOR); } if (!player.draw()){ if(ofGetElapsedTimef()-lastPoll>POLL_INTERVAL) { loadInstagramFeed(); } ofPushMatrix(); //Store the coordinate system nexessary for some reason background.draw(0,0,1080*FACTOR,1920*FACTOR); //ofGetWidth(),ofGetHeight()); ofPopMatrix(); //Restore the coordinate system int colinitialoffset=40; int rowinitialoffset=60; int coloffset=520; int imgsize=480; int rowoffset=615; int col=0; int row=0; int cols=2; int textcolinset=10; int textrowinset=50; //some kind of rendering bug with textsuite means it has to go last or everything is dim bool imageWaiting=false; if (!items.empty()) { for (int i = 0; i < items.size(); i++) { if (items[i].image->isAllocated()) { int imgx=(colinitialoffset+(col*coloffset))*FACTOR; int imgy=(rowinitialoffset+(row*rowoffset))*FACTOR; items[i].image->draw(imgx,imgy,imgsize*FACTOR,imgsize*FACTOR); myText.setText(items[i].caption); myText.wrapTextX(imgsize*FACTOR); myText.setColor(255,255,255,255); myText.drawCenter(imgx+((imgsize*FACTOR)/2),imgy+((imgsize+textcolinset)*FACTOR),2); myText.setText(items[i].price); myText.wrapTextX(imgsize*FACTOR); myText.setColor(255,255,255,255); myText.drawCenter(imgx+((imgsize*FACTOR)/2),imgy+((imgsize+textcolinset+(FONTSPACING*2))*FACTOR),2); } else imageWaiting=true; col++; if (col==cols){ col=0; row++; } } } ofEnableAlphaBlending(); overlay.draw(0,0,1080*FACTOR,1920*FACTOR); //ofGetWidth(),ofGetHeight()); //don't work on a horiz screen?? ofDisableAlphaBlending(); //for some reason the final is only drawn on the frame AFTER all 5 images become allocated //hence the "primed" mechanism if (primed){ ofImage img; //float rotation=ofDegToRad(ROTATION); //int width=(1920*FACTOR*sin(rotation))+(1080*FACTOR*cos(rotation)); //int height=(1920*FACTOR*cos(rotation))+(1080*FACTOR*sin(rotation)); img.grabScreen(0, 0,1080*FACTOR,1920*FACTOR); if(ROTATION>0){ img.rotate90(1); img.crop(860*FACTOR,0,1080*FACTOR,1920*FACTOR); } else { //img.crop(0,0,1080*FACTOR,1920*FACTOR); } img.save(ofFilePath().getUserHomeDir()+"/Dropbox/menugrab/"+SCREENGRABFILEPATH); primed=false; } if (!isGrabbed&&!imageWaiting) { primed=true; isGrabbed=true; } } ofPopMatrix(); } //-------------------------------------------------------------- void ofApp::keyPressed(int key){ } //-------------------------------------------------------------- void ofApp::keyReleased(int key){ } //-------------------------------------------------------------- void ofApp::mouseMoved(int x, int y){ } //-------------------------------------------------------------- void ofApp::mouseDragged(int x, int y, int button){ } //-------------------------------------------------------------- void ofApp::mousePressed(int x, int y, int button){ } //-------------------------------------------------------------- void ofApp::mouseReleased(int x, int y, int button){ } //-------------------------------------------------------------- void ofApp::mouseEntered(int x, int y){ } //-------------------------------------------------------------- void ofApp::mouseExited(int x, int y){ } //-------------------------------------------------------------- void ofApp::windowResized(int w, int h){ } //-------------------------------------------------------------- void ofApp::gotMessage(ofMessage msg){ } //-------------------------------------------------------------- void ofApp::dragEvent(ofDragInfo dragInfo){ } //-------------------------------------------------------------- void ofApp::exit() { getImages.stopThread(); }