From 6189e11d3a0d07cef0bc650fa84a99b7dfa7ce6c Mon Sep 17 00:00:00 2001 From: arif Date: Wed, 26 Mar 2008 23:11:36 +0000 Subject: [PATCH] *** empty log message *** --- cmd/smyrna/draw.c | 2 +- cmd/smyrna/gltemplate.c | 1 + cmd/smyrna/gui/topviewsettings.c | 80 ++++++++++++--- cmd/smyrna/main.c | 7 +- cmd/smyrna/viewport.c | 163 ++++++++++++++++++++++++++++--- cmd/smyrna/viewport.h | 1 + 6 files changed, 224 insertions(+), 30 deletions(-) diff --git a/cmd/smyrna/draw.c b/cmd/smyrna/draw.c index 8e863dfa1..ecf2f433d 100755 --- a/cmd/smyrna/draw.c +++ b/cmd/smyrna/draw.c @@ -599,7 +599,7 @@ void draw_fisheye_magnifier(ViewInfo * view) void drawBorders(ViewInfo * view) { if (view->bdVisible) { - glColor4f((float) 0.8, (float) 0.1, (float) 0.1, (float) 1); + glColor4f(view->borderColor.R,view->borderColor.B,view->borderColor.G,view->borderColor.A); glLineWidth(2); glBegin(GL_LINE_STRIP); glVertex2d(view->bdxLeft, view->bdyBottom); diff --git a/cmd/smyrna/gltemplate.c b/cmd/smyrna/gltemplate.c index bb82bcaed..68f054df2 100755 --- a/cmd/smyrna/gltemplate.c +++ b/cmd/smyrna/gltemplate.c @@ -203,6 +203,7 @@ static gboolean configure_event(GtkWidget * widget, glMatrixMode(GL_MODELVIEW); gdk_gl_drawable_gl_end(gldrawable); /*** OpenGL END ***/ + return TRUE; } diff --git a/cmd/smyrna/gui/topviewsettings.c b/cmd/smyrna/gui/topviewsettings.c index b6713f89c..258bc3d6d 100644 --- a/cmd/smyrna/gui/topviewsettings.c +++ b/cmd/smyrna/gui/topviewsettings.c @@ -15,37 +15,55 @@ #include "topviewsettings.h" #include "gui.h" +#include "color.h" + void on_settingsOKBtn_clicked(GtkWidget * widget, gpointer user_data) { - + update_graph_from_settings(view->g[view->activeGraph]); + set_viewport_settings_from_template (view,view->g[view->activeGraph]); + gtk_widget_hide(glade_xml_get_widget(xml, "dlgSettings")); } void on_settingsCancelBtn_clicked(GtkWidget * widget, gpointer user_data) { - + gtk_widget_hide(glade_xml_get_widget(xml, "dlgSettings")); } static int set_color_button_widget(char* attribute,char* widget_name) { GdkColor color; + gvcolor_t cl; + char* buf; buf=agget(view->g[view->activeGraph],attribute); - if (!buf) + if ((!buf)||(strcmp(buf,"")==0)) buf=agget(view->default_attributes,attribute); if (buf) { - gdk_color_parse(buf,&color); + colorxlate(buf, &cl, RGBA_DOUBLE); + color.red=(int) (cl.u.RGBA[0] * 65535.0); + color.green=(int) (cl.u.RGBA[1] * 65535.0); + color.blue=(int) (cl.u.RGBA[2] * 65535.0); +// gdk_color_parse(buf,&color); gtk_color_button_set_color((GtkColorButton*)glade_xml_get_widget(xml, widget_name),&color); return 1; } return 0; - - +} +static int get_color_button_widget_to_attribute(char* attribute,char* widget_name,Agraph_t * g) +{ + GdkColor color; + char* buf=malloc(256); + gtk_color_button_get_color((GtkColorButton*)glade_xml_get_widget(xml, widget_name),&color); + sprintf(buf,"#%02x%02x%02x",(int)((float)color.red/65535.0*255.0),(int)((float)color.green/65535.0*255.0),(int)((float)color.blue/65535.0*255.0)); + agattr(g, AGRAPH,attribute,buf); + free(buf); + return 1; } static int set_checkbox_widget(char* attribute,char* widget_name) @@ -53,7 +71,7 @@ static int set_checkbox_widget(char* attribute,char* widget_name) char* buf; int value; buf=agget(view->g[view->activeGraph],attribute); - if (!buf) + if ((!buf)||(strcmp(buf,"")==0)) buf=agget(view->default_attributes,attribute); if (buf) { @@ -65,6 +83,15 @@ static int set_checkbox_widget(char* attribute,char* widget_name) } +static int get_checkbox_widget_to_attribute(char* attribute,char* widget_name,Agraph_t * g) +{ + int value; + char buf[5]; + value=(int)gtk_toggle_button_get_active((GtkToggleButton*)glade_xml_get_widget(xml, widget_name)); +// agattr( + agattr(g, AGRAPH,attribute,itoa(value,buf,10)); + return 1; +} @@ -92,13 +119,13 @@ int load_settings_from_graph(Agraph_t * g) buf=agget(view->g[view->activeGraph],"defaultfontname"); if (!buf) buf=agget(view->default_attributes,"defaultfontname"); - if (!buf) + if (buf) gtk_font_selection_set_font_name((GtkFontSelection*)glade_xml_get_widget(xml, "settingsFontSelection"),buf); /*Node Shape Combo, 0:opengl dots, 1:circle ,2:box */ - buf=agget(view->g[view->activeGraph],"defaultfontname"); - if (!buf) - buf=agget(view->default_attributes,"defaultfontname"); + buf=agget(view->g[view->activeGraph],"defaultnodeshape"); if (!buf) + buf=agget(view->default_attributes,"defaultnodeshape"); + if (buf) { /*select the right item in combo box*/ gtk_combo_box_set_active ((GtkComboBox*)glade_xml_get_widget(xml, "settingsFontSelection"),atoi(buf)); @@ -111,13 +138,38 @@ int load_settings_from_graph(Agraph_t * g) int update_graph_from_settings(Agraph_t * g) { - - return 1; + gchar* buf; + int value; + char buf2[10]; + buf='\0'; +/* buf=gtk_font_selection_get_font_name((GtkFontSelection*)glade_xml_get_widget(xml, "settingsFontSelection")); + agset(g,"defaultfontname",buf);*/ + value=gtk_combo_box_get_active ((GtkComboBox*)glade_xml_get_widget(xml, "settingsFontSelection")); + sprintf(buf2,"%i",value); + agattr(g, AGRAPH,"defaultfontname",buf2); + get_color_button_widget_to_attribute("bgcolor","settingsColorBtn1",g); + get_color_button_widget_to_attribute("bordercolor","settingsColorBtn2",g); + get_color_button_widget_to_attribute("gridcolor","settingsColorBtn3",g); + get_color_button_widget_to_attribute("highlightednodecolor","settingsColorBtn6",g); + get_color_button_widget_to_attribute("highlightededgecolor","settingsColorBtn7",g); + get_color_button_widget_to_attribute("selectednodecolor","settingsColorBtn8",g); + get_color_button_widget_to_attribute("selectededgecolor","settingsColorBtn9",g); + get_checkbox_widget_to_attribute("bordervisible","settingsChkBox2",g); + get_checkbox_widget_to_attribute("gridvisible","settingsChkBox3",g); + get_checkbox_widget_to_attribute("randomizenodecolors","settingsChkBox4",g); + get_checkbox_widget_to_attribute("randomizeedgecolors","settingsChkBox5",g); + get_checkbox_widget_to_attribute("usermode","settingsChkBox10",g); + get_checkbox_widget_to_attribute("nodesizewithdegree","settingsChkBox11",g); + get_checkbox_widget_to_attribute("antialiasing","settingsChkBox12",g); + +// free (buf); + return 1; } int show_settings_form() { - gtk_widget_hide(glade_xml_get_widget(xml, "dlgSettings")); + load_settings_from_graph(view->g[view->activeGraph]); + gtk_widget_hide(glade_xml_get_widget(xml, "dlgSettings")); gtk_widget_show(glade_xml_get_widget(xml, "dlgSettings")); gtk_window_set_keep_above((GtkWindow *) glade_xml_get_widget(xml, "dlgSettings"), 1); diff --git a/cmd/smyrna/main.c b/cmd/smyrna/main.c index 0ac9d60f3..321621129 100755 --- a/cmd/smyrna/main.c +++ b/cmd/smyrna/main.c @@ -57,7 +57,8 @@ int main(int argc, char *argv[]) { GdkGLConfig *glconfig; char* smyrnaDir; - load_attributes(); + + load_attributes(); smyrnaDir = getenv ("SMYRNA_PATH"); @@ -82,7 +83,9 @@ int main(int argc, char *argv[]) init_viewport(view); - gtk_set_locale(); + + + gtk_set_locale(); gtk_init(&argc, &argv); #ifdef _WIN32 diff --git a/cmd/smyrna/viewport.c b/cmd/smyrna/viewport.c index 5407d2bec..4984222f2 100755 --- a/cmd/smyrna/viewport.c +++ b/cmd/smyrna/viewport.c @@ -57,6 +57,22 @@ void init_viewport(ViewInfo * view) FILE *input_file; + /*loading default visual attributes*/ + input_file = fopen(DEFAULT_ATTRIBUTES_TEMPLATE_DOT_FILE, "r"); + if (input_file == NULL) + { + g_print("default attributes template graph is not found! Program is being terminated...."); + exit(-1); + } + + else if (!(view->default_attributes = agread(input_file, NIL(Agdisc_t *)))) + { + g_print("Could not load default attributes template graph! Program is being terminated...."); + exit(-1); + } + + + //init graphs view->g = NULL; //no graph, gl screen should check it view->graphCount = 0; //and disable interactivity if count is zero @@ -74,7 +90,7 @@ void init_viewport(ViewInfo * view) view->borderColor.B = 0; view->borderColor.A = 1; - view->bdVisible = 1; //show borders red + view->bdVisible =1; //show borders red view->gridSize = 10; view->gridColor.R = 0.5; @@ -144,22 +160,143 @@ void init_viewport(ViewInfo * view) view->Selection.Anti = 0; view->Topview = malloc(sizeof(topview)); view->Topview->topviewmenu = '\0'; - /*loading default visual attributes*/ - input_file = fopen(DEFAULT_ATTRIBUTES_TEMPLATE_DOT_FILE, "r"); - if (input_file == NULL) - { - g_print("default attributes template graph is not found! Program is being terminated...."); - exit(-1); - } + set_viewport_settings_from_template (view,view->default_attributes); - else if (!(view->default_attributes = agread(input_file, NIL(Agdisc_t *)))) - { - g_print("Could not load default attributes template graph! Program is being terminated...."); - exit(-1); - } +} +static char* get_attribute_value(char* attr,ViewInfo * view,Agraph_t *g) +{ + char* buf; + buf=agget(g,attr); + if ((!buf)||(strcmp(buf,"")==0)) + buf=agget(view->default_attributes,attr); + return buf; + +} +void set_viewport_settings_from_template (ViewInfo * view,Agraph_t *g) +{ + gvcolor_t cl; + char* buf; + /*graph [antialiasing=1, + bgcolor="#ffffff", + bordercolor="#38eb29", + bordercoloralpha="1", + bordervisible=1, + defaultfontname=1, + defaultfontsize=52, + gridcolor="#6033d8", + gridcoloralpha="1", + gridvisible=1, + highlightededgecolor="#c41b50", + highlightededgecoloralpha="1", + highlightednodecolor="#d1cd24", + highlightednodecoloralpha="1", + defaultlinewidth=1 + nodesizewithdegree=1, + randomizeedgecolors=1, + randomizenodecolors=1, + selectededgecolor="#ffc0cb", + selectededgecoloralpha="1", + selectednodecolor="#8ce61d", + selectednodecoloralpha + gridcoloralpha="1", + defaultmagnifierwidth="300", + defaultmagnifierheight="200", + defaultmagnifierkts="5", + defaultfisheyemagnifierradius="250" + usermode=1 + ]; + border color*/ + colorxlate(get_attribute_value("bordercolor",view,g), &cl, RGBA_DOUBLE); + view->borderColor.R = (float)cl.u.RGBA[0]; + view->borderColor.G = (float)cl.u.RGBA[1]; + view->borderColor.B = (float)cl.u.RGBA[2]; + + view->borderColor.A = (float)atof(get_attribute_value("bordercoloralpha",view,g)); + + + view->bdVisible = (float)atof(get_attribute_value("bordervisible",view,g)); + + + buf=get_attribute_value("gridcolor",view,g); + colorxlate(buf, &cl, RGBA_DOUBLE); + view->gridColor.R = (float)cl.u.RGBA[0]; + view->gridColor.G = (float)cl.u.RGBA[1]; + view->gridColor.B = (float)cl.u.RGBA[2]; + view->gridColor.A = (float)atof(get_attribute_value("gridcoloralpha",view,g)); + + + + view->gridSize = (float)atof(buf=get_attribute_value("gridsize",view,g)); + + view->gridVisible = atoi(get_attribute_value("gridvisible",view,g)); + + //mouse mode=pan + + //background color , default white + colorxlate(get_attribute_value("bgcolor",view,g), &cl, RGBA_DOUBLE); + + view->bgColor.R = (float)cl.u.RGBA[0]; + view->bgColor.G = (float)cl.u.RGBA[1]; + view->bgColor.B =(float) cl.u.RGBA[2]; + view->bgColor.A = 1; + + //selected nodes are drawn with this color + colorxlate(get_attribute_value("selectednodecolor",view,g), &cl, RGBA_DOUBLE); + view->selectedNodeColor.R = (float)cl.u.RGBA[0]; + view->selectedNodeColor.G = (float)cl.u.RGBA[1]; + view->selectedNodeColor.B = (float)cl.u.RGBA[2]; + view->selectedNodeColor.A = (float)atof(get_attribute_value("selectednodecoloralpha",view,g)); + //selected edge are drawn with this color + colorxlate(get_attribute_value("selectededgecolor",view,g), &cl, RGBA_DOUBLE); + view->selectedEdgeColor.R = (float)cl.u.RGBA[0]; + view->selectedEdgeColor.G = (float)cl.u.RGBA[1]; + view->selectedEdgeColor.B = (float)cl.u.RGBA[2]; + view->selectedEdgeColor.A = (float)atof(get_attribute_value("selectededgecoloralpha",view,g)); + + + colorxlate(get_attribute_value("highlightednodecolor",view,g), &cl, RGBA_DOUBLE); + view->highlightedNodeColor.R = (float)cl.u.RGBA[0]; + view->highlightedNodeColor.G = (float)cl.u.RGBA[1]; + view->highlightedNodeColor.B = (float)cl.u.RGBA[2]; + view->highlightedNodeColor.A = (float)atof(get_attribute_value("highlightednodecoloralpha",view,g)); + + buf=agget(g,"highlightededgecolor"); + colorxlate(get_attribute_value("highlightededgecolor",view,g), &cl, RGBA_DOUBLE); + view->highlightedEdgeColor.R = (float)cl.u.RGBA[0]; + view->highlightedEdgeColor.G = (float)cl.u.RGBA[1]; + view->highlightedEdgeColor.B = (float)cl.u.RGBA[2]; + view->highlightedEdgeColor.A = (float)atof(get_attribute_value("highlightededgecoloralpha",view,g)); + + +/* + +but here i am, on the road again +here i am, up on the stage +here i go, playing the star again +there i go, turn the page + +*/ + + + + /*default line width*/ + view->LineWidth = (float)atof(get_attribute_value("defaultlinewidth",view,g)); + view->FontSize = atoi(get_attribute_value("defaultfontsize",view,g)); + + view->topviewusermode = atoi(get_attribute_value("usermode",view,g)); + get_attribute_value("defaultmagnifierwidth",view,g); + view->mg.width = atoi(get_attribute_value("defaultmagnifierwidth",view,g)); + view->mg.height = atoi(get_attribute_value("defaultmagnifierheight",view,g)); + + view->mg.kts = (float)atof(get_attribute_value("defaultmagnifierkts",view,g)); + + view->fmg.R = atoi(get_attribute_value("defaultfisheyemagnifierradius",view,g)); + + glClearColor(view->bgColor.R, view->bgColor.G, view->bgColor.B, view->bgColor.A); //background color } + int add_graph_to_viewport_from_file(char *fileName) { //returns 1 if successfull else 0 diff --git a/cmd/smyrna/viewport.h b/cmd/smyrna/viewport.h index 4c7e3c55c..5638c3224 100755 --- a/cmd/smyrna/viewport.h +++ b/cmd/smyrna/viewport.h @@ -27,6 +27,7 @@ void init_viewport(ViewInfo * view); +void set_viewport_settings_from_template (ViewInfo * view,Agraph_t *g); void clear_viewport(ViewInfo * view); int add_graph_to_viewport_from_file(char *fileName); //returns 1 if successfull else 0 ++ int add_new_graph_to_viewport(); //returns graph index , otherwise -1 -- 2.50.1