1 /* GLArea.c */
2 /**********************************************************************************************************
3 Copyright (c) 2002-2013 Abdul-Rahman Allouche. All rights reserved
4 
5 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
6 documentation files (the Gabedit), to deal in the Software without restriction, including without limitation
7 the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
8 and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
9 
10   The above copyright notice and this permission notice shall be included in all copies or substantial portions
11   of the Software.
12 
13 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
14 TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
15 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
16 CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17 DEALINGS IN THE SOFTWARE.
18 ************************************************************************************************************/
19 
20 #include "../../Config.h"
21 #include "../Common/Global.h"
22 #include "GlobalOrb.h"
23 #include "../Utils/Vector3d.h"
24 #include "../Utils/Transformation.h"
25 #include "../Utils/UtilsGL.h"
26 #include "../Utils/Constants.h"
27 #include "../Geometry/GeomGlobal.h"
28 #include "../Display/AxisGL.h"
29 #include "../Display/PrincipalAxisGL.h"
30 #include "../Display/UtilsOrb.h"
31 #include "../Display/GLArea.h"
32 #include "../Utils/UtilsInterface.h"
33 
34 static gboolean showSymbols = FALSE;
35 static gboolean showNumbers = FALSE;
36 static gboolean showCharges = FALSE;
37 static gboolean showDistances = FALSE;
38 static gboolean showDipole = FALSE;
39 static gboolean showAxes = FALSE;
40 static gchar fontName[BSIZE] = "courier 14";
41 static gchar fontNameTitle[BSIZE] = "courier 48";
42 static gboolean ortho = FALSE;
43 static gchar* strTitle = NULL;
44 static gint xTitle = 0;
45 static gint yTitle = 0;
46 static GdkColor colorTitle = {65535,0,0};
47 static gboolean initColor = TRUE;
48 
49 /*********************************************************************************************/
init_labels_font()50 void init_labels_font()
51 {
52 	sprintf(fontName,"%s",FontsStyleLabel.fontname);
53 	sprintf(fontNameTitle,"%s","courier bold 20");
54 }
55 /*********************************************************************************************/
get_labels_ortho()56 gboolean get_labels_ortho()
57 {
58 	return ortho;
59 }
60 /*********************************************************************************************/
set_labels_ortho(gboolean o)61 void set_labels_ortho(gboolean o)
62 {
63 	ortho = o;
64 }
65 /*********************************************************************************************/
get_show_symbols()66 gboolean get_show_symbols()
67 {
68 	return showSymbols;
69 }
70 /*********************************************************************************************/
set_show_symbols(gboolean ac)71 void set_show_symbols(gboolean ac)
72 {
73 	showSymbols=ac;
74 }
75 /*********************************************************************************************/
get_show_charges()76 gboolean get_show_charges()
77 {
78 	return showCharges;
79 }
80 /*********************************************************************************************/
get_show_numbers()81 gboolean get_show_numbers()
82 {
83 	return showNumbers;
84 }
85 /*********************************************************************************************/
set_show_numbers(gboolean ac)86 void set_show_numbers(gboolean ac)
87 {
88 	showNumbers=ac;
89 }
90 /*********************************************************************************************/
set_show_charges(gboolean ac)91 void set_show_charges(gboolean ac)
92 {
93 	showCharges=ac;
94 }
95 /*********************************************************************************************/
showLabelSymbolsNumbersCharges(PangoContext * ft2_context)96 void showLabelSymbolsNumbersCharges(PangoContext *ft2_context)
97 {
98 	gint i;
99 	gchar buffer[BSIZE];
100 	gchar bSymbol[10];
101 	gchar bNumber[BSIZE];
102 	gchar bCharge[10];
103 	V4d color  = {0.8,0.8,0.8,1.0 };
104 
105 
106 	if(nCenters<1) return;
107 
108 	glInitFontsUsing(FontsStyleLabel.fontname, &ft2_context);
109 
110 	color[0] = FontsStyleLabel.TextColor.red/65535.0;
111 	color[1] = FontsStyleLabel.TextColor.green/65535.0;
112 	color[2] = FontsStyleLabel.TextColor.blue/65535.0;
113 	glDisable ( GL_LIGHTING ) ;
114 	glColor4dv(color);
115 
116 	for(i=0;i<(gint)nCenters;i++)
117 	{
118 
119 		if(showSymbols) sprintf(bSymbol,"%s",GeomOrb[i].Symb);
120 		else bSymbol[0]='\0';
121 		if(showNumbers) sprintf(bNumber,"[%d]",i+1);
122 		else bNumber[0]='\0';
123 		if(showCharges) sprintf(bCharge,"%0.3f",GeomOrb[i].partialCharge);
124 		else bCharge[0]='\0';
125 		sprintf(buffer,"%s%s%s",bSymbol,bNumber,bCharge);
126 		if(ortho)
127 			glPrintOrtho(GeomOrb[i].C[0], GeomOrb[i].C[1], GeomOrb[i].C[2], buffer , TRUE, TRUE, ft2_context);
128 		else
129 		{
130 			/* glPrint(GeomOrb[i].C[0], GeomOrb[i].C[1], GeomOrb[i].C[2], buffer);*/
131 			glPrintScale(GeomOrb[i].C[0], GeomOrb[i].C[1], GeomOrb[i].C[2], 1.1*GeomOrb[i].Prop.radii,buffer, ft2_context);
132 		}
133 	}
134 	glEnable ( GL_LIGHTING ) ;
135 	glDeleteFontsList();
136 }
137 /*********************************************************************************************/
get_show_distances()138 gboolean get_show_distances()
139 {
140 	return showDistances;
141 }
142 /*********************************************************************************************/
set_show_distances(gboolean ac)143 void set_show_distances(gboolean ac)
144 {
145 	showDistances=ac;
146 }
147 /*********************************************************************************************/
showLabelDistances(PangoContext * ft2_context)148 void showLabelDistances(PangoContext *ft2_context)
149 {
150 	gint i;
151 	gint k;
152 	gint j;
153 	gdouble distance;
154 	gdouble tmp[3];
155 	gchar buffer[BSIZE];
156 	V4d color  = {0.8,0.8,0.8,1.0 };
157 
158 	if(nCenters<1) return;
159 	color[0] = FontsStyleLabel.TextColor.red/65535.0;
160 	color[1] = FontsStyleLabel.TextColor.green/65535.0;
161 	color[2] = FontsStyleLabel.TextColor.blue/65535.0;
162 
163 	glInitFontsUsing(FontsStyleLabel.fontname, &ft2_context);
164 	glDisable ( GL_LIGHTING ) ;
165 	glColor4dv(color);
166 
167 	for(i=0;i<(gint)nCenters;i++)
168 	for(j=i+1;j<(gint)nCenters;j++)
169 	{
170 		for(k=0;k<3;k++)
171 			tmp[k] = (GeomOrb[i].C[k] - GeomOrb[j].C[k]);
172 		distance = v3d_length(tmp);
173 		if(distance>=(GeomOrb[i].Prop.covalentRadii + GeomOrb[j].Prop.covalentRadii))
174 			continue;
175 		for(k=0;k<3;k++)
176 			tmp[k] = (GeomOrb[i].C[k] + GeomOrb[j].C[k])/2;
177 		sprintf(buffer, "%0.3f",distance*BOHR_TO_ANG);
178 
179 		if(ortho)
180 			glPrintOrtho(tmp[0], tmp[1], tmp[2], buffer, TRUE, TRUE, ft2_context);
181 		else
182 		{
183 			/* glPrint(tmp[0], tmp[1], tmp[2], buffer);*/
184 			gdouble r = GeomOrb[i].Prop.radii;
185 			if(GeomOrb[j].Prop.radii>r)r = GeomOrb[j].Prop.radii;
186 			glPrintScale(tmp[0], tmp[1], tmp[2], 1.1*r,buffer, ft2_context);
187 		}
188 	}
189 	glEnable ( GL_LIGHTING ) ;
190 	glDeleteFontsList();
191 }
192 /*********************************************************************************************/
get_show_dipole()193 gboolean get_show_dipole()
194 {
195 	return showDipole;
196 }
197 /*********************************************************************************************/
set_show_dipole(gboolean ac)198 void set_show_dipole(gboolean ac)
199 {
200 	showDipole=ac;
201 }
202 /*********************************************************************************************/
showLabelDipole(PangoContext * ft2_context)203 void showLabelDipole(PangoContext *ft2_context)
204 {
205 	gint i;
206 	V4d color  = {0.8,0.8,0.8,1.0 };
207 	V3d Base1Pos  = {Dipole.origin[0],Dipole.origin[1],Dipole.origin[2]};
208 	V3d Base2Pos  = {Dipole.origin[0]+Dipole.value[0],Dipole.origin[1]+Dipole.value[1],Dipole.origin[2]+Dipole.value[2]};
209 
210 	GLdouble radius = Dipole.radius;
211 	V3d Center;
212 	GLdouble p1=90;
213 	GLdouble p2=10;
214 	GLdouble p = p1 + p2;
215 	GLdouble scal = 2;
216 	gdouble module;
217 	gchar buffer[BSIZE];
218 
219 	if(nCenters<1) return;
220 	if(!showDipole) return;
221 	if(!ShowDipoleOrb) return;
222 
223 	color[0] = FontsStyleLabel.TextColor.red/65535.0;
224 	color[1] = FontsStyleLabel.TextColor.green/65535.0;
225 	color[2] = FontsStyleLabel.TextColor.blue/65535.0;
226 
227 	glInitFontsUsing(FontsStyleLabel.fontname, &ft2_context);
228 	glDisable ( GL_LIGHTING ) ;
229 	glColor4dv(color);
230 
231 	if(radius<0.1) radius = 0.1;
232 
233 	Base2Pos[0] = Base1Pos[0]+Dipole.value[0]*scal;
234 	Base2Pos[1] = Base1Pos[1]+Dipole.value[1]*scal;
235 	Base2Pos[2] = Base1Pos[2]+Dipole.value[2]*scal;
236 
237 	Center[0] = (Base1Pos[0]*p2 + Base2Pos[0]*p1)/p;
238 	Center[1] = (Base1Pos[1]*p2 + Base2Pos[1]*p1)/p;
239 	Center[2] = (Base1Pos[2]*p2 + Base2Pos[2]*p1)/p;
240 
241 	module = 0;
242 	for(i=0;i<3;i++)
243 		module += Dipole.value[i]*Dipole.value[i];
244 	module = sqrt(module);
245 	module *= AUTODEB;
246 	sprintf(buffer,"%0.3f D",module);
247 
248 	if(ortho)
249 		glPrintOrtho(Center[0], Center[1], Center[2], buffer, TRUE, TRUE, ft2_context);
250 	else
251 	{
252 	/*	glPrint(Center[0], Center[1], Center[2], buffer); */
253 		glPrintScale(Center[0], Center[1], Center[2], 1.1*radius,buffer, ft2_context);
254 	}
255 	glEnable ( GL_LIGHTING ) ;
256 	glDeleteFontsList();
257 }
258 /*********************************************************************************************/
get_show_axes()259 gboolean get_show_axes()
260 {
261 	return showAxes;
262 }
263 /*********************************************************************************************/
set_show_axes(gboolean ac)264 void set_show_axes(gboolean ac)
265 {
266 	showAxes=ac;
267 }
268 /*********************************************************************************************/
showLabelAxes(PangoContext * ft2_context)269 void showLabelAxes(PangoContext *ft2_context)
270 {
271 	gint i;
272 	V4d color  = {0.8,0.8,0.8,1.0 };
273 	gchar buffer[BSIZE];
274 	gboolean show;
275 	gboolean negative;
276 	gdouble origin[3];
277 	gdouble radius;
278 	gdouble scal;
279 	gdouble xColor[3];
280 	gdouble yColor[3];
281 	gdouble zColor[3];
282 	gdouble vectorX[]  = {1,0,0};
283 	gdouble vectorY[]  = {0,1,0};
284 	gdouble vectorZ[]  = {0,0,1};
285 
286 	if(!showAxes) return;
287 	if(!testShowAxis()) return;
288 
289 	getAxisProperties(&show, &negative, origin, &radius, &scal, xColor, yColor, zColor);
290 
291 	for(i=0;i<3;i++)
292 	{
293 		vectorX[i] *= scal;
294 		vectorY[i] *= scal;
295 		vectorZ[i] *= scal;
296 	}
297 	for(i=0;i<3;i++)
298 	{
299 		vectorX[i] += origin[i];
300 		vectorY[i] += origin[i];
301 		vectorZ[i] += origin[i];
302 	}
303 
304 
305 	color[0] = FontsStyleLabel.TextColor.red/65535.0;
306 	color[1] = FontsStyleLabel.TextColor.green/65535.0;
307 	color[2] = FontsStyleLabel.TextColor.blue/65535.0;
308 
309 	glInitFontsUsing(FontsStyleLabel.fontname, &ft2_context);
310 
311 	if(radius<0.1) radius = 0.1;
312 	glDisable ( GL_LIGHTING ) ;
313 	glColor4dv(color);
314 
315 
316 	if(ortho)
317 	{
318 		sprintf(buffer,"X");
319 		glPrintOrtho(vectorX[0], vectorX[1], vectorX[2], buffer, TRUE, TRUE, ft2_context);
320 		sprintf(buffer,"Y");
321 		glPrintOrtho(vectorY[0], vectorY[1], vectorY[2], buffer, TRUE, TRUE, ft2_context);
322 		sprintf(buffer,"Z");
323 		glPrintOrtho(vectorZ[0], vectorZ[1], vectorZ[2], buffer, TRUE, TRUE, ft2_context);
324 	}
325 	else
326 	{
327 		/*
328 		sprintf(buffer,"X");
329 		glPrint(vectorX[0], vectorX[1], vectorX[2], buffer);
330 		sprintf(buffer,"Y");
331 		glPrint(vectorY[0], vectorY[1], vectorY[2], buffer);
332 		sprintf(buffer,"Z");
333 		glPrint(vectorZ[0], vectorZ[1], vectorZ[2], buffer);
334 		*/
335 		sprintf(buffer,"X");
336 		glPrintScale(vectorX[0], vectorX[1], vectorX[2], 1.1*radius, buffer, ft2_context);
337 		sprintf(buffer,"Y");
338 		glPrintScale(vectorY[0], vectorY[1], vectorY[2], 1.1*radius, buffer, ft2_context);
339 		sprintf(buffer,"Z");
340 		glPrintScale(vectorZ[0], vectorZ[1], vectorZ[2], 1.1*radius, buffer, ft2_context);
341 	}
342 	glEnable ( GL_LIGHTING ) ;
343 	glDeleteFontsList();
344 }
345 /*********************************************************************************************/
showLabelPrincipalAxes(PangoContext * ft2_context)346 void showLabelPrincipalAxes(PangoContext *ft2_context)
347 {
348 	gint i;
349 	V4d color  = {0.8,0.8,0.8,1.0 };
350 	gchar buffer[BSIZE];
351 	gboolean show;
352 	gboolean negative;
353 	gboolean def;
354 	gdouble origin[3];
355 	gdouble radius;
356 	gdouble scal;
357 	gdouble c1[3];
358 	gdouble c2[3];
359 	gdouble c3[3];
360 	gdouble v1[]  = {1,0,0};
361 	gdouble v2[]  = {0,1,0};
362 	gdouble v3[]  = {0,0,1};
363 	gdouble I[]  = {1,1,1};
364 
365 	if(!showAxes) return;
366 	if(!testShowPrincipalAxisGL()) return;
367 
368 	getPrincipalAxisProperties(&show, &negative, &def, origin, &radius, &scal, v1,v2, v3, c1,c2, c3);
369 	if(!def) return;
370 	getPrincipalAxisInertias(I);
371 
372 	for(i=0;i<3;i++)
373 	{
374 		v1[i] *= scal;
375 		v2[i] *= scal;
376 		v3[i] *= scal;
377 	}
378 	for(i=0;i<3;i++)
379 	{
380 		v1[i] += origin[i];
381 		v2[i] += origin[i];
382 		v3[i] += origin[i];
383 	}
384 
385 
386 	color[0] = FontsStyleLabel.TextColor.red/65535.0;
387 	color[1] = FontsStyleLabel.TextColor.green/65535.0;
388 	color[2] = FontsStyleLabel.TextColor.blue/65535.0;
389 
390 	glInitFontsUsing(FontsStyleLabel.fontname, &ft2_context);
391 
392 	if(radius<0.1) radius = 0.1;
393 	glDisable ( GL_LIGHTING ) ;
394 	glColor4dv(color);
395 
396 
397 	if(ortho)
398 	{
399 		sprintf(buffer,"I=%0.3f",I[0]);
400 		glPrintOrtho(v1[0], v1[1], v1[2], buffer, TRUE, TRUE, ft2_context);
401 		sprintf(buffer,"I=%0.3f",I[1]);
402 		glPrintOrtho(v2[0], v2[1], v2[2], buffer, TRUE, TRUE, ft2_context);
403 		sprintf(buffer,"I=%0.3f",I[2]);
404 		glPrintOrtho(v3[0], v3[1], v3[2], buffer, TRUE, TRUE, ft2_context);
405 	}
406 	else
407 	{
408 		/*
409 		sprintf(buffer,"I=%0.3f",I[0]);
410 		glPrint(v1[0], v1[1], v1[2], buffer);
411 		sprintf(buffer,"I=%0.3f",I[1]);
412 		glPrint(v2[0], v2[1], v2[2], buffer);
413 		sprintf(buffer,"I=%0.3f",I[2]);
414 		glPrint(v3[0], v3[1], v3[2], buffer);
415 		*/
416 		sprintf(buffer,"I=%0.3f",I[0]);
417 		glPrintScale(v1[0], v1[1], v1[2], 1.1*radius, buffer, ft2_context);
418 		sprintf(buffer,"I=%0.3f",I[1]);
419 		glPrintScale(v2[0], v2[1], v2[2], 1.1*radius, buffer, ft2_context);
420 		sprintf(buffer,"I=%0.3f",I[2]);
421 		glPrintScale(v3[0], v3[1], v3[2], 1.1*radius, buffer, ft2_context);
422 	}
423 	glEnable ( GL_LIGHTING ) ;
424 	glDeleteFontsList();
425 }
426 /*********************************************************************************************/
showLabelTitle(gint width,gint height,PangoContext * ft2_context)427 void showLabelTitle(gint width, gint height, PangoContext *ft2_context)
428 {
429 	V4d color  = {0.8,0.8,0.8,1.0 };
430 
431 	if(nCenters<1) return;
432 	if(!strTitle) return;
433 	if(xTitle<0) return;
434 	if(yTitle<0) return;
435 
436 	if(initColor)
437 	{
438 		colorTitle.red = FontsStyleLabel.TextColor.red;
439 		colorTitle.green = FontsStyleLabel.TextColor.green;
440 		colorTitle.blue = FontsStyleLabel.TextColor.blue;
441 		initColor = FALSE;
442 	}
443 	color[0] = colorTitle.red/65535.0;
444 	color[1] = colorTitle.green/65535.0;
445 	color[2] = colorTitle.blue/65535.0;
446 
447 	glInitFontsUsing(fontNameTitle, &ft2_context);
448 	glDisable ( GL_LIGHTING ) ;
449 	glColor4dv(color);
450 
451 	glLoadIdentity();
452 
453 	glMatrixMode(GL_PROJECTION);
454 	glPushMatrix();
455 	glLoadIdentity();
456 	gluOrtho2D(0, width, 0, height);
457 
458 
459 	/* glPrintWin(xTitle/100.0*width,(yTitle)/100.0*height+glTextHeight(),height, strTitle, ft2_context);*/
460 	glPrintWin(xTitle/100.0*width,(yTitle)/100.0*height+2*glTextHeight(),height, strTitle, ft2_context);
461 
462 	glPopMatrix();
463 	glMatrixMode(GL_MODELVIEW);
464 
465 	glEnable ( GL_LIGHTING ) ;
466 	glDeleteFontsList();
467 }
468 /*********************************************************************************************/
get_label_title()469 gchar* get_label_title()
470 {
471 	return strTitle;
472 }
473 /*********************************************************************************************/
set_label_title(gchar * str,gint x,gint y)474 void set_label_title(gchar* str, gint x, gint y)
475 {
476 	if(strTitle) g_free(strTitle);
477 	strTitle = NULL;
478 	if(str) strTitle = g_strdup(str);
479 	if(x>=0) xTitle = x;
480 	if(y>=0) yTitle = y;
481 }
482 /********************************************************************************/
apply_set_title(GtkWidget * Win,gpointer data)483 static void apply_set_title(GtkWidget *Win,gpointer data)
484 {
485 	GtkWidget* entry = NULL;
486 	GtkWidget* xSpinButton = NULL;
487 	GtkWidget* ySpinButton = NULL;
488 	GtkWidget* fontButton = NULL;
489 	GtkWidget* colorButton = NULL;
490 	gdouble xValue = 0;
491 	gdouble yValue = 0;
492 	G_CONST_RETURN gchar* fontStr = NULL;
493 	G_CONST_RETURN gchar* str = NULL;
494 
495 	if(!GTK_IS_WIDGET(Win)) return;
496 
497 	entry = g_object_get_data (G_OBJECT (Win), "Entry");
498 	xSpinButton = g_object_get_data (G_OBJECT (Win), "XSpinButton");
499 	ySpinButton = g_object_get_data (G_OBJECT (Win), "YSpinButton");
500 	fontButton = g_object_get_data (G_OBJECT (Win), "FontButton");
501 	colorButton = g_object_get_data (G_OBJECT (Win), "ColorButton");
502 
503 	str = gtk_entry_get_text(GTK_ENTRY(entry));
504 	fontStr = gtk_font_button_get_font_name(GTK_FONT_BUTTON(fontButton));
505 	xValue = gtk_spin_button_get_value (GTK_SPIN_BUTTON(xSpinButton));
506 	yValue = gtk_spin_button_get_value (GTK_SPIN_BUTTON(ySpinButton));
507 	if(xValue>=0 && xValue<=100) xTitle = xValue;
508 	if(yValue>=0 && yValue<=100) yTitle = yValue;
509 	if(fontStr) sprintf(fontNameTitle,"%s",fontStr);
510 	if(str && strlen(str)>1)
511 	{
512 		if(strTitle) g_free(strTitle);
513 		strTitle = g_strdup(str);
514 	}
515 	if(colorButton) gtk_color_button_get_color (GTK_COLOR_BUTTON(colorButton), &colorTitle);
516 	glarea_rafresh(GLArea);
517 
518 }
519 /********************************************************************************/
apply_set_title_close(GtkWidget * Win,gpointer data)520 static void apply_set_title_close(GtkWidget *Win,gpointer data)
521 {
522 	apply_set_title(Win,data);
523 	delete_child(Win);
524 }
525 /********************************************************************************/
add_entry_title(GtkWidget * table,gchar * strLabel,gint il)526 static GtkWidget *add_entry_title( GtkWidget *table, gchar* strLabel, gint il)
527 {
528 	gushort i;
529 	gushort j;
530 	GtkWidget *entry;
531 	GtkWidget *label;
532 
533 /*----------------------------------------------------------------------------------*/
534 	i = il;
535 	j = 0;
536 	label = gtk_label_new(strLabel);
537 	gtk_table_attach(GTK_TABLE(table),label, j,j+1,i,i+1,
538                   (GtkAttachOptions)(GTK_FILL|GTK_SHRINK) ,
539                   (GtkAttachOptions)(GTK_FILL|GTK_SHRINK),
540                   1,1);
541 /*----------------------------------------------------------------------------------*/
542 	i = il;
543 	j = 1;
544 	label = gtk_label_new(":");
545 	gtk_table_attach(GTK_TABLE(table),label, j,j+1,i,i+1,
546                   (GtkAttachOptions)(GTK_FILL|GTK_SHRINK) ,
547                   (GtkAttachOptions)(GTK_FILL|GTK_SHRINK),
548                   1,1);
549 /*----------------------------------------------------------------------------------*/
550 	i = il;
551 	j = 2;
552 	entry =  gtk_entry_new();
553 	if(strTitle) gtk_entry_set_text(GTK_ENTRY(entry),strTitle);
554 	else gtk_entry_set_text(GTK_ENTRY(entry),"");
555 
556 	gtk_table_attach(GTK_TABLE(table),entry,
557 			j,j+4,i,i+1,
558                   (GtkAttachOptions)(GTK_FILL|GTK_EXPAND) ,
559                   (GtkAttachOptions)(GTK_FILL|GTK_SHRINK),
560                   1,1);
561 
562   	return entry;
563 }
564 /********************************************************************************/
add_font_button(GtkWidget * table,gchar * strLabel,gint il)565 static GtkWidget *add_font_button( GtkWidget *table, gchar* strLabel, gint il)
566 {
567 	gushort i;
568 	gushort j;
569 	GtkWidget *fontButton;
570 	GtkWidget *label;
571 
572 /*----------------------------------------------------------------------------------*/
573 	i = il;
574 	j = 0;
575 	label = gtk_label_new(strLabel);
576 	gtk_table_attach(GTK_TABLE(table),label, j,j+1,i,i+1,
577                   (GtkAttachOptions)(GTK_FILL|GTK_SHRINK) ,
578                   (GtkAttachOptions)(GTK_FILL|GTK_SHRINK),
579                   1,1);
580 /*----------------------------------------------------------------------------------*/
581 	i = il;
582 	j = 1;
583 	label = gtk_label_new(":");
584 	gtk_table_attach(GTK_TABLE(table),label, j,j+1,i,i+1,
585                   (GtkAttachOptions)(GTK_FILL|GTK_SHRINK) ,
586                   (GtkAttachOptions)(GTK_FILL|GTK_SHRINK),
587                   1,1);
588 /*----------------------------------------------------------------------------------*/
589 	i = il;
590 	j = 2;
591 	fontButton =  gtk_font_button_new_with_font   (fontNameTitle);
592 
593 	gtk_table_attach(GTK_TABLE(table),fontButton,
594 			j,j+4,i,i+1,
595                   (GtkAttachOptions)(GTK_FILL|GTK_EXPAND) ,
596                   (GtkAttachOptions)(GTK_FILL|GTK_SHRINK),
597                   1,1);
598 
599   	return fontButton;
600 }
601 /********************************************************************************/
add_spin_button(GtkWidget * table,gchar * strLabel,gint il)602 static GtkWidget *add_spin_button( GtkWidget *table, gchar* strLabel, gint il)
603 {
604 	gushort i;
605 	gushort j;
606 	GtkWidget *spinButton;
607 	GtkWidget *label;
608 
609 /*----------------------------------------------------------------------------------*/
610 	i = il;
611 	j = 0;
612 	label = gtk_label_new(strLabel);
613 	gtk_table_attach(GTK_TABLE(table),label, j,j+1,i,i+1,
614                   (GtkAttachOptions)(GTK_FILL|GTK_SHRINK) ,
615                   (GtkAttachOptions)(GTK_FILL|GTK_SHRINK),
616                   1,1);
617 /*----------------------------------------------------------------------------------*/
618 	i = il;
619 	j = 1;
620 	label = gtk_label_new(":");
621 	gtk_table_attach(GTK_TABLE(table),label, j,j+1,i,i+1,
622                   (GtkAttachOptions)(GTK_FILL|GTK_SHRINK) ,
623                   (GtkAttachOptions)(GTK_FILL|GTK_SHRINK),
624                   1,1);
625 /*----------------------------------------------------------------------------------*/
626 	i = il;
627 	j = 2;
628 	spinButton =  gtk_spin_button_new_with_range (0, 100, 1);
629 
630 	gtk_table_attach(GTK_TABLE(table),spinButton,
631 			j,j+4,i,i+1,
632                   (GtkAttachOptions)(GTK_FILL|GTK_EXPAND) ,
633                   (GtkAttachOptions)(GTK_FILL|GTK_SHRINK),
634                   1,1);
635 
636   	return spinButton;
637 }
638 /********************************************************************************/
add_color_button(GtkWidget * table,gchar * strLabel,gint il)639 static GtkWidget *add_color_button( GtkWidget *table, gchar* strLabel, gint il)
640 {
641 	gushort i;
642 	gushort j;
643 	GtkWidget *colorButton;
644 	GtkWidget *label;
645 
646 	if(initColor)
647 	{
648 		colorTitle.red = FontsStyleLabel.TextColor.red;
649 		colorTitle.green = FontsStyleLabel.TextColor.green;
650 		colorTitle.blue = FontsStyleLabel.TextColor.blue;
651 		initColor = FALSE;
652 	}
653 
654 /*----------------------------------------------------------------------------------*/
655 	i = il;
656 	j = 0;
657 	label = gtk_label_new(strLabel);
658 	gtk_table_attach(GTK_TABLE(table),label, j,j+1,i,i+1,
659                   (GtkAttachOptions)(GTK_FILL|GTK_SHRINK) ,
660                   (GtkAttachOptions)(GTK_FILL|GTK_SHRINK),
661                   1,1);
662 /*----------------------------------------------------------------------------------*/
663 	i = il;
664 	j = 1;
665 	label = gtk_label_new(":");
666 	gtk_table_attach(GTK_TABLE(table),label, j,j+1,i,i+1,
667                   (GtkAttachOptions)(GTK_FILL|GTK_SHRINK) ,
668                   (GtkAttachOptions)(GTK_FILL|GTK_SHRINK),
669                   1,1);
670 /*----------------------------------------------------------------------------------*/
671 	i = il;
672 	j = 2;
673 
674 	colorButton =  gtk_color_button_new_with_color(&colorTitle);
675 
676 	gtk_table_attach(GTK_TABLE(table),colorButton,
677 			j,j+4,i,i+1,
678                   (GtkAttachOptions)(GTK_FILL|GTK_EXPAND) ,
679                   (GtkAttachOptions)(GTK_FILL|GTK_SHRINK),
680                   1,1);
681 
682   	return colorButton;
683 }
684 /********************************************************************************/
set_title_dlg()685 void set_title_dlg()
686 {
687 	GtkWidget *Win;
688 	GtkWidget *frame;
689 	GtkWidget *vboxframe;
690 	GtkWidget *hbox;
691 	GtkWidget *table;
692 	GtkWidget *vboxall;
693 	GtkWidget *xSpinButton;
694 	GtkWidget *ySpinButton;
695 	GtkWidget *fontButton;
696 	GtkWidget *button;
697 	GtkWidget *entry;
698 	GtkWidget *colorButton;
699 
700 	Win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
701 	gtk_window_set_title(GTK_WINDOW(Win),_("Set title"));
702 	gtk_window_set_position(GTK_WINDOW(Win),GTK_WIN_POS_CENTER);
703 	gtk_container_set_border_width (GTK_CONTAINER (Win), 5);
704 	gtk_window_set_modal (GTK_WINDOW (Win), TRUE);
705 
706 	add_glarea_child(Win,_("Title "));
707 
708 	vboxall = create_vbox(Win);
709 	frame = gtk_frame_new (_("Set title"));
710 	gtk_container_set_border_width (GTK_CONTAINER (frame), 5);
711 	gtk_container_add (GTK_CONTAINER (vboxall), frame);
712 	gtk_widget_show (frame);
713 
714 	vboxframe = create_vbox(frame);
715 	table = gtk_table_new(5,3,FALSE);
716 	gtk_container_add(GTK_CONTAINER(vboxframe),table);
717 
718 	entry = add_entry_title(table, _("Title"), 0);
719 	xSpinButton = add_spin_button( table, _("X position(%)"), 1);
720 	gtk_spin_button_set_value(GTK_SPIN_BUTTON(xSpinButton),xTitle);
721 	ySpinButton = add_spin_button( table, _("Y position(%)"), 2);
722 	gtk_spin_button_set_value(GTK_SPIN_BUTTON(ySpinButton),yTitle);
723 	fontButton =  add_font_button(table, _("Font"),  3);
724 	colorButton =  add_color_button(table, _("Color"),  4);
725 
726 	g_object_set_data (G_OBJECT (Win), "Entry",entry);
727 	g_object_set_data (G_OBJECT (Win), "XSpinButton",xSpinButton);
728 	g_object_set_data (G_OBJECT (Win), "YSpinButton",ySpinButton);
729 	g_object_set_data (G_OBJECT (Win), "FontButton",fontButton);
730 	g_object_set_data (G_OBJECT (Win), "ColorButton",colorButton);
731 
732 	hbox = create_hbox_false(vboxall);
733 	gtk_widget_realize(Win);
734 
735 	button = create_button(Win,_("OK"));
736 	gtk_box_pack_end (GTK_BOX( hbox), button, FALSE, TRUE, 3);
737 	GTK_WIDGET_SET_FLAGS(button, GTK_CAN_DEFAULT);
738 	gtk_widget_grab_default(button);
739 	gtk_widget_show (button);
740 	g_signal_connect_swapped(G_OBJECT(button), "clicked",(GCallback)apply_set_title_close,G_OBJECT(Win));
741 
742 	button = create_button(Win,_("Apply"));
743 	gtk_box_pack_end (GTK_BOX( hbox), button, FALSE, TRUE, 3);
744 	GTK_WIDGET_SET_FLAGS(button, GTK_CAN_DEFAULT);
745 	gtk_widget_show (button);
746 	g_signal_connect_swapped(G_OBJECT(button), "clicked",(GCallback)apply_set_title,G_OBJECT(Win));
747 
748 	button = create_button(Win,_("Cancel"));
749 	GTK_WIDGET_SET_FLAGS(button, GTK_CAN_DEFAULT);
750 	gtk_box_pack_end (GTK_BOX( hbox), button, FALSE, TRUE, 3);
751 	g_signal_connect_swapped(G_OBJECT(button), "clicked",(GCallback)delete_child, G_OBJECT(Win));
752 	g_signal_connect_swapped(G_OBJECT(button), "clicked",(GCallback)gtk_widget_destroy,G_OBJECT(Win));
753 	gtk_widget_show (button);
754 
755 	gtk_widget_show_all (Win);
756 }
757