atomes 1.3.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-2026 by CNRS and University of Strasbourg */
15
21
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
78cairo_surface_t * draw_legend_surface (int da, double ti, ColRGBA dcol, ColRGBA bcol)
79{
80 cairo_surface_t * cst;
81 cairo_t * tcst;
82 curve_dash * tdash;
83 cst = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 80, 80);
84 tcst = cairo_create (cst);
85 tdash = selectdash (da);
86 cairo_set_dash (tcst, tdash -> a, tdash -> b, 0);
87 cairo_set_source_rgb (tcst, bcol.red, bcol.green, bcol.blue);
88 cairo_paint (tcst);
89 cairo_set_source_rgb (tcst, dcol.red, dcol.green, dcol.blue);
90 cairo_set_line_width (tcst, ti);
91 cairo_move_to (tcst, 10, 10);
92 cairo_line_to (tcst, 70, 10);
93 cairo_line_to (tcst, 70, 70);
94 cairo_line_to (tcst, 10, 70);
95 cairo_line_to (tcst, 10, 10);
96 cairo_stroke (tcst);
97 g_free (tdash);
98 cairo_destroy (tcst);
99 return cst;
100}
101
102#ifdef GTK4
111G_MODULE_EXPORT void show_data_legend (GtkCheckButton * leg, gpointer data)
112#else
121G_MODULE_EXPORT void show_data_legend (GtkToggleButton * leg, gpointer data)
122#endif
123{
124 Curve * this_curve = get_curve_from_pointer (data);
125 this_curve -> show_legend = button_get_status ((GtkWidget *)leg);
126 widget_set_sensitive (this_curve -> curve_edit -> legend_box, this_curve -> show_legend);
127 if (! this_curve -> show_legend)
128 {
129 widget_set_sensitive (this_curve -> curve_edit -> legend_box_style, 0);
130 }
131 else
132 {
133 widget_set_sensitive (this_curve -> curve_edit -> legend_box_style, this_curve -> show_legend_box);
134 }
135 update_curve (data);
136}
137
145void set_legend_box_style (gpointer data)
146{
147 cairo_surface_t * pix;
148 Curve * this_curve = get_curve_from_pointer (data);
149 curve_edition * cedit = this_curve -> curve_edit;
150 pix = draw_legend_surface (this_curve -> legend_box_dash,
151 this_curve -> legend_box_thickness,
152 this_curve -> legend_box_color,
153 this_curve -> backcolor);
154 cedit -> legend_style_area = destroy_this_widget (cedit -> legend_style_area);
155 cedit -> legend_style_area = create_image_from_data (IMG_SURFACE, (gpointer)pix);
156 cairo_surface_destroy (pix);
157 widget_set_sensitive (cedit -> legend_style_area, this_curve -> show_legend_box);
158 show_the_widgets (cedit -> legend_style_area);
159#ifdef GTK4
160 gtk_widget_set_hexpand (cedit -> legend_style_area, TRUE);
161#endif
162 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, cedit -> legend_box_style, cedit -> legend_style_area, TRUE, TRUE, 0);
163 update_curve (data);
164}
165
166#ifdef GTK4
175G_MODULE_EXPORT void show_data_legend_box (GtkCheckButton * bleg, gpointer data)
176#else
185G_MODULE_EXPORT void show_data_legend_box (GtkToggleButton * bleg, gpointer data)
186#endif
187{
188 get_curve_from_pointer (data) -> show_legend_box = button_get_status ((GtkWidget *)bleg);
189 widget_set_sensitive (get_curve_from_pointer (data) -> curve_edit -> legend_box_style, get_curve_from_pointer (data) -> show_legend_box);
190 update_curve (data);
191}
192
201G_MODULE_EXPORT void set_legend_font (GtkFontButton * fontb, gpointer data)
202{
203 Curve * this_curve = get_curve_from_pointer (data);
204 g_free (this_curve -> legend_font);
205 this_curve -> legend_font = g_strdup_printf ("%s", gtk_font_chooser_get_font (GTK_FONT_CHOOSER(fontb)));
206 update_curve (data);
207}
208
217G_MODULE_EXPORT void set_legend_color (GtkColorChooser * colob, gpointer data)
218{
219 get_curve_from_pointer (data) -> legend_color = get_button_color (colob);
221}
222
231G_MODULE_EXPORT void set_legend_pos (GtkEntry * entry, gpointer data)
232{
233 const gchar *f;
234 double z;
235 qint * ad = (qint *)data;
236 tint cd;
237 cd.a = ad -> a;
238 cd.b = ad -> b;
239 cd.c = ad -> c;
240 f = entry_get_text (entry);
241 z = string_to_double ((gpointer)f);
242 Curve * this_curve = get_curve_from_pointer ((gpointer)& cd);
243 if (z >= 0.0 && z <= 1.0)
244 {
245 this_curve -> legend_pos[ad -> d] = z;
246 }
247 else
248 {
249 show_warning (ctext[ad -> d], this_curve -> window);
250 }
251 update_entry_double (entry, this_curve -> legend_pos[ad -> d]);
252
253 update_curve (& cd);
254}
255
264G_MODULE_EXPORT void set_legend_box_line (GtkComboBox * fbox, gpointer data)
265{
266 get_curve_from_pointer (data) -> legend_box_dash = combo_get_active ((GtkWidget *)fbox) + 1;
268}
269
278G_MODULE_EXPORT void set_legend_box_thickness (GtkEntry * entry, gpointer data)
279{
280 const gchar * str;
281 Curve * this_curve = get_curve_from_pointer (data);
282 str = entry_get_text (entry);
283 this_curve -> legend_box_thickness = string_to_double ((gpointer)str);
284 update_entry_double (entry, this_curve -> legend_box_thickness);
286}
287
296G_MODULE_EXPORT void set_legend_box_color (GtkColorChooser * colob, gpointer data)
297{
298 get_curve_from_pointer (data) -> legend_box_color = get_button_color (colob);
300}
301
310GtkWidget * create_tab_3 (curve_edition * cedit, gpointer data)
311{
312 GtkWidget * dhbox;
313 GtkWidget * legend_area;
314 GtkWidget * legend_style_box;
315 GtkWidget * legend_dash_box;
316 GtkWidget * legend_thickness;
317
318 int i;
319 Curve * this_curve = get_curve_from_pointer (data);
320 GtkWidget * legendbox = create_vbox (BSEP);
321 GtkWidget * leghbox = create_hbox (0);
322 add_box_child_start (GTK_ORIENTATION_VERTICAL, legendbox, leghbox, FALSE, FALSE, 10);
323 GtkWidget * legvbox = create_vbox (BSEP);
324 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, leghbox, legvbox, FALSE, FALSE, 10);
325
326 add_box_child_start (GTK_ORIENTATION_VERTICAL, legvbox,
327 check_button (_("Show/Hide legend"), -1, -1, this_curve -> show_legend, G_CALLBACK(show_data_legend), data),
328 FALSE, TRUE, 5);
329
330 legend_area = create_hbox (0);
331 add_box_child_start (GTK_ORIENTATION_VERTICAL, legvbox, legend_area, FALSE, FALSE, 10);
332 cedit -> legend_box = create_vbox (BSEP);
333 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, legend_area, cedit -> legend_box, FALSE, FALSE, 0);
334
335 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, bbox (cedit -> legend_box, _("Font:")),
336 font_button (this_curve -> legend_font, 150, -1, G_CALLBACK(set_legend_font), data),
337 FALSE, FALSE, 0);
338
339 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, bbox (cedit -> legend_box, _("Color:")),
340 color_button (this_curve -> legend_color, TRUE, 150, 30, G_CALLBACK(set_legend_color), data),
341 FALSE, FALSE, 0);
342
343 dhbox = bbox (cedit -> legend_box, _("Position:"));
344 GtkWidget * lxyc;
345 for ( i=0 ; i < 2 ; i++ )
346 {
347 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, dhbox, markup_label(lapos[i], (i==0)?10:30, -1, 1.0, 0.5), FALSE, FALSE, 5);
348 lxyc = create_entry (G_CALLBACK(set_legend_pos), 100, 10, FALSE, (gpointer)& cedit -> dataxe[i]);
349 update_entry_double (GTK_ENTRY(lxyc), this_curve -> legend_pos[i]);
350 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, dhbox, lxyc, FALSE, FALSE, 5);
351 }
352
353 dhbox = create_hbox (0);
354 add_box_child_start (GTK_ORIENTATION_VERTICAL, cedit -> legend_box, dhbox, FALSE, FALSE, 10);
355 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, dhbox,
356 check_button (_("Show/Hide legend box"), -1, -1, this_curve -> show_legend_box, G_CALLBACK(show_data_legend_box), data),
357 FALSE, FALSE, 40);
358
359 cedit -> legend_box_style = create_hbox (0);
360 add_box_child_start (GTK_ORIENTATION_VERTICAL, cedit -> legend_box, cedit -> legend_box_style, FALSE, FALSE, 0);
361 legend_style_box = create_vbox (BSEP);
362 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, cedit -> legend_box_style, legend_style_box, FALSE, FALSE, 0);
363
364// Legend box style
365 legend_dash_box = create_combo ();
366 for ( i=1 ; i < ndash ; i++)
367 {
368 combo_text_append (legend_dash_box, g_strdup_printf("%d", i));
369 }
370 gtk_widget_set_size_request (legend_dash_box, 120, -1);
371 combo_set_active (legend_dash_box, this_curve -> legend_box_dash - 1);
372 g_signal_connect (G_OBJECT(legend_dash_box), "changed", G_CALLBACK(set_legend_box_line), data);
373 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, cbox (legend_style_box, _("Line style:")), legend_dash_box, FALSE, FALSE, 0);
374
375// Legend box linewidth
376 legend_thickness = create_entry (G_CALLBACK(set_legend_box_thickness), 120, 10, FALSE, data);
377 update_entry_double (GTK_ENTRY(legend_thickness), this_curve -> legend_box_thickness);
378 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, cbox (legend_style_box, _("Line width:")), legend_thickness, FALSE, FALSE, 0);
379
380// Legend box line color
381 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, cbox (legend_style_box, _("Color:")),
382 color_button (this_curve -> legend_box_color, TRUE, 120, -1, G_CALLBACK(set_legend_box_color), data),
383 FALSE, FALSE, 0);
384
385// Legend box pix
386 cairo_surface_t * legend_pix = draw_legend_surface (this_curve -> legend_box_dash,
387 this_curve -> legend_box_thickness,
388 this_curve -> legend_box_color,
389 this_curve -> backcolor);
390 cedit -> legend_style_area = create_image_from_data (IMG_SURFACE, (gpointer)legend_pix);
391 cairo_surface_destroy (legend_pix);
392#ifdef GTK4
393 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, cedit -> legend_box_style, markup_label(" ", 20, -1, 0.0, 0.0), FALSE, FALSE, 0);
394 gtk_widget_set_hexpand (cedit -> legend_style_area, TRUE);
395#endif
396 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, cedit -> legend_box_style, cedit -> legend_style_area, FALSE, FALSE, 0);
397
398 widget_set_sensitive (cedit -> legend_box_style, this_curve -> show_legend_box);
399 widget_set_sensitive (cedit -> legend_box, this_curve -> show_legend);
400 return legendbox;
401}
Callback declarations for main window.
char * lapos[2]
Definition cedit.c:78
char * ctext[2]
Definition tab-1.c:85
Curve * get_curve_from_pointer(gpointer data)
get Curve pointer from pointer
Definition curve.c:313
curve_dash * selectdash(int iddash)
setup dash pointer
Definition curve.c:135
int ndash
Definition curve.c:92
void update_curve(gpointer data)
update curve rendering
Definition curve.c:635
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:611
Global variable declarations Global convenience function declarations Global data structure defin...
@ IMG_SURFACE
Definition global.h:278
int combo_get_active(GtkWidget *combo)
retrieve the active item's position
Definition gtk-misc.c:935
GtkWidget * create_entry(GCallback handler, int dim, int cdim, gboolean key_release, gpointer data)
Create a GtkEntry.
Definition gtk-misc.c:1401
void update_entry_double(GtkEntry *entry, double doubleval)
update the content of a GtkEntry as double
Definition gtk-misc.c:688
GtkWidget * font_button(gchar *font, int dimx, int dimy, GCallback handler, gpointer data)
create a font selection button
Definition gtk-misc.c:1855
void combo_set_active(GtkWidget *combo, int pos)
set the active item's position
Definition gtk-misc.c:958
const gchar * entry_get_text(GtkEntry *entry)
get the text in a GtkEntry
Definition gtk-misc.c:652
#define BSEP
Definition global.h:261
GtkWidget * fbox(GtkWidget *box, char *lab)
box creating routine, to help design faster elements for the GUI
Definition gtk-misc.c:2120
GtkWidget * check_button(gchar *text, int dimx, int dimy, gboolean state, GCallback handler, gpointer data)
create a check button
Definition gtk-misc.c:1937
GtkWidget * create_combo()
create a GtkCombox widget, note deprecated in GTK4
Definition gtk-misc.c:1010
GtkWidget * markup_label(gchar *text, int dimx, int dimy, float ax, float ay)
create a GtkLabel with pango markup
Definition gtk-misc.c:1672
GtkWidget * cbox(GtkWidget *box, char *lab)
box creating routine, to help design faster elements for the GUI
Definition gtk-misc.c:2102
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:340
ColRGBA get_button_color(GtkColorChooser *colob)
get the ColRGBA color from a GtkColorChooser button
Definition gtk-misc.c:2406
void widget_set_sensitive(GtkWidget *widg, gboolean sensitive)
Set sensitivity for a GtkWidget, ensuring it is a GtkWidget.
Definition gtk-misc.c:247
GtkWidget * create_hbox(int spacing)
create a GtkBox with horizontal orientation
Definition gtk-misc.c:849
GtkWidget * create_image_from_data(int format, gpointer item_image)
create Gtk image for data
Definition gtk-misc.c:1530
void combo_text_append(GtkWidget *combo, gchar *text)
append text in GtkComboBox widget
Definition gtk-misc.c:987
GtkWidget * destroy_this_widget(GtkWidget *widg)
destroy a GtkWidget
Definition gtk-misc.c:2213
GtkWidget * color_button(ColRGBA col, gboolean alpha, int dimx, int dimy, GCallback handler, gpointer data)
create a color selection button
Definition gtk-misc.c:1833
GtkWidget * bbox(GtkWidget *box, char *lab)
box creating routine, to help design faster elements for the GUI
Definition gtk-misc.c:2084
GtkWidget * create_vbox(int spacing)
create a GtkBox with vertical orientation
Definition gtk-misc.c:837
int button_get_status(GtkWidget *button)
get status of check / toggle button
Definition gtk-misc.c:1899
void show_the_widgets(GtkWidget *widg)
show GtkWidget
Definition gtk-misc.c:202
void show_warning(char *warning, GtkWidget *win)
show warning
Definition interface.c:266
Messaging function declarations.
double z
Definition ogl_draw.c:63
Function declarations for reading atomes project file Function declarations for saving atomes proje...
float blue
Definition global.h:138
float red
Definition global.h:136
float green
Definition global.h:137
Definition global.h:126
Definition global.h:118
int b
Definition global.h:120
int c
Definition global.h:121
int a
Definition global.h:119
void set_legend_box_style(gpointer data)
update legend style widgets
Definition tab-3.c:145
G_MODULE_EXPORT void show_data_legend(GtkToggleButton *leg, gpointer data)
show / hide legend toggle callback GTK3
Definition tab-3.c:121
G_MODULE_EXPORT void set_legend_box_thickness(GtkEntry *entry, gpointer data)
set legend box thickness entry callback
Definition tab-3.c:278
G_MODULE_EXPORT void set_legend_color(GtkColorChooser *colob, gpointer data)
change legend color
Definition tab-3.c:217
G_MODULE_EXPORT void set_legend_box_color(GtkColorChooser *colob, gpointer data)
set legend color
Definition tab-3.c:296
cairo_surface_t * draw_legend_surface(int da, double ti, ColRGBA dcol, ColRGBA bcol)
draw legend preview
Definition tab-3.c:78
G_MODULE_EXPORT void set_legend_font(GtkFontButton *fontb, gpointer data)
change legend font
Definition tab-3.c:201
GtkWidget * create_tab_3(curve_edition *cedit, gpointer data)
handle the creation of the 3rd tab of the curve edition dialog
Definition tab-3.c:310
G_MODULE_EXPORT void show_data_legend_box(GtkToggleButton *bleg, gpointer data)
show / hide legend box toggle callback GTK3
Definition tab-3.c:185
G_MODULE_EXPORT void set_legend_pos(GtkEntry *entry, gpointer data)
set the legend position entry callback
Definition tab-3.c:231
G_MODULE_EXPORT void set_legend_box_line(GtkComboBox *fbox, gpointer data)
change the legend box line type
Definition tab-3.c:264
GdkPixbuf * pix
Definition workspace.c:69