From 77dbdaac0c4fc06cc80628629f17a8a0f6281029 Mon Sep 17 00:00:00 2001 From: Adrien 'neox' Bourmault Date: Tue, 10 Sep 2024 13:25:47 +0200 Subject: [PATCH] src/*: fix missing functions to generate GLArea The new UI prototype did not bring functions to generate a GLArea at the correct location in the code tree. This commit fixes this. Signed-off-by: Adrien 'neox' Bourmault --- include/util.h | 85 +++++++++++++++++++++++++++++++++++++++ src/signal.c | 9 +++-- src/util/draw/gl.c | 2 +- src/widget/state/middle.c | 3 +- 4 files changed, 93 insertions(+), 6 deletions(-) diff --git a/include/util.h b/include/util.h index 277407a..0efd61a 100644 --- a/include/util.h +++ b/include/util.h @@ -82,3 +82,88 @@ void util_pile_test(); // called in fsm/measure.c void util_double_list_test(); // " " void util_sorted_list_test(); // " " +//------------------------------------------------------------------------------ + +/* + * Look for stack entry and returns stack_id + * + * @params container_widget, generally the GtkBox that contains the GLArea + * + * @returns stack_id + */ +long util_gl_get_stack(void *container_widget); + +/* + * Look for stack entry and returns stack_id + * + * @params container_widget, generally the GtkBox that contains the GLArea + * + * @returns stack_id + */ +long util_gl_is_util_ready(void *container_widget); + +/* + * Look for stack entry and initializes OpenGL for it + * + * @params container_widget, generally the GtkBox that contains the GLArea + * + * @returns bool, true if success + */ +bool util_gl_init_stack(void *container_widget, GError *error_buffer); + +/* + * Look for stack entry and shutdowns OpenGL for it + * + * @params container_widget, generally the GtkBox that contains the GLArea + * + * @returns bool, true if success + */ +bool util_gl_shutdown_stack(void *container_widget, GError *error_buffer); + +void util_gl_clean_stack_index(void); + +/* + * Look for stack entry and triggers OpenGL for drawing + * + * @params container_widget, generally the GtkBox that contains the GLArea + * + * @returns bool, true if success + */ +bool util_gl_render_stack(GtkWidget *container_widget); + +/* + * Look for stack entry and triggers OpenGL for drawing + * + * @params container_widget, generally the GtkBox that contains the GLArea + * + * @returns bool, true if success + */ +bool util_gl_update_axis(GtkWidget *container_widget, int axis, int value); + +/* + * Look for every stack entry and shutdowns OpenGL for it + * + * @params void + * + * @returns bool, true if success + */ +void util_gl_shutdown_all_stacks(void); + +/* + * Creates a slider widget + * + * @params axis, meaning which axis we're building (for label) + * + * @returns GtkWidget*, pointer to the new widget + */ +GtkWidget *create_axis_slider(int axis); + +/* + * Creates GLArea and indexes it + * + * @params target_mode, meaning which util_gl_stack we're on + * target_widget, meaning the box that will host the GLArea + * + * @returns bool, true if success + */ +bool util_gl_setup_glarea(int target_mode, GtkWidget *target_widget); \ No newline at end of file diff --git a/src/signal.c b/src/signal.c index 744830e..856d2ed 100644 --- a/src/signal.c +++ b/src/signal.c @@ -31,6 +31,7 @@ #include "../include/signal.h" #include "../include/widget.h" #include "../include/graphics.h" +#include "../include/util.h" static void on_auto_notification (const char *message) @@ -114,7 +115,7 @@ gboolean on_glarea_render(GtkGLArea *area, return false; } - if (graphics_render_stack(gtk_widget_get_parent(GTK_WIDGET(area))) == false) { + if (util_gl_render_stack(gtk_widget_get_parent(GTK_WIDGET(area))) == false) { on_auto_notification("Failed to render corresponding graphic stack !"); return false; } @@ -138,7 +139,7 @@ void on_glarea_realize(GtkWidget *widget) } // Link graphical stack to widget - if (graphics_init_graphics_stack(gtk_widget_get_parent(widget), + if (util_gl_init_stack(gtk_widget_get_parent(widget), internal_error) == false) { on_auto_notification( "Failed to link the graphic stack to widgets !"); @@ -163,7 +164,7 @@ void on_glarea_unrealize(GtkWidget *widget) } // Destroy graphic stack - if (graphics_shutdown_graphics_stack(gtk_widget_get_parent(widget), + if (util_gl_shutdown_stack(gtk_widget_get_parent(widget), internal_error) == false) { on_auto_notification( "Failed to shutdown the graphic stack !"); @@ -185,7 +186,7 @@ void on_axis_value_change(GtkAdjustment *adjustment, gpointer data) g_assert(axis >= 0 && axis < N_AXIS); /* Update the rotation angle */ - graphics_update_axis_stack(container_widget, + util_gl_update_axis(container_widget, axis, gtk_adjustment_get_value(adjustment)); diff --git a/src/util/draw/gl.c b/src/util/draw/gl.c index 5a96c44..1860fde 100644 --- a/src/util/draw/gl.c +++ b/src/util/draw/gl.c @@ -81,7 +81,7 @@ long util_gl_get_stack(void *container_widget) * * @returns stack_id */ -long util_gl_is_util_ready(void *container_widget) +long util_gl_is_ready(void *container_widget) { // look for stack_index entry for (int i = 0; i < stack_index_size; i++) { diff --git a/src/widget/state/middle.c b/src/widget/state/middle.c index c9a7ecb..4a632e4 100644 --- a/src/widget/state/middle.c +++ b/src/widget/state/middle.c @@ -27,6 +27,7 @@ #include "../../../include/fsm.h" #include "../../../include/widget.h" #include "../../../include/signal.h" +#include "../../../include/util.h" static GtkAdjustment *X_adjust; static GtkAdjustment *Y_adjust; @@ -89,7 +90,7 @@ static void *get_ZOOM_box() void *widget_get_space_view(int partition_space_vs_camera) { GtkBox *drawbox = GTK_BOX (gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0)); - ui_setup_glarea (GTK_BOX (drawbox)); + util_gl_setup_glarea (0, GTK_WIDGET (drawbox)); GtkBox *camera = GTK_BOX (gtk_box_new (GTK_ORIENTATION_VERTICAL, 2)); gtk_box_append (camera, GTK_WIDGET (get_XYZ_box()));