diff options
| author | Tim Redfern <tim@getdrop.com> | 2017-08-31 00:34:32 +0100 |
|---|---|---|
| committer | Tim Redfern <tim@getdrop.com> | 2017-08-31 00:34:32 +0100 |
| commit | b0d54aadaf9dfb3b2f14974f55b3a725619ea445 (patch) | |
| tree | ad882b21f92f3124cb0713494d15fbc4614ecfc7 /gui | |
| parent | 52f12dfc10edfc4dd063b610f65dd2e901d3080c (diff) | |
correct window scale
Diffstat (limited to 'gui')
| -rw-r--r-- | gui/src/chainImage.cpp | 69 | ||||
| -rw-r--r-- | gui/src/chainImage.h | 14 | ||||
| -rw-r--r-- | gui/src/main.cpp | 30 | ||||
| -rw-r--r-- | gui/src/ofApp.cpp | 20 | ||||
| -rw-r--r-- | gui/src/ofApp.h | 3 |
5 files changed, 124 insertions, 12 deletions
diff --git a/gui/src/chainImage.cpp b/gui/src/chainImage.cpp index 67fbad6..643bb2e 100644 --- a/gui/src/chainImage.cpp +++ b/gui/src/chainImage.cpp @@ -47,15 +47,15 @@ float chainImage::getScale(){ void chainImage::makeThumbnail(){ thumbnail=(const ofImage)*this; //copy the ofImage itself - float thumbheight=ofGetHeight()*THUMB_BORDER_RATIO; + float thumbheight=THUMB_SIZE; //ofGetWindowHeight()*THUMB_BORDER_RATIO; float thumbwidth=(thumbnail.getWidth()/thumbnail.getHeight())*thumbheight; - float borderwidth=ofGetHeight()*(1.0-THUMB_BORDER_RATIO)*0.5; + float borderwidth=ofGetWindowHeight()*(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(), + (float)ofGetWindowWidth(),(float)ofGetWindowHeight(), borderwidth); thumbnail.resize(thumbwidth,thumbheight); @@ -71,6 +71,8 @@ void chainImage::drawChain(float fadeIn){ ofSetColor(255,255,255,255); + setAnchorPoint(getWidth()/2,getHeight()/2); + draw(0,0,getWidth(),getHeight()); glTranslatef(linkPos.x,linkPos.y,0); @@ -81,6 +83,8 @@ void chainImage::drawChain(float fadeIn){ ofSetColor(255,255,255,255*min(1.0,transition/fadeIn)); + link->setAnchorPoint(link->getWidth()/2,link->getHeight()/2); + link->draw(0,0,link->getWidth(),link->getHeight()); glPopMatrix(); @@ -107,9 +111,42 @@ bool chainImage::fromJson(Json::Value json){ return false; } +void chainImageSet::drawOutput(){ + + float camera_throw= (float)outputSize.y/(float)outputSize.x; //the ratio of z distance to x width + + if (images.size()){ + + 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, + 0,1,0); + + currentImage->drawChain(); + + } + +} + void chainImageSet::drawGui(){ + + ofBackground(0,0,0); + float t_xoffs=0.0; - float borderwidth=ofGetHeight()*(1.0-THUMB_BORDER_RATIO)*0.5; + float borderwidth=THUMB_SIZE*0.1; //ofGetWindowHeight()*(1.0-THUMB_BORDER_RATIO)*0.5; + + glPushMatrix(); + + /* + 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 @@ -210,7 +247,9 @@ void chainImageSet::drawGui(){ } - t_xoffs+=ii->thumbnail.getWidth()+(borderwidth*2) ; + t_xoffs+=ii->thumbnail.getWidth()+(borderwidth*2); + + //glPopMatrix(); } } @@ -249,6 +288,8 @@ if not make a symbolic link } else { selected=images.begin(); + currentImage=&(*images.begin()); + currentImage->start(); } @@ -334,7 +375,7 @@ void chainImageSet::keyPressed(ofKeyEventArgs &keyargs){ 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()/ofGetHeight()); + dragPoint=ofPoint(x-clickPoint.x,y-clickPoint.y)*(selected->getHeight()/ofGetWindowHeight()); break; case OF_MOUSE_BUTTON_2: //alt-click @@ -402,6 +443,8 @@ bool chainImageSet::loadJson(std::string _filename){ } selected=images.begin(); + currentImage=&(*images.begin()); + currentImage->start(); filename=_filename; return true; @@ -410,7 +453,17 @@ bool chainImageSet::loadJson(std::string _filename){ ofLogVerbose("JSON load: parsing unsuccesful\n"); return false; } - - + +void chainImageSet::update(){ + float decay_factor=0.995; + if (images.size()){ + if (currentImage->update(decay_factor)){ //if returns true, switch images + currentImage=currentImage->link; + currentImage->start(); + ofLogNotice() << "Switched images"; + currentImage->update(decay_factor); + } + } +} diff --git a/gui/src/chainImage.h b/gui/src/chainImage.h index 6fa5bca..2ac3566 100644 --- a/gui/src/chainImage.h +++ b/gui/src/chainImage.h @@ -4,6 +4,8 @@ #include "ofxJSON.h" #define THUMB_BORDER_RATIO 0.8 +#define THUMB_SIZE 160 +#define DEFAULT_FADEIN 0.3 class chainImage : public ofImage{ //todo: threaded image loader @@ -22,7 +24,8 @@ class chainImage : public ofImage{ makeThumbnail(); //could there be a way to load without committing the texture - setUseTexture(false); + //setUseTexture(false); + setAnchorPoint(getWidth()/2,getHeight()/2); return true; } @@ -33,7 +36,7 @@ class chainImage : public ofImage{ ofVec3f getTransform(); float getScale(); - void drawChain(float fadeIn); + void drawChain(float fadeIn=DEFAULT_FADEIN); ofImage thumbnail; void makeThumbnail(); @@ -63,8 +66,11 @@ class chainImageSet{ chainImageSet(){ currentDefaultImageRatio=0.3; filename=""; + outputSize=ofPoint(1024,576); } void drawGui(); + void drawOutput(); + void update(); bool add(std::string filename,glm::vec2 pos); void keyPressed(ofKeyEventArgs &keyargs); void mouseDragged(int x, int y, int button); @@ -74,6 +80,8 @@ class chainImageSet{ bool saveJson(std::string filename); bool loadJson(std::string filename); + ofPoint outputSize; + std::list <chainImage> images; float currentDefaultImageRatio; @@ -84,4 +92,6 @@ class chainImageSet{ float dragRotate; std::string filename; + + chainImage *currentImage; };
\ No newline at end of file diff --git a/gui/src/main.cpp b/gui/src/main.cpp index 072f406..52f9d48 100644 --- a/gui/src/main.cpp +++ b/gui/src/main.cpp @@ -3,6 +3,7 @@ //======================================================================== int main(int argc, char *argv[]){ + /* ofSetupOpenGL(1600,200,OF_WINDOW); // <-------- setup the GL context // this kicks off the running of my app @@ -10,10 +11,37 @@ int main(int argc, char *argv[]){ // pass in width and height too: ofApp *app = new ofApp(); - app->arguments = vector<string>(argv, argv + argc); + ofRunApp(app); // start the app + */ + + //app->arguments = vector<string>(argv, argv + argc); + + ofGLFWWindowSettings settings; + settings.width = 1024; + settings.height = 576; + settings.setPosition(ofVec2f(300,0)); + settings.resizable = true; + shared_ptr<ofAppBaseWindow> mainWindow = ofCreateWindow(settings); + + settings.width = 1600; + settings.height = 200; + settings.setPosition(ofVec2f(0,700)); + settings.resizable = true; + // uncomment next line to share main's OpenGL resources with gui + settings.shareContextWith = mainWindow; + shared_ptr<ofAppBaseWindow> guiWindow = ofCreateWindow(settings); + guiWindow->setVerticalSync(false); + + shared_ptr<ofApp> mainApp(new ofApp); + //mainApp->setupGui(); + ofAddListener(mainWindow->events().update,mainApp.get(),&ofApp::updateOutput); + ofAddListener(mainWindow->events().draw,mainApp.get(),&ofApp::drawOutput); + ofAddListener(mainWindow->events().windowResized,mainApp.get(),&ofApp::outputWindowResized); + ofRunApp(guiWindow, mainApp); + ofRunMainLoop(); }
\ No newline at end of file diff --git a/gui/src/ofApp.cpp b/gui/src/ofApp.cpp index 7e25b42..b026984 100644 --- a/gui/src/ofApp.cpp +++ b/gui/src/ofApp.cpp @@ -18,13 +18,26 @@ void ofApp::update(){ } +void ofApp::updateOutput(ofEventArgs & args){ + + images.update(); + +} + + //-------------------------------------------------------------- void ofApp::draw(){ ofBackground(0,0,0); - images.drawGui(); } +void ofApp::drawOutput(ofEventArgs & args){ + ofBackground(0,0,0); + + images.drawOutput(); + +} + //-------------------------------------------------------------- void ofApp::keyPressed(ofKeyEventArgs &keyargs){ images.keyPressed(keyargs); @@ -70,6 +83,11 @@ void ofApp::windowResized(int w, int h){ } +void ofApp::outputWindowResized(ofResizeEventArgs &resizeargs){ + //printf("Output window: %i,%i \n",resizeargs.width,resizeargs.height); + images.outputSize=ofPoint(resizeargs.width,resizeargs.height); +} + //-------------------------------------------------------------- void ofApp::gotMessage(ofMessage msg){ diff --git a/gui/src/ofApp.h b/gui/src/ofApp.h index ceb3e41..ac6d850 100644 --- a/gui/src/ofApp.h +++ b/gui/src/ofApp.h @@ -10,7 +10,9 @@ class ofApp : public ofBaseApp{ public: void setup(); void update(); + void updateOutput(ofEventArgs & args); void draw(); + void drawOutput(ofEventArgs & args); void keyPressed(ofKeyEventArgs &keyargs); void keyReleased(int key); @@ -21,6 +23,7 @@ class ofApp : public ofBaseApp{ void mouseEntered(int x, int y); void mouseExited(int x, int y); void windowResized(int w, int h); + void outputWindowResized(ofResizeEventArgs &resizeargs); void dragEvent(ofDragInfo dragInfo); void gotMessage(ofMessage msg); |
