atomes 1.2.1
atomes: an atomic scale modeling tool box
Loading...
Searching...
No Matches
color_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
23/*
24* This file: 'color_box.c'
25*
26* Contains:
27*
28
29 - The functions to create the color palettes for the menus of the OpenGL window
30 - The callbacks to set the color using the color palettes
31
32*
33* List of functions:
34
35 void get_color (ColRGBA * but, int cid);
36 void color_box (glwin * view, int ideo, int spec, int geo);
37
38 G_MODULE_EXPORT void set_back_color (GtkWidget * widg, gpointer data);
39 G_MODULE_EXPORT void set_box_color (GtkWidget * widg, gpointer data);
40 G_MODULE_EXPORT void set_at_color (GtkWidget * widg, gpointer data);
41 G_MODULE_EXPORT void set_rings_color (GtkWidget * widg, gpointer data);
42 G_MODULE_EXPORT void set_total_coord_color (GtkWidget * widg, gpointer data);
43 G_MODULE_EXPORT void set_partial_coord_color (GtkWidget * widg, gpointer data);
44 G_MODULE_EXPORT void set_frag_mol_color (GtkWidget * widg, gpointer data);
45
46 GtkWidget * color_box (glwin * view, int ideo, int spec, int geo);
47 GtkWidget * color_palette (glwin * view, int ideo, int spec, int geo);
48
49*/
50
51#include "global.h"
52#include "interface.h"
53#include "project.h"
54#include "glwindow.h"
55#include "color_box.h"
56#include "glview.h"
57
58extern void update_gradient_widgets (gradient_edition * gradient_win, background * back);
59
68void get_color (ColRGBA * but, int cid)
69{
70 int rid = cid / 4;
71 int bid = cid - rid*4;
72 but -> red = (rid < 6) ? 0.0 : (rid < 11) ? 0.2 * (rid - 5) : 1.0;
73 but -> green = (rid < 6) ? 0.2*rid : (rid < 11) ? 1.0 - 0.2 * (rid - 5) : 0.2 * (rid - 10);
74 but -> blue = bid * 0.333;
75 if (bid == 3) but -> blue = 1.0;
76}
77
89cairo_surface_t * col_surface (double r, double g, double b, int x, int y)
90{
91 cairo_surface_t * cst;
92 cairo_t * tcst;
93 cst = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, x, y);
94 tcst = cairo_create (cst);
95 cairo_set_source_rgb (tcst, r, g, b);
96 cairo_paint (tcst);
97 cairo_destroy (tcst);
98 return cst;
99}
100
109G_MODULE_EXPORT void set_back_color (GtkWidget * widg, gpointer data)
110{
111 tint * col = (tint *) data;
112 project * this_proj = get_project_by_id(col -> a);
113 get_color (& this_proj -> modelgl -> anim -> last -> img -> back -> color, col -> b);
114 this_proj -> modelgl -> anim -> last -> img -> back -> gradient = 0;
115 cleaning_shaders (this_proj -> modelgl, BACKG);
116 if (this_proj -> modelgl -> gradient_win) update_gradient_widgets (this_proj -> modelgl -> gradient_win, this_proj -> modelgl -> anim -> last -> img -> back);
117 this_proj -> modelgl -> create_shaders[MEASU] = TRUE;
118 update (this_proj -> modelgl);
119}
120
129G_MODULE_EXPORT void set_box_color (GtkWidget * widg, gpointer data)
130{
131 tint * col = (tint *) data;
132 project * this_proj = get_project_by_id(col -> a);
133 get_color (& this_proj -> modelgl -> anim -> last -> img -> abc -> color, col -> b);
134 this_proj -> modelgl -> create_shaders[MDBOX] = TRUE;
135 update (this_proj -> modelgl);
136}
137
146G_MODULE_EXPORT void set_at_color (GtkWidget * widg, gpointer data)
147{
148 tint * col = (tint *) data;
149 project * this_proj = get_project_by_id(col -> a);
150 get_color (& this_proj -> modelgl -> anim -> last -> img -> at_color[col -> c], col -> b);
151 int shaders[2] = {ATOMS, BONDS};
152 re_create_md_shaders (2, shaders, this_proj);
153 this_proj -> modelgl -> create_shaders[LABEL] = TRUE;
154 if (this_proj -> modelgl -> anim -> last -> img -> color_map[1] == 0) this_proj -> modelgl -> create_shaders[POLYS] = TRUE;
155 update (this_proj -> modelgl);
156}
157
166G_MODULE_EXPORT void set_rings_color (GtkWidget * widg, gpointer data)
167{
168 qint * col = (qint *)data;
169 project * this_proj = get_project_by_id(col -> a);
170 get_color (& this_proj -> modelgl -> anim -> last -> img -> spcolor[4+col -> b][0][col -> c], col -> d);
171 int shaders[1] = {RINGS};
172 re_create_md_shaders (1, shaders, this_proj);
173 update (this_proj -> modelgl);
174}
175
184G_MODULE_EXPORT void set_total_coord_color (GtkWidget * widg, gpointer data)
185{
186 qint * col = (qint *)data;
187 project * this_proj = get_project_by_id(col -> a);
188 get_color (& this_proj -> modelgl -> anim -> last -> img -> spcolor[0][col -> b][col -> c], col -> d);
189 int shaders[2] = {ATOMS, BONDS};
190 re_create_md_shaders (2, shaders, this_proj);
191 this_proj -> modelgl -> create_shaders[LABEL] = TRUE;
192 if (this_proj -> modelgl -> anim -> last -> img -> color_map[1] == 1) this_proj -> modelgl -> create_shaders[POLYS] = TRUE;
193 update (this_proj -> modelgl);
194}
195
204G_MODULE_EXPORT void set_partial_coord_color (GtkWidget * widg, gpointer data)
205{
206 qint * col = (qint *)data;
207 project * this_proj = get_project_by_id(col -> a);
208 get_color (& this_proj -> modelgl -> anim -> last -> img -> spcolor[1][col -> b][col -> c], col -> d);
209 int shaders[2] = {ATOMS, BONDS};
210 re_create_md_shaders (2, shaders, this_proj);
211 this_proj -> modelgl -> create_shaders[LABEL] = TRUE;
212 if (this_proj -> modelgl -> anim -> last -> img -> color_map[1] == 2) this_proj -> modelgl -> create_shaders[POLYS] = TRUE;
213 update (this_proj -> modelgl);
214}
215
224G_MODULE_EXPORT void set_frag_mol_color (GtkWidget * widg, gpointer data)
225{
226 qint * col = (qint *)data;
227 project * this_proj = get_project_by_id(col -> a);
228 get_color (& this_proj -> modelgl -> anim -> last -> img -> spcolor[col -> b][0][col -> c], col -> d);
229 int shaders[2] = {ATOMS, BONDS};
230 re_create_md_shaders (2, shaders, this_proj);
231 this_proj -> modelgl -> create_shaders[LABEL] = TRUE;
232 if (this_proj -> modelgl -> anim -> last -> img -> color_map[1] == col -> b + 1) this_proj -> modelgl -> create_shaders[POLYS] = TRUE;
233 update (this_proj -> modelgl);
234}
235
236#ifdef GTK4
247void color_box (glwin * view, int ideo, int spec, int geo)
248#else
259GtkWidget * color_box (glwin * view, int ideo, int spec, int geo)
260#endif
261{
262 int l, m, n, p;
263 p = view -> proj;
264#ifdef GTK3
265 GtkWidget * but;
266 GtkWidget * coltable;
267// #ifdef GTK3
268 coltable = gtk_menu_new ();
269// #else
270// coltable = gtk_grid_new ();
271// #endif
272 ColRGBA but_col;
273#endif
274 project * this_proj = get_project_by_id(p);
275 l = 0;
276 for (l=0; l<64; l++)
277 {
278#ifdef GTK3
279 get_color (& but_col, l);
280 cairo_surface_t * surface = col_surface (but_col.red, but_col.green, but_col.blue, 12, 12);
281// #ifdef GTK3
282 but = gtk3_menu_item (NULL, NULL, IMG_SURFACE, (gpointer)surface, NULL, NULL, FALSE, 0, 0, FALSE, FALSE, FALSE);
283/* #else
284 GtkWidget * but_img = create_image_from_data (IMG_SURFACE, surface);
285 show_the_widgets (but_img);
286 but = gtk_button_new ();
287 add_container_child (CONTAINER_BUT, but, but_img);
288 gtk_button_set_has_frame ((GtkButton *)but, FALSE);
289 show_the_widgets (but);
290#endif */
291 cairo_surface_destroy (surface);
292#endif
293 if (ideo < -2)
294 {
295 view -> gcid[4+spec][geo][l].a = p;
296 view -> gcid[4+spec][geo][l].b = spec;
297 view -> gcid[4+spec][geo][l].c = geo;
298 view -> gcid[4+spec][geo][l].d = l;
299#ifdef GTK3
300 g_signal_connect (G_OBJECT (but), "activate", G_CALLBACK(set_rings_color), & view -> gcid[4+spec][geo][l]);
301#endif
302 }
303 else if (ideo == -2)
304 {
305#ifdef GTK3
306 g_signal_connect (G_OBJECT (but), "activate", G_CALLBACK(set_back_color), & view -> colorp[l][0]);
307#endif
308 }
309 else if (ideo == -1)
310 {
311#ifdef GTK3
312 g_signal_connect (G_OBJECT (but), "activate", G_CALLBACK(set_box_color), & view -> colorp[l][0]);
313#endif
314 }
315 else if (ideo < this_proj -> nspec*2)
316 {
317#ifdef GTK3
318 g_signal_connect (G_OBJECT (but), "activate", G_CALLBACK(set_at_color), & view -> colorp[l][ideo]);
319#endif
320 }
321 else if (ideo < 2*this_proj -> nspec + this_proj -> coord -> totcoord[0])
322 {
323 n = ideo - 2*this_proj -> nspec;
324 view -> gcid[0][n][l].a = p;
325 view -> gcid[0][n][l].b = spec;
326 view -> gcid[0][n][l].c = geo;
327 view -> gcid[0][n][l].d = l;
328#ifdef GTK3
329 g_signal_connect (G_OBJECT (but), "activate", G_CALLBACK(set_total_coord_color), & view -> gcid[0][n][l]);
330#endif
331 }
332 else if (ideo < 2*this_proj -> nspec + this_proj -> coord -> totcoord[0] + this_proj -> coord -> totcoord[1])
333 {
334 n = ideo - 2*this_proj -> nspec - this_proj -> coord -> totcoord[0];
335 view -> gcid[1][n][l].a = p;
336 view -> gcid[1][n][l].b = spec;
337 view -> gcid[1][n][l].c = geo;
338 view -> gcid[1][n][l].d = l;
339#ifdef GTK3
340 g_signal_connect (G_OBJECT (but), "activate", G_CALLBACK(set_partial_coord_color), & view -> gcid[1][n][l]);
341#endif
342 }
343 else
344 {
345 n = ideo - 2*this_proj -> nspec;
346 for (m= 0; m<spec; m++)
347 {
348 n -= this_proj -> coord -> totcoord[m];
349 }
350 view -> gcid[spec][n][l].a = p;
351 view -> gcid[spec][n][l].b = spec;
352 view -> gcid[spec][n][l].c = geo;
353 view -> gcid[spec][n][l].d = l;
354#ifdef GTK3
355 g_signal_connect (G_OBJECT (but), "activate", G_CALLBACK(set_frag_mol_color), & view -> gcid[spec][n][l]);
356#endif
357 }
358 m = l/4;
359#ifdef GTK3
360 gtk_menu_attach (GTK_MENU(coltable), but, l-m*4, l+1-m*4, m, m+1);
361// #else
362 // gtk_grid_attach (GTK_GRID(coltable), but, l-m*4, m, 1, 1);
363#endif
364 }
365#ifdef GTK3
366 but = create_menu_item (FALSE, "More colors ...");
367 gtk_menu_shell_append ((GtkMenuShell *)coltable, but);
368 if (ideo < -2)
369 {
370 g_signal_connect (G_OBJECT (but), "activate", G_CALLBACK(window_color_coord), & view -> gcid[4+spec][geo][4+spec]);
371 }
372 else if (ideo == -2)
373 {
374 g_signal_connect (G_OBJECT (but), "activate", G_CALLBACK(to_run_back_color_window), view);
375 }
376 else if (ideo == -1)
377 {
378 g_signal_connect (G_OBJECT (but), "activate", G_CALLBACK(to_run_box_color_window), view);
379 }
380 else if (ideo < this_proj -> nspec*2)
381 {
382 g_signal_connect (G_OBJECT (but), "activate", G_CALLBACK(to_run_atom_color_window), & view -> colorp[0][ideo]);
383 }
384 else if (ideo < this_proj -> nspec*2 + this_proj -> coord -> totcoord[0])
385 {
386 g_signal_connect (G_OBJECT (but), "activate", G_CALLBACK(window_color_coord), & view -> gcid[0][n][0]);
387 }
388 else if (ideo < 2*this_proj -> nspec + this_proj -> coord -> totcoord[0] + this_proj -> coord -> totcoord[1])
389 {
390 g_signal_connect (G_OBJECT (but), "activate", G_CALLBACK(window_color_coord), & view -> gcid[1][n][1]);
391 }
392 else
393 {
394 g_signal_connect (G_OBJECT (but), "activate", G_CALLBACK(window_color_coord), & view -> gcid[spec][n][spec]);
395 }
396 show_the_widgets (coltable);
397 return coltable;
398#endif
399}
400
401#ifdef GTK4
412GtkWidget * color_palette (glwin * view, int ideo, int spec, int geo)
413{
414 int l, m, n, p;
415 p = view -> proj;
416 GtkWidget * but;
417 GtkWidget * coltable = gtk_grid_new ();
418 ColRGBA but_col;
419 project * this_proj = get_project_by_id(p);
420 l = 0;
421 for (l=0; l<64; l++)
422 {
423 get_color (& but_col, l);
424 cairo_surface_t * surface = col_surface (but_col.red, but_col.green, but_col.blue, 12, 12);
425 GtkWidget * but_img = create_image_from_data (IMG_SURFACE, surface);
426 show_the_widgets (but_img);
427 but = gtk_button_new ();
428 add_container_child (CONTAINER_BUT, but, but_img);
429 gtk_button_set_has_frame ((GtkButton *)but, FALSE);
430 show_the_widgets (but);
431 cairo_surface_destroy (surface);
432 if (ideo < -2)
433 {
434 g_signal_connect (G_OBJECT (but), "activate", G_CALLBACK(set_rings_color), & view -> gcid[4+spec][geo][l]);
435 }
436 else if (ideo == -2)
437 {
438 g_signal_connect (G_OBJECT (but), "activate", G_CALLBACK(set_back_color), & view -> colorp[l][0]);
439 }
440 else if (ideo == -1)
441 {
442 g_signal_connect (G_OBJECT (but), "activate", G_CALLBACK(set_box_color), & view -> colorp[l][0]);
443 }
444 else if (ideo < this_proj -> nspec*2)
445 {
446 g_signal_connect (G_OBJECT (but), "activate", G_CALLBACK(set_at_color), & view -> colorp[l][ideo]);
447 }
448 else if (ideo < 2*this_proj -> nspec + this_proj -> coord -> totcoord[0])
449 {
450 n = ideo - 2*this_proj -> nspec;
451 g_signal_connect (G_OBJECT (but), "activate", G_CALLBACK(set_total_coord_color), & view -> gcid[0][n][l]);
452 }
453 else if (ideo < 2*this_proj -> nspec + this_proj -> coord -> totcoord[0] + this_proj -> coord -> totcoord[1])
454 {
455 n = ideo - 2*this_proj -> nspec - this_proj -> coord -> totcoord[0];
456 g_signal_connect (G_OBJECT (but), "activate", G_CALLBACK(set_partial_coord_color), & view -> gcid[1][n][l]);
457 }
458 else
459 {
460 n = ideo - 2*this_proj -> nspec;
461 for (m= 0; m<spec; m++)
462 {
463 n -= this_proj -> coord -> totcoord[m];
464 }
465 g_signal_connect (G_OBJECT (but), "activate", G_CALLBACK(set_frag_mol_color), & view -> gcid[spec][n][l]);
466 }
467 m = l/4;
468 gtk_grid_attach (GTK_GRID(coltable), but, l-m*4, m, 1, 1);
469 }
470 show_the_widgets (coltable);
471 return coltable;
472}
473#endif
G_MODULE_EXPORT void set_box_color(GtkWidget *widg, gpointer data)
set box color
Definition color_box.c:129
G_MODULE_EXPORT void set_frag_mol_color(GtkWidget *widg, gpointer data)
set fragment color
Definition color_box.c:224
G_MODULE_EXPORT void set_back_color(GtkWidget *widg, gpointer data)
set background color
Definition color_box.c:109
G_MODULE_EXPORT void set_at_color(GtkWidget *widg, gpointer data)
set atomic species color
Definition color_box.c:146
GtkWidget * color_box(glwin *view, int ideo, int spec, int geo)
create the color palette pointers and menus GTK3 version
Definition color_box.c:259
cairo_surface_t * col_surface(double r, double g, double b, int x, int y)
create a cairo sufrace painted with the appropriate color
Definition color_box.c:89
G_MODULE_EXPORT void set_rings_color(GtkWidget *widg, gpointer data)
set ring polyhedra color
Definition color_box.c:166
G_MODULE_EXPORT void set_partial_coord_color(GtkWidget *widg, gpointer data)
set partial coordination color
Definition color_box.c:204
void update_gradient_widgets(gradient_edition *gradient_win, background *back)
update the widgets of the gradient window
Definition w_colors.c:84
void get_color(ColRGBA *but, int cid)
get color from the color palette id
Definition color_box.c:68
G_MODULE_EXPORT void set_total_coord_color(GtkWidget *widg, gpointer data)
set total coordination color
Definition color_box.c:184
Structure definitions for color management Function declarations for color management.
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:223
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:585
color colorp[64]
G_MODULE_EXPORT void window_color_coord(GtkWidget *widg, gpointer data)
create a window to select a color callback GTK3
Definition w_colors.c:677
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:615
ColRGBA col
Definition d_measures.c:77
Global variable declarations Global convenience function declarations Global data structure defin...
@ IMG_SURFACE
Definition global.h:264
GtkWidget * gtk3_menu_item(GtkWidget *menu, gchar *name, int icon_format, gpointer item_icon, GCallback handler, gpointer data, gboolean accel, guint key, GdkModifierType mod, gboolean check, gboolean radio, gboolean status)
project * proj
@ CONTAINER_BUT
Definition global.h:255
GtkWidget * create_image_from_data(int format, gpointer item_image)
create Gtk image for data
Definition gtk-misc.c:1504
GtkWidget * create_menu_item(gboolean add_mnemo, gchar *action)
void add_container_child(int type, GtkWidget *widg, GtkWidget *child)
Add a GtkWidget into another GtkWidget.
Definition gtk-misc.c:235
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...
void re_create_md_shaders(int nshaders, int shaders[nshaders], project *this_proj)
re-initialize some MD dependent OpenGL shaders
void cleaning_shaders(glwin *view, int shader)
re-initialize an OpenGL shader
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
@ MDBOX
Definition glwin.h:93
@ MEASU
Definition glwin.h:99
@ ATOMS
Definition glwin.h:89
@ RINGS
Definition glwin.h:96
@ BACKG
Definition glwin.h:103
Function declarations for the creation of the OpenGL window.
Messaging function declarations.
double y
Definition ogl_draw.c:61
double x
Definition ogl_draw.c:61
Function declarations for reading atomes project file Function declarations for saving atomes proje...
float blue
Definition global.h:126
float red
Definition global.h:124
float green
Definition global.h:125
Definition glwin.h:965
Definition global.h:114
Definition global.h:106
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
GtkWidget * img
Definition workspace.c:70