Cleanup and added events

This commit is contained in:
Adrien Bourmault 2023-01-26 01:38:51 +01:00
parent 3c762e71b8
commit 8aae05fefc
No known key found for this signature in database
GPG Key ID: 6EB408FE0ACEC664
3 changed files with 139 additions and 112 deletions

View File

@ -58,6 +58,10 @@ GemGraphClientApplication *gem_graph_client_application_new(const char *applicat
G_END_DECLS G_END_DECLS
void ui_enable_action(const char *name);
void ui_disable_action(const char *name);
// //
// Actions // Actions
// //
@ -120,10 +124,6 @@ static const GActionEntry app_actions[] = {
{ "toastclose", on_toast_close_action, NULL, NULL, NULL }, { "toastclose", on_toast_close_action, NULL, NULL, NULL },
}; };
void ui_enable_action(const char *name);
void ui_disable_action(const char *name);
// //
// Actions responses // Actions responses
// //
@ -135,6 +135,19 @@ void on_openfile_response_complete(GObject *source_object,
GAsyncResult *result, GAsyncResult *result,
GemGraphClientWindow *self); GemGraphClientWindow *self);
//
// General events
//
void on_axis_value_change(GtkAdjustment *adjustment, gpointer data);
gboolean on_render(GtkGLArea * area, GdkGLContext * context);
void on_realize(GtkWidget *widget);
void on_unrealize(GtkWidget *widget);
void on_close_window(GtkWidget *widget);
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
// //
@ -146,4 +159,5 @@ void ui_set_stack(const char *mode);
void ui_send_notification(const char *message); void ui_send_notification(const char *message);
void ui_send_internal_notification(const char *message); void ui_send_internal_notification(const char *message);
void ui_close_internal_notification(void); void ui_close_internal_notification(void);
void ui_toggle_sidebar();
void ui_setup_glarea(); void ui_setup_glarea();

View File

