From 6f74f80e4c116c61b4734ffbae86aff881daaf5b Mon Sep 17 00:00:00 2001 From: Tim Redfern Date: Sat, 26 Apr 2014 18:20:21 +0100 Subject: started GLFW version --- le_new/src/layers.h | 132 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 132 insertions(+) create mode 100755 le_new/src/layers.h (limited to 'le_new/src/layers.h') diff --git a/le_new/src/layers.h b/le_new/src/layers.h new file mode 100755 index 0000000..0ddca29 --- /dev/null +++ b/le_new/src/layers.h @@ -0,0 +1,132 @@ +#ifndef SVGLAYER_H +#define SVGLAYER_H + +#include "ofxSVGTiny.h" +#include "ofMain.h" +#include "ofxSprite.h" + +class layer +{ + public: + layer(){}; + layer(string _f) {load(_f);}; + virtual ~layer(){}; + virtual void load(string _f){}; + virtual void draw(float a,int cx,int cy,float colShift){}; + virtual void draw(float a,unsigned char* controllers,int cx,int cy,bool transparentBlack=false,float colShift=0.0f){ draw(a,cx,cy,colShift);}; + bool getLoaded() {return isLoaded;}; + virtual void setNote(int note) {}; + string name; + int startNote,endNote; + protected: + bool isLoaded; + private: + +}; + +class svglayer: public layer +{ + public: + svglayer(); + svglayer(string _f); + virtual ~svglayer(); + void load(string _f); + void draw(float a,int cx,int cy,float colShift); + void draw(float a,unsigned char* controllers,int cx,int cy,bool transparentBlack=false,float colShift=0.0f); + void getCentre(int cx,int cy); + protected: + private: + ofxSVGTiny svg; + vector fills; + vector strokes; + float xo,yo; +}; + +class sunkenSprite: public ofxSprite { + public: + float playhead,frameRate; + void setFrameRate(float frameRate) { this->frameRate = frameRate;}; + void play() { + startTime=ofGetElapsedTimef(); + ofxSprite::play(); + } + void update() { + if (!getIsPlaying()) return; + playhead=fmod(speed * frameRate * (ofGetElapsedTimef()-startTime),(float)getTotalFrames()); + ofxSprite::setCurrentFrame(playhead); + + } + void setCurrentFrame(float frame) { + //this idea doesn't work - fucks up when frameRate is 0 - + //need to rethink + + //when frameRate is 0 startTime doesn't matter + //this still might not be not entirely correct + if (frameRate>0) startTime-=(frame-pos) / ((float)(frameRate * speed )); + //printf("sunkensprite setting frame %i of %i\n",(int)frame,getTotalFrames()); + //printf("1 checking frame %i of %i\n",(int)frame,getTotalFrames()); + ofxSprite::setCurrentFrame(frame); + /* + pos = frame; + printf("2 checking frame %i of %i\n",(int)frame,getTotalFrames()); + printf("requesting movie frame %i of %i\n",(int)pos,getTotalFrames()); + if (pos<0) if (loop) { pos += totalFrames; } else stop(); + if (pos>=totalFrames) if (loop) { + while (pos>=totalFrames) pos -= totalFrames; + } else { pos = totalFrames-.00001f; isPlaying=false; } + printf("set movie frame %i of %i\n",(int)pos,totalFrames); + */ + } + void draw(int x,int y,int w,int h) { + + int f=playhead; + float fr=fmod(playhead,1.0); + ofSetColor(255,255,255,(1.0-fr)*255); + //not always? + getImageAtFrame(f).setUseTexture(true); + getImageAtFrame(f).reloadTexture(); + getImageAtFrame(f).draw(x,y,w,h); + ofSetColor(255,255,255,fr*255); + f=(f+1)%getTotalFrames(); + getImageAtFrame(f).setUseTexture(true); + getImageAtFrame(f).reloadTexture(); + getImageAtFrame(f).draw(x,y,w,h); + } + + private: + float startTime; + float speed,pos; //will this override the base class speed correctly? + +}; + +class imglayer: public layer +{ + public: + imglayer(); + imglayer(string _f,int _frames=1,int _start=1,float _rate=0,int note=0,int endnote=0); + virtual ~imglayer(); + void load(string _filename,int _frames=1,int _start=1,float _rate=0.0,int note=0,int endnote=0); + void draw(float a,int cx,int cy,float colShift); + void draw(float a,unsigned char* controllers,int cx,int cy,bool transparentBlack,float colShift); + void setNote(int n); + protected: + private: + sunkenSprite sprite; +}; + +class videolayer: public layer +{ + public: + videolayer(); + videolayer(string _f,int n,int e,float s); + virtual ~videolayer(); + void load(string _f); + void draw(float a,int cx,int cy,float colShift); + void draw(float a,unsigned char* controllers,int cx,int cy,bool transparentBlack,float colShift); + void setNote(int n); + protected: + private: + float speed; + ofVideoPlayer mov; +}; +#endif // SVGLAYER_H -- cgit v1.2.3