atomes 1.1.15
atomes: an atomic scale modeling tool box
Loading...
Searching...
No Matches
w_spiner.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_spiner.c'
24*
25* Contains:
26*
27
28 - The functions to create the 'Spin' window
29
30*
31* List of functions:
32
33 gboolean spin (gpointer data);
34
35 static gboolean spin_wait_for_stop (gpointer data);
36
37 G_MODULE_EXPORT void spin_go (GtkButton * but, gpointer data);
38 G_MODULE_EXPORT void spin_stop (GtkButton * but, gpointer data);
39 G_MODULE_EXPORT void window_spinner (GtkWidget * widg, gpointer data);
40
41*/
42
43#include "global.h"
44#include "glview.h"
45
46extern void save_rotation_quaternion (glwin * view);
47extern void rotate_x_y (glwin * view, double angle_x, double angle_y);
48
56gboolean spin (gpointer data)
57{
58 tint * val = (tint *) data;
59 project * this_proj = get_project_by_id(val -> a);
60#ifdef DEBUG
61// g_debug (":: SPIN:: a= %d, c= %d", val -> a, val -> c);
62// g_debug (":: SPIN:: speed[c]= %d", this_proj -> modelgl -> spin_speed[val -> c]);
63#endif
64 if (this_proj -> modelgl -> spin[val -> c])
65 {
66 save_rotation_quaternion (this_proj -> modelgl);
67 double cameraAngle[2] = {0.0, 0.0};
68 cameraAngle[val -> c] = 0.1 * this_proj -> modelgl -> spin_speed[val -> c];
69 rotate_x_y (this_proj -> modelgl, cameraAngle[0], cameraAngle[1]);
70 update (this_proj -> modelgl);
71 return TRUE;
72 }
73 else
74 {
75 return FALSE;
76 }
77}
78
86static gboolean spin_wait_for_stop (gpointer data)
87{
88 tint * val = (tint *) data;
89 if (get_project_by_id(val -> a) -> modelgl -> spin[val -> c])
90 {
91 return TRUE;
92 }
93 else
94 {
95 return FALSE;
96 }
97}
98
107G_MODULE_EXPORT void spin_go (GtkButton * but, gpointer data)
108{
109 tint * val = (tint *) data;
110 glwin * view = get_project_by_id(val -> a) -> modelgl;
111
112 int s = val -> b - 2;
113#ifdef DEBUG
114// g_debug (":: SPIN_GO:: a= %d, b= %d, c= %d, d=%d", val -> a, val -> b, val -> c, s);
115// g_debug (":: SPIN_GO:: speed[b]= %d", view -> spin_speed[val -> c]);
116#endif
117 view -> spin_speed[val -> c] += s;
118 if (view -> spin_speed[val -> c] == 0)
119 {
120 view -> spin[val -> c] = FALSE;
121 g_timeout_add (REFRESH, (GSourceFunc) spin_wait_for_stop, data);
122 }
123 else if (! view -> spin[val -> c])
124 {
125 view -> spin[val -> c] = TRUE;
126 g_timeout_add (REFRESH, (GSourceFunc) spin, data);
127 }
128}
129
138G_MODULE_EXPORT void spin_stop (GtkButton * but, gpointer data)
139{
140 glwin * view = (glwin *) data;
141 int i;
142 for (i=0; i<2; i++)
143 {
144 view -> spin[i] = FALSE;
145 view -> spin_speed[i] = 0;
146 }
147 //set_sensitive_coord_menu (view, TRUE);
148}
149
158G_MODULE_EXPORT void window_spinner (GtkWidget * widg, gpointer data)
159{
160 glwin * view = (glwin *) data;
161 if (view -> spiner == NULL)
162 {
163 view -> spiner = g_malloc0 (sizeof*view -> spiner);
164 gchar * str = g_strdup_printf ("%s - spin", prepare_for_title(get_project_by_id(view -> proj) -> name));
165 view -> spiner -> win = create_win (str, view -> win, FALSE, FALSE);
166 g_free (str);
167 GtkWidget * table = gtk_grid_new ();
168 add_container_child (CONTAINER_WIN, view -> spiner -> win, table);
169 view -> spiner -> right = create_button ("Right", IMG_STOCK, GO_RIGHT, -1, -1, GTK_RELIEF_NONE, G_CALLBACK(spin_go), & view -> colorp[1][1]);
170 view -> spiner -> left = create_button ("Left", IMG_STOCK, GO_LEFT, -1, -1, GTK_RELIEF_NONE, G_CALLBACK(spin_go), & view -> colorp[3][1]);
171 view -> spiner -> stop = create_button ("Stop", IMG_STOCK, MEDIA_STOP, -1, -1, GTK_RELIEF_NONE, G_CALLBACK(spin_stop), view);
172 view -> spiner -> up = create_button ("Up", IMG_STOCK, GO_UP, -1, -1, GTK_RELIEF_NONE, G_CALLBACK(spin_go), & view -> colorp[3][0]);
173 view -> spiner -> down = create_button ("Down", IMG_STOCK, GO_DOWN, -1, -1, GTK_RELIEF_NONE, G_CALLBACK(spin_go), & view -> colorp[1][0]);
174 gtk_grid_attach (GTK_GRID (table), view -> spiner -> right, 2,1,1,1);
175 gtk_grid_attach (GTK_GRID (table), view -> spiner -> left, 0,1,1,1);
176 gtk_grid_attach (GTK_GRID (table), view -> spiner -> stop, 1,1,1,1);
177 gtk_grid_attach (GTK_GRID (table), view -> spiner -> up, 1,0,1,1);
178 gtk_grid_attach (GTK_GRID (table), view -> spiner -> down, 1,2,1,1);
179 add_gtk_close_event (view -> spiner -> win, G_CALLBACK(hide_this_window), NULL);
180 show_the_widgets (view -> spiner -> win);
181 gtk_window_set_resizable (GTK_WINDOW(view -> spiner -> win), FALSE);
182 }
183 else
184 {
185 show_the_widgets (view -> spiner -> win);
186 }
187}
color colorp[64]
float val
Definition dlp_init.c:117
dint up
Global variable declarations Global convenience function declarations Global data structure defin...
@ IMG_STOCK
Definition global.h:264
#define GO_RIGHT
Definition global.h:193
GtkWidget * create_win(gchar *str, GtkWidget *parent, gboolean modal, gboolean resiz)
create a new GtkWindow
Definition gtk-misc.c:445
project * proj
G_MODULE_EXPORT gboolean hide_this_window(GtkWidget *win, GdkEvent *event, gpointer data)
hide a GtkWindow
Definition gtk-misc.c:2371
void add_gtk_close_event(GtkWidget *widg, GCallback handler, gpointer data)
add a close event signal and callback to a GtkWidget
Definition gtk-misc.c:2387
@ CONTAINER_WIN
Definition global.h:250
#define GO_LEFT
Definition global.h:194
GtkWidget * create_button(gchar *text, int image_format, gchar *image, int dimx, int dimy, int relief, GCallback handler, gpointer data)
create a simple button
Definition gtk-misc.c:1863
#define GO_DOWN
Definition global.h:196
gchar * prepare_for_title(gchar *init)
prepare a string for a window title, getting rid of all markup
Definition tools.c:71
void add_container_child(int type, GtkWidget *widg, GtkWidget *child)
Add a GtkWidget into another GtkWidget.
Definition gtk-misc.c:226
#define GO_UP
Definition global.h:195
#define MEDIA_STOP
Definition global.h:188
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...
#define REFRESH
Refresh time for spinning the OpenGL window in milliseconds.
Definition glview.h:130
Definition glwin.h:875
Definition global.h:104
int b
Definition tab-1.c:95
int c
Definition tab-1.c:95
int a
Definition tab-1.c:95
G_MODULE_EXPORT void spin_go(GtkButton *but, gpointer data)
start spin
Definition w_spiner.c:107
void save_rotation_quaternion(glwin *view)
save the rotation quaternion of the last image
Definition glview.c:543
G_MODULE_EXPORT void window_spinner(GtkWidget *widg, gpointer data)
create the spin window callback
Definition w_spiner.c:158
gboolean spin(gpointer data)
spin
Definition w_spiner.c:56
void rotate_x_y(glwin *view, double angle_x, double angle_y)
rotate the OpenGL camera
Definition glview.c:1081
G_MODULE_EXPORT void spin_stop(GtkButton *but, gpointer data)
stop spin
Definition w_spiner.c:138