@ -81,7 +81,7 @@ void on_togglesidebar_action(GSimpleAction *action,
g_assert(GEM_GRAPH_CLIENT_IS_APPLICATION(self)); g_assert(GEM_GRAPH_CLIENT_IS_APPLICATION(self));
ui_send_internal_notification("Not implemented !"); ui_toggle_sidebar();
} }
void on_editmode_action(GSimpleAction *action, void on_editmode_action(GSimpleAction *action,
@ -184,6 +184,68 @@ void on_toast_close_action(GSimpleAction *action,
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
/*
* General events
*/
void on_axis_value_change(GtkAdjustment *adjustment, gpointer data)
{
int axis = GPOINTER_TO_INT(data);
g_assert(axis >= 0 && axis < N_AXIS);
/* Update the rotation angle */
rotation_angles[axis] = gtk_adjustment_get_value(adjustment);
/* Update the contents of the GL drawing area */
gtk_widget_queue_draw(gl_area);
}
gboolean on_render(GtkGLArea * area, GdkGLContext * context)
{
if(gtk_gl_area_get_error(area) != NULL)
return FALSE;
graphics_draw();
return TRUE;
}
/* We need to set up our state when we realize the GtkGLArea widget */
void on_realize(GtkWidget *widget)
{
gtk_gl_area_make_current(GTK_GL_AREA(widget));
if(gtk_gl_area_get_error(GTK_GL_AREA(widget)) != NULL)
return;
graphics_init();
}
/* We should tear down the state when unrealizing */
void on_unrealize(GtkWidget *widget)
{
gtk_gl_area_make_current(GTK_GL_AREA(widget));
if(gtk_gl_area_get_error(GTK_GL_AREA(widget)) != NULL)
return;
graphics_shutdown();
}
void on_close_window(GtkWidget *widget)
{
/* Reset the state */
gl_area = NULL;
rotation_angles[X_AXIS] = 0.0;
rotation_angles[Y_AXIS] = 0.0;
rotation_angles[Z_AXIS] = 0.0;
}
/* -------------------------------------------------------------------------- */
/* /*
* Responses * Responses
*/ */

View File

@ -40,111 +40,6 @@ static GemGraphClientWindow *window;
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
static void on_axis_value_change(GtkAdjustment *adjustment, gpointer data);
static inline GtkWidget *create_axis_slider(int axis)
{
GtkWidget *box, *label, *slider;
GtkAdjustment *adj;
const char *text;
box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
switch (axis) {
case X_AXIS:
text = "X";
break;
case Y_AXIS:
text = "Y";
break;
case Z_AXIS:
text = "Z";
break;
default:
g_assert_not_reached();
}
label = gtk_label_new(text);
gtk_box_append(GTK_BOX(box), label);
gtk_widget_show(label);
adj = gtk_adjustment_new(0.0, 0.0, 360.0, 1.0, 12.0, 0.0);
g_signal_connect(adj, "value-changed",
G_CALLBACK(on_axis_value_change),
GINT_TO_POINTER(axis));
slider = gtk_scale_new(GTK_ORIENTATION_HORIZONTAL, adj);
gtk_box_append(GTK_BOX(box), slider);
gtk_widget_set_hexpand(slider, TRUE);
gtk_widget_show(slider);
gtk_widget_show(box);
return box;
}
/* -------------------------------------------------------------------------- */
static void on_axis_value_change(GtkAdjustment *adjustment, gpointer data)
{
int axis = GPOINTER_TO_INT(data);
g_assert(axis >= 0 && axis < N_AXIS);
/* Update the rotation angle */
rotation_angles[axis] = gtk_adjustment_get_value(adjustment);
/* Update the contents of the GL drawing area */
gtk_widget_queue_draw(gl_area);
}
static gboolean on_render(GtkGLArea * area, GdkGLContext * context)
{
if(gtk_gl_area_get_error(area) != NULL)
return FALSE;
graphics_draw();
return TRUE;
}
/* We need to set up our state when we realize the GtkGLArea widget */
static void on_realize(GtkWidget *widget)
{
gtk_gl_area_make_current(GTK_GL_AREA(widget));
if(gtk_gl_area_get_error(GTK_GL_AREA(widget)) != NULL)
return;
graphics_init();
}
/* We should tear down the state when unrealizing */
static void on_unrealize(GtkWidget *widget)
{
gtk_gl_area_make_current(GTK_GL_AREA(widget));
if(gtk_gl_area_get_error(GTK_GL_AREA(widget)) != NULL)
return;
graphics_shutdown();
}
static void on_close_window(GtkWidget *widget)
{
/* Reset the state */
gl_area = NULL;
rotation_angles[X_AXIS] = 0.0;
rotation_angles[Y_AXIS] = 0.0;
rotation_angles[Z_AXIS] = 0.0;
}
/* -------------------------------------------------------------------------- */
struct _GemGraphClientWindow struct _GemGraphClientWindow
{ {
GtkApplicationWindow parent_instance; GtkApplicationWindow parent_instance;
@ -223,6 +118,10 @@ static void gem_graph_client_window_init(GemGraphClientWindow *self)
window = self; window = self;
// Launch with sidebar off
ui_toggle_sidebar();
// Setup GLArea
ui_setup_glarea(); ui_setup_glarea();
} }
@ -300,12 +199,53 @@ void ui_close_internal_notification(void)
gtk_revealer_set_reveal_child(window->toast_revealer, false); gtk_revealer_set_reveal_child(window->toast_revealer, false);
} }
static inline GtkWidget *create_axis_slider(int axis)
{
GtkWidget *box, *label, *slider;
GtkAdjustment *adj;
const char *text;
box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
switch (axis) {
case X_AXIS:
text = "X";
break;
case Y_AXIS:
text = "Y";
break;
case Z_AXIS:
text = "Z";
break;
default:
g_assert_not_reached();
}
label = gtk_label_new(text);
gtk_box_append(GTK_BOX(box), label);
gtk_widget_show(label);
adj = gtk_adjustment_new(0.0, 0.0, 360.0, 1.0, 12.0, 0.0);
g_signal_connect(adj, "value-changed",
G_CALLBACK(on_axis_value_change),
GINT_TO_POINTER(axis));
slider = gtk_scale_new(GTK_ORIENTATION_HORIZONTAL, adj);
gtk_box_append(GTK_BOX(box), slider);
gtk_widget_set_hexpand(slider, TRUE);
gtk_widget_show(slider);
gtk_widget_show(box);
return box;
}
void ui_setup_glarea() void ui_setup_glarea()
{ {
int i, minor=4, major=0; int i, minor=4, major=0;
GtkWidget * controls; GtkWidget * controls;
gint height;
gint width;
gl_area = GTK_WIDGET(window->run_glarea); gl_area = GTK_WIDGET(window->run_glarea);
controls = GTK_WIDGET(window->run_controls); controls = GTK_WIDGET(window->run_controls);
@ -337,3 +277,14 @@ void ui_setup_glarea()
gtk_gl_area_get_required_version( GTK_GL_AREA(gl_area), &minor, &major); gtk_gl_area_get_required_version( GTK_GL_AREA(gl_area), &minor, &major);
} }
void ui_toggle_sidebar(void)
{
int position = gtk_paned_get_position(window->main_paned);
if (position != 0) {
gtk_paned_set_position(window->main_paned, 0);
} else {
gtk_paned_set_position(window->main_paned, 300);
}
}