1
2 /*
3 * Ump - Unnamed Math Program
4 * Copyright (c) 2004-2006 by Mattias Hultgren <mattias_hultgren@tele2.se>
5 *
6 * See main.cpp
7 */
8
9 #include <gtk/gtk.h>
10 #include <math.h>
11 #include <string.h>
12 #include <stdlib.h>
13 #include "ump_graphwin.h"
14 #include "ump_editor.h"
15 #include "ump_simplewin.h"
16 #include "ump_aboutwin.h"
17 #include "ump_picturewin.h"
18 #include "ump_advancedwin.h"
19 #include "ump_prefwin.h"
20 #include "matrix_editor.h"
21 #include "picture.h"
22 #include "picture2gtk.h"
23 #include "main.h"
24 #include "gradient_editor.h"
25
26 #define GET_BOOLEAN_KEY( KEY, DEST ) if((str = setup_file.get_key( KEY )) != 0) \
27 { \
28 if( *str == "True" ) \
29 DEST = true; \
30 else if( *str == "False" ) \
31 DEST = false; \
32 else \
33 { \
34 char tmp_err[ERROR_OBJ_MSG_LEN]; \
35 snprintf( tmp_err, ERROR_OBJ_MSG_LEN, _("Invalid format in file %s"), "<Configure file>" ); \
36 THROW_ERROR( ErrorType_File_IO, tmp_err ); \
37 } \
38 }
39
40
41 void graphwin_settings_show(void);
42
43
44 graph_settings settings;
45
46
47 GtkWidget *graphwin = 0, *graphwin_vbox, *graphwin_vbox_top, *graphwin_menu, *graphwin_plot_frame;
48 GtkWidget *spinwidth,*spinheight,*entryxmin,*entryxmax,*entryymin,*entryymax;
49 GtkWidget *notebook, *checkaxes, *checkgrid;
50 #ifdef PLOT_3D
51 GtkWidget *notebook_2d_3d, *graphwin_3d_frame, *graphwin_3d_width_label;
52 GtkWidget *graphwin_3d_height_label, *graphwin_3d_width, *graphwin_3d_height;
53 GtkWidget *graphwin_3d_xmin_label, *graphwin_3d_xmax_label, *graphwin_3d_xsteps_label;
54 GtkWidget *graphwin_3d_ymin_label, *graphwin_3d_ymax_label, *graphwin_3d_ysteps_label;
55 GtkWidget *graphwin_3d_zmin_label, *graphwin_3d_zmax_label;
56 GtkWidget *graphwin_3d_xmin, *graphwin_3d_xmax, *graphwin_3d_xsteps;
57 GtkWidget *graphwin_3d_ymin, *graphwin_3d_ymax, *graphwin_3d_ysteps;
58 GtkWidget *graphwin_3d_zmin, *graphwin_3d_zmax;
59 GtkWidget *graphwin_3d_notebook, *graphwin_buttonlabel_3d_draw;
60 #endif
61 GtkWidget *graphwin_width, *graphwin_height, *graphwin_xmin, *graphwin_xmax, *graphwin_ymin, *graphwin_ymax;
62 GtkWidget *graphwin_buttonlabel_settings, *graphwin_polar_start, *graphwin_polar_stop, *graphwin_polar_steps;
63 GtkWidget *graphwin_buttonlabel_draw, *graphwin_para_start, *graphwin_para_stop, *graphwin_para_steps;
64
65 GtkWidget *polarentrystart, *polarentrystop, *polarentrystep;
66 GtkWidget *parentrystart, *parentrystop, *parentrystep;
67 const gint max_len_entry = 100;
68
69 #ifdef PLOT_3D
70 #define PLOT_3D_FUNCTIONS 5
71 #endif
72
73 struct bunch
74 {
75 picture2gtk colorpic;
76 GtkWidget *check,*entry,*entry2,*button;
77 #ifdef PLOT_3D
78 GtkWidget *combo;
79 }func[10], polar[10], par[5], func_3d[PLOT_3D_FUNCTIONS];
80 Vector<picture_h::colorrgb> func_3d_colors[PLOT_3D_FUNCTIONS];
81 #else
82 }func[10], polar[10], par[5];
83 #endif
84
85
aboutwin_show_graphtool(void)86 void aboutwin_show_graphtool(void) { aboutwin_show(GTK_WINDOW(graphwin)); }
prefwin_show_graphtool(void)87 void prefwin_show_graphtool(void) { prefwin_show(GTK_WINDOW(graphwin)); }
88
89
90
91 void drawbutton_click(GtkButton *button,gpointer user_data);
92
93
colordialogcancel(GtkButton * button,gpointer user_data)94 void colordialogcancel(GtkButton *button,gpointer user_data)
95 {
96 GtkWidget *dialog = gtk_widget_get_toplevel(GTK_WIDGET(button));
97
98 if(GTK_WIDGET_TOPLEVEL(dialog))
99 gtk_widget_destroy(GTK_WIDGET(dialog));
100 }
101
colordialogok(GtkButton * button,gpointer user_data)102 void colordialogok(GtkButton *button,gpointer user_data)
103 {
104 GtkWidget *dialog = gtk_widget_get_toplevel(GTK_WIDGET(button));
105
106 if(GTK_WIDGET_TOPLEVEL(dialog))
107 {
108 if(graphwin == 0)
109 gtk_widget_destroy(GTK_WIDGET(dialog));
110
111 GdkColor color;
112 gtk_color_selection_get_current_color(
113 GTK_COLOR_SELECTION(GTK_COLOR_SELECTION_DIALOG(dialog)->colorsel), &color );
114 {
115 picture2gtk *tmp = (picture2gtk *) user_data;
116 picture_h::colorrgb colorr;
117
118 gdkcolor_to_colorrgb( color, colorr );
119
120 tmp->clear(colorr);
121 tmp->update();
122 }
123
124 gtk_widget_destroy(GTK_WIDGET(dialog));
125 }
126 }
127
colorbutton_click(GtkButton * button,gpointer user_data)128 void colorbutton_click(GtkButton *button,gpointer user_data)
129 {
130 GtkColorSelectionDialog *colordialog;
131 GdkColor color;
132
133 colorrgb_to_gdkcolor( ((picture2gtk *) user_data)->get_pixel(0,0), color );
134
135 colordialog = (GtkColorSelectionDialog *) gtk_color_selection_dialog_new(NULL);
136
137 gtk_color_selection_set_current_color(GTK_COLOR_SELECTION(colordialog->colorsel),&color);
138
139 g_signal_connect( GTK_OBJECT(colordialog->ok_button), "clicked", G_CALLBACK(colordialogok),
140 user_data);
141
142 g_signal_connect( GTK_OBJECT(colordialog->cancel_button), "clicked",
143 G_CALLBACK(colordialogcancel), user_data );
144
145 gtk_window_set_transient_for( GTK_WINDOW(colordialog), GTK_WINDOW(graphwin) );
146 gtk_window_set_modal( GTK_WINDOW(colordialog), TRUE );
147
148 gtk_widget_show_all( GTK_WIDGET(colordialog) );
149
150 gtk_widget_hide(colordialog->help_button);
151 }
152
drawbutton_click(GtkButton * button,gpointer user_data)153 void drawbutton_click(GtkButton *button,gpointer user_data)
154 {
155 try
156 {
157 settings.width = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(spinwidth));
158 settings.height = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(spinheight));
159 settings.xmin = gtk_entry_get_text(GTK_ENTRY(entryxmin));
160 settings.xmax = gtk_entry_get_text(GTK_ENTRY(entryxmax));
161 settings.ymin = gtk_entry_get_text(GTK_ENTRY(entryymin));
162 settings.ymax = gtk_entry_get_text(GTK_ENTRY(entryymax));
163
164 settings.grid_on = (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(checkgrid)) == TRUE) ? true : false;
165
166 settings.axes_on = (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(checkaxes)) == TRUE) ? true : false;
167
168 settings.active_page = gtk_notebook_get_current_page(GTK_NOTEBOOK(notebook));
169
170 for(int i=0;i<10;i++) // setting up all functions
171 {
172 settings.func[i].entry = gtk_entry_get_text(GTK_ENTRY(func[i].entry));
173 settings.func[i].color = func[i].colorpic.get_pixel(0,0);
174 settings.func[i].show_this = (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(func[i].check)) == TRUE) ? true : false;
175
176 settings.polar[i].entry = gtk_entry_get_text(GTK_ENTRY(polar[i].entry));
177 settings.polar[i].color = polar[i].colorpic.get_pixel(0,0);
178 settings.polar[i].show_this = (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(polar[i].check)) == TRUE) ? true : false;
179
180 if(i < 5)
181 {
182 settings.par[i].entry = gtk_entry_get_text(GTK_ENTRY(par[i].entry));
183 settings.par[i].entry2 = gtk_entry_get_text(GTK_ENTRY(par[i].entry2));
184 settings.par[i].color = par[i].colorpic.get_pixel(0,0);
185 settings.par[i].show_this = (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(par[i].check)) == TRUE) ? true : false;
186 }
187 }
188 settings.polar_start = gtk_entry_get_text(GTK_ENTRY(polarentrystart));
189 settings.polar_stop = gtk_entry_get_text(GTK_ENTRY(polarentrystop));
190 settings.polar_steps = gtk_entry_get_text(GTK_ENTRY(polarentrystep));
191
192 settings.par_start = gtk_entry_get_text(GTK_ENTRY(parentrystart));
193 settings.par_stop = gtk_entry_get_text(GTK_ENTRY(parentrystop));
194 settings.par_steps = gtk_entry_get_text(GTK_ENTRY(parentrystep));
195 }
196 catch(error_obj error)
197 {
198 (*TEXTVIEW_FUNCTION)(error.msg);
199 (*TEXTVIEW_FUNCTION)("\n");
200 }
201
202 picturewin_show( &settings );
203 }
204
entry_insert(GtkEditable * editable,gchar * new_text,gint new_text_length,gint * position)205 void entry_insert(GtkEditable *editable, gchar *new_text, gint new_text_length, gint *position)
206 {
207 for(gint i=0;i<new_text_length;i++)
208 {
209 if(new_text[i] == '\"')
210 new_text[i] = ' ';
211 }
212 }
entry_changed(GtkEditable * editable,gpointer user_data)213 void entry_changed(GtkEditable *editable,gpointer user_data)
214 {
215 bunch *tmp;
216 const gchar *str;
217 bool empty = true, empty2 = false;
218
219 tmp = (bunch *) user_data;
220
221 str = gtk_entry_get_text(GTK_ENTRY(tmp->entry));
222
223 if(str != 0)
224 {
225 for(int i=0;str[i] != 0;i++)
226 {
227 if(str[i] != ' ')
228 {
229 empty = false;
230 break;
231 }
232 }
233 }
234
235 if(tmp->entry2 != 0)
236 {
237 empty2 = true;
238 str = gtk_entry_get_text(GTK_ENTRY(tmp->entry2));
239
240 if(str != 0)
241 {
242 for(int i=0;str[i] != 0;i++)
243 {
244 if(str[i] != ' ')
245 {
246 empty2 = false;
247 break;
248 }
249 }
250 }
251 }
252
253 if( empty == true || empty2 == true )
254 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(tmp->check),FALSE);
255 else
256 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(tmp->check),TRUE);
257 }
checkbox_toggled(GtkToggleButton * togglebutton,gpointer user_data)258 void checkbox_toggled(GtkToggleButton *togglebutton, gpointer user_data)
259 {
260 bunch *tmp;
261 const gchar *str;
262 bool empty = true, empty2 = false;
263
264 if(gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON(togglebutton) ) == FALSE)
265 return;
266
267 tmp = (bunch *) user_data;
268
269 str = gtk_entry_get_text(GTK_ENTRY(tmp->entry));
270
271 if(str != 0)
272 {
273 for(int i=0;str[i] != 0;i++)
274 {
275 if(str[i] != ' ')
276 {
277 empty = false;
278 break;
279 }
280 }
281 }
282
283 if(tmp->entry2 != 0)
284 {
285 empty2 = true;
286 str = gtk_entry_get_text(GTK_ENTRY(tmp->entry2));
287
288 if(str != 0)
289 {
290 for(int i=0;str[i] != 0;i++)
291 {
292 if(str[i] != ' ')
293 {
294 empty2 = false;
295 break;
296 }
297 }
298 }
299 }
300
301 if(empty == true || empty2 == true)
302 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(togglebutton),FALSE);
303 else
304 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(togglebutton),TRUE);
305 }
306
307 #ifdef PLOT_3D
gradientbutton_click(GtkButton * button,gpointer user_data)308 void gradientbutton_click(GtkButton *button,gpointer user_data)
309 {
310 int i = GPOINTER_TO_INT(user_data);
311
312 gradient_editor( graphwin, func_3d_colors[i] );
313
314 for( int32 i2=0; i2<45; i2++ )
315 {
316 picture_h::colorrgb tmp_color;
317 math::color_list_get_color( func_3d_colors[i], 0.0, 44.0, floatx(44-i2), &tmp_color );
318 func_3d[i].colorpic.line( 0, i2, 18, i2, tmp_color );
319 }
320 func_3d[i].colorpic.update();
321 }
322
drawbutton_3d_click(GtkButton * button,gpointer user_data)323 void drawbutton_3d_click(GtkButton *button,gpointer user_data)
324 {
325 utf8_string str;
326 math::CodeLine function;
327
328 try
329 {
330 if( settings.show_code )
331 (*TEXTVIEW_FUNCTION)( "_3d_clear\n" );
332 function.set_code_line( "_3d_clear\n" );
333 function.calc( 0 );
334
335 str = "_3d_set_prop( \"Width\", ";
336 str.append( gtk_entry_get_text( GTK_ENTRY(graphwin_3d_width) ) );
337 str.append( ", \"Height\", " );
338 str.append( gtk_entry_get_text( GTK_ENTRY(graphwin_3d_height) ) );
339 str.append( ", \"Look at\", [[ ((" );
340 str.append( gtk_entry_get_text( GTK_ENTRY(graphwin_3d_xmin) ) );
341 str.append( ")+(" );
342 str.append( gtk_entry_get_text( GTK_ENTRY(graphwin_3d_xmax) ) );
343 str.append( "))/2 ][ ((" );
344 str.append( gtk_entry_get_text( GTK_ENTRY(graphwin_3d_ymin) ) );
345 str.append( ")+(" );
346 str.append( gtk_entry_get_text( GTK_ENTRY(graphwin_3d_ymax) ) );
347 str.append( "))/2 ][ ((" );
348 str.append( gtk_entry_get_text( GTK_ENTRY(graphwin_3d_zmin) ) );
349 str.append( ")+(" );
350 str.append( gtk_entry_get_text( GTK_ENTRY(graphwin_3d_zmax) ) );
351 str.append( "))/2 ]], \"Camera distance\", sqrt( |(" );
352 str.append( gtk_entry_get_text( GTK_ENTRY(graphwin_3d_xmin) ) );
353 str.append( ")-(" );
354 str.append( gtk_entry_get_text( GTK_ENTRY(graphwin_3d_xmax) ) );
355 str.append( ")|^2 + |(" );
356 str.append( gtk_entry_get_text( GTK_ENTRY(graphwin_3d_ymin) ) );
357 str.append( ")-(" );
358 str.append( gtk_entry_get_text( GTK_ENTRY(graphwin_3d_ymax) ) );
359 str.append( ")|^2 + |(" );
360 str.append( gtk_entry_get_text( GTK_ENTRY(graphwin_3d_zmin) ) );
361 str.append( ")-(" );
362 str.append( gtk_entry_get_text( GTK_ENTRY(graphwin_3d_zmax) ) );
363 str.append( ")|^2 ) )" );
364 if( settings.show_code )
365 {
366 (*TEXTVIEW_FUNCTION)( str );
367 (*TEXTVIEW_FUNCTION)( "\n" );
368 }
369 function.set_code_line( str.c_str() );
370 function.calc( 0 );
371
372 str = "plot_x_matrix = table( \"x\", x, dec( ";
373 str.append( gtk_entry_get_text( GTK_ENTRY(graphwin_3d_xmin) ) );
374 str.append( " ), dec( " );
375 str.append( gtk_entry_get_text( GTK_ENTRY(graphwin_3d_xmax) ) );
376 str.append( " ), " );
377 str.append( gtk_entry_get_text( GTK_ENTRY(graphwin_3d_xsteps) ) );
378 str.append( " )" );
379 if( settings.show_code )
380 {
381 (*TEXTVIEW_FUNCTION)( str );
382 (*TEXTVIEW_FUNCTION)( "\n" );
383 }
384 function.set_code_line( str.c_str() );
385 function.calc( 0 );
386
387 str = "plot_y_matrix = table( \"y\", y, dec( ";
388 str.append( gtk_entry_get_text( GTK_ENTRY(graphwin_3d_ymin) ) );
389 str.append( ") , dec( " );
390 str.append( gtk_entry_get_text( GTK_ENTRY(graphwin_3d_ymax) ) );
391 str.append( " ) , " );
392 str.append( gtk_entry_get_text( GTK_ENTRY(graphwin_3d_ysteps) ) );
393 str.append( " )" );
394 if( settings.show_code )
395 {
396 (*TEXTVIEW_FUNCTION)( str );
397 (*TEXTVIEW_FUNCTION)( "\n" );
398 }
399 function.set_code_line( str.c_str() );
400 function.calc( 0 );
401
402 for( int i=0; i<PLOT_3D_FUNCTIONS; i++ ) // setting up all functions
403 {
404 char number[3] = "z0";
405
406 number[1] = '0' + i;
407 str = number;
408 str.append( " = \"" );
409 str.append( gtk_entry_get_text( GTK_ENTRY(func_3d[i].entry) ) );
410 str.append( "\"" );
411 if( settings.show_code )
412 {
413 (*TEXTVIEW_FUNCTION)( str.c_str() );
414 (*TEXTVIEW_FUNCTION)("\n");
415 }
416 function.set_code_line( str.c_str() );
417 function.calc( 0 );
418 }
419
420
421 for( int i=0; i<PLOT_3D_FUNCTIONS; i++ )
422 {
423 char number[2] = "0";
424 if( gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(func_3d[i].check)) == TRUE )
425 {
426 str = "plot_z_matrix = table2d( z";
427 number[0] = '0' + i;
428 str.append( number );
429 str.append( ", x, dec( " );
430 str.append( gtk_entry_get_text( GTK_ENTRY(graphwin_3d_xmin) ) );
431 str.append( " ) , dec( " );
432 str.append( gtk_entry_get_text( GTK_ENTRY(graphwin_3d_xmax) ) );
433 str.append( " ), " );
434 str.append( gtk_entry_get_text( GTK_ENTRY(graphwin_3d_xsteps) ) );
435 str.append( ", y, dec( " );
436 str.append( gtk_entry_get_text( GTK_ENTRY(graphwin_3d_ymin) ) );
437 str.append( " ), dec( " );
438 str.append( gtk_entry_get_text( GTK_ENTRY(graphwin_3d_ymax) ) );
439 str.append( " ), " );
440 str.append( gtk_entry_get_text( GTK_ENTRY(graphwin_3d_ysteps) ) );
441 str.append( ", i )" );
442
443 if( settings.show_code )
444 {
445 (*TEXTVIEW_FUNCTION)( str );
446 (*TEXTVIEW_FUNCTION)( "\n" );
447 }
448 function.set_code_line( str.c_str() );
449 function.calc( 0 );
450
451 str = "_3d_add_plane( plot_x_matrix, plot_y_matrix, plot_z_matrix, \"";
452 switch( gtk_combo_box_get_active( GTK_COMBO_BOX(func_3d[i].combo) ) )
453 {
454 case 0: str.append( "Wireframed\", " ); break;
455 case 1: str.append( "Semi-solid\", " ); break;
456 default: str.append( "Solid\", " ); break;
457 }
458 str.append( gtk_entry_get_text( GTK_ENTRY(graphwin_3d_zmin) ) );
459 str.append( ", " );
460 str.append( gtk_entry_get_text( GTK_ENTRY(graphwin_3d_zmax) ) );
461 str.append( ", [" );
462
463 for( int i2=0; i2<func_3d_colors[i].get_size(); i2++ )
464 {
465 picture_h::colorrgb *tmp_color;
466
467 str.append( "[ " );
468
469 tmp_color = func_3d_colors[i][i2];
470 floatx_to_string( floatx(tmp_color->red)/255.0f, str, format );
471 str.append( ", " );
472 floatx_to_string( floatx(tmp_color->green)/255.0f, str, format );
473 str.append( ", " );
474 floatx_to_string( floatx(tmp_color->blue)/255.0f, str, format );
475
476 str.append( " ]" );
477 }
478 str.append( "] )" );
479
480 if( settings.show_code )
481 {
482 (*TEXTVIEW_FUNCTION)( str );
483 (*TEXTVIEW_FUNCTION)( "\n" );
484 }
485 function.set_code_line( str.c_str() );
486 function.calc( 0 );
487 }
488 }
489
490 if( settings.show_code )
491 (*TEXTVIEW_FUNCTION)( "_3d_render\n" );
492 function.set_code_line( "_3d_render\n" );
493 function.calc( 0 );
494 }
495 catch( error_obj error )
496 {
497 GtkWidget *dialog;
498
499 dialog = gtk_message_dialog_new( GTK_WINDOW(graphwin), GTK_DIALOG_DESTROY_WITH_PARENT,
500 GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, error.msg );
501 gtk_dialog_run( GTK_DIALOG(dialog) );
502 gtk_widget_destroy(dialog);
503 }
504 catch( ... )
505 {
506 try{ THROW_ERROR( ErrorType_Memory, _("Couldn't get memory.") ); }
507 catch( error_obj error )
508 {
509 GtkWidget *dialog;
510
511 dialog = gtk_message_dialog_new( GTK_WINDOW(graphwin), GTK_DIALOG_DESTROY_WITH_PARENT,
512 GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, error.msg );
513 gtk_dialog_run( GTK_DIALOG(dialog) );
514 gtk_widget_destroy(dialog);
515 }
516 }
517 }
518
graphwin_3d_tab_functions(void)519 GtkWidget *graphwin_3d_tab_functions(void)
520 {
521 #define NUM_GRADIENTS 3
522 static char gradients[NUM_GRADIENTS][30] =
523 {
524 "ff0000 0000ff ff00ff",
525 "ff00e0 ff0000 ffff00",
526 "0000ff 009090 000000 0000ff"
527 };
528
529 GtkWidget *table, *tmp;
530 char tmp_str[100];
531 bool tmp_bool;
532 const char *tmp_char_ptr;
533 const utf8_string *str;
534
535 table = gtk_table_new( PLOT_3D_FUNCTIONS*2, 4, FALSE );
536
537 gtk_container_set_border_width( GTK_CONTAINER(table), 3 );
538
539 for( int i=0; i<PLOT_3D_FUNCTIONS; i++ )
540 {
541 func_3d[i].entry2 = 0;
542 func_3d[i].entry = gtk_entry_new();
543
544 snprintf( tmp_str, 100, "GRAPHTOOL_3D_Z%ld_ENTRY", i );
545 gtk_entry_set_text( GTK_ENTRY(func_3d[i].entry),
546 setup_file.get_key_c_str(tmp_str, "") );
547 gtk_table_attach( GTK_TABLE(table), func_3d[i].entry, 1, 3, i*2, i*2+1,
548 GtkAttachOptions( GTK_EXPAND | GTK_FILL ), GtkAttachOptions(0), 0, 0 );
549
550 g_signal_connect( GTK_OBJECT(func_3d[i].entry), "changed",
551 G_CALLBACK(entry_changed), gpointer(&func_3d[i]) );
552 g_signal_connect( GTK_OBJECT(func_3d[i].entry), "insert-text",
553 G_CALLBACK(entry_insert), NULL );
554 g_signal_connect_swapped( GTK_OBJECT(func_3d[i].entry), "activate",
555 G_CALLBACK(drawbutton_3d_click), NULL );
556
557 func_3d[i].check = gtk_check_button_new();
558 g_signal_connect( GTK_OBJECT(func_3d[i].check), "toggled",
559 G_CALLBACK(checkbox_toggled), gpointer(&func_3d[i]) );
560
561 snprintf( tmp_str, 100, "GRAPHTOOL_3D_Z%ld_SHOW", i );
562 GET_BOOLEAN_KEY( tmp_str, tmp_bool );
563 gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON(func_3d[i].check), tmp_bool ? TRUE : FALSE );
564 gtk_table_attach( GTK_TABLE(table), func_3d[i].check, 0, 1, i*2, i*2+1, GTK_FILL,
565 GtkAttachOptions(0), 1, 1 );
566
567 snprintf( tmp_str, 100, "z_%ld=", i );
568 tmp = gtk_label_new_with_mnemonic( tmp_str );
569 gtk_label_set_mnemonic_widget( GTK_LABEL(tmp), func_3d[i].entry );
570 gtk_container_add( GTK_CONTAINER(func_3d[i].check), tmp) ;
571
572 func_3d[i].combo = gtk_combo_box_new_text();
573 gtk_combo_box_append_text( GTK_COMBO_BOX(func_3d[i].combo), "Wireframed" );
574 gtk_combo_box_append_text( GTK_COMBO_BOX(func_3d[i].combo), "Semi-solid" );
575 gtk_combo_box_append_text( GTK_COMBO_BOX(func_3d[i].combo), "Solid" );
576
577 snprintf( tmp_str, 100, "GRAPHTOOL_3D_Z%ld_DRAW_MODE", i );
578 tmp_char_ptr = setup_file.get_key_c_str(tmp_str, "Semi-solid");
579 if( strcmp( tmp_char_ptr, "Wireframed" ) == 0 )
580 gtk_combo_box_set_active( GTK_COMBO_BOX(func_3d[i].combo), 0 );
581 else if( strcmp( tmp_char_ptr, "Semi-solid" ) == 0 )
582 gtk_combo_box_set_active( GTK_COMBO_BOX(func_3d[i].combo), 1 );
583 else // if( strcmp( tmp_char_ptr, "Solid" ) == 0 )
584 gtk_combo_box_set_active( GTK_COMBO_BOX(func_3d[i].combo), 2 );
585 gtk_table_attach( GTK_TABLE(table), func_3d[i].combo, 1, 2, i*2+1, i*2+2,
586 GTK_FILL, GtkAttachOptions(0), 1, 1 );
587
588 func_3d[i].button = gtk_button_new();
589 g_signal_connect( GTK_OBJECT(func_3d[i].button), "clicked",
590 G_CALLBACK(gradientbutton_click), GINT_TO_POINTER(i) );
591
592 snprintf( tmp_str, 100, "GRAPHTOOL_3D_Z%ld_COLOR", i );
593 tmp_char_ptr = setup_file.get_key_c_str( tmp_str, gradients[i%NUM_GRADIENTS] );
594 hexstring_to_colorrgbs( tmp_char_ptr, func_3d_colors[i] );
595 tmp = gtk_drawing_area_new();
596 func_3d[i].colorpic.set_size( 19, 45 );
597
598 for( int32 i2=0; i2<45; i2++ )
599 {
600 picture_h::colorrgb tmp_color;
601 math::color_list_get_color( func_3d_colors[i], 0.0, 44.0, floatx(44-i2), &tmp_color );
602 func_3d[i].colorpic.line( 0, i2, 18, i2, tmp_color );
603 }
604 func_3d[i].colorpic.connect_to_drawing_area(tmp);
605 func_3d[i].colorpic.update();
606 gtk_container_add( GTK_CONTAINER(func_3d[i].button), tmp );
607
608 gtk_table_attach( GTK_TABLE(table), func_3d[i].button, 3, 4, i*2, i*2+2,
609 GtkAttachOptions(0), GtkAttachOptions(0), 1, 1 );
610 }
611
612 return table;
613 }
614
graphwin_3d_tab(void)615 GtkWidget *graphwin_3d_tab(void)
616 {
617 GtkWidget *vbox, *table;
618 const char *tmp_char_ptr;
619 int tmp_int;
620
621 vbox = gtk_vbox_new( FALSE, 3 );
622 gtk_container_set_border_width( GTK_CONTAINER(vbox), 3 );
623
624 graphwin_3d_frame = gtk_frame_new(0);
625 gtk_box_pack_start( GTK_BOX(vbox), graphwin_3d_frame, FALSE, FALSE, 0 );
626
627 table = gtk_table_new( 4, 6, FALSE );
628 gtk_container_set_border_width( GTK_CONTAINER(table), 3 );
629 gtk_container_add( GTK_CONTAINER(graphwin_3d_frame), table );
630
631 graphwin_3d_width_label = gtk_label_new(0);
632 gtk_table_attach( GTK_TABLE(table), graphwin_3d_width_label, 0, 1, 0, 1, GTK_FILL,
633 GtkAttachOptions(0), 3, 3 );
634 gtk_misc_set_alignment( GTK_MISC(graphwin_3d_width_label), 1, 0.5 );
635 graphwin_3d_height_label = gtk_label_new(0);
636 gtk_table_attach( GTK_TABLE(table), graphwin_3d_height_label, 0, 1, 1, 2, GTK_FILL,
637 GtkAttachOptions(0), 3, 3 );
638 gtk_misc_set_alignment( GTK_MISC(graphwin_3d_height_label), 1, 0.5 );
639
640 if( (tmp_char_ptr = setup_file.get_key_c_str("GRAPHTOOL_3D_WIDTH")) != 0 )
641 {
642 if(sscanf( tmp_char_ptr, "%ld", &tmp_int ) == 1)
643 {
644 if( tmp_int < 2 && tmp_int > 2000 )
645 tmp_int = 400;
646 }
647 else
648 tmp_int = 400;
649 }
650 else
651 tmp_int = 400;
652 graphwin_3d_width = gtk_spin_button_new_with_range( 2, 2000, 1 );
653 gtk_spin_button_set_value( GTK_SPIN_BUTTON(graphwin_3d_width), tmp_int );
654 gtk_table_attach( GTK_TABLE(table), graphwin_3d_width, 1, 2, 0, 1,
655 GtkAttachOptions(GTK_EXPAND | GTK_FILL), GtkAttachOptions(0), 3, 3 );
656 gtk_label_set_mnemonic_widget( GTK_LABEL(graphwin_3d_width_label), graphwin_3d_width );
657 if( (tmp_char_ptr = setup_file.get_key_c_str("GRAPHTOOL_3D_HEIGHT")) != 0 )
658 {
659 if(sscanf( tmp_char_ptr, "%ld", &tmp_int ) == 1)
660 {
661 if( tmp_int < 2 && tmp_int > 2000 )
662 tmp_int = 400;
663 }
664 else
665 tmp_int = 400;
666 }
667 else
668 tmp_int = 400;
669 graphwin_3d_height = gtk_spin_button_new_with_range( 2, 2000, 1 );
670 gtk_spin_button_set_value( GTK_SPIN_BUTTON(graphwin_3d_height), tmp_int );
671 gtk_table_attach( GTK_TABLE(table), graphwin_3d_height, 1, 2, 1, 2,
672 GtkAttachOptions(GTK_EXPAND | GTK_FILL), GtkAttachOptions(0), 3, 3 );
673 gtk_label_set_mnemonic_widget( GTK_LABEL(graphwin_3d_height_label), graphwin_3d_height );
674
675 graphwin_3d_xmin_label = gtk_label_new(0);
676 gtk_table_attach( GTK_TABLE(table), graphwin_3d_xmin_label, 2, 3, 0, 1, GTK_FILL,
677 GtkAttachOptions(0), 3, 3 );
678 gtk_misc_set_alignment( GTK_MISC(graphwin_3d_xmin_label), 1, 0.5 );
679 graphwin_3d_xmax_label = gtk_label_new(0);
680 gtk_table_attach( GTK_TABLE(table), graphwin_3d_xmax_label, 2, 3, 1, 2, GTK_FILL,
681 GtkAttachOptions(0), 3, 3 );
682 gtk_misc_set_alignment( GTK_MISC(graphwin_3d_xmax_label), 1, 0.5 );
683 graphwin_3d_xsteps_label = gtk_label_new(0);
684 gtk_table_attach( GTK_TABLE(table), graphwin_3d_xsteps_label, 2, 3, 2, 3, GTK_FILL,
685 GtkAttachOptions(0), 3, 3 );
686 gtk_misc_set_alignment( GTK_MISC(graphwin_3d_xsteps_label), 1, 0.5 );
687 graphwin_3d_ymin_label = gtk_label_new(0);
688 gtk_table_attach( GTK_TABLE(table), graphwin_3d_ymin_label, 4, 5, 0, 1, GTK_FILL,
689 GtkAttachOptions(0), 3, 3 );
690 gtk_misc_set_alignment( GTK_MISC(graphwin_3d_ymin_label), 1, 0.5 );
691 graphwin_3d_ymax_label = gtk_label_new(0);
692 gtk_table_attach( GTK_TABLE(table), graphwin_3d_ymax_label, 4, 5, 1, 2, GTK_FILL,
693 GtkAttachOptions(0), 3, 3 );
694 gtk_misc_set_alignment( GTK_MISC(graphwin_3d_ymax_label), 1, 0.5 );
695 graphwin_3d_ysteps_label = gtk_label_new(0);
696 gtk_table_attach( GTK_TABLE(table), graphwin_3d_ysteps_label, 4, 5, 2, 3, GTK_FILL,
697 GtkAttachOptions(0), 3, 3 );
698 gtk_misc_set_alignment( GTK_MISC(graphwin_3d_ysteps_label), 1, 0.5 );
699
700 graphwin_3d_xmin = gtk_entry_new();
701 gtk_entry_set_text( GTK_ENTRY(graphwin_3d_xmin),
702 setup_file.get_key_c_str("GRAPHTOOL_3D_XMIN","-10") );
703 gtk_table_attach( GTK_TABLE(table), graphwin_3d_xmin, 3, 4, 0, 1,
704 GtkAttachOptions(GTK_EXPAND | GTK_FILL), GtkAttachOptions(0), 3, 3 );
705 graphwin_3d_xmax = gtk_entry_new();
706 gtk_entry_set_text( GTK_ENTRY(graphwin_3d_xmax),
707 setup_file.get_key_c_str("GRAPHTOOL_3D_XMAX","10") );
708 gtk_table_attach( GTK_TABLE(table), graphwin_3d_xmax, 3, 4, 1, 2,
709 GtkAttachOptions(GTK_EXPAND | GTK_FILL), GtkAttachOptions(0), 3, 3 );
710 graphwin_3d_xsteps = gtk_spin_button_new_with_range( 1, 10000, 1 );
711 gtk_spin_button_set_value( GTK_SPIN_BUTTON(graphwin_3d_xsteps), atoi(setup_file.get_key_c_str("GRAPHTOOL_3D_XSTEPS","50") ) );
712 gtk_table_attach( GTK_TABLE(table), graphwin_3d_xsteps, 3, 4, 2, 3,
713 GtkAttachOptions(GTK_EXPAND | GTK_FILL), GtkAttachOptions(0), 3, 3 );
714 graphwin_3d_ymin = gtk_entry_new();
715 gtk_entry_set_text( GTK_ENTRY(graphwin_3d_ymin),
716 setup_file.get_key_c_str("GRAPHTOOL_3D_YMIN","-10") );
717 gtk_table_attach( GTK_TABLE(table), graphwin_3d_ymin, 5, 6, 0, 1,
718 GtkAttachOptions(GTK_EXPAND | GTK_FILL), GtkAttachOptions(0), 3, 3 );
719 graphwin_3d_ymax = gtk_entry_new();
720 gtk_entry_set_text( GTK_ENTRY(graphwin_3d_ymax),
721 setup_file.get_key_c_str("GRAPHTOOL_3D_YMAX","10") );
722 gtk_table_attach( GTK_TABLE(table), graphwin_3d_ymax, 5, 6, 1, 2,
723 GtkAttachOptions(GTK_EXPAND | GTK_FILL), GtkAttachOptions(0), 3, 3 );
724 graphwin_3d_ysteps = gtk_spin_button_new_with_range( 1, 10000, 1 );
725 gtk_spin_button_set_value( GTK_SPIN_BUTTON(graphwin_3d_ysteps), atoi(setup_file.get_key_c_str("GRAPHTOOL_3D_YSTEPS","50") ) );
726 gtk_table_attach( GTK_TABLE(table), graphwin_3d_ysteps, 5, 6, 2, 3,
727 GtkAttachOptions(GTK_EXPAND | GTK_FILL), GtkAttachOptions(0), 3, 3 );
728
729 graphwin_3d_zmin_label = gtk_label_new(0);
730 gtk_table_attach( GTK_TABLE(table), graphwin_3d_zmin_label, 2, 3, 3, 4, GTK_FILL,
731 GtkAttachOptions(0), 3, 3 );
732 gtk_misc_set_alignment( GTK_MISC(graphwin_3d_zmin_label), 1, 0.5 );
733 graphwin_3d_zmax_label = gtk_label_new(0);
734 gtk_table_attach( GTK_TABLE(table), graphwin_3d_zmax_label, 4, 5, 3, 4, GTK_FILL,
735 GtkAttachOptions(0), 3, 3 );
736 gtk_misc_set_alignment( GTK_MISC(graphwin_3d_zmax_label), 1, 0.5 );
737 graphwin_3d_zmin = gtk_entry_new();
738 gtk_entry_set_text( GTK_ENTRY(graphwin_3d_zmin),
739 setup_file.get_key_c_str("GRAPHTOOL_3D_ZMIN","-10") );
740 gtk_table_attach( GTK_TABLE(table), graphwin_3d_zmin, 3, 4, 3, 4,
741 GtkAttachOptions(GTK_EXPAND | GTK_FILL), GtkAttachOptions(0), 3, 3 );
742 graphwin_3d_zmax = gtk_entry_new();
743 gtk_entry_set_text( GTK_ENTRY(graphwin_3d_zmax),
744 setup_file.get_key_c_str("GRAPHTOOL_3D_ZMAX","10") );
745 gtk_table_attach( GTK_TABLE(table), graphwin_3d_zmax, 5, 6, 3, 4,
746 GtkAttachOptions(GTK_EXPAND | GTK_FILL), GtkAttachOptions(0), 3, 3 );
747
748
749 gtk_label_set_mnemonic_widget( GTK_LABEL(graphwin_3d_xmin_label), graphwin_3d_xmin );
750 gtk_label_set_mnemonic_widget( GTK_LABEL(graphwin_3d_xmax_label), graphwin_3d_xmax );
751 gtk_label_set_mnemonic_widget( GTK_LABEL(graphwin_3d_xsteps_label), graphwin_3d_xsteps );
752 gtk_label_set_mnemonic_widget( GTK_LABEL(graphwin_3d_ymin_label), graphwin_3d_ymin );
753 gtk_label_set_mnemonic_widget( GTK_LABEL(graphwin_3d_ymax_label), graphwin_3d_ymax );
754 gtk_label_set_mnemonic_widget( GTK_LABEL(graphwin_3d_ysteps_label), graphwin_3d_ysteps );
755 gtk_label_set_mnemonic_widget( GTK_LABEL(graphwin_3d_zmin_label), graphwin_3d_zmin );
756 gtk_label_set_mnemonic_widget( GTK_LABEL(graphwin_3d_zmax_label), graphwin_3d_zmax );
757
758
759
760 graphwin_3d_notebook = gtk_notebook_new();
761 gtk_box_pack_start( GTK_BOX(vbox), graphwin_3d_notebook, TRUE, TRUE, 0 );
762 gtk_notebook_append_page( GTK_NOTEBOOK(graphwin_3d_notebook), graphwin_3d_tab_functions(), 0 );
763
764 {
765 GtkWidget *box = gtk_hbox_new( FALSE, 0 );
766 GtkWidget *tmpimg,*tmpbox,*drawbutton;
767 tmpimg = gtk_image_new_from_stock( GTK_STOCK_CLEAR, GTK_ICON_SIZE_BUTTON );
768 graphwin_buttonlabel_3d_draw = gtk_label_new( 0 );
769 tmpbox = gtk_hbox_new( FALSE, 0 );
770 gtk_box_pack_start( GTK_BOX(tmpbox), tmpimg, FALSE, FALSE, 2 );
771 gtk_box_pack_start( GTK_BOX(tmpbox), graphwin_buttonlabel_3d_draw, FALSE, FALSE, 2 );
772 drawbutton = gtk_button_new();
773 gtk_container_add( GTK_CONTAINER(drawbutton), tmpbox );
774
775 g_signal_connect( GTK_OBJECT(drawbutton), "clicked",
776 G_CALLBACK(drawbutton_3d_click), gpointer(0) );
777 gtk_box_pack_start( GTK_BOX(box), drawbutton, FALSE, FALSE, 0 );
778
779 gtk_box_pack_start( GTK_BOX(vbox), box, FALSE, FALSE, 0 );
780 }
781
782 return vbox;
783 }
784 #endif
785
786
graphwin_load_settings(void)787 void graphwin_load_settings(void)
788 {
789 char tmpstr[50];
790 const char *tmp;
791 const utf8_string *str;
792
793 if((str = setup_file.get_key("GRAPHTOOL_WIDTH")) != 0)
794 {
795 int32 width;
796 if(sscanf( str->c_str(), "%ld", &width ) == 1)
797 {
798 if( width >= 2 && width <= 2000 )
799 settings.width = width;
800 }
801 }
802 if((str = setup_file.get_key("GRAPHTOOL_HEIGHT")) != 0)
803 {
804 int32 height;
805 if(sscanf( str->c_str(), "%ld", &height ) == 1)
806 {
807 if( height >= 2 && height <= 2000 )
808 settings.height = height;
809 }
810 }
811 if((str = setup_file.get_key("GRAPHTOOL_XMIN")) != 0)
812 settings.xmin = *str;
813 if((str = setup_file.get_key("GRAPHTOOL_XMAX")) != 0)
814 settings.xmax = *str;
815 if((str = setup_file.get_key("GRAPHTOOL_YMIN")) != 0)
816 settings.ymin = *str;
817 if((str = setup_file.get_key("GRAPHTOOL_YMAX")) != 0)
818 settings.ymax = *str;
819
820 if((tmp = setup_file.get_key_c_str( "GRAPHTOOL_BGCOLOR" )) != 0)
821 hexstring_to_colorrgb( tmp, settings.bgcolor );
822
823 if((tmp = setup_file.get_key_c_str( "GRAPHTOOL_AXES_COLOR" )) != 0)
824 hexstring_to_colorrgb( tmp, settings.axes_color );
825
826 if((tmp = setup_file.get_key_c_str( "GRAPHTOOL_GRID_COLOR" )) != 0)
827 hexstring_to_colorrgb( tmp, settings.grid_color );
828
829 GET_BOOLEAN_KEY( "GRAPHTOOL_ANTIALIASING", settings.use_antialiasing );
830 GET_BOOLEAN_KEY( "GRAPHTOOL_SHOW_CODE", settings.show_code );
831 GET_BOOLEAN_KEY( "GRAPHTOOL_AXES_ON", settings.axes_on );
832 GET_BOOLEAN_KEY( "GRAPHTOOL_GRID_ON", settings.grid_on );
833 if((str = setup_file.get_key("GRAPHTOOL_PLOT_MODE")) != 0)
834 settings.plot_mode = *str;
835 GET_BOOLEAN_KEY( "GRAPHTOOL_SHOW_ACTIVE_PAGE_ONLY", settings.show_active_page_only );
836
837 if((tmp = setup_file.get_key_c_str("GRAPHTOOL_ACTIVE_PAGE")) != 0)
838 {
839 int val;
840 if(sscanf( tmp, "%ld", &val ) == 1)
841 {
842 if( val >= 0 && val <= 2 )
843 settings.active_page = val;
844 }
845 }
846
847 if((str = setup_file.get_key("GRAPHTOOL_GRID_SCALE1")) != 0)
848 settings.grid_scale1 = *str;
849 if((str = setup_file.get_key("GRAPHTOOL_GRID_SCALE2")) != 0)
850 settings.grid_scale2 = *str;
851 if((str = setup_file.get_key("GRAPHTOOL_GRID_TYPE")) != 0)
852 settings.grid_type = *str;
853 if((str = setup_file.get_key("GRAPHTOOL_AXES_SCALEX")) != 0)
854 settings.scalex = *str;
855 if((str = setup_file.get_key("GRAPHTOOL_AXES_SCALEY")) != 0)
856 settings.scaley = *str;
857 if((tmp = setup_file.get_key_c_str("GRAPHTOOL_AXES_SCALE_LENGTH")) != 0)
858 {
859 int val;
860 if(sscanf( tmp, "%ld", &val ) == 1)
861 {
862 if( val >= 0 && val <= 100 )
863 settings.scale_length = val;
864 }
865 }
866
867 if((str = setup_file.get_key("GRAPHTOOL_POLAR_START")) != 0)
868 settings.polar_start = *str;
869 if((str = setup_file.get_key("GRAPHTOOL_POLAR_STOP")) != 0)
870 settings.polar_stop = *str;
871 if((str = setup_file.get_key("GRAPHTOOL_POLAR_STEPS")) != 0)
872 settings.polar_steps = *str;
873 if((str = setup_file.get_key("GRAPHTOOL_PAR_START")) != 0)
874 settings.par_start = *str;
875 if((str = setup_file.get_key("GRAPHTOOL_PAR_STOP")) != 0)
876 settings.par_stop = *str;
877 if((str = setup_file.get_key("GRAPHTOOL_PAR_STEPS")) != 0)
878 settings.par_steps = *str;
879
880 for(int i=0;i<10;i++)
881 {
882 snprintf( tmpstr, 50, "GRAPHTOOL_Y%lu_SHOW", i );
883 GET_BOOLEAN_KEY( tmpstr, settings.func[i].show_this );
884
885 snprintf( tmpstr, 50, "GRAPHTOOL_Y%lu_ENTRY", i );
886 if((str = setup_file.get_key( tmpstr )) != 0)
887 settings.func[i].entry = *str;
888
889 snprintf( tmpstr, 50, "GRAPHTOOL_Y%lu_COLOR", i );
890 if((tmp = setup_file.get_key_c_str( tmpstr )) != 0)
891 hexstring_to_colorrgb( tmp, settings.func[i].color );
892
893 snprintf( tmpstr, 50, "GRAPHTOOL_R%lu_SHOW", i );
894 GET_BOOLEAN_KEY( tmpstr, settings.polar[i].show_this );
895
896 snprintf( tmpstr, 50, "GRAPHTOOL_R%lu_ENTRY", i );
897 if((str = setup_file.get_key( tmpstr )) != 0)
898 settings.polar[i].entry = *str;
899
900 snprintf( tmpstr, 50, "GRAPHTOOL_R%lu_COLOR", i );
901 if((tmp = setup_file.get_key_c_str( tmpstr )) != 0)
902 hexstring_to_colorrgb( tmp, settings.polar[i].color );
903
904 if(i<5)
905 {
906 snprintf( tmpstr, 50, "GRAPHTOOL_XF%lu_SHOW", i );
907 GET_BOOLEAN_KEY( tmpstr, settings.par[i].show_this );
908
909 snprintf( tmpstr, 50, "GRAPHTOOL_XF%lu_ENTRY", i );
910 if((str = setup_file.get_key( tmpstr )) != 0)
911 settings.par[i].entry = *str;
912
913 snprintf( tmpstr, 50, "GRAPHTOOL_YF%lu_ENTRY", i );
914 if((str = setup_file.get_key( tmpstr )) != 0)
915 settings.par[i].entry2 = *str;
916
917 snprintf( tmpstr, 50, "GRAPHTOOL_XF%lu_COLOR", i );
918 if((tmp = setup_file.get_key_c_str( tmpstr )) != 0)
919 hexstring_to_colorrgb( tmp, settings.par[i].color );
920 }
921 }
922 }
923
graphwin_build_menu(void)924 GtkWidget* graphwin_build_menu(void)
925 {
926 GtkActionGroup *actions;
927 GtkUIManager *ui_manager;
928 GError *error = NULL;
929 static const gchar *menu =
930 "<ui>"
931 " <menubar>"
932 " <menu action='FileMenu'>"
933 " <menuitem action='Preferences'/>"
934 " <separator/>"
935 " <menuitem action='Close'/>"
936 " <separator/>"
937 " <menuitem action='Quit'/>"
938 " </menu>"
939 " <menu action='ToolsMenu'>"
940 " <menuitem action='Simple'/>"
941 " <menuitem action='Advanced'/>"
942 " <menuitem action='Editor'/>"
943 " <menuitem action='MatrixEdit'/>"
944 " </menu>"
945 " <menuitem action='About'/>"
946 " </menubar>"
947 "</ui>";
948 GtkActionEntry entries[] = {
949 { "FileMenu", NULL, menu_file },
950 { "Preferences", GTK_STOCK_PREFERENCES, menu_pref, NULL, NULL, G_CALLBACK(prefwin_show_graphtool) },
951 { "Close", GTK_STOCK_CLOSE, menu_file_close, "<ctrl>W", NULL, G_CALLBACK(graphwin_close) },
952 { "Quit", GTK_STOCK_QUIT, menu_file_quit, "<ctrl>Q", NULL, G_CALLBACK(UMP_gtk_quit) },
953 { "ToolsMenu", NULL, menu_tools },
954 { "Simple", NULL, menu_tools_simple, NULL, NULL, G_CALLBACK(simplewin_show) },
955 { "Advanced", NULL, menu_tools_advanced, NULL, NULL, G_CALLBACK(advancedwin_show) },
956 { "Editor", NULL, menu_tools_editor, NULL, NULL, G_CALLBACK(editor_showwin) },
957 { "MatrixEdit", NULL, menu_tools_matrixedit,NULL, NULL, G_CALLBACK(matrix_editor_show) },
958 { "About", NULL, menu_about, NULL, NULL, G_CALLBACK(aboutwin_show_graphtool) }
959 };
960 guint n_entries = G_N_ELEMENTS(entries);
961
962 actions = gtk_action_group_new("Actions");
963 gtk_action_group_add_actions(actions, entries, n_entries, NULL);
964 ui_manager = gtk_ui_manager_new();
965 gtk_ui_manager_insert_action_group(ui_manager, actions, 0);
966 gtk_window_add_accel_group( GTK_WINDOW(graphwin), gtk_ui_manager_get_accel_group(ui_manager) );
967 if (!gtk_ui_manager_add_ui_from_string(ui_manager, menu, -1, &error))
968 {
969 g_message("building menus failed: %s", error->message);
970 g_error_free(error);
971 return 0;
972 }
973 gtk_ui_manager_ensure_update(ui_manager);
974
975 return gtk_ui_manager_get_widget(ui_manager, "/menubar");
976 }
977
graphwin_show(void)978 GtkWindow* graphwin_show(void)
979 {
980 GtkWidget *table,*tmp,*box2,*box3,*drawbutton;
981 GtkAdjustment *adj;
982 char tmp_str[10];
983
984 if(graphwin == 0)
985 {
986 graphwin_load_settings();
987
988 graphwin = gtk_window_new(GTK_WINDOW_TOPLEVEL);
989
990 gtk_window_set_title(GTK_WINDOW(graphwin), _("Ump - Graph tools") );
991 g_signal_connect_swapped( GTK_OBJECT(graphwin), "delete-event", G_CALLBACK(graphwin_close), NULL );
992
993
994 graphwin_vbox_top = gtk_vbox_new(FALSE, 0);
995 gtk_container_add(GTK_CONTAINER(graphwin),graphwin_vbox_top);
996
997 if((graphwin_menu = graphwin_build_menu()) == 0)
998 {
999 gtk_widget_destroy( graphwin );
1000 graphwin = 0;
1001 return 0;
1002 }
1003
1004 gtk_box_pack_start( GTK_BOX(graphwin_vbox_top), graphwin_menu, FALSE, FALSE, 0 );
1005
1006 tmp = gtk_alignment_new( 0.5, 0.5, 1.0, 1.0 );
1007 gtk_alignment_set_padding( GTK_ALIGNMENT(tmp), 3, 4, 3, 3 );
1008 gtk_box_pack_start( GTK_BOX(graphwin_vbox_top), tmp, FALSE, FALSE, 0 );
1009
1010 graphwin_vbox = gtk_vbox_new( FALSE, 3 );
1011 #ifdef PLOT_3D
1012 notebook_2d_3d = gtk_notebook_new();
1013 gtk_notebook_append_page( GTK_NOTEBOOK(notebook_2d_3d), graphwin_vbox, gtk_label_new(0) );
1014
1015 gtk_notebook_append_page( GTK_NOTEBOOK(notebook_2d_3d), graphwin_3d_tab(), gtk_label_new(0) );
1016
1017 gtk_container_add( GTK_CONTAINER(tmp), notebook_2d_3d );
1018 #else
1019 gtk_container_add( GTK_CONTAINER(tmp), graphwin_vbox );
1020 #endif
1021
1022
1023 graphwin_plot_frame = gtk_frame_new( 0 );
1024 gtk_box_pack_start( GTK_BOX(graphwin_vbox), graphwin_plot_frame, FALSE, FALSE, 0 );
1025 gtk_container_set_border_width( GTK_CONTAINER(graphwin_plot_frame), 2 );
1026
1027 table = gtk_table_new(3, 6, FALSE);
1028 gtk_table_set_row_spacings( GTK_TABLE(table), 2 );
1029 gtk_table_set_col_spacings( GTK_TABLE(table), 2 );
1030 gtk_container_set_border_width( GTK_CONTAINER(table), 2 );
1031 gtk_container_add( GTK_CONTAINER(graphwin_plot_frame), table );
1032
1033 graphwin_width = gtk_label_new( 0 );
1034 gtk_table_attach( GTK_TABLE(table), graphwin_width, 0, 1, 0, 1, GTK_FILL,
1035 GtkAttachOptions(0), 1, 1 );
1036 gtk_misc_set_alignment(GTK_MISC (graphwin_width), 1, 0.5);
1037
1038 adj = (GtkAdjustment *) gtk_adjustment_new(settings.width, 2, 2000, 1, 10, 10);
1039 spinwidth = gtk_spin_button_new(adj, 1, 0);
1040 gtk_table_attach( GTK_TABLE(table), spinwidth, 1, 2, 0, 1,
1041 GtkAttachOptions(GTK_EXPAND | GTK_FILL), GtkAttachOptions(0), 1, 1 );
1042 gtk_label_set_mnemonic_widget( GTK_LABEL(graphwin_width), spinwidth );
1043
1044 graphwin_height = gtk_label_new( 0 );
1045 gtk_table_attach( GTK_TABLE(table), graphwin_height, 0, 1, 1, 2, GTK_FILL,
1046 GtkAttachOptions(0), 1, 1);
1047 gtk_misc_set_alignment( GTK_MISC(graphwin_height), 1, 0.5 );
1048
1049 adj = (GtkAdjustment *) gtk_adjustment_new(settings.height, 2, 2000, 1, 10, 10);
1050 spinheight = gtk_spin_button_new(adj, 1, 0);
1051 gtk_table_attach( GTK_TABLE(table), spinheight, 1, 2, 1, 2,
1052 GtkAttachOptions(GTK_EXPAND | GTK_FILL),GtkAttachOptions(0), 1, 1 );
1053 gtk_label_set_mnemonic_widget( GTK_LABEL(graphwin_height), spinheight );
1054
1055 graphwin_xmin = gtk_label_new( 0 );
1056 gtk_table_attach( GTK_TABLE(table), graphwin_xmin, 2, 3, 0, 1, GTK_FILL,
1057 GtkAttachOptions(0), 1, 1);
1058 gtk_misc_set_alignment(GTK_MISC (graphwin_xmin), 1, 0.5);
1059
1060 graphwin_xmax = gtk_label_new( 0 );
1061 gtk_table_attach( GTK_TABLE(table), graphwin_xmax, 2, 3, 1, 2, GTK_FILL,
1062 GtkAttachOptions(0), 1, 1 );
1063 gtk_misc_set_alignment(GTK_MISC (graphwin_xmax), 1, 0.5);
1064
1065 entryxmin = gtk_entry_new();
1066 gtk_table_attach( GTK_TABLE(table), entryxmin, 3, 4, 0, 1,
1067 GtkAttachOptions(GTK_EXPAND | GTK_FILL), GtkAttachOptions(0), 1, 1 );
1068 gtk_entry_set_max_length(GTK_ENTRY (entryxmin), 20);
1069 gtk_entry_set_text(GTK_ENTRY(entryxmin), settings.xmin.c_str() );
1070 gtk_label_set_mnemonic_widget( GTK_LABEL(graphwin_xmin), entryxmin );
1071
1072 entryxmax = gtk_entry_new();
1073 gtk_table_attach( GTK_TABLE(table), entryxmax, 3, 4, 1, 2,
1074 GtkAttachOptions(GTK_EXPAND | GTK_FILL), GtkAttachOptions(0), 1, 1 );
1075 gtk_entry_set_max_length(GTK_ENTRY(entryxmax), 20);
1076 gtk_entry_set_text(GTK_ENTRY(entryxmax), settings.xmax.c_str() );
1077 gtk_label_set_mnemonic_widget( GTK_LABEL(graphwin_xmax), entryxmax );
1078
1079 graphwin_ymin = gtk_label_new( 0 );
1080 gtk_table_attach( GTK_TABLE(table), graphwin_ymin, 4, 5, 0, 1, GTK_FILL,
1081 GtkAttachOptions(0), 1, 1 );
1082 gtk_misc_set_alignment(GTK_MISC (graphwin_ymin), 1, 0.5);
1083
1084 graphwin_ymax = gtk_label_new( 0 );
1085 gtk_table_attach( GTK_TABLE(table), graphwin_ymax, 4, 5, 1, 2, GTK_FILL,
1086 GtkAttachOptions(0), 1, 1 );
1087 gtk_misc_set_alignment(GTK_MISC (graphwin_ymax), 1, 0.5);
1088
1089 entryymin = gtk_entry_new();
1090 gtk_table_attach( GTK_TABLE(table), entryymin, 5, 6, 0, 1,
1091 GtkAttachOptions(GTK_EXPAND | GTK_FILL), GtkAttachOptions(0), 1, 1 );
1092 gtk_entry_set_max_length(GTK_ENTRY (entryymin), 20);
1093 gtk_entry_set_text(GTK_ENTRY(entryymin), settings.ymin.c_str() );
1094 gtk_label_set_mnemonic_widget( GTK_LABEL(graphwin_ymin), entryymin );
1095
1096 entryymax = gtk_entry_new();
1097 gtk_table_attach( GTK_TABLE(table), entryymax, 5, 6, 1, 2,
1098 GtkAttachOptions(GTK_EXPAND | GTK_FILL), GtkAttachOptions(0), 1, 1 );
1099 gtk_entry_set_max_length(GTK_ENTRY(entryymax), 20);
1100 gtk_entry_set_text(GTK_ENTRY(entryymax), settings.ymax.c_str() );
1101 gtk_label_set_mnemonic_widget( GTK_LABEL(graphwin_ymax), entryymax );
1102
1103 checkaxes = gtk_check_button_new_with_mnemonic( 0 );
1104 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkaxes), settings.axes_on ? TRUE : FALSE );
1105 gtk_table_attach( GTK_TABLE(table), checkaxes, 0, 2, 2, 3, GTK_FILL,
1106 GtkAttachOptions(0), 1, 1 );
1107
1108 checkgrid = gtk_check_button_new_with_mnemonic( 0 );
1109 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkgrid), settings.grid_on ? TRUE : FALSE );
1110 gtk_table_attach( GTK_TABLE(table), checkgrid, 2, 4, 2, 3, GTK_FILL,
1111 GtkAttachOptions(0), 1, 1 );
1112
1113 {
1114 GtkWidget *tmpimg,*tmpbox;
1115 tmpimg = gtk_image_new_from_stock( GTK_STOCK_PREFERENCES, GTK_ICON_SIZE_BUTTON );
1116 graphwin_buttonlabel_settings = gtk_label_new( 0 );
1117 tmpbox = gtk_hbox_new(FALSE,0);
1118 gtk_box_pack_start( GTK_BOX(tmpbox), tmpimg, FALSE, FALSE, 2 );
1119 gtk_box_pack_start( GTK_BOX(tmpbox), graphwin_buttonlabel_settings, FALSE, FALSE, 2 );
1120 tmp = gtk_button_new();
1121 gtk_container_add(GTK_CONTAINER(tmp),tmpbox);
1122 }
1123 g_signal_connect( GTK_OBJECT(tmp), "clicked", G_CALLBACK(graphwin_settings_show), NULL );
1124 gtk_table_attach( GTK_TABLE(table), tmp, 5, 6, 2, 3, GTK_FILL, GtkAttachOptions(0), 1, 1 );
1125
1126
1127 notebook = gtk_notebook_new();
1128
1129 // Page 'Functions' starts
1130 table = gtk_table_new(10, 3, FALSE);
1131 gtk_container_set_border_width( GTK_CONTAINER(table), 2 );
1132
1133 for(int i=0;i<10;i++)
1134 {
1135 func[i].entry2 = 0;
1136 func[i].entry = gtk_entry_new();
1137 gtk_table_attach( GTK_TABLE(table), func[i].entry, 1, 2, i, i+1,
1138 GtkAttachOptions(GTK_EXPAND | GTK_FILL),
1139 GtkAttachOptions(0), 1, 1 );
1140 gtk_entry_set_max_length( GTK_ENTRY(func[i].entry), max_len_entry );
1141 gtk_entry_set_text( GTK_ENTRY(func[i].entry), settings.func[i].entry.c_str() );
1142 g_signal_connect( GTK_OBJECT(func[i].entry), "changed",
1143 G_CALLBACK(entry_changed), gpointer(&func[i]) );
1144 g_signal_connect( GTK_OBJECT(func[i].entry), "insert-text",
1145 G_CALLBACK(entry_insert), NULL );
1146 g_signal_connect_swapped( GTK_OBJECT(func[i].entry), "activate",
1147 G_CALLBACK(drawbutton_click), NULL );
1148
1149 func[i].check = gtk_check_button_new();
1150 g_signal_connect( GTK_OBJECT(func[i].check), "toggled",
1151 G_CALLBACK(checkbox_toggled), gpointer(&func[i]) );
1152 gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON(func[i].check), settings.func[i].show_this ? TRUE : FALSE );
1153 gtk_table_attach( GTK_TABLE(table), func[i].check, 0, 1, i, i+1, GTK_FILL,
1154 GtkAttachOptions(0), 1, 1 );
1155
1156 snprintf( tmp_str, 10, "y_%ld=", i );
1157 tmp = gtk_label_new_with_mnemonic( tmp_str );
1158 gtk_label_set_mnemonic_widget(GTK_LABEL(tmp),func[i].entry);
1159 gtk_container_add(GTK_CONTAINER(func[i].check),tmp);
1160
1161
1162 func[i].button = gtk_button_new();
1163 g_signal_connect( GTK_OBJECT(func[i].button), "clicked",
1164 G_CALLBACK(colorbutton_click), gpointer(&func[i].colorpic) );
1165
1166 tmp = gtk_drawing_area_new();
1167 func[i].colorpic.set_size( 19, 19 );
1168 func[i].colorpic.clear( settings.func[i].color );
1169 func[i].colorpic.connect_to_drawing_area(tmp);
1170 func[i].colorpic.update();
1171 gtk_container_add( GTK_CONTAINER(func[i].button), tmp );
1172
1173 gtk_table_attach( GTK_TABLE(table), func[i].button, 2, 3, i, i+1,
1174 GtkAttachOptions(0), GtkAttachOptions(0), 1, 1 );
1175 }
1176 gtk_notebook_append_page( GTK_NOTEBOOK(notebook), table, 0 );
1177 // Page 'Functions' ends
1178
1179 // Page 'Polar functions' starts
1180 box2 = gtk_vbox_new(FALSE,0);
1181 gtk_container_set_border_width( GTK_CONTAINER(box2), 2 );
1182
1183 box3 = gtk_hbox_new(FALSE,0);
1184 graphwin_polar_start = gtk_label_new( 0 );
1185 gtk_misc_set_alignment(GTK_MISC(graphwin_polar_start), 1, 0.5);
1186 gtk_box_pack_start(GTK_BOX(box3),graphwin_polar_start,FALSE,FALSE,0);
1187
1188 polarentrystart = gtk_entry_new();
1189 g_signal_connect_swapped( GTK_OBJECT(polarentrystart), "activate",
1190 G_CALLBACK(drawbutton_click), NULL );
1191 gtk_entry_set_max_length( GTK_ENTRY(polarentrystart), 20 );
1192 gtk_entry_set_text( GTK_ENTRY(polarentrystart), settings.polar_start.c_str() );
1193 gtk_box_pack_start( GTK_BOX(box3), polarentrystart, FALSE, FALSE, 0 );
1194 gtk_label_set_mnemonic_widget( GTK_LABEL(graphwin_polar_start), polarentrystart );
1195
1196 graphwin_polar_stop = gtk_label_new( 0 );
1197 gtk_misc_set_alignment(GTK_MISC(graphwin_polar_stop), 1, 0.5);
1198 gtk_box_pack_start(GTK_BOX(box3),graphwin_polar_stop,FALSE,FALSE,0);
1199
1200 polarentrystop = gtk_entry_new();
1201 g_signal_connect_swapped( GTK_OBJECT(polarentrystop), "activate",
1202 G_CALLBACK(drawbutton_click), NULL );
1203 gtk_entry_set_max_length( GTK_ENTRY(polarentrystop), 20 );
1204 gtk_entry_set_text( GTK_ENTRY(polarentrystop), settings.polar_stop.c_str() );
1205 gtk_box_pack_start( GTK_BOX(box3), polarentrystop, FALSE, FALSE, 0 );
1206 gtk_label_set_mnemonic_widget( GTK_LABEL(graphwin_polar_stop), polarentrystop );
1207
1208 graphwin_polar_steps = gtk_label_new_with_mnemonic( _(" St_eps:") );
1209 gtk_misc_set_alignment(GTK_MISC(graphwin_polar_steps), 1, 0.5);
1210 gtk_box_pack_start(GTK_BOX(box3),graphwin_polar_steps,FALSE,FALSE,0);
1211
1212 polarentrystep = gtk_spin_button_new_with_range( 1, 10000, 1 );
1213 g_signal_connect_swapped( GTK_OBJECT(polarentrystep), "activate",
1214 G_CALLBACK(drawbutton_click), NULL );
1215 gtk_spin_button_set_value( GTK_SPIN_BUTTON(polarentrystep), atoi(settings.polar_steps.c_str()) );
1216 gtk_box_pack_start( GTK_BOX(box3), polarentrystep, TRUE, TRUE, 0 );
1217 gtk_label_set_mnemonic_widget( GTK_LABEL(graphwin_polar_steps),polarentrystep );
1218
1219 gtk_box_pack_start( GTK_BOX(box2), box3, FALSE, FALSE, 2 );
1220
1221 table = gtk_table_new(10, 3, FALSE);
1222 gtk_box_pack_start(GTK_BOX(box2),table,FALSE,FALSE,0);
1223
1224 for(int i=0;i<10;i++)
1225 {
1226 polar[i].entry2 = 0;
1227 polar[i].entry = gtk_entry_new();
1228 gtk_table_attach( GTK_TABLE(table), polar[i].entry, 1, 2, i, i+1,
1229 GtkAttachOptions(GTK_EXPAND | GTK_FILL),
1230 GtkAttachOptions(0), 1, 1);
1231 gtk_entry_set_max_length( GTK_ENTRY(polar[i].entry), max_len_entry );
1232 gtk_entry_set_text( GTK_ENTRY(polar[i].entry), settings.polar[i].entry.c_str() );
1233 g_signal_connect( GTK_OBJECT(polar[i].entry), "changed",
1234 G_CALLBACK(entry_changed), gpointer(&polar[i]) );
1235 g_signal_connect( GTK_OBJECT(polar[i].entry), "insert-text",
1236 G_CALLBACK(entry_insert), NULL );
1237 g_signal_connect_swapped( GTK_OBJECT(polar[i].entry), "activate",
1238 G_CALLBACK(drawbutton_click), NULL );
1239
1240 polar[i].check = gtk_check_button_new();
1241 g_signal_connect( GTK_OBJECT(polar[i].check), "toggled",
1242 G_CALLBACK(checkbox_toggled), gpointer(&polar[i]) );
1243 gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON(polar[i].check),
1244 settings.polar[i].show_this ? TRUE : FALSE );
1245 gtk_table_attach( GTK_TABLE(table), polar[i].check, 0, 1, i, i+1, GTK_FILL,
1246 GtkAttachOptions(0), 1, 1);
1247
1248 snprintf( tmp_str, 10, "r_%ld=", i );
1249 tmp = gtk_label_new_with_mnemonic( tmp_str );
1250 gtk_label_set_mnemonic_widget(GTK_LABEL(tmp),polar[i].entry);
1251 gtk_container_add(GTK_CONTAINER(polar[i].check),tmp);
1252
1253
1254 polar[i].button = gtk_button_new();
1255 g_signal_connect( GTK_OBJECT(polar[i].button), "clicked",
1256 G_CALLBACK(colorbutton_click), gpointer(&polar[i].colorpic) );
1257
1258 tmp = gtk_drawing_area_new();
1259 polar[i].colorpic.set_size( 19, 19 );
1260 polar[i].colorpic.clear( settings.polar[i].color );
1261 polar[i].colorpic.connect_to_drawing_area(tmp);
1262 polar[i].colorpic.update();
1263 gtk_container_add(GTK_CONTAINER(polar[i].button),tmp);
1264
1265 gtk_table_attach( GTK_TABLE(table), polar[i].button, 2, 3, i, i+1,
1266 GtkAttachOptions(0), GtkAttachOptions(0), 1, 1 );
1267 }
1268
1269 gtk_notebook_append_page( GTK_NOTEBOOK(notebook), box2, 0 );
1270 // Page 'Polar functions' ends
1271
1272 // Page 'Parametric functions' starts
1273 box2 = gtk_vbox_new(FALSE,0);
1274 gtk_container_set_border_width( GTK_CONTAINER(box2), 2 );
1275
1276 box3 = gtk_hbox_new(FALSE,0);
1277 graphwin_para_start = gtk_label_new( 0 );
1278 gtk_misc_set_alignment(GTK_MISC(graphwin_para_start), 1, 0.5);
1279 gtk_box_pack_start(GTK_BOX(box3),graphwin_para_start,FALSE,FALSE,0);
1280
1281 parentrystart = gtk_entry_new();
1282 g_signal_connect_swapped( GTK_OBJECT(parentrystart), "activate",
1283 G_CALLBACK(drawbutton_click), NULL );
1284 gtk_entry_set_max_length( GTK_ENTRY(parentrystart), 20);
1285 gtk_entry_set_text( GTK_ENTRY(parentrystart), settings.par_start.c_str() );
1286 gtk_box_pack_start( GTK_BOX(box3), parentrystart, FALSE, FALSE, 0 );
1287 gtk_label_set_mnemonic_widget( GTK_LABEL(graphwin_para_start), parentrystart );
1288
1289 graphwin_para_stop = gtk_label_new( 0 );
1290 gtk_misc_set_alignment(GTK_MISC(graphwin_para_stop), 1, 0.5);
1291 gtk_box_pack_start(GTK_BOX(box3),graphwin_para_stop,FALSE,FALSE,0);
1292
1293 parentrystop = gtk_entry_new();
1294 g_signal_connect_swapped( GTK_OBJECT(parentrystop), "activate",
1295 G_CALLBACK(drawbutton_click), NULL );
1296 gtk_entry_set_max_length( GTK_ENTRY(parentrystop), 20 );
1297 gtk_entry_set_text( GTK_ENTRY(parentrystop), settings.par_stop.c_str() );
1298 gtk_box_pack_start( GTK_BOX(box3), parentrystop, FALSE, FALSE, 0 );
1299 gtk_label_set_mnemonic_widget( GTK_LABEL(graphwin_para_stop), parentrystop );
1300
1301 graphwin_para_steps = gtk_label_new( 0 );
1302 gtk_misc_set_alignment( GTK_MISC(graphwin_para_steps), 1, 0.5 );
1303 gtk_box_pack_start( GTK_BOX(box3), graphwin_para_steps, FALSE, FALSE, 0 );
1304
1305 parentrystep = gtk_spin_button_new_with_range( 1, 10000, 1 );
1306 g_signal_connect_swapped( GTK_OBJECT(parentrystep), "activate",
1307 G_CALLBACK(drawbutton_click), NULL );
1308 gtk_entry_set_max_length( GTK_ENTRY(parentrystep), 20);
1309 gtk_spin_button_set_value( GTK_SPIN_BUTTON(parentrystep), atoi(settings.par_steps.c_str()) );
1310 gtk_box_pack_start( GTK_BOX(box3), parentrystep, TRUE, TRUE, 0 );
1311 gtk_label_set_mnemonic_widget( GTK_LABEL(graphwin_para_steps), parentrystep );
1312
1313 gtk_box_pack_start( GTK_BOX(box2), box3, FALSE, FALSE, 2 );
1314
1315 table = gtk_table_new( 10, 3, FALSE );
1316 gtk_box_pack_start( GTK_BOX(box2), table, FALSE, FALSE, 0 );
1317
1318 for(int i=0;i<5;i++)
1319 {
1320 par[i].entry = gtk_entry_new();
1321 gtk_table_attach( GTK_TABLE(table), par[i].entry, 1, 2, i*2, i*2+1,
1322 GtkAttachOptions(GTK_EXPAND | GTK_FILL),
1323 GtkAttachOptions(0), 1, 1 );
1324 gtk_entry_set_max_length(GTK_ENTRY(par[i].entry), max_len_entry);
1325 gtk_entry_set_text(GTK_ENTRY(par[i].entry), settings.par[i].entry.c_str() );
1326 g_signal_connect( GTK_OBJECT(par[i].entry), "changed",
1327 G_CALLBACK(entry_changed), gpointer(&par[i]) );
1328 g_signal_connect( GTK_OBJECT(par[i].entry), "insert-text",
1329 G_CALLBACK(entry_insert), NULL );
1330 g_signal_connect_swapped( GTK_OBJECT(par[i].entry), "activate",
1331 G_CALLBACK(drawbutton_click), NULL );
1332
1333 par[i].entry2 = gtk_entry_new();
1334 gtk_table_attach( GTK_TABLE(table), par[i].entry2, 1, 2, i*2+1, i*2+2,
1335 GtkAttachOptions(GTK_EXPAND | GTK_FILL),
1336 GtkAttachOptions(0), 1, 1 );
1337 gtk_entry_set_max_length(GTK_ENTRY(par[i].entry2), max_len_entry);
1338 gtk_entry_set_text(GTK_ENTRY(par[i].entry2), settings.par[i].entry2.c_str() );
1339 g_signal_connect( GTK_OBJECT(par[i].entry2), "changed",
1340 G_CALLBACK(entry_changed), gpointer(&par[i]) );
1341 g_signal_connect( GTK_OBJECT(par[i].entry2), "insert-text",
1342 G_CALLBACK(entry_insert), NULL );
1343 g_signal_connect_swapped( GTK_OBJECT(par[i].entry2), "activate",
1344 G_CALLBACK(drawbutton_click), NULL );
1345
1346 par[i].check = gtk_check_button_new();
1347 g_signal_connect( GTK_OBJECT(par[i].check), "toggled",
1348 G_CALLBACK(checkbox_toggled), gpointer(&par[i]) );
1349 gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON(par[i].check),
1350 settings.par[i].show_this ? TRUE : FALSE );
1351 gtk_table_attach( GTK_TABLE(table), par[i].check, 0, 1, i*2, i*2+1, GTK_FILL,
1352 GtkAttachOptions(0), 1, 1 );
1353
1354 snprintf( tmp_str, 10, "yf_%ld=", i );
1355 tmp = gtk_label_new_with_mnemonic( tmp_str );
1356 gtk_table_attach( GTK_TABLE(table), tmp, 0, 1, i*2+1, i*2+2, GTK_FILL,
1357 GtkAttachOptions(0), 1, 1 );
1358 gtk_label_set_mnemonic_widget( GTK_LABEL(tmp), par[i].entry2 );
1359 gtk_misc_set_alignment( GTK_MISC(tmp), 1.0f, 0.5f );
1360
1361 snprintf( tmp_str, 10, "xf_%ld=", i );
1362 tmp = gtk_label_new_with_mnemonic( tmp_str );
1363 gtk_label_set_mnemonic_widget(GTK_LABEL(tmp),par[i].entry);
1364 gtk_container_add(GTK_CONTAINER(par[i].check),tmp);
1365
1366
1367 par[i].button = gtk_button_new();
1368 g_signal_connect( GTK_OBJECT(par[i].button), "clicked",
1369 G_CALLBACK(colorbutton_click), gpointer(&par[i].colorpic) );
1370
1371 tmp = gtk_drawing_area_new();
1372 par[i].colorpic.set_size( 19, 45 );
1373 par[i].colorpic.clear( settings.par[i].color );
1374 par[i].colorpic.connect_to_drawing_area(tmp);
1375 par[i].colorpic.update();
1376 gtk_container_add( GTK_CONTAINER(par[i].button), tmp );
1377
1378 gtk_table_attach( GTK_TABLE(table), par[i].button, 2, 3, i*2, i*2+2,
1379 GtkAttachOptions(0), GtkAttachOptions(0), 1, 1 );
1380 }
1381
1382 gtk_notebook_append_page( GTK_NOTEBOOK(notebook), box2, 0 );
1383 // Page 'Parametric functions' ends
1384
1385
1386 gtk_box_pack_start( GTK_BOX(graphwin_vbox), notebook, TRUE, TRUE, 0 );
1387 gtk_container_set_border_width( GTK_CONTAINER(notebook), 2 );
1388
1389
1390 box2 = gtk_hbox_new( FALSE, 0 );
1391 {
1392 GtkWidget *tmpimg,*tmpbox;
1393 tmpimg = gtk_image_new_from_stock( GTK_STOCK_CLEAR, GTK_ICON_SIZE_BUTTON );
1394 graphwin_buttonlabel_draw = gtk_label_new( 0 );
1395 tmpbox = gtk_hbox_new(FALSE,0);
1396 gtk_box_pack_start( GTK_BOX(tmpbox), tmpimg, FALSE, FALSE, 2 );
1397 gtk_box_pack_start( GTK_BOX(tmpbox), graphwin_buttonlabel_draw, FALSE, FALSE, 2 );
1398 drawbutton = gtk_button_new();
1399 gtk_container_add( GTK_CONTAINER(drawbutton), tmpbox );
1400 }
1401 g_signal_connect( GTK_OBJECT(drawbutton), "clicked",
1402 G_CALLBACK(drawbutton_click), gpointer(0) );
1403 gtk_box_pack_start( GTK_BOX(box2), drawbutton, FALSE, FALSE, 2 );
1404
1405 gtk_box_pack_start( GTK_BOX(graphwin_vbox), box2, FALSE, FALSE, 3 );
1406
1407 graphwin_translate(); // fix all strings
1408
1409 gtk_widget_show_all(graphwin);
1410 open_windows |= GRAPHTOOL_WIN;
1411
1412 switch(settings.active_page)
1413 {
1414 case 1: // polar
1415 gtk_notebook_set_current_page( GTK_NOTEBOOK(notebook), 1 );
1416 gtk_widget_grab_focus(polar[0].entry);
1417 break;
1418 case 2: // parametric
1419 gtk_notebook_set_current_page( GTK_NOTEBOOK(notebook), 2 );
1420 gtk_widget_grab_focus(par[0].entry);
1421 break;
1422 default: // function
1423 gtk_notebook_set_current_page( GTK_NOTEBOOK(notebook), 0 );
1424 gtk_widget_grab_focus(func[0].entry);
1425 }
1426 #ifdef PLOT_3D
1427 {
1428 bool tmp_bool = false;
1429 const utf8_string *str;
1430 GET_BOOLEAN_KEY( "GRAPHTOOL_3D_ACTIVE", tmp_bool );
1431 gtk_notebook_set_current_page( GTK_NOTEBOOK(notebook_2d_3d), tmp_bool ? 1 : 0 );
1432 }
1433 #endif
1434 }
1435 else
1436 gtk_window_present(GTK_WINDOW(graphwin));
1437
1438 return GTK_WINDOW( graphwin );
1439 }
1440
graphwin_translate(void)1441 void graphwin_translate(void)
1442 {
1443 if(graphwin != 0)
1444 {
1445 GtkWidget *new_menu;
1446 GtkWidget *label;
1447
1448 gtk_window_set_title(GTK_WINDOW(graphwin), _("Ump - Graph tools") );
1449
1450
1451 gtk_frame_set_label( GTK_FRAME(graphwin_plot_frame), _("Plot window") );
1452
1453 gtk_label_set_text_with_mnemonic( GTK_LABEL(graphwin_width), _("_Width:") );
1454 gtk_label_set_text_with_mnemonic( GTK_LABEL(graphwin_height), _("_Height:") );
1455
1456 gtk_label_set_text_with_mnemonic( GTK_LABEL(graphwin_xmin), _(" Xmin:") );
1457 gtk_label_set_text_with_mnemonic( GTK_LABEL(graphwin_xmax), _(" Xmax:") );
1458 gtk_label_set_text_with_mnemonic( GTK_LABEL(graphwin_ymin), _(" Ymin:") );
1459 gtk_label_set_text_with_mnemonic( GTK_LABEL(graphwin_ymax), _(" Ymax:") );
1460
1461 gtk_button_set_label( GTK_BUTTON(checkaxes), _("Show a_xes") );
1462 gtk_button_set_label( GTK_BUTTON(checkgrid), _("Show _grid") );
1463
1464
1465 gtk_label_set_text_with_mnemonic( GTK_LABEL(graphwin_buttonlabel_settings),
1466 _("More _settings") );
1467 {
1468 const char *trans;
1469 trans = _(" _Start:");
1470 gtk_label_set_text_with_mnemonic( GTK_LABEL(graphwin_polar_start), trans );
1471 gtk_label_set_text_with_mnemonic( GTK_LABEL(graphwin_para_start), trans );
1472
1473 trans = _(" S_top:");
1474 gtk_label_set_text_with_mnemonic( GTK_LABEL(graphwin_polar_stop), trans );
1475 gtk_label_set_text_with_mnemonic( GTK_LABEL(graphwin_para_stop), trans );
1476
1477 trans = _(" St_eps:");
1478 gtk_label_set_text_with_mnemonic( GTK_LABEL(graphwin_polar_steps), trans );
1479 gtk_label_set_text_with_mnemonic( GTK_LABEL(graphwin_para_steps), trans );
1480 }
1481
1482 gtk_label_set_text_with_mnemonic( GTK_LABEL(graphwin_buttonlabel_draw), _("Draw") );
1483
1484 label = gtk_label_new_with_mnemonic( _("_Functions") );
1485 gtk_notebook_set_tab_label( GTK_NOTEBOOK(notebook),
1486 gtk_notebook_get_nth_page( GTK_NOTEBOOK(notebook), 0), label );
1487
1488 label = gtk_label_new_with_mnemonic( _("_Polar functions") );
1489 gtk_notebook_set_tab_label( GTK_NOTEBOOK(notebook),
1490 gtk_notebook_get_nth_page( GTK_NOTEBOOK(notebook), 1), label );
1491
1492 label = gtk_label_new_with_mnemonic( _("Pa_rametric functions") );
1493 gtk_notebook_set_tab_label( GTK_NOTEBOOK(notebook),
1494 gtk_notebook_get_nth_page( GTK_NOTEBOOK(notebook), 2), label );
1495
1496 #ifdef PLOT_3D
1497 label = gtk_label_new_with_mnemonic( _("_2D plot") );
1498 gtk_notebook_set_tab_label( GTK_NOTEBOOK(notebook_2d_3d),
1499 gtk_notebook_get_nth_page( GTK_NOTEBOOK(notebook_2d_3d), 0), label );
1500
1501 label = gtk_label_new_with_mnemonic( _("_3D plot") );
1502 gtk_notebook_set_tab_label( GTK_NOTEBOOK(notebook_2d_3d),
1503 gtk_notebook_get_nth_page( GTK_NOTEBOOK(notebook_2d_3d), 1), label );
1504
1505 gtk_frame_set_label( GTK_FRAME(graphwin_3d_frame), _("Plot window") );
1506
1507 gtk_label_set_text_with_mnemonic( GTK_LABEL(graphwin_3d_width_label), _("_Width:") );
1508 gtk_label_set_text_with_mnemonic( GTK_LABEL(graphwin_3d_height_label), _("_Height:") );
1509 gtk_label_set_text_with_mnemonic( GTK_LABEL(graphwin_3d_xmin_label), _(" Xmin:") );
1510 gtk_label_set_text_with_mnemonic( GTK_LABEL(graphwin_3d_xmax_label), _(" Xmax:") );
1511 gtk_label_set_text_with_mnemonic( GTK_LABEL(graphwin_3d_xsteps_label), _(" Xsteps:") );
1512 gtk_label_set_text_with_mnemonic( GTK_LABEL(graphwin_3d_ymin_label), _(" Ymin:") );
1513 gtk_label_set_text_with_mnemonic( GTK_LABEL(graphwin_3d_ymax_label), _(" Ymax:") );
1514 gtk_label_set_text_with_mnemonic( GTK_LABEL(graphwin_3d_ysteps_label), _(" Ysteps:") );
1515 gtk_label_set_text_with_mnemonic( GTK_LABEL(graphwin_3d_zmin_label), _(" Zmin:") );
1516 gtk_label_set_text_with_mnemonic( GTK_LABEL(graphwin_3d_zmax_label), _(" Zmax:") );
1517
1518 label = gtk_label_new_with_mnemonic( _("_Functions") );
1519 gtk_notebook_set_tab_label( GTK_NOTEBOOK(graphwin_3d_notebook),
1520 gtk_notebook_get_nth_page( GTK_NOTEBOOK(graphwin_3d_notebook), 0), label );
1521
1522 gtk_label_set_text_with_mnemonic( GTK_LABEL(graphwin_buttonlabel_3d_draw), _("Draw") );
1523
1524 for( int i=0; i<PLOT_3D_FUNCTIONS; i++ )
1525 {
1526 gtk_combo_box_append_text( GTK_COMBO_BOX(func_3d[i].combo), _("Wireframed") );
1527 gtk_combo_box_append_text( GTK_COMBO_BOX(func_3d[i].combo), _("Semi-solid") );
1528 gtk_combo_box_append_text( GTK_COMBO_BOX(func_3d[i].combo), _("Solid") );
1529
1530 gtk_combo_box_set_active( GTK_COMBO_BOX(func_3d[i].combo),
1531 gtk_combo_box_get_active( GTK_COMBO_BOX(func_3d[i].combo) )+3 );
1532 }
1533
1534 for( int i=0; i<PLOT_3D_FUNCTIONS; i++ )
1535 {
1536 for( int i2=0; i2<3; i2++ )
1537 gtk_combo_box_remove_text( GTK_COMBO_BOX(func_3d[i].combo), 0 );
1538 }
1539 #endif
1540
1541 if( (new_menu = graphwin_build_menu()) == 0 )
1542 return;
1543
1544 gtk_widget_destroy( graphwin_menu );
1545 graphwin_menu = new_menu;
1546
1547 gtk_box_pack_start(GTK_BOX(graphwin_vbox_top), graphwin_menu, FALSE, FALSE, 0);
1548 gtk_box_reorder_child( GTK_BOX(graphwin_vbox_top), graphwin_menu, 0 );
1549 }
1550 }
1551
graphwin_close(void)1552 void graphwin_close(void)
1553 {
1554 if(graphwin != 0)
1555 {
1556 char str[50], str2[10];
1557
1558 #ifdef PLOT_3D
1559 settings.active_page = gtk_notebook_get_current_page(GTK_NOTEBOOK(notebook));
1560 setup_file.set_key( "GRAPHTOOL_3D_ACTIVE",
1561 (gtk_notebook_get_current_page(GTK_NOTEBOOK(notebook_2d_3d)) == 1) ? "True" : "False" );
1562
1563 setup_file.set_key( "GRAPHTOOL_3D_WIDTH", gtk_entry_get_text( GTK_ENTRY(graphwin_3d_width) ) );
1564 setup_file.set_key( "GRAPHTOOL_3D_HEIGHT", gtk_entry_get_text( GTK_ENTRY(graphwin_3d_height) ) );
1565
1566 setup_file.set_key( "GRAPHTOOL_3D_XMIN", gtk_entry_get_text( GTK_ENTRY(graphwin_3d_xmin) ) );
1567 setup_file.set_key( "GRAPHTOOL_3D_XMAX", gtk_entry_get_text( GTK_ENTRY(graphwin_3d_xmax) ) );
1568 setup_file.set_key( "GRAPHTOOL_3D_XSTEPS", gtk_entry_get_text( GTK_ENTRY(graphwin_3d_xsteps) ) );
1569 setup_file.set_key( "GRAPHTOOL_3D_YMIN", gtk_entry_get_text( GTK_ENTRY(graphwin_3d_ymin) ) );
1570 setup_file.set_key( "GRAPHTOOL_3D_YMAX", gtk_entry_get_text( GTK_ENTRY(graphwin_3d_ymax) ) );
1571 setup_file.set_key( "GRAPHTOOL_3D_YSTEPS", gtk_entry_get_text( GTK_ENTRY(graphwin_3d_ysteps) ) );
1572 setup_file.set_key( "GRAPHTOOL_3D_ZMIN", gtk_entry_get_text( GTK_ENTRY(graphwin_3d_zmin) ) );
1573 setup_file.set_key( "GRAPHTOOL_3D_ZMAX", gtk_entry_get_text( GTK_ENTRY(graphwin_3d_zmax) ) );
1574
1575 {
1576 bool tmp_bool;
1577 const char *tmp_char_ptr;
1578 utf8_string color_str;
1579
1580 for(int i=0;i<PLOT_3D_FUNCTIONS;i++)
1581 {
1582 tmp_bool = (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(func_3d[i].check)) == TRUE) ? true : false;
1583 snprintf( str, 50, "GRAPHTOOL_3D_Z%lu_SHOW", i );
1584 setup_file.set_key( str, tmp_bool ? "True" : "False" );
1585
1586 tmp_char_ptr = gtk_entry_get_text(GTK_ENTRY(func_3d[i].entry));
1587 snprintf( str, 50, "GRAPHTOOL_3D_Z%lu_ENTRY", i );
1588 setup_file.set_key( str, tmp_char_ptr );
1589
1590 snprintf( str, 50, "GRAPHTOOL_3D_Z%ld_DRAW_MODE", i );
1591 switch( gtk_combo_box_get_active( GTK_COMBO_BOX(func_3d[i].combo) ) )
1592 {
1593 case 0:
1594 setup_file.set_key( str, "Wireframed" );
1595 break;
1596 case 1:
1597 setup_file.set_key( str, "Semi-solid" );
1598 break;
1599 default:
1600 setup_file.set_key( str, "Solid" );
1601 break;
1602 }
1603
1604 color_str = "";
1605 for( int i2=0; i2<func_3d_colors[i].get_size(); i2++ )
1606 {
1607 snprintf( str, 50, "%02lx%02lx%02lx", func_3d_colors[i][i2]->red,
1608 func_3d_colors[i][i2]->green, func_3d_colors[i][i2]->blue );
1609 if( i2 != 0 )
1610 color_str.append( " " );
1611 color_str.append( str );
1612 }
1613 snprintf( str, 50, "GRAPHTOOL_3D_Z%ld_COLOR", i );
1614 setup_file.set_key( str, color_str );
1615 }
1616 }
1617 #endif
1618
1619 settings.width = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(spinwidth));
1620 snprintf( str, 50, "%lu", settings.width );
1621 setup_file.set_key( "GRAPHTOOL_WIDTH", str );
1622
1623 settings.height = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(spinheight));
1624 snprintf( str, 50, "%lu", settings.height );
1625 setup_file.set_key( "GRAPHTOOL_HEIGHT", str );
1626
1627 snprintf( str2, 10, "%02lx%02lx%02lx", settings.bgcolor.red, settings.bgcolor.green, settings.bgcolor.blue );
1628 setup_file.set_key( "GRAPHTOOL_BGCOLOR", str2 );
1629
1630 settings.xmin = gtk_entry_get_text(GTK_ENTRY(entryxmin));
1631 setup_file.set_key( "GRAPHTOOL_XMIN", settings.xmin );
1632 settings.xmax = gtk_entry_get_text(GTK_ENTRY(entryxmax));
1633 setup_file.set_key( "GRAPHTOOL_XMAX", settings.xmax );
1634 settings.ymin = gtk_entry_get_text(GTK_ENTRY(entryymin));
1635 setup_file.set_key( "GRAPHTOOL_YMIN", settings.ymin );
1636 settings.ymax = gtk_entry_get_text(GTK_ENTRY(entryymax));
1637 setup_file.set_key( "GRAPHTOOL_YMAX", settings.ymax );
1638
1639 settings.axes_on = (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(checkaxes)) == TRUE) ? true : false;
1640 setup_file.set_key( "GRAPHTOOL_AXES_ON", settings.axes_on ? "True" : "False" );
1641
1642 snprintf( str2, 10, "%02lx%02lx%02lx", settings.axes_color.red, settings.axes_color.green, settings.axes_color.blue );
1643 setup_file.set_key( "GRAPHTOOL_AXES_COLOR", str2 );
1644
1645 settings.grid_on = (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(checkgrid)) == TRUE) ? true : false;
1646 setup_file.set_key( "GRAPHTOOL_GRID_ON", settings.grid_on ? "True" : "False" );
1647
1648 snprintf( str2, 10, "%02lx%02lx%02lx", settings.grid_color.red, settings.grid_color.green, settings.grid_color.blue );
1649 setup_file.set_key( "GRAPHTOOL_GRID_COLOR", str2 );
1650
1651 setup_file.set_key( "GRAPHTOOL_GRID_SCALE1", settings.grid_scale1 );
1652 setup_file.set_key( "GRAPHTOOL_GRID_SCALE2", settings.grid_scale2 );
1653 setup_file.set_key( "GRAPHTOOL_GRID_TYPE", settings.grid_type );
1654 setup_file.set_key( "GRAPHTOOL_AXES_SCALEX", settings.scalex );
1655 setup_file.set_key( "GRAPHTOOL_AXES_SCALEY", settings.scaley );
1656 snprintf( str, 50, "%ld", settings.scale_length );
1657 setup_file.set_key( "GRAPHTOOL_AXES_SCALE_LENGTH", str );
1658
1659 setup_file.set_key( "GRAPHTOOL_SHOW_CODE", settings.show_code ? "True" : "False" );
1660
1661 setup_file.set_key( "GRAPHTOOL_ANTIALIASING", settings.use_antialiasing ? "True" : "False" );
1662
1663 setup_file.set_key( "GRAPHTOOL_PLOT_MODE", settings.plot_mode );
1664
1665 setup_file.set_key( "GRAPHTOOL_SHOW_ACTIVE_PAGE_ONLY", settings.show_active_page_only ? "True" : "False" );
1666
1667 settings.active_page = gtk_notebook_get_current_page(GTK_NOTEBOOK(notebook));
1668 snprintf( str, 50, "%ld", settings.active_page );
1669 setup_file.set_key( "GRAPHTOOL_ACTIVE_PAGE", str );
1670
1671
1672 settings.polar_start = gtk_entry_get_text(GTK_ENTRY(polarentrystart));
1673 setup_file.set_key( "GRAPHTOOL_POLAR_START", settings.polar_start );
1674
1675 settings.polar_stop = gtk_entry_get_text(GTK_ENTRY(polarentrystop));
1676 setup_file.set_key( "GRAPHTOOL_POLAR_STOP", settings.polar_stop );
1677
1678 settings.polar_steps = gtk_entry_get_text(GTK_ENTRY(polarentrystep));
1679 setup_file.set_key( "GRAPHTOOL_POLAR_STEPS", settings.polar_steps );
1680
1681 settings.par_start = gtk_entry_get_text(GTK_ENTRY(parentrystart));
1682 setup_file.set_key( "GRAPHTOOL_PAR_START", settings.par_start );
1683
1684 settings.par_stop = gtk_entry_get_text(GTK_ENTRY(parentrystop));
1685 setup_file.set_key( "GRAPHTOOL_PAR_STOP", settings.par_stop );
1686
1687 settings.par_steps = gtk_entry_get_text(GTK_ENTRY(parentrystep));
1688 setup_file.set_key( "GRAPHTOOL_PAR_STEPS", settings.par_steps );
1689
1690 for(int i=0;i<10;i++)
1691 {
1692 settings.func[i].show_this = (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(func[i].check)) == TRUE) ? true : false;
1693 snprintf( str, 50, "GRAPHTOOL_Y%lu_SHOW", i );
1694 setup_file.set_key( str, settings.func[i].show_this ? "True" : "False" );
1695
1696 settings.func[i].entry = gtk_entry_get_text(GTK_ENTRY(func[i].entry));
1697 snprintf( str, 50, "GRAPHTOOL_Y%lu_ENTRY", i );
1698 setup_file.set_key( str, settings.func[i].entry );
1699
1700 settings.func[i].color = func[i].colorpic.get_pixel(0,0);
1701 snprintf( str, 50, "GRAPHTOOL_Y%lu_COLOR", i );
1702 snprintf( str2, 10, "%02lx%02lx%02lx", settings.func[i].color.red, settings.func[i].color.green, settings.func[i].color.blue );
1703 setup_file.set_key( str, str2 );
1704
1705 settings.polar[i].show_this = (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(polar[i].check)) == TRUE) ? true : false;
1706 snprintf( str, 50, "GRAPHTOOL_R%lu_SHOW", i );
1707 setup_file.set_key( str, settings.polar[i].show_this ? "True" : "False" );
1708
1709 settings.polar[i].entry = gtk_entry_get_text(GTK_ENTRY(polar[i].entry));
1710 snprintf( str, 50, "GRAPHTOOL_R%lu_ENTRY", i );
1711 setup_file.set_key( str, settings.polar[i].entry );
1712
1713 settings.polar[i].color = polar[i].colorpic.get_pixel(0,0);
1714 snprintf( str, 50, "GRAPHTOOL_R%lu_COLOR", i );
1715 snprintf( str2, 10, "%02lx%02lx%02lx", settings.polar[i].color.red, settings.polar[i].color.green, settings.polar[i].color.blue );
1716 setup_file.set_key( str, str2 );
1717
1718 if(i < 5)
1719 {
1720 settings.par[i].show_this = (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(par[i].check)) == TRUE) ? true : false;
1721 snprintf( str, 50, "GRAPHTOOL_XF%lu_SHOW", i );
1722 setup_file.set_key( str, settings.par[i].show_this ? "True" : "False" );
1723
1724 settings.par[i].entry = gtk_entry_get_text(GTK_ENTRY(par[i].entry));
1725 snprintf( str, 50, "GRAPHTOOL_XF%lu_ENTRY", i );
1726 setup_file.set_key( str, settings.par[i].entry );
1727
1728 settings.par[i].entry2 = gtk_entry_get_text(GTK_ENTRY(par[i].entry2));
1729 snprintf( str, 50, "GRAPHTOOL_YF%lu_ENTRY", i );
1730 setup_file.set_key( str, settings.par[i].entry2 );
1731
1732 settings.par[i].color = par[i].colorpic.get_pixel(0,0);
1733 snprintf( str, 50, "GRAPHTOOL_XF%lu_COLOR", i );
1734 snprintf( str2, 10, "%02lx%02lx%02lx", settings.par[i].color.red, settings.par[i].color.green, settings.par[i].color.blue );
1735 setup_file.set_key( str, str2 );
1736 }
1737 }
1738
1739 gtk_widget_destroy( graphwin );
1740 graphwin = 0;
1741
1742 open_windows &= ~GRAPHTOOL_WIN;
1743 if(open_windows == 0)
1744 UMP_gtk_quit();
1745 }
1746 }
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773 GtkWidget *graphwin_settings,*plot_mode,*show_code,*scalex,*scaley,*scale_length,
1774 *bgcolor, *axes_color, *grid_color, *grid_scale1, *grid_scale2, *grid_type,
1775 *show_active_page_only, *antialiasing;
1776
1777
graphwin_settings_close(void)1778 void graphwin_settings_close(void)
1779 {
1780 gtk_widget_destroy( graphwin_settings );
1781 }
graphwin_settings_ok(void)1782 void graphwin_settings_ok(void)
1783 {
1784 GdkColor tmpcolor;
1785
1786 if(gtk_combo_box_get_active(GTK_COMBO_BOX(grid_type)) == 0)
1787 settings.grid_type = "Rect";
1788 else
1789 settings.grid_type = "Polar";
1790 switch( gtk_combo_box_get_active(GTK_COMBO_BOX(plot_mode)) )
1791 {
1792 case 0:
1793 settings.plot_mode = "Dots";
1794 break;
1795 case 1:
1796 settings.plot_mode = "Connected";
1797 break;
1798 default:
1799 settings.plot_mode = "Connected without asymptotes";
1800 break;
1801 }
1802
1803 settings.show_code = (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(show_code)) == TRUE) ?
1804 true : false;
1805
1806 settings.show_active_page_only = (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(show_active_page_only)) == TRUE)
1807 ? true : false;
1808
1809 settings.use_antialiasing = (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(antialiasing)) == TRUE)
1810 ? true : false;
1811
1812 gtk_color_button_get_color(GTK_COLOR_BUTTON(bgcolor), &tmpcolor);
1813 gdkcolor_to_colorrgb( tmpcolor, settings.bgcolor );
1814 gtk_color_button_get_color(GTK_COLOR_BUTTON(axes_color), &tmpcolor);
1815 gdkcolor_to_colorrgb( tmpcolor, settings.axes_color );
1816 gtk_color_button_get_color(GTK_COLOR_BUTTON(grid_color), &tmpcolor);
1817 gdkcolor_to_colorrgb( tmpcolor, settings.grid_color );
1818
1819 settings.scalex = gtk_entry_get_text(GTK_ENTRY(scalex));
1820 settings.scaley = gtk_entry_get_text(GTK_ENTRY(scaley));
1821 settings.scale_length = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(scale_length));
1822
1823
1824 settings.grid_scale1 = gtk_entry_get_text(GTK_ENTRY(grid_scale1));
1825 settings.grid_scale2 = gtk_entry_get_text(GTK_ENTRY(grid_scale2));
1826
1827 settings.grid_type = (gtk_combo_box_get_active(GTK_COMBO_BOX(grid_type)) == 0) ?
1828 "Rect" : "Polar";
1829
1830 graphwin_settings_close();
1831 }
1832
grid_type_changed(GtkComboBox * combobox)1833 void grid_type_changed(GtkComboBox *combobox)
1834 {
1835 if(gtk_combo_box_get_active(GTK_COMBO_BOX(grid_type)) == 0)
1836 {
1837 gtk_entry_set_text( GTK_ENTRY(grid_scale1), "2" );
1838 gtk_entry_set_text( GTK_ENTRY(grid_scale2), "2" );
1839 }
1840 else
1841 {
1842 try
1843 {
1844 utf8_string str;
1845
1846 gtk_entry_set_text( GTK_ENTRY(grid_scale1), "2" );
1847
1848 floatx_to_string( asinx(1.0) / (floatx(math::degfix.real) * 3.0), str, format );
1849
1850 gtk_entry_set_text( GTK_ENTRY(grid_scale2), str.c_str() );
1851 }
1852 catch(...) { }
1853 }
1854 }
1855
graphwin_settings_show(void)1856 void graphwin_settings_show(void)
1857 {
1858 GtkWidget *box, *box2, *tmp;
1859 GtkAdjustment *adj;
1860 GdkColor color;
1861 GtkTooltips *tooltips;
1862
1863 tooltips = gtk_tooltips_new();
1864
1865 graphwin_settings = gtk_window_new(GTK_WINDOW_TOPLEVEL);
1866
1867 gtk_window_set_title(GTK_WINDOW(graphwin_settings), _("More settings") );
1868 g_signal_connect_swapped(GTK_OBJECT(graphwin_settings), "delete-event", G_CALLBACK(graphwin_settings_close), NULL);
1869 gtk_container_set_border_width( GTK_CONTAINER(graphwin_settings), 2 );
1870
1871 box = gtk_vbox_new(FALSE,0);
1872
1873 {
1874 GtkWidget *frame,*align,*vbox,*hbox;
1875
1876 frame = gtk_frame_new( _("General") );
1877 gtk_box_pack_start( GTK_BOX(box), frame, FALSE, FALSE, 2 );
1878
1879 align = gtk_alignment_new( 0.5, 0.5, 1.0, 1.0 );
1880 gtk_alignment_set_padding( GTK_ALIGNMENT(align), 3, 3, 12, 3 );
1881 gtk_container_add( GTK_CONTAINER(frame), align );
1882
1883 vbox = gtk_vbox_new( FALSE, 0 );
1884 gtk_container_add( GTK_CONTAINER(align), vbox );
1885
1886 hbox = gtk_hbox_new( FALSE, 0 );
1887 gtk_box_pack_start( GTK_BOX(vbox), hbox, FALSE, FALSE, 0 );
1888
1889 tmp = gtk_label_new_with_mnemonic( _("Background color: ") );
1890 gtk_misc_set_alignment( GTK_MISC(tmp), 0.0, 0.5 );
1891 gtk_box_pack_start( GTK_BOX(hbox), tmp, FALSE, FALSE, 0 );
1892
1893 colorrgb_to_gdkcolor( settings.bgcolor, color );
1894 bgcolor = gtk_color_button_new_with_color( &color );
1895 gtk_color_button_set_title( GTK_COLOR_BUTTON(bgcolor), NULL );
1896 gtk_label_set_mnemonic_widget( GTK_LABEL(tmp), bgcolor );
1897 gtk_box_pack_start( GTK_BOX(hbox), bgcolor, TRUE, TRUE, 0 );
1898
1899 show_code = gtk_check_button_new_with_mnemonic( _("_Show code") );
1900 gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON(show_code), (settings.show_code) ? TRUE : FALSE );
1901 gtk_box_pack_start( GTK_BOX(vbox), show_code, FALSE, FALSE, 0 );
1902
1903 show_active_page_only = gtk_check_button_new_with_mnemonic( _("Show _active page only") );
1904 gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON(show_active_page_only),
1905 (settings.show_active_page_only) ? TRUE : FALSE );
1906 gtk_box_pack_start( GTK_BOX(vbox), show_active_page_only, FALSE, FALSE, 0 );
1907
1908 antialiasing = gtk_check_button_new_with_mnemonic( _("Antialiasing") );
1909 gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON(antialiasing),
1910 (settings.use_antialiasing) ? TRUE : FALSE );
1911 gtk_box_pack_start( GTK_BOX(vbox), antialiasing, FALSE, FALSE, 0 );
1912
1913 hbox = gtk_hbox_new( FALSE, 0 );
1914 gtk_box_pack_start( GTK_BOX(vbox), hbox, FALSE, FALSE, 0 );
1915
1916 tmp = gtk_label_new_with_mnemonic( _("_Plot mode: ") );
1917 gtk_misc_set_alignment( GTK_MISC(tmp), 0.0, 0.5 );
1918 gtk_box_pack_start( GTK_BOX(hbox), tmp, FALSE, FALSE, 0 );
1919
1920 plot_mode = gtk_combo_box_new_text();
1921 gtk_combo_box_append_text( GTK_COMBO_BOX(plot_mode), _("Dots") );
1922 gtk_combo_box_append_text( GTK_COMBO_BOX(plot_mode), _("Connected") );
1923 gtk_combo_box_append_text( GTK_COMBO_BOX(plot_mode), _("Connected without asymptotes") );
1924 if( settings.plot_mode == "Dots" )
1925 gtk_combo_box_set_active( GTK_COMBO_BOX(plot_mode), 0 );
1926 else if(settings.plot_mode == "Connected" )
1927 gtk_combo_box_set_active( GTK_COMBO_BOX(plot_mode), 1 );
1928 else
1929 gtk_combo_box_set_active( GTK_COMBO_BOX(plot_mode), 2 );
1930 gtk_label_set_mnemonic_widget( GTK_LABEL(tmp), plot_mode );
1931 gtk_box_pack_start( GTK_BOX(hbox), plot_mode, TRUE, TRUE, 0 );
1932 }
1933
1934 {
1935 GtkWidget *frame,*align,*table;
1936
1937 frame = gtk_frame_new( _("Axes") );
1938 gtk_box_pack_start( GTK_BOX(box), frame, FALSE, FALSE, 2 );
1939
1940 align = gtk_alignment_new( 0.5, 0.5, 1.0, 1.0 );
1941 gtk_alignment_set_padding( GTK_ALIGNMENT(align), 3, 3, 12, 3 );
1942 gtk_container_add( GTK_CONTAINER(frame), align );
1943
1944 table = gtk_table_new( 4, 2, FALSE );
1945 gtk_container_add( GTK_CONTAINER(align), table );
1946
1947 tmp = gtk_label_new_with_mnemonic( _("Color: ") );
1948 gtk_misc_set_alignment( GTK_MISC(tmp), 0.0, 0.5 );
1949 gtk_table_attach( GTK_TABLE (table), tmp, 0, 1, 0, 1, GTK_FILL,
1950 GtkAttachOptions(0), 1, 1 );
1951
1952 colorrgb_to_gdkcolor( settings.axes_color, color );
1953 axes_color = gtk_color_button_new_with_color( &color );
1954 gtk_color_button_set_title( GTK_COLOR_BUTTON(axes_color), NULL );
1955 gtk_label_set_mnemonic_widget( GTK_LABEL(tmp), axes_color );
1956 gtk_table_attach( GTK_TABLE(table), axes_color, 1, 2, 0, 1,
1957 GtkAttachOptions(GTK_FILL | GTK_EXPAND),
1958 GtkAttachOptions(0), 1, 1 );
1959
1960 tmp = gtk_label_new_with_mnemonic( _("Scale X-axis: ") );
1961 gtk_misc_set_alignment( GTK_MISC(tmp), 0.0, 0.5 );
1962 gtk_table_attach( GTK_TABLE(table), tmp, 0, 1, 1, 2, GTK_FILL,
1963 GtkAttachOptions(0), 1, 1 );
1964
1965 scalex = gtk_entry_new();
1966 gtk_entry_set_max_length( GTK_ENTRY(scalex), 20);
1967 gtk_entry_set_text( GTK_ENTRY(scalex), settings.scalex.c_str() );
1968 gtk_label_set_mnemonic_widget( GTK_LABEL(tmp), scalex );
1969 gtk_table_attach( GTK_TABLE(table), scalex, 1, 2, 1, 2,
1970 GtkAttachOptions(GTK_FILL | GTK_EXPAND),
1971 GtkAttachOptions(0), 1, 1 );
1972
1973 tmp = gtk_label_new_with_mnemonic( _("Scale Y-axis: ") );
1974 gtk_misc_set_alignment( GTK_MISC(tmp), 0.0, 0.5 );
1975 gtk_table_attach( GTK_TABLE(table), tmp, 0, 1, 2, 3, GTK_FILL,
1976 GtkAttachOptions(0), 1, 1 );
1977
1978 scaley = gtk_entry_new();
1979 gtk_entry_set_max_length( GTK_ENTRY(scaley), 20);
1980 gtk_entry_set_text( GTK_ENTRY(scaley), settings.scaley.c_str() );
1981 gtk_label_set_mnemonic_widget( GTK_LABEL(tmp), scaley );
1982 gtk_table_attach( GTK_TABLE(table), scaley, 1, 2, 2, 3,
1983 GtkAttachOptions(GTK_FILL | GTK_EXPAND),
1984 GtkAttachOptions(0), 1, 1);
1985
1986 tmp = gtk_label_new_with_mnemonic( _("Length of scale marks: ") );
1987 gtk_misc_set_alignment( GTK_MISC(tmp), 0.0, 0.5 );
1988 gtk_table_attach( GTK_TABLE(table), tmp, 0, 1, 3, 4, GTK_FILL,
1989 GtkAttachOptions(0), 1, 1);
1990
1991 adj = (GtkAdjustment *) gtk_adjustment_new(settings.scale_length, 0, 100, 1, 5, 5);
1992 scale_length = gtk_spin_button_new(adj, 1, 0);
1993 gtk_label_set_mnemonic_widget(GTK_LABEL(tmp),scale_length);
1994 gtk_table_attach( GTK_TABLE(table), scale_length, 1, 2, 3, 4,
1995 GtkAttachOptions(GTK_FILL | GTK_EXPAND),
1996 GtkAttachOptions(0), 1, 1 );
1997 }
1998
1999 {
2000 GtkWidget *frame,*align,*table;
2001
2002 frame = gtk_frame_new( _("Grid") );
2003 gtk_box_pack_start(GTK_BOX(box),frame,FALSE,FALSE,2);
2004
2005 align = gtk_alignment_new( 0.5, 0.5, 1.0, 1.0 );
2006 gtk_alignment_set_padding( GTK_ALIGNMENT(align), 3, 3, 12, 3 );
2007 gtk_container_add( GTK_CONTAINER(frame), align);
2008
2009 table = gtk_table_new( 4, 2, FALSE );
2010 gtk_container_add( GTK_CONTAINER(align), table );
2011
2012 tmp = gtk_label_new_with_mnemonic( _("Color: ") );
2013 gtk_misc_set_alignment( GTK_MISC(tmp), 0.0, 0.5 );
2014 gtk_table_attach( GTK_TABLE(table), tmp, 0, 1, 0, 1, GTK_FILL,
2015 GtkAttachOptions(0), 1, 1 );
2016
2017 colorrgb_to_gdkcolor( settings.grid_color, color );
2018 grid_color = gtk_color_button_new_with_color( &color );
2019 gtk_color_button_set_title( GTK_COLOR_BUTTON(grid_color), NULL );
2020 gtk_label_set_mnemonic_widget( GTK_LABEL(tmp), grid_color );
2021 gtk_table_attach( GTK_TABLE(table), grid_color, 1, 2, 0, 1,
2022 GtkAttachOptions(GTK_FILL | GTK_EXPAND),
2023 GtkAttachOptions(0), 1, 1 );
2024
2025 tmp = gtk_label_new_with_mnemonic( _("Type: ") );
2026 gtk_misc_set_alignment( GTK_MISC(tmp), 0.0, 0.5 );
2027 gtk_table_attach( GTK_TABLE(table), tmp, 0, 1, 1, 2, GTK_FILL,
2028 GtkAttachOptions(0), 1, 1 );
2029
2030 grid_type = gtk_combo_box_new_text();
2031 gtk_table_attach( GTK_TABLE(table), grid_type, 1, 2, 1, 2,
2032 GtkAttachOptions(GTK_FILL | GTK_EXPAND), GTK_FILL, 0, 0 );
2033 gtk_combo_box_append_text( GTK_COMBO_BOX(grid_type), _("Rectangular") );
2034 gtk_combo_box_append_text( GTK_COMBO_BOX(grid_type), _("Polar") );
2035 if(settings.grid_type == "Rect")
2036 gtk_combo_box_set_active( GTK_COMBO_BOX(grid_type), 0 );
2037 else
2038 gtk_combo_box_set_active( GTK_COMBO_BOX(grid_type), 1 );
2039 g_signal_connect_swapped(GTK_OBJECT(grid_type), "changed", G_CALLBACK(grid_type_changed), NULL);
2040
2041 tmp = gtk_label_new_with_mnemonic( _("Scale 1: ") );
2042 gtk_misc_set_alignment( GTK_MISC(tmp), 0.0, 0.5 );
2043 gtk_table_attach( GTK_TABLE(table), tmp, 0, 1, 2, 3, GTK_FILL,
2044 GtkAttachOptions(0), 1, 1 );
2045
2046 grid_scale1 = gtk_entry_new();
2047 gtk_entry_set_max_length( GTK_ENTRY(grid_scale1), 20);
2048 gtk_entry_set_text( GTK_ENTRY(grid_scale1), settings.grid_scale1.c_str() );
2049 gtk_label_set_mnemonic_widget( GTK_LABEL(tmp), grid_scale1 );
2050 gtk_table_attach( GTK_TABLE(table), grid_scale1, 1, 2, 2, 3,
2051 GtkAttachOptions(GTK_FILL | GTK_EXPAND), GtkAttachOptions(0), 1, 1);
2052 gtk_tooltips_set_tip( tooltips, grid_scale1,
2053 _("In the rectangulary mode this is the X scale,\nelse this is the 'radial' scale."),
2054 NULL );
2055
2056 tmp = gtk_label_new_with_mnemonic( _("Scale 2: ") );
2057 gtk_misc_set_alignment( GTK_MISC(tmp), 0.0, 0.5 );
2058 gtk_table_attach( GTK_TABLE(table), tmp, 0, 1, 3, 4, GTK_FILL,
2059 GtkAttachOptions(0), 1, 1 );
2060
2061 grid_scale2 = gtk_entry_new();
2062 gtk_entry_set_max_length( GTK_ENTRY(grid_scale2), 20);
2063 gtk_entry_set_text( GTK_ENTRY(grid_scale2), settings.grid_scale2.c_str() );
2064 gtk_label_set_mnemonic_widget( GTK_LABEL(tmp), grid_scale2 );
2065 gtk_table_attach( GTK_TABLE(table), grid_scale2, 1, 2, 3, 4,
2066 GtkAttachOptions(GTK_FILL | GTK_EXPAND), GtkAttachOptions(0), 1, 1 );
2067 gtk_tooltips_set_tip( tooltips, grid_scale2,
2068 _("In the rectangulary mode this is the Y scale,\nelse this is the 'degree' scale."),
2069 NULL );
2070 }
2071
2072
2073 box2 = gtk_hbox_new(FALSE,0);
2074 {
2075 GtkWidget *tmpimg,*tmpbox,*tmplabel;
2076 tmpimg = gtk_image_new_from_stock( GTK_STOCK_OK, GTK_ICON_SIZE_BUTTON );
2077
2078 tmplabel = gtk_label_new_with_mnemonic(button_ok);
2079
2080 tmpbox = gtk_hbox_new(FALSE,0);
2081 gtk_box_pack_start( GTK_BOX(tmpbox), tmpimg, FALSE, FALSE, 2 );
2082 gtk_box_pack_start( GTK_BOX(tmpbox), tmplabel, FALSE, FALSE, 2 );
2083 tmp = gtk_button_new();
2084 gtk_container_add(GTK_CONTAINER(tmp),tmpbox);
2085 }
2086 g_signal_connect_swapped( GTK_OBJECT(tmp), "clicked", G_CALLBACK(graphwin_settings_ok), NULL);
2087 gtk_box_pack_end( GTK_BOX(box2), tmp, FALSE, FALSE, 2 );
2088 {
2089 GtkWidget *tmpimg,*tmpbox,*tmplabel;
2090 tmpimg = gtk_image_new_from_stock( GTK_STOCK_CANCEL, GTK_ICON_SIZE_BUTTON );
2091
2092 tmplabel = gtk_label_new_with_mnemonic(button_cancel);
2093
2094 tmpbox = gtk_hbox_new(FALSE,0);
2095 gtk_box_pack_start( GTK_BOX(tmpbox), tmpimg, FALSE, FALSE, 2 );
2096 gtk_box_pack_start( GTK_BOX(tmpbox), tmplabel, FALSE, FALSE, 2 );
2097 tmp = gtk_button_new();
2098 gtk_container_add( GTK_CONTAINER(tmp), tmpbox );
2099 }
2100 g_signal_connect_swapped( GTK_OBJECT(tmp), "clicked", G_CALLBACK(graphwin_settings_close), NULL );
2101 gtk_box_pack_end( GTK_BOX(box2), tmp, FALSE, FALSE, 2 );
2102
2103 gtk_box_pack_start( GTK_BOX(box), box2, FALSE, FALSE, 2 );
2104
2105
2106 gtk_window_set_modal( GTK_WINDOW(graphwin_settings), TRUE );
2107 gtk_window_set_transient_for( GTK_WINDOW(graphwin_settings), GTK_WINDOW(graphwin) );
2108 gtk_container_add( GTK_CONTAINER(graphwin_settings), box );
2109 gtk_widget_show_all(graphwin_settings);
2110 }
2111