atomes 1.1.16
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);
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
55/*
56 The object type for color change
57 -2 : background
58 -1 : box
59 > -1 : coordination
60*/
62
72G_MODULE_EXPORT void run_window_color (GtkDialog * win, gint response_id, gpointer data)
73{
74 project * this_proj = (project *)data;
75
76 if (response_id == GTK_RESPONSE_OK)
77 {
78 ColRGBA colo = get_window_color (GTK_WIDGET(win));
79 if (wc_cid == -2)
80 {
81 this_proj -> modelgl -> anim -> last -> img -> backcolor = colo;
82 this_proj -> modelgl -> create_shaders[MEASU] = TRUE;
83 }
84 else if (wc_cid == -1)
85 {
86 this_proj -> modelgl -> anim -> last -> img -> box_color = colo;
87 this_proj -> modelgl -> create_shaders[MDBOX] = TRUE;
88 }
89 else
90 {
91 this_proj -> modelgl -> anim -> last -> img -> at_color[wc_cid] = colo;
92 int shaders[2] = {ATOMS, BONDS};
93 re_create_md_shaders (2, shaders, this_proj);
94 int shader[1] = {POLYS};
95 if (this_proj -> modelgl -> anim -> last -> img -> color_map[1] == 0) re_create_md_shaders (1, shader, this_proj);
96 }
97 update (this_proj -> modelgl);
98 }
100}
101
110void window_color (project * this_proj, glwin * view)
111{
112 gchar * str;
113 GdkRGBA col;
114 if (wc_cid == -2)
115 {
116 str = g_strdup_printf ("Background color");
117 col = colrgba_togtkrgba (view -> anim -> last -> img -> backcolor);
118 }
119 else if (wc_cid == -1)
120 {
121 str = g_strdup_printf ("Model box color");
122 col = colrgba_togtkrgba (view -> anim -> last -> img -> box_color);
123 }
124 else
125 {
126 if (wc_cid < this_proj -> nspec)
127 {
128 str = g_strdup_printf ("%s - atom(s) color", this_proj -> chemistry -> label[wc_cid]);
129 }
130 else
131 {
132 str = g_strdup_printf ("%s* - clone(s) color", this_proj -> chemistry -> label[wc_cid-this_proj -> nspec]);
133 }
134 col = colrgba_togtkrgba (view -> anim -> last -> img -> at_color[wc_cid]);
135 }
136 GtkWidget * win = gtk_color_chooser_dialog_new (str, GTK_WINDOW(view -> win));
137 gtk_window_set_modal (GTK_WINDOW(win), TRUE);
138 gtk_color_chooser_set_use_alpha (GTK_COLOR_CHOOSER(win), TRUE);
139 gtk_color_chooser_set_rgba (GTK_COLOR_CHOOSER(win), & col);
140 g_free (str);
141 run_this_gtk_dialog (win, G_CALLBACK(run_window_color), this_proj);
142}
143
144#ifdef GTK4
154G_MODULE_EXPORT void to_run_back_color_window (GSimpleAction * action, GVariant * parameter, gpointer data)
155#else
164G_MODULE_EXPORT void to_run_back_color_window (GtkWidget * widg, gpointer data)
165#endif
166{
167 glwin * view = (glwin *) data;
168 wc_cid = -2;
169 window_color (get_project_by_id(view -> proj), view);
170 update (view);
171}
172
173#ifdef GTK4
183G_MODULE_EXPORT void to_run_box_color_window (GSimpleAction * action, GVariant * parameter, gpointer data)
184#else
193G_MODULE_EXPORT void to_run_box_color_window (GtkWidget * widg, gpointer data)
194#endif
195{
196 glwin * view = (glwin *) data;
197 wc_cid = -1;
198 window_color (get_project_by_id(view -> proj), view);
199 view -> create_shaders[MDBOX] = TRUE;
200 update (view);
201}
202
203#ifdef GTK4
213G_MODULE_EXPORT void to_run_atom_color_window (GSimpleAction * action, GVariant * parameter, gpointer data)
214#else
223G_MODULE_EXPORT void to_run_atom_color_window (GtkWidget * widg, gpointer data)
224#endif
225{
226 tint * id = (tint *) data;
227 // g_debug ("Atom color:: proj= %d, id -> b= %d, id -> c= %d", id -> a, id -> b, id -> c);
228 project * this_proj = get_project_by_id(id -> a);
229 wc_cid = id -> c;
230 window_color (this_proj, this_proj -> modelgl);
231 int shaders[3] = {ATOMS, BONDS, SELEC};
232 re_create_md_shaders (3, shaders, this_proj);
233 this_proj -> modelgl -> create_shaders[LABEL] = TRUE;
234 update (this_proj -> modelgl);
235}
236
246G_MODULE_EXPORT void run_window_color_coord (GtkDialog * win, gint response_id, gpointer data)
247{
248 qint * cid = (qint *)data;
249 int c, g, s;
250 project * this_proj = get_project_by_id(cid -> a);
251 s = cid -> b;
252 c = cid -> c;
253 g = cid -> d;
254 if (response_id == GTK_RESPONSE_OK)
255 {
256 if (g > 1) s = 0;
257 this_proj -> modelgl -> anim -> last -> img -> spcolor[g][s][c] = get_window_color (GTK_WIDGET(win));
258 int shaders[4] = {ATOMS, BONDS, POLYS, RINGS};
259 re_create_md_shaders (4, shaders, this_proj);
260 update (this_proj -> modelgl);
261 }
263}
264
265#ifdef GTK4
275G_MODULE_EXPORT void window_color_coord (GSimpleAction * action, GVariant * parameter, gpointer data)
276#else
285G_MODULE_EXPORT void window_color_coord (GtkWidget * widg, gpointer data)
286#endif
287{
288 qint * cid = (qint *)data;
289 gchar * str;
290 int c, g, s;
291 project * this_proj = get_project_by_id(cid -> a);
292 s = cid -> b;
293 c = cid -> c;
294 g = cid -> d;
295 g_debug ("s= %d, c= %d, g= %d", s, c, g);
296 switch (g)
297 {
298 case 0:
299 str = g_strdup_printf ("%s atom(s) %d fold coordination sphere color", this_proj -> chemistry -> label[s],
300 this_proj -> coord -> geolist[0][s][c]);
301 break;
302 case 1:
303 str = g_strdup_printf ("%s - %s coordination sphere color", this_proj -> chemistry -> label[s],
304 prepare_for_title(exact_name(env_name (this_proj, c, s, 1, NULL))));
305 break;
306 case 2:
307 str = g_strdup_printf ("Fragment N°%d color", c);
308 g = s;
309 s = 0;
310 break;
311 case 3:
312 str = g_strdup_printf ("Molecule N°%d color", c);
313 g = s;
314 s = 0;
315 break;
316 case 9:
317 str = g_strdup_printf ("%d atom chain(s) color", this_proj -> coord -> geolist[g][0][c]);
318 s = 0;
319 break;
320 default:
321 str = g_strdup_printf ("%s - %d atom ring(s) color", rings_type[s], this_proj -> coord -> geolist[g][0][c]);
322 s = 0;
323 break;
324 }
325 GtkWidget * win = gtk_color_chooser_dialog_new (str, GTK_WINDOW(this_proj -> modelgl -> win));
326 g_free (str);
327 set_color_chooser_color (win, this_proj -> modelgl -> anim -> last -> img -> spcolor[g][s][c]);
328 gtk_color_chooser_set_use_alpha (GTK_COLOR_CHOOSER(win), TRUE);
329 gtk_window_set_modal ((GtkWindow *)win, TRUE);
330 run_this_gtk_dialog (win, G_CALLBACK(run_window_color_coord), data);
331}
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:492
void set_color_chooser_color(GtkWidget *color_win, ColRGBA col)
set the color of a color selection window
Definition gtk-misc.c:2265
ColRGBA get_window_color(GtkWidget *color_win)
get the ColRGBA color from a color selection window
Definition gtk-misc.c:2250
project * proj
GdkRGBA colrgba_togtkrgba(ColRGBA col)
convert ColRGBA color to GdkRGBA color
Definition gtk-misc.c:1634
void destroy_this_dialog(GtkDialog *dialog)
destroy a GtkDialog
Definition gtk-misc.c:2065
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:112
Definition global.h:104
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:164
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:193
int wc_cid
Definition w_colors.c:61
G_MODULE_EXPORT void window_color_coord(GtkWidget *widg, gpointer data)
create a window to select a color callback GTK3
Definition w_colors.c:285
G_MODULE_EXPORT void run_window_color(GtkDialog *win, gint response_id, gpointer data)
window color chooser - running the dialog
Definition w_colors.c:72
void window_color(project *this_proj, glwin *view)
window color chooser - creating the dialog
Definition w_colors.c:110
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:246
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:223
GtkWidget * img
Definition workspace.c:70