From: arif Date: Tue, 10 Mar 2009 22:58:49 +0000 (+0000) Subject: restructured glcomp X-Git-Tag: LAST_LIBGRAPH~32^2~2298 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8dc67f56f94d23d26fb7b8c2f77e0a507e6c198d;p=graphviz restructured glcomp cleared more warnings --- diff --git a/cmd/smyrna/draw.c b/cmd/smyrna/draw.c index 790bc76e5..51116e480 100755 --- a/cmd/smyrna/draw.c +++ b/cmd/smyrna/draw.c @@ -455,7 +455,7 @@ static void SetFont(xdot_op * op, int param) { //activate the right font view->fontset->activefont=add_font(view->fontset,op->u.font.name);//load or set active font - view->FontSize = (int) op->u.font.size; + view->FontSize = op->u.font.size; } static void InsertImage(xdot_op * op, int param) @@ -480,8 +480,8 @@ static void EmbedText(xdot_op * op, int param) if (param == 1) //selected fontColor(view->fontset->fonts[view->fontset->activefont],view->selectedNodeColor.R, view->selectedNodeColor.G, view->selectedNodeColor.B); - fontDrawString(view->fontset->fonts[view->fontset->activefont],(int) (x - dx), op->u.text.y - (int) dy, - op->u.text.width, op->u.text.text); + fontDrawString(view->fontset->fonts[view->fontset->activefont], (x - dx), (GLfloat)op->u.text.y - dy, + (GLfloat)op->u.text.width, op->u.text.text); } void draw_selection_box(ViewInfo * view) @@ -648,7 +648,7 @@ static void drawXdot(xdot * xDot, int param, void *p) for (id = 0; id < xDot->cnt; id++) { - globalz += GLOBAL_Z_OFFSET; + globalz += (float)GLOBAL_Z_OFFSET; op = ops + id; op->obj = p; op->op.drawfunc(&(op->op), param); @@ -879,9 +879,9 @@ int draw_node_hintbox_gl_polygon(GLfloat x,GLfloat y,GLfloat z,GLfloat fs,char* { - float X,Y,Z,pad; - pad=fs/5.0; - X=x;Y=y;Z=z+0.0005; + GLfloat X,Y,Z,pad; + pad=fs/(GLfloat)5.0; + X=x;Y=y;Z=z+(GLfloat)0.0005; glBegin(GL_POLYGON); glVertex3f(X,Y,Z); Y=Y + fs; @@ -897,7 +897,7 @@ int draw_node_hintbox_gl_polygon(GLfloat x,GLfloat y,GLfloat z,GLfloat fs,char* glVertex3f(X,Y,Z); X=x;Y=Y+fs+2*pad; glVertex3f(X,Y,Z); - X=x+strlen(text)*fs/2.0+2.0*pad; + X=x+strlen(text)*fs/(GLfloat)2.0+(GLfloat)2.0*pad; glVertex3f(X,Y,Z); Y=y+fs; glVertex3f(X,Y,Z); @@ -913,14 +913,14 @@ int draw_node_hintbox_gl_line(GLfloat x,GLfloat y,GLfloat z,GLfloat fs,char* tex { - float X,Y,Z,pad; - pad=fs/5.0; - X=x;Y=y;Z=z+0.001; + GLfloat X,Y,Z,pad; + pad=fs/(GLfloat)5.0; + X=x;Y=y;Z=z+(GLfloat)0.001; glBegin(GL_LINE_STRIP); glVertex3f(X,Y,Z); Y=Y + 2*fs+2*pad; glVertex3f(X,Y,Z); - X=X+2*pad+strlen(text)*fs/2.0; + X=X+2*pad+strlen(text)*fs/(GLfloat)2.0; glVertex3f(X,Y,Z); Y=y+fs; glVertex3f(X,Y,Z); diff --git a/cmd/smyrna/glmotion.c b/cmd/smyrna/glmotion.c index ee8b08db2..020b999e5 100644 --- a/cmd/smyrna/glmotion.c +++ b/cmd/smyrna/glmotion.c @@ -46,8 +46,8 @@ int glmotion_main(ViewInfo * v,GdkEventMotion * event,GtkWidget * widget) && ((v->mouse.mouse_mode == MM_MAGNIFIER) || (v->mouse.mouse_mode == MM_FISHEYE_MAGNIFIER))) { - v->mouse.mouse_X = event->x; - v->mouse.mouse_Y = event->y; + v->mouse.mouse_X = (float)event->x; + v->mouse.mouse_Y = (float)event->y; redraw = TRUE; } diff --git a/cmd/smyrna/gltemplate.c b/cmd/smyrna/gltemplate.c index 123a23530..b5dd952e9 100755 --- a/cmd/smyrna/gltemplate.c +++ b/cmd/smyrna/gltemplate.c @@ -236,6 +236,21 @@ gboolean expose_event(GtkWidget * widget, GdkEventExpose * event, return TRUE; } +static gboolean key_release_event(GtkWidget * widget, + GdkEventButton * event, gpointer data) +{ + printf ("a key is released\n"); + +} + +static gboolean key_press_event(GtkWidget * widget, GdkEventKey * event, + gpointer data) +{ + printf ("a key is pressed\n"); + +} + + /* when a mouse button is clicked this function is called params:gtk opgn gl canvas , GdkEventButton object and custom data @@ -583,7 +598,7 @@ void create_window(GdkGLConfig * glconfig, GtkWidget * vbox) // GDK_BUTTON_MOTION_MASK = 1 << 4, GDK_BUTTON_MOTION_MASK | GDK_POINTER_MOTION_MASK| - GDK_BUTTON_PRESS_MASK | + GDK_BUTTON_PRESS_MASK |GDK_KEY_PRESS | GDK_BUTTON_RELEASE_MASK | GDK_VISIBILITY_NOTIFY_MASK); @@ -598,7 +613,11 @@ void create_window(GdkGLConfig * glconfig, GtkWidget * vbox) G_CALLBACK(button_press_event), NULL); g_signal_connect(G_OBJECT(view->drawing_area), "button_release_event", G_CALLBACK(button_release_event), NULL); - g_signal_connect(G_OBJECT(view->drawing_area), "motion_notify_event", + g_signal_connect(G_OBJECT(view->drawing_area), "key_release_event", + G_CALLBACK(button_release_event), NULL); + g_signal_connect(G_OBJECT(view->drawing_area), "key_press_event", + G_CALLBACK(button_release_event), NULL); + g_signal_connect(G_OBJECT(view->drawing_area), "motion_notify_event", G_CALLBACK(motion_notify_event), NULL); diff --git a/cmd/smyrna/selection.c b/cmd/smyrna/selection.c index 3ed973b81..0fbe84b25 100755 --- a/cmd/smyrna/selection.c +++ b/cmd/smyrna/selection.c @@ -1033,7 +1033,7 @@ int point_within_sphere_with_coords(float x0, float y0, float z0, float r, float distance_to_line(float ax,float ay,float bx,float by,float cx,float cy) { //this function returns the distance between a line(a-b) segment and a point(c) in 2D plane - return sqrt( + return (float)sqrt( pow(((by-ay)*(cx-ax)+(bx-ax)*(cy-ay)),2) / ( pow((bx-ax),2) + pow((by-ay),2)) diff --git a/cmd/smyrna/topfisheyeview.c b/cmd/smyrna/topfisheyeview.c index 05e032b1d..49abf8353 100644 --- a/cmd/smyrna/topfisheyeview.c +++ b/cmd/smyrna/topfisheyeview.c @@ -230,7 +230,6 @@ void prepare_topological_fisheye(topview* t) Hierarchy *hp; ex_vtx_data *gg; topview_node *np; - char buf[512]; v_data *graph = makeGraph(t, &ne); @@ -302,7 +301,7 @@ void printalllevels(topview* t) void drawtopfishnodes(topview * t) { - int level, v, i, n; + int level, v; Hierarchy *hp = t->h; @@ -333,8 +332,8 @@ void drawtopfishnodes(topview * t) continue; if (level !=0) - glColor4f((GLfloat) (hp->nlevels - level)*0.5 / (GLfloat) hp->nlevels, - (GLfloat) level / (GLfloat) hp->nlevels, 0,view->defaultnodealpha); + glColor4f((GLfloat) (hp->nlevels - level)*(GLfloat)0.5 / (GLfloat) hp->nlevels, + (GLfloat) level / (GLfloat) hp->nlevels, (GLfloat)0,(GLfloat)view->defaultnodealpha); else glColor4f((GLfloat) 1, (GLfloat) level / (GLfloat) hp->nlevels*2, 0,view->defaultnodealpha); @@ -351,7 +350,7 @@ void drawtopfishnodes(topview * t) } void drawtopfishnodelabels(topview* t) { - int v, i, n,finenodes,focusnodes; + int v, finenodes,focusnodes; char buf[512]; char* str; float fs = view->FontSizeConst; @@ -375,18 +374,17 @@ void drawtopfishnodelabels(topview* t) if((v==t->fs->foci_nodes[0]) &&(focusnodes)) { - fs=view->FontSizeConst*1.4; - fontColorA(view->fontset->fonts[view->fontset->activefont],0, 0, 1, 1); + fs=view->FontSizeConst*(float)1.4; + fontColorA(view->fontset->fonts[view->fontset->activefont],(float)0, (float)0, (float)1, (float)1); fontSize(view->fontset->fonts[view->fontset->activefont],fs); - fontDrawString(view->fontset->fonts[view->fontset->activefont],gg[v].physical_x_coord,gg[v].physical_y_coord, (fs*strlen(buf)*0.4),buf); - printf ("focus coords : %f , %f\n",gg[v].physical_x_coord,gg[v].physical_y_coord); + fontDrawString(view->fontset->fonts[view->fontset->activefont],gg[v].physical_x_coord,gg[v].physical_y_coord, (fs*strlen(buf)*(GLfloat)0.4),buf); } else if (finenodes) { fs=view->FontSizeConst; fontColorA(view->fontset->fonts[view->fontset->activefont],0, 0, 0, 1); fontSize(view->fontset->fonts[view->fontset->activefont],fs); - fontDrawString(view->fontset->fonts[view->fontset->activefont],gg[v].physical_x_coord,gg[v].physical_y_coord, (fs*strlen(buf)*0.4),buf); + fontDrawString(view->fontset->fonts[view->fontset->activefont],gg[v].physical_x_coord,gg[v].physical_y_coord, (fs*strlen(buf)*(GLfloat)0.4),buf); } } @@ -414,7 +412,7 @@ void drawtopfishedges(topview * t) double x, y; n = g[v].edges[i]; if (level !=0) - glColor4f((GLfloat) (hp->nlevels - level)*0.5 / (GLfloat) hp->nlevels, + glColor4f((GLfloat) (hp->nlevels - level)*(GLfloat)0.5 / (GLfloat) hp->nlevels, (GLfloat) level / (GLfloat) hp->nlevels, 0,view->defaultedgealpha); else glColor4f((GLfloat) 1, @@ -672,7 +670,7 @@ int get_active_frame(topview* t) void drawtopologicalfisheyestatic(topview * t) { - int level, v, i, n; + int level, v; Hierarchy* hp = t->h; glPointSize(15); @@ -680,12 +678,12 @@ void drawtopologicalfisheyestatic(topview * t) for (level=0;level < hp->nlevels;level++) { for (v=0;v < hp->nvtxs[level]; v++) { ex_vtx_data* gg = hp->geom_graphs[level]; - vtx_data* g = hp->graphs[level]; + v_data* g = hp->graphs[level]; if(gg[v].active_level==level) { double x0 = gg[v].physical_x_coord; double y0 = gg[v].physical_y_coord; // glColor3f((GLfloat)(hp->nlevels-level)/(GLfloat)hp->nlevels,(GLfloat)level/(GLfloat)hp->nlevels,0); - glColor4f(0,1,0,0.2); + glColor4f((GLfloat)0,(GLfloat)1,(GLfloat)0,(GLfloat)0.2); glVertex3f((GLfloat)x0,(GLfloat)y0,(GLfloat)0); } } diff --git a/cmd/smyrna/topview.c b/cmd/smyrna/topview.c index 0fc655f1c..28955c5f5 100755 --- a/cmd/smyrna/topview.c +++ b/cmd/smyrna/topview.c @@ -17,6 +17,9 @@ #include "glTexFontTGA.h" #include "glTexFontDefs.h" #include "glTexFontInclude.h" +#include "glcompbutton.h" +#include "glcomppanel.h" +#include "glcomplabel.h" #include "gltemplate.h" #include "topview.h" #include "math.h" @@ -79,7 +82,7 @@ void preparetopview(Agraph_t * g, topview * t) int maxlabelsize=0; float maxedgelen,minedgelen,len,edgelength; maxedgelen=0; - minedgelen=99999999; //FIX ME if you have a giant graph or fix your graph + minedgelen=99999999.00000; //FIX ME if you have a giant graph or fix your graph edgelength=0; ind = 0; @@ -164,7 +167,7 @@ void preparetopview(Agraph_t * g, topview * t) t->Nodes[ind].Label2 = '\0'; if (t->Nodes[ind].Label) - maxlabelsize = maxlabelsize + strlen(t->Nodes[ind].Label); + maxlabelsize = maxlabelsize + (int)strlen(t->Nodes[ind].Label); for (e = agfstout(g, v); e; e = agnxtout(g, e)) { @@ -1441,11 +1444,11 @@ static glCompSet *glcreate_gl_topview_menu(void) */ //small panel left bottom - p = glCompPanelNew(25, 25, 325, 40); + p = glCompPanelNew(25, 25, 325, 40,scientific_y); p->data = 0; glCompSetAddPanel(s, p); - b = glCompButtonNew(5, 7, 75, 25, "BROWSE", '\0', 0, 0); + b = glCompButtonNew(5, 7, 75, 25, "BROWSE", '\0', 0, 0,scientific_y); b->panel = p; b->groupid = 1; b->customptr = view; @@ -1453,7 +1456,7 @@ static glCompSet *glcreate_gl_topview_menu(void) b->callbackfunc = menu_click_control; - b = glCompButtonNew(85, 7, 75, 25, "SHOW", '\0', 0, 0); + b = glCompButtonNew(85, 7, 75, 25, "SHOW", '\0', 0, 0,scientific_y); b->panel = p; b->customptr = view; b->groupid = 1; @@ -1461,14 +1464,14 @@ static glCompSet *glcreate_gl_topview_menu(void) glCompSetAddButton(s, b); - b = glCompButtonNew(165, 7, 75, 25, "CAMERAS", '\0', 0, 0); + b = glCompButtonNew(165, 7, 75, 25, "CAMERAS", '\0', 0, 0,scientific_y); b->customptr = view; b->panel = p; b->groupid = 1; b->callbackfunc = menu_click_3d_view; glCompSetAddButton(s, b); - b = glCompButtonNew(245, 7, 75, 25, "HIDE", '\0', 0, 0); + b = glCompButtonNew(245, 7, 75, 25, "HIDE", '\0', 0, 0,scientific_y); b->color.R = 1; b->customptr = view; b->panel = p; @@ -1476,14 +1479,18 @@ static glCompSet *glcreate_gl_topview_menu(void) b->callbackfunc = menu_click_hide; glCompSetAddButton(s, b); + //Fisheye control panel +// p = glCompPanelNew( 25, view->h-40, 165, 40,scientific_y); + // p->data = 1; //control panel + // glCompSetAddPanel(s, p); - //control panel - p = glCompPanelNew(25, 75, 165, 277); + //control panel + p = glCompPanelNew(25, 75, 165, 277,scientific_y); p->data = 1; //control panel glCompSetAddPanel(s, p); //view mode normal button - b = glCompButtonNew(5, 7, 75, 25, "NORMAL", '\0', 0, 0); + b = glCompButtonNew(5, 7, 75, 25, "NORMAL", '\0', 0, 0,scientific_y); b->color.R = 0; b->color.G = 1; b->color.B = (float) 0.1; @@ -1494,7 +1501,7 @@ static glCompSet *glcreate_gl_topview_menu(void) glCompSetAddButton(s, b); //view mode fisheye button - b = glCompButtonNew(85, 7, 75, 25, "FISHEYE", '\0', 0, 0); + b = glCompButtonNew(85, 7, 75, 25, "FISHEYE", '\0', 0, 0,scientific_y); b->color.R = 0; b->color.G = 1; b->color.B = (float) 0.1; @@ -1505,33 +1512,33 @@ static glCompSet *glcreate_gl_topview_menu(void) glCompSetAddButton(s, b); //rotate - b = glCompButtonNew(5, 197, 72, 72, "", smyrna_icon_rotate, 72, 72); + b = glCompButtonNew(5, 197, 72, 72, "", smyrna_icon_rotate, 72, 72,scientific_y); b->groupid = 3; b->customptr = view; b->panel = p; b->callbackfunc = menu_click_rotate; glCompSetAddButton(s, b); - b = glCompButtonNew(80, 251, 40, 20, "X", '\0', 0, 0); + b = glCompButtonNew(80, 251, 40, 20, "X", '\0', 0, 0,scientific_y); b->customptr = view; b->panel = p; b->groupid = 1; b->callbackfunc = menu_click_rotate_x; glCompSetAddButton(s, b); - b = glCompButtonNew(125, 251, 40, 20, "Y", '\0', 0, 0); + b = glCompButtonNew(125, 251, 40, 20, "Y", '\0', 0, 0,scientific_y); b->customptr = view; b->panel = p; b->groupid = 1; b->callbackfunc = menu_click_rotate_y; glCompSetAddButton(s, b); - b = glCompButtonNew(80, 231, 40, 20, "XY", '\0', 0, 0); + b = glCompButtonNew(80, 231, 40, 20, "XY", '\0', 0, 0,scientific_y); b->customptr = view; b->panel = p; b->groupid = 1; b->callbackfunc = menu_click_rotate_xy; glCompSetAddButton(s, b); - b = glCompButtonNew(125, 231, 40, 20, "Z", '\0', 0, 0); + b = glCompButtonNew(125, 231, 40, 20, "Z", '\0', 0, 0,scientific_y); b->customptr = view; b->panel = p; b->groupid = 1; @@ -1539,7 +1546,7 @@ static glCompSet *glcreate_gl_topview_menu(void) glCompSetAddButton(s, b); //sanity button to center the drawing and fit it in the screen - b = glCompButtonNew(80, 201, 90, 20, "center", '\0', 0, 0); + b = glCompButtonNew(80, 201, 90, 20, "center", '\0', 0, 0,scientific_y); b->customptr = view; b->panel = p; b->groupid = 0; @@ -1554,7 +1561,7 @@ static glCompSet *glcreate_gl_topview_menu(void) //pan button b = glCompButtonNew(5, 120, 72, 72, "adasasds", smyrna_icon_pan, 72, - 72); + 72,scientific_y); b->groupid = 3; b->customptr = view; b->panel = p; @@ -1562,7 +1569,7 @@ static glCompSet *glcreate_gl_topview_menu(void) glCompSetAddButton(s, b); //zoom b = glCompButtonNew(85, 120, 72, 72, "adasasds", smyrna_icon_zoom, 72, - 72); + 72,scientific_y); b->groupid = 3; b->customptr = view; b->panel = p; @@ -1570,7 +1577,7 @@ static glCompSet *glcreate_gl_topview_menu(void) glCompSetAddButton(s, b); //zoom + b = glCompButtonNew(85, 82, 36, 36, "adasasds", smyrna_icon_zoomplus, - 36, 36); + 36, 36,scientific_y); b->groupid = 0; b->customptr = view; b->panel = p; @@ -1578,7 +1585,7 @@ static glCompSet *glcreate_gl_topview_menu(void) glCompSetAddButton(s, b); //zoom - b = glCompButtonNew(121, 82, 36, 36, "adasasds", smyrna_icon_zoomminus, - 36, 36); + 36, 36,scientific_y); b->groupid = 0; b->panel = p; b->customptr = view; @@ -1586,19 +1593,19 @@ static glCompSet *glcreate_gl_topview_menu(void) glCompSetAddButton(s, b); b = glCompButtonNew(5, 45, 72, 72, "adasasds", smyrna_icon_fisheye, 72, - 72); + 72,scientific_y); b->groupid = 3; b->panel = p; b->customptr = view; b->callbackfunc = menu_click_fisheye_magnifier; glCompSetAddButton(s, b); //zoom percantage label - l = glCompLabelNew(100, 45, 24, "100"); + l = glCompLabelNew(100, 45, 24, "100",scientific_y); l->panel = p; l->fontsizefactor = (float) 0.4; glCompSetAddLabel(s, l); view->Topview->customptr = l; - l = glCompLabelNew(93, 65, 20, "zoom"); + l = glCompLabelNew(93, 65, 20, "zoom",scientific_y); l->panel = p; l->fontsizefactor = (float) 0.4; glCompSetAddLabel(s, l); diff --git a/cmd/smyrna/viewportcamera.c b/cmd/smyrna/viewportcamera.c index b2562608f..c374d886b 100644 --- a/cmd/smyrna/viewportcamera.c +++ b/cmd/smyrna/viewportcamera.c @@ -17,6 +17,10 @@ #include "gui.h" #include "math.h" #include "memory.h" +#include "glcompbutton.h" +#include "glcomplabel.h" +#include "glcomppanel.h" + static viewport_camera *new_viewport_camera(ViewInfo * view) { @@ -195,13 +199,13 @@ void attach_camera_widget(ViewInfo * view) /*container for camera buttons */ p = glCompPanelNew((GLfloat) 25, (GLfloat) 75, (GLfloat) 4 * PANEL_PADDING + - 3 * CAMERA_BUTTON_WIDTH, (GLfloat) p_height); + 3 * CAMERA_BUTTON_WIDTH, (GLfloat) p_height,scientific_y); p->data = 3; glCompSetAddPanel(s, p); b = glCompButtonNew((GLfloat) PANEL_PADDING, (GLfloat) PANEL_PADDING, (GLfloat) CAMERA_BUTTON_WIDTH, - (GLfloat) CAMERA_BUTTON_HEIGHT, "ADD", '\0', 0, 0); + (GLfloat) CAMERA_BUTTON_HEIGHT, "ADD", '\0', 0, 0,scientific_y); b->panel = p; b->groupid = 0; b->customptr = view; @@ -212,7 +216,7 @@ void attach_camera_widget(ViewInfo * view) (GLfloat) CAMERA_BUTTON_WIDTH, (GLfloat) PANEL_PADDING, (GLfloat) CAMERA_BUTTON_WIDTH, - (GLfloat) CAMERA_BUTTON_HEIGHT, "2D", '\0', 0, 0); + (GLfloat) CAMERA_BUTTON_HEIGHT, "2D", '\0', 0, 0,scientific_y); b->panel = p; b->groupid = 4; //4 is assigned to all camera buttons b->customptr = view; @@ -228,7 +232,7 @@ void attach_camera_widget(ViewInfo * view) sprintf(buf, "CAM%i", ind + 1); b = glCompButtonNew((GLfloat)x, (GLfloat)y, (GLfloat) CAMERA_BUTTON_WIDTH, (GLfloat) CAMERA_BUTTON_HEIGHT, buf, '\0', 0, - 0); + 0,scientific_y); b->panel = p; b->groupid = 4; //4 is assigned to all camera buttons b->data = ind; //assign camera id to custom data to use single call back @@ -239,7 +243,7 @@ void attach_camera_widget(ViewInfo * view) x = PANEL_PADDING * 2 + CAMERA_BUTTON_WIDTH; b = glCompButtonNew((GLfloat)x,(GLfloat) y, (GLfloat) CAMERA_BUTTON_WIDTH, (GLfloat) CAMERA_BUTTON_HEIGHT, "Remove", '\0', - 0, 0); + 0, 0,scientific_y); b->panel = p; b->groupid = 0; b->data = ind; //assign camera id to custom data to use single call back @@ -251,7 +255,7 @@ void attach_camera_widget(ViewInfo * view) b = glCompButtonNew((GLfloat) x, (GLfloat) y, (GLfloat) CAMERA_BUTTON_WIDTH, (GLfloat) CAMERA_BUTTON_HEIGHT, "Edit", '\0', - 0, 0); + 0, 0,scientific_y); b->panel = p; b->groupid = 0; b->data = ind; //assign camera id to custom data to use single call back diff --git a/lib/glcomp/glCompTrackBar.c b/lib/glcomp/glCompTrackBar.c new file mode 100644 index 000000000..4e5b29686 --- /dev/null +++ b/lib/glcomp/glCompTrackBar.c @@ -0,0 +1,25 @@ +#include "glcomptrackbar.h" + +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; + 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->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->font=font_init(); +} diff --git a/lib/glcomp/glCompTrackBar.h b/lib/glcomp/glCompTrackBar.h new file mode 100644 index 000000000..77f00d55d --- /dev/null +++ b/lib/glcomp/glCompTrackBar.h @@ -0,0 +1,9 @@ +#ifndef GLCOMPTRACKBAR_H +#define GLCOMPTRACKBAR_H + +#include "glcompdefs.h" + + + + +#endif diff --git a/lib/glcomp/glTexFont.c b/lib/glcomp/glTexFont.c index 798057418..d3df30643 100755 --- a/lib/glcomp/glTexFont.c +++ b/lib/glcomp/glTexFont.c @@ -138,16 +138,7 @@ void fontScissorNormal (texFont_t* font,int xpos, int ypos, int tabs, int carrag } /* ============= -fontScissorTextRegion -Scissor region used setup for a text region. -============= -*/ -void fontScissorTextRegion (texFont_t* font) -{ - glScissor (font->regionX, font->regionY, font->regionW, font->regionH); -} -/* ============= fontFgColorReset @@ -210,7 +201,7 @@ fontRegion Sets up a font region. Only good for one fontDrawString. ============= */ -void fontRegion (texFont_t* font,int x, int y, int w, int h) +void fontRegion (texFont_t* font,float x, float y, float w, float h) { font->region = 1; font->regionX = x; @@ -268,8 +259,8 @@ void fontRenderChar (texFont_t* font,char c, GLfloat x, GLfloat y, GLfloat size) if (font->shadow) { if (!font->bold) - fontDrawChar (font,c, x + 1.0, y + 1.0, size, 1); - else fontDrawChar (font,c, x + 2.0, y + 1.0, size, 1); + fontDrawChar (font,c, x + (GLfloat)1.0, y + (GLfloat)1.0, size, 1); + else fontDrawChar (font,c, x + (GLfloat)2.0, y + (GLfloat)1.0, size, 1); } @@ -277,7 +268,7 @@ void fontRenderChar (texFont_t* font,char c, GLfloat x, GLfloat y, GLfloat size) fontDrawChar (font,c, x, y, size, 0); if (font->bold) - fontDrawChar (font,c, x + 1.0, y, size, 0); + fontDrawChar (font,c, x + (GLfloat)1.0, y, size, 0); } /* ============= @@ -339,8 +330,8 @@ void fontWalkString (texFont_t* font,char *buffPtr, GLfloat xpos, GLfloat ypos, GLfloat charGap; xMax = vPort[0] + vPort[2]; - carrage = fontGetCharHits (buffPtr, '\n'); - tabs = fontGetCharHits (buffPtr, '\t'); + carrage = (GLfloat) fontGetCharHits (buffPtr, '\n'); + tabs = (GLfloat) fontGetCharHits (buffPtr, '\t'); if (!tabs) tabs = 1; @@ -797,12 +788,12 @@ fontset_t* fontset_init() } static char* fontpath = NULL; -static int fontpathsz = 0; +static size_t fontpathsz = 0; int add_font(fontset_t* fontset,char* fontdesc) { int id; - int sz; + size_t sz; texFont_t* tf; id=fontId(fontset,fontdesc); diff --git a/lib/glcomp/glTexFont.h b/lib/glcomp/glTexFont.h index 8290904e8..26ae2c98b 100755 --- a/lib/glcomp/glTexFont.h +++ b/lib/glcomp/glTexFont.h @@ -23,6 +23,7 @@ typedef float GLfloat; #include #include #endif +#include "glcompdefs.h" /* Error Codes */ #define FONT_FILE_NOT_FOUND -13 /* file was not found */ @@ -36,38 +37,6 @@ typedef float GLfloat; typedef float vec2_t[2]; #endif -typedef struct -{ - float fgColor[4]; /* foreground color, default white */ - float gdColor[4]; /* gradient color, default gray */ - float bgColor[4]; /* background color, default gray */ - float size; /* size of text, default 12 */ - int shadow; /* shadow text? default 0 */ - int gradient; /* gradient? default 0 */ - int italic; /* italic amount, defaul 0 */ - int bold; /* bold text? */ - int region; /* do we have a text region */ - float regionX; /* lower left x */ - float regionY; /* lower left y */ - float regionW; /* text region w */ - float regionH; /* text region h */ - float tIncX; /* used for texture coords, x axis amount to move */ - float tIncY; /* used for texture coords, y axis amount to move */ - int blockRow; /* characters per row */ - int blockCol; /* characters per col */ - unsigned int texId; /* texture id */ - float zdepth; //third dimension , depth of fonts - char* fontdesc; //font description -} texFont_t; - - -typedef struct -{ - texFont_t** fonts; - int count; - int activefont; - char* font_directory; //location where the glfont files are stored -}fontset_t; #ifdef __cplusplus extern "C" { @@ -127,7 +96,7 @@ Sets up a font region. Upper left corner is described by (xpos, ypos). The region is w units wide and h units tall. ============= */ -void fontRegion (texFont_t* font,int xpos, int ypos, int w, int h); +void fontRegion (texFont_t* font,float xpos, float ypos, float w, float h); /* ============= fontSize diff --git a/lib/glcomp/glTexFontDefs.h b/lib/glcomp/glTexFontDefs.h index 2db027fad..2bc0806ca 100755 --- a/lib/glcomp/glTexFontDefs.h +++ b/lib/glcomp/glTexFontDefs.h @@ -1,28 +1,3 @@ -/* - Copyright (c) 1999 Nate Miller - - Notice: Usage of any code in this file is subject to the rules - described in the LICENSE.TXT file included in this directory. - Reading, compiling, or otherwise using this code constitutes - automatic acceptance of the rules in said text file. - - File -- glTexFontDefs.h - Date -- 5/31/99 - Author -- Nate 'm|d' Miller - Contact -- vandals1@home.com - Web -- http://members.home.com/vandals1 - - All functions are called internally by the library, These should never be - called from anywhere but INSIDE the library. Versy messy but doesn't - matter all that much. -*/ -/* - FONT_BLOCK_COL, FONT_BLOCK_ROW - - Number of characters per row and per col in the font map. - FONT_BLOCK_COL * FONT_BLOCK_ROW must equal 256. If it doesn't the library - will fail to work properly. Why 256? Chars range from 0 to 255. -*/ #define FONT_BLOCK_COL 16 #define FONT_BLOCK_ROW 16 #define FONT_GET_MODES 1 @@ -33,7 +8,6 @@ #define FONT_ITALIC 8 /* italic amount in pixels */ #define fontColorCopy(a,b) {b[0]= a[0]; b[1]= a[1]; b[2]= a[2]; b[3]= a[3];} /* copys colors */ -/* various functions used by the library, see texFont.c for info */ void fontDrawChar (texFont_t* font,char c, GLfloat x, GLfloat y, GLfloat size, int shadow); void fontScissorNormal (texFont_t* font,int xpos, int ypos, int tabs, int carrage, int size, int len); int fontSetColorFromToken (texFont_t* font,char *s); @@ -41,7 +15,6 @@ int fontGetCharHits (char *s, char f); void fontMakeMap (texFont_t* font); void fontSetModes (int state); void fontReset (texFont_t* font); -void fontScissorTextRegion (texFont_t* font); int fontItalicsMode (texFont_t* font,char *s); int fontBoldMode (texFont_t* font,char *s); void fontRenderChar (texFont_t* font,char c, GLfloat x, GLfloat y, GLfloat size); diff --git a/lib/glcomp/glTexFontInclude.h b/lib/glcomp/glTexFontInclude.h index 94fbfcf39..aac45e968 100755 --- a/lib/glcomp/glTexFontInclude.h +++ b/lib/glcomp/glTexFontInclude.h @@ -1,18 +1,4 @@ -/* - Copyright (c) 1999 Nate Miller - - Notice: Usage of any code in this file is subject to the rules - described in the LICENSE.TXT file included in this directory. - Reading, compiling, or otherwise using this code constitutes - automatic acceptance of the rules in said text file. - File -- glTexFontInclude.h - Date -- 6/12/99 - Author -- Nate 'm|d' Miller - Contact -- vandals1@home.com - Web -- http://members.home.com/vandals1 -*/ -/* just generic headers to include, nothing fancy */ #include #include #include diff --git a/lib/glcomp/glTexFontTGA.c b/lib/glcomp/glTexFontTGA.c index 506f39043..09973ef48 100755 --- a/lib/glcomp/glTexFontTGA.c +++ b/lib/glcomp/glTexFontTGA.c @@ -52,7 +52,7 @@ unsigned char *fontGetRGBA (FILE *s, int size) { unsigned char *rgba; unsigned char temp; - int bread; + size_t bread; int i; rgba = malloc (size * 4); @@ -86,11 +86,11 @@ fontGetRGB Reads in RGB data for a 24bit image. ============= */ -unsigned char *fontGetRGB (FILE *s, int size) +unsigned char *fontGetRGB (FILE *s, size_t size) { unsigned char *rgb; unsigned char temp; - int bread; + size_t bread; int i; rgb = malloc (size * 3); @@ -98,7 +98,7 @@ unsigned char *fontGetRGB (FILE *s, int size) if (rgb == NULL) return 0; - bread = fread (rgb, sizeof (unsigned char), size * 3, s); + bread = fread (rgb, sizeof (unsigned char), size * (size_t) 3, s); if (bread != size * 3) { @@ -107,7 +107,7 @@ unsigned char *fontGetRGB (FILE *s, int size) } /* TGA is stored in BGR, make it RGB */ - for (i = 0; i < size * 3; i += 3) + for (i = 0; i < (int)size * 3; i += 3) { temp = rgb[i]; rgb[i] = rgb[i + 2]; @@ -128,7 +128,7 @@ Reads a gray scale image. unsigned char *fontGetGray (FILE *s, int size) { unsigned char *grayData; - int bread; + size_t bread; grayData = malloc (size); @@ -304,9 +304,9 @@ unsigned char *load_png_font(char* file_name,int *imageWidth,int *imageHeight) b0=-1;b1=-1;b2=-1;b3=-1; - for (i=0; i < info_ptr->height; i++) + for (i=0; i < (int)info_ptr->height; i++) { - for (ii=0;ii < png_get_rowbytes(png_ptr, info_ptr); ii=ii+pixeloffset) + 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]; diff --git a/lib/glcomp/glcomp.vcproj b/lib/glcomp/glcomp.vcproj index 323620580..1ab84b88d 100644 --- a/lib/glcomp/glcomp.vcproj +++ b/lib/glcomp/glcomp.vcproj @@ -147,6 +147,14 @@ Filter="h;hpp;hxx;hm;inl;inc;xsd" UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}" > + + + + @@ -155,6 +163,10 @@ RelativePath=".\glcomptexture.h" > + + @@ -191,6 +203,18 @@ Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx" UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}" > + + + + + + @@ -199,6 +223,10 @@ RelativePath=".\glcomptexture.c" > + + diff --git a/lib/glcomp/glcompbutton.c b/lib/glcomp/glcompbutton.c new file mode 100644 index 000000000..d1454f1cd --- /dev/null +++ b/lib/glcomp/glcompbutton.c @@ -0,0 +1,275 @@ +#include "glcompbutton.h" +#include "glcomptexture.h" +#include "glTexFont.h" + +glCompButton *glCompButtonNew(GLfloat x, GLfloat y, GLfloat w, GLfloat h, + char *caption, char *glyphfile, + int glyphwidth, int glyphheight,glCompOrientation orientation) +{ + 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->orientation=orientation; + p->callbackfunc = '\0'; + p->panel = '\0'; + p->customptr = '\0'; + p->font = font_init(); + + 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; + if (p->font->texId==-1) //no font has been set yet + copy_font((p->font),(s->font)); + 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]; + } + if (found) { + free(p->font); + 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 / (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; + } + 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.G * color_fac, + p->color.B * 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.G / color_fac, + p->color.B / 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 * (GLfloat) 2 - + p->fontsize * strlen(p->caption) * + GLCOMPSET_FONT_SIZE_FACTOR) / (GLfloat) 2.0 + p->pos.x + + p->thickness; + fonty = + (p->height - p->thickness * (GLfloat) 2 - + p->fontsize) / (GLfloat) 2.0 + p->pos.y + p->thickness; + fontSize(p->font,p->fontsize); +// fontColorA (p->fontcolor.R,p->fontcolor.B,p->fontcolor.G,p->fontcolor.A); + fontColorA(p->font,0, 0, 0, 1); + fontDrawString(p->font,(GLfloat) fontx, (GLfloat) fonty, + (p->fontsize *(GLfloat) strlen(p->caption) * + GLCOMPSET_FONT_SIZE_FACTOR), 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 - p->thickness * (GLfloat) 2 - + p->glyphheight) / (GLfloat) 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.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 = p->pos.x - p->panel->pos.x; + p->pos.y = p->pos.y - p->panel->pos.y; + } + + return 1; + + +} +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); + + +} + + diff --git a/lib/glcomp/glcompbutton.h b/lib/glcomp/glcompbutton.h new file mode 100644 index 000000000..0931958a1 --- /dev/null +++ b/lib/glcomp/glcompbutton.h @@ -0,0 +1,15 @@ +#ifndef GLCOMPBUTTON_H +#define GLCOMPBUTTON_H + +#include "glcompdefs.h" + + +extern glCompButton *glCompButtonNew(GLfloat x, GLfloat y, GLfloat w, GLfloat h,char *caption, char *glyphfile,int glyphwidth, int glyphheight,glCompOrientation orientation); +extern int glCompSetAddButton(glCompSet * s, glCompButton * p); +extern int glCompSetRemoveButton(glCompSet * s, glCompButton * p); +extern int glCompDrawButton(glCompButton * p); +extern void glCompButtonClick(glCompButton * p); + + + +#endif diff --git a/lib/glcomp/glcompdefs.h b/lib/glcomp/glcompdefs.h new file mode 100644 index 000000000..c57d9e6bb --- /dev/null +++ b/lib/glcomp/glcompdefs.h @@ -0,0 +1,192 @@ +#ifndef GLCOMPDEFS_H +#define GLCOMPDEFS_H + +#ifdef _WIN32 +#include "windows.h" +#endif +#include +#include +#include +#ifdef WIN32 +#define strdup _strdup +#endif + + +#define GLCOMPSET_PANEL_COLOR_R (GLfloat)0.16 +#define GLCOMPSET_PANEL_COLOR_G (GLfloat)0.44 +#define GLCOMPSET_PANEL_COLOR_B (GLfloat)0.87 +#define GLCOMPSET_PANEL_COLOR_ALPHA (GLfloat)0.5 +#define GLCOMPSET_PANEL_SHADOW_COLOR_R (GLfloat)0 +#define GLCOMPSET_PANEL_SHADOW_COLOR_G (GLfloat)0 +#define GLCOMPSET_PANEL_SHADOW_COLOR_B (GLfloat)0 +#define GLCOMPSET_PANEL_SHADOW_COLOR_A (GLfloat)0.3 +#define GLCOMPSET_PANEL_SHADOW_WIDTH (GLfloat)4 + +#define GLCOMPSET_BUTTON_COLOR_R (GLfloat)0 +#define GLCOMPSET_BUTTON_COLOR_G (GLfloat)1 +#define GLCOMPSET_BUTTON_COLOR_B (GLfloat)0.3 +#define GLCOMPSET_BUTTON_COLOR_ALPHA (GLfloat)0.6 +#define GLCOMPSET_BUTTON_THICKNESS (GLfloat)3 +#define GLCOMPSET_BUTTON_BEVEL_BRIGHTNESS (GLfloat)1.7 +#define GLCOMPSET_FONT_SIZE (GLfloat)14 +#define GLCOMPSET_BUTTON_FONT_COLOR_R (GLfloat)1 +#define GLCOMPSET_BUTTON_FONT_COLOR_G (GLfloat)1 +#define GLCOMPSET_BUTTON_FONT_COLOR_B (GLfloat)1 +#define GLCOMPSET_BUTTON_FONT_COLOR_ALPHA (GLfloat)1 +#define GLCOMPSET_FONT_SIZE_FACTOR (GLfloat)0.7 +#define GLCOMPSET_LABEL_COLOR_R (GLfloat)0 +#define GLCOMPSET_LABEL_COLOR_G (GLfloat)0 +#define GLCOMPSET_LABEL_COLOR_B (GLfloat)0 +#define GLCOMPSET_LABEL_COLOR_ALPHA (GLfloat)1 + +#define GLCOMPSET_PANEL_BEVEL (GLfloat)0.1 +#define GLCOMPSET_BEVEL_DIFF (GLfloat)0.001 +#define GLCOMPSET_DEFAULT_PAD (GLfloat)3 + +typedef void (*callbackfunc_t) (void *component); +typedef enum { inverted_y,scientific_y} glCompOrientation; + +typedef struct _glCompPoint { + GLfloat x, y; +} glCompPoint; +typedef struct { + GLfloat R; + GLfloat G; + GLfloat B; + GLfloat A; //Alpha +} glCompColor; +typedef struct { + unsigned int id; + float w, h; +} glCompTexture; +typedef struct +{ + float fgColor[4]; /* foreground color, default white */ + float gdColor[4]; /* gradient color, default gray */ + float bgColor[4]; /* background color, default gray */ + float size; /* size of text, default 12 */ + int shadow; /* shadow text? default 0 */ + int gradient; /* gradient? default 0 */ + int italic; /* italic amount, defaul 0 */ + int bold; /* bold text? */ + int region; /* do we have a text region */ + float regionX; /* lower left x */ + float regionY; /* lower left y */ + float regionW; /* text region w */ + float regionH; /* text region h */ + float tIncX; /* used for texture coords, x axis amount to move */ + float tIncY; /* used for texture coords, y axis amount to move */ + int blockRow; /* characters per row */ + int blockCol; /* characters per col */ + unsigned int texId; /* texture id */ + float zdepth; //third dimension , depth of fonts + char* fontdesc; //font description +} texFont_t; + + +typedef struct +{ + texFont_t** fonts; + int count; + int activefont; + char* font_directory; //location where the glfont files are stored +}fontset_t; + + + + + + +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; + texFont_t* font; //pointer to font to use + glCompOrientation orientation; + +} glCompPanel; +typedef struct _glCompTrackBar { + GLfloat width,height; + glCompPanel* outerpanel; + glCompPanel* trackline; + glCompPanel* indicator; + + GLfloat bevel; + glCompColor color; + glCompColor shadowcolor; + + + float value; + float maxvalue; + float minvalue; + int enabled; + int visible; + void *parentset; //parent compset + int data; + texFont_t* font; //pointer to font to use + glCompOrientation orientation; + +}glCompTrackBar; +typedef struct _glCompLabel { + glCompPoint pos; + GLfloat size; + GLfloat bevel; + glCompColor color; + int visible; + char *text; + GLfloat fontsizefactor; + glCompPanel *panel; //container panel + texFont_t* font; //pointer to font to use + glCompOrientation orientation; + +} 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; + texFont_t* font; //pointer to font to use + glCompOrientation orientation; + +} 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; + texFont_t* font; //pointer to font to use +} glCompSet; + +#endif diff --git a/lib/glcomp/glcomplabel.c b/lib/glcomp/glcomplabel.c new file mode 100644 index 000000000..af23f9fd6 --- /dev/null +++ b/lib/glcomp/glcomplabel.c @@ -0,0 +1,86 @@ +#include "glcomplabel.h" +#include "glcomptexture.h" +#include "glTexFont.h" + + +glCompLabel *glCompLabelNew(GLfloat x, GLfloat y, GLfloat size, char *text,glCompOrientation orientation) +{ + 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'; + p->font = font_init(); + return p; +} + +int glCompSetAddLabel(glCompSet * s, glCompLabel * p) +{ + s->labelcount++; + s->labels = realloc(s->labels, sizeof(glCompLabel *) * s->labelcount); + s->labels[s->labelcount - 1] = p; + if (p->font->texId==-1) //no font has been set yet + copy_font(p->font,s->font); + return 1; +} + + +int glCompSetRemoveLabel(glCompSet * s, glCompLabel * p) +{ + int ind = 0; + int found = 0; + for (; 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->font); + 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->font, p->size); + fontColorA(p->font,p->color.R, p->color.G, p->color.B, p->color.A); + + fontDrawString(p->font, p->pos.x, p->pos.y, + (p->size * p->fontsizefactor * + strlen(p->text)), 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; +} diff --git a/lib/glcomp/glcomplabel.h b/lib/glcomp/glcomplabel.h new file mode 100644 index 000000000..d98e05eb5 --- /dev/null +++ b/lib/glcomp/glcomplabel.h @@ -0,0 +1,14 @@ +#ifndef GLCOMPLABEL_H +#define GLCOMPLABEL_H + +#include "glcompdefs.h" + + +extern glCompLabel *glCompLabelNew(GLfloat x, GLfloat y, GLfloat size, char *text,glCompOrientation orientation); +extern int glCompSetAddLabel(glCompSet * s, glCompLabel * p); +extern int glCompSetRemoveLabel(glCompSet * s, glCompLabel * p); +extern int glCompDrawLabel(glCompLabel * p); + + + +#endif diff --git a/lib/glcomp/glcomppanel.c b/lib/glcomp/glcomppanel.c new file mode 100644 index 000000000..49d6c1bff --- /dev/null +++ b/lib/glcomp/glcomppanel.c @@ -0,0 +1,135 @@ +#include "glcomppanel.h" +#include "glcomptexture.h" +#include "glTexFont.h" + + +glCompPanel *glCompPanelNew(GLfloat x, GLfloat y, GLfloat w, GLfloat h,glCompOrientation orientation) +{ + 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; + p->orientation=orientation; + p->font = font_init(); + return p; +} +int glCompDrawPanel(glCompPanel * p) +{ + 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, 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.G, p->shadowcolor.B, + p->color.A); + glVertex3f(p->pos.x, p->pos.y, + p->bevel + (GLfloat) GLCOMPSET_BEVEL_DIFF); + glVertex3f(p->pos.x + p->width, p->pos.y, + p->bevel + (GLfloat) GLCOMPSET_BEVEL_DIFF); + glVertex3f(p->pos.x + p->width, p->pos.y + p->height, + p->bevel + (GLfloat) GLCOMPSET_BEVEL_DIFF); + glVertex3f(p->pos.x, p->pos.y + p->height, + p->bevel + (GLfloat) GLCOMPSET_BEVEL_DIFF); + glVertex3f(p->pos.x, p->pos.y, 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 - p->shadowwidth / ((GLfloat) 2.0), p->bevel); + glVertex3f(p->pos.x + p->shadowwidth / (GLfloat) 2.0 + p->width, + p->pos.y - p->shadowwidth / (GLfloat) 2.0, p->bevel); + glVertex3f(p->pos.x + p->shadowwidth / (GLfloat) 2.0 + p->width, + p->pos.y - p->shadowwidth / (GLfloat) 2.0 + p->height, + p->bevel); + glEnd(); + glLineWidth(1); + return 1; +} + +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; + if (p->font->texId==-1) //no font has been set yet + copy_font(p->font,s->font); + return 1; +} + +int glCompSetRemovePanel(glCompSet * s, glCompPanel * p) +{ + int ind = 0; + int found = 0; + for (; ind < s->panelcount; ind++) { + if ((s->panels[ind] == p) && found == 0) + found = 1; + if ((found == 1)&&(ind <(s->panelcount-1))) + s->panels[ind] = s->panels[ind + 1]; + } + if (found) { + free(p->font); + free(p); + s->panelcount--; + s->panels = + realloc(s->panels, sizeof(glCompPanel *) * s->panelcount); + return 1; + } + return 0; +} + +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; + return 1; + + +} + +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; + return 1; + +} + diff --git a/lib/glcomp/glcomppanel.h b/lib/glcomp/glcomppanel.h new file mode 100644 index 000000000..07e9c90d8 --- /dev/null +++ b/lib/glcomp/glcomppanel.h @@ -0,0 +1,14 @@ +#ifndef GLCOMPPANEL_H +#define GLCOMPPANEL_H + +#include "glcompdefs.h" + + +extern glCompPanel *glCompPanelNew(GLfloat x, GLfloat y, GLfloat w, GLfloat h,glCompOrientation orientation); +extern int glCompDrawPanel(glCompPanel * p); +extern int glCompSetAddPanel(glCompSet * s, glCompPanel * p); +extern int glCompSetRemovePanel(glCompSet * s, glCompPanel * p); +extern int glCompPanelShow(glCompPanel * p); +extern int glCompPanelHide(glCompPanel * p); + +#endif diff --git a/lib/glcomp/glcompset.c b/lib/glcomp/glcompset.c index c50d8354b..8a5b39160 100644 --- a/lib/glcomp/glcompset.c +++ b/lib/glcomp/glcompset.c @@ -15,21 +15,58 @@ #include "glcompset.h" #include "memory.h" +#include "glcomppanel.h" +#include "glcomplabel.h" +#include "glcompbutton.h" - -#ifdef WIN32 -char * +//#ifdef WIN32 +/*char * mystrdup(const char *string) { char *nstr; nstr = (char *) malloc(strlen(string) + 1); if (nstr) - strcpy(nstr, string); + strcpy(nstr, (char*)string); return nstr; } #define strdup mystrdup -#endif +#endif*/ +//converts screen location to opengl coordinates +static void glCompSetGetPos(int x, int y, float *X, float *Y, float *Z) +{ + GLdouble wwinX; + GLdouble wwinY; + GLdouble wwinZ; + GLdouble posX, posY, posZ; + + + GLint viewport[4]; + GLdouble modelview[16]; + GLdouble projection[16]; + GLfloat winX, winY; + 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 = (float) posX; + *Y = (float) posY; + *Z = (float) posZ; +} + + + void glCompDrawBegin() //pushes a gl stack @@ -62,199 +99,12 @@ void glCompDrawEnd() //pops the gl stack glPopMatrix(); } -int glCompDrawPanel(glCompPanel * p) -{ - 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, 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.G, p->shadowcolor.B, - p->color.A); - glVertex3f(p->pos.x, p->pos.y, - p->bevel + (GLfloat) GLCOMPSET_BEVEL_DIFF); - glVertex3f(p->pos.x + p->width, p->pos.y, - p->bevel + (GLfloat) GLCOMPSET_BEVEL_DIFF); - glVertex3f(p->pos.x + p->width, p->pos.y + p->height, - p->bevel + (GLfloat) GLCOMPSET_BEVEL_DIFF); - glVertex3f(p->pos.x, p->pos.y + p->height, - p->bevel + (GLfloat) GLCOMPSET_BEVEL_DIFF); - glVertex3f(p->pos.x, p->pos.y, 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 - p->shadowwidth / ((GLfloat) 2.0), p->bevel); - glVertex3f(p->pos.x + p->shadowwidth / (GLfloat) 2.0 + p->width, - p->pos.y - p->shadowwidth / (GLfloat) 2.0, p->bevel); - glVertex3f(p->pos.x + p->shadowwidth / (GLfloat) 2.0 + p->width, - p->pos.y - p->shadowwidth / (GLfloat) 2.0 + p->height, - p->bevel); - glEnd(); - glLineWidth(1); - return 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; - p->font = font_init(); - return p; -} -glCompTrackBar* glCompTrackBarNew(GLfloat x, GLfloat y, GLfloat w, GLfloat h) -{ - 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; - 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->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->font=font_init(); -} -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; - if (p->font->texId==-1) //no font has been set yet - copy_font(p->font,s->font); - 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; - if (p->font->texId==-1) //no font has been set yet - copy_font(p->font,s->font); - return 1; -} - -int glCompSetRemovePanel(glCompSet * s, glCompPanel * p) -{ - int ind = 0; - int found = 0; - for (; ind < s->panelcount; ind++) { - if ((s->panels[ind] == p) && found == 0) - found = 1; - if ((found == 1)&&(ind <(s->panelcount-1))) - s->panels[ind] = s->panels[ind + 1]; - } - if (found) { - free(p->font); - 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 < 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->font); - 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->font,(int) p->size); - fontColorA(p->font,p->color.R, p->color.G, p->color.B, p->color.A); - - fontDrawString(p->font,(int) p->pos.x, (int) p->pos.y, - (int) (p->size * p->fontsizefactor * - strlen(p->text)), 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(); - return 1; -} - -int glCompSetDrawPanels(glCompSet * s) +static int glCompSetDrawPanels(glCompSet * s) { int ind = 0; for (; ind < s->panelcount; ind++) { @@ -301,250 +151,24 @@ int glCompSetShow(glCompSet * s) return 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'; - p->font = font_init(); - return p; -} - -int glCompSetAddButton(glCompSet * s, glCompButton * p) +static int glCompPointInButton(glCompButton * p, float x, float y) { - s->buttoncount++; - s->buttons = - realloc(s->buttons, sizeof(glCompButton *) * s->buttoncount); - s->buttons[s->buttoncount - 1] = p; - p->parentset = s; - if (p->font->texId==-1) //no font has been set yet - copy_font((p->font),(s->font)); - 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]; + 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 (found) { - free(p->font); - free(p->caption); - free(p); - s->buttoncount--; - s->buttons = - realloc(s->buttons, sizeof(glCompButton *) * s->buttoncount); + if ((x >= button_x) && + (x <= button_x + p->width) && + (y >= button_y) && (y <= button_y + p->height)) return 1; - } - return 0; -} - -int glCompDrawButton(glCompButton * p) -{ - float color_fac; - float thickness = p->thickness; - float fontx, fonty; - if (!p->visible) + else 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 / (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; - } - 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.G * color_fac, - p->color.B * 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.G / color_fac, - p->color.B / 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 * (GLfloat) 2 - - p->fontsize * strlen(p->caption) * - GLCOMPSET_FONT_SIZE_FACTOR) / (GLfloat) 2.0 + p->pos.x + - p->thickness; - fonty = - (p->height - p->thickness * (GLfloat) 2 - - p->fontsize) / (GLfloat) 2.0 + p->pos.y + p->thickness; - fontSize(p->font,(int) p->fontsize); -// fontColorA (p->fontcolor.R,p->fontcolor.B,p->fontcolor.G,p->fontcolor.A); - fontColorA(p->font,0, 0, 0, 1); - fontDrawString(p->font,(int) fontx, (int) fonty, - (int) (p->fontsize * strlen(p->caption) * - GLCOMPSET_FONT_SIZE_FACTOR), 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 - p->thickness * (GLfloat) 2 - - p->glyphheight) / (GLfloat) 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.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 = p->pos.x - p->panel->pos.x; - p->pos.y = p->pos.y - p->panel->pos.y; - } - - return 1; +} -} int glCompSetClick(glCompSet * s, int x, int y) { @@ -591,137 +215,9 @@ int glCompSetRelease(glCompSet * s, int x, int y) 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; - GLint viewport[4]; - GLdouble modelview[16]; - GLdouble projection[16]; - GLfloat winX, winY; - 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 = (float) posX; - *Y = (float) posY; - *Z = (float) 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'; - p->font = font_init(); - 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; - return 1; - - -} - -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; - return 1; - -} void glCompSetClear(glCompSet * s) { @@ -753,6 +249,14 @@ glCompSet* glCompSetNew() s->font = font_init(); return s; } + +int glCompSetDraw(glCompSet * s) +{ + glCompDrawBegin(); + glCompSetDrawPanels(s); + glCompDrawEnd(); + return 1; +} #if 0 static void change_fonts(glCompSet * s,const texFont_t* sourcefont) { diff --git a/lib/glcomp/glcompset.h b/lib/glcomp/glcompset.h index 239629ffa..2edddce93 100644 --- a/lib/glcomp/glcompset.h +++ b/lib/glcomp/glcompset.h @@ -23,172 +23,19 @@ #include "glTexFontTGA.h" #include "glTexFontDefs.h" #include "glTexFontInclude.h" -//#include "gltemplate.h" #include "glcomptexture.h" -#define GLCOMPSET_PANEL_COLOR_R (GLfloat)0.16 -#define GLCOMPSET_PANEL_COLOR_G (GLfloat)0.44 -#define GLCOMPSET_PANEL_COLOR_B (GLfloat)0.87 -#define GLCOMPSET_PANEL_COLOR_ALPHA (GLfloat)0.5 -#define GLCOMPSET_PANEL_SHADOW_COLOR_R (GLfloat)0 -#define GLCOMPSET_PANEL_SHADOW_COLOR_G (GLfloat)0 -#define GLCOMPSET_PANEL_SHADOW_COLOR_B (GLfloat)0 -#define GLCOMPSET_PANEL_SHADOW_COLOR_A (GLfloat)0.3 -#define GLCOMPSET_PANEL_SHADOW_WIDTH (GLfloat)4 -#define GLCOMPSET_BUTTON_COLOR_R (GLfloat)0 -#define GLCOMPSET_BUTTON_COLOR_G (GLfloat)1 -#define GLCOMPSET_BUTTON_COLOR_B (GLfloat)0.3 -#define GLCOMPSET_BUTTON_COLOR_ALPHA (GLfloat)0.6 -#define GLCOMPSET_BUTTON_THICKNESS (GLfloat)3 -#define GLCOMPSET_BUTTON_BEVEL_BRIGHTNESS (GLfloat)1.7 -#define GLCOMPSET_FONT_SIZE (GLfloat)14 -#define GLCOMPSET_BUTTON_FONT_COLOR_R (GLfloat)1 -#define GLCOMPSET_BUTTON_FONT_COLOR_G (GLfloat)1 -#define GLCOMPSET_BUTTON_FONT_COLOR_B (GLfloat)1 -#define GLCOMPSET_BUTTON_FONT_COLOR_ALPHA (GLfloat)1 -#define GLCOMPSET_FONT_SIZE_FACTOR (GLfloat)0.7 -#define GLCOMPSET_LABEL_COLOR_R (GLfloat)0 -#define GLCOMPSET_LABEL_COLOR_G (GLfloat)0 -#define GLCOMPSET_LABEL_COLOR_B (GLfloat)0 -#define GLCOMPSET_LABEL_COLOR_ALPHA (GLfloat)1 +extern glCompSet* glCompSetNew(void); +extern void glCompSetClear(glCompSet * s); +extern int glCompSetDraw(glCompSet * s); +extern int glCompSetHide(glCompSet * s); +extern int glCompSetShow(glCompSet * s); +extern int glCompSetClick(glCompSet * s, int x, int y); +extern int glCompSetRelease(glCompSet * s, int x, int y); -#define GLCOMPSET_PANEL_BEVEL (GLfloat)0.1 -#define GLCOMPSET_BEVEL_DIFF (GLfloat)0.001 -#define GLCOMPSET_DEFAULT_PAD (GLfloat)3 - -typedef void (*callbackfunc_t) (void *component); - -typedef struct _glCompPoint { - GLfloat x, y; -} glCompPoint; -typedef struct { - GLfloat R; - GLfloat G; - GLfloat B; - GLfloat 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; - texFont_t* font; //pointer to font to use - -} glCompPanel; -typedef struct _glCompTrackBar { - GLfloat width,height; - glCompPanel* outerpanel; - glCompPanel* trackline; - glCompPanel* indicator; - - GLfloat bevel; - glCompColor color; - glCompColor shadowcolor; - - - float value; - float maxvalue; - float minvalue; - int enabled; - int visible; - void *parentset; //parent compset - int data; - texFont_t* font; //pointer to font to use -}glCompTrackBar; -typedef struct _glCompLabel { - glCompPoint pos; - GLfloat size; - GLfloat bevel; - glCompColor color; - int visible; - char *text; - GLfloat fontsizefactor; - glCompPanel *panel; //container panel - texFont_t* font; //pointer to font to use -} 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; - texFont_t* font; //pointer to font to use -} 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; - texFont_t* font; //pointer to font to use -} glCompSet; - -glCompSet* glCompSetNew(void); -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); - -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(void); //pushes a gl stack -void glCompDrawEnd(void); //pops the gl stack -int glCompDrawPanel(glCompPanel * p); -int glCompSetClick(glCompSet * s, int x, int y); -int glCompSetRelease(glCompSet * s, int x, int y); -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); -int glCompSetDrawPanels(glCompSet * s); +extern void glCompDrawBegin(); +extern void glCompDrawEnd(); /* change all components's fonts in s