From 53c2fd920978381a7ffc10fefb28024ab457fe9a Mon Sep 17 00:00:00 2001 From: Adrien 'neox' Bourmault Date: Wed, 10 Jan 2024 18:27:46 +0100 Subject: [PATCH] src/graphics, src/ui: now capable of generating multiple GLArea and their stack --- src/graphics/arrows.c | 2 -- src/graphics/draw.c | 16 ++++++++-------- src/graphics/graphics.c | 4 +++- src/ui/graphics.c | 14 +++++++------- src/ui/window.c | 30 ++++++++++++------------------ 5 files changed, 30 insertions(+), 36 deletions(-) diff --git a/src/graphics/arrows.c b/src/graphics/arrows.c index 9e0336c..56b0e5f 100644 --- a/src/graphics/arrows.c +++ b/src/graphics/arrows.c @@ -43,8 +43,6 @@ int draw_one_arrow_vertex (const int stack_id, int arrow_y, int arrow_z) { - struct graphic_stack_t *stack = &graphic_stack[stack_id]; - float max = fmax(space_X_int, space_Y_int); max = fmax(max, space_Z_int); diff --git a/src/graphics/draw.c b/src/graphics/draw.c index c596e90..8bc262b 100644 --- a/src/graphics/draw.c +++ b/src/graphics/draw.c @@ -41,20 +41,20 @@ void graphics_draw_vertex (const int stack_id, GLfloat y, GLfloat z) { - //g_printerr("stack_id is %d\n", stack_id); - //g_printerr("stack_id is %d\n", stack_id); - //g_printerr("graphic_stack is at %p\n", graphic_stack); - //g_printerr("graphic_stack[stack_id] is at %p\n", graphic_stack + stack_id); - struct graphic_stack_t *stack = &graphic_stack[stack_id]; + g_printerr("stack_id is %d\n", stack_id); + g_printerr("stack_id is %d\n", stack_id); + g_printerr("graphic_stack is at %p\n", graphic_stack); + g_printerr("graphic_stack[stack_id] is at %p\n", graphic_stack + stack_id); + volatile struct graphic_stack_t *stack = &graphic_stack[stack_id]; + + g_printerr("Currently stack->buffer_vertex_origin @ %p\n", stack->buffer_vertex_origin); //assert (stack->buffer_vertex_origin); - //g_printerr("Currently stack->buffer_vertex_origin @ %p\n", stack->buffer_vertex_origin); - stack->buffer_vertex_origin = g_realloc (stack->buffer_vertex_origin, (stack->buffer_vertex_size + 3) * sizeof(GLfloat)); - //print_stack(stack_id); + print_stack(stack_id); stack->buffer_vertex_origin[stack->buffer_vertex_size + 0] = x; stack->buffer_vertex_origin[stack->buffer_vertex_size + 1] = y; diff --git a/src/graphics/graphics.c b/src/graphics/graphics.c index 921c85c..14a1dbc 100644 --- a/src/graphics/graphics.c +++ b/src/graphics/graphics.c @@ -132,6 +132,8 @@ int graphics_init(void *error_buffer) } } + memset(&graphic_stack[cur_id], 0, sizeof(struct graphic_stack_t)); + /* g_printerr("[debug] graphics_init() : graphic_stack (@0x%p) has %ld elements\n", */ /* graphic_stack, */ /* graphic_stack_size); */ @@ -152,7 +154,7 @@ int graphics_init(void *error_buffer) glDebugMessageCallback(graphics_debug_callback, NULL); - //print_stack(cur_id); + print_stack(cur_id); return cur_id; } diff --git a/src/ui/graphics.c b/src/ui/graphics.c index ec37f17..091e704 100644 --- a/src/ui/graphics.c +++ b/src/ui/graphics.c @@ -84,19 +84,19 @@ long ui_is_graphic_stack_ready(void *container_widget) */ bool ui_init_graphic_stack(void *container_widget, GError *error_buffer) { - //g_printerr("[debug] ui_init_graphic_stack()\n"); + g_printerr("[debug] ui_init_graphic_stack()\n"); - //g_printerr("[debug] ui_init_graphic_stack() : target is %p\n", container_widget); + g_printerr("[debug] ui_init_graphic_stack() : target is %p\n", container_widget); // look for stack_index entry for (int i = 0; i < stack_index_size; i++) { - //g_printerr("[debug] ui_init_graphic_stack() : i is %d\n", i); - //g_printerr("[debug] ui_init_graphic_stack() : target would be %p\n", - //stack_index[i].container_widget); + g_printerr("[debug] ui_init_graphic_stack() : i is %d\n", i); + g_printerr("[debug] ui_init_graphic_stack() : target would be %p\n", + stack_index[i].container_widget); if (stack_index[i].container_widget == (void *)container_widget) { stack_index[i].stack_id = graphics_init(&error_buffer); - //g_printerr("[debug] ui_init_graphic_stack() : stack_id is %d\n", - //stack_index[i].stack_id); + g_printerr("[debug] ui_init_graphic_stack() : stack_id is %d\n", + stack_index[i].stack_id); if (stack_index[i].stack_id >= 0) return true; else diff --git a/src/ui/window.c b/src/ui/window.c index a8bfe0b..a7ed883 100644 --- a/src/ui/window.c +++ b/src/ui/window.c @@ -51,6 +51,8 @@ struct _GemGraphClientWindow GtkLabel *toast_text; GtkBox *control_zone; GtkBox *run_glarea_box; + GtkBox *edition_glarea_box; + GtkBox *presentation_glarea_box; }; G_DEFINE_FINAL_TYPE (GemGraphClientWindow, @@ -105,6 +107,12 @@ static void gem_graph_client_window_class_init(GemGraphClientWindowClass *klass) gtk_widget_class_bind_template_child(widget_class, GemGraphClientWindow, run_glarea_box); + gtk_widget_class_bind_template_child(widget_class, + GemGraphClientWindow, + edition_glarea_box); + gtk_widget_class_bind_template_child(widget_class, + GemGraphClientWindow, + presentation_glarea_box); } static void gem_graph_client_window_init(GemGraphClientWindow *self) @@ -120,7 +128,7 @@ static void gem_graph_client_window_init(GemGraphClientWindow *self) void ui_set_stack(int mode) { - g_printerr("[debug] ui_set_stack()\n"); + //g_printerr("[debug] ui_set_stack()\n"); if (window->main_stack == NULL) { g_printerr("Can't find self->main_stack !\n"); @@ -142,6 +150,7 @@ void ui_set_stack(int mode) GTK_STACK_TRANSITION_TYPE_CROSSFADE); gtk_menu_button_set_icon_name(window->main_button_mode, "document-edit-symbolic"); + ui_setup_glarea(EDIT_MODE, GTK_WIDGET(window->edition_glarea_box)); break; case RUN_MODE: gtk_stack_set_visible_child_full(window->main_stack, @@ -163,6 +172,8 @@ void ui_set_stack(int mode) GTK_STACK_TRANSITION_TYPE_CROSSFADE); gtk_menu_button_set_icon_name(window->main_button_mode, "x-office-presentation-symbolic"); + ui_setup_glarea(PRESENTATION_MODE, + GTK_WIDGET(window->presentation_glarea_box)); break; case HOME_MODE: gtk_stack_set_visible_child_full(window->main_stack, @@ -223,20 +234,3 @@ void ui_toggle_sidebar(void) gtk_paned_set_position(window->main_paned, 400); } } - -void ui_run_attach_glarea(GtkWidget *glarea) -{ - gtk_box_append(window->run_glarea_box, glarea); - gtk_widget_show(glarea); -} - -void ui_run_detach_glarea(GtkWidget *glarea) -{ - gtk_box_remove(window->run_glarea_box, glarea); -} - -void ui_attach_controls(GtkWidget *controls) -{ - gtk_box_append(window->control_zone, controls); - gtk_widget_show(controls); -}