/// handy function for creating a buffer of any type - mn and mx will be cast from float or just ignored, /// whatever is appropriate for the type. static RawDataBuffer *createVar(int type, const char *s, int size,float mn=0,float mx=1){ switch(type){ case T_NAMEFLOAT: if(DataManager::findFloatBuffer(s)) throw Exception(tok.getline()).set("variable %s already exists",s); else { printf("Adding var %s, size %d, range (%f,%f)\n",s,size,mn,mx); return DataManager::createFloatBuffer(s,size,mn,mx); } break; default: throw ParseException(&tok).set("unsupported type for variable %s",s); } return NULL; }
DataBuffer<float> *ConfigManager::parseFloatSource(){ DataBuffer<float> *b; char buf[256]; switch(tok.getnext()){ case T_VAR: tok.getnextident(buf); b = DataManager::findFloatBuffer(buf); if(!b) throw ParseException(&tok).set("undefined variable '%s'",buf); break; case T_EXPR: tok.getnextstring(buf); // OK, we're going to lose a reference to this, but such is life. // In this version we never delete expressions anyway. try { b = (new Expression(buf))->buffer; } catch(Exception& e){ throw Exception(e,tok.getline()); } // now parse the extra bits tok.getnextcheck(T_RANGE); float mn,mx; switch(tok.getnext()){ case T_INT: case T_FLOAT: mn = tok.getfloat(); tok.getnextcheck(T_TO); mx = tok.getnextfloat(); b->setMinMax(mn,mx); break; case T_AUTO: b->setAutoRange(); break; default: throw UnexpException(&tok,"expected number or 'auto'"); } break; default: throw UnexpException(&tok,"'var' or 'expr'"); } return b; }
static void parseWindow(){ // option defaults bool fullScreen = false; // should it be fullscreen? bool disabled = false; // what size? (default is fit around widgets. Ignored for fullscreen.) int width=-1,height=-1; // if set, move the window to a screen of the given dimensions int swidth=-1,sheight=-1; // title if any char title[256]; // "tab" number - used to generate a shortcut to pull this window // to the front int number=-1; title[0]=0; int screensetline=-1; // set this window to not inverse ConfigManager::inverse=false; // get window options bool done = false; while(!done){ switch(tok.getnext()){ case T_OCURLY: done = true; break; case T_TITLE: tok.getnextstring(title); break; case T_NUMBER: number = tok.getnextint(); break; case T_INVERSE: ConfigManager::inverse=true; break; case T_FULLSCREEN: fullScreen = true; break; case T_SIZE: // size of window if not fullscreen width = tok.getnextint(); tok.getnextcheck(T_COMMA); height = tok.getnextint(); break; case T_SCREEN: // move to a screen of given dimensions swidth = tok.getnextint(); tok.getnextcheck(T_COMMA); screensetline = tok.getline(); sheight = tok.getnextint(); break; case T_DISABLE: // the window is disabled and should be immediately closed disabled=true; break; } } // create a window Window *w = getApp()->createWindow(); if(number>=0) getApp()->setWindowKey(number,w); ConfigManager::setStyle(w); // and parse the contents parseContainer(w->centralWidget()); if(*title){ w->setWindowTitle(title); } // move the window if we want to if(swidth>0){ QDesktopWidget *dt = QApplication::desktop(); QRect r; int i; for(i=0;i<dt->screenCount();i++){ r = dt->screenGeometry(i); printf("Found display : %d x %d\n",r.width(),r.height()); if(r.width() == swidth && r.height()==sheight) break; } if(i==dt->screenCount()) throw Exception(screensetline).set("could not find display of %d x %d",swidth,sheight); w->move(r.topLeft()); } // finally show the window and resize if required if(disabled){ w->hide(); // marked "disabled" in the config } else { w->setWindowState(Qt::WindowActive); w->raise(); w->activateWindow(); if(fullScreen){ w->showFullScreen(); } else { if(width>0) w->resize(width,height); w->showNormal(); } } }