summaryrefslogtreecommitdiff
path: root/liveengineUnmapped/src/layers.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'liveengineUnmapped/src/layers.cpp')
-rwxr-xr-xliveengineUnmapped/src/layers.cpp115
1 files changed, 115 insertions, 0 deletions
diff --git a/liveengineUnmapped/src/layers.cpp b/liveengineUnmapped/src/layers.cpp
new file mode 100755
index 0000000..4ac0c59
--- /dev/null
+++ b/liveengineUnmapped/src/layers.cpp
@@ -0,0 +1,115 @@
+#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*layerspercontroller);j<(int)((i+1)*layerspercontroller);j++) {
+ svg.getPathAt(j).setFillColor(fills[i]*a*controllers[i]);
+ if (!transparentBlack||((a*controllers[i])/127.0)>0.1) {
+ svg.getPathAt(j).draw(xo,yo);
+ }
+ }
+ }
+}
+
+
+svglayer::~svglayer()
+{
+ //dtor
+}
+
+imglayer::imglayer() {
+ //img.setUseTexture(false);
+}
+imglayer::imglayer(string _f)
+{
+ load(_f);
+}
+
+void imglayer::load(string _f){
+ bool success=img.loadImage(_f);
+ printf("%s\n",success?"loaded":"not loaded");
+}
+
+/*
+WTF is going on with the image drawing
+
+
+*/
+void imglayer::draw(float a,int cx,int cy,float colShift) {
+ //if (img.isAllocated()) if (!img.isUsingTexture()) img.setUseTexture(true); //has to be done from the main thread? still doesn't work
+ img.draw(0,0,ofGetWidth(),ofGetHeight());
+ printf("drawing %f\n",ofGetElapsedTimef());
+}
+
+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);
+}
+
+
+imglayer::~imglayer()
+{
+ //img.setUseTexture(false); //free texture
+}