summaryrefslogtreecommitdiff
path: root/cubedbus.c
diff options
context:
space:
mode:
authorJoel Bosveld <joel@JOEL-UBUNTU.(none)>2007-11-21 22:04:45 +0900
committerJoel Bosveld <joel@JOEL-UBUNTU.(none)>2007-11-21 22:04:45 +0900
commit95982b91c7c8f8bd0d0368ce762458d58478976e (patch)
tree605b79f38083d0642922f5af98d21de15dba30cc /cubedbus.c
parentf25a503b0d79ec09a922915d51a3817b20f37a1f (diff)
downloadcubedbus-95982b91c7c8f8bd0d0368ce762458d58478976e.tar.gz
cubedbus-95982b91c7c8f8bd0d0368ce762458d58478976e.tar.bz2
Lots of changes. Added a new object heirachy system. Added checks for
when we get screen. Deleting doesn't work, and will crash if you try.
Diffstat (limited to 'cubedbus.c')
-rw-r--r--cubedbus.c327
1 files changed, 154 insertions, 173 deletions
diff --git a/cubedbus.c b/cubedbus.c
index 9384c20..af58084 100644
--- a/cubedbus.c
+++ b/cubedbus.c
@@ -68,6 +68,11 @@ CubedbusScreen;
CubedbusScreen *gs = GET_CUBEDBUS_SCREEN(s, GET_CUBEDBUS_DISPLAY(s->display)) /* Macros to get the gs pointer to CubedbusScreen struct */
#include "cubedbusTexture.c.in"
+#include "cubedbusColour.c.in"
+#include "cubedbusObject.c.in"
+
+#include "cubedbusStd.c.in"
+
static Bool
cubedbusAddObject (CompDisplay *d,
@@ -81,85 +86,55 @@ cubedbusAddObject (CompDisplay *d,
Window xid;
xid = getIntOptionNamed (option, nOption, "root", 0);
s = findScreenAtDisplay (d, xid);
+ if(!s) return FALSE;
CUBEDBUS_SCREEN(s);
-
- CubedbusObject *objptr;
- objptr=gs->head;
+ CubedbusObject *head=gs->head;
+ CubedbusObject *objptr=gs->head;
+
+ CubedbusName *cubedbusName = malloc (sizeof(CubedbusName));
+ int i;
+
- if (gs->head == NULL)
- {
- gs->head = malloc (sizeof(CubedbusObject));
- if(gs->head == NULL)
- {
- compLogMessage (NULL, "cubedbus", CompLogLevelError, "Out of memory. Could not add object");
- return FALSE;
- }
- objptr=gs->head;
- objptr->prev = NULL;
- }
- else
+
+ cubedbusGetName( getStringOptionNamed(option,nOption,"name",""), cubedbusName );
+
+ /* sets the head pointer correctly */
+
+ for(i=0;i<cubedbusName->n -1;i++) /* stop 1 before the object to be created */
{
while(1)
{
- if(objptr->next == NULL )
+ if(objptr == NULL) return FALSE;
+
+ if(!strcmp(objptr->name,cubedbusName->string[i]))
{
- objptr->next = malloc (sizeof(CubedbusObject));
- if(objptr->next == NULL)
- {
- compLogMessage (NULL, "cubedbus", CompLogLevelError, "Out of memory. Could not add object");
- return FALSE;
- }
- objptr->next->prev=objptr;
- objptr=objptr->next; /* objptr now points to newly created object */
-
- break;
+ head=objptr;
+ CubedbusObj *data=objptr->data;
+ objptr=data->firstChild;
+
+ break;
}
else objptr=objptr->next;
}
}
- /* have now created CubedbusObject */
+ char name[16];
- objptr->next=NULL;
- objptr->type=getIntOptionNamed (option,nOption, "type", 0);
- if(objptr->type == 0) return FALSE;
- objptr->s=s;
-
- char *tempName=getStringOptionNamed (option,nOption,"name", "");
- if(strcmp(tempName,"") == 0 || strlen(tempName) >= 16)
+ if( (strcmp(cubedbusName->string[i],"") == 0) || ( strlen(cubedbusName->string[i]) >= 16))
{
compLogMessage (NULL,"cubedbus",CompLogLevelError, "error with name");
return FALSE;
}
+
+ strcpy(name,cubedbusName->string[i]);
+
+ free(cubedbusName->string);
+ free(cubedbusName);
+
- strcpy(objptr->name,tempName);
-
- switch (objptr->type)
- {
- case CUBEDBUS_COLOUR_OBJECT:
- {
-
- objptr->func =&cubedbusDrawColourObject; /* function called when drawing */
- objptr->delfunc=&cubedbusDeleteColourObject; /* function called when deleting */
- objptr->modfunc=&cubedbusModifyColourObject; /* function called when modifying */
- objptr->addfunc=&cubedbusAddColourObject; /* function called when adding */
-
- return (objptr->addfunc) (objptr, option, nOption);
- }
- case CUBEDBUS_TEXTURE_OBJECT:
- {
-
- objptr->func =&cubedbusDrawTextureObject; /* function called when drawing */
- objptr->delfunc=&cubedbusDeleteTextureObject; /* function called when deleting */
- objptr->modfunc=&cubedbusModifyTextureObject; /* function called when modifying */
- objptr->addfunc=&cubedbusAddTextureObject; /* function called when adding */
- return (objptr->addfunc) (objptr, option, nOption);
- }
- }
-
- return FALSE;
+ return cubedbusAddStdObject (option, nOption, head, s, name);
}
static Bool
@@ -169,49 +144,57 @@ cubedbusDeleteObject (CompDisplay *d,
CompOption *option,
int nOption)
{
+ //get gs pointer
CompScreen *s;
Window xid;
xid = getIntOptionNamed (option, nOption, "root", 0);
s = findScreenAtDisplay (d, xid);
+ if(!s) return FALSE;
CUBEDBUS_SCREEN(s);
-
- CubedbusObject *objptr;
- objptr=gs->head;
- char name[16];
+ compLogMessage(NULL, "cubedbus", CompLogLevelDebug, "started teh delete function");
- char *tempName=getStringOptionNamed (option,nOption,"name", "");
-
- if(strlen(tempName) >= 16) /* should be array length */
- {
- compLogMessage (NULL,"cubedbus",CompLogLevelError, "name is too long");
- return FALSE;
- }
- strcpy(name,tempName);
+ CubedbusObject **head=&gs->head;
+ CubedbusObject *objptr=gs->head;
-
- if (objptr == NULL)
- {
- return FALSE;
- }
- else
+ CubedbusName *cubedbusName = malloc (sizeof(CubedbusName));
+ int i;
+
+ if(!cubedbusGetName( getStringOptionNamed(option,nOption,"name",""), cubedbusName )) return FALSE;
+
+ /* sets the head pointer correctly */
+
+ for(i=0;i<cubedbusName->n -1 ;i++) /* stop 1 before the object to be created */
{
while(1)
{
- if(!strcmp(objptr->name,name))
+ if(objptr == NULL) return FALSE;
+
+ if(!strcmp(objptr->name, cubedbusName->string[i]))
{
-
- if(objptr->prev != NULL) objptr->prev->next=objptr->next;
- else gs->head=objptr->next;
-
- if(objptr->next != NULL) objptr->next->prev=objptr->prev;
-
- return (objptr->delfunc) (objptr); /* call the delete function */
-
+ head=&objptr;
+ CubedbusObj *data=objptr->data;
+ objptr=data->firstChild;
+ break;
}
- objptr=objptr->next;
- if(objptr==NULL)return FALSE;
+ else objptr=objptr->next;
+ }
+ }
+
+ while(1)
+ {
+ if(objptr==NULL) return false;
+ if(!strcmp(objptr->name,cubedbusName->string[i]))
+ {
+ if(!(objptr->prev == NULL)) objptr->prev->next=objptr->next;
+ else *head=(objptr->next);
+
+ if(!(objptr->next == NULL)) objptr->next->prev=objptr->prev;
+
+ compLogMessage(NULL, "cubedbus", CompLogLevelDebug, "calling delfunc");
+ return (objptr->delfunc) (objptr);
}
+ objptr=objptr->next;
}
}
@@ -226,6 +209,7 @@ cubedbusModifyObject (CompDisplay *d,
Window xid;
xid = getIntOptionNamed (option, nOption, "root", 0);
s = findScreenAtDisplay (d, xid);
+ if(!s) return FALSE;
CUBEDBUS_SCREEN(s);
CubedbusObject *objptr;
@@ -249,80 +233,7 @@ cubedbusModifyObject (CompDisplay *d,
}
}
-
-/* Drawing functions */
-static bool
-cubedbusDrawColourObject (CubedbusObject *obj)
-{
- glShadeModel (GL_SMOOTH);
-
- CubedbusColourObject *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 */
-
-
-
- glCallList(data->dList);
-
-
-
-
- return TRUE;
-}
-
-/* Delete Functions */
-static bool
-cubedbusDeleteColourObject (CubedbusObject *obj)
-{
- CubedbusColourObject *data=obj->data;
- glDeleteLists (data->dList, 1);
- free(obj->data);
- free(obj);
- return TRUE;
-}
-
-/* Modify Functions */
-
-static bool
-cubedbusModifyColourObject (CubedbusObject *obj, CompOption *option, int nOption)
-{
- return TRUE;
-}
-
-/* Add Functions */
-
-static bool
-cubedbusAddColourObject (CubedbusObject *obj, CompOption *option, int nOption)
-{
- obj->data= malloc( sizeof(CubedbusColourObject) );
- if(obj->data == NULL) return FALSE;
-
- CubedbusColourObject *colourData=obj->data;
-
- colourData->rotate[0]=getFloatOptionNamed (option,nOption, "rotateAngle", 0.0);
- colourData->rotate[1]=getFloatOptionNamed (option,nOption, "rotateX", 0.0);
- colourData->rotate[2]=getFloatOptionNamed (option,nOption, "rotateY", 0.0);
- colourData->rotate[3]=getFloatOptionNamed (option,nOption, "rotateZ", 0.0);
- colourData->translate[0]=getFloatOptionNamed (option,nOption, "translateX", 0.0);
- colourData->translate[1]=getFloatOptionNamed (option,nOption, "translateY", 0.0);
- colourData->translate[2]=getFloatOptionNamed (option,nOption, "translateZ", 0.0);
- colourData->scale[0]=getFloatOptionNamed (option,nOption, "scaleX", 1.0);
- colourData->scale[1]=getFloatOptionNamed (option,nOption, "scaleY", 1.0);
- colourData->scale[2]=getFloatOptionNamed (option,nOption, "scaleZ", 1.0);
- colourData->order=getBoolOptionNamed (option, nOption, "order", TRUE);
-
-
- /* Code to make dList */
-
- cubedbusGenerateDList(option, nOption, &colourData->dList);
-
- return TRUE;
-}
static bool
cubedbusGenerateDList(CompOption *option, int nOption, GLuint *dList)
@@ -335,7 +246,7 @@ cubedbusGenerateDList(CompOption *option, int nOption, GLuint *dList)
float x,y,z;
char string[5];
- glBegin(GL_TRIANGLES); /************** CHANGE TO TRIANGLES AND MOVE INTO STANDARD FUNCTION **************/
+ glBegin(GL_TRIANGLES);
int max=getIntOptionNamed(option, nOption, "numberOfPoints", 0);
for(i=0;i<max;i++)
@@ -366,6 +277,39 @@ cubedbusGenerateDList(CompOption *option, int nOption, GLuint *dList)
return TRUE;
}
+/* Get name */
+static bool
+cubedbusGetName(char *name, CubedbusName *storage)
+{
+ int i;
+ char **temp;
+
+ storage->string=malloc (sizeof(char*)*3); /* 3 is the number of expected layers - root -> object -> colour */
+ storage->string[0]=strsep(&name,".");
+
+
+ for(i=1;;i++)
+ {
+ if(i>2)
+ {
+ temp=realloc(storage->string, sizeof(char*)*(i+1));
+ if (temp==NULL)
+ {
+ free(storage->string);
+ return FALSE;
+ }
+ storage->string=temp;
+ }
+ storage->string[i] = strsep(&name,".");
+
+ if(storage->string[i]==NULL)
+ {
+ storage->n=i;
+ return TRUE;
+ }
+ }
+}
+
/* Standard plugin 'stuff' */
static void
@@ -426,19 +370,21 @@ cubedbusPaintInside (CompScreen *s,
CubedbusObject *obj=gs->head;
glScalef(0.5,0.5,0.5);
- while(true)
- {
- if(obj == NULL) break; /* pull out of loop if finished drawing all objects */
+
+
+ if(obj == NULL) compLogMessage(NULL,"cubedbus", CompLogLevelWarn, "no root object to draw"); /* pull out of loop if finished drawing all objects */
- glPushMatrix();
+ else
+ {
+ glPushMatrix();
- if(!( (obj->func) (obj) )) compLogMessage(NULL, "cubedbus", CompLogLevelWarn, "error calling function") ; /* Call function */
+ if(!( (obj->func) (obj) )) compLogMessage(NULL, "cubedbus", CompLogLevelWarn, "error calling function") ; /* Call function */
- glPopMatrix();
-
- obj = obj->next;
- }
+ glPopMatrix();
+ glColor4usv (defaultColor);
+ }
+
/**********************************************/
glPopMatrix();
@@ -560,7 +506,42 @@ cubedbusInitScreen (CompPlugin *p,
s->base.privates[gd->screenPrivateIndex].ptr = gs; /* For the CUBEDBUS_SCREEN macro to work */
- gs->head= NULL;
+ /**/
+ gs->head= malloc (sizeof(CubedbusObject));
+ if(gs->head == NULL) return FALSE;
+ gs->head->next=NULL;
+ gs->head->prev=NULL;
+ gs->head->type=CUBEDBUS_OBJECT;
+
+ strcpy(gs->head->name,"root");
+
+ gs->head->s=s;
+ gs->head->func =&cubedbusDrawObj; /* function called when drawing */
+ gs->head->delfunc=&cubedbusDeleteObj; /* function called when deleting */
+ gs->head->modfunc=&cubedbusModifyObj; /* function called when modifying */
+ gs->head->addfunc=&cubedbusAddObj; /* function called when adding */
+
+
+
+ gs->head->data = malloc( sizeof(CubedbusObj) );
+ if(gs->head->data == NULL) return FALSE;
+
+ CubedbusObj *data=gs->head->data;
+
+ data->rotate[0]=0;
+ data->rotate[1]=0;
+ data->rotate[2]=0;
+ data->rotate[3]=0;
+ data->translate[0]=0;
+ data->translate[1]=0;
+ data->translate[2]=0;
+ data->scale[0]=1;
+ data->scale[1]=1;
+ data->scale[2]=1;
+ data->order=TRUE;
+ data->rotateSpeed=0;
+ data->firstChild=NULL;
+ /**/
WRAP (gs, s, donePaintScreen, cubedbusDonePaintScreen); /*Functions version of ... is called instead of cores (which then also calls core function) */