atomes 1.2.1
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-2025 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 this_proj -> curves[b][c] -> show_legend = button_get_status ((GtkWidget *)leg);
139 widget_set_sensitive (legend_box, this_proj -> curves[b][c] -> show_legend);
140 if (! this_proj -> curves[b][c] -> show_legend)
141 {
143 }
144 else
145 {
146 widget_set_sensitive (legend_box_style, this_proj -> curves[b][c] -> show_legend_box);
147 }
148 update_curve (data);
149}
150
158void set_legend_box_style (gpointer data)
159{
160 cairo_surface_t * pix;
161 tint * cd = (tint *)data;
162 a = cd -> a;
163 b = cd -> b;
164 c = cd -> c;
165 project * this_proj = get_project_by_id(a);
166 pix = draw_legend_surface (this_proj -> curves[b][c] -> legend_box_dash,
167 this_proj -> curves[b][c] -> legend_box_thickness,
168 this_proj -> curves[b][c] -> legend_box_color,
169 this_proj -> curves[b][c] -> backcolor);
172 cairo_surface_destroy (pix);
173 widget_set_sensitive (legend_style_area, this_proj -> curves[b][c] -> show_legend_box);
175#ifdef GTK4
176 gtk_widget_set_hexpand (legend_style_area, TRUE);
177#endif
178 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, legend_box_style, legend_style_area, TRUE, TRUE, 0);
179 update_curve (data);
180}
181
182#ifdef GTK4
191G_MODULE_EXPORT void show_data_legend_box (GtkCheckButton * bleg, gpointer data)
192#else
201G_MODULE_EXPORT void show_data_legend_box (GtkToggleButton * bleg, gpointer data)
202#endif
203{
204 tint * cd = (tint *)data;
205 a = cd -> a;
206 b = cd -> b;
207 c = cd -> c;
208 project * this_proj = get_project_by_id(a);
209 this_proj -> curves[b][c] -> show_legend_box = button_get_status ((GtkWidget *)bleg);
210 widget_set_sensitive (legend_box_style, this_proj -> curves[b][c] -> show_legend_box);
211 update_curve (data);
212}
213
222G_MODULE_EXPORT void set_legend_font (GtkFontButton * fontb, gpointer data)
223{
224 tint * cd = (tint *)data;
225 a = cd -> a;
226 b = cd -> b;
227 c = cd -> c;
228 project * this_proj = get_project_by_id(a);
229 g_free (this_proj -> curves[b][c] -> legend_font);
230 this_proj -> curves[b][c] -> legend_font = g_strdup_printf ("%s", gtk_font_chooser_get_font (GTK_FONT_CHOOSER(fontb)));
231 update_curve (data);
232}
233
242G_MODULE_EXPORT void set_legend_color (GtkColorChooser * colob, gpointer data)
243{
244 tint * ad = (tint *)data;
245 a = ad -> a;
246 b = ad -> b;
247 c = ad -> c;
248 project * this_proj = get_project_by_id(a);
249 this_proj -> curves[b][c] -> legend_color = get_button_color (colob);
251}
252
261G_MODULE_EXPORT void set_legend_pos (GtkEntry * entry, gpointer data)
262{
263 const gchar *f;
264 double z;
265 qint * ad = (qint *)data;
266 tint cd;
267
268 a = ad -> a;
269 b = ad -> b;
270 c = ad -> c;
271 d = ad -> d;
272 f = entry_get_text (entry);
273 z = string_to_double ((gpointer)f);
274 project * this_proj = get_project_by_id(a);
275 if (z >= 0.0 && z <= 1.0)
276 {
277 this_proj -> curves[b][c] -> legend_pos[d] = z;
278 }
279 else
280 {
281 show_warning (ctext[d], this_proj -> curves[b][c] -> window);
282 }
283 update_entry_double (entry, this_proj -> curves[b][c] -> legend_pos[d]);
284 cd.a = a;
285 cd.b = b;
286 cd.c = c;
287 update_curve (& cd);
288}
289
298G_MODULE_EXPORT void set_legend_box_line (GtkComboBox * fbox, gpointer data)
299{
300 tint * cd = (tint *)data;
301
302 a = cd -> a;
303 b = cd -> b;
304 c = cd -> c;
305 get_project_by_id(a) -> curves[b][c] -> legend_box_dash = combo_get_active ((GtkWidget *)fbox) + 1;
307}
308
317G_MODULE_EXPORT void set_legend_box_thickness (GtkEntry * entry, gpointer data)
318{
319 tint * cd = (tint *)data;
320 const gchar * str;
321
322 a = cd -> a;
323 b = cd -> b;
324 c = cd -> c;
325 str = entry_get_text (entry);
326 project * this_proj = get_project_by_id(a);
327 this_proj -> curves[b][c] -> legend_box_thickness = string_to_double ((gpointer)str);
328 update_entry_double (entry, this_proj -> curves[b][c] -> legend_box_thickness);
330}
331
340G_MODULE_EXPORT void set_legend_box_color (GtkColorChooser * colob, gpointer data)
341{
342 tint * ad = (tint *)data;
343 a = ad -> a;
344 b = ad -> b;
345 c = ad -> c;
346 get_project_by_id(a) -> curves[b][c] -> legend_box_color = get_button_color (colob);
348}
349
357GtkWidget * create_tab_3 (gpointer data)
358{
359 GtkWidget * dhbox;
360 GtkWidget * legend_area;
361 GtkWidget * legend_style_box;
362 GtkWidget * legend_dash_box;
363 GtkWidget * legend_thickness;
364
365 tint * cd = (tint *) data;
366 int i;
367
368 a = cd -> a;
369 b = cd -> b;
370 c = cd -> c;
371 project * this_proj = get_project_by_id(a);
372
373 GtkWidget * legendbox = create_vbox (BSEP);
374 GtkWidget * leghbox = create_hbox (0);
375 add_box_child_start (GTK_ORIENTATION_VERTICAL, legendbox, leghbox, FALSE, FALSE, 10);
376 GtkWidget * legvbox = create_vbox (BSEP);
377 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, leghbox, legvbox, FALSE, FALSE, 10);
378
379 add_box_child_start (GTK_ORIENTATION_VERTICAL, legvbox,
380 check_button ("Show/hide legend", -1, -1, this_proj -> curves[b][c] -> show_legend, G_CALLBACK(show_data_legend), data),
381 FALSE, TRUE, 5);
382
383 legend_area = create_hbox (0);
384 add_box_child_start (GTK_ORIENTATION_VERTICAL, legvbox, legend_area, FALSE, FALSE, 10);
386 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, legend_area, legend_box, FALSE, FALSE, 0);
387
388 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, bbox (legend_box, "Font:"),
389 font_button (this_proj -> curves[b][c] -> legend_font, 150, -1, G_CALLBACK(set_legend_font), data),
390 FALSE, FALSE, 0);
391
392 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, bbox (legend_box, "Color:"),
393 color_button (this_proj -> curves[b][c] -> legend_color, TRUE, 150, 30, G_CALLBACK(set_legend_color), data),
394 FALSE, FALSE, 0);
395
396 dhbox = bbox (legend_box, "Position:");
397 GtkWidget * lxyc;
398 for ( i=0 ; i < 2 ; i++ )
399 {
400 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, dhbox, markup_label(lapos[i], (i==0)?10:30, -1, 1.0, 0.5), FALSE, FALSE, 5);
401 lxyc = create_entry (G_CALLBACK(set_legend_pos), 100, 10, FALSE, (gpointer)& dataxe[i]);
402 update_entry_double (GTK_ENTRY(lxyc), this_proj -> curves[b][c] -> legend_pos[i]);
403 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, dhbox, lxyc, FALSE, FALSE, 5);
404 }
405
406 dhbox = create_hbox (0);
407 add_box_child_start (GTK_ORIENTATION_VERTICAL, legend_box, dhbox, FALSE, FALSE, 10);
408 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, dhbox,
409 check_button ("Show/hide legend box", -1, -1, this_proj -> curves[b][c] -> show_legend_box, G_CALLBACK(show_data_legend_box), data),
410 FALSE, FALSE, 40);
411
413 add_box_child_start (GTK_ORIENTATION_VERTICAL, legend_box, legend_box_style, FALSE, FALSE, 0);
414 legend_style_box = create_vbox (BSEP);
415 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, legend_box_style, legend_style_box, FALSE, FALSE, 0);
416
417// Legend box style
418 legend_dash_box = create_combo ();
419 for ( i=1 ; i < ndash ; i++)
420 {
421 combo_text_append (legend_dash_box, g_strdup_printf("%d", i));
422 }
423 gtk_widget_set_size_request (legend_dash_box, 120, -1);
424 combo_set_active (legend_dash_box, this_proj -> curves[b][c] -> legend_box_dash - 1);
425 g_signal_connect (G_OBJECT(legend_dash_box), "changed", G_CALLBACK(set_legend_box_line), data);
426 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, cbox (legend_style_box, "Line style:"), legend_dash_box, FALSE, FALSE, 0);
427
428// Legend box linewidth
429 legend_thickness = create_entry (G_CALLBACK(set_legend_box_thickness), 120, 10, FALSE, data);
430 update_entry_double (GTK_ENTRY(legend_thickness), this_proj -> curves[b][c] -> legend_box_thickness);
431 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, cbox (legend_style_box, "Line width:"), legend_thickness, FALSE, FALSE, 0);
432
433// Legend box line color
434 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, cbox (legend_style_box, "Color:"),
435 color_button (this_proj -> curves[b][c] -> legend_box_color, TRUE, 120, -1, G_CALLBACK(set_legend_box_color), data),
436 FALSE, FALSE, 0);
437
438// Legend box pix
439 cairo_surface_t * legend_pix = draw_legend_surface (this_proj -> curves[b][c] -> legend_box_dash,
440 this_proj -> curves[b][c] -> legend_box_thickness,
441 this_proj -> curves[b][c] -> legend_box_color,
442 this_proj -> curves[b][c] -> backcolor);
443 legend_style_area = create_image_from_data (IMG_SURFACE, (gpointer)legend_pix);
444 cairo_surface_destroy (legend_pix);
445#ifdef GTK4
446 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, legend_box_style, markup_label(" ", 20, -1, 0.0, 0.0), FALSE, FALSE, 0);
447 gtk_widget_set_hexpand (legend_style_area, TRUE);
448#endif
449 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, legend_box_style, legend_style_area, FALSE, FALSE, 0);
450
451 widget_set_sensitive (legend_box_style, this_proj -> curves[b][c] -> show_legend_box);
452 widget_set_sensitive (legend_box, this_proj -> curves[b][c] -> show_legend);
453 return legendbox;
454}
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:264
int combo_get_active(GtkWidget *combo)
retrieve the active item's position
Definition gtk-misc.c:909
GtkWidget * create_entry(GCallback handler, int dim, int cdim, gboolean key_release, gpointer data)
Create a GtkEntry.
Definition gtk-misc.c:1375
void update_entry_double(GtkEntry *entry, double doubleval)
update the content of a GtkEntry as double
Definition gtk-misc.c:643
GtkWidget * font_button(gchar *font, int dimx, int dimy, GCallback handler, gpointer data)
create a font selection button
Definition gtk-misc.c:1811
void combo_set_active(GtkWidget *combo, int pos)
set the active item's position
Definition gtk-misc.c:932
const gchar * entry_get_text(GtkEntry *entry)
get the text in a GtkEntry
Definition gtk-misc.c:607
#define BSEP
Definition global.h:247
GtkWidget * fbox(GtkWidget *box, char *lab)
box creating routine, to help design faster elements for the GUI
Definition gtk-misc.c:2076
GtkWidget * check_button(gchar *text, int dimx, int dimy, gboolean state, GCallback handler, gpointer data)
create a check button
Definition gtk-misc.c:1893
GtkWidget * create_combo()
create a GtkCombox widget, note deprecated in GTK4
Definition gtk-misc.c:984
GtkWidget * markup_label(gchar *text, int dimx, int dimy, float ax, float ay)
create a GtkLabel with pango markup
Definition gtk-misc.c:1646
GtkWidget * cbox(GtkWidget *box, char *lab)
box creating routine, to help design faster elements for the GUI
Definition gtk-misc.c:2058
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:308
ColRGBA get_button_color(GtkColorChooser *colob)
get the ColRGBA color from a GtkColorChooser button
Definition gtk-misc.c:2371
void widget_set_sensitive(GtkWidget *widg, gboolean sensitive)
Set sensitivity for a GtkWidget, ensuring it is a GtkWidget.
Definition gtk-misc.c:215
GtkWidget * create_hbox(int spacing)
create a GtkBox with horizontal orientation
Definition gtk-misc.c:823
GtkWidget * create_image_from_data(int format, gpointer item_image)
create Gtk image for data
Definition gtk-misc.c:1504
void combo_text_append(GtkWidget *combo, gchar *text)
append text in GtkComboBox widget
Definition gtk-misc.c:961
GtkWidget * destroy_this_widget(GtkWidget *widg)
destroy a GtkWidget
Definition gtk-misc.c:2169
GtkWidget * color_button(ColRGBA col, gboolean alpha, int dimx, int dimy, GCallback handler, gpointer data)
create a color selection button
Definition gtk-misc.c:1789
GtkWidget * bbox(GtkWidget *box, char *lab)
box creating routine, to help design faster elements for the GUI
Definition gtk-misc.c:2040
GtkWidget * create_vbox(int spacing)
create a GtkBox with vertical orientation
Definition gtk-misc.c:811
int button_get_status(GtkWidget *button)
get status of check / toggle button
Definition gtk-misc.c:1855
void show_the_widgets(GtkWidget *widg)
show GtkWidget
Definition gtk-misc.c:182
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:61
Function declarations for reading atomes project file Function declarations for saving atomes proje...
float blue
Definition global.h:126
float red
Definition global.h:124
float green
Definition global.h:125
Definition global.h:114
Definition global.h:106
int b
Definition global.h:108
int c
Definition global.h:109
int a
Definition global.h:107
void set_legend_box_style(gpointer data)
update legend style widgets
Definition tab-3.c:158
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:317
G_MODULE_EXPORT void set_legend_color(GtkColorChooser *colob, gpointer data)
change legend color
Definition tab-3.c:242
G_MODULE_EXPORT void set_legend_box_color(GtkColorChooser *colob, gpointer data)
set legend color
Definition tab-3.c:340
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:222
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:201
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:261
GtkWidget * create_tab_3(gpointer data)
handle the creation of the 3rd tab of the curve edition dialog
Definition tab-3.c:357
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:298
GdkPixbuf * pix
Definition workspace.c:69