From 603d1a2a94a1263a85c353997eb3276d120d0822 Mon Sep 17 00:00:00 2001 From: Tim Redfern Date: Tue, 29 Aug 2017 18:34:26 +0100 Subject: adding load save --- gui/addons.make | 1 + gui/src/chainImage.cpp | 68 +++++++++++++++++++++++++++++++++++++++++++------- gui/src/chainImage.h | 9 ++++++- gui/src/ofApp.cpp | 4 +-- gui/src/ofApp.h | 2 +- 5 files changed, 71 insertions(+), 13 deletions(-) create mode 100644 gui/addons.make diff --git a/gui/addons.make b/gui/addons.make new file mode 100644 index 0000000..ab5217b --- /dev/null +++ b/gui/addons.make @@ -0,0 +1 @@ +ofxJSON diff --git a/gui/src/chainImage.cpp b/gui/src/chainImage.cpp index 02f3b32..44aaace 100644 --- a/gui/src/chainImage.cpp +++ b/gui/src/chainImage.cpp @@ -242,8 +242,9 @@ if not make a symbolic link return false; } -void chainImageSet::keyPressed(int key){ - switch(key){ +void chainImageSet::keyPressed(ofKeyEventArgs &keyargs){ + //printf("Got key %i, modifiers:%i\n",keyargs.key,keyargs.modifiers); + switch(keyargs.key){ case '[': if (selected==images.begin()){ selected=--images.end(); @@ -268,6 +269,43 @@ void chainImageSet::keyPressed(int key){ case OF_KEY_RIGHT: selected->linkPos.x++; break; + case 's': + case 83: { + //printf("Saving... keyargs modifiers:%i\n",keyargs.modifiers); + //saves over last filename or use control to choose a new one + if (!filename.length()||keyargs.hasModifier(OF_KEY_CONTROL)){ + ofFileDialogResult saveFileResult = ofSystemSaveDialog(ofGetTimestampString() + ".json" , "Save your file"); + if (saveFileResult.bSuccess){ + filename=saveFileResult.filePath; + //printf("Got filename: %s\n",filename.c_str()); + } + //else printf("ofSystemSaveDialog failed.\n"); + } + if (filename.length()){ + //printf("Saving %s\n",filename.c_str()); + saveJson(filename); + } + + break; + } + case 'l':{ + //load_chain(); + ofFileDialogResult openFileResult= ofSystemLoadDialog("Select a json preset"); + + //Check if the user opened a file + if (openFileResult.bSuccess){ + + ofLogVerbose("Selected %s\n",openFileResult.filePath); + + //We have a file, check it and process it + //processOpenFileSelection(openFileResult); + + }else { + ofLogVerbose("User hit cancel"); + } + break; + + } } } @@ -279,7 +317,7 @@ void chainImageSet::mouseDragged(int x, int y, int button){ break; case OF_MOUSE_BUTTON_2: //alt-click - dragRotate=((x-clickPoint.x)/(selected->thumbnail.getWidth() ))*180.0f; + dragRotate=((clickPoint.x-x)/(selected->thumbnail.getWidth()))*180.0f; break; case OF_MOUSE_BUTTON_3: //control-click @@ -290,17 +328,29 @@ void chainImageSet::mouseDragged(int x, int y, int button){ //-------------------------------------------------------------- void chainImageSet::mousePressed(int x, int y, int button){ + //todo: select clickPoint=ofPoint(x,y); } //-------------------------------------------------------------- void chainImageSet::mouseReleased(int x, int y, int button){ - selected->linkPos+=dragPoint; - dragPoint=ofPoint(0,0); - selected->linkScale*=(1.0f+dragScale); - dragScale=0.0f; - selected->linkRot+=dragRotate; - dragRotate=0.0f; + if (images.size()){ + selected->linkPos+=dragPoint; + dragPoint=ofPoint(0,0); + selected->linkScale*=(1.0f+dragScale); + dragScale=0.0f; + selected->linkRot+=dragRotate; + dragRotate=0.0f; + } } +bool chainImageSet::saveJson(std::string filename){ + +} +bool chainImageSet::loadJson(std::string filename){ + +} + + + diff --git a/gui/src/chainImage.h b/gui/src/chainImage.h index f5d89f2..ac78bd3 100644 --- a/gui/src/chainImage.h +++ b/gui/src/chainImage.h @@ -47,13 +47,18 @@ class chainImageSet{ public: chainImageSet(){ currentDefaultImageRatio=0.3; + filename=""; } void drawGui(); bool add(std::string filename,glm::vec2 pos); - void keyPressed(int key); + void keyPressed(ofKeyEventArgs &keyargs); void mouseDragged(int x, int y, int button); void mousePressed(int x, int y, int button); void mouseReleased(int x, int y, int button); + + saveJson(std::string filename); + loadJson(std::string filename); + std::list images; float currentDefaultImageRatio; @@ -62,4 +67,6 @@ class chainImageSet{ ofPoint dragPoint; float dragScale; float dragRotate; + + std::string filename; }; \ No newline at end of file diff --git a/gui/src/ofApp.cpp b/gui/src/ofApp.cpp index 4ab2dc4..cb808d1 100644 --- a/gui/src/ofApp.cpp +++ b/gui/src/ofApp.cpp @@ -26,8 +26,8 @@ void ofApp::draw(){ } //-------------------------------------------------------------- -void ofApp::keyPressed(int key){ - images.keyPressed(key); +void ofApp::keyPressed(ofKeyEventArgs &keyargs){ + images.keyPressed(keyargs); } //-------------------------------------------------------------- diff --git a/gui/src/ofApp.h b/gui/src/ofApp.h index da9d734..ceb3e41 100644 --- a/gui/src/ofApp.h +++ b/gui/src/ofApp.h @@ -12,7 +12,7 @@ class ofApp : public ofBaseApp{ void update(); void draw(); - void keyPressed(int key); + void keyPressed(ofKeyEventArgs &keyargs); void keyReleased(int key); void mouseMoved(int x, int y ); void mouseDragged(int x, int y, int button); -- cgit v1.2.3