summaryrefslogtreecommitdiff
path: root/gui/src
diff options
context:
space:
mode:
Diffstat (limited to 'gui/src')
-rw-r--r--gui/src/chainImage.cpp214
-rw-r--r--gui/src/chainImage.h56
-rw-r--r--gui/src/main.cpp19
-rw-r--r--gui/src/ofApp.cpp90
-rw-r--r--gui/src/ofApp.h31
5 files changed, 410 insertions, 0 deletions
diff --git a/gui/src/chainImage.cpp b/gui/src/chainImage.cpp
new file mode 100644
index 0000000..2ac6074
--- /dev/null
+++ b/gui/src/chainImage.cpp
@@ -0,0 +1,214 @@
+#include "chainImage.h"
+
+#define min(a,b) ((a) < (b) ? (a) : (b))
+#define max(a,b) ((a) > (b) ? (a) : (b))
+
+void chainImage::init(ofPoint _linkPos,float _linkScale,float _linkRot){
+ linkPos=_linkPos;
+ linkScale=_linkScale;
+ linkRot=_linkRot;
+ setAnchorPercent(0.5,0.5);
+}
+
+void chainImage::start(){
+ transition=0.0f;
+ time=ofGetElapsedTimef();
+ setUseTexture(true);
+ scale=linkScale;
+}
+
+bool chainImage::update(float decayRatio){
+
+ scale*=decayRatio;
+
+ transition=-(scale-linkScale)/(linkScale-(linkScale*link->linkScale));
+
+ if (scale>linkScale*link->linkScale) return false;
+ else {
+ transition = 1.0f;
+ return true;
+ }
+}
+ofVec3f chainImage::getTransform(){
+
+ ofVec3f _scaledTarget = link->linkPos * linkScale;
+
+ return linkPos + ( _scaledTarget * transition );
+}
+float chainImage::getScale(){
+
+ return scale;
+
+}
+void chainImage::makeThumbnail(){
+ thumbnail=(const ofImage)*this; //copy the ofImage itself
+
+ float thumbheight=ofGetHeight()*THUMB_BORDER_RATIO;
+ float thumbwidth=(thumbnail.getWidth()/thumbnail.getHeight())*thumbheight;
+
+ float borderwidth=ofGetHeight()*(1.0-THUMB_BORDER_RATIO)*0.5;
+
+ printf("Rescaling: %fx%f to %fx%f for screen %fx%f, border %f\n",
+ thumbnail.getWidth(),thumbnail.getHeight(),
+ thumbwidth,thumbheight,
+ (float)ofGetWidth(),(float)ofGetHeight(),
+ borderwidth);
+
+ thumbnail.resize(thumbwidth,thumbheight);
+
+ thumbnail.setAnchorPoint(thumbnail.getWidth()/2,thumbnail.getHeight()/2);
+}
+
+void chainImage::drawChain(float fadeIn){
+
+ glPushMatrix();
+
+ ofDisableAlphaBlending();
+
+ ofSetColor(255,255,255,255);
+
+ draw(0,0,getWidth(),getHeight());
+
+ glTranslatef(linkPos.x,linkPos.y,0);
+
+ glScalef(linkScale,linkScale,linkScale);
+
+ ofEnableAlphaBlending();
+
+ ofSetColor(255,255,255,255*min(1.0,transition/fadeIn));
+
+ link->draw(0,0,link->getWidth(),link->getHeight());
+
+ glPopMatrix();
+}
+
+void chainImageSet::drawGui(){
+ float t_xoffs=0.0;
+ float borderwidth=ofGetHeight()*(1.0-THUMB_BORDER_RATIO)*0.5;
+
+ //draw each image, outlined
+
+ for(std::list<chainImage>::iterator ii=images.begin(); ii != images.end(); ii++){
+
+ 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);
+
+ 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);
+
+ if (ii->link){
+
+ float subpictx=t_xoffs+borderwidth+thumbx+(ii->linkPos.x*thumbscale);
+ float subpicty=borderwidth+thumby+(ii->linkPos.y*thumbscale);
+
+ ofDrawLine(
+ subpictx,
+ subpicty,
+ t_xoffs+(borderwidth*3)+ii->thumbnail.getWidth(),
+ borderwidth+thumby
+
+ );
+
+ //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);
+
+ ii->link->thumbnail.draw(
+ subpictx,
+ subpicty,
+ ii->link->thumbnail.getWidth()*ii->linkScale,
+ ii->link->thumbnail.getHeight()*ii->linkScale
+ );
+
+ ofPoint p1=ofPoint(
+ subpictx-(ii->link->thumbnail.getWidth()*ii->linkScale*0.5),
+ subpicty-(ii->link->thumbnail.getHeight()*ii->linkScale*0.5));
+ ofPoint p2=ofPoint(
+ subpictx+(ii->link->thumbnail.getWidth()*ii->linkScale*0.5),
+ subpicty-(ii->link->thumbnail.getHeight()*ii->linkScale*0.5));
+ ofPoint p3=ofPoint(
+ subpictx+(ii->link->thumbnail.getWidth()*ii->linkScale*0.5),
+ subpicty+(ii->link->thumbnail.getHeight()*ii->linkScale*0.5));
+ ofPoint p4=ofPoint(
+ subpictx-(ii->link->thumbnail.getWidth()*ii->linkScale*0.5),
+ subpicty+(ii->link->thumbnail.getHeight()*ii->linkScale*0.5));
+
+ ofDrawLine(p1,p2);
+ ofDrawLine(p2,p3);
+ ofDrawLine(p3,p4);
+ ofDrawLine(p4,p1);
+
+
+ }
+
+
+ t_xoffs+=ii->thumbnail.getWidth()+(borderwidth*2) ;
+ }
+
+}
+
+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.makeThumbnail();
+
+ //could there be a way to load without committing the texture
+ image.setUseTexture(false);
+ 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());
+ }
+
+
+
+ return true;
+ }
+ printf("Could not load file: %s \n",filename.c_str());
+
+ return false;
+}
+
+
diff --git a/gui/src/chainImage.h b/gui/src/chainImage.h
new file mode 100644
index 0000000..03089a2
--- /dev/null
+++ b/gui/src/chainImage.h
@@ -0,0 +1,56 @@
+#pragma once
+
+#include "ofMain.h"
+
+#define THUMB_BORDER_RATIO 0.8
+
+class chainImage : public ofImage{
+ //todo: threaded image loader
+
+ public:
+ chainImage(){
+ link=NULL;
+ ofImage();
+ }
+ void init(ofPoint _linkPos,float _linkScale,float _linkRot);
+
+ void start();
+ bool load(std::string _filename){
+ filename=_filename;
+ return ofImage::load(filename);
+ }
+
+ bool update(float decayRatio);
+ ofVec3f getTransform();
+ float getScale();
+
+ void drawChain(float fadeIn);
+
+ ofImage thumbnail;
+ void makeThumbnail();
+
+ chainImage *link;
+ ofPoint linkPos;
+ float linkScale;
+ float linkRot;
+ float transition;
+ float fadeIn;
+ float speed;
+ float time;
+ float scale;
+
+ std::string filename;
+
+};
+
+class chainImageSet{
+ public:
+ chainImageSet(){
+ currentDefaultImageRatio=0.3;
+ }
+ void drawGui();
+ bool add(std::string filename,glm::vec2 pos);
+ std::list <chainImage> images;
+ float currentDefaultImageRatio;
+
+}; \ No newline at end of file
diff --git a/gui/src/main.cpp b/gui/src/main.cpp
new file mode 100644
index 0000000..0346c1e
--- /dev/null
+++ b/gui/src/main.cpp
@@ -0,0 +1,19 @@
+#include "ofMain.h"
+#include "ofApp.h"
+
+//========================================================================
+int main(int argc, char *argv[]){
+ ofSetupOpenGL(1600,250,OF_WINDOW); // <-------- setup the GL context
+
+ // this kicks off the running of my app
+ // can be OF_WINDOW or OF_FULLSCREEN
+ // pass in width and height too:
+ ofApp *app = new ofApp();
+
+ app->arguments = vector<string>(argv, argv + argc);
+
+ ofRunApp(app); // start the app
+
+
+}
+ \ No newline at end of file
diff --git a/gui/src/ofApp.cpp b/gui/src/ofApp.cpp
new file mode 100644
index 0000000..4000461
--- /dev/null
+++ b/gui/src/ofApp.cpp
@@ -0,0 +1,90 @@
+#include "ofApp.h"
+#include "glew.h"
+
+//--------------------------------------------------------------
+void ofApp::setup(){
+
+
+
+}
+
+//--------------------------------------------------------------
+void ofApp::update(){
+
+ std::stringstream strm;
+ strm << "fps: " << ofGetFrameRate();
+ ofSetWindowTitle(strm.str());
+
+
+}
+
+//--------------------------------------------------------------
+void ofApp::draw(){
+ ofBackground(0,0,0);
+
+ images.drawGui();
+}
+
+//--------------------------------------------------------------
+void ofApp::keyPressed(int key){
+
+}
+
+//--------------------------------------------------------------
+void ofApp::keyReleased(int key){
+
+}
+
+//--------------------------------------------------------------
+void ofApp::mouseMoved(int x, int y ){
+
+}
+
+//--------------------------------------------------------------
+void ofApp::mouseDragged(int x, int y, int button){
+
+}
+
+//--------------------------------------------------------------
+void ofApp::mousePressed(int x, int y, int button){
+
+}
+
+//--------------------------------------------------------------
+void ofApp::mouseReleased(int x, int y, int button){
+
+}
+
+//--------------------------------------------------------------
+void ofApp::mouseEntered(int x, int y){
+
+}
+
+//--------------------------------------------------------------
+void ofApp::mouseExited(int x, int y){
+
+}
+
+//--------------------------------------------------------------
+void ofApp::windowResized(int w, int h){
+
+}
+
+//--------------------------------------------------------------
+void ofApp::gotMessage(ofMessage msg){
+
+}
+
+//--------------------------------------------------------------
+void ofApp::dragEvent(ofDragInfo dragInfo){
+ std::string filenames;
+
+ for (auto f = dragInfo.files.begin(); f != dragInfo.files.end(); f++){
+ if (f!=dragInfo.files.begin()){
+ filenames=filenames+", ";
+ }
+ filenames=filenames+*f;
+ images.add(*f,dragInfo.position);
+ }
+
+}
diff --git a/gui/src/ofApp.h b/gui/src/ofApp.h
new file mode 100644
index 0000000..da9d734
--- /dev/null
+++ b/gui/src/ofApp.h
@@ -0,0 +1,31 @@
+#pragma once
+
+#include "ofMain.h"
+#include "chainImage.h"
+
+
+
+class ofApp : public ofBaseApp{
+
+ public:
+ void setup();
+ void update();
+ void draw();
+
+ void keyPressed(int key);
+ void keyReleased(int key);
+ void mouseMoved(int x, int y );
+ void mouseDragged(int x, int y, int button);
+ void mousePressed(int x, int y, int button);
+ void mouseReleased(int x, int y, int button);
+ void mouseEntered(int x, int y);
+ void mouseExited(int x, int y);
+ void windowResized(int w, int h);
+ void dragEvent(ofDragInfo dragInfo);
+ void gotMessage(ofMessage msg);
+
+ vector<string> arguments;
+
+ chainImageSet images;
+
+};