summaryrefslogtreecommitdiff
path: root/liveengineUnmapped/src/viewport.cpp
blob: a169146eb58c83ff8d81a93998d3e048d2352936 (plain)
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#include "viewport.h"



viewport::viewport()
{
    //ctor
}
viewport::viewport(int _w,int _h,int _x,int _y,float _r,int _ox,int _oy) {
	setup(_w,_h,_x,_y,_r,_ox,_oy);
}

void viewport::setup(int _w,int _h,int _x,int _y,float _r,int _ox,int _oy) {
	r=_r;
	w=_w;
	h=_h;
	x=_x;
	y=_y;
	ox=_ox;
	oy=_oy;
	rb1.allocate(w,h,GL_RGB);
	rb2.allocate(w,h,GL_RGB);

	printf("%ix%i, vp offset: %f,%f\n",w,h,-(sin(ofDegToRad(r))*h/2)-(cos(ofDegToRad(r))*w/2),-(sin(ofDegToRad(r))*w/2)-(cos(ofDegToRad(r))*h/2));
}

void viewport::draw(float a,unsigned char* controllers,int xshift,int yshift,playlist &list,bool transparentBlack,int note,int mode,ofColor* controller_colours,bool controlColours,float scale,float fscale,float colShift,int fadeBG){
	
	//http://forum.xfce.org/viewtopic.php?id=6580
		
		// test screen shape
		/*
		ofSetColor(255,0,0);
		ofRect(0,0,w/2,h/2);
		ofRect(w/2,h/2,w/2,h/2);
		ofSetColor(0,255,0);
		ofRect(0,h/2,w/2,h/2);
		ofRect(w/2,0,w/2,h/2);
		*/

		ofPushMatrix();
		
		rb1.begin();

		//can be done with texture offset?

		int startx=((w-(w*fscale))/2)+xshift;
		while (startx>0) startx-=(w*fscale);
		int starty=((h-(h*fscale))/2)+yshift;
		while (starty>0) starty-=(h*fscale);
		
		for (int i=startx;i<w*2;i+=(w*fscale)) {
			for (int j=starty;j<h*2;j+=(h*fscale)) {
			    rb2.draw(i,j,w*fscale,h*fscale);
			}
		}

		if (fadeBG>0) {
			//fadeout part
			ofEnableAlphaBlending();
			ofSetColor(0,0,0,fadeBG);
			ofRect(0,0,w,h);
			ofDisableAlphaBlending();
		}

		float notewidth=w/NUM_NOTES;
		float noteheight=h/NUM_CONTROLLERS;

		ofPushStyle();

			if (note>0) {
				switch(mode) {
					case BLOCKS:
						for (int i=0;i<NUM_CONTROLLERS;i++){
						ofSetColor(ofColor((controller_colours[i].r*controllers[i])>>7,(controller_colours[i].g*controllers[i])>>7,(controller_colours[i].b*controllers[i])>>7));
						ofRect((note-START_NOTE)*notewidth,i*noteheight,notewidth,noteheight);
						}
						break;
					case LIST:
				if (list.lock()) { //if playlist is loaded
				    if (list.layers.find(note)!=list.layers.end()) {
					ofPushMatrix();
					ofTranslate(w/2,h/2);
					ofScale(scale,scale,scale);
					ofTranslate(-w/2,-h/2);
					ofSetColor(255,255,255);
					if (controlColours) list.layers[note]->draw(a,controllers,w,h,transparentBlack,colShift);
					else list.layers[note]->draw(a,w,h,colShift);
					ofPopMatrix();
				    }
				    list.unlock();
				}
						break;
				}
			}

			ofPopStyle();

			rb1.end();

			rb2.begin();
			ofSetColor(255,255,255);
			rb1.draw(0,0);
			rb2.end();

			ofPopMatrix();
			
			ofPushMatrix();
			//ofTranslate(x+(w/2),y+(h/2)); this was the one that was working
			//ofTranslate(abs(sin(ofDegToRad(r))*h/2)+abs(cos(ofDegToRad(r))*w/2),abs(sin(ofDegToRad(r))*w/2)+abs(cos(ofDegToRad(r))*h/2));
			ofTranslate(x,y);

			ofTranslate(((w/2)*abs(cos(ofDegToRad(r))))+((h/2)*abs(sin(ofDegToRad(r)))),
				((w/2)*abs(sin(ofDegToRad(r))))+((h/2)*abs(cos(ofDegToRad(r)))));

			ofRotate(r);
			ofTranslate(-w/2,-h/2);
			//ofTranslate(-abs(sin(ofDegToRad(r))*h/2)-abs(cos(ofDegToRad(r))*w/2),-abs(sin(ofDegToRad(r))*w/2)-abs(cos(ofDegToRad(r))*h/2));
			//ofTranslate(ox,oy); get rid of this and get the rotation right
			
			ofDisableAlphaBlending();

			rb2.draw(0,0);	

			ofPopMatrix();
			
		
	
	

}

viewport::~viewport()
{
    //dtor
}