atomes 1.1.14
atomes: an atomic scale modeling tool box
Loading...
Searching...
No Matches
w_colors.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: 'w_colors.c'
24*
25* Contains:
26*
27
28 - The functions to create the color selection dialogs
29
30*
31* List of functions:
32
33 void window_color (project * this_proj, glwin * view, int wc_cid);
34
35 G_MODULE_EXPORT void run_window_color (GtkDialog * win, gint response_id, gpointer data);
36 G_MODULE_EXPORT void to_run_back_color_window (GSimpleAction * action, GVariant * parameter, gpointer data);
37 G_MODULE_EXPORT void to_run_back_color_window (GtkWidget * widg, gpointer data);
38 G_MODULE_EXPORT void to_run_box_color_window (GSimpleAction * action, GVariant * parameter, gpointer data);
39 G_MODULE_EXPORT void to_run_box_color_window (GtkWidget * widg, gpointer data);
40 G_MODULE_EXPORT void to_run_atom_color_window (GSimpleAction * action, GVariant * parameter, gpointer data);
41 G_MODULE_EXPORT void to_run_atom_color_window (GtkWidget * widg, gpointer data);
42 G_MODULE_EXPORT void run_window_color_coord (GtkDialog * win, gint response_id, gpointer data);
43 G_MODULE_EXPORT void window_color_coord (GSimpleAction * action, GVariant * parameter, gpointer data);
44 G_MODULE_EXPORT void window_color_coord (GtkWidget * widg, gpointer data);
45
46*/
47
48#include "global.h"
49#include "interface.h"
50#include "project.h"
51#include "glwindow.h"
52#include "glview.h"
53#include "color_box.h"
54
56
66G_MODULE_EXPORT void run_window_color (GtkDialog * win, gint response_id, gpointer data)
67{
68 project * this_proj = (project *)data;
69
70 if (response_id == GTK_RESPONSE_OK)
71 {
72 ColRGBA colo = get_window_color (GTK_WIDGET(win));
73 if (wc_cid == -2)
74 {
75 this_proj -> modelgl -> anim -> last -> img -> backcolor = colo;
76 this_proj -> modelgl -> create_shaders[MEASU] = TRUE;
77 }
78 else if (wc_cid == -1)
79 {
80 this_proj -> modelgl -> anim -> last -> img -> box_color = colo;
81 this_proj -> modelgl -> create_shaders[MDBOX] = TRUE;
82 }
83 else
84 {
85 this_proj -> modelgl -> anim -> last -> img -> at_color[wc_cid] = colo;
86 int shaders[2] = {ATOMS, BONDS};
87 re_create_md_shaders (2, shaders, this_proj);
88 int shader[1] = {POLYS};
89 if (this_proj -> modelgl -> anim -> last -> img -> color_map[1] == 0) re_create_md_shaders (1, shader, this_proj);
90 }
91 update (this_proj -> modelgl);
92 }
94}
95
105void window_color (project * this_proj, glwin * view, int wc_cid)
106{
107 gchar * str;
108 GdkRGBA col;
109 if (wc_cid == -2)
110 {
111 str = g_strdup_printf ("Background color");
112 col = colrgba_togtkrgba (view -> anim -> last -> img -> backcolor);
113 }
114 else if (wc_cid == -1)
115 {
116 str = g_strdup_printf ("Model box color");
117 col = colrgba_togtkrgba (view -> anim -> last -> img -> box_color);
118 }
119 else
120 {
121 if (wc_cid < this_proj -> nspec)
122 {
123 str = g_strdup_printf ("%s - atom(s) color", this_proj -> chemistry -> label[wc_cid]);
124 }
125 else
126 {
127 str = g_strdup_printf ("%s* - clone(s) color", this_proj -> chemistry -> label[wc_cid-this_proj -> nspec]);
128 }
129 col = colrgba_togtkrgba (view -> anim -> last -> img -> at_color[wc_cid]);
130 }
131 GtkWidget * win = gtk_color_chooser_dialog_new (str, GTK_WINDOW(view -> win));
132 gtk_window_set_modal (GTK_WINDOW(win), TRUE);
133 gtk_color_chooser_set_use_alpha (GTK_COLOR_CHOOSER(win), TRUE);
134 gtk_color_chooser_set_rgba (GTK_COLOR_CHOOSER(win), & col);
135 g_free (str);
136 run_this_gtk_dialog (win, G_CALLBACK(run_window_color), this_proj);
137}
138
139#ifdef GTK4
149G_MODULE_EXPORT void to_run_back_color_window (GSimpleAction * action, GVariant * parameter, gpointer data)
150#else
159G_MODULE_EXPORT void to_run_back_color_window (GtkWidget * widg, gpointer data)
160#endif
161{
162 glwin * view = (glwin *) data;
163 window_color (get_project_by_id(view -> proj), view, -2);
164 update (view);
165}
166
167#ifdef GTK4
177G_MODULE_EXPORT void to_run_box_color_window (GSimpleAction * action, GVariant * parameter, gpointer data)
178#else
187G_MODULE_EXPORT void to_run_box_color_window (GtkWidget * widg, gpointer data)
188#endif
189{
190 glwin * view = (glwin *) data;
191 window_color (get_project_by_id(view -> proj), view, -1);
192 view -> create_shaders[MDBOX] = TRUE;
193 update (view);
194}
195
196#ifdef GTK4
206G_MODULE_EXPORT void to_run_atom_color_window (GSimpleAction * action, GVariant * parameter, gpointer data)
207#else
216G_MODULE_EXPORT void to_run_atom_color_window (GtkWidget * widg, gpointer data)
217#endif
218{
219 tint * id = (tint *) data;
220 // g_debug ("Atom color:: proj= %d, id -> b= %d, id -> c= %d", id -> a, id -> b, id -> c);
221 project * this_proj = get_project_by_id(id -> a);
222 window_color (this_proj, this_proj -> modelgl, id -> c);
223 int shaders[3] = {ATOMS, BONDS, SELEC};
224 re_create_md_shaders (3, shaders, this_proj);
225 this_proj -> modelgl -> create_shaders[LABEL] = TRUE;
226 update (this_proj -> modelgl);
227}
228
238G_MODULE_EXPORT void run_window_color_coord (GtkDialog * win, gint response_id, gpointer data)
239{
240 qint * cid = (qint *)data;
241 int c, g, s;
242 project * this_proj = get_project_by_id(cid -> a);
243 s = cid -> b;
244 c = cid -> c;
245 g = cid -> d;
246 if (response_id == GTK_RESPONSE_OK)
247 {
248 if (g > 1) s = 0;
249 this_proj -> modelgl -> anim -> last -> img -> spcolor[g][s][c] = get_window_color (GTK_WIDGET(win));
250 int shaders[4] = {ATOMS, BONDS, POLYS, RINGS};
251 re_create_md_shaders (4, shaders, this_proj);
252 update (this_proj -> modelgl);
253 }
255}
256
257#ifdef GTK4
267G_MODULE_EXPORT void window_color_coord (GSimpleAction * action, GVariant * parameter, gpointer data)
268#else
277G_MODULE_EXPORT void window_color_coord (GtkWidget * widg, gpointer data)
278#endif
279{
280 qint * cid = (qint *)data;
281 gchar * str;
282 int c, g, s;
283 project * this_proj = get_project_by_id(cid -> a);
284 s = cid -> b;
285 c = cid -> c;
286 g = cid -> d;
287 g_debug ("s= %d, c= %d, g= %d", s, c, g);
288 switch (g)
289 {
290 case 0:
291 str = g_strdup_printf ("%s atom(s) %d fold coordination sphere color", this_proj -> chemistry -> label[s],
292 this_proj -> coord -> geolist[0][s][c]);
293 break;
294 case 1:
295 str = g_strdup_printf ("%s - %s coordination sphere color", this_proj -> chemistry -> label[s],
296 prepare_for_title(exact_name(env_name (this_proj, c, s, 1, NULL))));
297 break;
298 case 2:
299 str = g_strdup_printf ("Fragment N°%d color", c);
300 g = s;
301 s = 0;
302 break;
303 case 3:
304 str = g_strdup_printf ("Molecule N°%d color", c);
305 g = s;
306 s = 0;
307 break;
308 case 9:
309 str = g_strdup_printf ("%d atom chain(s) color", this_proj -> coord -> geolist[g][0][c]);
310 s = 0;
311 break;
312 default:
313 str = g_strdup_printf ("%s - %d atom ring(s) color", rings_type[s], this_proj -> coord -> geolist[g][0][c]);
314 s = 0;
315 break;
316 }
317 GtkWidget * win = gtk_color_chooser_dialog_new (str, GTK_WINDOW(this_proj -> modelgl -> win));
318 g_free (str);
319 set_color_chooser_color (win, this_proj -> modelgl -> anim -> last -> img -> spcolor[g][s][c]);
320 gtk_color_chooser_set_use_alpha (GTK_COLOR_CHOOSER(win), TRUE);
321 gtk_window_set_modal ((GtkWindow *)win, TRUE);
322 run_this_gtk_dialog (win, G_CALLBACK(run_window_color_coord), data);
323}
integer(kind=c_int) function chemistry()
Definition chemistry.F90:22
Structure definitions for color management Function declarations for color management.
void label(cairo_t *cr, double val, int axe, int p, project *this_proj)
draw axis label
Definition labels.c:56
ColRGBA col
Definition d_measures.c:77
char * rings_type[5]
Definition global.c:143
Global variable declarations Global convenience function declarations Global data structure defin...
void run_this_gtk_dialog(GtkWidget *dial, GCallback handler, gpointer data)
run a GTK (3 and 4) basic GtkDialog
Definition gtk-misc.c:472
void set_color_chooser_color(GtkWidget *color_win, ColRGBA col)
set the color of a color selection window
Definition gtk-misc.c:2241
ColRGBA get_window_color(GtkWidget *color_win)
get the ColRGBA color from a color selection window
Definition gtk-misc.c:2226
project * proj
GdkRGBA colrgba_togtkrgba(ColRGBA col)
convert ColRGBA color to GdkRGBA color
Definition gtk-misc.c:1614
void destroy_this_dialog(GtkDialog *dialog)
destroy a GtkDialog
Definition gtk-misc.c:2041
gchar * prepare_for_title(gchar *init)
prepare a string for a window title, getting rid of all markup
Definition tools.c:71
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:439
Variable declarations related to the OpenGL window Function declarations related to the OpenGL wind...
void re_create_md_shaders(int nshaders, int shaders[nshaders], project *this_proj)
re-initialize some MD dependent OpenGL shaders
action
Definition glview.h:189
shaders
The different types of shaders in the atomes program.
Definition glwin.h:88
@ BONDS
Definition glwin.h:90
@ LABEL
Definition glwin.h:98
@ POLYS
Definition glwin.h:92
@ SELEC
Definition glwin.h:91
@ MDBOX
Definition glwin.h:93
@ MEASU
Definition glwin.h:99
@ ATOMS
Definition glwin.h:89
@ RINGS
Definition glwin.h:96
Function declarations for the creation of the OpenGL window.
gchar * env_name(project *this_proj, int g, int s, int f, GtkTextBuffer *buffer)
ouput the name of a coordination sphere
Definition interface.c:889
gchar * exact_name(gchar *name)
short cut to print string without spaces
Definition interface.c:370
Messaging function declarations.
Function declarations for reading atomes project file Function declarations for saving atomes proje...
Definition glwin.h:875
Definition global.h:106
Definition global.h:98
int b
Definition tab-1.c:95
int c
Definition tab-1.c:95
int d
Definition tab-1.c:95
int a
Definition tab-1.c:95
G_MODULE_EXPORT void to_run_back_color_window(GtkWidget *widg, gpointer data)
to run background color selection window callback GTK3
Definition w_colors.c:159
G_MODULE_EXPORT void to_run_box_color_window(GtkWidget *widg, gpointer data)
to run box color selection window callback GTK3
Definition w_colors.c:187
int wc_cid
Definition w_colors.c:55
G_MODULE_EXPORT void window_color_coord(GtkWidget *widg, gpointer data)
create a window to select a color callback GTK3
Definition w_colors.c:277
G_MODULE_EXPORT void run_window_color(GtkDialog *win, gint response_id, gpointer data)
window color chooser - running the dialog
Definition w_colors.c:66
G_MODULE_EXPORT void run_window_color_coord(GtkDialog *win, gint response_id, gpointer data)
window to select a color - running the dialog
Definition w_colors.c:238
G_MODULE_EXPORT void to_run_atom_color_window(GtkWidget *widg, gpointer data)
to run atom color selection window callback GTK3
Definition w_colors.c:216
void window_color(project *this_proj, glwin *view, int wc_cid)
window color chooser - creating the dialog
Definition w_colors.c:105
GtkWidget * img
Definition workspace.c:70