summaryrefslogtreecommitdiff
path: root/gui
diff options
context:
space:
mode:
authorTim Redfern <tim@getdrop.com>2017-09-12 20:41:31 +0100
committerTim Redfern <tim@getdrop.com>2017-09-12 20:41:31 +0100
commit304c8f22dfb4e068685b2a1e1023129a7cd12eb4 (patch)
tree31f8b9c837e1234e171283cc7f63339dd6ad3d22 /gui
parentd68b8424c8e63cb84147d021608fe5a69b30b288 (diff)
threading not finished
Diffstat (limited to 'gui')
-rw-r--r--gui/src/chainImage.cpp431
-rw-r--r--gui/src/chainImage.h58
-rw-r--r--gui/src/ofApp.cpp3
-rw-r--r--gui/src/ofApp.h2
4 files changed, 6 insertions, 488 deletions
diff --git a/gui/src/chainImage.cpp b/gui/src/chainImage.cpp
index a9ef602..78731ba 100644
--- a/gui/src/chainImage.cpp
+++ b/gui/src/chainImage.cpp
@@ -14,7 +14,7 @@ void chainImage::init(ofPoint _linkPos,float _linkScale,float _linkRot){
setAnchorPercent(0.5,0.5);
}
-void chainImage::start(bool reverse=false){
+void chainImage::start(bool reverse){
transition=reverse?1.0f:0.0f;
time=ofGetElapsedTimef();
setUseTexture(true);
@@ -22,7 +22,7 @@ void chainImage::start(bool reverse=false){
}
-int chainImage::update(float decayRatio){
+int chainImage::updateOutput(float decayRatio){
//where there is rotation of the link, the path needs to be rotated
@@ -187,430 +187,3 @@ bool chainImage::fromJson(Json::Value json){
return false;
}
-void chainImageSet::drawOutput(){
-
- //movment and rotation are working on their own but not together.
-
- float camera_throw= (float)outputSize.y/(float)outputSize.x; //the ratio of z distance to x width
-
- camera_throw*=fitFactor; //fudge factor to allow tweening
-
- if (images.size()){
-
-/*
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- glOrtho(-ofGetWidth()/2, ofGetWidth()/2, ofGetHeight()/2, -ofGetHeight()/2, 0.0f, 5000.0f);
-*/
- glMatrixMode ( GL_MODELVIEW );
- glLoadIdentity ( );
- gluLookAt( currentImage->getTransform().x,
- currentImage->getTransform().y, // i1.linkPos.y+(xform.y*intervalpoint),
- currentImage->getWidth()*camera_throw*currentImage->getScale(),
- currentImage->getTransform().x,
- currentImage->getTransform().y, // i1.linkPos.y+(xform.y*intervalpoint),
- 0,
- sin(-currentImage->getRotation()*(PI/180)),
- cos(-currentImage->getRotation()*(PI/180)),
- 0);
-
-
- currentImage->drawChain(DEFAULT_FADEIN,additive,intensity);
-
- }
-
-}
-
-void chainImageSet::drawGui(int x,int y,bool is_selected){
-
- float t_xoffs=0.0;
- float borderwidth=THUMB_SIZE*0.1; //ofGetWindowHeight()*(1.0-THUMB_BORDER_RATIO)*0.5;
-
-
-
- /*
- float relscale=((float)ofGetWindowHeight())/THUMB_SIZE;
- glScalef(relscale,relscale,relscale);
- //scale view by distance betweeen thumnail size and window size: doesn't work
- */
-
- //draw each image, outlined
-
- glPushMatrix();
-
- glTranslatef(x,y,0);
-
- for(std::list<chainImage>::iterator ii=images.begin(); ii != images.end(); ii++){
-
- ofSetColor(255,255,255);
-
- float thumbx=ii->thumbnail.getWidth()/2;
- float thumby=ii->thumbnail.getHeight()/2;
- float thumbscale=ii->thumbnail.getWidth()/ii->getWidth();
-
-
- //why do I have to set this every time??
- ii->thumbnail.setAnchorPercent(0.5,0.5);
-
- ii->thumbnail.draw(
- t_xoffs+borderwidth+thumbx,
- borderwidth+thumby,
- ii->thumbnail.getWidth(),
- ii->thumbnail.getHeight()
- );
-
- ofSetColor(255,255,255);
- if (ii==selected) ofSetColor(255,0,0);
- if (&(*ii)==currentImage) ofSetColor(0,255,0);
-
- ofDrawLine(t_xoffs+borderwidth,borderwidth,
- t_xoffs+borderwidth+ii->thumbnail.getWidth(),borderwidth);
- ofDrawLine(t_xoffs+borderwidth+ii->thumbnail.getWidth(),borderwidth,
- t_xoffs+borderwidth+ii->thumbnail.getWidth(),borderwidth+ii->thumbnail.getHeight());
- ofDrawLine(t_xoffs+borderwidth+ii->thumbnail.getWidth(),borderwidth+ii->thumbnail.getHeight(),
- t_xoffs+borderwidth,borderwidth+ii->thumbnail.getHeight());
- ofDrawLine(t_xoffs+borderwidth,borderwidth+ii->thumbnail.getHeight(),
- t_xoffs+borderwidth,borderwidth);
-
- ofSetColor(255,255,255);
-
- if (ii->link){
- ofPoint lp=ii->linkPos;
- if (ii==selected){
- lp+=dragPoint;
- }
-
- float subpictx=t_xoffs+borderwidth+thumbx+(lp.x*thumbscale);
- float subpicty=borderwidth+thumby+(lp.y*thumbscale);
-
- ofDrawLine(
- subpictx,
- subpicty,
- t_xoffs+(borderwidth*3)+ii->thumbnail.getWidth(),
- borderwidth+thumby
-
- );
-
- glPushMatrix();
-
- glTranslatef(subpictx,subpicty,0);
-
- float r=ii->linkRot;
- if (ii==selected) r+=dragRotate;
- glRotatef(r,0,0,1);
-
- //printf("Sub image: centre at %f,%f \n",ii->link->thumbnail.getAnchorPoint().x,ii->link->thumbnail.getAnchorPoint().y);
-
- ii->link->thumbnail.setAnchorPercent(0.5,0.5);
-
- float thescale=ii->linkScale;
- if (ii==selected){
- thescale*=(1.0f+dragScale);
- }
-
- ii->link->thumbnail.draw(
- 0,
- 0,
- ii->link->thumbnail.getWidth()*thescale,
- ii->link->thumbnail.getHeight()*thescale
- );
-
- ofPoint p1=ofPoint(
- -(ii->link->thumbnail.getWidth()*thescale*0.5),
- -(ii->link->thumbnail.getHeight()*thescale*0.5));
- ofPoint p2=ofPoint(
- (ii->link->thumbnail.getWidth()*thescale*0.5),
- -(ii->link->thumbnail.getHeight()*thescale*0.5));
- ofPoint p3=ofPoint(
- (ii->link->thumbnail.getWidth()*thescale*0.5),
- (ii->link->thumbnail.getHeight()*thescale*0.5));
- ofPoint p4=ofPoint(
- -(ii->link->thumbnail.getWidth()*thescale*0.5),
- (ii->link->thumbnail.getHeight()*thescale*0.5));
-
- ofDrawLine(p1,p2);
- ofDrawLine(p2,p3);
- ofDrawLine(p3,p4);
- ofDrawLine(p4,p1);
-
-
-
- glPopMatrix();
-
- }
-
-
- t_xoffs+=ii->thumbnail.getWidth()+(borderwidth*2);
-
-
- }
-
- if (is_selected) {
- ofSetColor(0,0,255);
- ofPolyline box;
- box.addVertex(ofPoint(5,5));
- box.addVertex(ofPoint(t_xoffs-5,5));
- box.addVertex(ofPoint(t_xoffs-5,(THUMB_SIZE/THUMB_BORDER_RATIO)-10));
- box.addVertex(ofPoint(5,(THUMB_SIZE/THUMB_BORDER_RATIO)-10));
- box.addVertex(ofPoint(5,5));
- box.draw();
- }
-
-
- glPopMatrix();
-
-}
-
-bool chainImageSet::add(std::string filename,glm::vec2 pos){
- printf("Dropped file: %s at %f,%f \n",filename.c_str(),pos.x,pos.y);
-/*
-attempt to add file to chain.
-find if file exists in data folder
-if not make a symbolic link
-*/
- chainImage image;
- if (image.load(filename)){
-
- image.init(ofPoint(0,0),
- currentDefaultImageRatio,
- 0 //default rotation
- );
-
- printf("Loaded file: %s at %f,%f \n",filename.c_str(),pos.x,pos.y);
-
-
- images.push_back(image);
- (*images.rbegin()).link=&(*images.begin());
-
- printf("Linked: %s to %s\n",
- images.rbegin()->filename.c_str(),
- images.begin()->filename.c_str());
-
-
- if (images.size()>1){
- (++images.rbegin())->link=&(*(images.rbegin()));
- printf("Linked: %s to %s\n",
- (++images.rbegin())->filename.c_str(),
- images.rbegin()->filename.c_str());
- }
- else {
- selected=images.begin();
- currentImage=&(*images.begin());
- currentImage->start();
- }
-
-
-
- return true;
- }
- printf("Could not load file: %s \n",filename.c_str());
-
- return false;
-}
-
-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();
- }
- else --selected;
- break;
- case ']':
- ++selected;
- if (selected==images.end()){
- selected=images.begin();
- }
- break;
- case OF_KEY_UP:
- selected->linkPos.y--;
- break;
- case OF_KEY_DOWN:
- selected->linkPos.y++;
- break;
- case OF_KEY_LEFT:
- selected->linkPos.x--;
- break;
- case OF_KEY_RIGHT:
- selected->linkPos.x++;
- break;
- case OF_KEY_BACKSPACE:{
- images.clear();
- filename.clear();
- /*
- auto previous=selected;
- previous--;
- if (previous==images.end()){
- previous=images.end()--;
- }
- previous->link=selected->link;
- printf("DELETED: %s \n",selected->filename.c_str());
- images.erase(selected);
- selected=previous++;
- if (selected==images.end()){
- selected=images.begin();
- }
- 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){
-
-
- bool success=loadJson(openFileResult.fileName);
-
- ofLogVerbose("Load %s %s\n",
- openFileResult.filePath.c_str(),
- success?"succeeded":"failed");
-
-
- }else {
- ofLogVerbose("User hit cancel");
- }
- break;
-
- }
- }
-}
-
-//--------------------------------------------------------------
-void chainImageSet::mouseDragged(int x, int y, int button){
- switch (button){
- case OF_MOUSE_BUTTON_1:
- dragPoint=ofPoint(x-clickPoint.x,y-clickPoint.y)*(selected->getHeight()/ofGetWindowHeight());
- break;
- case OF_MOUSE_BUTTON_2:
- //alt-click
- dragRotate=((clickPoint.x-x)/(selected->thumbnail.getWidth()))*180.0f;
- break;
- case OF_MOUSE_BUTTON_3:
- //control-click
- dragScale=(y-clickPoint.y)/(selected->thumbnail.getHeight());
- //if (dragScale*selected->linkScale<0.15){
- // dragScale=0.15/selected->linkScale;
- //}
- break;
- }
- }
-
-//--------------------------------------------------------------
-void chainImageSet::mousePressed(int x, int y, int button){
- //todo: select
- clickPoint=ofPoint(x,y);
-}
-
-//--------------------------------------------------------------
-void chainImageSet::mouseReleased(int x, int y, int button){
- 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){
- 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){
- 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();
- currentImage=&(*images.begin());
- currentImage->start();
- filename=_filename;
- return true;
-
-
- }
- ofLogVerbose("JSON load: parsing unsuccesful\n");
- return false;
-}
-
-void chainImageSet::update(){
-
- if (images.size()){
- int switchResponse=currentImage->update(decayFactor);
- switch(switchResponse){
- case SWITCH_FORWARD:{
- currentImage=currentImage->link;
- currentImage->start();
- ofLogNotice() << "Switched images forward";
- currentImage->update(decayFactor);
- break;
- }
- case SWITCH_NONE:
- break;
- case SWITCH_REVERSE:{
- for (auto ii=images.begin();ii!=images.end();++ii){
- if (ii->link->filename==currentImage->filename){
- currentImage=&(*ii);
- currentImage->start(true);
- ofLogNotice() << "Switched images reverse";
- currentImage->update(decayFactor);
- break;
- }
- }
- break;
- }
- }
- }
-}
-
-
diff --git a/gui/src/chainImage.h b/gui/src/chainImage.h
index 66b2dbf..30a1cd2 100644
--- a/gui/src/chainImage.h
+++ b/gui/src/chainImage.h
@@ -2,7 +2,6 @@
#include "ofMain.h"
#include "ofxJSON.h"
-#include "ofxThreadedImageLoader.h"
#define THUMB_BORDER_RATIO 0.8
#define THUMB_SIZE 160
@@ -24,7 +23,7 @@ class chainImage : public ofImage{
}
void init(ofPoint _linkPos,float _linkScale,float _linkRot);
- void start(bool reverse);
+ void start(bool reverse=false);
bool load(std::string _filename){
filename=_filename;
if (ofImage::load(filename)){
@@ -39,7 +38,7 @@ class chainImage : public ofImage{
return false;
}
- int update(float decayRatio);
+ int updateOutput(float decayRatio);
ofVec3f getTransform();
float getScale();
float getRotation();
@@ -71,56 +70,3 @@ class chainImage : public ofImage{
};
-class chainImageSet{
- public:
- chainImageSet(){
- currentDefaultImageRatio=0.3;
- filename="";
- outputSize=ofPoint(1024,576);
- decayFactor=.999;
- additive=false;
- intensity=1.0f;
- fitFactor=0.9f;
- dragScale=0.0f;
- dragRotate=0.0f;
- dragPoint=ofPoint(0,0);
- }
- chainImageSet(const chainImageSet& mom){
- chainImageSet();
- }
- void drawGui(int x,int y,bool is_selected);
- void drawOutput();
- void update();
- bool add(std::string filename,glm::vec2 pos);
- 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);
-
- bool saveJson(std::string filename);
- bool loadJson(std::string filename);
-
- ofPoint outputSize;
-
- std::list <chainImage> images;
-
- float currentDefaultImageRatio;
-
- std::list<chainImage>::iterator selected;
- ofPoint clickPoint;
- ofPoint dragPoint;
- float dragScale;
- float dragRotate;
- float fitFactor;
-
- std::string filename;
-
- chainImage *currentImage;
-
- float decayFactor;
-
- bool additive;
- float intensity;
-
- ofxThreadedImageLoader loader;
-}; \ No newline at end of file
diff --git a/gui/src/ofApp.cpp b/gui/src/ofApp.cpp
index a264f83..2e8fe90 100644
--- a/gui/src/ofApp.cpp
+++ b/gui/src/ofApp.cpp
@@ -47,13 +47,12 @@ void ofApp::update(){
strm << "fps: " << ofGetFrameRate();
ofSetWindowTitle(strm.str());
-
}
void ofApp::updateOutput(ofEventArgs & args){
for (int i=0;i<sets.size();i++){
- sets[i].update();
+ sets[i].updateOutput();
}
}
diff --git a/gui/src/ofApp.h b/gui/src/ofApp.h
index 8216a9c..82db257 100644
--- a/gui/src/ofApp.h
+++ b/gui/src/ofApp.h
@@ -4,7 +4,7 @@
#include "ofxDmx.h"
//#include "ofxArtnet.h"
#include "ofxMidi.h"
-#include "chainImage.h"
+#include "chainImageSet.h"