summaryrefslogtreecommitdiff
path: root/cubedbusWindow.c.in
blob: d7db8a24ca2b2b93117ae9a3f7ec4d180d713c1d (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
#define CUBEDBUS_WINDOW_OBJECT 4

typedef struct _CubedbusWindowObject CubedbusWindowObject;


static bool cubedbusDrawWindowObject (CubedbusObject *obj);
static bool cubedbusDeleteWindowObject (CubedbusObject *obj);
static bool cubedbusModifyWindowObject (CubedbusObject *obj, CompOption *option, int nOption);
static bool cubedbusAddWindowObject (CubedbusObject *obj, CompOption *option, int nOption);

struct _CubedbusWindowObject
{
CompWindow *w;


GLuint dList;
bool order;
float rotate[4], translate[3], scale[3];
float rotateSpeed;

float x0,x1,x2,x3;
float y0,y1,y2,y3;
float z0,z1,z2,z3;
};


static bool
cubedbusAddWindowObject (CubedbusObject *obj, CompOption *option, int nOption)
{
	obj->data= malloc( sizeof(CubedbusWindowObject) );
		if(obj->data == NULL) return FALSE;
				
	CubedbusWindowObject *windowData=obj->data;	
	
	windowData->rotate[0]=getFloatOptionNamed (option,nOption, "rotateAngle", 0.0);
	windowData->rotate[1]=getFloatOptionNamed (option,nOption, "rotateX", 0.0);
	windowData->rotate[2]=getFloatOptionNamed (option,nOption, "rotateY", 0.0);
	windowData->rotate[3]=getFloatOptionNamed (option,nOption, "rotateZ", 0.0);
	windowData->translate[0]=getFloatOptionNamed (option,nOption, "translateX", 0.0);
	windowData->translate[1]=getFloatOptionNamed (option,nOption, "translateY", 0.0);
	windowData->translate[2]=getFloatOptionNamed (option,nOption, "translateZ", 0.0);
	windowData->scale[0]=getFloatOptionNamed (option,nOption, "scaleX", 1.0);
	windowData->scale[1]=getFloatOptionNamed (option,nOption, "scaleY", 1.0);
	windowData->scale[2]=getFloatOptionNamed (option,nOption, "scaleZ", 1.0);
	windowData->order=getBoolOptionNamed (option, nOption, "order", TRUE);
	windowData->rotateSpeed=getFloatOptionNamed (option, nOption, "rotateSpeed", 0);
	
	windowData->x0=getFloatOptionNamed (option, nOption, "x0", 0);
	windowData->x1=getFloatOptionNamed (option, nOption, "x1", 0);
	windowData->x2=getFloatOptionNamed (option, nOption, "x2", 0);
	windowData->x3=getFloatOptionNamed (option, nOption, "x3", 0);
	
	windowData->y0=getFloatOptionNamed (option, nOption, "y0", 0);
	windowData->y1=getFloatOptionNamed (option, nOption, "y1", 0);
	windowData->y2=getFloatOptionNamed (option, nOption, "y2", 0);
	windowData->y3=getFloatOptionNamed (option, nOption, "y3", 0);
	
	windowData->z0=getFloatOptionNamed (option, nOption, "z0", 0);
	windowData->z1=getFloatOptionNamed (option, nOption, "z1", 0);
	windowData->z2=getFloatOptionNamed (option, nOption, "z2", 0);
	windowData->z3=getFloatOptionNamed (option, nOption, "z3", 0);	
	
	
	Window xid=getIntOptionNamed (option, nOption, "win", 0);
		if(xid==0) 
			{
		           compLogMessage (NULL, "cubedbus", CompLogLevelWarn, "xid==0");
			}
	    windowData->w = findWindowAtDisplay( obj->s->display,
    								xid);
	return TRUE;
}

static bool
cubedbusDeleteWindowObject (CubedbusObject *obj)
{
		free(obj->data);
		free(obj);		
	return TRUE;
}

static bool
cubedbusModifyWindowObject (CubedbusObject *obj, CompOption *option, int nOption)
{
	return TRUE;
}

static bool
cubedbusDrawWindowObject (CubedbusObject *obj)
{
	
	CubedbusWindowObject *data=obj->data;
	
			if(data->order) glTranslatef (data->translate[0], data->translate[1], data->translate[2]);
		glRotatef ( data->rotate[0], data->rotate[1], data->rotate[2], data->rotate[3]);
			if(!(data->order)) glTranslatef (data->translate[0], data->translate[1], data->translate[2]); 
		
		glScalef( data->scale[0],data->scale[1], data->scale[2]); /* Rotate, translate and scale  */

    		/*glEnable (data->w->texture->target);*/
    		
    		enableTexture (obj->s, data->w->texture, 
    			COMP_TEXTURE_FILTER_GOOD); 

					/* draw texture */
				glBegin(GL_QUADS); 

					glTexCoord2f (0, 0);
    		 	 	glVertex3f( data->x0,data->y0,data->z0 );	// Top Left Of The Texture and Quad          
		  
					glTexCoord2f ((data->w->width), 0);  
    				glVertex3f( data->x1,data->y1,data->z1);	// Top Right Of The Texture and Quad    
						
					glTexCoord2f (	(data->w->width), (data->w->height));  
    				glVertex3f( data->x2,data->y2,data->z2);	// Bot Right Of The Texture and Quad    
										
					glTexCoord2f ( 0, (data->w->height)); 
    				glVertex3f( data->x3,data->y3,data->z3);

				glEnd();			
					
    		disableTexture (obj->s, data->w->texture);
    		
    	data->rotate[0]+=data->rotateSpeed;
    	if(data->rotate[0]>360) data->rotate[0]=0;
    	if(data->rotate[0]<0) data->rotate[0]=360;					
	return TRUE;
}