atomes 1.3.1
atomes: an atomic scale modeling tool box
Loading...
Searching...
No Matches
w_box.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: 'w_box.c'
24*
25* Contains:
26*
27
28 - The functions to create the box properties window
29
30*
31* List of functions:
32
33 G_MODULE_EXPORT void update_box_parameter (GtkEntry * res, gpointer data);
34 G_MODULE_EXPORT void set_box_combo_style (GtkWidget * widg, gpointer data);
35 G_MODULE_EXPORT void set_show_box_toggle (GtkCheckButton * but, gpointer data);
36 G_MODULE_EXPORT void set_show_box_toggle (GtkToggleButton * but, gpointer data);
37 G_MODULE_EXPORT void set_color_box (GtkColorChooser * colob, gpointer data);
38 G_MODULE_EXPORT void box_advanced (GtkWidget * widg, gpointer data);
39
40*/
41
42#include "global.h"
43#include "interface.h"
44#include "glview.h"
45#include "glwindow.h"
46#include "preferences.h"
47
48gboolean from_box_or_axis = FALSE;
49
58G_MODULE_EXPORT void update_box_parameter (GtkEntry * res, gpointer data)
59{
60 glwin * view;
61 int box_type;
62 double box_line;
63 double box_rad;
64 const gchar * n = entry_get_text (res);
65#ifdef GTK3
66 gchar * str;
67#endif // GTK3
68 double v = string_to_double ((gpointer)n);
69 if (preferences)
70 {
71 box_type = tmp_box -> box;
72 box_line = tmp_box -> line;
73 box_rad = tmp_box -> rad;
74 }
75 else
76 {
77 view = (glwin *)data;
78 box_type = view -> anim -> last -> img -> abc -> box;
79 box_line = view -> anim -> last -> img -> abc -> line;
80 box_rad = view -> anim -> last -> img -> abc -> rad;
81 }
82 if (box_type == CYLINDERS)
83 {
84 if (v > 0.0) box_rad = v;
85 v = box_rad;
86 if (! preferences)
87 {
88#ifdef GTK3
89 // GTK3 Menu Action To Check
90 str = g_strdup_printf (_("Radius [ %f Å ]"), v);
91 gtk_menu_item_set_label (GTK_MENU_ITEM(view -> ogl_box_axis[0][6]), str);
92 g_free (str);
93#endif
94 view -> anim -> last -> img -> abc -> rad = v;
95 }
96 else
97 {
98 tmp_box -> rad = v;
99 }
100 }
101 else
102 {
103 if (v > 0.0) box_line = v;
104 v = box_line;
105 if (! preferences)
106 {
107#ifdef GTK3
108 // GTK3 Menu Action To Check
109 str = g_strdup_printf (_("Width [ %f pts ]"), v);
110 gtk_menu_item_set_label (GTK_MENU_ITEM(view -> ogl_box_axis[0][4]), str);
111 g_free (str);
112#endif
113 view -> anim -> last -> img -> abc -> line = v;
114 }
115 else
116 {
117 tmp_box -> line = v;
118 }
119 }
121 if (! preferences)
122 {
123 view -> create_shaders[MDBOX] = TRUE;
124 update (view);
125 }
126}
127
136G_MODULE_EXPORT void set_box_combo_style (GtkWidget * widg, gpointer data)
137{
138 int i = combo_get_active (widg);
139 glwin * view;
140 box_edition * box_win;
141 if (! preferences)
142 {
143 view = (glwin *)data;
144 box_win = view -> box_win;
145 }
146 else
147 {
148 box_win = pref_box_win;
149 }
150#ifdef GTK4
151 if (! preferences)
152 {
153 view -> anim -> last -> img -> abc -> box = (i < 0) ? (NONE) : (i == 0) ? WIREFRAME : CYLINDERS;
154 view -> create_shaders[MDBOX] = TRUE;
155 update (view);
156 }
157#else
158 from_box_or_axis = TRUE;
159#endif
160 if (i == 1)
161 {
162 hide_the_widgets (box_win -> width_box);
163 show_the_widgets (box_win -> radius_box);
164 if (! preferences)
165 {
166#ifdef GTK3
167 // GTK3 Menu Action To Check
168 gtk_check_menu_item_set_active ((GtkCheckMenuItem *)view -> ogl_box_axis[0][2], TRUE);
169#endif
170 }
171 else
172 {
173 tmp_box -> box = CYLINDERS;
174 }
175 }
176 else if (i == 0)
177 {
178 hide_the_widgets (box_win -> radius_box);
179 show_the_widgets (box_win -> width_box);
180 if (! preferences)
181 {
182#ifdef GTK3
183 // GTK3 Menu Action To Check
184 gtk_check_menu_item_set_active ((GtkCheckMenuItem *)view -> ogl_box_axis[0][1], TRUE);
185#endif
186 }
187 else
188 {
189 tmp_box -> box = WIREFRAME;
190 }
191 }
192 if (! preferences)
193 {
194 view -> create_shaders[MDBOX] = TRUE;
195 update (view);
196#ifdef GTK4
197 update_menu_bar (view);
198#endif
199 }
200#ifdef GTK3
201 from_box_or_axis = FALSE;
202#endif
203}
204
205#ifdef GTK4
214G_MODULE_EXPORT void set_show_box_toggle (GtkCheckButton * but, gpointer data)
215#else
224G_MODULE_EXPORT void set_show_box_toggle (GtkToggleButton * but, gpointer data)
225#endif
226{
227 gboolean val = button_get_status ((GtkWidget *)but);
228 glwin * view;
229 box_edition * box_win;
230 if (! preferences)
231 {
232 view = (glwin *)data;
233 box_win = view -> box_win;
234 }
235 else
236 {
237 box_win = pref_box_win;
238 }
239#ifdef GTK3
240 from_box_or_axis = TRUE;
241#endif // GTK3
242 if (val)
243 {
244 if (! preferences)
245 {
246#ifdef GTK3
247 // GTK3 Menu Action To Check
248 gtk_check_menu_item_set_active ((GtkCheckMenuItem *)view -> ogl_box_axis[0][0], TRUE);
249#endif
250 }
251 combo_set_active (box_win -> styles, WIREFRAME-1);
252 }
253 else
254 {
255 if (! preferences)
256 {
257#ifdef GTK3
258 // GTK3 Menu Action To Check
259 gtk_check_menu_item_set_active ((GtkCheckMenuItem *)view -> ogl_box_axis[0][0], FALSE);
260#endif
261 }
262 combo_set_active (box_win -> styles, NONE);
263 }
264#ifdef GTK3
265 from_box_or_axis = FALSE;
266#endif // GTK3
267 widget_set_sensitive (box_win -> box_data, val);
268#ifdef GTK4
269 if (! preferences) update_menu_bar (view);
270#endif
271}
272
281G_MODULE_EXPORT void set_color_box (GtkColorChooser * colob, gpointer data)
282{
283 if (preferences)
284 {
285 tmp_box -> color = get_button_color (colob);
286 }
287 else
288 {
289 glwin * view = (glwin *)data;
290 view -> anim -> last -> img -> abc -> color = get_button_color (colob);
291 view -> create_shaders[MDBOX] = TRUE;
292 update (view);
293 }
294}
295
296#ifdef GTK4
305G_MODULE_EXPORT gboolean on_box_delete (GtkWindow * widg, gpointer data)
306#else
316G_MODULE_EXPORT gboolean on_box_delete (GtkWidget * widg, GdkEvent * event, gpointer data)
317#endif
318{
319 glwin * view = (glwin *)data;
320 view -> box_win -> win = destroy_this_widget (view -> box_win -> win);
321 g_free (view -> box_win);
322 view -> box_win = NULL;
323 return TRUE;
324}
325
334G_MODULE_EXPORT void box_advanced (GtkWidget * widg, gpointer data)
335{
336 int i;
337 glwin * view;
338 box_edition * the_box;
339 int box_type;
340 double box_line;
341 double box_rad;
342 ColRGBA box_color;
343
344 if (preferences)
345 {
346 the_box = pref_box_win;
347 box_type = tmp_box -> box;
348 box_color = tmp_box -> color;
349 box_line = tmp_box -> line;
350 box_rad = tmp_box -> rad;
351 }
352 else
353 {
354 view = (glwin *)data;
355 view -> box_win = g_malloc0(sizeof*view -> box_win);
356 the_box = view -> box_win;
357 box_type = view -> anim -> last -> img -> abc -> box;
358 box_color = view -> anim -> last -> img -> abc -> color;
359 box_line = view -> anim -> last -> img -> abc -> line;
360 box_rad = view -> anim -> last -> img -> abc -> rad;
361 }
362
363 GtkWidget * vbox = create_vbox (BSEP);
364 if (preferences)
365 {
366 the_box -> win = create_vbox (BSEP);
367 adv_box (the_box -> win, _("<b>Box settings</b>"), 5, 120, 0.0);
368 GtkWidget * hbox = create_hbox (BSEP);
369 add_box_child_start (GTK_ORIENTATION_VERTICAL, the_box -> win, hbox, FALSE, FALSE, 20);
370 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hbox, vbox, FALSE, FALSE, 60);
371 }
372 else
373 {
374 gchar * str = g_strdup_printf (_("%s - box settings"), get_project_by_id(view -> proj)->name);
375 the_box -> win = create_win (str, view -> win, FALSE, FALSE);
376 g_free (str);
377 add_container_child (CONTAINER_WIN, the_box -> win, vbox);
378 }
379 GtkWidget * box;
380 gboolean ac;
381 if (box_type != NONE)
382 {
383 ac = TRUE;
384 }
385 else
386 {
387 ac = FALSE;
388 }
389 the_box -> show_hide = check_button (_("Show/Hide box"), 100, 40, ac, G_CALLBACK(set_show_box_toggle), data);
390 add_box_child_start (GTK_ORIENTATION_VERTICAL, vbox, the_box -> show_hide, FALSE, FALSE, 0);
391 the_box -> box_data = create_vbox (BSEP);
392 add_box_child_start (GTK_ORIENTATION_VERTICAL, vbox, the_box -> box_data, TRUE, TRUE, 10);
393 widget_set_sensitive (the_box -> box_data, ac);
394
395 GtkWidget * pos_box = create_vbox (BSEP);
396 add_box_child_start (GTK_ORIENTATION_VERTICAL, the_box -> box_data, pos_box, TRUE, TRUE, 0);
397
398 box = abox (the_box -> box_data, _("Style "), 5);
399 the_box -> styles = create_combo ();
400 combo_text_append (the_box -> styles, _("Wireframes"));
401 combo_text_append (the_box -> styles, _("Cylinders"));
402 if (box_type == NONE) i = NONE;
403 if (box_type == WIREFRAME) i = 0;
404 if (box_type == CYLINDERS) i = 1;
405 combo_set_active (the_box -> styles, i);
406 gtk_widget_set_size_request (the_box -> styles, 120, -1);
407 g_signal_connect (G_OBJECT (the_box -> styles), "changed", G_CALLBACK(set_box_combo_style), data);
408 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, box, the_box -> styles, FALSE, FALSE, 10);
409 the_box -> width_box = abox (the_box -> box_data, _("Line width [pts] "), 0);
410 the_box -> width = create_entry (G_CALLBACK(update_box_parameter), 120, 10, FALSE, data);
411 update_entry_double (GTK_ENTRY(the_box -> width), box_line);
412 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, the_box -> width_box, the_box -> width, FALSE, FALSE, 10);
413 the_box -> radius_box = abox (the_box -> box_data, _("Cylinder radius [&#xC5;] "), 0);
414 the_box -> radius = create_entry (G_CALLBACK(update_box_parameter), 120, 10, FALSE, data);
415 update_entry_double (GTK_ENTRY(the_box -> radius), box_rad);
416 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, the_box -> radius_box, the_box -> radius, FALSE, FALSE, 10);
417
418 // Colors
419 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, abox (the_box -> box_data, _("Color "), 5), color_button(box_color, TRUE, 120, -1, G_CALLBACK(set_color_box), data), FALSE, FALSE, 10);
420
421 if (! preferences)
422 {
423 add_global_option (vbox, & view -> colorp[1][0]);
424 add_gtk_close_event (the_box -> win, G_CALLBACK(on_box_delete), view);
425 show_the_widgets (the_box -> win);
426 if (box_type)
427 {
428 hide_the_widgets (the_box -> width_box);
429 }
430 else
431 {
432 hide_the_widgets (the_box -> radius_box);
433 }
434 }
435}
color colorp[64]
float val
Definition dlp_init.c:117
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...
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 * create_win(gchar *str, GtkWidget *parent, gboolean modal, gboolean resiz)
create a new GtkWindow
Definition gtk-misc.c:486
project * proj
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
void add_gtk_close_event(GtkWidget *widg, GCallback handler, gpointer data)
add a close event signal and callback to a GtkWidget
Definition gtk-misc.c:2557
void add_global_option(GtkWidget *vbox, tint *oid)
add a button to update global user preferences
GtkWidget * check_button(gchar *text, int dimx, int dimy, gboolean state, GCallback handler, gpointer data)
create a check button
Definition gtk-misc.c:1937
@ CONTAINER_WIN
Definition global.h:266
GtkWidget * create_combo()
create a GtkCombox widget, note deprecated in GTK4
Definition gtk-misc.c:1010
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
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
void add_container_child(int type, GtkWidget *widg, GtkWidget *child)
Add a GtkWidget into another GtkWidget.
Definition gtk-misc.c:267
void hide_the_widgets(GtkWidget *widg)
hide GtkWidget
Definition gtk-misc.c:224
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
GtkWidget * abox(GtkWidget *box, char *lab, int vspace)
box creating routine, to help design faster elements for the GUI
Definition gtk-misc.c:2067
void show_the_widgets(GtkWidget *widg)
show GtkWidget
Definition gtk-misc.c:202
project * get_project_by_id(int p)
get project pointer using id number
Definition project.c:120
void update(glwin *view)
update the rendering of the OpenGL window
Definition glview.c:461
Variable declarations related to the OpenGL window Function declarations related to the OpenGL wind...
styles
Definition glview.h:180
@ CYLINDERS
Definition glview.h:186
@ WIREFRAME
Definition glview.h:183
@ NONE
Definition glview.h:181
@ MDBOX
Definition glwin.h:93
Function declarations for the creation of the OpenGL window.
Messaging function declarations.
gboolean from_box_or_axis
Definition w_box.c:48
box_edition * pref_box_win
box * tmp_box
GtkWidget * adv_box(GtkWidget *box, char *lab, int vspace, int size, float xalign)
create a box with markup label
Definition w_advance.c:146
gboolean preferences
Preference variable declarations.
Definition glwin.h:350
Definition glwin.h:967
G_MODULE_EXPORT void set_show_box_toggle(GtkToggleButton *but, gpointer data)
toggle show / hide box callback GTK3
Definition w_box.c:224
G_MODULE_EXPORT void set_box_combo_style(GtkWidget *widg, gpointer data)
set box style callback
Definition w_box.c:136
G_MODULE_EXPORT void set_color_box(GtkColorChooser *colob, gpointer data)
set box color callback
Definition w_box.c:281
G_MODULE_EXPORT void update_box_parameter(GtkEntry *res, gpointer data)
update box parameter callback
Definition w_box.c:58
G_MODULE_EXPORT gboolean on_box_delete(GtkWidget *widg, GdkEvent *event, gpointer data)
box window delete event - GTK3
Definition w_box.c:316
G_MODULE_EXPORT void box_advanced(GtkWidget *widg, gpointer data)
create the box edition window
Definition w_box.c:334
GtkWidget * res[2]
Definition w_encode.c:342
GtkWidget * hbox
Definition workspace.c:71
GtkWidget * img
Definition workspace.c:70
GtkWidget * vbox
Definition workspace.c:72