void InstagramView::loadProfileImage(){ ofRegisterURLNotification(this); size_t found = _args.profilePictureUrl.find_last_of("/\\"); string profilePictureFileName = _args.profilePictureUrl.substr(found + 1); // Before loading check if we already have the file ofFile file = ofFile(profilePictureFileName); if(file.exists() && Settings::instance()->getCache()){ initProfileImage(profilePictureFileName); }else{ ofSaveURLAsync(_args.profilePictureUrl, profilePictureFileName); } }
//-------------------------------------------------------------- void ofApp::draw(){ int frameDiff; while (oscReceiver.hasWaitingMessages()) { cout << "New msg is coming + "; ofxOscMessage m; oscReceiver.getNextMessage(&m); if (m.getAddress() == "/sync/play/FW_SH_02_HBD_A/frameJump") { frameJump = m.getArgAsInt32(0); cout << "Frame sync, jump(" << frameJump << ") frames\r\n"; // do move forward videoPlayers[i]->setFrame(frameJump); } else if (m.getAddress() == "/sync/play/nowPlayingFile") { // can I get all the file list from the beginning? loadVideo(m.getArgAsString(0)); } else if (m.getAddress() == "/sync/play/nowPlayingStart") { isCellStart = m.getArgAsInt32(0); } else if (m.getAddress() == "/sync/play/nowPlayingStop") { isCellStop = m.getArgAsInt32(0); } else if (m.getAddress() == "/sync/play/type") { mediaType = m.getArgAsString(0); } else if (m.getAddress() == "/sync/play/nowPlayingKickTime") { cellKickTime = m.getArgAsInt32(0); } //dumpOSC(m); } strFruitString = strFruitPrefix + ofToString(currentAppleAmount) + strUnit; if (!videoPause) { // if (((videoPlayers[i]->getPosition() * videoPlayers[i]->getDuration()) - videoPlayers[i]->getDuration()) == 0){ // // if (i < N_VIDEO_PLAYERS-1) { // i++; // } // else { // i = 0; // loopCounter++; // } // } //for(auto p : videoPlayers) { // p->draw(ofMap(i++, 0, videoPlayers.size(), 0, ofGetWidth()), ofGetHeight()/2 - 108*2, 192*4, 108*4); //ofPushMatrix(); //ofSetColor(ofRandom(255), 0, 0); // ofRect(0,0,ofGetWidth(),ofGetHeight()); // ofEnableAlphaBlending(); // ofSetColor(255,255,255); // #if 0 // for 1080 x 3840 video //---------------------------------------------------------- draw video texture to fullscreen. ofRectangle screenRect(0, 0, ofGetWidth(), ofGetHeight()); ofRectangle videoRect(0, 0, videoPlayers[i]->getWidth(), videoPlayers[i]->getHeight()); ofRectangle videoFullscreenRect = videoRect; videoFullscreenRect.scaleTo(screenRect, OF_ASPECT_RATIO_KEEP_BY_EXPANDING); videoPlayers[i]->draw(0, 0, videoFullscreenRect.getWidth(), videoFullscreenRect.getHeight()); #endif #if 1 // for 2 1080 x 1920 videos //---------------------------------------------------------- draw video texture to fullscreen. for (int videoNum = 0; videoNum < videoPlayers.size(); videoNum++) { if (videoNum == 1) { //top ofRectangle screenRect(0, 0, ofGetWidth(), ofGetHeight()/2); ofRectangle videoRect(0, 0, videoPlayers[videoNum]->getWidth(), videoPlayers[videoNum]->getHeight()); ofRectangle videoFullscreenRect = videoRect; videoFullscreenRect.scaleTo(screenRect, OF_ASPECT_RATIO_KEEP_BY_EXPANDING); videoPlayers[videoNum]->draw(0, 0, videoFullscreenRect.getWidth(), videoFullscreenRect.getHeight()); } else if (videoNum == 0) { //bottom ofRectangle screenRect(0, 0, ofGetWidth(), ofGetHeight()/2); ofRectangle videoRect(0, 0, videoPlayers[videoNum]->getWidth(), videoPlayers[videoNum]->getHeight()); ofRectangle videoFullscreenRect = videoRect; videoFullscreenRect.scaleTo(screenRect, OF_ASPECT_RATIO_KEEP_BY_EXPANDING); videoPlayers[videoNum]->draw(0, ofGetHeight()/2, videoFullscreenRect.getWidth(), videoFullscreenRect.getHeight()); } } if (i < N_VIDEO_PLAYERS-1) { i++; } else { i = 0; //loopCounter++; } #endif //videoPlayers[i]->draw(0, 0, 900, 1400); //p->draw(ofMap(i++, 0, videoPlayers.size(), 0, ofGetWidth()), ofGetHeight()/2 - 108*2, 192*4, 108*4); // 2304x4096 sumsung tv @1 // 2304x8192 ofScreen // 2026x3840 video // cout << "w:" << w << "\n"; // p->draw(0, 0); //ofPopMatrix(); //} } if (imageDisplay) { ofRectangle screenRect(0, 0, ofGetWidth()/2, ofGetHeight()/2); ofRectangle videoRect(0, 0, imgTop->width, imgTop->height); ofRectangle videoFullscreenRect = videoRect; videoFullscreenRect.scaleTo(screenRect, OF_ASPECT_RATIO_KEEP_BY_EXPANDING); if (imgTopPosters.size() == 1) { ofSetColor(255, 255, 255); // very important, don't delete set color imgTopPosters[0]->draw(0, 0, imgTopPosters[0]->width, imgTopPosters[0]->height); } if (dbgImg) { ofSetColor(0, 0, 255); imgTop->drawBounds(0, 0, imgTop->width, imgTop->height); imgBottom->drawBounds(0, 4096, imgBottom->width, imgBottom->height); } else { ofPushMatrix(); ofEnableAlphaBlending(); ofSetColor(255, 255, 255); // very important, don't delete set color // ensure first image is showing //imgTopPosters[0]->draw(0, 0, imgTopPosters[0]->width, imgTopPosters[0]->height); if ((ofGetElapsedTimef() - initTime) > 2) { //videoPause = !videoPause; //imageDisplay = !imageDisplay; initTime = ofGetElapsedTimef(); if (imgTopx && !isUpdateImg) { //ofColor(255, 0, 0, 100); int size = imgTopPosters.size(); // size limitation is 2 by design if (size > 0) { imgTopPosters[imgRotateIndex]->draw(0, 0, imgTopPosters[imgRotateIndex]->width, imgTopPosters[imgRotateIndex]->height); imgRotateIndex++; if (imgRotateIndex >= size) imgRotateIndex = 0; //ofSleepMillis(3000);// well... } // for (auto i = imgTopPosters.begin(); i!= imgTopPosters.end(); ++i) { // //(*i)->draw(0, 0, imgTopx->width, imgTopx->height); // (*i)->draw(0, 0, (*i)->width, (*i)->height); // } //imgTopx->draw(0, 0, imgTopx->width, imgTopx->height); } else{ imgTopPosters[0]->draw(0, 0, imgTopPosters[0]->width, imgTopPosters[0]->height); //imgTop->draw(0, 0, imgTop->width, imgTop->height); } } ofNoFill(); ofSetColor(100, 0, 100, 100); ofCircle(imgTop->width/2, imgTop->height/3+100, 400); ofDisableAlphaBlending(); //ofRectangle bbox; float fontSize = 300; //ofTranslate(100, 2* ofGetHeight()/3); //ofRotateY(50 * ofGetElapsedTimef()); ofSetColor(100, 0, 100, 128); FZLfont.draw(strPoster, fontSize, imgTop->width/2-100+0.1*x, imgTop->height/3+100+0.1*y); //bbox = unicodeFont.getStringBoundingBox(strFruitPrefix, 100, 2* ofGetHeight()/3); //ofSetColor(0, 200, 0); //ofFill(); //ofRotateZ(-5); ofEnableAlphaBlending(); ofPopMatrix(); // Bottom poster //ofColor(255, 255, 255); //ofTranslate(0, 4096); // samgung tv ofSetColor(255, 255, 255); // very important, don't delete set color ofTranslate(0, 7680/2); // pptv imgBottom->draw(0, 0, imgBottom->width, imgBottom->height); } } ofDrawBitmapStringHighlight("FPS: " + ofToString(fps), 20, 360); ofDrawBitmapStringHighlight("Frame " + ofToString(videoPlayers[i]->getCurrentFrame()) + "/" + ofToString(videoPlayers[i]->getTotalNumFrames()), 20, 380); ofDrawBitmapStringHighlight("Duration " + ofToString(videoPlayers[i]->getPosition() * videoPlayers[i]->getDuration(), 2) + "/" + ofToString(videoPlayers[0]->getDuration(), 2), 20, 400); ofDrawBitmapStringHighlight("Speed " + ofToString(videoPlayers[i]->getSpeed(), 2), 20, 420); ofDrawBitmapStringHighlight("Canvas W:" + ofToString(ofGetWidth()) + " H:" + ofToString(ofGetHeight()), 20, 440); ofDrawBitmapString("Total Loop #" + ofToString(loopCounter) + " \nClip #" + ofToString(i), 20, 460); // send out frame number information msgSend.setAddress("/sync/play/FW_SH_02_HBD_A/currentFrame"); msgSend.addIntArg(videoPlayers[i]->getCurrentFrame()); oscSender.sendMessage(msgSend); #if 0 #if 0 ofPushMatrix(); ofRectangle bbox; ofSetColor(255, 0, 0, 32); float fontSize = 20 /*134*/; //TIME_SAMPLE_START("bbox"); //ofTranslate(100, 2* ofGetHeight()/3); bbox = unicodeFont.getBBox(strFruitString, fontSize, 500, 500); //TIME_SAMPLE_STOP("bbox"); ofRect(bbox); ofPopMatrix(); #endif ofPushMatrix(); ofRectangle bbox; float fontSize = 134; //ofTranslate(100, 2* ofGetHeight()/3); //ofRotateY(50 * ofGetElapsedTimef()); ofSetColor(0xd3, 0xd3, 0xd3, 200); unicodeFont.draw(strFruitString, fontSize, 100, 2* ofGetHeight()/3); bbox = unicodeFont.getStringBoundingBox(strFruitPrefix, 100, 2* ofGetHeight()/3); ofSetColor(0, 200, 0); //ofFill(); ofEnableAlphaBlending(); ofRect(bbox); //ofRotateZ(-5); ofPopMatrix(); // text background ofSetColor(153, 153, 153, 100); ofRect(100, 2* ofGetHeight()/3 - 130, ofGetWidth()-100, 160); if (isDemoMode) { if ((ofGetElapsedTimef() - initTimeDbg) > 3.0) { videoPause = !videoPause; imageDisplay = !imageDisplay; initTimeDbg = ofGetElapsedTimef(); } } if (isDownloadImg){ isDownloadImg = !isDownloadImg; cout << "Downloading..." << "\n"; ofSetColor(100, 0, 100, 128); if (isUpdateImg) { string str = "Poster Updating..."; FZLfont.draw(str, 200, ofGetWidth()/2, ofGetHeight()/4*2); } // read file name from iOS client char serverPath[512] = "http://192.168.43.155:8080/"; if (strUpdateFileDate.length() != 0) { sprintf(updateURL, "%s%s.jpg", serverPath, strUpdateFileDate.c_str()); cout << "Update URL: " << updateURL << "\n"; ofSaveURLAsync(updateURL, "images/L1.jpg"); } else{ cout << "ERROR: No update date" << "\n"; } } if (isUpdateImg) { // reload image here if (imgTopx) delete imgTopx; imgTopx = new ofxGiantImage(); imgTopx->loadImage("images/L1.jpg"); imgTopPosters.push_back(imgTopx); // push into image queues isUpdateImg = !isUpdateImg; } #endif }
void InstagramView::draw(){ ofSetHexColor(0xFFFFFF); // Draw media #ifdef TARGET_RASPBERRY_PI if(_video.isPlaying()){ _video.draw(0, 0, ofGetHeight(), ofGetHeight()); #else if(_video.isLoaded() && _video.isInitialized()){ _video.draw(0, 0, ofGetHeight(), ofGetHeight()); #endif }else if(_image.isAllocated()){ _image.draw(0, 0, ofGetHeight(), ofGetHeight()); } // Draw avatar ofPushStyle(); float avatarX = ofGetHeight() + _margin; float avatarY = _margin; ofSetHexColor(0xEB545A); ofDrawRectangle(avatarX, avatarY, _avatarWidth, _avatarHeight); if(_profileImage.isAllocated()){ ofSetHexColor(0xFFFFFF); _profileImage.draw(avatarX + 5, avatarY + 5, _avatarWidth - 10, _avatarHeight - 10); }else{ ofSetHexColor(0x333333); ofDrawRectangle(avatarX + 5, avatarY + 5, _avatarWidth - 10, _avatarHeight - 10); } ofPopStyle(); // Draw username ofPushStyle(); float usernameX = avatarX + _avatarWidth + (_margin / 2.0f); float usernameY = avatarY + (_avatarHeight / 2.0f) + 5.0f; ofSetHexColor(0xEB545A); if(_fontMdBold.isLoaded()){ string username = "******" + _args.username; _fontMdBold.drawString(username, usernameX, usernameY); } ofPopStyle(); // Draw comment ofPushStyle(); float commentX = avatarX; float commentY = avatarY + _avatarHeight + _margin + _fontLgRegular.getSize(); ofSetHexColor(0x000000); if(_fontLgRegular.isLoaded()){ _fontLgRegular.drawString(_args.caption, commentX, commentY); } ofPopStyle(); // Draw hashtag ofPushStyle(); string hashtag = "@fablabberlin"; float hashtagX = commentX; float hashtagY = ofGetHeight() - _margin - (_fontMdRegular.getLineHeight() * 2.5f); ofSetHexColor(0x61C5EA); if(_fontMdBold.isLoaded()){ _fontMdBold.drawString(hashtag, hashtagX, hashtagY); } ofPopStyle(); // Draw info ofPushStyle(); string info = "Fab Lab Berlin on Instagram.\nContent? Talk to the lab manager!"; float infoX = hashtagX; float infoY = ofGetHeight() - _margin - _fontMdRegular.getLineHeight(); ofSetHexColor(0x61C5EA); if(_fontMdRegular.isLoaded()){ _fontMdRegular.drawString(info, infoX, infoY); } ofPopStyle(); } void InstagramView::loadImage(){ ofRegisterURLNotification(this); size_t found = _args.imageUrl.find_last_of("/\\"); string imageFileName = _args.imageUrl.substr(found + 1); // Uncomment this if caching is not important or filesystem does not support long filenames //found = imageFileName.find_first_of("?\\"); //string fileName = imageFileName.substr(0, found); // Before loading check if we already have the file ofFile file = ofFile(imageFileName); if(file.exists() && Settings::instance()->getCache()){ initImage(imageFileName); }else{ ofSaveURLAsync(_args.imageUrl, imageFileName); } }