Mercurial > hg > tweakathon2ios
view presetManager.h @ 17:2a7320a8cbed
explore mode shows stuff, can go thru saving various presets.
author | Robert Tubb <rt300@eecs.qmul.ac.uk> |
---|---|
date | Tue, 21 Oct 2014 18:58:25 +0100 |
parents | 2da0350a4aa2 |
children | 36cdb73691da |
line wrap: on
line source
// // presetManager.h // oscSenderExample // // Created by Robert Tubb on 07/11/2012. // // // defines: // PresetManager // and Preset #ifndef __oscSenderExample__presetManager__ #define __oscSenderExample__presetManager__ #define PRESET_FILENAME "presets.json" #include <iostream> #include <string> #include "ofMain.h" #include "ofxiPhone.h" #include "ofxiPhoneExtras.h" #include "eventLogger.h" #include "json.h" #include <ctime> #include "PresetView.h" //--------------------------------------------------------------------------- class Preset{ public: // important details - these saved to file (uploaded?) string creatorUserName; unsigned int creatorDeviceID; // unique user device ID string name; // name of preset unsigned long long creationTime; // datetime that preset was created milliseconds string imageFileName; vector<int> CCValues; // the actual data bool isFilled; PresetIconView* iconView; // from save button press Preset(vector<int> aCCValues, string aname, int aID, string un, unsigned int uid, string imageFile = ""){ CCValues = aCCValues; if (CCValues.size()){ isFilled = true; }else{ isFilled = false; } name = aname; creatorUserName = un; creatorDeviceID = uid; double timemsd = [NSDate timeIntervalSinceReferenceDate]; creationTime = (unsigned long long)(timemsd*1000); //TODO color / texture? imageFileName = imageFile; if (imageFileName != ""){ iconView = new PresetIconView(name, imageFileName); } }; // contruct from json value Preset(Json::Value jval){ name = jval["name"].asString(); creatorUserName = jval["creatorUserName"].asString(); creatorDeviceID = jval["creatorDeviceID"].asUInt(); creationTime = jval["creationTime"].asLargestInt(); // dodgy? imageFileName = jval["imageFileName"].asString(); Json::Value JArray = jval["CCValues"]; if(JArray.size() < 1){ cout << "No Presets"; } for ( unsigned int i = 0; i < JArray.size(); i++ ) { CCValues.push_back(JArray[i].asInt()); } if (imageFileName != ""){ iconView = new PresetIconView(name, imageFileName); } } ofImage* getImage(){ return iconView->getImage(); } Json::Value presetToJson(); string displayTextDescription(){ // eg: for grid hover // objC to C to C++ bleurgh NSDate *ocdate = [NSDate dateWithTimeIntervalSinceReferenceDate:(NSTimeInterval)(creationTime/1000.0)]; NSString *dateText = [ocdate description]; const char *date_str = [dateText cStringUsingEncoding:NSASCIIStringEncoding]; stringstream ss; ss << "Name: \t" << name << "\nCreation time: \t" << date_str << "\nCreator: \t" << creatorUserName << '\n'; return ss.str(); } string getName(){ return name; } vector<int> getValues(){ return CCValues; } void setValues(vector<int> v){ CCValues = v; double timemsd = [NSDate timeIntervalSinceReferenceDate]; creationTime = (unsigned long long)(timemsd*1000); if (CCValues.size()){ isFilled = true; }else{ isFilled = false; } } }; //--------------------------------------------------------------------------- class PresetManager{ public: PresetManager(); void savePreset(string name, vector<int> stuff); void generatePresetSlot(const string name, const string imagefn); void saveFilledSlotToFile(); vector<int> recallPreset(int presetID); vector<int> recallPreset(string name); void startLoadAll(); // load everything from the json file void exitAndSaveAll(); // save stuff to the json file void printAll(); void clearAll(); Preset* getPresetAtIndex(int index){ if (index >= thePresets.size()){ cout << "ERROR: index " << index << " exceeds number of presets " << thePresets.size() << endl; return NULL; }else{ return thePresets[index]; } }; protected: string presetFileName; int nextID; int timesOpened; bool presetAlertShowing; vector<Preset *> thePresets; Json::Value allPresetsToJson(); void loadPresetsFromJsonFile(const string &jsonFile); void updatePresetFile(); void showNameDialog(); }; #endif /* defined(__oscSenderExample__presetManager__) */