atomes 1.1.14
atomes: an atomic scale modeling tool box
Loading...
Searching...
No Matches
cell_pixel.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: 'cell_pixel.c'
25*
26* Contains:
27*
28
29 - The functions to create the pixel debugging tab for the cell edition window
30 This is only used when DEBUG option is activated at build time
31
32*
33* List of functions:
34
35 void pix_info_ (int * na, int * nb, int * nc);
36 void send_pix_info_ (int * p, int listp[27], int * ngb);
37 void update_pix_table (project * this_proj);
38
39 G_MODULE_EXPORT void set_pix (GtkEntry * res, gpointer data);
40
41 GtkWidget * create_css_label (gchar * str, int id);
42 GtkWidget * attach_grid (project * this_proj, int init);
43 GtkWidget * pixels_tab (project * this_proj);
44
45*/
46
47#ifdef DEBUG
48
49#include "cell_edit.h"
50
60void pix_info_ (int * na, int * nb, int * nc)
61{
62 active_project -> pix[0] = *na;
63 active_project -> pix[1] = *nb;
64 active_project -> pix[2] = *nc;
66}
67
77void send_pix_info_ (int * p, int listp[27], int * ngb)
78{
79 int i;
80 for (i=0; i<* ngb; i++)
81 {
82 active_project -> pixels[* p][i] = listp[i];
83 }
84}
85
94GtkWidget * create_css_label (gchar * str, int id)
95{
96 gchar * colo[2] = {"white", "yellow"};
97 gchar * backcol;
98 if (id)
99 {
100 backcol = g_strdup_printf ("label#icolor {\n"
101 " background-color: red;\n"
102 " color: %s;\n}", colo[id]);
103 }
104 else
105 {
106 backcol = g_strdup_printf ("label#color {\n"
107 " background-color: blue;\n"
108 " color: %s;\n}", colo[id]);
109
110 }
111 provide_gtk_css (backcol);
112 g_free (backcol);
113 GtkWidget * lab = markup_label(str, 50, 50, 0.5, 0.5);
114 gtk_widget_set_name (lab, (id) ? "icolor" : "color");
115 gtk_widget_show (lab);
116 return lab;
117}
118
127GtkWidget * attach_grid (project * this_proj, int init)
128{
129 GtkWidget * table = gtk_grid_new ();
130 gchar * str;
131 gboolean actif;
132 int i, j, k, l, m;
133 l = init+1;
134 for (i=0; i<this_proj -> pix[1]; i++)
135 {
136 for (j=0; j<this_proj -> pix[0]; j++)
137 {
138 actif = FALSE;
139 for (k=0; k<27; k++)
140 {
141 if (l == this_proj -> pixels[this_proj -> actif_pix-1][k])
142 {
143 actif = TRUE;
144 }
145 }
146 if (l == this_proj -> actif_pix)
147 {
148 str = g_strdup_printf ("<b>%d</b>", l);
149 m = 1;
150 }
151 else
152 {
153 str = g_strdup_printf ("%d", l);
154 m = 0;
155 }
156 l ++;
157 if (actif)
158 {
159 gtk_grid_attach (GTK_GRID (table), create_css_label(str, m), j, i, 1, 1);
160 }
161 else
162 {
163 gtk_grid_attach (GTK_GRID (table), markup_label(str, 50, 50, 0.5, 0.5), j, i, 1, 1);
164 }
165 g_free (str);
166 }
167 }
168 gtk_widget_set_size_request (table, this_proj -> pix[0]*50, this_proj -> pix[1]*50);
169 return table;
170}
171
179void update_pix_table (project * this_proj)
180{
181 int i;
182 int pix[3];
183
184 for (i=0; i<3; i++)
185 {
186 this_proj -> pix_tab[i] = destroy_this_widget (this_proj -> pix_tab[i]);
187 }
188
189 // Seed for bottom grid
190 if (this_proj -> actif_pix <= this_proj -> pix[0]*this_proj -> pix[1])
191 {
192 pix[0] = this_proj -> pix[0]*this_proj -> pix[1]*(this_proj -> pix[2]-1);
193 }
194 else
195 {
196 pix[0] = (this_proj -> actif_pix-1)/(this_proj -> pix[0]*this_proj -> pix[1]);
197 pix[0] -= 1;
198 pix[0] *= (this_proj -> pix[0]*this_proj -> pix[1]);
199 }
200
201 // Seed for pixel grid
202 pix[1] = (this_proj -> actif_pix-1)/(this_proj -> pix[0]*this_proj -> pix[1]);
203 pix[1] *= (this_proj -> pix[0]*this_proj -> pix[1]);
204
205 // Seed for top grid
206 if (this_proj -> actif_pix > this_proj -> pix[0]*this_proj -> pix[1]*(this_proj -> pix[2]-1))
207 {
208 pix[2] = 0;
209 }
210 else
211 {
212 pix[2] = (this_proj -> actif_pix-1)/(this_proj -> pix[0]*this_proj -> pix[1]);
213 pix[2] += 1;
214 pix[2] *= (this_proj -> pix[0]*this_proj -> pix[1]);
215 }
216 for (i=0; i<3; i++)
217 {
218 this_proj -> pix_tab[i] = attach_grid (this_proj, pix[i]);
219 add_box_child_start (GTK_ORIENTATION_VERTICAL, this_proj -> pix_box, this_proj -> pix_tab[i], FALSE, FALSE, 20);
220 }
221 show_the_widgets (this_proj -> pix_box);
222}
223
232G_MODULE_EXPORT void set_pix (GtkEntry * res, gpointer data)
233{
234 int id = GPOINTER_TO_INT (data);
235 project * this_proj = get_project_by_id (id);
236 const gchar * m = entry_get_text (res);
237 double v = atof(m);
238 int p = (int)v;
239 int n = this_proj-> pix[0] * this_proj -> pix[1] * this_proj -> pix[2];
240 if (p > 0 && p <= n)
241 {
242 this_proj -> actif_pix = p;
243 }
244 update_entry_int (res, this_proj -> actif_pix);
245 update_pix_table (this_proj);
246}
247
255GtkWidget * pixels_tab (project * this_proj)
256{
257 GtkWidget * vbox = create_vbox (BSEP);
258 GtkWidget * hbox = create_hbox (0);
259 gchar * str = g_strdup_printf ("\tSelect pixel to check, from 1 to %d:", this_proj -> pix[0]*this_proj -> pix[1]*this_proj->pix[2]);
260 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hbox, markup_label(str, -1, -1, 0.0, 0.5), FALSE, FALSE, 10);
261 g_free (str);
262 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hbox, create_entry(G_CALLBACK(set_pix), 100, 15, FALSE, GINT_TO_POINTER(this_proj -> id)), FALSE, FALSE, 10);
263 add_box_child_start (GTK_ORIENTATION_VERTICAL, vbox, hbox, FALSE, FALSE, 5);
264 GtkWidget * scroll = create_scroll (vbox, 700, 350, GTK_SHADOW_ETCHED_IN);
265 this_proj -> actif_pix = 1;
266 this_proj -> pix_box = create_vbox (0);
267 this_proj -> pix_tab[0] = this_proj -> pix_tab[1] = this_proj -> pix_tab[2] = NULL;
268 update_pix_table (this_proj);
269 add_container_child (CONTAINER_SCR, scroll, this_proj -> pix_box);
270 return vbox;
271}
272
273#endif // DEBUG
Function declarations for the cell edition window.
GtkWidget * pixels_tab(project *this_proj)
int ** allocdint(int xal, int yal)
allocate an int ** pointer
Definition global.c:342
GtkWidget * create_entry(GCallback handler, int dim, int cdim, gboolean key_release, gpointer data)
Create a GtkEntry.
Definition gtk-misc.c:1294
GtkWidget * create_scroll(GtkWidget *box, int dimx, int dimy, int shadow)
create a scroll window
Definition gtk-misc.c:1940
const gchar * entry_get_text(GtkEntry *entry)
get the text in a GtkEntry
Definition gtk-misc.c:577
#define BSEP
Definition global.h:217
void update_entry_int(GtkEntry *entry, int intval)
update the content of a GtkEntry as int
Definition gtk-misc.c:594
@ CONTAINER_SCR
Definition global.h:223
GtkWidget * markup_label(gchar *text, int dimx, int dimy, float ax, float ay)
Definition gtk-misc.c:1565
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:279
GtkWidget * create_hbox(int spacing)
create a GtkBox with horizontal orientation
Definition gtk-misc.c:793
GtkWidget * destroy_this_widget(GtkWidget *widg)
destroy a GtkWidget
Definition gtk-misc.c:2010
void provide_gtk_css(gchar *css)
create a css provider based on the css data
Definition gtk-misc.c:1986
void add_container_child(int type, GtkWidget *widg, GtkWidget *child)
Add a GtkWidget into another GtkWidget.
Definition gtk-misc.c:206
GtkWidget * create_vbox(int spacing)
create a GtkBox with vertical orientation
Definition gtk-misc.c:781
project * active_project
Definition project.c:47
void show_the_widgets(GtkWidget *widg)
show GtkWidget
Definition gtk-misc.c:169
project * get_project_by_id(int p)
get project pointer using id number
Definition project.c:120
GtkWidget * res[2]
Definition w_encode.c:212
GdkPixbuf * pix
Definition workspace.c:69
GtkWidget * hbox
Definition workspace.c:71
GtkWidget * vbox
Definition workspace.c:72
GtkWidget * lab
Definition workspace.c:73