1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
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
}
|