diff options
| author | Tim Redfern <tim@eclectronics.org> | 2015-04-12 22:20:30 +0100 |
|---|---|---|
| committer | Tim Redfern <tim@eclectronics.org> | 2015-04-12 22:20:30 +0100 |
| commit | 8c86c8e56d5948f44ba7524284824bbc6eff952b (patch) | |
| tree | 704dc88be2f22c69b4d16838092bc83cf692a75b /liveengine/src/layers.h | |
Diffstat (limited to 'liveengine/src/layers.h')
| -rwxr-xr-x | liveengine/src/layers.h | 131 |
1 files changed, 131 insertions, 0 deletions
diff --git a/liveengine/src/layers.h b/liveengine/src/layers.h new file mode 100755 index 0000000..f8ed650 --- /dev/null +++ b/liveengine/src/layers.h @@ -0,0 +1,131 @@ +#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 <ofColor> fills; + vector <ofColor> 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; + +}; +
+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
|
