diff options
| author | Tim Redfern <tim@eclectronics.org> | 2015-03-29 22:33:39 +0100 |
|---|---|---|
| committer | Tim Redfern <tim@eclectronics.org> | 2015-03-29 22:33:39 +0100 |
| commit | a28770084787abd086c30b0ed4483fe22c19dca4 (patch) | |
| tree | ee798bc2a464181ddf37999118420164d207f131 /sunkenEngine/src/layers.h | |
| parent | 1aef8df9feeff8c76411bb4f4faa2e51d3ee252e (diff) | |
working for parlour OSX
Diffstat (limited to 'sunkenEngine/src/layers.h')
| -rwxr-xr-x | sunkenEngine/src/layers.h | 134 |
1 files changed, 134 insertions, 0 deletions
diff --git a/sunkenEngine/src/layers.h b/sunkenEngine/src/layers.h new file mode 100755 index 0000000..d34664a --- /dev/null +++ b/sunkenEngine/src/layers.h @@ -0,0 +1,134 @@ +#ifndef SVGLAYER_H
+#define SVGLAYER_H
+
+#include "ofxSVGTiny.h"
+#include "ofMain.h"
+#include "ofxSprite.h"
+
+#include <math.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.0f);
+ ofSetColor(255,255,255,(1.0-fr)*255);
+ //not always?
+ getImageAtFrame(f).setUseTexture(true);
+ //getImageAtFrame(f).reloadTexture(); ->190315 still necessary?
+ getImageAtFrame(f).draw(x,y,w,h);
+ ofSetColor(255,255,255,fr*255);
+ f=(f+1)%getTotalFrames();
+ getImageAtFrame(f).setUseTexture(true);
+ //getImageAtFrame(f).reloadTexture(); ->190315 still necessary?
+ 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
|
