1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
|
#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<std::string,menuItem> 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 <std::string> 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 "<<price<<" from "<<*it;
}
else{
if (!foundTags){
caption+=*it;
caption+=" ";
}
}
}
if (interesting){
items.push_back(menuItem(caption,price));
//items[slot]=menuItem(test[i],price);
std::string id=instagram.getImageID()[i];
if (imagepool.find(id)==imagepool.end()){
imagepool[id]=ofImage();
//ofLog(OF_LOG_NOTICE) << menutag << " " << slot << " " << caption << price << " " << id;
newInteresting=true;
}
if (!imagepool[id].isAllocated()) {
getImages.loadFromURL(imagepool[id], instagram.getImageURL()[i]);
ofLog(OF_LOG_NOTICE) << "LOADING " << id << " " << slot << " " << caption;
}
else {
ofLog(OF_LOG_NOTICE) << "REUSE " << id << " " << slot << " " << menutag;
}
items[slot].image=&imagepool[id];
slot++;
if (slot==IMAGE_SLOTS) break;
}
else ofLog(OF_LOG_NOTICE) << "instagram " << i << " " << price << " " << tags;
//this is where we would clean up unused images in the pool
}
}
lastPoll=ofGetElapsedTimef();
if (newInteresting){
isGrabbed=false;
}
return newInteresting;
}
//--------------------------------------------------------------
void ofApp::setup(){
scanner=dirScanner(ofFilePath().getUserHomeDir()+"/Dropbox/menugrab");
scanner.scan();
player=dirPlayer(&scanner);
/*
std::string str ("€");
ofLog(OF_LOG_NOTICE) << "code for € is " << ((int)str.at(0)) << " not " << 0xA4;
ofLog(OF_LOG_NOTICE) << "-30 as uint8_t is " << ((int)((uint8_t)-30));
*/
//items.resize(IMAGE_SLOTS);
ofTrueTypeFont::setGlobalDpi(150);
myText.init("American Typewriter Regular.ttf", FONTSIZE*FACTOR, 'i');
background.load("images/background1080.png");
overlay.load("images/overlay1080.png");
//instagram.setup(hangdaitoken,"self");
//instagram.setCertFileLocation(ofToDataPath("ca-bundle.crt",false));
menutag=MENUTAG;
//loadInstagramFeed();
/*
instagram.getUserRecentMedia("self");
//instagram.searchForTags("hangdai");
//ofLog(OF_LOG_NOTICE) << instagram["data"][0]["caption"]["text"].asString();
const Json::Value selfdata = instagram.getJSON()["data"];
for ( int index = 0; index < selfdata.size(); ++index ) // Iterates over the sequence elements.
ofLog(OF_LOG_NOTICE) << selfdata[index]["caption"]["text"].asString();
*/
//load
ofSetFrameRate(15);
lastPoll=POLL_INTERVAL;
primed=false;
}
//--------------------------------------------------------------
void ofApp::update(){
//ofBackground(255);
}
//--------------------------------------------------------------
void ofApp::draw(){
ofSetColor(255,255,255);
ofPushMatrix();
if(ROTATION>0){
ofTranslate(1920*FACTOR,0*FACTOR);
ofRotate(ROTATION);
//ofTranslate(0*FACTOR,0*FACTOR);
}
player.draw();
return;
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();
}
|