atomes 1.1.15
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-2024 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
66void get_color (ColRGBA * but, int cid)
67{
68 int rid = cid / 4;
69 int bid = cid - rid*4;
70 but -> red = (rid < 6) ? 0.0 : (rid < 11) ? 0.2 * (rid - 5) : 1.0;
71 but -> green = (rid < 6) ? 0.2*rid : (rid < 11) ? 1.0 - 0.2 * (rid - 5) : 0.2 * (rid - 10);
72 but -> blue = bid * 0.333;
73 if (bid == 3) but -> blue = 1.0;
74}
75
87cairo_surface_t * col_surface (double r, double g, double b, int x, int y)
88{
89 cairo_surface_t * cst;
90 cairo_t * tcst;
91 cst = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, x, y);
92 tcst = cairo_create (cst);
93 cairo_set_source_rgb (tcst, r, g, b);
94 cairo_paint (tcst);
95 cairo_destroy (tcst);
96 return cst;
97}
98
107G_MODULE_EXPORT void set_back_color (GtkWidget * widg, gpointer data)
108{
109 tint * col = (tint *) data;
110 project * this_proj = get_project_by_id(col -> a);
111 get_color (& this_proj -> modelgl -> anim -> last -> img -> backcolor, col -> b);
112 this_proj -> modelgl -> create_shaders[MEASU] = TRUE;
113 update (this_proj -> modelgl);
114}
115
124G_MODULE_EXPORT void set_box_color (GtkWidget * widg, gpointer data)
125{
126 tint * col = (tint *) data;
127 project * this_proj = get_project_by_id(col -> a);
128 get_color (& this_proj -> modelgl -> anim -> last -> img -> box_color, col -> b);
129 this_proj -> modelgl -> create_shaders[MDBOX] = TRUE;
130 update (this_proj -> modelgl);
131}
132
141G_MODULE_EXPORT void set_at_color (GtkWidget * widg, gpointer data)
142{
143 tint * col = (tint *) data;
144 project * this_proj = get_project_by_id(col -> a);
145 get_color (& this_proj -> modelgl -> anim -> last -> img -> at_color[col -> c], col -> b);
146 int shaders[2] = {ATOMS, BONDS};
147 re_create_md_shaders (2, shaders, this_proj);
148 this_proj -> modelgl -> create_shaders[LABEL] = TRUE;
149 if (this_proj -> modelgl -> anim -> last -> img -> color_map[1] == 0) this_proj -> modelgl -> create_shaders[POLYS] = TRUE;
150 update (this_proj -> modelgl);
151}
152
161G_MODULE_EXPORT void set_rings_color (GtkWidget * widg, gpointer data)
162{
163 qint * col = (qint *)data;
164 project * this_proj = get_project_by_id(col -> a);
165 get_color (& this_proj -> modelgl -> anim -> last -> img -> spcolor[4+col -> b][0][col -> c], col -> d);
166 int shaders[1] = {RINGS};
167 re_create_md_shaders (1, shaders, this_proj);
168 update (this_proj -> modelgl);
169}
170
179G_MODULE_EXPORT void set_total_coord_color (GtkWidget * widg, gpointer data)
180{
181 qint * col = (qint *)data;
182 project * this_proj = get_project_by_id(col -> a);
183 get_color (& this_proj -> modelgl -> anim -> last -> img -> spcolor[0][col -> b][col -> c], col -> d);
184 int shaders[2] = {ATOMS, BONDS};
185 re_create_md_shaders (2, shaders, this_proj);
186 this_proj -> modelgl -> create_shaders[LABEL] = TRUE;
187 if (this_proj -> modelgl -> anim -> last -> img -> color_map[1] == 1) this_proj -> modelgl -> create_shaders[POLYS] = TRUE;
188 update (this_proj -> modelgl);
189}
190
199G_MODULE_EXPORT void set_partial_coord_color (GtkWidget * widg, gpointer data)
200{
201 qint * col = (qint *)data;
202 project * this_proj = get_project_by_id(col -> a);
203 get_color (& this_proj -> modelgl -> anim -> last -> img -> spcolor[1][col -> b][col -> c], col -> d);
204 int shaders[2] = {ATOMS, BONDS};
205 re_create_md_shaders (2, shaders, this_proj);
206 this_proj -> modelgl -> create_shaders[LABEL] = TRUE;
207 if (this_proj -> modelgl -> anim -> last -> img -> color_map[1] == 2) this_proj -> modelgl -> create_shaders[POLYS] = TRUE;
208 update (this_proj -> modelgl);
209}
210
219G_MODULE_EXPORT void set_frag_mol_color (GtkWidget * widg, gpointer data)
220{
221 qint * col = (qint *)data;
222 project * this_proj = get_project_by_id(col -> a);
223 get_color (& this_proj -> modelgl -> anim -> last -> img -> spcolor[col -> b][0][col -> c], col -> d);
224 int shaders[2] = {ATOMS, BONDS};
225 re_create_md_shaders (2, shaders, this_proj);
226 this_proj -> modelgl -> create_shaders[LABEL] = TRUE;
227 if (this_proj -> modelgl -> anim -> last -> img -> color_map[1] == col -> b + 1) this_proj -> modelgl -> create_shaders[POLYS] = TRUE;
228 update (this_proj -> modelgl);
229}
230
231#ifdef GTK4
242void color_box (glwin * view, int ideo, int spec, int geo)
243#else
254GtkWidget * color_box (glwin * view, int ideo, int spec, int geo)
255#endif
256{
257 int l, m, n, p;
258 p = view -> proj;
259#ifdef GTK3
260 GtkWidget * but;
261 GtkWidget * coltable;
262// #ifdef GTK3
263 coltable = gtk_menu_new ();
264// #else
265// coltable = gtk_grid_new ();
266// #endif
267 ColRGBA but_col;
268#endif
269 project * this_proj = get_project_by_id(p);
270 l = 0;
271 for (l=0; l<64; l++)
272 {
273#ifdef GTK3
274 get_color (& but_col, l);
275 cairo_surface_t * surface = col_surface (but_col.red, but_col.green, but_col.blue, 12, 12);
276// #ifdef GTK3
277 but = gtk3_menu_item (NULL, NULL, IMG_SURFACE, (gpointer)surface, NULL, NULL, FALSE, 0, 0, FALSE, FALSE, FALSE);
278/* #else
279 GtkWidget * but_img = create_image_from_data (IMG_SURFACE, surface);
280 show_the_widgets (but_img);
281 but = gtk_button_new ();
282 add_container_child (CONTAINER_BUT, but, but_img);
283 gtk_button_set_has_frame ((GtkButton *)but, FALSE);
284 show_the_widgets (but);
285#endif */
286 cairo_surface_destroy (surface);
287#endif
288 if (ideo < -2)
289 {
290 view -> gcid[4+spec][geo][l].a = p;
291 view -> gcid[4+spec][geo][l].b = spec;
292 view -> gcid[4+spec][geo][l].c = geo;
293 view -> gcid[4+spec][geo][l].d = l;
294#ifdef GTK3
295 g_signal_connect (G_OBJECT (but), "activate", G_CALLBACK(set_rings_color), & view -> gcid[4+spec][geo][l]);
296#endif
297 }
298 else if (ideo == -2)
299 {
300#ifdef GTK3
301 g_signal_connect (G_OBJECT (but), "activate", G_CALLBACK(set_back_color), & view -> colorp[l][0]);
302#endif
303 }
304 else if (ideo == -1)
305 {
306#ifdef GTK3
307 g_signal_connect (G_OBJECT (but), "activate", G_CALLBACK(set_box_color), & view -> colorp[l][0]);
308#endif
309 }
310 else if (ideo < this_proj -> nspec*2)
311 {
312#ifdef GTK3
313 g_signal_connect (G_OBJECT (but), "activate", G_CALLBACK(set_at_color), & view -> colorp[l][ideo]);
314#endif
315 }
316 else if (ideo < 2*this_proj -> nspec + this_proj -> coord -> totcoord[0])
317 {
318 n = ideo - 2*this_proj -> nspec;
319 view -> gcid[0][n][l].a = p;
320 view -> gcid[0][n][l].b = spec;
321 view -> gcid[0][n][l].c = geo;
322 view -> gcid[0][n][l].d = l;
323#ifdef GTK3
324 g_signal_connect (G_OBJECT (but), "activate", G_CALLBACK(set_total_coord_color), & view -> gcid[0][n][l]);
325#endif
326 }
327 else if (ideo < 2*this_proj -> nspec + this_proj -> coord -> totcoord[0] + this_proj -> coord -> totcoord[1])
328 {
329 n = ideo - 2*this_proj -> nspec - this_proj -> coord -> totcoord[0];
330 view -> gcid[1][n][l].a = p;
331 view -> gcid[1][n][l].b = spec;
332 view -> gcid[1][n][l].c = geo;
333 view -> gcid[1][n][l].d = l;
334#ifdef GTK3
335 g_signal_connect (G_OBJECT (but), "activate", G_CALLBACK(set_partial_coord_color), & view -> gcid[1][n][l]);
336#endif
337 }
338 else
339 {
340 n = ideo - 2*this_proj -> nspec;
341 for (m= 0; m<spec; m++)
342 {
343 n -= this_proj -> coord -> totcoord[m];
344 }
345 view -> gcid[spec][n][l].a = p;
346 view -> gcid[spec][n][l].b = spec;
347 view -> gcid[spec][n][l].c = geo;
348 view -> gcid[spec][n][l].d = l;
349#ifdef GTK3
350 g_signal_connect (G_OBJECT (but), "activate", G_CALLBACK(set_frag_mol_color), & view -> gcid[spec][n][l]);
351#endif
352 }
353 m = l/4;
354#ifdef GTK3
355 gtk_menu_attach (GTK_MENU(coltable), but, l-m*4, l+1-m*4, m, m+1);
356// #else
357 // gtk_grid_attach (GTK_GRID(coltable), but, l-m*4, m, 1, 1);
358#endif
359 }
360#ifdef GTK3
361 but = create_menu_item (FALSE, "More colors ...");
362 gtk_menu_shell_append ((GtkMenuShell *)coltable, but);
363// #endif
364 if (ideo < -2)
365 {
366 g_signal_connect (G_OBJECT (but), "activate", G_CALLBACK(window_color_coord), & view -> gcid[4+spec][geo][4+spec]);
367 }
368 else if (ideo == -2)
369 {
370 g_signal_connect (G_OBJECT (but), "activate", G_CALLBACK(to_run_back_color_window), view);
371 }
372 else if (ideo == -1)
373 {
374 g_signal_connect (G_OBJECT (but), "activate", G_CALLBACK(to_run_box_color_window), view);
375 }
376 else if (ideo < this_proj -> nspec*2)
377 {
378 g_signal_connect (G_OBJECT (but), "activate", G_CALLBACK(to_run_atom_color_window), & view -> colorp[0][ideo]);
379 }
380 else if (ideo < this_proj -> nspec*2 + this_proj -> coord -> totcoord[0])
381 {
382 g_signal_connect (G_OBJECT (but), "activate", G_CALLBACK(window_color_coord), & view -> gcid[0][n][0]);
383 }
384 else if (ideo < 2*this_proj -> nspec + this_proj -> coord -> totcoord[0] + this_proj -> coord -> totcoord[1])
385 {
386 g_signal_connect (G_OBJECT (but), "activate", G_CALLBACK(window_color_coord), & view -> gcid[1][n][1]);
387 }
388 else
389 {
390 g_signal_connect (G_OBJECT (but), "activate", G_CALLBACK(window_color_coord), & view -> gcid[spec][n][spec]);
391 }
392 show_the_widgets (coltable);
393 return coltable;
394#endif
395}
396
397#ifdef GTK4
408GtkWidget * color_palette (glwin * view, int ideo, int spec, int geo)
409{
410 int l, m, n, p;
411 p = view -> proj;
412 GtkWidget * but;
413 GtkWidget * coltable = gtk_grid_new ();
414 ColRGBA but_col;
415 project * this_proj = get_project_by_id(p);
416 l = 0;
417 for (l=0; l<64; l++)
418 {
419 get_color (& but_col, l);
420 cairo_surface_t * surface = col_surface (but_col.red, but_col.green, but_col.blue, 12, 12);
421 GtkWidget * but_img = create_image_from_data (IMG_SURFACE, surface);
422 show_the_widgets (but_img);
423 but = gtk_button_new ();
424 add_container_child (CONTAINER_BUT, but, but_img);
425 gtk_button_set_has_frame ((GtkButton *)but, FALSE);
426 show_the_widgets (but);
427 cairo_surface_destroy (surface);
428 if (ideo < -2)
429 {
430 g_signal_connect (G_OBJECT (but), "activate", G_CALLBACK(set_rings_color), & view -> gcid[4+spec][geo][l]);
431 }
432 else if (ideo == -2)
433 {
434 g_signal_connect (G_OBJECT (but), "activate", G_CALLBACK(set_back_color), & view -> colorp[l][0]);
435 }
436 else if (ideo == -1)
437 {
438 g_signal_connect (G_OBJECT (but), "activate", G_CALLBACK(set_box_color), & view -> colorp[l][0]);
439 }
440 else if (ideo < this_proj -> nspec*2)
441 {
442 g_signal_connect (G_OBJECT (but), "activate", G_CALLBACK(set_at_color), & view -> colorp[l][ideo]);
443 }
444 else if (ideo < 2*this_proj -> nspec + this_proj -> coord -> totcoord[0])
445 {
446 n = ideo - 2*this_proj -> nspec;
447 g_signal_connect (G_OBJECT (but), "activate", G_CALLBACK(set_total_coord_color), & view -> gcid[0][n][l]);
448 }
449 else if (ideo < 2*this_proj -> nspec + this_proj -> coord -> totcoord[0] + this_proj -> coord -> totcoord[1])
450 {
451 n = ideo - 2*this_proj -> nspec - this_proj -> coord -> totcoord[0];
452 g_signal_connect (G_OBJECT (but), "activate", G_CALLBACK(set_partial_coord_color), & view -> gcid[1][n][l]);
453 }
454 else
455 {
456 n = ideo - 2*this_proj -> nspec;
457 for (m= 0; m<spec; m++)
458 {
459 n -= this_proj -> coord -> totcoord[m];
460 }
461 g_signal_connect (G_OBJECT (but), "activate", G_CALLBACK(set_frag_mol_color), & view -> gcid[spec][n][l]);
462 }
463 m = l/4;
464 gtk_grid_attach (GTK_GRID(coltable), but, l-m*4, m, 1, 1);
465 }
466 show_the_widgets (coltable);
467 return coltable;
468}
469#endif
G_MODULE_EXPORT void set_box_color(GtkWidget *widg, gpointer data)
set box color
Definition color_box.c:124
G_MODULE_EXPORT void set_frag_mol_color(GtkWidget *widg, gpointer data)
set fragment color
Definition color_box.c:219
G_MODULE_EXPORT void set_back_color(GtkWidget *widg, gpointer data)
set background color
Definition color_box.c:107
G_MODULE_EXPORT void set_at_color(GtkWidget *widg, gpointer data)
set atomic species color
Definition color_box.c:141
GtkWidget * color_box(glwin *view, int ideo, int spec, int geo)
create the color palette pointers and menus GTK3 version
Definition color_box.c:254
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:87
G_MODULE_EXPORT void set_rings_color(GtkWidget *widg, gpointer data)
set ring polyhedra color
Definition color_box.c:161
G_MODULE_EXPORT void set_partial_coord_color(GtkWidget *widg, gpointer data)
set partial coordination color
Definition color_box.c:199
void get_color(ColRGBA *but, int cid)
get color from the color palette id
Definition color_box.c:66
G_MODULE_EXPORT void set_total_coord_color(GtkWidget *widg, gpointer data)
set total coordination color
Definition color_box.c:179
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: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
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:285
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
ColRGBA col
Definition d_measures.c:77
Global variable declarations Global convenience function declarations Global data structure defin...
@ IMG_SURFACE
Definition global.h:262
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:253
GtkWidget * create_image_from_data(int format, gpointer item_image)
create Gtk image for data
Definition gtk-misc.c:1443
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:226
void show_the_widgets(GtkWidget *widg)
show GtkWidget
Definition gtk-misc.c:173
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
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
Function declarations for the creation of the OpenGL window.
Messaging function declarations.
double y
Definition ogl_draw.c:57
double x
Definition ogl_draw.c:57
Function declarations for reading atomes project file Function declarations for saving atomes proje...
float blue
Definition global.h:124
float red
Definition global.h:122
float green
Definition global.h:123
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
GtkWidget * img
Definition workspace.c:70