atomes 1.1.15
atomes: an atomic scale modeling tool box
Loading...
Searching...
No Matches
tab-3.c
Go to the documentation of this file.
1/* This file is part of the 'atomes' software
2
3'atomes' is free software: you can redistribute it and/or modify it under the terms
4of the GNU Affero General Public License as published by the Free Software Foundation,
5either version 3 of the License, or (at your option) any later version.
6
7'atomes' is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
8without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
9See the GNU General Public License for more details.
10
11You should have received a copy of the GNU Affero General Public License along with 'atomes'.
12If not, see <https://www.gnu.org/licenses/>
13
14Copyright (C) 2022-2024 by CNRS and University of Strasbourg */
15
22/*
23* This file: 'tab-3.c'
24*
25* Contains:
26*
27
28 - The 3rd tab of the curve layout edition dialog
29
30*
31* List of functions:
32
33 void set_legend_box_style (gpointer data);
34
35 G_MODULE_EXPORT void show_data_legend (GtkCheckButton * leg, gpointer data);
36 G_MODULE_EXPORT void show_data_legend (GtkToggleButton * leg, gpointer data);
37 G_MODULE_EXPORT void show_data_legend_box (GtkCheckButton * bleg, gpointer data);
38 G_MODULE_EXPORT void show_data_legend_box (GtkToggleButton * bleg, gpointer data);
39 G_MODULE_EXPORT void set_legend_font (GtkFontButton * fontb, gpointer data);
40 G_MODULE_EXPORT void set_legend_color (GtkColorChooser * colob, gpointer data);
41 G_MODULE_EXPORT void set_legend_pos (GtkEntry * p, gpointer data);
42 G_MODULE_EXPORT void set_legend_box_line (GtkComboBox * fbox, gpointer data);
43 G_MODULE_EXPORT void set_legend_box_thickness (GtkEntry * entry, gpointer data);
44 G_MODULE_EXPORT void set_legend_box_color (GtkColorChooser * colob, gpointer data);
45
46 GtkWidget * create_tab_3 (gpointer data);
47
48*/
49
50#ifdef HAVE_CONFIG_H
51# include <config.h>
52#endif
53
54#include <gtk/gtk.h>
55#include <cairo.h>
56#include <cairo-pdf.h>
57#include <cairo-svg.h>
58#include <string.h>
59#include <stdlib.h>
60#include <math.h>
61
62#include "global.h"
63#include "interface.h"
64#include "callbacks.h"
65#include "project.h"
66#include "curve.h"
67#include "cedit.h"
68
69GtkWidget * legend_box = NULL;
70GtkWidget * legend_box_style = NULL;
71GtkWidget * legend_style_area = NULL;
72
73extern char * ctext[2];
74extern qint dataxe[2];
75extern int a, b, c, d;
76
87cairo_surface_t * draw_legend_surface (int da, double ti, ColRGBA dcol, ColRGBA bcol)
88{
89 cairo_surface_t * cst;
90 cairo_t * tcst;
91 curve_dash * tdash;
92 cst = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 80, 80);
93 tcst = cairo_create (cst);
94 tdash = selectdash (da);
95 cairo_set_dash (tcst, tdash -> a, tdash -> b, 0);
96 cairo_set_source_rgb (tcst, bcol.red, bcol.green, bcol.blue);
97 cairo_paint (tcst);
98 cairo_set_source_rgb (tcst, dcol.red, dcol.green, dcol.blue);
99 cairo_set_line_width (tcst, ti);
100 cairo_move_to (tcst, 10, 10);
101 cairo_line_to (tcst, 70, 10);
102 cairo_line_to (tcst, 70, 70);
103 cairo_line_to (tcst, 10, 70);
104 cairo_line_to (tcst, 10, 10);
105 cairo_stroke (tcst);
106 g_free (tdash);
107 cairo_destroy (tcst);
108 return cst;
109}
110
111#ifdef GTK4
120G_MODULE_EXPORT void show_data_legend (GtkCheckButton * leg, gpointer data)
121#else
130G_MODULE_EXPORT void show_data_legend (GtkToggleButton * leg, gpointer data)
131#endif
132{
133 tint * cd = (tint *)data;
134 a = cd -> a;
135 b = cd -> b;
136 c = cd -> c;
137 project * this_proj = get_project_by_id(a);
138#ifdef GTK4
139 this_proj -> curves[b][c] -> show_legend = gtk_check_button_get_active (leg);
140#else
141 this_proj -> curves[b][c] -> show_legend = gtk_toggle_button_get_active (leg);
142#endif
143 widget_set_sensitive (legend_box, this_proj -> curves[b][c] -> show_legend);
144 if (! this_proj -> curves[b][c] -> show_legend)
145 {
147 }
148 else
149 {
150 widget_set_sensitive (legend_box_style, this_proj -> curves[b][c] -> show_legend_box);
151 }
152 update_curve (data);
153}
154
162void set_legend_box_style (gpointer data)
163{
164 cairo_surface_t * pix;
165 tint * cd = (tint *)data;
166 a = cd -> a;
167 b = cd -> b;
168 c = cd -> c;
169 project * this_proj = get_project_by_id(a);
170 pix = draw_legend_surface (this_proj -> curves[b][c] -> legend_box_dash,
171 this_proj -> curves[b][c] -> legend_box_thickness,
172 this_proj -> curves[b][c] -> legend_box_color,
173 this_proj -> curves[b][c] -> backcolor);
176 cairo_surface_destroy (pix);
177 widget_set_sensitive (legend_style_area, this_proj -> curves[b][c] -> show_legend_box);
179#ifdef GTK4
180 gtk_widget_set_hexpand (legend_style_area, TRUE);
181#endif
182 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, legend_box_style, legend_style_area, TRUE, TRUE, 0);
183 update_curve (data);
184}
185
186#ifdef GTK4
195G_MODULE_EXPORT void show_data_legend_box (GtkCheckButton * bleg, gpointer data)
196#else
205G_MODULE_EXPORT void show_data_legend_box (GtkToggleButton * bleg, gpointer data)
206#endif
207{
208 tint * cd = (tint *)data;
209 a = cd -> a;
210 b = cd -> b;
211 c = cd -> c;
212 project * this_proj = get_project_by_id(a);
213#ifdef GTK4
214 this_proj -> curves[b][c] -> show_legend_box = gtk_check_button_get_active (bleg);
215#else
216 this_proj -> curves[b][c] -> show_legend_box = gtk_toggle_button_get_active (bleg);
217#endif
218 widget_set_sensitive (legend_box_style, this_proj -> curves[b][c] -> show_legend_box);
219 update_curve (data);
220}
221
230G_MODULE_EXPORT void set_legend_font (GtkFontButton * fontb, gpointer data)
231{
232 tint * cd = (tint *)data;
233 a = cd -> a;
234 b = cd -> b;
235 c = cd -> c;
236 project * this_proj = get_project_by_id(a);
237 g_free (this_proj -> curves[b][c] -> legend_font);
238 this_proj -> curves[b][c] -> legend_font = g_strdup_printf ("%s", gtk_font_chooser_get_font (GTK_FONT_CHOOSER(fontb)));
239 update_curve (data);
240}
241
250G_MODULE_EXPORT void set_legend_color (GtkColorChooser * colob, gpointer data)
251{
252 tint * ad = (tint *)data;
253 a = ad -> a;
254 b = ad -> b;
255 c = ad -> c;
256 project * this_proj = get_project_by_id(a);
257 this_proj -> curves[b][c] -> legend_color = get_button_color (colob);
259}
260
269G_MODULE_EXPORT void set_legend_pos (GtkEntry * entry, gpointer data)
270{
271 const gchar *f;
272 double z;
273 qint * ad = (qint *)data;
274 tint cd;
275
276 a = ad -> a;
277 b = ad -> b;
278 c = ad -> c;
279 d = ad -> d;
280 f = entry_get_text (entry);
281 z = string_to_double ((gpointer)f);
282 project * this_proj = get_project_by_id(a);
283 if (z >= 0.0 && z <= 1.0)
284 {
285 this_proj -> curves[b][c] -> legend_pos[d] = z;
286 }
287 else
288 {
289 show_warning (ctext[d], this_proj -> curves[b][c] -> window);
290 }
291 update_entry_double (entry, this_proj -> curves[b][c] -> legend_pos[d]);
292 cd.a = a;
293 cd.b = b;
294 cd.c = c;
295 update_curve (& cd);
296}
297
306G_MODULE_EXPORT void set_legend_box_line (GtkComboBox * fbox, gpointer data)
307{
308 tint * cd = (tint *)data;
309
310 a = cd -> a;
311 b = cd -> b;
312 c = cd -> c;
313 get_project_by_id(a) -> curves[b][c] -> legend_box_dash = gtk_combo_box_get_active (GTK_COMBO_BOX(fbox)) + 1;
315}
316
325G_MODULE_EXPORT void set_legend_box_thickness (GtkEntry * entry, gpointer data)
326{
327 tint * cd = (tint *)data;
328 const gchar * str;
329
330 a = cd -> a;
331 b = cd -> b;
332 c = cd -> c;
333 str = entry_get_text (entry);
334 project * this_proj = get_project_by_id(a);
335 this_proj -> curves[b][c] -> legend_box_thickness = string_to_double ((gpointer)str);
336 update_entry_double (entry, this_proj -> curves[b][c] -> legend_box_thickness);
338}
339
348G_MODULE_EXPORT void set_legend_box_color (GtkColorChooser * colob, gpointer data)
349{
350 tint * ad = (tint *)data;
351 a = ad -> a;
352 b = ad -> b;
353 c = ad -> c;
354 get_project_by_id(a) -> curves[b][c] -> legend_box_color = get_button_color (colob);
356}
357
365GtkWidget * create_tab_3 (gpointer data)
366{
367 GtkWidget * dhbox;
368 GtkWidget * legend_area;
369 GtkWidget * legend_style_box;
370 GtkWidget * legend_dash_box;
371 GtkWidget * legend_thickness;
372
373 tint * cd = (tint *) data;
374 int i;
375
376 a = cd -> a;
377 b = cd -> b;
378 c = cd -> c;
379 project * this_proj = get_project_by_id(a);
380
381 GtkWidget * legendbox = create_vbox (BSEP);
382 GtkWidget * leghbox = create_hbox (0);
383 add_box_child_start (GTK_ORIENTATION_VERTICAL, legendbox, leghbox, FALSE, FALSE, 10);
384 GtkWidget * legvbox = create_vbox (BSEP);
385 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, leghbox, legvbox, FALSE, FALSE, 10);
386
387 add_box_child_start (GTK_ORIENTATION_VERTICAL, legvbox,
388 check_button ("Show/hide legend", -1, -1, this_proj -> curves[b][c] -> show_legend, G_CALLBACK(show_data_legend), data),
389 FALSE, TRUE, 5);
390
391 legend_area = create_hbox (0);
392 add_box_child_start (GTK_ORIENTATION_VERTICAL, legvbox, legend_area, FALSE, FALSE, 10);
394 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, legend_area, legend_box, FALSE, FALSE, 0);
395
396 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, bbox (legend_box, "Font:"),
397 font_button (this_proj -> curves[b][c] -> legend_font, 150, -1, G_CALLBACK(set_legend_font), data),
398 FALSE, FALSE, 0);
399
400 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, bbox (legend_box, "Color:"),
401 color_button (this_proj -> curves[b][c] -> legend_color, TRUE, 150, 30, G_CALLBACK(set_legend_color), data),
402 FALSE, FALSE, 0);
403
404 dhbox = bbox (legend_box, "Position:");
405 GtkWidget * lxyc;
406 for ( i=0 ; i < 2 ; i++ )
407 {
408 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, dhbox, markup_label(lapos[i], (i==0)?10:30, -1, 1.0, 0.5), FALSE, FALSE, 5);
409 lxyc = create_entry (G_CALLBACK(set_legend_pos), 100, 10, FALSE, (gpointer)& dataxe[i]);
410 update_entry_double (GTK_ENTRY(lxyc), this_proj -> curves[b][c] -> legend_pos[i]);
411 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, dhbox, lxyc, FALSE, FALSE, 5);
412 }
413
414 dhbox = create_hbox (0);
415 add_box_child_start (GTK_ORIENTATION_VERTICAL, legend_box, dhbox, FALSE, FALSE, 10);
416 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, dhbox,
417 check_button ("Show/hide legend box", -1, -1, this_proj -> curves[b][c] -> show_legend_box, G_CALLBACK(show_data_legend_box), data),
418 FALSE, FALSE, 40);
419
421 add_box_child_start (GTK_ORIENTATION_VERTICAL, legend_box, legend_box_style, FALSE, FALSE, 0);
422 legend_style_box = create_vbox (BSEP);
423 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, legend_box_style, legend_style_box, FALSE, FALSE, 0);
424
425// Legend box style
426 legend_dash_box = create_combo ();
427 for ( i=1 ; i < ndash ; i++)
428 {
429 combo_text_append (legend_dash_box, g_strdup_printf("%d", i));
430 }
431 gtk_widget_set_size_request (legend_dash_box, 120, -1);
432 gtk_combo_box_set_active(GTK_COMBO_BOX(legend_dash_box), this_proj -> curves[b][c] -> legend_box_dash - 1);
433 g_signal_connect (G_OBJECT(legend_dash_box), "changed", G_CALLBACK(set_legend_box_line), data);
434 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, cbox (legend_style_box, "Line style:"), legend_dash_box, FALSE, FALSE, 0);
435
436// Legend box linewidth
437 legend_thickness = create_entry (G_CALLBACK(set_legend_box_thickness), 120, 10, FALSE, data);
438 update_entry_double (GTK_ENTRY(legend_thickness), this_proj -> curves[b][c] -> legend_box_thickness);
439 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, cbox (legend_style_box, "Line width:"), legend_thickness, FALSE, FALSE, 0);
440
441// Legend box line color
442 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, cbox (legend_style_box, "Color:"),
443 color_button (this_proj -> curves[b][c] -> legend_box_color, TRUE, 120, -1, G_CALLBACK(set_legend_box_color), data),
444 FALSE, FALSE, 0);
445
446// Legend box pix
447 cairo_surface_t * legend_pix = draw_legend_surface (this_proj -> curves[b][c] -> legend_box_dash,
448 this_proj -> curves[b][c] -> legend_box_thickness,
449 this_proj -> curves[b][c] -> legend_box_color,
450 this_proj -> curves[b][c] -> backcolor);
451 legend_style_area = create_image_from_data (IMG_SURFACE, (gpointer)legend_pix);
452 cairo_surface_destroy (legend_pix);
453#ifdef GTK4
454 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, legend_box_style, markup_label(" ", 20, -1, 0.0, 0.0), FALSE, FALSE, 0);
455 gtk_widget_set_hexpand (legend_style_area, TRUE);
456#endif
457 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, legend_box_style, legend_style_area, FALSE, FALSE, 0);
458
459 widget_set_sensitive (legend_box_style, this_proj -> curves[b][c] -> show_legend_box);
460 widget_set_sensitive (legend_box, this_proj -> curves[b][c] -> show_legend);
461 return legendbox;
462}
Callback declarations for main window.
char * lapos[2]
Definition cedit.c:89
Variable declarations for the curve layout edition window.
curve_dash * selectdash(int iddash)
setup dash pointer
Definition curve.c:134
int ndash
Definition curve.c:91
void update_curve(gpointer data)
update curve rendering
Definition curve.c:589
Variable declarations for the curve widget Functions for interactions with the curve widget.
void show_legend(cairo_t *cr, project *this_proj, int rid, int cid)
draw legend
Definition legend.c:56
double string_to_double(gpointer string)
convert string to double
Definition global.c:624
Global variable declarations Global convenience function declarations Global data structure defin...
@ IMG_SURFACE
Definition global.h:262
GtkWidget * create_entry(GCallback handler, int dim, int cdim, gboolean key_release, gpointer data)
Create a GtkEntry.
Definition gtk-misc.c:1314
void update_entry_double(GtkEntry *entry, double doubleval)
update the content of a GtkEntry as double
Definition gtk-misc.c:633
GtkWidget * font_button(gchar *font, int dimx, int dimy, GCallback handler, gpointer data)
create a font selection button
Definition gtk-misc.c:1750
const gchar * entry_get_text(GtkEntry *entry)
get the text in a GtkEntry
Definition gtk-misc.c:597
#define BSEP
Definition global.h:245
GtkWidget * fbox(GtkWidget *box, char *lab)
Definition gtk-misc.c:1941
GtkWidget * check_button(gchar *text, int dimx, int dimy, gboolean state, GCallback handler, gpointer data)
create a check button
Definition gtk-misc.c:1799
GtkWidget * create_combo()
create a GtkCombox widget, note deprecated in GTK4
Definition gtk-misc.c:923
GtkWidget * markup_label(gchar *text, int dimx, int dimy, float ax, float ay)
Definition gtk-misc.c:1585
GtkWidget * cbox(GtkWidget *box, char *lab)
Definition gtk-misc.c:1931
void add_box_child_start(int orientation, GtkWidget *widg, GtkWidget *child, gboolean expand, gboolean fill, int padding)
Add a GtkWidget in a GtkBox at the initial position.
Definition gtk-misc.c:299
ColRGBA get_button_color(GtkColorChooser *colob)
get the ColRGBA color from a GtkColorChooser button
Definition gtk-misc.c:2236
void widget_set_sensitive(GtkWidget *widg, gboolean sensitive)
Set sensitivity for a GtkWidget, ensuring it is a GtkWidget.
Definition gtk-misc.c:206
GtkWidget * create_hbox(int spacing)
create a GtkBox with horizontal orientation
Definition gtk-misc.c:813
GtkWidget * create_image_from_data(int format, gpointer item_image)
create Gtk image for data
Definition gtk-misc.c:1443
void combo_text_append(GtkWidget *combo, gchar *text)
append text in GtkComboBox widget
Definition gtk-misc.c:900
GtkWidget * destroy_this_widget(GtkWidget *widg)
destroy a GtkWidget
Definition gtk-misc.c:2034
GtkWidget * color_button(ColRGBA col, gboolean alpha, int dimx, int dimy, GCallback handler, gpointer data)
create a color selection button
Definition gtk-misc.c:1728
GtkWidget * bbox(GtkWidget *box, char *lab)
Definition gtk-misc.c:1921
GtkWidget * create_vbox(int spacing)
create a GtkBox with vertical orientation
Definition gtk-misc.c:801
void show_the_widgets(GtkWidget *widg)
show GtkWidget
Definition gtk-misc.c:173
project * get_project_by_id(int p)
get project pointer using id number
Definition project.c:120
void show_warning(char *warning, GtkWidget *win)
show warning
Definition interface.c:260
Messaging function declarations.
double z
Definition ogl_draw.c:57
Function declarations for reading atomes project file Function declarations for saving atomes proje...
float blue
Definition global.h:124
float red
Definition global.h:122
float green
Definition global.h:123
Definition global.h:112
Definition global.h:104
int b
Definition global.h:106
int c
Definition global.h:107
int a
Definition global.h:105
void set_legend_box_style(gpointer data)
update legend style widgets
Definition tab-3.c:162
int b
Definition tab-3.c:75
G_MODULE_EXPORT void show_data_legend(GtkToggleButton *leg, gpointer data)
show / hide legend toggle callback GTK3
Definition tab-3.c:130
int c
Definition tab-3.c:75
G_MODULE_EXPORT void set_legend_box_thickness(GtkEntry *entry, gpointer data)
set legend box thickness entry callback
Definition tab-3.c:325
G_MODULE_EXPORT void set_legend_color(GtkColorChooser *colob, gpointer data)
change legend color
Definition tab-3.c:250
G_MODULE_EXPORT void set_legend_box_color(GtkColorChooser *colob, gpointer data)
set legend color
Definition tab-3.c:348
int d
Definition tab-3.c:75
cairo_surface_t * draw_legend_surface(int da, double ti, ColRGBA dcol, ColRGBA bcol)
draw legend preview
Definition tab-3.c:87
G_MODULE_EXPORT void set_legend_font(GtkFontButton *fontb, gpointer data)
change legend font
Definition tab-3.c:230
int a
Definition tab-1.c:95
GtkWidget * legend_style_area
Definition tab-3.c:71
G_MODULE_EXPORT void show_data_legend_box(GtkToggleButton *bleg, gpointer data)
show / hide legend box toggle callback GTK3
Definition tab-3.c:205
char * ctext[2]
Definition tab-1.c:91
qint dataxe[2]
Definition tab-1.c:92
GtkWidget * legend_box
Definition tab-3.c:69
G_MODULE_EXPORT void set_legend_pos(GtkEntry *entry, gpointer data)
set the legend position entry callback
Definition tab-3.c:269
GtkWidget * create_tab_3(gpointer data)
handle the creation of the 3rd tab of the curve edition dialog
Definition tab-3.c:365
GtkWidget * legend_box_style
Definition tab-3.c:70
G_MODULE_EXPORT void set_legend_box_line(GtkComboBox *fbox, gpointer data)
change the legend box line type
Definition tab-3.c:306
GdkPixbuf * pix
Definition workspace.c:69