#include <stdio.h>
#ifndef _LINKEDLIST_H_
#define _LINKEDLIST_H_
#ifndef _POLYGONSTRUCT_H_
#define _POLYGONSTRUCT_H_
#include <GL/gl.h>
#define MAXVERTS 32
typedef struct poly_struct {
int type; /* E.g., 0=SQUARE, 1=POLY, 2=RECT, ... */
GLint numVerts; /* # of vertices in polygon */
GLdouble v[MAXVERTS][2]; /* Polygon's vertex array: */
/* v[i][0] = vertex i's x-coord; */
/* v[i][1] = vertex i's y-coord */
GLdouble center[2]; /* Polygon's "center" point, for use in */
/* rotating polygon */
GLdouble rot_angle; /* Rotation angle for polygon (degrees) */
GLdouble rgb[3]; /* Polygon's color: 0.0=off, 1.0=max; */
/* rgb[0]=red, [1]=green, [2]=blue */
} Polygon;
#endif
typedef struct polygon_list_struct {
Polygon p;
struct polygon_list_struct *next, /* Pointers to next, prev polygons */
*prev; /* in the doubly-linked list */
} Polygon_list_node;
#endif
/*
* Global pointers for the linked list:
*/
Polygon_list_node *head = NULL, /* Pointer to the head of the list */
*curr = NULL, /* Pointer to the currently selected node */
*tail = NULL; /* Pointer to the tail of the list */
void InsertAfter(Polygon_list_node *item, Polygon_list_node *afterMe) {
/*
* Inserts *item after *afterMe in the linked list:
*/
if (afterMe == NULL) {
if (head == NULL && tail == NULL) { /* empty list */
head = tail = item;
item->prev = item->next = NULL;
}
else
fprintf(stderr
,"InsertAfter: cannot insert after a NULL ptrn"); return;
}
item->prev = afterMe;
if (afterMe == tail) {
tail = item;
item->next = NULL;
}
else {
item->next = afterMe->next;
item->next->prev = item;
}
afterMe->next = item;
}
void InsertBefore(Polygon_list_node *item, Polygon_list_node *beforeMe) {
/*
* Inserts *item before *beforeMe in the linked list:
*/
if (beforeMe == NULL) {
if (head == NULL && tail == NULL) { /* empty list */
head = tail = item;
item->prev = item->next = NULL;
}
else
fprintf(stderr
,"InsertBefore: cannot insert before a NULL ptrn"); return;
}
item->next = beforeMe;
if (beforeMe == head) {
head = item;
item->prev = NULL;
}
else {
item->prev = beforeMe->prev;
item->prev->next = item;
}
beforeMe->prev = item;
}
void RemoveItem(Polygon_list_node *item) {
/*
* Removes *item from the linked list (but doesn't free() it):
*/
if (item == NULL) /* Should print out an error message */
return;
if (item == head && item == tail) { /* Only one element in the list */
head = tail = NULL;
}
else if (item == head) {
item->next->prev = NULL;
head = item->next;
}
else if (item == tail) {
item->prev->next = NULL;
tail = item->prev;
}
else {
item->prev->next = item->next;
item->next->prev = item->prev;
}
item->prev = item->next = NULL;
}