atomes 1.2.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-2025 by CNRS and University of Strasbourg */
15
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
48#define BOX_STYLES 2
49
50gchar * box_style[BOX_STYLES] = {"Wireframe", "Cylinders"};
51
52gboolean from_box_or_axis = FALSE;
53
62G_MODULE_EXPORT void update_box_parameter (GtkEntry * res, gpointer data)
63{
64 glwin * view;
65 int box_type;
66 double box_line;
67 double box_rad;
68 const gchar * n = entry_get_text (res);
69#ifdef GTK3
70 gchar * str;
71#endif // GTK3
72 double v = string_to_double ((gpointer)n);
73 if (preferences)
74 {
75 box_type = tmp_box -> box;
76 box_line = tmp_box -> line;
77 box_rad = tmp_box -> rad;
78 }
79 else
80 {
81 view = (glwin *)data;
82 box_type = view -> anim -> last -> img -> abc -> box;
83 box_line = view -> anim -> last -> img -> abc -> line;
84 box_rad = view -> anim -> last -> img -> abc -> rad;
85 }
86 if (box_type == CYLINDERS)
87 {
88 if (v > 0.0) box_rad = v;
89 v = box_rad;
90 if (! preferences)
91 {
92#ifdef GTK3
93 // GTK3 Menu Action To Check
94 str = g_strdup_printf ("_Radius [ %f Å ]", v);
95 gtk_menu_item_set_label (GTK_MENU_ITEM(view -> ogl_box_axis[0][6]), str);
96 g_free (str);
97#endif
98 view -> anim -> last -> img -> abc -> rad = v;
99 }
100 else
101 {
102 tmp_box -> rad = v;
103 }
104 }
105 else
106 {
107 if (v > 0.0) box_line = v;
108 v = box_line;
109 if (! preferences)
110 {
111#ifdef GTK3
112 // GTK3 Menu Action To Check
113 str = g_strdup_printf ("_Width [ %f pts ]", v);
114 gtk_menu_item_set_label (GTK_MENU_ITEM(view -> ogl_box_axis[0][4]), str);
115 g_free (str);
116#endif
117 view -> anim -> last -> img -> abc -> line = v;
118 }
119 else
120 {
121 tmp_box -> line = v;
122 }
123 }
125 if (! preferences)
126 {
127 view -> create_shaders[MDBOX] = TRUE;
128 update (view);
129 }
130}
131
140G_MODULE_EXPORT void set_box_combo_style (GtkWidget * widg, gpointer data)
141{
142 int i = combo_get_active (widg);
143 glwin * view;
144 box_edition * box_win;
145 if (! preferences)
146 {
147 view = (glwin *)data;
148 box_win = view -> box_win;
149 }
150 else
151 {
152 box_win = pref_box_win;
153 }
154#ifdef GTK4
155 if (! preferences)
156 {
157 view -> anim -> last -> img -> abc -> box = (i < 0) ? (NONE) : (i == 0) ? WIREFRAME : CYLINDERS;
158 view -> create_shaders[MDBOX] = TRUE;
159 update (view);
160 }
161#else
162 from_box_or_axis = TRUE;
163#endif
164 if (i == 1)
165 {
166 if (is_the_widget_visible(box_win -> width_box)) hide_the_widgets (box_win -> width_box);
167 if (! is_the_widget_visible(box_win -> radius_box)) show_the_widgets (box_win -> radius_box);
168 if (! preferences)
169 {
170#ifdef GTK3
171 // GTK3 Menu Action To Check
172 gtk_check_menu_item_set_active ((GtkCheckMenuItem *)view -> ogl_box_axis[0][2], TRUE);
173#endif
174 }
175 else
176 {
177 tmp_box -> box = CYLINDERS;
178 }
179 }
180 else if (i == 0)
181 {
182 if (is_the_widget_visible(box_win -> radius_box)) hide_the_widgets (box_win -> radius_box);
183 if (! is_the_widget_visible(box_win -> width_box)) show_the_widgets (box_win -> width_box);
184 if (! preferences)
185 {
186#ifdef GTK3
187 // GTK3 Menu Action To Check
188 gtk_check_menu_item_set_active ((GtkCheckMenuItem *)view -> ogl_box_axis[0][1], TRUE);
189#endif
190 }
191 else
192 {
193 tmp_box -> box = WIREFRAME;
194 }
195 }
196 if (! preferences)
197 {
198 view -> create_shaders[MDBOX] = TRUE;
199 update (view);
200#ifdef GTK4
201 update_menu_bar (view);
202#endif
203 }
204#ifdef GTK3
205 from_box_or_axis = FALSE;
206#endif
207}
208
209#ifdef GTK4
218G_MODULE_EXPORT void set_show_box_toggle (GtkCheckButton * but, gpointer data)
219#else
228G_MODULE_EXPORT void set_show_box_toggle (GtkToggleButton * but, gpointer data)
229#endif
230{
231 gboolean val = button_get_status ((GtkWidget *)but);
232 glwin * view;
233 box_edition * box_win;
234 if (! preferences)
235 {
236 view = (glwin *)data;
237 box_win = view -> box_win;
238 }
239 else
240 {
241 box_win = pref_box_win;
242 }
243#ifdef GTK3
244 from_box_or_axis = TRUE;
245#endif // GTK3
246 if (val)
247 {
248 if (! preferences)
249 {
250#ifdef GTK3
251 // GTK3 Menu Action To Check
252 gtk_check_menu_item_set_active ((GtkCheckMenuItem *)view -> ogl_box_axis[0][0], TRUE);
253#endif
254 }
255 combo_set_active (box_win -> styles, WIREFRAME-1);
256 }
257 else
258 {
259 if (! preferences)
260 {
261#ifdef GTK3
262 // GTK3 Menu Action To Check
263 gtk_check_menu_item_set_active ((GtkCheckMenuItem *)view -> ogl_box_axis[0][0], FALSE);
264#endif
265 }
266 combo_set_active (box_win -> styles, NONE);
267 }
268#ifdef GTK3
269 from_box_or_axis = FALSE;
270#endif // GTK3
271 widget_set_sensitive (box_win -> box_data, val);
272#ifdef GTK4
273 if (! preferences) update_menu_bar (view);
274#endif
275}
276
285G_MODULE_EXPORT void set_color_box (GtkColorChooser * colob, gpointer data)
286{
287 if (preferences)
288 {
289 tmp_box -> color = get_button_color (colob);
290 }
291 else
292 {
293 glwin * view = (glwin *)data;
294 view -> anim -> last -> img -> abc -> color = get_button_color (colob);
295 view -> create_shaders[MDBOX] = TRUE;
296 update (view);
297 }
298}
299
300#ifdef GTK4
309G_MODULE_EXPORT gboolean on_box_delete (GtkWindow * widg, gpointer data)
310#else
320G_MODULE_EXPORT gboolean on_box_delete (GtkWidget * widg, GdkEvent * event, gpointer data)
321#endif
322{
323 glwin * view = (glwin *)data;
324 view -> box_win -> win = destroy_this_widget (view -> box_win -> win);
325 g_free (view -> box_win);
326 view -> box_win = NULL;
327 return TRUE;
328}
329
338G_MODULE_EXPORT void box_advanced (GtkWidget * widg, gpointer data)
339{
340 int i;
341 glwin * view;
342 box_edition * the_box;
343 int box_type;
344 double box_line;
345 double box_rad;
346 ColRGBA box_color;
347
348 if (preferences)
349 {
350 the_box = pref_box_win;
351 box_type = tmp_box -> box;
352 box_color = tmp_box -> color;
353 box_line = tmp_box -> line;
354 box_rad = tmp_box -> rad;
355 }
356 else
357 {
358 view = (glwin *)data;
359 view -> box_win = g_malloc0(sizeof*view -> box_win);
360 the_box = view -> box_win;
361 box_type = view -> anim -> last -> img -> abc -> box;
362 box_color = view -> anim -> last -> img -> abc -> color;
363 box_line = view -> anim -> last -> img -> abc -> line;
364 box_rad = view -> anim -> last -> img -> abc -> rad;
365 }
366
367 GtkWidget * vbox = create_vbox (BSEP);
368 if (preferences)
369 {
370 the_box -> win = create_vbox (BSEP);
371 adv_box (the_box -> win, "<b>Box settings</b>", 5, 120, 0.0);
372 GtkWidget * hbox = create_hbox (BSEP);
373 add_box_child_start (GTK_ORIENTATION_VERTICAL, the_box -> win, hbox, FALSE, FALSE, 20);
374 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hbox, vbox, FALSE, FALSE, 60);
375 }
376 else
377 {
378 gchar * str = g_strdup_printf ("%s - box settings", get_project_by_id(view -> proj)->name);
379 the_box -> win = create_win (str, view -> win, FALSE, FALSE);
380 g_free (str);
381 add_container_child (CONTAINER_WIN, the_box -> win, vbox);
382 }
383 GtkWidget * box;
384 gboolean ac;
385 if (box_type != NONE)
386 {
387 ac = TRUE;
388 }
389 else
390 {
391 ac = FALSE;
392 }
393 the_box -> show_hide = check_button ("Show / hide box", 100, 40, ac, G_CALLBACK(set_show_box_toggle), data);
394 add_box_child_start (GTK_ORIENTATION_VERTICAL, vbox, the_box -> show_hide, FALSE, FALSE, 0);
395 the_box -> box_data = create_vbox (BSEP);
396 add_box_child_start (GTK_ORIENTATION_VERTICAL, vbox, the_box -> box_data, TRUE, TRUE, 10);
397 widget_set_sensitive (the_box -> box_data, ac);
398
399 GtkWidget * pos_box = create_vbox (BSEP);
400 add_box_child_start (GTK_ORIENTATION_VERTICAL, the_box -> box_data, pos_box, TRUE, TRUE, 0);
401
402 box = abox (the_box -> box_data, "Style ", 5);
403 the_box -> styles = create_combo ();
404 for (i=0; i<BOX_STYLES; i++)
405 {
406 combo_text_append (the_box -> styles, box_style[i]);
407 }
408 if (box_type == NONE) i = NONE;
409 if (box_type == WIREFRAME) i = 0;
410 if (box_type == CYLINDERS) i = 1;
411 combo_set_active (the_box -> styles, i);
412 gtk_widget_set_size_request (the_box -> styles, 120, -1);
413 g_signal_connect (G_OBJECT (the_box -> styles), "changed", G_CALLBACK(set_box_combo_style), data);
414 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, box, the_box -> styles, FALSE, FALSE, 10);
415 the_box -> width_box = abox (the_box -> box_data, "Line width [pts] ", 0);
416 the_box -> width = create_entry (G_CALLBACK(update_box_parameter), 120, 10, FALSE, data);
417 update_entry_double (GTK_ENTRY(the_box -> width), box_line);
418 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, the_box -> width_box, the_box -> width, FALSE, FALSE, 10);
419 the_box -> radius_box = abox (the_box -> box_data, "Cylinder radius [&#xC5;] ", 0);
420 the_box -> radius = create_entry (G_CALLBACK(update_box_parameter), 120, 10, FALSE, data);
421 update_entry_double (GTK_ENTRY(the_box -> radius), box_rad);
422 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, the_box -> radius_box, the_box -> radius, FALSE, FALSE, 10);
423
424 // Colors
425 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);
426
427 if (! preferences)
428 {
429 add_global_option (vbox, & view -> colorp[1][0]);
430 add_gtk_close_event (the_box -> win, G_CALLBACK(on_box_delete), view);
431 show_the_widgets (the_box -> win);
432 if (box_type)
433 {
434 hide_the_widgets (the_box -> width_box);
435 }
436 else
437 {
438 hide_the_widgets (the_box -> radius_box);
439 }
440 }
441}
color colorp[64]
float val
Definition dlp_init.c:117
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...
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
gboolean is_the_widget_visible(GtkWidget *widg)
test if a GtkWidget exist, then return if it is visible or not
Definition gtk-misc.c:724
GtkWidget * create_win(gchar *str, GtkWidget *parent, gboolean modal, gboolean resiz)
create a new GtkWindow
Definition gtk-misc.c:454
project * proj
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
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:2522
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:1893
@ CONTAINER_WIN
Definition global.h:252
GtkWidget * create_combo()
create a GtkCombox widget, note deprecated in GTK4
Definition gtk-misc.c:984
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
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
void add_container_child(int type, GtkWidget *widg, GtkWidget *child)
Add a GtkWidget into another GtkWidget.
Definition gtk-misc.c:235
void hide_the_widgets(GtkWidget *widg)
hide GtkWidget
Definition gtk-misc.c:198
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
GtkWidget * abox(GtkWidget *box, char *lab, int vspace)
box creating routine, to help design faster elements for the GUI
Definition gtk-misc.c:2023
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 update(glwin *view)
update the rendering of the OpenGL window
Definition glview.c:450
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
struct box box
box layout data structure
Definition glwin.h:349
@ MDBOX
Definition glwin.h:93
Function declarations for the creation of the OpenGL window.
Messaging function declarations.
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:151
gboolean preferences
Preference variable declarations.
Definition glwin.h:351
Definition glwin.h:965
gboolean from_box_or_axis
Definition w_box.c:52
#define BOX_STYLES
Definition w_box.c:48
G_MODULE_EXPORT void set_show_box_toggle(GtkToggleButton *but, gpointer data)
toggle show / hide box callback GTK3
Definition w_box.c:228
G_MODULE_EXPORT void set_box_combo_style(GtkWidget *widg, gpointer data)
set box style callback
Definition w_box.c:140
G_MODULE_EXPORT void set_color_box(GtkColorChooser *colob, gpointer data)
set box color callback
Definition w_box.c:285
G_MODULE_EXPORT void update_box_parameter(GtkEntry *res, gpointer data)
update box parameter callback
Definition w_box.c:62
gchar * box_style[BOX_STYLES]
Definition w_box.c:50
G_MODULE_EXPORT gboolean on_box_delete(GtkWidget *widg, GdkEvent *event, gpointer data)
box window delete event - GTK3
Definition w_box.c:320
G_MODULE_EXPORT void box_advanced(GtkWidget *widg, gpointer data)
create the box edition window
Definition w_box.c:338
GtkWidget * res[2]
Definition w_encode.c:212
GtkWidget * hbox
Definition workspace.c:71
GtkWidget * img
Definition workspace.c:70
GtkWidget * vbox
Definition workspace.c:72