From c9355e4f2dbe4f4d468e834bb1a07057952ada61 Mon Sep 17 00:00:00 2001 From: erg Date: Thu, 17 Sep 2009 20:26:38 +0000 Subject: [PATCH] Fix warnings; re-indent --- lib/glcomp/glCompTrackBar.c | 29 +- lib/glcomp/glcompbutton.c | 341 ++++++++++++++---------- lib/glcomp/glcomplabel.c | 74 +++--- lib/glcomp/glcomppanel.c | 79 +++--- lib/glcomp/glcompset.c | 157 +++++------ lib/glcomp/glcomptext.c | 515 ++++++++++++++++++------------------ lib/glcomp/glcomptextpng.c | 212 ++++++++------- lib/glcomp/glpangofont.c | 196 +++++++------- lib/glcomp/glutils.c | 304 +++++++++++---------- 9 files changed, 1009 insertions(+), 898 deletions(-) diff --git a/lib/glcomp/glCompTrackBar.c b/lib/glcomp/glCompTrackBar.c index 4591e2fbd..c7a2875f2 100644 --- a/lib/glcomp/glCompTrackBar.c +++ b/lib/glcomp/glCompTrackBar.c @@ -1,3 +1,5 @@ +/* vim:set shiftwidth=4 ts=8: */ + /********************************************************** * This software is part of the graphviz package * * http://www.graphviz.org/ * @@ -15,12 +17,13 @@ -glCompTrackBar* glCompTrackBarNew(GLfloat x, GLfloat y, GLfloat w, GLfloat h,glCompOrientation orientation) +glCompTrackBar *glCompTrackBarNew(GLfloat x, GLfloat y, GLfloat w, + GLfloat h, glCompOrientation orientation) { - glCompTrackBar* p; - p=malloc(sizeof(glCompTrackBar)); - /*default color values for a panel*/ - p->color.R = GLCOMPSET_PANEL_COLOR_R; + glCompTrackBar *p; + p = malloc(sizeof(glCompTrackBar)); + /*default color values for a panel */ + 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; @@ -29,13 +32,13 @@ glCompTrackBar* glCompTrackBarNew(GLfloat x, GLfloat y, GLfloat w, GLfloat h,glC p->shadowcolor.B = GLCOMPSET_PANEL_SHADOW_COLOR_B; p->shadowcolor.A = GLCOMPSET_PANEL_SHADOW_COLOR_A; p->bevel = GLCOMPSET_PANEL_BEVEL; - p->outerpanel->pos.x=x; - p->outerpanel->pos.y=y; - p->outerpanel->width=w; - p->outerpanel->height=h; - p->indicator->width=p->outerpanel->width-2*GLCOMPSET_DEFAULT_PAD; - p->indicator->shadowwidth=0; + p->outerpanel->pos.x = x; + p->outerpanel->pos.y = y; + p->outerpanel->width = w; + p->outerpanel->height = h; + p->indicator->width = p->outerpanel->width - 2 * GLCOMPSET_DEFAULT_PAD; + p->indicator->shadowwidth = 0; - p->font=font_init(); - return NULL; + p->font = font_init(); + return NULL; } diff --git a/lib/glcomp/glcompbutton.c b/lib/glcomp/glcompbutton.c index 4490cefb3..15f75ef0a 100644 --- a/lib/glcomp/glcompbutton.c +++ b/lib/glcomp/glcompbutton.c @@ -1,3 +1,6 @@ + +/* vim:set shiftwidth=4 ts=8: */ + /********************************************************** * This software is part of the graphviz package * * http://www.graphviz.org/ * @@ -21,7 +24,8 @@ glCompButton *glCompButtonNew(GLfloat x, GLfloat y, GLfloat w, GLfloat h, char *caption, char *glyphfile, - int glyphwidth, int glyphheight,glCompOrientation orientation) + int glyphwidth, int glyphheight, + glCompOrientation orientation) { glCompButton *p; p = malloc(sizeof(glCompButton)); @@ -60,11 +64,11 @@ glCompButton *glCompButtonNew(GLfloat x, GLfloat y, GLfloat w, GLfloat h, p->glyphheight = 0; p->hasglyph = 0; } - p->orientation=orientation; - p->callbackfunc = '\0'; + p->orientation = orientation; + p->callbackfunc = '\0'; p->panel = '\0'; p->customptr = '\0'; - p->font=(glCompText*)0; + p->font = (glCompText *) 0; return p; } @@ -76,171 +80,224 @@ int glCompSetAddButton(glCompSet * s, glCompButton * p) realloc(s->buttons, sizeof(glCompButton *) * s->buttoncount); s->buttons[s->buttoncount - 1] = p; p->parentset = s; - p->font=s->fontset->fonts[s->fontset->activefont]; - return 1; + p->font = s->fontset->fonts[s->fontset->activefont]; + return 1; } int glCompSetRemoveButton(glCompSet * s, glCompButton * p) { int ind = 0; int found = 0; - for (; ind < s->buttoncount ; ind++) - { - if ((s->buttons[ind] == p) && found == 0) - found = 1; - if ((found == 1) &&(ind <= (s->buttoncount-1))) - s->buttons[ind] = s->buttons[ind + 1]; + for (; ind < s->buttoncount; ind++) { + if ((s->buttons[ind] == p) && found == 0) + found = 1; + if ((found == 1) && (ind <= (s->buttoncount - 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); + if (found) { + free(p->caption); + free(p); + s->buttoncount--; + s->buttons = + realloc(s->buttons, sizeof(glCompButton *) * s->buttoncount); - return 1; + return 1; } return 0; } int glCompDrawButton(glCompButton * p) { - int kts,kts2; - GLfloat tempX,tempY; - GLfloat h,h2; /*container widget height*/ - float color_fac; + int kts, kts2; + GLfloat tempX, tempY; + GLfloat h, h2; /*container widget height */ + float color_fac; float thickness = p->thickness; float fontx, fonty; - GLfloat fontwidth; + GLfloat fontwidth; - if (p->orientation==1){ kts=1; h=0;}else{kts=-1; h=((glCompSet*)p->parentset)->h;} - if (p->panel->orientation==1){ kts2=1; h2=0;}else - { - kts2=-1; h2=((glCompSet*)p->panel->parentset)->h; - } - if ((!p->visible) || (!p->panel->visible)) - return 0; - if (p->panel) - { - tempX=p->pos.x; - tempY=p->pos.y; - p->pos.x = p->panel->pos.x + p->pos.x; - p->pos.y = p->panel->pos.y*kts2*kts+h2 + p->pos.y-h; - if (p->panel->orientation==0) - p->pos.y = p->pos.y - p->panel->height; + if (p->orientation == 1) { + kts = 1; + h = 0; + } else { + kts = -1; + h = ((glCompSet *) p->parentset)->h; + } + if (p->panel->orientation == 1) { + kts2 = 1; + h2 = 0; + } else { + kts2 = -1; + h2 = ((glCompSet *) p->panel->parentset)->h; + } + if ((!p->visible) || (!p->panel->visible)) + return 0; + if (p->panel) { + tempX = p->pos.x; + tempY = p->pos.y; + p->pos.x = p->panel->pos.x + p->pos.x; + p->pos.y = p->panel->pos.y * kts2 * kts + h2 + p->pos.y - h; + if (p->panel->orientation == 0) + p->pos.y = p->pos.y - p->panel->height; } - if (p->status == 1) - { - color_fac = GLCOMPSET_BUTTON_BEVEL_BRIGHTNESS; - glColor4f(p->color.R / (GLfloat) 1.2, p->color.G / (GLfloat) 1.2, p->color.B / (GLfloat) 1.2, p->color.A); - p->thickness = p->thickness / (GLfloat) 1.2; + if (p->status == 1) { + color_fac = GLCOMPSET_BUTTON_BEVEL_BRIGHTNESS; + glColor4f(p->color.R / (GLfloat) 1.2, p->color.G / (GLfloat) 1.2, + p->color.B / (GLfloat) 1.2, p->color.A); + p->thickness = p->thickness / (GLfloat) 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 * (GLfloat) 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 * (GLfloat) 1.2; + } + if (!p->hasglyph) { + glBegin(GL_POLYGON); + glVertex3f(p->pos.x + p->thickness, + (p->pos.y * kts + h) + p->thickness, p->bevel); + glVertex3f(p->pos.x + p->width - p->thickness, + (p->pos.y * kts + h) + p->thickness, p->bevel); + glVertex3f(p->pos.x + p->width - p->thickness, + (p->pos.y * kts + h) + p->height * kts - p->thickness, + p->bevel); + glVertex3f(p->pos.x + p->thickness, + (p->pos.y * kts + h) + p->height * kts - p->thickness, + p->bevel); + glVertex3f(p->pos.x + p->thickness, + (p->pos.y * kts + h) + p->thickness, p->bevel); + glEnd(); + //buttom thickness + glColor4f(p->color.R * color_fac, p->color.G * color_fac, + p->color.B * color_fac, p->color.A); + glBegin(GL_POLYGON); + glVertex3f(p->pos.x + p->thickness, + (p->pos.y * kts + h) + p->thickness, p->bevel); + glVertex3f(p->pos.x + p->width - p->thickness, + (p->pos.y * kts + h) + p->thickness, p->bevel); + glVertex3f(p->pos.x + p->width, (p->pos.y * kts + h), p->bevel); + glVertex3f(p->pos.x, (p->pos.y * kts + h), p->bevel); + glVertex3f(p->pos.x + p->thickness, + (p->pos.y * kts + h) + p->thickness, p->bevel); + glEnd(); + //left thickness + glBegin(GL_POLYGON); + glVertex3f(p->pos.x + p->width, + (p->pos.y * kts + h) + p->height * kts, p->bevel); + glVertex3f(p->pos.x + p->width - p->thickness, + (p->pos.y * kts + h) + p->height * kts - p->thickness, + p->bevel); + glVertex3f(p->pos.x + p->width - p->thickness, + (p->pos.y * kts + h) + p->thickness, p->bevel); + glVertex3f(p->pos.x + p->width, (p->pos.y * kts + h), p->bevel); + glVertex3f(p->pos.x + p->width, + (p->pos.y * kts + h) + p->height * kts, p->bevel); + glEnd(); + glColor4f(p->color.R / color_fac, p->color.G / color_fac, + p->color.B / color_fac, p->color.A); + glBegin(GL_POLYGON); + glVertex3f(p->pos.x + p->thickness, + (p->pos.y * kts + h) + p->thickness, p->bevel); + glVertex3f(p->pos.x + p->thickness, + (p->pos.y * kts + h) + p->height * kts - p->thickness, + p->bevel); + glVertex3f(p->pos.x, (p->pos.y * kts + h) + p->height * kts, + p->bevel); + glVertex3f(p->pos.x, (p->pos.y * kts + h), p->bevel); + glVertex3f(p->pos.x + p->thickness, + (p->pos.y * kts + h) + p->thickness, p->bevel); + glEnd(); + //left thickness + glBegin(GL_POLYGON); + glVertex3f(p->pos.x + p->thickness, + (p->pos.y * kts + h) + p->height * kts - p->thickness, + p->bevel); + glVertex3f(p->pos.x, (p->pos.y * kts + h) + p->height * kts, + p->bevel); + glVertex3f(p->pos.x + p->width, + (p->pos.y * kts + h) + p->height * kts, p->bevel); + glVertex3f(p->pos.x + p->width - p->thickness, + (p->pos.y * kts + h) + p->height * kts - p->thickness, + p->bevel); + glVertex3f(p->pos.x + p->thickness, + (p->pos.y * kts + h) + p->height * kts - p->thickness, + p->bevel); + glEnd(); + //draw caption + fontColor(p->font, p->fontcolor.R, p->fontcolor.G, p->fontcolor.B, + p->fontcolor.A); + /*get the string length */ + fontwidth = + (GLfloat) glutBitmapLength(GLUT_BITMAP_HELVETICA_12, + (unsigned char *) p->caption); + fontx = + (p->width - p->thickness * (GLfloat) 2 - + fontwidth) / (GLfloat) 2.0 + p->pos.x + p->thickness; + fonty = + (p->height * kts - p->thickness * (GLfloat) 2 - + p->fontsize) / (GLfloat) 2.0 + (p->pos.y * kts + h) + + p->thickness; + glprintf(p->font, fontx, fonty, p->bevel, fontwidth, p->caption); } - if (!p->hasglyph) - { - glBegin(GL_POLYGON); - glVertex3f(p->pos.x + p->thickness, (p->pos.y*kts+h) + p->thickness, p->bevel); - glVertex3f(p->pos.x + p->width - p->thickness,(p->pos.y*kts+h) + p->thickness, p->bevel); - glVertex3f(p->pos.x + p->width - p->thickness,(p->pos.y*kts+h) + p->height*kts - p->thickness, p->bevel); - glVertex3f(p->pos.x + p->thickness,(p->pos.y*kts+h) + p->height*kts - p->thickness, p->bevel); - glVertex3f(p->pos.x + p->thickness, (p->pos.y*kts+h) + p->thickness,p->bevel); - glEnd(); - //buttom thickness - glColor4f(p->color.R * color_fac, p->color.G * color_fac,p->color.B * color_fac, p->color.A); - glBegin(GL_POLYGON); - glVertex3f(p->pos.x + p->thickness, (p->pos.y*kts+h) + p->thickness,p->bevel); - glVertex3f(p->pos.x + p->width - p->thickness,(p->pos.y*kts+h) + p->thickness, p->bevel); - glVertex3f(p->pos.x + p->width, (p->pos.y*kts+h), p->bevel); - glVertex3f(p->pos.x, (p->pos.y*kts+h), p->bevel); - glVertex3f(p->pos.x + p->thickness, (p->pos.y*kts+h) + p->thickness,p->bevel); - glEnd(); - //left thickness - glBegin(GL_POLYGON); - glVertex3f(p->pos.x + p->width, (p->pos.y*kts+h) + p->height*kts, p->bevel); - glVertex3f(p->pos.x + p->width - p->thickness,(p->pos.y*kts+h) + p->height*kts - p->thickness, p->bevel); - glVertex3f(p->pos.x + p->width - p->thickness,(p->pos.y*kts+h) + p->thickness, p->bevel); - glVertex3f(p->pos.x + p->width, (p->pos.y*kts+h), p->bevel); - glVertex3f(p->pos.x + p->width, (p->pos.y*kts+h) + p->height*kts, p->bevel); - glEnd(); - glColor4f(p->color.R / color_fac, p->color.G / color_fac, p->color.B / color_fac, p->color.A); - glBegin(GL_POLYGON); - glVertex3f(p->pos.x + p->thickness, (p->pos.y*kts+h) + p->thickness,p->bevel); - glVertex3f(p->pos.x + p->thickness,(p->pos.y*kts+h) + p->height*kts - p->thickness, p->bevel); - glVertex3f(p->pos.x, (p->pos.y*kts+h) + p->height*kts, p->bevel); - glVertex3f(p->pos.x, (p->pos.y*kts+h), p->bevel); - glVertex3f(p->pos.x + p->thickness, (p->pos.y*kts+h) + p->thickness,p->bevel); - glEnd(); - //left thickness - glBegin(GL_POLYGON); - glVertex3f(p->pos.x + p->thickness, - (p->pos.y*kts+h) + p->height*kts - p->thickness, p->bevel); - glVertex3f(p->pos.x, (p->pos.y*kts+h) + p->height*kts, p->bevel); - glVertex3f(p->pos.x + p->width, (p->pos.y*kts+h) + p->height*kts, p->bevel); - glVertex3f(p->pos.x + p->width - p->thickness,(p->pos.y*kts+h) + p->height*kts - p->thickness, p->bevel); - glVertex3f(p->pos.x + p->thickness, - (p->pos.y*kts+h) + p->height*kts - p->thickness, p->bevel); - glEnd(); - //draw caption - fontColor(p->font,p->fontcolor.R, p->fontcolor.G, p->fontcolor.B, p->fontcolor.A); - /*get the string length*/ - fontwidth=(GLfloat)glutBitmapLength(GLUT_BITMAP_HELVETICA_12,(unsigned char*)p->caption); - fontx =(p->width - p->thickness * (GLfloat) 2 - fontwidth )/ (GLfloat) 2.0 + p->pos.x + p->thickness; - fonty =(p->height*kts - p->thickness * (GLfloat) 2 -p->fontsize) / (GLfloat) 2.0 + (p->pos.y*kts+h) + p->thickness; - glprintf(p->font, fontx,fonty, p->bevel,fontwidth,p->caption); - } //put glyph - else - { - glEnable(GL_TEXTURE_2D); - fontx =(p->width - p->thickness * (GLfloat) 2 - p->glyphwidth) / (GLfloat) 2.0 + p->pos.x + p->thickness; - fonty =(p->height*kts - p->thickness * (GLfloat) 2 - p->glyphheight) / (GLfloat) 2.0 + (p->pos.y*kts+h) + 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.G * color_fac,p->color.B * 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(); + else { + glEnable(GL_TEXTURE_2D); + fontx = + (p->width - p->thickness * (GLfloat) 2 - + p->glyphwidth) / (GLfloat) 2.0 + p->pos.x + p->thickness; + fonty = + (p->height * kts - p->thickness * (GLfloat) 2 - + p->glyphheight) / (GLfloat) 2.0 + (p->pos.y * kts + h) + + 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.G * color_fac, + p->color.B * 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=tempX; - p->pos.y=tempY; + if (p->panel) { + p->pos.x = tempX; + p->pos.y = tempY; } - - return 1; + + return 1; } + void glCompButtonClick(glCompButton * p) { int ind; @@ -267,9 +324,7 @@ void glCompButtonClick(glCompButton * p) } -void glCompButtonSetText(glCompButton * p,char* str) +void glCompButtonSetText(glCompButton * p, char *str) { - replacestr(str,&p->caption); + replacestr(str, &p->caption); } - - diff --git a/lib/glcomp/glcomplabel.c b/lib/glcomp/glcomplabel.c index 9fa4e47dc..fac60f1f8 100644 --- a/lib/glcomp/glcomplabel.c +++ b/lib/glcomp/glcomplabel.c @@ -1,3 +1,5 @@ +/* vim:set shiftwidth=4 ts=8: */ + /********************************************************** * This software is part of the graphviz package * * http://www.graphviz.org/ * @@ -15,7 +17,8 @@ #include "glcomptext.h" -glCompLabel *glCompLabelNew(GLfloat x, GLfloat y, GLfloat size, char *text,glCompOrientation orientation) +glCompLabel *glCompLabelNew(GLfloat x, GLfloat y, GLfloat size, char *text, + glCompOrientation orientation) { glCompLabel *p; p = malloc(sizeof(glCompLabel)); @@ -40,7 +43,7 @@ int glCompSetAddLabel(glCompSet * s, glCompLabel * p) s->labelcount++; s->labels = realloc(s->labels, sizeof(glCompLabel *) * s->labelcount); s->labels[s->labelcount - 1] = p; - p->font=s->fontset->fonts[s->fontset->activefont]; + p->font = s->fontset->fonts[s->fontset->activefont]; p->parentset = s; return 1; } @@ -71,39 +74,50 @@ int glCompSetRemoveLabel(glCompSet * s, glCompLabel * p) int glCompDrawLabel(glCompLabel * p) { - int kts,kts2; - GLfloat tempX,tempY; - GLfloat h,h2; /*container widget height*/ - float color_fac; + int kts, kts2; + GLfloat tempX, tempY; + GLfloat h, h2; /*container widget height */ +#ifdef UNUSED + float color_fac; float fontx, fonty; - GLfloat fontwidth; + GLfloat fontwidth; +#endif - if (p->orientation==1){ kts=1; h=0;}else{kts=-1; h=((glCompSet*)p->parentset)->h;} - if (p->panel->orientation==1){ kts2=1; h2=0;}else - { - kts2=-1; h2=((glCompSet*)p->panel->parentset)->h; - } - if ((!p->visible) || (!p->panel->visible)) - return 0; - if (p->panel) - { - tempX=p->pos.x; - tempY=p->pos.y; - p->pos.x = p->panel->pos.x + p->pos.x; - p->pos.y = p->panel->pos.y*kts2*kts+h2 + p->pos.y-h; - if (p->panel->orientation==0) - p->pos.y = p->pos.y - p->panel->height; + if (p->orientation == 1) { + kts = 1; + h = 0; + } else { + kts = -1; + h = ((glCompSet *) p->parentset)->h; + } + if (p->panel->orientation == 1) { + kts2 = 1; + h2 = 0; + } else { + kts2 = -1; + h2 = ((glCompSet *) p->panel->parentset)->h; } - printf ("kts:%d h:%f kts2:%d h2:%d \n", kts , h , kts2, h2); + if ((!p->visible) || (!p->panel->visible)) + return 0; + if (p->panel) { + tempX = p->pos.x; + tempY = p->pos.y; + p->pos.x = p->panel->pos.x + p->pos.x; + p->pos.y = p->panel->pos.y * kts2 * kts + h2 + p->pos.y - h; + if (p->panel->orientation == 0) + p->pos.y = p->pos.y - p->panel->height; + } + printf("kts:%d h:%f kts2:%d h2:%f \n", kts, h, kts2, h2); - p->font->fontheight=p->size; - fontColor(p->font,p->color.R, p->color.G, p->color.B, p->color.A); + p->font->fontheight = p->size; + fontColor(p->font, p->color.R, p->color.G, p->color.B, p->color.A); - glprintf(p->font, p->pos.x, p->pos.y,p->panel->bevel,(p->size * p->fontsizefactor *strlen(p->text)), p->text); - if (p->panel) { - p->pos.x = tempX; - p->pos.y = tempY; - return 1; + glprintf(p->font, p->pos.x, p->pos.y, p->panel->bevel, + (p->size * p->fontsizefactor * strlen(p->text)), p->text); + if (p->panel) { + p->pos.x = tempX; + p->pos.y = tempY; + return 1; } return 0; } diff --git a/lib/glcomp/glcomppanel.c b/lib/glcomp/glcomppanel.c index 79c51a9c3..f4be4e57b 100644 --- a/lib/glcomp/glcomppanel.c +++ b/lib/glcomp/glcomppanel.c @@ -1,3 +1,6 @@ +/* vim:set shiftwidth=4 ts=8: */ + + /********************************************************** * This software is part of the graphviz package * * http://www.graphviz.org/ * @@ -15,7 +18,8 @@ #include "glcomptext.h" -glCompPanel *glCompPanelNew(GLfloat x, GLfloat y, GLfloat w, GLfloat h,glCompOrientation orientation) +glCompPanel *glCompPanelNew(GLfloat x, GLfloat y, GLfloat w, GLfloat h, + glCompOrientation orientation) { glCompPanel *p; p = malloc(sizeof(glCompPanel)); @@ -33,64 +37,72 @@ glCompPanel *glCompPanelNew(GLfloat x, GLfloat y, GLfloat w, GLfloat h,glCompOri p->pos.y = y; p->width = w; p->height = h; - p->orientation=orientation; - p->text=(char*)0; + p->orientation = orientation; + p->text = (char *) 0; p->font = font_init(); return p; } -void glCompSetPanelText(glCompPanel * p,char* t) +void glCompSetPanelText(glCompPanel * p, char *t) { - p->text=realloc(p->text,strlen(t)+sizeof(char)); - strcpy(p->text,t); + p->text = realloc(p->text, strlen(t) + sizeof(char)); + strcpy(p->text, t); } int glCompDrawPanel(glCompPanel * p) { - int kts; - GLfloat h; /*container widget height*/ - if (p->orientation==1){ kts=1; h=0;}else{kts=-1; h=((glCompSet*)p->parentset)->h;} - if (!p->visible) + int kts; + GLfloat h; /*container widget height */ + if (p->orientation == 1) { + kts = 1; + h = 0; + } else { + kts = -1; + h = ((glCompSet *) p->parentset)->h; + } + if (!p->visible) return 0; glColor4f(p->color.R, p->color.G, p->color.B, p->color.A); glBegin(GL_POLYGON); - glVertex3f(p->pos.x, (p->pos.y*kts+h), p->bevel); - glVertex3f(p->pos.x + p->width, (p->pos.y*kts+h), p->bevel); - glVertex3f(p->pos.x + p->width, (p->pos.y*kts+h) + p->height*kts, p->bevel); - glVertex3f(p->pos.x, (p->pos.y*kts+h) + p->height*kts, p->bevel); - glVertex3f(p->pos.x, (p->pos.y*kts+h), p->bevel); + glVertex3f(p->pos.x, (p->pos.y * kts + h), p->bevel); + glVertex3f(p->pos.x + p->width, (p->pos.y * kts + h), p->bevel); + glVertex3f(p->pos.x + p->width, (p->pos.y * kts + h) + p->height * kts, + p->bevel); + glVertex3f(p->pos.x, (p->pos.y * kts + h) + p->height * kts, p->bevel); + glVertex3f(p->pos.x, (p->pos.y * kts + h), p->bevel); glEnd(); glBegin(GL_LINE_STRIP); glColor4f(p->shadowcolor.R, p->shadowcolor.G, p->shadowcolor.B, p->color.A); - glVertex3f(p->pos.x, (p->pos.y*kts+h), + glVertex3f(p->pos.x, (p->pos.y * kts + h), p->bevel + (GLfloat) GLCOMPSET_BEVEL_DIFF); - glVertex3f(p->pos.x + p->width, (p->pos.y*kts+h), + glVertex3f(p->pos.x + p->width, (p->pos.y * kts + h), p->bevel + (GLfloat) GLCOMPSET_BEVEL_DIFF); - glVertex3f(p->pos.x + p->width, (p->pos.y*kts+h) + p->height*kts, + glVertex3f(p->pos.x + p->width, (p->pos.y * kts + h) + p->height * kts, p->bevel + (GLfloat) GLCOMPSET_BEVEL_DIFF); - glVertex3f(p->pos.x, (p->pos.y*kts+h) + p->height*kts, + glVertex3f(p->pos.x, (p->pos.y * kts + h) + p->height * kts, p->bevel + (GLfloat) GLCOMPSET_BEVEL_DIFF); - glVertex3f(p->pos.x, (p->pos.y*kts+h), p->bevel); + glVertex3f(p->pos.x, (p->pos.y * kts + h), p->bevel); glEnd(); glLineWidth(p->shadowwidth); glBegin(GL_LINE_STRIP); glColor4f((GLfloat) p->shadowcolor.R, (GLfloat) p->shadowcolor.G, (GLfloat) p->shadowcolor.B, (GLfloat) p->shadowcolor.A); glVertex3f(p->pos.x + p->shadowwidth / ((GLfloat) 2.0), - (p->pos.y*kts+h) - p->shadowwidth / ((GLfloat) 2.0), p->bevel); - glVertex3f(p->pos.x + p->shadowwidth / (GLfloat) 2.0 + p->width, - (p->pos.y*kts+h) - p->shadowwidth / (GLfloat) 2.0, p->bevel); + (p->pos.y * kts + h) - p->shadowwidth / ((GLfloat) 2.0), + p->bevel); glVertex3f(p->pos.x + p->shadowwidth / (GLfloat) 2.0 + p->width, - (p->pos.y*kts+h) - p->shadowwidth / (GLfloat) 2.0 + p->height*kts, + (p->pos.y * kts + h) - p->shadowwidth / (GLfloat) 2.0, p->bevel); + glVertex3f(p->pos.x + p->shadowwidth / (GLfloat) 2.0 + p->width, + (p->pos.y * kts + h) - p->shadowwidth / (GLfloat) 2.0 + + p->height * kts, p->bevel); glEnd(); glLineWidth(1); - //draw text - if(p->text) - { + //draw text + if (p->text) { - } + } return 1; } @@ -100,7 +112,7 @@ int glCompSetAddPanel(glCompSet * s, glCompPanel * p) s->panels = realloc(s->panels, sizeof(glCompPanel *) * s->panelcount); s->panels[s->panelcount - 1] = p; p->parentset = s; - p->font=s->fontset->fonts[s->fontset->activefont]; + p->font = s->fontset->fonts[s->fontset->activefont]; return 1; } @@ -108,10 +120,10 @@ int glCompSetRemovePanel(glCompSet * s, glCompPanel * p) { int ind = 0; int found = 0; - for (; ind < s->panelcount; ind++) { + for (; ind < s->panelcount; ind++) { if ((s->panels[ind] == p) && found == 0) found = 1; - if ((found == 1)&&(ind <(s->panelcount-1))) + if ((found == 1) && (ind < (s->panelcount - 1))) s->panels[ind] = s->panels[ind + 1]; } if (found) { @@ -127,7 +139,7 @@ int glCompSetRemovePanel(glCompSet * s, glCompPanel * p) int glCompPanelHide(glCompPanel * p) { - int ind = 0; + /* int ind = 0; */ p->visible = 0; return 1; @@ -136,9 +148,8 @@ int glCompPanelHide(glCompPanel * p) int glCompPanelShow(glCompPanel * p) { - int ind = 0; + /* int ind = 0; */ p->visible = 1; return 1; } - diff --git a/lib/glcomp/glcompset.c b/lib/glcomp/glcompset.c index 7db688a6c..2c1565ecb 100644 --- a/lib/glcomp/glcompset.c +++ b/lib/glcomp/glcompset.c @@ -65,7 +65,7 @@ static void glCompSetGetPos(int x, int y, float *X, float *Y, float *Z) *Z = (float) posZ; } -void glCompDrawBegin(void) //pushes a gl stack +void glCompDrawBegin(void) //pushes a gl stack { int vPort[4]; @@ -87,7 +87,7 @@ void glCompDrawBegin(void) //pushes a gl stack } -void glCompDrawEnd(void) //pops the gl stack +void glCompDrawEnd(void) //pops the gl stack { glMatrixMode(GL_PROJECTION); glPopMatrix(); @@ -153,34 +153,43 @@ int glCompSetShow(glCompSet * s) } static int glCompPointInButton(glCompButton * p, float x, float y) { - int kts,kts2; - GLfloat tempX,tempY; - GLfloat h,h2; /*container widget height*/ - float color_fac; - float thickness = p->thickness; - float fontx, fonty; - GLfloat fontwidth; - float button_x, button_y; - - if (p->orientation==1){ kts=1; h=0;}else{kts=-1; h=((glCompSet*)p->parentset)->h;} - if (p->panel->orientation==1){ kts2=1; h2=0;}else - { - kts2=-1; h2=((glCompSet*)p->panel->parentset)->h; - } + int kts, kts2; + /* GLfloat tempX,tempY; */ + GLfloat h, h2; /*container widget height */ + /* float color_fac; */ + /* float thickness = p->thickness; */ + /* float fontx, fonty; */ + /* GLfloat fontwidth; */ + float button_x, button_y; + + if (p->orientation == 1) { + kts = 1; + h = 0; + } else { + kts = -1; + h = ((glCompSet *) p->parentset)->h; + } + if (p->panel->orientation == 1) { + kts2 = 1; + h2 = 0; + } else { + kts2 = -1; + h2 = ((glCompSet *) p->panel->parentset)->h; + } if (!p->visible) - return 0; - if (p->panel) - { - button_x = p->panel->pos.x + p->pos.x; - button_y = p->panel->pos.y*kts2*kts+h2 + p->pos.y-h; - if (p->panel->orientation==0) - button_y = button_y - p->panel->height; + return 0; + if (p->panel) { + button_x = p->panel->pos.x + p->pos.x; + button_y = p->panel->pos.y * kts2 * kts + h2 + p->pos.y - h; + if (p->panel->orientation == 0) + button_y = button_y - p->panel->height; } - if ((x >= button_x) && (x <= button_x + p->width) && (y >= button_y) && (y <= button_y + p->height)) - return 1; + if ((x >= button_x) && (x <= button_x + p->width) && (y >= button_y) + && (y <= button_y + p->height)) + return 1; else - return 0; + return 0; } @@ -188,32 +197,28 @@ static int glCompPointInButton(glCompButton * p, float x, float 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; - } - } + 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 1; + } else return 0; } @@ -227,7 +232,7 @@ int glCompSetRelease(glCompSet * s, int x, int y) if ((glCompPointInButton (s->buttons[ind], s->clickedX, s->clickedY))) { glCompButtonClick(s->buttons[ind]); - break; + break; } } } @@ -242,12 +247,11 @@ int glCompSetRelease(glCompSet * s, int x, int y) void glCompSetClear(glCompSet * s) { int ind = 0; - for (ind = 0; ind < s->buttoncount; ind++) - { - /*if (s->buttons[ind]->caption) - free(s->buttons[ind]->caption); - free(s->buttons[ind]);*/ - glCompSetRemoveButton(s, s->buttons[ind]); + for (ind = 0; ind < s->buttoncount; ind++) { + /*if (s->buttons[ind]->caption) + free(s->buttons[ind]->caption); + free(s->buttons[ind]); */ + glCompSetRemoveButton(s, s->buttons[ind]); } free(s->buttons); for (ind = 0; ind < s->labelcount; ind++) { @@ -262,12 +266,12 @@ void glCompSetClear(glCompSet * s) free(s); } -glCompSet* glCompSetNew( int w, int h) +glCompSet *glCompSetNew(int w, int h) { glCompSet *s = NEW(glCompSet); - s->w=(GLfloat)w; - s->h=(GLfloat)h; - s->groupCount=0; + s->w = (GLfloat) w; + s->h = (GLfloat) h; + s->groupCount = 0; return s; } @@ -281,38 +285,37 @@ int glCompSetDraw(glCompSet * s) void glcompsetUpdateBorder(glCompSet * s, int w, int h) { - if ( w > 0 && h > 0) - { - s->w=(GLfloat)w; - s->h=(GLfloat)h; - } + if (w > 0 && h > 0) { + s->w = (GLfloat) w; + s->h = (GLfloat) h; + } } -extern int glcompsetGetGroupId(glCompSet *s) +extern int glcompsetGetGroupId(glCompSet * s) { - return s->groupCount; + return s->groupCount; } -extern int glcompsetNextGroupId(glCompSet *s) +extern int glcompsetNextGroupId(glCompSet * s) { - int rv= s->groupCount; - s->groupCount++; - return rv; + int rv = s->groupCount; + s->groupCount++; + return rv; } #if 0 -static void change_fonts(glCompSet * s,const texFont_t* sourcefont) +static void change_fonts(glCompSet * s, const texFont_t * sourcefont) { int ind; for (ind = 0; ind < s->buttoncount; ind++) { - copy_font((s->buttons[ind]->font),sourcefont); + copy_font((s->buttons[ind]->font), sourcefont); } for (ind = 0; ind < s->labelcount; ind++) { - copy_font((s->labels[ind]->font),sourcefont); + copy_font((s->labels[ind]->font), sourcefont); } for (ind = 0; ind < s->panelcount; ind++) { - copy_font((s->panels[ind]->font),sourcefont); + copy_font((s->panels[ind]->font), sourcefont); } } #endif diff --git a/lib/glcomp/glcomptext.c b/lib/glcomp/glcomptext.c index ae8919897..0d421b874 100644 --- a/lib/glcomp/glcomptext.c +++ b/lib/glcomp/glcomptext.c @@ -1,3 +1,5 @@ +/* vim:set shiftwidth=4 ts=8: */ + /********************************************************** * This software is part of the graphviz package * * http://www.graphviz.org/ * @@ -16,200 +18,201 @@ #include "memory.h" #include -void -print_bitmap_string(void* font, char* s) +void print_bitmap_string(void *font, char *s) { - if (s && strlen(s)) { - while (*s) { - glutBitmapCharacter(font, *s); + if (s && strlen(s)) { + while (*s) { + glutBitmapCharacter(font, *s); // glutBitmapCharacter(GLUT_BITMAP_HELVETICA_12, *s); - s++; - } - } + s++; + } + } } -void init_gl_vars(glCompText* f) +void init_gl_vars(glCompText * f) { - glGetIntegerv(GL_POLYGON_MODE, f->glcache.poly); - - if (f->glcache.poly[0] != GL_FILL) - glPolygonMode (GL_FRONT, GL_FILL); - if (f->glcache.poly[1] != GL_FILL) - glPolygonMode (GL_BACK, GL_FILL); - - f->glcache.istextureon = glIsEnabled (GL_TEXTURE_2D); - if (!f->glcache.istextureon) - glEnable (GL_TEXTURE_2D); - f->glcache.isdepthon = glIsEnabled (GL_DEPTH_TEST); - if (f->glcache.isdepthon) - glDisable (GL_DEPTH_TEST); - f->glcache.islightingon= glIsEnabled (GL_LIGHTING); - if (f->glcache.islightingon) - glDisable(GL_LIGHTING); - glGetIntegerv(GL_MATRIX_MODE, &f->glcache.matrix); - - f->glcache.isblendon= glIsEnabled (GL_BLEND); - glGetIntegerv (GL_BLEND_SRC, &f->glcache.blendfrom); - glGetIntegerv (GL_BLEND_DST, &f->glcache.blendto); - if (&f->glcache.isblendon) - glEnable (GL_BLEND); - glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glGetIntegerv(GL_POLYGON_MODE, f->glcache.poly); + + if (f->glcache.poly[0] != GL_FILL) + glPolygonMode(GL_FRONT, GL_FILL); + if (f->glcache.poly[1] != GL_FILL) + glPolygonMode(GL_BACK, GL_FILL); + + f->glcache.istextureon = glIsEnabled(GL_TEXTURE_2D); + if (!f->glcache.istextureon) + glEnable(GL_TEXTURE_2D); + f->glcache.isdepthon = glIsEnabled(GL_DEPTH_TEST); + if (f->glcache.isdepthon) + glDisable(GL_DEPTH_TEST); + f->glcache.islightingon = glIsEnabled(GL_LIGHTING); + if (f->glcache.islightingon) + glDisable(GL_LIGHTING); + glGetIntegerv(GL_MATRIX_MODE, &f->glcache.matrix); + + f->glcache.isblendon = glIsEnabled(GL_BLEND); + glGetIntegerv(GL_BLEND_SRC, &f->glcache.blendfrom); + glGetIntegerv(GL_BLEND_DST, &f->glcache.blendto); + if (&f->glcache.isblendon) + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); } -void restore_gl_vars(glCompText* f) + +void restore_gl_vars(glCompText * f) { - if (f->glcache.poly[0] != GL_FILL) - glPolygonMode (GL_FRONT, f->glcache.poly[0]); - if (f->glcache.poly[1] != GL_FILL) - glPolygonMode (GL_BACK, f->glcache.poly[1]); - - if (f->glcache.islightingon) - glEnable(GL_LIGHTING); - - if (!f->glcache.isblendon) - { - glDisable (GL_BLEND); - glBlendFunc (f->glcache.blendfrom, f->glcache.blendto); - } else glBlendFunc (f->glcache.blendfrom, f->glcache.blendto); - - if (f->glcache.isdepthon) - glEnable (GL_DEPTH_TEST); - if (!f->glcache.istextureon) - glDisable (GL_TEXTURE_2D); - glMatrixMode (f->glcache.matrix); + if (f->glcache.poly[0] != GL_FILL) + glPolygonMode(GL_FRONT, f->glcache.poly[0]); + if (f->glcache.poly[1] != GL_FILL) + glPolygonMode(GL_BACK, f->glcache.poly[1]); + + if (f->glcache.islightingon) + glEnable(GL_LIGHTING); + + if (!f->glcache.isblendon) { + glDisable(GL_BLEND); + glBlendFunc(f->glcache.blendfrom, f->glcache.blendto); + } else + glBlendFunc(f->glcache.blendfrom, f->glcache.blendto); + + if (f->glcache.isdepthon) + glEnable(GL_DEPTH_TEST); + if (!f->glcache.istextureon) + glDisable(GL_TEXTURE_2D); + glMatrixMode(f->glcache.matrix); } -void glprintfglut (void* font, GLfloat xpos, GLfloat ypos, GLfloat zpos,char *bf) +void glprintfglut(void *font, GLfloat xpos, GLfloat ypos, GLfloat zpos, + char *bf) { - glRasterPos3f(xpos,ypos,zpos+0.001); - print_bitmap_string(font,bf); + glRasterPos3f(xpos, ypos, zpos + 0.001); + print_bitmap_string(font, bf); } -static void -glPrintf (glCompText* font, GLfloat xpos, GLfloat ypos, GLfloat zpos, - GLfloat width, char *bf, int usez) +static void +glPrintf(glCompText * font, GLfloat xpos, GLfloat ypos, GLfloat zpos, + GLfloat width, char *bf, int usez) { - int vPort[4]; - GLfloat size = font->fontheight; - GLfloat x = xpos; - GLfloat y = ypos; + int vPort[4]; + GLfloat size = font->fontheight; + GLfloat x = xpos; + GLfloat y = ypos; int xMax; - int charCount; - int maxcharCount; - char* tempC; - GLfloat charGap; - - //set the color - glColor4f(font->color.R,font->color.G,font->color.B,font->color.A); - if (!font) - return; - if (font->isglut) - { - glprintfglut (font->glutfont, xpos,ypos,zpos,bf); - return; - } + int charCount; + int maxcharCount; + char *tempC; + GLfloat charGap; + + //set the color + glColor4f(font->color.R, font->color.G, font->color.B, font->color.A); + if (!font) + return; + if (font->isglut) { + glprintfglut(font->glutfont, xpos, ypos, zpos, bf); + return; + } - glGetIntegerv (GL_VIEWPORT, vPort); + glGetIntegerv(GL_VIEWPORT, vPort); - init_gl_vars(font); - glBindTexture (GL_TEXTURE_2D, font->texId); + init_gl_vars(font); + glBindTexture(GL_TEXTURE_2D, font->texId); - xMax = vPort[0] + vPort[2]; + xMax = vPort[0] + vPort[2]; - tempC=bf; - charCount=0; - maxcharCount=0; + tempC = bf; + charCount = 0; + maxcharCount = 0; - while (*tempC != '\0') - { - if ( *tempC == '\t') - charCount=charCount+FONT_TAB_SPACE; - else - charCount++; - tempC++; - } - if (charCount > maxcharCount) - maxcharCount=charCount; - charGap=(width / (float)maxcharCount); + while (*tempC != '\0') { + if (*tempC == '\t') + charCount = charCount + FONT_TAB_SPACE; + else + charCount++; + tempC++; + } + if (charCount > maxcharCount) + maxcharCount = charCount; + charGap = (width / (float) maxcharCount); - for ( ; *bf; *bf ++, x += charGap) //size*0.7 is the distance between2 characters - { + for (; *bf; *bf++, x += charGap) //size*0.7 is the distance between2 characters + { - glBegin (GL_QUADS); - glTexCoord2f (font->bmp[(int)(*bf)][0], font->bmp[(int)(*bf)][1]); - glVertex3f (x, y,0); + glBegin(GL_QUADS); + glTexCoord2f(font->bmp[(int) (*bf)][0], font->bmp[(int) (*bf)][1]); + glVertex3f(x, y, 0); - glTexCoord2f (font->bmp[(int)(*bf)][0] + font->tIncX, font->bmp[(int)(*bf)][1]); - glVertex3f (x + size, y,0); + glTexCoord2f(font->bmp[(int) (*bf)][0] + font->tIncX, + font->bmp[(int) (*bf)][1]); + glVertex3f(x + size, y, 0); - glColor4f (font->color.R,font->color.G,font->color.B,font->color.A); + glColor4f(font->color.R, font->color.G, font->color.B, + font->color.A); - glTexCoord2f (font->bmp[(int)(*bf)][0] + font->tIncX, font->bmp[(int)(*bf)][1] + font->tIncY); - glVertex3f (x + size, y + size,0); + glTexCoord2f(font->bmp[(int) (*bf)][0] + font->tIncX, + font->bmp[(int) (*bf)][1] + font->tIncY); + glVertex3f(x + size, y + size, 0); - glTexCoord2f (font->bmp[(int)(*bf)][0], font->bmp[(int)(*bf)][1] + font->tIncY); - glVertex3f (x , y + size,0); - glEnd (); - } + glTexCoord2f(font->bmp[(int) (*bf)][0], + font->bmp[(int) (*bf)][1] + font->tIncY); + glVertex3f(x, y + size, 0); + glEnd(); + } - restore_gl_vars(font); + restore_gl_vars(font); } -void -glprintf (glCompText* font, GLfloat xpos, GLfloat ypos, GLfloat zpos,GLfloat width, char *bf) - +void +glprintf(glCompText * font, GLfloat xpos, GLfloat ypos, GLfloat zpos, + GLfloat width, char *bf) { - glPrintf (font, xpos, ypos, zpos, width, bf, 0); + glPrintf(font, xpos, ypos, zpos, width, bf, 0); } -void -glprintfz (glCompText* font, GLfloat xpos, GLfloat ypos, GLfloat zpos, - GLfloat width, char *bf) +void +glprintfz(glCompText * font, GLfloat xpos, GLfloat ypos, GLfloat zpos, + GLfloat width, char *bf) { - glPrintf (font, xpos, ypos, zpos, width, bf, 0); + glPrintf(font, xpos, ypos, zpos, width, bf, 0); } -static int fontId(fontset_t* fontset,char* fontdesc) +static int fontId(fontset_t * fontset, char *fontdesc) { - int ind=0; - for (ind=0;ind < fontset->count;ind ++) - { - if (strcmp(fontset->fonts[ind]->fontdesc,fontdesc) == 0) - return ind; - } - return -1; + int ind = 0; + for (ind = 0; ind < fontset->count; ind++) { + if (strcmp(fontset->fonts[ind]->fontdesc, fontdesc) == 0) + return ind; + } + return -1; } -static int glutfontId(fontset_t* fontset,void* glutfont) +static int glutfontId(fontset_t * fontset, void *glutfont) { - int ind=0; - for (ind=0;ind < fontset->count;ind ++) - { - if (fontset->fonts[ind]->glutfont == glutfont) - return ind; - } - return -1; + int ind = 0; + for (ind = 0; ind < fontset->count; ind++) { + if (fontset->fonts[ind]->glutfont == glutfont) + return ind; + } + return -1; } -glCompText* glut_font_init(void) +glCompText *glut_font_init(void) { - glCompText* font = NEW(glCompText); - font->color.R=1.00; - font->color.G=1.00; - font->color.B=1.00; - font->color.A=1.00; + glCompText *font = NEW(glCompText); + font->color.R = 1.00; + font->color.G = 1.00; + font->color.B = 1.00; + font->color.A = 1.00; /* font->fontheight=12; @@ -239,77 +242,74 @@ glCompText* glut_font_init(void) -glCompText* font_init() +glCompText *font_init() { - glCompText* font = NEW(glCompText); - int idx = 0; - float x, y; + glCompText *font = NEW(glCompText); + int idx = 0; + float x, y; - font->color.R=1.00; - font->color.G=1.00; - font->color.B=1.00; - font->color.A=1.00; + font->color.R = 1.00; + font->color.G = 1.00; + font->color.B = 1.00; + font->color.A = 1.00; - font->fontheight=12; - font->tIncX=0.0; - font->tIncY=0.0; - font->texId=-1; - font->fontdesc=(char*)0; + font->fontheight = 12; + font->tIncX = 0.0; + font->tIncY = 0.0; + font->texId = -1; + font->fontdesc = (char *) 0; - font->tIncX = (float)pow (C_DPI, -1); - font->tIncY = (float)pow (R_DPI, -1); + font->tIncX = (float) pow(C_DPI, -1); + font->tIncY = (float) pow(R_DPI, -1); - - for (y = 1 - font->tIncY; y >= 0; y -= font->tIncY) - { - for (x = 0; x <= 1 - font->tIncX; x += font->tIncX, idx ++) - { - font->bmp[idx][0]=x; - font->bmp[idx][1]=y; - } + + for (y = 1 - font->tIncY; y >= 0; y -= font->tIncY) { + for (x = 0; x <= 1 - font->tIncX; x += font->tIncX, idx++) { + font->bmp[idx][0] = x; + font->bmp[idx][1] = y; } + } return font; } -void copy_font(glCompText* targetfont,const glCompText* sourcefont) +void copy_font(glCompText * targetfont, const glCompText * sourcefont) { - int idx = 0; - float x, y; + int idx = 0; + float x, y; - targetfont->color.R=sourcefont->color.R; - targetfont->color.G=sourcefont->color.G; - targetfont->color.B=sourcefont->color.B; - targetfont->color.A=sourcefont->color.A; + targetfont->color.R = sourcefont->color.R; + targetfont->color.G = sourcefont->color.G; + targetfont->color.B = sourcefont->color.B; + targetfont->color.A = sourcefont->color.A; - targetfont->fontheight=sourcefont->fontheight; - targetfont->tIncX=sourcefont->tIncX; - targetfont->tIncY=sourcefont->tIncY; - targetfont->texId=sourcefont->texId; - if (targetfont->fontdesc) - free(targetfont->fontdesc); - if(sourcefont->fontdesc!=(char*)0) - targetfont->fontdesc=strdup(sourcefont->fontdesc); - else - targetfont->fontdesc=(char*)0; + targetfont->fontheight = sourcefont->fontheight; + targetfont->tIncX = sourcefont->tIncX; + targetfont->tIncY = sourcefont->tIncY; + targetfont->texId = sourcefont->texId; + if (targetfont->fontdesc) + free(targetfont->fontdesc); + if (sourcefont->fontdesc != (char *) 0) + targetfont->fontdesc = strdup(sourcefont->fontdesc); + else + targetfont->fontdesc = (char *) 0; - targetfont->tIncX = (float)pow (C_DPI, -1); - targetfont->tIncY = (float)pow (R_DPI, -1); + targetfont->tIncX = (float) pow(C_DPI, -1); + targetfont->tIncY = (float) pow(R_DPI, -1); - - for (y = 1 - targetfont->tIncY; y >= 0; y -= targetfont->tIncY) - { - for (x = 0; x <= 1 - targetfont->tIncX; x += targetfont->tIncX, idx ++) - { - targetfont->bmp[idx][0]=x; - targetfont->bmp[idx][1]=y; - } + + for (y = 1 - targetfont->tIncY; y >= 0; y -= targetfont->tIncY) { + for (x = 0; x <= 1 - targetfont->tIncX; + x += targetfont->tIncX, idx++) { + targetfont->bmp[idx][0] = x; + targetfont->bmp[idx][1] = y; } + } } @@ -317,87 +317,83 @@ void copy_font(glCompText* targetfont,const glCompText* sourcefont) #define TMPTEMP "/tmp/_sfXXXX" #endif -fontset_t* fontset_init() +fontset_t *fontset_init() { - fontset_t* fs = NEW(fontset_t); - fs->activefont=-1; - fs->count=0; + fontset_t *fs = NEW(fontset_t); + fs->activefont = -1; + fs->count = 0; #ifdef _WIN32 - fs->font_directory = "c:/fontfiles"; //FIX ME + fs->font_directory = "c:/fontfiles"; //FIX ME #else - fs->font_directory = strdup (TMPTEMP); - mkdtemp (fs->font_directory); + fs->font_directory = strdup(TMPTEMP); + mkdtemp(fs->font_directory); #endif - fs->fonts=0; + fs->fonts = 0; return fs; } -static char* fontpath = NULL; +static char *fontpath = NULL; static size_t fontpathsz = 0; -glCompText* add_glut_font(fontset_t* fontset,void* glutfont) +glCompText *add_glut_font(fontset_t * fontset, void *glutfont) { - int id; - id=glutfontId(fontset,glutfont); - if(id==-1) - { - fontset->fonts = ALLOC(fontset->count+1,fontset->fonts,glCompText*); - fontset->fonts[fontset->count] = glut_font_init (); - fontset->fonts[fontset->count]->isglut=1; - fontset->fonts[fontset->count]->glutfont=glutfont; - fontset->count++; - return fontset->fonts[fontset->count-1]; - } - else - return fontset->fonts[id]; + int id; + id = glutfontId(fontset, glutfont); + if (id == -1) { + fontset->fonts = + ALLOC(fontset->count + 1, fontset->fonts, glCompText *); + fontset->fonts[fontset->count] = glut_font_init(); + fontset->fonts[fontset->count]->isglut = 1; + fontset->fonts[fontset->count]->glutfont = glutfont; + fontset->count++; + return fontset->fonts[fontset->count - 1]; + } else + return fontset->fonts[id]; } -glCompText* add_font(fontset_t* fontset,char* fontdesc) +glCompText *add_font(fontset_t * fontset, char *fontdesc) { - int id; + int id; size_t sz; - glCompText* tf; - - id=fontId(fontset,fontdesc); - if (id==-1) - { - sz = strlen(fontset->font_directory)+strlen(fontdesc)+6; - if (sz > fontpathsz) - { - fontpathsz = 2*sz; - fontpath = ALLOC (fontpathsz, fontpath, char); - } - sprintf(fontpath,"%s/%s.png",fontset->font_directory,fontdesc); - if(create_font_file(fontdesc,fontpath,(float)32,(float)32)==0) - { - fontset->fonts = ALLOC(fontset->count+1,fontset->fonts,glCompText*); - fontset->fonts[fontset->count] = tf = font_init (); - tf->fontdesc = strdup(fontdesc); - fontset->fonts[fontset->count]->isglut=0; - glGenTextures (1, &(tf->texId)); //get opengl texture name - if ((tf->texId >= 0) && glCompLoadFontPNG (fontpath, tf->texId)) - { - fontset->activefont=fontset->count; - fontset->count++; - return fontset->fonts[fontset->count-1]; - } - else - return NULL; - } - else - return NULL; + glCompText *tf; + + id = fontId(fontset, fontdesc); + if (id == -1) { + sz = strlen(fontset->font_directory) + strlen(fontdesc) + 6; + if (sz > fontpathsz) { + fontpathsz = 2 * sz; + fontpath = ALLOC(fontpathsz, fontpath, char); } - else - return fontset->fonts[id]; + sprintf(fontpath, "%s/%s.png", fontset->font_directory, fontdesc); + if (create_font_file(fontdesc, fontpath, (float) 32, (float) 32) == + 0) { + fontset->fonts = + ALLOC(fontset->count + 1, fontset->fonts, glCompText *); + fontset->fonts[fontset->count] = tf = font_init(); + tf->fontdesc = strdup(fontdesc); + fontset->fonts[fontset->count]->isglut = 0; + glGenTextures(1, &(tf->texId)); //get opengl texture name + if ((tf->texId >= 0) && glCompLoadFontPNG(fontpath, tf->texId)) { + fontset->activefont = fontset->count; + fontset->count++; + return fontset->fonts[fontset->count - 1]; + } else + return NULL; + } else + return NULL; + } else + return fontset->fonts[id]; } -void free_font_set(fontset_t* fontset) + +void free_font_set(fontset_t * fontset) { int ind; - for (ind=0;ind < fontset->count;ind ++) { + for (ind = 0; ind < fontset->count; ind++) { #ifndef _WIN32 - sprintf(fontpath,"%s/%s.png",fontset->font_directory,fontset->fonts[ind]->fontdesc); - unlink (fontpath); + sprintf(fontpath, "%s/%s.png", fontset->font_directory, + fontset->fonts[ind]->fontdesc); + unlink(fontpath); #endif free(fontset->fonts[ind]->fontdesc); free(fontset->fonts[ind]); @@ -405,19 +401,18 @@ void free_font_set(fontset_t* fontset) free(fontset->fonts); #ifndef _WIN32 if (fontset->font_directory) - rmdir (fontset->font_directory); + rmdir(fontset->font_directory); #endif - if (fontset->font_directory) - free(fontset->font_directory); + if (fontset->font_directory) + free(fontset->font_directory); free(fontset); } -void fontColor (glCompText* font,float r, float g, float b,float a) +void fontColor(glCompText * font, float r, float g, float b, float a) { - font->color.R=r; - font->color.G=g; - font->color.B=b; - font->color.A=a; + font->color.R = r; + font->color.G = g; + font->color.B = b; + font->color.A = a; } - diff --git a/lib/glcomp/glcomptextpng.c b/lib/glcomp/glcomptextpng.c index 6d0833ea1..1e537ee71 100644 --- a/lib/glcomp/glcomptextpng.c +++ b/lib/glcomp/glcomptextpng.c @@ -1,3 +1,5 @@ +/* vim:set shiftwidth=4 ts=8: */ + /********************************************************** * This software is part of the graphviz package * * http://www.graphviz.org/ * @@ -16,105 +18,97 @@ -unsigned char *load_png_font(char* file_name,int *imageWidth,int *imageHeight) +unsigned char *load_png_font(char *file_name, int *imageWidth, + int *imageHeight) { - unsigned char *imageData = NULL; - unsigned char header[8]; - int i,ii,b0,b1,b2,b3,pixeloffset; - long int c; - png_structp png_ptr; - png_infop info_ptr; - png_infop end_info; - png_bytepp row_pointers; //actual image data - int is_png=0; - FILE *fp = fopen(file_name, "rb"); - if (!fp) - { - return (unsigned char*)0; + unsigned char *imageData = NULL; + unsigned char header[8]; + int i, ii, b0, b1, b2, b3, pixeloffset; + long int c; + png_structp png_ptr; + png_infop info_ptr; + png_infop end_info; + png_bytepp row_pointers; //actual image data + int is_png = 0; + FILE *fp = fopen(file_name, "rb"); + if (!fp) { + return (unsigned char *) 0; } fread(header, 1, 8, fp); is_png = !png_sig_cmp(header, 0, 8); - if (!is_png) - { - printf ("glcomp error:file is not a valid PNG file\n"); - return (unsigned char*)0; + if (!is_png) { + printf("glcomp error:file is not a valid PNG file\n"); + return (unsigned char *) 0; } png_ptr = png_create_read_struct - (PNG_LIBPNG_VER_STRING, NULL,NULL,NULL); - if (!png_ptr) - { - printf ("glcomp error:file can not be read\n"); - return (unsigned char*)0; - } + (PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); + if (!png_ptr) { + printf("glcomp error:file can not be read\n"); + return (unsigned char *) 0; + } info_ptr = png_create_info_struct(png_ptr); - if (!info_ptr) - { - png_destroy_read_struct(&png_ptr, - (png_infopp)NULL, (png_infopp)NULL); - printf ("glcomp error:PNG file header is corrupted\n"); - return (unsigned char*)0; + if (!info_ptr) { + png_destroy_read_struct(&png_ptr, + (png_infopp) NULL, (png_infopp) NULL); + printf("glcomp error:PNG file header is corrupted\n"); + return (unsigned char *) 0; } end_info = png_create_info_struct(png_ptr); - if (!end_info) - { - printf ("glcomp error:PNG file header is corrupted\n"); - png_destroy_read_struct(&png_ptr, &info_ptr, - (png_infopp)NULL); - return (unsigned char*)0; + if (!end_info) { + printf("glcomp error:PNG file header is corrupted\n"); + png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp) NULL); + return (unsigned char *) 0; } - png_init_io(png_ptr, fp); + png_init_io(png_ptr, fp); png_set_sig_bytes(png_ptr, 8); //pass signature bytes - png_read_png(png_ptr, info_ptr, PNG_TRANSFORM_IDENTITY, NULL); //read real image data - - row_pointers = png_malloc(png_ptr, - info_ptr->height*sizeof(png_bytepp)); - row_pointers = png_get_rows(png_ptr, info_ptr); - *imageWidth=info_ptr->width; - *imageHeight=info_ptr->height; - imageData=malloc(info_ptr->height*info_ptr->width); - c=0; - //decide what pixel offset to use, ro - pixeloffset = png_get_rowbytes(png_ptr, info_ptr)/info_ptr->width; - - b0=-1;b1=-1;b2=-1;b3=-1; - - for (i=0; i < (int)info_ptr->height; i++) - { - for (ii=0;ii < (int)png_get_rowbytes(png_ptr, info_ptr); ii=ii+pixeloffset) - { - imageData[c]=row_pointers[info_ptr->height-i-1][ii]; - - if( - (b0!=row_pointers[info_ptr->height-i-1][ii]) - || - (b1!=row_pointers[info_ptr->height-i-1][ii+1]) - || - (b2!=row_pointers[info_ptr->height-i-1][ii+2]) - || - (b3!=row_pointers[info_ptr->height-i-1][ii+3]) - ) - { - b0=row_pointers[info_ptr->height-i-1][ii]; - b1=row_pointers[info_ptr->height-i-1][ii+1]; - b2=row_pointers[info_ptr->height-i-1][ii+2]; - b3=row_pointers[info_ptr->height-i-1][ii+3]; - - } - - - c++; - } - } - //cleaning libpng mess - png_destroy_read_struct(&png_ptr, &info_ptr, &end_info); - png_free(png_ptr, row_pointers); - return imageData; + png_read_png(png_ptr, info_ptr, PNG_TRANSFORM_IDENTITY, NULL); //read real image data + + row_pointers = png_malloc(png_ptr, + info_ptr->height * sizeof(png_bytepp)); + row_pointers = png_get_rows(png_ptr, info_ptr); + *imageWidth = info_ptr->width; + *imageHeight = info_ptr->height; + imageData = malloc(info_ptr->height * info_ptr->width); + c = 0; + //decide what pixel offset to use, ro + pixeloffset = png_get_rowbytes(png_ptr, info_ptr) / info_ptr->width; + + b0 = -1; + b1 = -1; + b2 = -1; + b3 = -1; + + for (i = 0; i < (int) info_ptr->height; i++) { + for (ii = 0; ii < (int) png_get_rowbytes(png_ptr, info_ptr); + ii = ii + pixeloffset) { + imageData[c] = row_pointers[info_ptr->height - i - 1][ii]; + + if ((b0 != row_pointers[info_ptr->height - i - 1][ii]) + || (b1 != row_pointers[info_ptr->height - i - 1][ii + 1]) + || (b2 != row_pointers[info_ptr->height - i - 1][ii + 2]) + || (b3 != row_pointers[info_ptr->height - i - 1][ii + 3]) + ) { + b0 = row_pointers[info_ptr->height - i - 1][ii]; + b1 = row_pointers[info_ptr->height - i - 1][ii + 1]; + b2 = row_pointers[info_ptr->height - i - 1][ii + 2]; + b3 = row_pointers[info_ptr->height - i - 1][ii + 3]; + + } + + + c++; + } + } + //cleaning libpng mess + png_destroy_read_struct(&png_ptr, &info_ptr, &end_info); + png_free(png_ptr, row_pointers); + return imageData; } @@ -122,16 +116,16 @@ unsigned char *load_png_font(char* file_name,int *imageWidth,int *imageHeight) #define imageHeight 256 static GLubyte imageData[imageWidth][imageHeight][4];*/ -int glCompLoadFontPNG (char *name, int id) +int glCompLoadFontPNG(char *name, int id) { - GLubyte *imageData = NULL; - int imageWidth,imageHeight,idx2,c; - -// imageData = fontGetData (s, size, imageBits); - imageData =load_png_font(name,&imageWidth,&imageHeight); - - c=0; - idx2=0; + GLubyte *imageData = NULL; + int imageWidth, imageHeight, idx2, c; + +// imageData = fontGetData (s, size, imageBits); + imageData = load_png_font(name, &imageWidth, &imageHeight); + + c = 0; + idx2 = 0; /* for (idx=0;idx < imageWidth*imageHeight+30000;idx=idx+1) { if (c!=imageData[idx]) @@ -150,26 +144,26 @@ int glCompLoadFontPNG (char *name, int id) }*/ - /* no image data */ - if (imageData == NULL) - return -1; + /* no image data */ + if (imageData == NULL) + return -1; - glBindTexture (GL_TEXTURE_2D, id); - glPixelStorei (GL_UNPACK_ALIGNMENT, 1); - glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); - glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); - /* glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); */ - glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - /* glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); */ - glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); -// glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE , GL_DECAL); + glBindTexture(GL_TEXTURE_2D, id); + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); + /* glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); */ + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + /* glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); */ + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); +// glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE , GL_DECAL); - glTexImage2D (GL_TEXTURE_2D, 0, GL_ALPHA, imageWidth, imageHeight, 0, GL_ALPHA, GL_UNSIGNED_BYTE, imageData); -// glTexImage2D (GL_TEXTURE_2D, 0, GL_RGBA, 256, 256, 0, GL_RGBA, GL_UNSIGNED_BYTE, imageData); + glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, imageWidth, imageHeight, 0, + GL_ALPHA, GL_UNSIGNED_BYTE, imageData); +// glTexImage2D (GL_TEXTURE_2D, 0, GL_RGBA, 256, 256, 0, GL_RGBA, GL_UNSIGNED_BYTE, imageData); - /* release data, its been uploaded */ + /* release data, its been uploaded */ - return 1; + return 1; } - diff --git a/lib/glcomp/glpangofont.c b/lib/glcomp/glpangofont.c index 1c0478372..03ea5c17a 100644 --- a/lib/glcomp/glpangofont.c +++ b/lib/glcomp/glpangofont.c @@ -19,59 +19,61 @@ #define DEFAULT_FONT_SIZE 32 #define ANTIALIAS -static int file_exists(const char * filename) +static int file_exists(const char *filename) { - FILE * file; - if (( file = fopen(filename, "r"))) - { - fclose(file); - return 1; + FILE *file; + if ((file = fopen(filename, "r"))) { + fclose(file); + return 1; } return 0; } -static PangoLayout * get_pango_layout (cairo_t *cr, - char *markup_text, - char* fontdescription, - double *width, - double *height - ) +static PangoLayout *get_pango_layout(cairo_t * cr, + char *markup_text, + char *fontdescription, + double *width, double *height) { PangoFontDescription *desc; - PangoFontMap* fontmap; - PangoContext *context; + PangoFontMap *fontmap; + PangoContext *context; PangoLayout *layout; int pango_width, pango_height; char *text; PangoAttrList *attr_list; - cairo_font_options_t* options; - fontmap = pango_cairo_font_map_get_default(); - context = pango_cairo_font_map_create_context(PANGO_CAIRO_FONT_MAP(fontmap)); - options=cairo_font_options_create(); + cairo_font_options_t *options; + fontmap = pango_cairo_font_map_get_default(); + context = + pango_cairo_font_map_create_context(PANGO_CAIRO_FONT_MAP(fontmap)); + options = cairo_font_options_create(); #ifdef ANTIALIAS -// cairo_font_options_set_antialias(options,CAIRO_ANTIALIAS_GRAY); +// cairo_font_options_set_antialias(options,CAIRO_ANTIALIAS_GRAY); #endif - cairo_font_options_set_hint_style(options,CAIRO_HINT_STYLE_FULL); - cairo_font_options_set_hint_metrics(options,CAIRO_HINT_METRICS_ON); - cairo_font_options_set_subpixel_order(options,CAIRO_SUBPIXEL_ORDER_BGR); -// pango_cairo_context_set_font_options(context, options); - - desc = pango_font_description_from_string(fontdescription); -// pango_font_description_set_family(desc, "CENTAUR.TTF"); - pango_font_description_set_size (desc, (gint)(DEFAULT_FONT_SIZE * PANGO_SCALE/2.0)); -// pango_font_description_set_style (desc,PANGO_STYLE_ITALIC); - - if (! pango_parse_markup (markup_text, -1, '\0', &attr_list, &text, NULL, NULL)) - return (PangoLayout*)0; - layout = pango_layout_new (context); - pango_layout_set_text (layout, text, -1); - pango_layout_set_font_description (layout, desc); - pango_layout_set_attributes (layout, attr_list); - pango_font_description_free (desc); - pango_layout_set_alignment (layout,PANGO_ALIGN_CENTER); - - if (width || height) - pango_layout_get_size (layout, &pango_width, &pango_height); + cairo_font_options_set_hint_style(options, CAIRO_HINT_STYLE_FULL); + cairo_font_options_set_hint_metrics(options, CAIRO_HINT_METRICS_ON); + cairo_font_options_set_subpixel_order(options, + CAIRO_SUBPIXEL_ORDER_BGR); +// pango_cairo_context_set_font_options(context, options); + + desc = pango_font_description_from_string(fontdescription); +// pango_font_description_set_family(desc, "CENTAUR.TTF"); + pango_font_description_set_size(desc, + (gint) (DEFAULT_FONT_SIZE * + PANGO_SCALE / 2.0)); +// pango_font_description_set_style (desc,PANGO_STYLE_ITALIC); + + if (!pango_parse_markup + (markup_text, -1, '\0', &attr_list, &text, NULL, NULL)) + return (PangoLayout *) 0; + layout = pango_layout_new(context); + pango_layout_set_text(layout, text, -1); + pango_layout_set_font_description(layout, desc); + pango_layout_set_attributes(layout, attr_list); + pango_font_description_free(desc); + pango_layout_set_alignment(layout, PANGO_ALIGN_CENTER); + + if (width || height) + pango_layout_get_size(layout, &pango_width, &pango_height); if (width) *width = (double) pango_width / PANGO_SCALE; @@ -83,72 +85,74 @@ static PangoLayout * get_pango_layout (cairo_t *cr, } static cairo_status_t -writer (void *closure, const unsigned char *data, unsigned int length) +writer(void *closure, const unsigned char *data, unsigned int length) { - if (length == fwrite(data, 1, length, (FILE *)closure)) - { - return CAIRO_STATUS_SUCCESS; - } + if (length == fwrite(data, 1, length, (FILE *) closure)) { + return CAIRO_STATUS_SUCCESS; + } - return CAIRO_STATUS_WRITE_ERROR; + return CAIRO_STATUS_WRITE_ERROR; } -int create_font_file(char* fontdescription,char* fontfile,float gw,float gh) +int create_font_file(char *fontdescription, char *fontfile, float gw, + float gh) { - char buf[]=" "; - int ncolumns=16; - int counter=0; - int X=0; - int Y=0; - cairo_t *cr; + char buf[] = " "; + int ncolumns = 16; + int counter = 0; + int X = 0; + int Y = 0; + cairo_t *cr; cairo_surface_t *surface; PangoLayout *layout; double width, height; - FILE* output_file; - int c; - int return_value=-1; - - if(file_exists(fontfile)) //checking if font file has already been created - return 0; - //create the right size canvas for character set - surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32,(int)((float)ncolumns*gw),(int)(gh*(float)ncolumns)); - cr = cairo_create(surface); - //draw a rectangle with same size of canvas - cairo_rectangle(cr, 0, 0,(float)ncolumns*gw,gh*(float)ncolumns); - //fill rectangle with black - cairo_set_source_rgb(cr, 0, 0, 0); - cairo_fill(cr); - //set pen color to white - cairo_set_source_rgb(cr, 1, 1, 1); - - for (c=0;c < 256 ; c++) - { - counter++; - if ((c !=38) && (c !=60)&& (c !=128) && (c < 129)) - buf[0]=c; - else - buf[0]=' '; - cairo_move_to(cr,X,Y); - layout = get_pango_layout (cr,buf,fontdescription, &width, &height); - pango_cairo_show_layout(cr, layout); - X=X+(int)gw; - if (counter==ncolumns) - { - X=0;Y=Y+(int)gh; - counter=0; - } - } - output_file = fopen(fontfile, "wb+"); - if(output_file) - { - cairo_surface_write_to_png_stream(surface, writer, output_file); - return_value=0; + FILE *output_file; + int c; + int return_value = -1; + + if (file_exists(fontfile)) //checking if font file has already been created + return 0; + //create the right size canvas for character set + surface = + cairo_image_surface_create(CAIRO_FORMAT_ARGB32, + (int) ((float) ncolumns * gw), + (int) (gh * (float) ncolumns)); + cr = cairo_create(surface); + //draw a rectangle with same size of canvas + cairo_rectangle(cr, 0, 0, (float) ncolumns * gw, + gh * (float) ncolumns); + //fill rectangle with black + cairo_set_source_rgb(cr, 0, 0, 0); + cairo_fill(cr); + //set pen color to white + cairo_set_source_rgb(cr, 1, 1, 1); + + for (c = 0; c < 256; c++) { + counter++; + if ((c != 38) && (c != 60) && (c != 128) && (c < 129)) + buf[0] = c; + else + buf[0] = ' '; + cairo_move_to(cr, X, Y); + layout = + get_pango_layout(cr, buf, fontdescription, &width, &height); + pango_cairo_show_layout(cr, layout); + X = X + (int) gw; + if (counter == ncolumns) { + X = 0; + Y = Y + (int) gh; + counter = 0; } - fclose(output_file); - g_object_unref (layout); + } + output_file = fopen(fontfile, "wb+"); + if (output_file) { + cairo_surface_write_to_png_stream(surface, writer, output_file); + return_value = 0; + } + fclose(output_file); + g_object_unref(layout); cairo_destroy(cr); cairo_surface_destroy(surface); - return return_value; + return return_value; } - diff --git a/lib/glcomp/glutils.c b/lib/glcomp/glutils.c index 693798632..7536ddabe 100644 --- a/lib/glcomp/glutils.c +++ b/lib/glcomp/glutils.c @@ -14,6 +14,8 @@ **********************************************************/ #include "glutils.h" +#include "stdlib.h" +#include "string.h" /* #include "glexpose.h" */ /* at given depth value, tranforms 2d Window location to 3d gl coords*/ @@ -30,16 +32,16 @@ int GetFixedOGLPos(int x, int y, float kts, GLfloat * X, GLfloat * Y, GLfloat winX, winY; GLdouble posX, posY, posZ; - glColor4f((GLfloat)0,(GLfloat)0,(GLfloat)0,(GLfloat)0.001); - glBegin(GL_POINTS); - glVertex3f((GLfloat)-100.00, (GLfloat)-100.00, (GLfloat)1.00); + glColor4f((GLfloat) 0, (GLfloat) 0, (GLfloat) 0, (GLfloat) 0.001); + glBegin(GL_POINTS); + glVertex3f((GLfloat) - 100.00, (GLfloat) - 100.00, (GLfloat) 1.00); glEnd(); - - glGetDoublev(GL_MODELVIEW_MATRIX, modelview); + + glGetDoublev(GL_MODELVIEW_MATRIX, modelview); glGetDoublev(GL_PROJECTION_MATRIX, projection); glGetIntegerv(GL_VIEWPORT, viewport); - gluProject(-100.0, -100.0, 1.00, modelview, projection, viewport, &wwinX, - &wwinY, &wwinZ); + gluProject(-100.0, -100.0, 1.00, modelview, projection, viewport, + &wwinX, &wwinY, &wwinZ); winX = (float) x; winY = (float) viewport[3] - (float) y; @@ -73,13 +75,13 @@ int GetOGLPosRef(int x, int y, float *X, float *Y, float *Z) glGetIntegerv(GL_VIEWPORT, viewport); //draw a point to a not important location to get window coordinates - glColor4f((GLfloat)0,(GLfloat)0,(GLfloat)0,(GLfloat)0.001); + glColor4f((GLfloat) 0, (GLfloat) 0, (GLfloat) 0, (GLfloat) 0.001); - glBegin(GL_POINTS); + glBegin(GL_POINTS); glVertex3f(-100.00, -100.00, 0.00); glEnd(); - gluProject(-100.0, -100.0, 0.00, modelview, projection, viewport, &wwinX, - &wwinY, &wwinZ); + gluProject(-100.0, -100.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, @@ -89,10 +91,10 @@ int GetOGLPosRef(int x, int y, float *X, float *Y, float *Z) *Y = (float) posY; *Z = (float) posZ; // glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); -// printf("==>(%d,%d,%d) -> (%f,%f,%f)\n",x,y,wwinZ,*X,*Y,*Z); +// printf("==>(%d,%d,%d) -> (%f,%f,%f)\n",x,y,wwinZ,*X,*Y,*Z); - return 1; + return 1; } @@ -109,7 +111,7 @@ float GetOGLDistance(int l) - GLint viewport[4]; + GLint viewport[4]; GLdouble modelview[16]; GLdouble projection[16]; GLfloat winX, winY; @@ -117,14 +119,14 @@ float GetOGLDistance(int l) - glGetDoublev(GL_MODELVIEW_MATRIX, modelview); + 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 - glColor4f((GLfloat)0,(GLfloat)0,(GLfloat)0,(GLfloat)0.001); + glColor4f((GLfloat) 0, (GLfloat) 0, (GLfloat) 0, (GLfloat) 0.001); - glBegin(GL_POINTS); + glBegin(GL_POINTS); glVertex3f(10.00, 10.00, 1.00); glEnd(); gluProject(10.0, 10.0, 1.00, modelview, projection, viewport, &wwinX, @@ -142,9 +144,10 @@ float GetOGLDistance(int l) gluUnProject(winX, winY, wwinZ, modelview, projection, viewport, &posXX, &posYY, &posZZ); // glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - return ((float) (posXX - posX)); + return ((float) (posXX - posX)); } + /* functions def: returns opengl coordinates of firt hit object by using screen coordinates x,y; 2D screen coordiantes (usually received from mouse events @@ -154,50 +157,50 @@ float GetOGLDistance(int l) */ -void to3D(int x, int y, GLfloat *X, GLfloat *Y,GLfloat *Z) +void to3D(int x, int y, GLfloat * X, GLfloat * Y, GLfloat * Z) { - int const WIDTH = 20; + int const WIDTH = 20; GLint viewport[4]; GLdouble modelview[16]; GLdouble projection[16]; GLfloat winX, winY; - GLfloat winZ[400]; + GLfloat winZ[400]; GLdouble posX, posY, posZ; - int idx; - static float comp; - glGetDoublev(GL_MODELVIEW_MATRIX, modelview); + int idx; + static float comp; + glGetDoublev(GL_MODELVIEW_MATRIX, modelview); glGetDoublev(GL_PROJECTION_MATRIX, projection); glGetIntegerv(GL_VIEWPORT, viewport); - winX = (float) x; + winX = (float) x; winY = (float) viewport[3] - (float) y; - glReadPixels(x-WIDTH/2.0, (int)winY-WIDTH/2.0, WIDTH, WIDTH, GL_DEPTH_COMPONENT, GL_FLOAT, &winZ); - comp=-9999999; - for (idx=0;idx < WIDTH* WIDTH ; idx ++) - { - if ((winZ[idx] > comp) && (winZ[idx] < 1)) - comp = winZ[idx]; - } - gluUnProject(winX,winY, comp,modelview, projection, viewport, &posX, - &posY, &posZ); - - *X = (GLfloat) posX; + glReadPixels(x - WIDTH / 2.0, (int) winY - WIDTH / 2.0, WIDTH, WIDTH, + GL_DEPTH_COMPONENT, GL_FLOAT, &winZ); + comp = -9999999; + for (idx = 0; idx < WIDTH * WIDTH; idx++) { + if ((winZ[idx] > comp) && (winZ[idx] < 1)) + comp = winZ[idx]; + } + gluUnProject(winX, winY, comp, modelview, projection, viewport, &posX, + &posY, &posZ); + + *X = (GLfloat) posX; *Y = (GLfloat) posY; *Z = (GLfloat) posZ; // glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - return ; - - - - + return; + + + + } int GetFixedOGLPoslocal(int x, int y, GLfloat * X, GLfloat * Y, - GLfloat * Z) + GLfloat * Z) { GLdouble wwinX; GLdouble wwinY; @@ -208,60 +211,61 @@ int GetFixedOGLPoslocal(int x, int y, GLfloat * X, GLfloat * Y, GLdouble projection[16]; GLfloat winX, winY; GLdouble posX, posY, posZ; - - glGetDoublev(GL_MODELVIEW_MATRIX, modelview); + + glGetDoublev(GL_MODELVIEW_MATRIX, modelview); glGetDoublev(GL_PROJECTION_MATRIX, projection); glGetIntegerv(GL_VIEWPORT, viewport); - glColor4f((GLfloat)0,(GLfloat)0,(GLfloat)0,(GLfloat)0.001); - glBegin(GL_POINTS); + glColor4f((GLfloat) 0, (GLfloat) 0, (GLfloat) 0, (GLfloat) 0.001); + glBegin(GL_POINTS); glVertex3f(10.00, 10.00, 0.00); glEnd(); - gluProject(10.0, 10.0, 1.00, modelview, projection, viewport, &wwinX, + gluProject(10.0, 10.0, 1.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; + *X = (GLfloat) posX; *Y = (GLfloat) posY; *Z = (GLfloat) posZ; // glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - return 1; + return 1; } -void linear_interplotate (float x1,float y1,float x2,float y2,float x3,float* y3) +void linear_interplotate(float x1, float y1, float x2, float y2, float x3, + float *y3) { - float a,b; - a=(y1-y2)/(x1-x2); - b=y1-a*x1; - *y3=a*x3+b; + float a, b; + a = (y1 - y2) / (x1 - x2); + b = y1 - a * x1; + *y3 = a * x3 + b; } #if 0 int glreversecamera(ViewInfo * view) { - glLoadIdentity(); - if (view->active_camera==-1) - { - gluLookAt(view->panx, view->pany, 20, view->panx, - view->pany, 0.0, 0.0, 1.0, 0.0); - glScalef(1*view->zoom*-1,1*view->zoom*-1,1*view->zoom*-1); - } - else - { - glScalef(1*view->cameras[view->active_camera]->r,1*view->cameras[view->active_camera]->r,1*view->cameras[view->active_camera]->r); + glLoadIdentity(); + if (view->active_camera == -1) { + gluLookAt(view->panx, view->pany, 20, view->panx, + view->pany, 0.0, 0.0, 1.0, 0.0); + glScalef(1 * view->zoom * -1, 1 * view->zoom * -1, + 1 * view->zoom * -1); + } else { + glScalef(1 * view->cameras[view->active_camera]->r, + 1 * view->cameras[view->active_camera]->r, + 1 * view->cameras[view->active_camera]->r); - } + } - return 1; + return 1; } #endif @@ -269,7 +273,7 @@ int glreversecamera(ViewInfo * view) -static point3f add (point3f p, point3f q) +static point3f add(point3f p, point3f q) { p.x += q.x; p.y += q.y; @@ -277,7 +281,7 @@ static point3f add (point3f p, point3f q) return p; } -static point3f sub (point3f p, point3f q) +static point3f sub(point3f p, point3f q) { p.x -= q.x; p.y -= q.y; @@ -285,17 +289,17 @@ static point3f sub (point3f p, point3f q) return p; } -static double dot (point3f p, point3f q) +static double dot(point3f p, point3f q) { - return (p.x*q.x + p.y*q.y + p.z*q.z); + return (p.x * q.x + p.y * q.y + p.z * q.z); } -static double len (point3f p) +static double len(point3f p) { - return sqrt(dot(p,p)); + return sqrt(dot(p, p)); } -static point3f scale (double d, point3f p) +static point3f scale(double d, point3f p) { p.x *= d; p.y *= d; @@ -303,52 +307,53 @@ static point3f scale (double d, point3f p) return p; } -static point3f blend (point3f p, point3f q, float m) +static point3f blend(point3f p, point3f q, float m) { point3f r; - r.x = p.x + m * ( q.x - p.x ); - r.y = p.y + m * ( q.y - p.y ); - r.z = p.z + m * ( q.z - p.z ); + r.x = p.x + m * (q.x - p.x); + r.y = p.y + m * (q.y - p.y); + r.z = p.z + m * (q.z - p.z); return r; } -static point3f normalize (point3f p) +static point3f normalize(point3f p) { - double d = len (p); + double d = len(p); - return scale (1/d, p); + return scale(1 / d, p); } -static double dist (point3f p, point3f q) +static double dist(point3f p, point3f q) { - return (len (sub (p,q))); + return (len(sub(p, q))); } -static point3f intersect (line l, plane J) +static point3f intersect(line l, plane J) { - double t = -(J.d + dot(l.u,J.N))/dot(l.v,J.N); - return (add(l.u, scale(t,l.v))); + double t = -(J.d + dot(l.u, J.N)) / dot(l.v, J.N); + return (add(l.u, scale(t, l.v))); } /* * Given a line l determined by two points a and b, and a 3rd point p, * return the distance between the point and the line */ -double point_to_line_dist (point3f p, point3f a, point3f b) { +double point_to_line_dist(point3f p, point3f a, point3f b) +{ line l; plane J; point3f q; l.u = a; - l.v = normalize (sub (b, a)); + l.v = normalize(sub(b, a)); J.N = l.v; J.d = -dot(p, l.v); - q = intersect (l, J); + q = intersect(l, J); - return (dist (p, q)); + return (dist(p, q)); } @@ -358,44 +363,48 @@ double point_to_line_dist (point3f p, point3f a, point3f b) { * If the perpendicular from p to the line a-b is outside of the segment, * return the distance to the closer of a or b. */ -double point_to_lineseg_dist (point3f p, point3f a, point3f b) +double point_to_lineseg_dist(point3f p, point3f a, point3f b) { float U; point3f q; - point3f ba = sub (b, a); - point3f pa = sub (p, a); + point3f ba = sub(b, a); + point3f pa = sub(p, a); - U = dot (pa, ba)/dot (ba, ba); + U = dot(pa, ba) / dot(ba, ba); if (U > 1) q = b; else if (U < 0) q = a; - else - q = blend (a, b, U); + else + q = blend(a, b, U); return dist(p, q); } + /* Calculates the parameters of a plane via given 3 points on it */ -void make_plane(point3f a,point3f b,point3f c,plane* P) +void make_plane(point3f a, point3f b, point3f c, plane * P) { - P->N.x=a.y*(b.z-c.z)+b.y*(c.z-a.z)+c.y*(a.z-b.z);//+ - P->N.y=a.z*(b.x-c.x)+b.z*(c.x-a.x)+c.z*(a.x-b.x);//+ - P->N.z=a.x*(b.y-c.y)+b.x*(c.y-a.y)+c.x*(a.y-b.y);//+ - P->d=(a.x*(b.y*c.z-c.y*b.z)+b.x*(c.y*a.z-a.y*c.z)+c.x*(a.y*b.z-b.y*a.z))*-1; + P->N.x = a.y * (b.z - c.z) + b.y * (c.z - a.z) + c.y * (a.z - b.z); //+ + P->N.y = a.z * (b.x - c.x) + b.z * (c.x - a.x) + c.z * (a.x - b.x); //+ + P->N.z = a.x * (b.y - c.y) + b.x * (c.y - a.y) + c.x * (a.y - b.y); //+ + P->d = + (a.x * (b.y * c.z - c.y * b.z) + b.x * (c.y * a.z - a.y * c.z) + + c.x * (a.y * b.z - b.y * a.z)) * -1; } -void replacestr(char *source,char **target) +void replacestr(char *source, char **target) { - if (*target) - free(*target); - *target =strdup(source); + if (*target) + free(*target); + *target = strdup(source); } + /* move a point on the great circle of it (spherical) @@ -403,50 +412,73 @@ void replacestr(char *source,char **target) #define G_PI 3.1415926535897932384626433832795028841971693993751 #define DEG2RAD G_PI/180 -int rot_spherex(plane J,double tet,point3f P,point3f* P2) +int rot_spherex(plane J, double tet, point3f P, point3f * P2) { - if (tet > 0) - { - tet=5; - tet=DEG2RAD * tet; - P2->x=(float)(J.N.x * J.N.x + cos(tet) * (1-J.N.x*J.N.x))*P.x + (J.N.x*J.N.y*(1-cos(tet)) - J.N.z*sin(tet)) - + (J.N.z * J.N.x*(1-cos(tet)) + J.N.y * sin(tet))* P.z; - P2->y=(float)(J.N.x * J.N.y*(1-cos(tet)) + J.N.z*sin(tet))*P.x + (J.N.y*J.N.y + cos(tet)*(1-J.N.y * J.N.y))* P.y - + (J.N.y*J.N.z*(1-cos(tet)) - J.N.x * sin(tet)) * P.z; - P2->z=(float)(J.N.z*J.N.x*(1-cos(tet)) - J.N.y *sin(tet))*P.x + (J.N.y*J.N.z*(1-cos(tet)) + J.N.x*sin(tet))*P.y - + (J.N.z*J.N.z+cos(tet)*(1-J.N.z*J.N.z))*P.z; - return 1; - } - else - return 0; + if (tet > 0) { + tet = 5; + tet = DEG2RAD * tet; + P2->x = + (float) (J.N.x * J.N.x + + cos(tet) * (1 - J.N.x * J.N.x)) * P.x + + (J.N.x * J.N.y * (1 - cos(tet)) - J.N.z * sin(tet)) + + (J.N.z * J.N.x * (1 - cos(tet)) + J.N.y * sin(tet)) * P.z; + P2->y = + (float) (J.N.x * J.N.y * (1 - cos(tet)) + + J.N.z * sin(tet)) * P.x + (J.N.y * J.N.y + + cos(tet) * (1 - + J.N.y * + J.N.y)) * P.y + + (J.N.y * J.N.z * (1 - cos(tet)) - J.N.x * sin(tet)) * P.z; + P2->z = + (float) (J.N.z * J.N.x * (1 - cos(tet)) - + J.N.y * sin(tet)) * P.x + (J.N.y * J.N.z * (1 - + cos(tet)) + + J.N.x * sin(tet)) * P.y + + (J.N.z * J.N.z + cos(tet) * (1 - J.N.z * J.N.z)) * P.z; + return 1; + } else + return 0; } #ifdef DEBUG -void main( void ) +void main(void) { point3f LineStart, LineEnd, Point; float Distance; - LineStart.x = 50.0f; LineStart.y = 80.0f; LineStart.z = 300.0f; - LineEnd.x = 50.0f; LineEnd.y = -800.0f; LineEnd.z = 1000.0f; - Point.x = 20.0f; Point.y = 1000.0f; Point.z = 400.0f; + LineStart.x = 50.0f; + LineStart.y = 80.0f; + LineStart.z = 300.0f; + LineEnd.x = 50.0f; + LineEnd.y = -800.0f; + LineEnd.z = 1000.0f; + Point.x = 20.0f; + Point.y = 1000.0f; + Point.z = 400.0f; - if( DistancePointLine( &Point, &LineStart, &LineEnd, &Distance ) ) - printf( "closest point falls within line segment, distance = %f\n", Distance ); + if (DistancePointLine(&Point, &LineStart, &LineEnd, &Distance)) + printf("closest point falls within line segment, distance = %f\n", + Distance); else - printf( "closest point does not fall within line segment\n" ); - - - LineStart.x = 0.0f; LineStart.y = 0.0f; LineStart.z = 50.0f; - LineEnd.x = 0.0f; LineEnd.y = 0.0f; LineEnd.z = -50.0f; - Point.x = 10.0f; Point.y = 50.0f; Point.z = 10.0f; - - if( DistancePointLine( &Point, &LineStart, &LineEnd, &Distance ) ) - printf( "closest point falls within line segment, distance = %f\n", Distance ); + printf("closest point does not fall within line segment\n"); + + + LineStart.x = 0.0f; + LineStart.y = 0.0f; + LineStart.z = 50.0f; + LineEnd.x = 0.0f; + LineEnd.y = 0.0f; + LineEnd.z = -50.0f; + Point.x = 10.0f; + Point.y = 50.0f; + Point.z = 10.0f; + + if (DistancePointLine(&Point, &LineStart, &LineEnd, &Distance)) + printf("closest point falls within line segment, distance = %f\n", + Distance); else - printf( "closest point does not fall within line segment\n" ); + printf("closest point does not fall within line segment\n"); } #endif - -- 2.40.0