atomes 1.1.15
atomes: an atomic scale modeling tool box
Loading...
Searching...
No Matches
m_render.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_render.c'
24*
25* Contains:
26*
27
28 - The functions to create the 'OpenGL -> Render' submenu
29
30*
31* List of functions:
32
33 G_MODULE_EXPORT void set_render (GtkWidget * widg, gpointer data);
34 G_MODULE_EXPORT void change_render_radio (GSimpleAction * action, GVariant * parameter, gpointer data);
35
36 GtkWidget * menu_render (glwin * view, int id);
37
38 GMenu * menu_render (glwin * view, int popm);
39
40*/
41
42#include "global.h"
43#include "glview.h"
44#include "glwindow.h"
45
46gchar * text_renders[OGL_RENDERS] = {"Filled", "Lines", "Points"};
47
56G_MODULE_EXPORT void set_render (GtkWidget * widg, gpointer data)
57{
58 tint * the_data = (tint *)data;
59 project * this_proj = get_project_by_id(the_data -> a);
60 int i = this_proj -> modelgl -> anim -> last -> img -> render;
61 int j = the_data -> b;
62#ifdef GTK3
63 if (i != j && gtk_check_menu_item_get_active ((GtkCheckMenuItem *)widg))
64#else
65 if (i != j)
66#endif
67 {
68 this_proj -> modelgl -> anim -> last -> img -> render = NONE;
69#ifdef GTK3
70 gtk_check_menu_item_set_active ((GtkCheckMenuItem *)this_proj -> modelgl -> ogl_render[i], FALSE);
71 if (widg != this_proj -> modelgl -> ogl_render[j])
72 {
73 gtk_check_menu_item_set_active ((GtkCheckMenuItem *)this_proj -> modelgl -> ogl_render[j], TRUE);
74 }
75#endif
76 this_proj -> modelgl -> anim -> last -> img -> render = j;
77 this_proj -> modelgl -> create_shaders[MAXIS] = TRUE;
78 update (this_proj -> modelgl);
79 }
80#ifdef GTK3
81 else if (i == j && ! gtk_check_menu_item_get_active ((GtkCheckMenuItem *)widg))
82 {
83 gtk_check_menu_item_set_active ((GtkCheckMenuItem *)this_proj -> modelgl -> ogl_render[j], TRUE);
84 }
85#endif
86}
87
88#ifdef GTK3
97GtkWidget * menu_render (glwin * view, int id)
98{
99 int i, j;
100 GtkWidget * menur = gtk_menu_new ();
101 j = view -> anim -> last -> img -> render;
102 if (id == 0)
103 {
104 for (i=0; i<OGL_RENDERS; i++)
105 {
106 view -> ogl_render[i] = gtk3_menu_item (menur, text_renders[i], IMG_NONE, NULL, G_CALLBACK(set_render), & view -> colorp[i][0], FALSE, 0, 0, TRUE, TRUE, (i == j) ? TRUE : FALSE);
107 widget_set_sensitive (view -> ogl_render[i], 0);
108 if (view -> anim -> last -> img -> style != WIREFRAME)
109 {
110 widget_set_sensitive (view -> ogl_render[i], 1);
111 }
112 }
113 }
114 else
115 {
116 GtkWidget * widg;
117 for (i=0; i<OGL_RENDERS; i++)
118 {
119 widg = gtk3_menu_item (menur, text_renders[i], IMG_NONE, NULL, G_CALLBACK(set_render), & view -> colorp[i][0], FALSE, 0, 0, TRUE, TRUE, (i == j) ? TRUE : FALSE);
120 widget_set_sensitive (widg, 0);
121 if (view -> anim -> last -> img -> style != WIREFRAME)
122 {
123 widget_set_sensitive (widg, 1);
124 }
125 }
126 }
127 return menur;
128}
129#else
130
140G_MODULE_EXPORT void change_render_radio (GSimpleAction * action, GVariant * parameter, gpointer data)
141{
142 glwin * view = (glwin *)data;
143 const gchar * render = g_variant_get_string (parameter, NULL);
144 int lgt = strlen (render);
145 gchar * name = g_strdup_printf ("%c%c", render[lgt-2], render[lgt-1]);
146 if (g_strcmp0(name, ".1") == 0)
147 {
148 g_free (name);
149 name = g_strdup_printf ("%.*s.0", lgt-2, render);
150 g_action_group_activate_action ((GActionGroup *)view -> action_group, "set-render", g_variant_new_string((const gchar *)name));
151 g_free (name);
152 }
153 else
154 {
155 gchar * render_name = NULL;
156 int i;
157 for (i=0; i<OGL_RENDERS*2; i++)
158 {
159 render_name = g_strdup_printf ("set-render.%d.0", i);
160 if (g_strcmp0(render, (const gchar *)render_name) == 0)
161 {
162 set_render (NULL, & view -> colorp[i][0]);
163 g_free (render_name);
164 render_name = NULL;
165 break;
166 }
167 g_free (render_name);
168 render_name = NULL;
169 }
170 g_action_change_state (G_ACTION (action), parameter);
171 }
172}
173
182GMenu * menu_render (glwin * view, int popm)
183{
184 int i;
185 GMenu * menu = g_menu_new ();
186 // gboolean sensitive = (view -> anim -> last -> img -> style == WIREFRAME || view -> anim -> last -> img -> style == PUNT) ? FALSE : TRUE;
187 for (i=0; i<OGL_RENDERS; i++)
188 {
189 append_opengl_item (view, menu, text_renders[i], "render", popm, i,
190 NULL, IMG_NONE, NULL,
191 FALSE, G_CALLBACK(change_render_radio), (gpointer)view,
192 FALSE, (view -> anim -> last -> img -> render == i) ? TRUE : FALSE, TRUE, TRUE);
193
194 }
195 return menu;
196}
197#endif
color colorp[64]
Global variable declarations Global convenience function declarations Global data structure defin...
@ IMG_NONE
Definition global.h:260
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 widget_set_sensitive(GtkWidget *widg, gboolean sensitive)
Set sensitivity for a GtkWidget, ensuring it is a GtkWidget.
Definition gtk-misc.c:206
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...
action
Definition glview.h:189
render
Definition glview.h:182
@ WIREFRAME
Definition glview.h:174
@ NONE
Definition glview.h:172
#define OGL_RENDERS
Definition glwin.h:57
@ 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)
G_MODULE_EXPORT void change_render_radio(GSimpleAction *action, GVariant *parameter, gpointer data)
set OpenGL rendering mode callback GTK4
Definition m_render.c:140
G_MODULE_EXPORT void set_render(GtkWidget *widg, gpointer data)
set OpenGL rendering mode callback
Definition m_render.c:56
gchar * text_renders[OGL_RENDERS]
Definition m_render.c:46
GMenu * menu_render(glwin *view, int popm)
create the 'OpenGL -> Render' submenu - GTK4
Definition m_render.c:182
Definition glwin.h:875
Definition global.h:104
int b
Definition tab-1.c:95
int a
Definition tab-1.c:95
GtkWidget * img
Definition workspace.c:70