atomes 1.1.14
atomes: an atomic scale modeling tool box
Loading...
Searching...
No Matches
m_axis.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: 'm_axis.c'
24*
25* Contains:
26*
27
28 - The functions to create the 'View -> Axis' submenu
29
30*
31* List of functions:
32
33 void menu_axis (GtkWidget * menu_ab, glwin * view, int id);
34 void menu_axis (GMenu * menu_ab, glwin * view, int popm);
35
36 G_MODULE_EXPORT void set_axis_template_pos (GtkWidget * widg, gpointer data);
37 G_MODULE_EXPORT void change_axis_pos_radio (GSimpleAction * action, GVariant * parameter, gpointer data);
38
39 GtkWidget * axis_position_submenu (glwin * view, int id);
40
41 GMenu * position_submenu (glwin * view, int popm, int pos);
42 GMenu * axis_position_submenu (glwin * view, int popm);
43
44*/
45
46#include "global.h"
47#include "glview.h"
48#include "glwindow.h"
49#include "submenus.h"
50
51#ifdef GTK4
52extern G_MODULE_EXPORT void axis_advanced (GSimpleAction * action, GVariant * parameter, gpointer data);
53#else
54extern G_MODULE_EXPORT void axis_advanced (GtkWidget * widg, gpointer data);
55#endif
56extern GtkWidget * create_layout_widget (gchar * str, GtkWidget * menu, int vab, gpointer data);
57
58#ifdef GTK3
67G_MODULE_EXPORT void set_axis_template_pos (GtkWidget * widg, gpointer data)
68{
69/* TOP_RIGHT = 0,
70 TOP_LEFT = 1,
71 BOTTOM_RIGHT = 2,
72 BOTTOM_LEFT = 3,
73 CENTER = 4 */
74 tint * the_data = (tint *)data;
75 project * this_proj = get_project_by_id(the_data -> a);
76 int i = this_proj -> modelgl -> anim -> last -> img -> axispos;
77 int j = the_data -> b;
78 if (gtk_check_menu_item_get_active ((GtkCheckMenuItem *)widg) && i != j)
79 {
80 this_proj -> modelgl -> anim -> last -> img -> axispos = NONE;
81 if (i != CUSTOM)
82 {
83 gtk_check_menu_item_set_active ((GtkCheckMenuItem *)this_proj -> modelgl -> ogl_box_axis[1][8+i], FALSE);
84 }
85 if (widg != this_proj -> modelgl -> ogl_box_axis[1][8+j])
86 {
87 gtk_check_menu_item_set_active ((GtkCheckMenuItem *)this_proj -> modelgl -> ogl_box_axis[1][8+j], TRUE);
88 }
89 this_proj -> modelgl -> anim -> last -> img -> axispos = j;
90 this_proj -> modelgl -> create_shaders[MAXIS] = TRUE;
91 update (this_proj -> modelgl);
92 }
93 else if (i == j && ! gtk_check_menu_item_get_active ((GtkCheckMenuItem *)widg))
94 {
95 if (i != CUSTOM)
96 {
97 gtk_check_menu_item_set_active ((GtkCheckMenuItem *)this_proj -> modelgl -> ogl_box_axis[1][8+i], TRUE);
98 }
99 }
100}
101
110GtkWidget * axis_position_submenu (glwin * view, int id)
111{
112 int i, j, k;
113 GtkWidget * menup = gtk_menu_new ();
114 GtkWidget * ud, * udm, * widg;
115 gchar * udlab[2] = {"Top", "Bottom"};
116 gchar * lrlab[2] = {"Right Corner", "Left Corner"};
117
118 i = 0;
119 for (j=0; j<2; j++)
120 {
121 ud = create_menu_item (FALSE, udlab[j]);
122 gtk_menu_shell_append ((GtkMenuShell *)menup, ud);
123 udm = gtk_menu_new ();
124 gtk_menu_item_set_submenu ((GtkMenuItem *)ud, udm);
125 for (k=0; k<2; k++)
126 {
127 if (id == 0)
128 {
129 view -> ogl_box_axis[1][8+i] = gtk3_menu_item (udm, lrlab[k], IMG_NONE, NULL, G_CALLBACK(set_axis_template_pos), & view -> colorp[i][0],
130 FALSE, 0, 0, TRUE, TRUE, (view -> anim -> last -> img -> axispos == i) ? TRUE: FALSE);
131 if (view -> anim -> last -> img -> box_axis[AXIS] == NONE) widget_set_sensitive (view -> ogl_box_axis[1][8+i], 0);
132 }
133 else
134 {
135 widg = gtk3_menu_item (udm, lrlab[k], IMG_NONE, NULL, G_CALLBACK(set_axis_template_pos), & view -> colorp[i][0],
136 FALSE, 0, 0, TRUE, TRUE, (view -> anim -> last -> img -> axispos == i) ? TRUE: FALSE);
137 if (view -> anim -> last -> img -> box_axis[AXIS] == NONE) widget_set_sensitive (widg, 0);
138 }
139 i += 1;
140 }
141 }
142 if (id == 0)
143 {
144 view -> ogl_box_axis[1][8+i] = gtk3_menu_item (menup, "Center", IMG_NONE, NULL, G_CALLBACK(set_axis_template_pos), & view -> colorp[i][0],
145 FALSE, 0, 0, TRUE, TRUE, (view -> anim -> last -> img -> axispos == i) ? TRUE: FALSE);
146 if (view -> anim -> last -> img -> box_axis[AXIS] == NONE) widget_set_sensitive (view -> ogl_box_axis[1][8+i], 0);
147 }
148 else
149 {
150 widg = gtk3_menu_item (menup, "Center", IMG_NONE, NULL, G_CALLBACK(set_axis_template_pos), & view -> colorp[i][0],
151 FALSE, 0, 0, TRUE, TRUE, (view -> anim -> last -> img -> axispos == i) ? TRUE: FALSE);
152 if (view -> anim -> last -> img -> box_axis[AXIS] == NONE) widget_set_sensitive (widg, 0);
153 }
154 return menup;
155}
156
166void menu_axis (GtkWidget * menu_ab, glwin * view, int id)
167{
168 GtkWidget * widg = create_menu_item (FALSE, "Length");
169 gtk_menu_shell_append ((GtkMenuShell *)menu_ab, widg);
170 GtkWidget * menul = gtk_menu_new ();
171 gtk_menu_item_set_submenu ((GtkMenuItem *)widg, menul);
172
173 gchar * str = g_strdup_printf (" Length [ %f Å ]", view -> anim -> last -> img -> axis_length);
174 if (id == 0)
175 {
176 view -> ogl_box_axis[1][7] = create_layout_widget (str, menul, view -> anim -> last -> img -> box_axis[AXIS], & view -> colorp[0][AXIS]);
177 if (view -> anim -> last -> img -> box_axis[AXIS] == NONE)
178 {
179 widget_set_sensitive (view -> ogl_box_axis[1][7], 0);
180 }
181 }
182 else
183 {
184 widg = create_layout_widget (str, menul, view -> anim -> last -> img -> box_axis[AXIS], & view -> colorp[0][AXIS]);
185 if (view -> anim -> last -> img -> box_axis[AXIS] == NONE)
186 {
187 widget_set_sensitive (widg, 0);
188 }
189 }
190 g_free (str);
191 gtk_menu_shell_append ((GtkMenuShell *)menu_ab, menu_item_new_with_submenu ("Position", TRUE, axis_position_submenu(view, id)));
192 add_advanced_item (menu_ab, G_CALLBACK(axis_advanced), (gpointer)view, FALSE, 0, 0);
193}
194#else
204G_MODULE_EXPORT void change_axis_pos_radio (GSimpleAction * action, GVariant * parameter, gpointer data)
205{
206 /* TOP_RIGHT = 0,
207 TOP_LEFT = 1,
208 BOTTOM_RIGHT = 2,
209 BOTTOM_LEFT = 3,
210 CENTER = 4 */
211 tint * the_data = (tint *)data;
212 glwin * view = get_project_by_id(the_data -> a) -> modelgl;
213 const gchar * pos = g_variant_get_string (parameter, NULL);
214 int lgt = strlen (pos);
215 gchar * name = g_strdup_printf ("%c%c", pos[lgt-2], pos[lgt-1]);
216 if (g_strcmp0(name, ".1") == 0)
217 {
218 g_free (name);
219 name = g_strdup_printf ("%.*s.0", lgt-2, pos);
220 g_action_group_activate_action ((GActionGroup *)view -> action_group, "set-axis-pos", g_variant_new_string((const gchar *)name));
221 g_free (name);
222 }
223 else
224 {
225 int i;
226 gchar * pos_name = NULL;
227 for (i=0; i<5; i++)
228 {
229 pos_name = g_strdup_printf ("set-axis-pos.%d.0", i);
230 if (g_strcmp0(pos, (const gchar *)pos_name) == 0)
231 {
232 view -> anim -> last -> img -> axispos = i;
233 g_free (pos_name);
234 pos_name = NULL;
235 break;
236 }
237 g_free (pos_name);
238 pos_name = NULL;
239 }
240 g_action_change_state (G_ACTION (action), parameter);
241 view -> create_shaders[MAXIS] = TRUE;
242 update (view);
243 g_action_change_state (G_ACTION (action), parameter);
244 }
245}
246
256GMenu * position_submenu (glwin * view, int popm, int pos)
257{
258 GMenu * menu = g_menu_new ();
259 gchar * lrlab[2] = {"Right Corner", "Left Corner"};
260 int i, j;
261 i = pos*2;
262 for (j=0; j<2; j++)
263 {
264 append_opengl_item (view, menu, lrlab[j], "axis-pos", popm, i, NULL, IMG_NONE, NULL, FALSE,
265 G_CALLBACK(change_axis_pos_radio), & view -> colorp[i][0],
266 FALSE, (view -> anim -> last -> img -> axispos == i) ? TRUE: FALSE, TRUE, TRUE);
267 i ++;
268 }
269 return menu;
270}
271
280GMenu * axis_position_submenu (glwin * view, int popm)
281{
282 int i;
283 GMenu * menu = g_menu_new ();
284 gchar * udlab[2] = {"Top", "Bottom"};
285 for (i=0; i<2; i++)
286 {
287 append_submenu (menu, udlab[i], position_submenu(view, popm, i));
288 }
289 append_opengl_item (view, menu, "Center", "axis-pos", popm, 4, NULL, IMG_NONE, NULL, FALSE,
290 G_CALLBACK(change_axis_pos_radio), & view -> colorp[4][0],
291 FALSE, (view -> anim -> last -> img -> axispos == 4) ? TRUE: FALSE, TRUE, TRUE);
292 return menu;
293}
294
304void menu_axis (GMenu * menu_ab, glwin * view, int popm)
305{
306 GMenuItem * item = g_menu_item_new ("Length", (view -> anim -> last -> img -> box_axis[AXIS]) != NONE ? NULL : "None");
307 g_menu_item_set_attribute (item, "custom", "s", "axis-length", NULL);
308 g_menu_item_set_submenu (item, (GMenuModel *)axis_box_param (view, popm, AXIS, NONE));
309 g_menu_append_item (menu_ab, item);
310 append_submenu (menu_ab, "Position", axis_position_submenu(view, popm));
311 append_opengl_item (view, menu_ab, "Advanced", "axis-advanced", popm, popm, NULL, IMG_STOCK, DPROPERTIES, FALSE,
312 G_CALLBACK(axis_advanced), (gpointer)view, FALSE, FALSE, FALSE, TRUE);
313}
314#endif
color colorp[64]
Global variable declarations Global convenience function declarations Global data structure defin...
@ IMG_NONE
Definition global.h:232
@ IMG_STOCK
Definition global.h:236
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)
void append_submenu(GMenu *menu, const gchar *label, GMenu *submenu)
append a GMenuItem with a subenu to a GMenu, and use markup for the GMenuItem
Definition gui.c:602
GtkWidget * add_advanced_item(GtkWidget *menu, GCallback handler, gpointer data, gboolean accel, guint key, GdkModifierType mod)
#define DPROPERTIES
Definition global.h:178
void widget_set_sensitive(GtkWidget *widg, gboolean sensitive)
Set sensitivity for a GtkWidget, ensuring it is a GtkWidget.
Definition gtk-misc.c:186
GtkWidget * create_menu_item(gboolean add_mnemo, gchar *action)
GtkWidget * menu_item_new_with_submenu(gchar *name, gboolean active, GtkWidget *sub_menu)
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...
@ CUSTOM
Definition glview.h:210
action
Definition glview.h:189
@ NONE
Definition glview.h:172
#define AXIS
Definition glwin.h:55
@ MAXIS
Definition glwin.h:94
Function declarations for the creation of the OpenGL window.
void append_opengl_item(glwin *view, GMenu *menu, const gchar *name, gchar *key, int mpop, int item_id, gchar *accel, int image_format, gpointer icon, gboolean custom, GCallback handler, gpointer data, gboolean check, gboolean status, gboolean radio, gboolean sensitive)
GMenu * position_submenu(glwin *view, int popm, int pos)
create elements of the 'Axis -> Position' submenu GTK4
Definition m_axis.c:256
GMenu * axis_position_submenu(glwin *view, int popm)
create the 'Axis -> Position' submenu GTK4
Definition m_axis.c:280
G_MODULE_EXPORT void axis_advanced(GtkWidget *widg, gpointer data)
create the axis advanced parameters window callback GTK3
Definition w_axis.c:497
GtkWidget * create_layout_widget(gchar *str, GtkWidget *menu, int vab, gpointer data)
G_MODULE_EXPORT void change_axis_pos_radio(GSimpleAction *action, GVariant *parameter, gpointer data)
handle change axis position signal GTK4
Definition m_axis.c:204
void menu_axis(GMenu *menu_ab, glwin *view, int popm)
create the 'Axis' submenu GTK4
Definition m_axis.c:304
GMenu * axis_box_param(glwin *view, int popm, int ab, int style)
create the box/axis '-> Length/Width/Radius' submenus GTK4
Definition m_box.c:435
Definition glwin.h:875
Definition global.h:98
Function declarations for the creation of the OpenGL window menus.
int b
Definition tab-1.c:95
int a
Definition tab-1.c:95
GtkWidget * img
Definition workspace.c:70