]> granicus.if.org Git - graphviz/commitdiff
*** empty log message ***
authorarif <devnull@localhost>
Tue, 26 Feb 2008 18:29:28 +0000 (18:29 +0000)
committerarif <devnull@localhost>
Tue, 26 Feb 2008 18:29:28 +0000 (18:29 +0000)
lib/glcomp/glcompset.c [new file with mode: 0644]
lib/glcomp/glcompset.h [new file with mode: 0644]
lib/glcomp/glcomptexture.c [new file with mode: 0644]
lib/glcomp/glcomptexture.h [new file with mode: 0644]
lib/glcomp/glutils.c [new file with mode: 0644]
lib/glcomp/glutils.h [new file with mode: 0644]

diff --git a/lib/glcomp/glcompset.c b/lib/glcomp/glcompset.c
new file mode 100644 (file)
index 0000000..6dc90db
--- /dev/null
@@ -0,0 +1,643 @@
+#include "glcompset.h"
+
+
+void glCompDrawBegin() //pushes a gl stack 
+{
+    int vPort[4];
+
+    glGetIntegerv (GL_VIEWPORT, vPort);
+
+       glMatrixMode (GL_PROJECTION);
+       glPushMatrix ();
+       glLoadIdentity ();
+
+  
+       glOrtho (0, vPort[2], 0, vPort[3], -1, 1);
+       glMatrixMode (GL_MODELVIEW);
+       glEnable (GL_BLEND); glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+//     glEnable( GL_TEXTURE_2D );
+
+       glPushMatrix ();
+       glLoadIdentity ();
+
+}
+
+void glCompDrawEnd()   //pops the gl stack 
+{      
+       glMatrixMode (GL_PROJECTION);
+       glPopMatrix ();
+       glMatrixMode (GL_MODELVIEW);
+       glPopMatrix ();
+}
+int glCompDrawPanel(glCompPanel* p)
+{
+       if(!p->visible)
+               return 0;
+       glColor4f(p->color.R,p->color.B,p->color.G,p->color.A);
+       glBegin(GL_POLYGON);
+               glVertex3f(p->pos.x,p->pos.y,p->bevel);
+               glVertex3f(p->pos.x+p->width,p->pos.y,p->bevel);
+               glVertex3f(p->pos.x+p->width,p->pos.y+p->height,p->bevel);
+               glVertex3f(p->pos.x,p->pos.y+p->height,p->bevel);
+               glVertex3f(p->pos.x,p->pos.y,p->bevel);
+       glEnd();
+       glBegin(GL_LINE_STRIP);
+               glColor4f(p->shadowcolor.R,p->shadowcolor.B,p->shadowcolor.G,p->color.A);
+               glVertex3f(p->pos.x,p->pos.y,p->bevel + GLCOMPSET_BEVEL_DIFF);
+               glVertex3f(p->pos.x+p->width,p->pos.y,p->bevel+GLCOMPSET_BEVEL_DIFF);
+               glVertex3f(p->pos.x+p->width,p->pos.y+p->height,p->bevel+GLCOMPSET_BEVEL_DIFF);
+               glVertex3f(p->pos.x,p->pos.y+p->height,p->bevel+GLCOMPSET_BEVEL_DIFF);
+               glVertex3f(p->pos.x,p->pos.y,p->bevel);
+       glEnd();
+       glLineWidth(p->shadowwidth);
+       glBegin(GL_LINE_STRIP);
+               glColor4f(p->shadowcolor.R,p->shadowcolor.B,p->shadowcolor.G,p->shadowcolor.A);
+               glVertex3f(p->pos.x+ p->shadowwidth/2.0,p->pos.y-p->shadowwidth/2.0,p->bevel);
+               glVertex3f(p->pos.x+ p->shadowwidth/2.0+p->width,p->pos.y-p->shadowwidth/2.0,p->bevel);
+               glVertex3f(p->pos.x+ p->shadowwidth/2.0+p->width,p->pos.y-p->shadowwidth/2.0+p->height,p->bevel);
+       glEnd();
+       glLineWidth(1);
+}
+
+glCompPanel* glCompPanelNew(GLfloat x,GLfloat y,GLfloat w,GLfloat h)
+{
+       glCompPanel* p;
+       p=malloc(sizeof(glCompPanel));
+       p->color.R=GLCOMPSET_PANEL_COLOR_R;
+       p->color.G=GLCOMPSET_PANEL_COLOR_G;
+       p->color.B=GLCOMPSET_PANEL_COLOR_B;
+       p->color.A=GLCOMPSET_PANEL_COLOR_ALPHA;
+       p->shadowcolor.R=GLCOMPSET_PANEL_SHADOW_COLOR_R;
+       p->shadowcolor.G=GLCOMPSET_PANEL_SHADOW_COLOR_G;
+       p->shadowcolor.B=GLCOMPSET_PANEL_SHADOW_COLOR_B;
+       p->shadowcolor.A=GLCOMPSET_PANEL_SHADOW_COLOR_A;
+       p->shadowwidth=GLCOMPSET_PANEL_SHADOW_WIDTH;
+       p->bevel=GLCOMPSET_PANEL_BEVEL;
+       p->pos.x=x;
+       p->pos.y=y;
+       p->width=w;
+       p->height=h;
+       return p;
+}
+int glCompSetAddPanel(glCompSet* s,glCompPanel* p)
+{
+       s->panelcount++;
+       s->panels=realloc(s->panels,sizeof(glCompPanel*)*s->panelcount);
+       s->panels[s->panelcount-1]=p;
+       p->parentset=s;
+       return 1;
+}
+int glCompSetAddLabel(glCompSet* s,glCompLabel* p)
+{
+       s->labelcount++;
+       s->labels=realloc(s->labels,sizeof(glCompLabel*)*s->labelcount);
+       s->labels[s->labelcount-1]=p;
+       return 1;
+}
+
+int glCompSetRemovePanel(glCompSet* s,glCompPanel* p)
+{
+       int ind=0;
+       int found=0;
+       for (ind ; ind < s->panelcount-1; ind ++)
+       {
+               if ((s->panels[ind] == p) && found==0)
+                       found=1;
+               if (found==1)
+                       s->panels[ind]=s->panels[ind+1];
+       }
+       if (found)
+       {
+               free(p);
+               s->panelcount--;
+               s->panels=realloc(s->panels,sizeof(glCompPanel*)*s->panelcount);
+               return 1;
+       }
+       return 0;
+}
+int glCompSetRemoveLabel(glCompSet* s,glCompLabel* p)
+{
+       int ind=0;
+       int found=0;
+       for (ind ; ind < s->labelcount-1; ind ++)
+       {
+               if ((s->labels[ind] == p) && found==0)
+                       found=1;
+               if (found==1)
+                       s->labels[ind]=s->labels[ind+1];
+       }
+       if (found)
+       {
+               free (p->text);
+               free (p);
+               s->labelcount--;
+               s->labels=realloc(s->labels,sizeof(glCompLabel*)*s->labelcount);
+               return 1;
+       }
+       return 0;
+}
+int glCompDrawLabel(glCompLabel* p)
+{
+       if(p->visible)
+       {
+               if (p->panel)
+               {
+                       p->pos.x=p->pos.x+p->panel->pos.x;
+                       p->pos.y=p->pos.y+p->panel->pos.y;
+               }
+
+               fontSize (p->size);
+               fontColorA (p->color.R,p->color.B,p->color.G,p->color.A);
+
+               fontDrawString  ( p->pos.x,p->pos.y,p->text,p->size*p->fontsizefactor*strlen(p->text));
+               if (p->panel)
+               {
+                       p->pos.x=p->pos.x-p->panel->pos.x;
+                       p->pos.y=p->pos.y-p->panel->pos.y;
+               }
+               return 1;
+       }
+       return 0;
+}
+int glCompLabelSetText(glCompLabel* p,char* text)
+{
+       free(p->text);
+       p->text=strdup(text);
+       return 1;
+}
+
+
+int glCompSetDraw(glCompSet* s)
+{
+       glCompDrawBegin();
+       glCompSetDrawPanels(s);
+       glCompDrawEnd();
+
+}
+int glCompSetDrawPanels(glCompSet* s)
+{
+       int ind=0;
+       for (ind ; ind < s->panelcount; ind ++)
+       {
+               glCompDrawPanel(s->panels[ind]);
+       }
+       for (ind=0 ; ind < s->buttoncount; ind ++)
+       {
+               glCompDrawButton(s->buttons[ind]);
+       }
+       for (ind=0 ; ind < s->labelcount; ind ++)
+       {
+               glCompDrawLabel(s->labels[ind]);
+       }
+}
+int glCompSetHide(glCompSet* s)
+{
+       int ind=0;
+       for (ind ; ind < s->panelcount; ind ++)
+       {
+               s->panels[ind]->visible=0;
+       }
+       for (ind=0 ; ind < s->buttoncount; ind ++)
+       {
+               s->buttons[ind]->visible=0;
+       }
+       for (ind=0 ; ind < s->labelcount; ind ++)
+       {
+               s->labels[ind]->visible=0;
+       }
+}
+int glCompSetShow(glCompSet* s)
+{
+       int ind=0;
+       for (ind ; ind < s->panelcount; ind ++)
+       {
+               s->panels[ind]->visible=1;
+       }
+       for (ind=0 ; ind < s->buttoncount; ind ++)
+       {
+               s->buttons[ind]->visible=1;
+       }
+       for (ind=0 ; ind < s->labelcount; ind ++)
+       {
+               s->labels[ind]->visible=1;
+       }
+}
+
+
+
+glCompButton* glCompButtonNew(GLfloat x,GLfloat y,GLfloat w,GLfloat h,char* caption,char* glyphfile,int glyphwidth,int glyphheight)
+{
+       glCompButton* p;
+       p=malloc(sizeof(glCompButton));
+       p->color.R=GLCOMPSET_BUTTON_COLOR_R;
+       p->color.G=GLCOMPSET_BUTTON_COLOR_G;
+       p->color.B=GLCOMPSET_BUTTON_COLOR_B;
+       p->color.A=GLCOMPSET_BUTTON_COLOR_ALPHA;
+       p->bevel=GLCOMPSET_PANEL_BEVEL+GLCOMPSET_BEVEL_DIFF;
+       p->thickness=GLCOMPSET_BUTTON_THICKNESS;
+       p->caption=strdup(caption);
+       p->pos.x=x;
+       p->pos.y=y;
+       p->width=w;
+       p->height=h;
+       p->enabled=1;
+       p->visible=1;
+       p->status=0;    //0 not pressed 1 pressed;
+       p->groupid=-1;
+       p->fontsize=GLCOMPSET_FONT_SIZE;
+       p->fontcolor.R=GLCOMPSET_BUTTON_FONT_COLOR_R;
+       p->fontcolor.G=GLCOMPSET_BUTTON_FONT_COLOR_G;
+       p->fontcolor.B=GLCOMPSET_BUTTON_FONT_COLOR_B;
+       p->fontcolor.A=GLCOMPSET_BUTTON_FONT_COLOR_ALPHA;
+       //load glyph
+       if(glyphfile)
+       {
+
+               p->glyph=glCompCreateTextureFromRaw(glyphfile,glyphwidth,glyphheight,0);
+               p->glyphwidth=glyphwidth;
+               p->glyphheight=glyphheight;
+               p->hasglyph=1;
+
+       }
+       else
+       {
+               p->glyphwidth=0;
+               p->glyphheight=0;
+               p->hasglyph=0;
+       }
+       p->callbackfunc='\0';
+       p->panel='\0';
+       p->customptr='\0';
+       return p;
+}
+int glCompSetAddButton(glCompSet* s,glCompButton* p)
+{
+       s->buttoncount++;
+       s->buttons=realloc(s->buttons,sizeof(glCompButton*)*s->buttoncount);
+       s->buttons[s->buttoncount-1]=p;
+       p->parentset=s;
+
+       return 1;
+}
+int glCompSetRemoveButton(glCompSet* s,glCompButton* p)
+{
+       int ind=0;
+       int found=0;
+       for (ind ; ind < s->buttoncount-1; ind ++)
+       {
+               if ((s->buttons[ind] == p) && found==0)
+                       found=1;
+               if (found==1)
+                       s->buttons[ind]=s->buttons[ind+1];
+       }
+       if (found)
+       {
+               free(p->caption);
+               free(p);
+               s->buttoncount--;
+               s->buttons=realloc(s->buttons,sizeof(glCompButton*)*s->buttoncount);
+
+               return 1;
+       }
+       return 0;
+}
+int glCompDrawButton(glCompButton* p)
+{
+       float color_fac;
+       float thickness=p->thickness;
+       float fontx,fonty;
+       if(!p->visible) 
+               return 0;
+       if (p->panel)
+       {
+               p->pos.x=p->panel->pos.x+p->pos.x;
+               p->pos.y=p->panel->pos.y+p->pos.y;
+       }
+       if (p->status==1)
+       {
+               color_fac=GLCOMPSET_BUTTON_BEVEL_BRIGHTNESS;
+               glColor4f(p->color.R/1.2,p->color.G/1.2,p->color.B/1.2,p->color.A);
+               p->thickness=p->thickness/1.2;
+
+       }
+
+       else
+       {
+               color_fac=1/GLCOMPSET_BUTTON_BEVEL_BRIGHTNESS;
+               glColor4f(p->color.R,p->color.G,p->color.B,p->color.A);
+               p->thickness=p->thickness*1.2;
+       }
+       if (!p->hasglyph)
+       {
+               glBegin(GL_POLYGON);
+               glVertex3f(p->pos.x+p->thickness,p->pos.y+p->thickness,p->bevel);
+               glVertex3f(p->pos.x+p->width-p->thickness,p->pos.y+p->thickness,p->bevel);
+               glVertex3f(p->pos.x+p->width-p->thickness,p->pos.y+p->height-p->thickness,p->bevel);
+               glVertex3f(p->pos.x+p->thickness,p->pos.y+p->height-p->thickness,p->bevel);
+               glVertex3f(p->pos.x+p->thickness,p->pos.y+p->thickness,p->bevel);
+               glEnd();
+               //buttom thickness
+               glColor4f(p->color.R*color_fac,p->color.B*color_fac,p->color.G*color_fac,p->color.A);
+               glBegin(GL_POLYGON);
+               glVertex3f(p->pos.x+p->thickness,p->pos.y+p->thickness,p->bevel);
+               glVertex3f(p->pos.x+p->width-p->thickness,p->pos.y+p->thickness,p->bevel);
+               glVertex3f(p->pos.x+p->width,p->pos.y,p->bevel);
+               glVertex3f(p->pos.x,p->pos.y,p->bevel);
+               glVertex3f(p->pos.x+p->thickness,p->pos.y+p->thickness,p->bevel);
+               glEnd();
+               //left thickness
+               glBegin(GL_POLYGON);
+               glVertex3f(p->pos.x+p->width,p->pos.y+p->height,p->bevel);
+               glVertex3f(p->pos.x+p->width-p->thickness,p->pos.y+p->height-p->thickness,p->bevel);
+               glVertex3f(p->pos.x+p->width-p->thickness,p->pos.y+p->thickness,p->bevel);
+               glVertex3f(p->pos.x+p->width,p->pos.y,p->bevel);
+               glVertex3f(p->pos.x+p->width,p->pos.y+p->height,p->bevel);
+               glEnd();
+
+               glColor4f(p->color.R/color_fac,p->color.B/color_fac,p->color.G/color_fac,p->color.A);
+               glBegin(GL_POLYGON);
+               glVertex3f(p->pos.x+p->thickness,p->pos.y+p->thickness,p->bevel);
+               glVertex3f(p->pos.x+p->thickness,p->pos.y+p->height-p->thickness,p->bevel);
+               glVertex3f(p->pos.x,p->pos.y+p->height,p->bevel);
+               glVertex3f(p->pos.x,p->pos.y,p->bevel);
+               glVertex3f(p->pos.x+p->thickness,p->pos.y+p->thickness,p->bevel);
+               glEnd();
+               //left thickness
+               glBegin(GL_POLYGON);
+               glVertex3f(p->pos.x+p->thickness,p->pos.y+p->height-p->thickness,p->bevel);
+               glVertex3f(p->pos.x,p->pos.y+p->height,p->bevel);
+               glVertex3f(p->pos.x+p->width,p->pos.y+p->height,p->bevel);
+               glVertex3f(p->pos.x+p->width-p->thickness,p->pos.y+p->height-p->thickness,p->bevel);
+               glVertex3f(p->pos.x+p->thickness,p->pos.y+p->height-p->thickness,p->bevel);
+               glEnd();
+               //draw caption
+               fontx=(p->width-p->thickness*2-p->fontsize*strlen(p->caption)*GLCOMPSET_FONT_SIZE_FACTOR)/2.0+p->pos.x+p->thickness;
+               fonty=(p->height-p->thickness*2-p->fontsize)/2.0+p->pos.y+p->thickness;
+               fontSize (p->fontsize);
+//             fontColorA (p->fontcolor.R,p->fontcolor.B,p->fontcolor.G,p->fontcolor.A);
+               fontColorA (0,0,0,1);
+               fontDrawString (fontx,fonty,p->caption,p->fontsize*strlen(p->caption)*GLCOMPSET_FONT_SIZE_FACTOR);
+       }
+       //put glyph
+       else
+       {
+
+               glEnable( GL_TEXTURE_2D );
+               fontx=(p->width-p->thickness*2-p->glyphwidth)/2.0+p->pos.x+p->thickness;
+               fonty=(p->height-p->thickness*2-p->glyphheight)/2.0+p->pos.y+p->thickness;
+               glBindTexture( GL_TEXTURE_2D, p->glyph->id);
+               glColor4f(1,1,1,1);
+               glBegin(GL_QUADS);
+               glTexCoord2d(0.0f, 1.0f); glVertex3d(fontx,fonty,p->bevel+GLCOMPSET_BEVEL_DIFF);
+               glTexCoord2d(1.0f, 1.0f); glVertex3d(fontx+p->glyph->w,fonty,p->bevel+GLCOMPSET_BEVEL_DIFF);
+               glTexCoord2d(1.0f, 0.0f); glVertex3d(fontx+p->glyph->w,fonty+p->glyph->h,p->bevel+GLCOMPSET_BEVEL_DIFF);
+               glTexCoord2d(0.0f, 0.0f); glVertex3d(fontx,fonty+p->glyph->h,p->bevel+GLCOMPSET_BEVEL_DIFF);
+//             glTexCoord2d(fontx,fonty); glVertex3d(fontx,fonty,p->bevel+GLCOMPSET_BEVEL_DIFF);
+
+               glEnd();
+               glDisable( GL_TEXTURE_2D );
+               if(p->status==1)
+               {
+                       glColor4f(p->color.R*color_fac,p->color.B*color_fac,p->color.G*color_fac,p->color.A/2);
+                       glBegin(GL_POLYGON);
+                       glVertex3d(fontx-p->thickness,fonty-p->thickness,p->bevel+GLCOMPSET_BEVEL_DIFF*2);
+                       glVertex3d(fontx+p->glyph->w+p->thickness,fonty-p->thickness,p->bevel+GLCOMPSET_BEVEL_DIFF*2);
+                       glVertex3d(fontx+p->glyph->w+p->thickness,fonty+p->glyph->h+p->thickness,p->bevel+GLCOMPSET_BEVEL_DIFF*2);
+                       glVertex3d(fontx-p->thickness,fonty+p->glyph->h+p->thickness,p->bevel+GLCOMPSET_BEVEL_DIFF*2);
+                       glEnd();
+
+               }
+
+       }
+       p->thickness=thickness;
+       if (p->panel)
+       {
+               p->pos.x=p->pos.x-p->panel->pos.x;
+               p->pos.y=p->pos.y-p->panel->pos.y;
+       }
+
+
+
+}
+int glCompSetClick(glCompSet* s,int x,int y)
+{
+
+       if(s)
+       {
+               int ind=0;
+               float X,Y,Z;
+
+               glCompDrawBegin();
+               glCompSetGetPos(x,y,&X,&Y,&Z);
+               glCompDrawEnd();
+
+
+               s->clickedX=X;
+               s->clickedY=Y;
+
+               for (ind=0 ; ind < s->buttoncount; ind ++)
+               {
+                       if((s->buttons[ind]->visible) && (s->buttons[ind]->enabled))
+                       {
+                               if(glCompPointInButton(s->buttons[ind],X,Y))
+                               {
+                                       if(s->buttons[ind]->groupid > -1)
+                                               s->buttons[ind]->status=1;
+                               }
+                       }
+               }
+               return 1;
+       }
+       else
+               return 0;
+}
+
+int glCompSetRelease(glCompSet* s,int x,int y)
+{
+       
+       int ind=0;
+       printf("in release\n");
+       for (ind=0 ; ind < s->buttoncount; ind ++)
+       {
+               if((s->buttons[ind]->visible) && (s->buttons[ind]->enabled))
+               {
+                       if((glCompPointInButton(s->buttons[ind],s->clickedX,s->clickedY)))
+                       {
+                               glCompButtonClick(s->buttons[ind]);
+                       }
+               }
+       }
+       return 1;
+}
+
+
+
+
+
+int glCompPointInButton(glCompButton* p,float x,float y)
+{
+       float button_x,button_y;
+       if (p->panel)
+       {
+               button_x=p->pos.x+p->panel->pos.x;
+               button_y=p->pos.y+p->panel->pos.y;
+       }
+
+       if (
+               (x >= button_x) &&
+               (x <= button_x+p->width) &&
+               (y >= button_y) &&
+               (y <= button_y+p->height))
+                       return 1;
+       else return 0;
+
+}
+
+//converts screen location to opengl coordinates
+void glCompSetGetPos(int x, int y,float* X,float* Y,float* Z)
+{
+
+       GLdouble wwinX;
+       GLdouble wwinY;
+       GLdouble wwinZ;
+       GLdouble posX, posY, posZ;
+
+
+       int ind;
+       GLdouble depth[5];
+       GLdouble raster[5];
+       GLint viewport[4];
+       GLdouble modelview[16];
+       GLdouble projection[16];
+       GLfloat winX, winY;
+       GLfloat winZ[36];
+       char buffer [200];
+       float kts=1;
+       glGetDoublev( GL_MODELVIEW_MATRIX, modelview );
+       glGetDoublev( GL_PROJECTION_MATRIX, projection );
+       glGetIntegerv( GL_VIEWPORT, viewport );
+
+       //draw a point  to a not important location to get window coordinates
+       glBegin(GL_POINTS);
+               glVertex3f(10.00,10.00,0.00);
+       glEnd();
+    gluProject(10.0,10.0,0.00,modelview,projection,viewport,&wwinX,&wwinY,&wwinZ );
+       winX = (float)x;
+       winY = (float)viewport[3] - (float)y;
+       gluUnProject( winX, winY, wwinZ, modelview, projection, viewport, &posX, &posY, &posZ);
+
+       *X=posX;
+       *Y=posY;
+       *Z=posZ;
+}
+
+
+void glCompButtonClick(glCompButton* p)
+{
+       int ind;
+       if (p->groupid > 0)
+       {
+               for (ind=0 ; ind < ((glCompSet*)p->parentset)->buttoncount;ind ++)
+               {
+                       if(     ((glCompSet*)p->parentset)->buttons[ind]->groupid == p->groupid)
+                               ((glCompSet*)p->parentset)->buttons[ind]->status=0;
+               }
+               p->status=1;
+       }
+       else
+       {
+               if (p->groupid==-1)
+               {
+                       if (p->status==0)
+                               p->status=1;
+                       else
+                               p->status=0;
+               }       
+               else
+                       p->status=0;
+       }
+       if(p->callbackfunc)
+               p->callbackfunc(p);
+
+
+}
+
+glCompLabel* glCompLabelNew(GLfloat x,GLfloat y,GLfloat size,char* text)
+{
+       glCompLabel* p;
+       p=malloc(sizeof(glCompLabel));
+       p->color.R=GLCOMPSET_LABEL_COLOR_R;
+       p->color.G=GLCOMPSET_LABEL_COLOR_G;
+       p->color.B=GLCOMPSET_LABEL_COLOR_B;
+       p->color.A=GLCOMPSET_LABEL_COLOR_ALPHA;
+       p->bevel=GLCOMPSET_PANEL_BEVEL+GLCOMPSET_BEVEL_DIFF;
+       p->text=strdup(text);
+       p->pos.x=x;
+       p->pos.y=y;
+       p->size=size;
+       p->visible=1;
+       p->fontsizefactor=GLCOMPSET_FONT_SIZE_FACTOR;
+       p->panel='\0';
+       return p;
+}
+
+int glCompPanelHide(glCompPanel* p)
+{
+               int ind=0;
+               for (ind=0 ; ind < ((glCompSet*)p->parentset)->buttoncount;ind ++)
+               {
+                       if(     ((glCompSet*)p->parentset)->buttons[ind]->panel==p)
+                               ((glCompSet*)p->parentset)->buttons[ind]->visible=0;
+               }
+
+               for (ind=0 ; ind < ((glCompSet*)p->parentset)->labelcount;ind ++)
+               {
+                       if(     ((glCompSet*)p->parentset)->labels[ind]->panel==p)
+                               ((glCompSet*)p->parentset)->labels[ind]->visible=0;
+               }
+               p->visible=0;
+
+}
+
+int glCompPanelShow(glCompPanel* p)
+{
+               int ind=0;
+               for (ind=0 ; ind < ((glCompSet*)p->parentset)->buttoncount;ind ++)
+               {
+                       if(     ((glCompSet*)p->parentset)->buttons[ind]->panel==p)
+                               ((glCompSet*)p->parentset)->buttons[ind]->visible=1;
+               }
+
+               for (ind=0 ; ind < ((glCompSet*)p->parentset)->labelcount;ind ++)
+               {
+                       if(     ((glCompSet*)p->parentset)->labels[ind]->panel==p)
+                               ((glCompSet*)p->parentset)->labels[ind]->visible=1;
+               }
+               p->visible=1;
+
+}
+
+void glCompSetClear(glCompSet* s)
+{
+       int ind=0;
+       for (ind =0 ; ind < s->buttoncount;ind ++)
+       {
+               free(s->buttons[ind]->caption);
+               free(s->buttons[ind]);
+       }
+       free (s->buttons);
+       for (ind =0 ; ind < s->labelcount;ind ++)
+       {
+               free(s->labels[ind]->text);
+               free(s->labels[ind]);
+       }
+       free (s->labels);
+       for (ind =0 ; ind < s->panelcount;ind ++)
+       {
+               free(s->panels[ind]);
+       }
+       free (s->panels);
+       free(s);
+}
+
+
diff --git a/lib/glcomp/glcompset.h b/lib/glcomp/glcompset.h
new file mode 100644 (file)
index 0000000..4859ff5
--- /dev/null
@@ -0,0 +1,157 @@
+/*Open GL basic component set
+  includes glPanel,glCompButton,glCompCustomButton,clCompLabel,glCompStyle
+*/
+#ifndef GLCOMPSET_H
+#define GLCOMPSET_H
+
+#include "glTexFont.h"
+#include "glTexFontTGA.h"
+#include "glTexFontDefs.h"
+#include "glTexFontInclude.h"
+#include "gltemplate.h"
+#include "glcomptexture.h"
+
+#define        GLCOMPSET_PANEL_COLOR_R         0.16
+#define        GLCOMPSET_PANEL_COLOR_G         0.44
+#define        GLCOMPSET_PANEL_COLOR_B         0.87
+#define        GLCOMPSET_PANEL_COLOR_ALPHA     0.5
+#define        GLCOMPSET_PANEL_SHADOW_COLOR_R          0
+#define        GLCOMPSET_PANEL_SHADOW_COLOR_G          0
+#define        GLCOMPSET_PANEL_SHADOW_COLOR_B          0
+#define        GLCOMPSET_PANEL_SHADOW_COLOR_A          0.3
+#define GLCOMPSET_PANEL_SHADOW_WIDTH           4
+
+#define        GLCOMPSET_BUTTON_COLOR_R                0
+#define        GLCOMPSET_BUTTON_COLOR_G                1
+#define        GLCOMPSET_BUTTON_COLOR_B                0.3
+#define        GLCOMPSET_BUTTON_COLOR_ALPHA    0.6
+#define        GLCOMPSET_BUTTON_THICKNESS              3
+#define        GLCOMPSET_BUTTON_BEVEL_BRIGHTNESS               1.7
+#define GLCOMPSET_FONT_SIZE                            14
+#define        GLCOMPSET_BUTTON_FONT_COLOR_R           1
+#define        GLCOMPSET_BUTTON_FONT_COLOR_G           1
+#define        GLCOMPSET_BUTTON_FONT_COLOR_B           1
+#define        GLCOMPSET_BUTTON_FONT_COLOR_ALPHA       1
+#define GLCOMPSET_FONT_SIZE_FACTOR                     0.7
+#define        GLCOMPSET_LABEL_COLOR_R         0
+#define        GLCOMPSET_LABEL_COLOR_G         0
+#define        GLCOMPSET_LABEL_COLOR_B         0
+#define        GLCOMPSET_LABEL_COLOR_ALPHA     1
+
+#define GLCOMPSET_PANEL_BEVEL                          0.1
+#define        GLCOMPSET_BEVEL_DIFF                            0.001
+
+typedef void (*callbackfunc_t)(void* component);
+
+typedef struct _glCompPoint
+{
+       GLfloat x,y;
+}glCompPoint;
+typedef struct{
+       float R;
+       float G;
+       float B;
+       float A;        //Alpha
+} glCompColor;
+
+typedef struct _glCompPanel
+{
+       glCompPoint pos;
+       GLfloat width,height;
+       GLfloat shadowwidth;
+       GLfloat bevel;
+       glCompColor color;
+       glCompColor shadowcolor;
+       int enabled;
+       int visible;
+       void* parentset;        //parent compset
+       int data;       
+
+
+}glCompPanel;
+typedef struct _glCompLabel
+{
+       glCompPoint pos;
+       GLfloat size;
+       GLfloat bevel;
+       glCompColor color;
+       int visible;
+       char* text;
+       GLfloat fontsizefactor;
+       glCompPanel* panel;     //container panel
+}glCompLabel;
+
+
+typedef struct _glCompButton{
+       glCompPoint pos;
+       GLfloat width,height;
+       GLfloat bevel;
+       GLfloat thickness;
+       glCompColor color;
+       glCompColor fontcolor;
+       char* caption;
+       int enabled;
+       int visible;
+       int status;     //0 not pressed 1 pressed;
+       int groupid;
+       void* parentset;        //parent compset
+       GLfloat fontsize;
+       int hasglyph;
+       glCompTexture*  glyph;
+       int glyphwidth,glyphheight;
+       glCompPanel* panel;     //container panel
+       callbackfunc_t callbackfunc; //call back for button click
+       void* customptr;        //general purpose void pointer to pass to call back
+       int data;
+}glCompButton;
+
+
+
+typedef struct
+{
+       glCompPanel** panels;
+       glCompButton** buttons;
+       glCompLabel** labels;
+
+       int panelcount;
+       int buttoncount;
+       int labelcount;
+       int active;     //0 dont draw, 1 draw
+       int enabled;    //0 disabled 1 enabled(allow mouse interaction)
+       GLfloat clickedX,clickedY;
+}glCompSet;
+
+glCompPanel* glCompPanelNew(GLfloat x,GLfloat y,GLfloat w,GLfloat h);
+void glCompSetClear(glCompSet* s);
+int glCompSetAddPanel(glCompSet* s,glCompPanel* p);
+int glCompSetRemovePanel(glCompSet* s,glCompPanel* p);
+int glCompSetDraw(glCompSet* s);
+
+glCompButton* glCompButtonNew(GLfloat x,GLfloat y,GLfloat w,GLfloat h,char* caption,char* glyphfile,int glyphwidth,int glyphheight);
+int glCompSetAddButton(glCompSet* s,glCompButton* p);
+int glCompSetRemoveButton(glCompSet* s,glCompButton* p);
+int glCompDrawButton(glCompButton* p);
+
+
+int glCompSetDraw(glCompSet* s);
+int glCompSetHide(glCompSet* s);
+int glCompSetShow(glCompSet* s);
+void glCompDrawBegin();        //pushes a gl stack 
+void glCompDrawEnd();  //pops the gl stack 
+int glCompDrawPanel(glCompPanel* p);
+int glCompSetClick(glCompSet* s,int x,int y);
+int glCompSetRelease(glCompSet* s);
+void glCompSetGetPos(int x, int y,float* X,float* Y,float* Z);
+int glCompPointInButton(glCompButton* p,float x,float y);
+void glCompButtonClick(glCompButton* p);
+
+glCompLabel* glCompLabelNew(GLfloat x,GLfloat y,GLfloat size,char* text);
+int glCompSetAddLabel(glCompSet* s,glCompLabel* p);
+int glCompSetRemoveLabel(glCompSet* s,glCompLabel* p);
+int glCompDrawLabel(glCompLabel* p);
+int glCompLabelSetText(glCompLabel* p,char* text);
+int glCompPanelHide(glCompPanel* p);
+int glCompPanelShow(glCompPanel* p);
+
+
+#endif
\ No newline at end of file
diff --git a/lib/glcomp/glcomptexture.c b/lib/glcomp/glcomptexture.c
new file mode 100644 (file)
index 0000000..2e58c27
--- /dev/null
@@ -0,0 +1,60 @@
+#include "glcomptexture.h"
+
+glCompTexture* glCompCreateTextureFromRaw(char* filename,int width,int height,int wrap)
+{
+       glCompTexture* t;       
+       BYTE * data;
+       FILE * file;
+       t=malloc(sizeof(glCompTexture));
+       glGenTextures( 1, &t->id );
+
+       // allocate buffer
+       data = malloc( width * height * 3 );
+       // open and read texture data
+       file = fopen( filename, "rb" );
+       fread( data, width * height * 3, 1, file );
+       fclose( file );
+
+
+// select our current texture
+       glBindTexture( GL_TEXTURE_2D, t->id);
+
+    // select modulate to mix texture with color for shading
+    glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
+
+    // when texture area is small, bilinear filter the closest mipmap
+    glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
+                     GL_LINEAR_MIPMAP_NEAREST );
+    // when texture area is large, bilinear filter the first mipmap
+    glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
+
+    // if wrap is true, the texture wraps over at the edges (repeat)
+    //       ... false, the texture ends at the edges (clamp)
+    glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,
+                     wrap ? GL_REPEAT : GL_CLAMP );
+    glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,
+                     wrap ? GL_REPEAT : GL_CLAMP );
+
+/*     glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,GL_REPEAT );
+       glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
+       glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+       glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
+       glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
+
+       
+       // build our texture mipmaps
+       glTexImage2D(GL_TEXTURE_2D, 0, 4, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE,data);*/
+
+    gluBuild2DMipmaps( GL_TEXTURE_2D, GL_RGB, width, height,
+                       GL_RGB, GL_UNSIGNED_BYTE, data );
+
+    // free buffer
+    free( data );
+       t->w=width;
+       t->h=height;
+       return t;
+}
+int glCompDeleteTexture(glCompTexture* t)
+{
+       return 0;
+}
\ No newline at end of file
diff --git a/lib/glcomp/glcomptexture.h b/lib/glcomp/glcomptexture.h
new file mode 100644 (file)
index 0000000..46adbce
--- /dev/null
@@ -0,0 +1,14 @@
+/*Open GL texture handling and storing mechanism
+  includes glPanel,glCompButton,glCompCustomButton,clCompLabel,glCompStyle
+*/
+#ifndef GLCOMPTEXTURE_H
+#define GLCOMPTEXTURE_H
+#include "gltemplate.h"
+typedef struct{
+       int id;
+       GLfloat w,h;
+} glCompTexture;
+
+glCompTexture* glCompCreateTextureFromRaw(char* filename,int width,int height,int wrap);
+int glCompDeleteTexture(glCompTexture* t);
+#endif
\ No newline at end of file
diff --git a/lib/glcomp/glutils.c b/lib/glcomp/glutils.c
new file mode 100644 (file)
index 0000000..738425e
--- /dev/null
@@ -0,0 +1,126 @@
+#include "glutils.h"
+
+
+
+/* at given depth value, tranforms 2d Window location to 3d gl coords*/
+int GetFixedOGLPos(int x, int y,float kts,GLfloat* X,GLfloat* Y, GLfloat* Z)
+{
+       GLdouble wwinX;
+       GLdouble wwinY;
+       GLdouble wwinZ;
+
+       GLint viewport[4];
+       GLdouble modelview[16];
+       GLdouble projection[16];
+       GLfloat winX, winY;
+       GLdouble posX, posY, posZ;
+
+       glBegin(GL_POINTS);
+               glVertex3f(10.00,10.00,0.00);
+       glEnd();
+
+       glGetDoublev( GL_MODELVIEW_MATRIX, modelview );
+       glGetDoublev( GL_PROJECTION_MATRIX, projection );
+       glGetIntegerv( GL_VIEWPORT, viewport );
+
+       gluProject(10.0,10.0,0.00,modelview,projection,viewport,&wwinX,&wwinY,&wwinZ );
+
+       winX = (float)x;
+       winY = (float)viewport[3] - (float)y;
+       gluUnProject( winX, winY, wwinZ, modelview, projection, viewport, &posX, &posY, &posZ);
+       *X=(GLfloat)posX;
+       *Y=(GLfloat)posY;
+       *Z=(GLfloat)posZ;
+
+       return 1;
+
+}
+
+/*transforms 2d windows location to 3d gl coords but depth is calculated unlike the previous function*/
+int GetOGLPosRef(int x, int y,float* X,float* Y,float* Z)
+{
+
+       GLdouble wwinX;
+       GLdouble wwinY;
+       GLdouble wwinZ;
+       GLdouble posX, posY, posZ;
+
+
+       int ind;
+       GLdouble depth[5];
+       GLdouble raster[5];
+       GLint viewport[4];
+       GLdouble modelview[16];
+       GLdouble projection[16];
+       GLfloat winX, winY;
+       GLfloat winZ[36];
+       char buffer [200];
+       float kts=1;
+       //glTranslatef (0.0,0.0,0.0);
+       glGetDoublev( GL_MODELVIEW_MATRIX, modelview );
+       glGetDoublev( GL_PROJECTION_MATRIX, projection );
+       glGetIntegerv( GL_VIEWPORT, viewport );
+
+       //draw a point  to a not important location to get window coordinates
+       glBegin(GL_POINTS);
+               glVertex3f(10.00,10.00,0.00);
+       glEnd();
+    gluProject(10.0,10.0,0.00,modelview,projection,viewport,&wwinX,&wwinY,&wwinZ );
+       winX = (float)x;
+       winY = (float)viewport[3] - (float)y;
+       gluUnProject( winX, winY, wwinZ, modelview, projection, viewport, &posX, &posY, &posZ);
+
+       *X=posX;
+       *Y=posY;
+       *Z=posZ;
+       return 1;
+
+}
+
+
+float GetOGLDistance(int l)
+{
+
+       int x,y;
+       float*  X,Y, Z;
+       GLdouble wwinX;
+       GLdouble wwinY;
+       GLdouble wwinZ;
+       GLdouble posX, posY, posZ;
+       GLdouble posXX, posYY, posZZ;
+
+
+       int ind;
+       GLdouble depth[5];
+       GLdouble raster[5];
+       GLint viewport[4];
+       GLdouble modelview[16];
+       GLdouble projection[16];
+       GLfloat winX, winY;
+       GLfloat winZ[36];
+       char buffer [200];
+       float kts=1;
+       //glTranslatef (0.0,0.0,0.0);
+       glGetDoublev( GL_MODELVIEW_MATRIX, modelview );
+       glGetDoublev( GL_PROJECTION_MATRIX, projection );
+       glGetIntegerv( GL_VIEWPORT, viewport );
+
+       //draw a point  to a not important location to get window coordinates
+       glBegin(GL_POINTS);
+               glVertex3f(10.00,10.00,0.00);
+       glEnd();
+    gluProject(10.0,10.0,0.00,modelview,projection,viewport,&wwinX,&wwinY,&wwinZ );
+       x=50;
+       y=50;
+       winX = (float)x;
+       winY = (float)viewport[3] - (float)y;
+       gluUnProject( winX, winY, wwinZ, modelview, projection, viewport, &posX, &posY, &posZ);
+       x=x+l;
+       y=50;
+       winX = (float)x;
+       winY = (float)viewport[3] - (float)y;
+       gluUnProject( winX, winY, wwinZ, modelview, projection, viewport, &posXX, &posYY, &posZZ);
+       printf ("return value:%f\n:",((float)posXX-(float)posX));
+       return ((float)(posXX-posX));
+
+}
diff --git a/lib/glcomp/glutils.h b/lib/glcomp/glutils.h
new file mode 100644 (file)
index 0000000..7d4b61b
--- /dev/null
@@ -0,0 +1,13 @@
+#ifndef GLUTILS_H
+#define GLUTILS_H
+#include "windows.h"
+#include <GL/gl.h>
+#include <GL/glu.h>                                                    
+
+
+int GetFixedOGLPos(int x, int y,float kts,GLfloat* X,GLfloat* Y, GLfloat* Z);
+int GetOGLPosRef(int x, int y,float* X,float* Y,float* Z);
+float GetOGLDistance(int l);
+
+#endif
+