summaryrefslogtreecommitdiff
path: root/gui
diff options
context:
space:
mode:
authorTim Redfern <tim@getdrop.com>2017-08-30 01:31:57 +0100
committerTim Redfern <tim@getdrop.com>2017-08-30 01:31:57 +0100
commit52f12dfc10edfc4dd063b610f65dd2e901d3080c (patch)
tree93fb5618c6776b077251013da65e0ccea5c39d40 /gui
parent603d1a2a94a1263a85c353997eb3276d120d0822 (diff)
load save
Diffstat (limited to 'gui')
-rw-r--r--gui/src/chainImage.cpp78
-rw-r--r--gui/src/chainImage.h23
-rw-r--r--gui/src/ofApp.cpp1
3 files changed, 89 insertions, 13 deletions
diff --git a/gui/src/chainImage.cpp b/gui/src/chainImage.cpp
index 44aaace..67fbad6 100644
--- a/gui/src/chainImage.cpp
+++ b/gui/src/chainImage.cpp
@@ -86,6 +86,27 @@ void chainImage::drawChain(float fadeIn){
glPopMatrix();
}
+Json::Value chainImage::toJson(){
+ Json::Value json=Json::Value(Json::objectValue);
+ json["linkPos"]=Json::Value(Json::arrayValue);
+ json["linkPos"].append(linkPos.x);
+ json["linkPos"].append(linkPos.y);
+ json["linkScale"]=linkScale;
+ json["linkRot"]=linkRot;
+ json["filename"]=filename;
+ return json;
+}
+
+bool chainImage::fromJson(Json::Value json){
+ if (load(json["filename"].asString())){
+ linkPos=ofPoint(json["linkPos"][0].asDouble(),json["linkPos"][1].asDouble());
+ linkScale=json["linkScale"].asDouble();
+ linkRot=json["linkRot"].asDouble();
+ return true;
+ }
+ return false;
+}
+
void chainImageSet::drawGui(){
float t_xoffs=0.0;
float borderwidth=ofGetHeight()*(1.0-THUMB_BORDER_RATIO)*0.5;
@@ -203,10 +224,7 @@ if not make a symbolic link
*/
chainImage image;
if (image.load(filename)){
- image.makeThumbnail();
-
- //could there be a way to load without committing the texture
- image.setUseTexture(false);
+
image.init(ofPoint(0,0),
currentDefaultImageRatio,
0 //default rotation
@@ -295,10 +313,13 @@ void chainImageSet::keyPressed(ofKeyEventArgs &keyargs){
//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);
+ bool success=loadJson(openFileResult.fileName);
+
+ ofLogVerbose("Load %s %s\n",
+ openFileResult.filePath.c_str(),
+ success?"succeeded":"failed");
+
}else {
ofLogVerbose("User hit cancel");
@@ -345,10 +366,49 @@ void chainImageSet::mouseReleased(int x, int y, int button){
}
bool chainImageSet::saveJson(std::string filename){
+ ofxJSON json;
+
+ json["images"] = Json::Value(Json::arrayValue);
+
+ for(std::list<chainImage>::iterator ii=images.begin(); ii != images.end(); ii++){
+ json["images"].append(ii->toJson());
+ }
+
+
+ json.save(filename, true);
}
-bool chainImageSet::loadJson(std::string filename){
-
+bool chainImageSet::loadJson(std::string _filename){
+ ofxJSON json;
+ bool parsingSuccessful = json.open(_filename);
+
+ if (parsingSuccessful)
+ {
+ images.clear();
+
+ for (int i=0;i<json["images"].size();i++){
+ chainImage image;
+ if (image.fromJson(json["images"][i])){
+ images.push_back(image);
+ }
+ }
+ for (std::list<chainImage>::iterator ii=images.begin(); ii != images.end(); ii++){
+ auto li=ii;
+ li++;
+ if (li==images.end()) {
+ li=images.begin();
+ }
+ ii->link=&(*li);
+
+ }
+ selected=images.begin();
+ filename=_filename;
+ return true;
+
+
+ }
+ ofLogVerbose("JSON load: parsing unsuccesful\n");
+ return false;
}
diff --git a/gui/src/chainImage.h b/gui/src/chainImage.h
index ac78bd3..6fa5bca 100644
--- a/gui/src/chainImage.h
+++ b/gui/src/chainImage.h
@@ -1,6 +1,7 @@
#pragma once
#include "ofMain.h"
+#include "ofxJSON.h"
#define THUMB_BORDER_RATIO 0.8
@@ -17,7 +18,15 @@ class chainImage : public ofImage{
void start();
bool load(std::string _filename){
filename=_filename;
- return ofImage::load(filename);
+ if (ofImage::load(filename)){
+ makeThumbnail();
+
+ //could there be a way to load without committing the texture
+ setUseTexture(false);
+ return true;
+ }
+
+ return false;
}
bool update(float decayRatio);
@@ -29,17 +38,23 @@ class chainImage : public ofImage{
ofImage thumbnail;
void makeThumbnail();
+ Json::Value toJson();
+ bool fromJson(Json::Value json);
+
chainImage *link;
+
ofPoint linkPos;
float linkScale;
float linkRot;
+ std::string filename;
+
float transition;
float fadeIn;
float speed;
float time;
float scale;
- std::string filename;
+
};
@@ -56,8 +71,8 @@ class chainImageSet{
void mousePressed(int x, int y, int button);
void mouseReleased(int x, int y, int button);
- saveJson(std::string filename);
- loadJson(std::string filename);
+ bool saveJson(std::string filename);
+ bool loadJson(std::string filename);
std::list <chainImage> images;
float currentDefaultImageRatio;
diff --git a/gui/src/ofApp.cpp b/gui/src/ofApp.cpp
index cb808d1..7e25b42 100644
--- a/gui/src/ofApp.cpp
+++ b/gui/src/ofApp.cpp
@@ -84,6 +84,7 @@ void ofApp::dragEvent(ofDragInfo dragInfo){
filenames=filenames+", ";
}
filenames=filenames+*f;
+
images.add(*f,dragInfo.position);
}