diff options
| author | Tim Redfern <tim@eclectronics.org> | 2014-04-26 18:20:21 +0100 |
|---|---|---|
| committer | Tim Redfern <tim@eclectronics.org> | 2014-04-26 18:20:21 +0100 |
| commit | 6f74f80e4c116c61b4734ffbae86aff881daaf5b (patch) | |
| tree | c0044aa2efefd53711cba63ed91860e265831703 /le_new/src/layers.cpp | |
| parent | ba9af7648a79b54836019ca792e40e81ca863c86 (diff) | |
started GLFW version
Diffstat (limited to 'le_new/src/layers.cpp')
| -rwxr-xr-x | le_new/src/layers.cpp | 229 |
1 files changed, 229 insertions, 0 deletions
diff --git a/le_new/src/layers.cpp b/le_new/src/layers.cpp new file mode 100755 index 0000000..bd0f1ce --- /dev/null +++ b/le_new/src/layers.cpp @@ -0,0 +1,229 @@ +#include "layers.h"
+
+svglayer::svglayer() {
+ xo=0;yo=0;
+}
+svglayer::svglayer(string _f)
+{
+ load(_f);
+}
+
+void svglayer::load(string _f){
+ //check if files exits
+ svg.load(_f);
+ printf("%s: %i paths\n",_f.c_str(),svg.getNumPath());
+ for (int i=0;i<svg.getNumPath();i++) {
+ fills.push_back(svg.getPathAt(i).getFillColor());
+ strokes.push_back(svg.getPathAt(i).getStrokeColor());
+ //printf(" path %i: fill %08x stroke %08x\n",i,svg.getPathAt(i).getFillColor().getHex(),svg.getPathAt(i).getStrokeColor().getHex());
+ }
+ isLoaded= (svg.getNumPath()>0);
+}
+void svglayer::getCentre(int cx,int cy) {
+ if (svg.getNumPath()>0) {
+ xo=(cx-svg.getWidth())/2;
+ yo=(cy-svg.getHeight())/2;
+ }
+}
+
+void svglayer::draw(float a,int cx,int cy,float colShift) {
+ getCentre(cx,cy);
+ for (int i=0;i<svg.getNumPath();i++) {
+ ofColor c=fills[i]*a;
+ if (colShift>0.0f) {
+ c.setHue(fmod(c.getHue()+colShift,255.0f));
+ //printf ("shift from %f to %f\n",c.getHue(),c.getHue()+colShift);
+ }
+ svg.getPathAt(i).setFillColor(c);
+ svg.getPathAt(i).draw(xo,yo);
+ }
+}
+/*
+void svglayer::draw(float a,unsigned char* controllers,int cx,int cy,bool transparentBlack,float colShift) {
+ getCentre(cx,cy);
+ //draw layers tinted by controllers
+ for (int i=0;i<svg.getNumPath();i++) {
+ float h=fmod(fills[i].getHue()+colShift,255.0f);
+ float ha=h/42.7; //0-5
+ int h1=(((int)ha)+2)%6;
+ int h2=h1+1;
+ float f2=ha-h1;
+ float f1=1.0f-f2;
+ //if (transparentBlack) printf("transparent black draw %f\n",(a*(((controllers[h1]*f1)+(controllers[h2]*f2))/127.0)));
+
+ svg.getPathAt(i).setFillColor(fills[i]*a*(((controllers[h1]*f1)+(controllers[h2]*f2))/127.0));;
+ if (!transparentBlack||(a*(((controllers[h1]*f1)+(controllers[h2]*f2))/127.0))>0.1) {
+ svg.getPathAt(i).draw(xo,yo);
+ }
+ }
+}
+*/
+
+void svglayer::draw(float a,unsigned char* controllers,int cx,int cy,bool transparentBlack,float colShift) {
+ getCentre(cx,cy);
+ //draw layers grouped by controllers
+ float layerspercontroller=((float)svg.getNumPath())/6.0f;
+
+ for (int i=0;i<6;i++) {
+ //for (int j=(int)((i+1)*layerspercontroller)-1;j>(int)(i*layerspercontroller);j--) {
+ for (int j=(int)(i*layerspercontroller);j<(int)((i+1)*layerspercontroller);j++) {
+ svg.getPathAt(j).setFillColor(fills[j]*a*(((float)controllers[5-i])/127.0f)); //try to reverse order of these
+ if (!transparentBlack||((a*controllers[5-i])/127.0f)>0.1) {
+ svg.getPathAt(j).draw(xo,yo);
+ }
+ }
+ }
+ //printf("counted %i layers of %i\n",(int)(6*layerspercontroller),svg.getNumPath());
+}
+
+
+svglayer::~svglayer()
+{
+ //dtor
+}
+
+//------------------------------------------------------------------------
+imglayer::imglayer() {
+ //sprite.setUseTexture(false);
+}
+imglayer::imglayer(string _filename,int _frames,int _start,float _rate,int n, int e){
+ load(_filename,_frames,_start,_rate,n,e);
+}
+
+void imglayer::load(string _filename,int _frames,int _start,float _rate,int n, int e){
+ startNote=n;
+ endNote=e;
+ sprite.load(_filename,_frames,_start);
+ sprite.setFrameRate(_rate);
+}
+
+
+void imglayer::draw(float a,int cx,int cy,float colShift) {
+ //if (sprite.isAllocated()) if (!sprite.isUsingTexture()) sprite.setUseTexture(true); //has to be done from the main thread? still doesn't work
+
+ sprite.update();
+ int x,y,w,h;
+ if ((((float)cx)/cy)<(((float)sprite.getWidth())/sprite.getHeight())){
+ x=0;
+ w=cx;
+ h=((float)cx)*(((float)sprite.getHeight())/sprite.getWidth());
+ y=(cy-h)/2;
+ }
+ else {
+ y=0;
+ h=cy;
+ w=((float)cy)*(((float)sprite.getWidth())/sprite.getHeight());
+ x=(cx-w)/2;
+ }
+ ofEnableAlphaBlending();
+ sprite.draw(x,y,w,h);
+ ofDisableAlphaBlending();
+}
+
+void imglayer::draw(float a,unsigned char* controllers,int cx,int cy,bool transparentBlack=false,float colShift=0.0f) {
+ imglayer::draw(a,cx,cy,colShift);
+}
+
+void imglayer::setNote(int note)
+{
+ //is called rerpeatedly no startNote,endNote
+ //printf("note %i (%i - %i)\n",note,startNote,endNote);
+ if ((startNote<=note)&&(endNote>=note)) {
+ if (!sprite.getIsPlaying()) {
+
+ sprite.play();
+
+ }
+ //printf("triggered frame %i of %i\n",(int)(((((float)note-startNote)/((float)endNote-startNote)))*sprite.getTotalFrames()),sprite.getTotalFrames());
+ sprite.setCurrentFrame((int)(((((float)note-startNote)/((float)endNote-startNote)))*sprite.getTotalFrames()));
+ //printf("movie %i (%i - %i) frame: %i\n",note,startNote,endNote,(int)(((((float)note-startNote)/((float)endNote-startNote)))*mov.getTotalNumFrames()));
+ }
+ else {
+ if (sprite.getIsPlaying()) {
+ sprite.stop();
+ }
+ }
+
+};
+
+
+imglayer::~imglayer()
+{
+ //sprite.setUseTexture(false); //free texture
+}
+//------------------------------------------------------------------------
+videolayer::videolayer() {
+ //sprite.setUseTexture(false);
+}
+videolayer::videolayer(string _f,int n,int e,float s)
+{
+ startNote=n;
+ endNote=e;
+ speed=s;
+ load(_f);
+}
+
+void videolayer::load(string _f){
+ name=_f;
+ mov.setPixelFormat(OF_PIXELS_BGRA);
+ mov.setUseTexture(false);
+ bool success=mov.loadMovie(_f);
+ if (success) {
+ mov.stop();
+ }
+ printf("%s %s %i bpp\n",success?"loaded":"not loaded",_f.c_str(),success?mov.getPixelsRef().getBytesPerPixel():0);
+}
+
+void videolayer::draw(float a,int cx,int cy,float colShift) {
+ if (mov.isPlaying()) {
+ mov.update();
+ //unsigned char *pix=mov.getPixels();
+ //for (int i=0;i<mov.getWidth()*mov.getHeight()*4;i+=4) pix[i+3]=(pix[i]>>2)+(pix[i+1]>>1)+(pix[i+2]>>2);
+ int x,y,w,h;
+ if ((((float)cx)/cy)<(((float)mov.getWidth())/mov.getHeight())){
+ x=0;
+ w=cx;
+ h=((float)cx)*(((float)mov.getHeight())/mov.getWidth());
+ y=(cy-h)/2;
+ }
+ else {
+ y=0;
+ h=cy;
+ w=((float)cy)*(((float)mov.getWidth())/mov.getHeight());
+ x=(cx-w)/2;
+ }
+ ofEnableAlphaBlending();
+ mov.draw(x,y,w,h);
+ ofDisableAlphaBlending();
+ }
+}
+
+void videolayer::draw(float a,unsigned char* controllers,int cx,int cy,bool transparentBlack=false,float colShift=0.0f) {
+ draw(a,cx,cy,colShift);
+}
+
+void videolayer::setNote(int note)
+{
+
+ if ((startNote<=note)&&(endNote>=note)) {
+ if (!mov.isPlaying()) {
+ //printf("starting movie!\n");
+ mov.setUseTexture(true);
+ mov.play();
+ mov.setSpeed(speed);
+ }
+ mov.setFrame((int)(((((float)note-startNote)/((float)endNote-startNote)))*mov.getTotalNumFrames()));
+ //printf("movie %i (%i - %i) frame: %i\n",note,startNote,endNote,(int)(((((float)note-startNote)/((float)endNote-startNote)))*mov.getTotalNumFrames()));
+ }
+ else {
+ if (mov.isPlaying()) {
+ mov.stop();
+ }
+ }
+
+};
+
+
+videolayer::~videolayer()
+{
+}
|
