From 64fa82a74185e4cabc91a477e85b9d0ee1a31155 Mon Sep 17 00:00:00 2001 From: Adrien Bourmault Date: Thu, 26 Jan 2023 01:07:07 +0100 Subject: [PATCH] GLArea dans la place --- include/ui.h | 1 + src/graphics/graphics.c | 3 +- src/ui/gemgraph.ui | 14 ++++-- src/ui/window.c | 98 ++++++++++++++++++++--------------------- 4 files changed, 61 insertions(+), 55 deletions(-) diff --git a/include/ui.h b/include/ui.h index 131e902..d91abbb 100644 --- a/include/ui.h +++ b/include/ui.h @@ -146,3 +146,4 @@ void ui_set_stack(const char *mode); void ui_send_notification(const char *message); void ui_send_internal_notification(const char *message); void ui_close_internal_notification(void); +void ui_setup_glarea(); diff --git a/src/graphics/graphics.c b/src/graphics/graphics.c index 7f7dfa7..af77a1c 100644 --- a/src/graphics/graphics.c +++ b/src/graphics/graphics.c @@ -212,6 +212,7 @@ void graphics_draw(void) float v[16]; float p[16]; + /* Compute the model view projection matrix using the * rotation angles specified through the GtkRange widgets */ @@ -222,7 +223,7 @@ void graphics_draw(void) compute_i(m); compute_i(v); - glClearColor(0, 0, 0, 1); + glClearColor(0, 0, 0, 0); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); /* Use our shaders */ diff --git a/src/ui/gemgraph.ui b/src/ui/gemgraph.ui index 3ad5c9f..93bbd17 100644 --- a/src/ui/gemgraph.ui +++ b/src/ui/gemgraph.ui @@ -107,10 +107,16 @@ run - - center - <b>Main zone: run mode</b> - True + + vertical + + + + + + + + diff --git a/src/ui/window.c b/src/ui/window.c index 63a60d4..7bb3827 100644 --- a/src/ui/window.c +++ b/src/ui/window.c @@ -143,56 +143,6 @@ static void on_close_window(GtkWidget *widget) rotation_angles[Z_AXIS] = 0.0; } -void on_activate(GtkApplication *app, gpointer user_data) -{ - GtkWidget *window, *box, *button, *controls; - int i, minor=4, major=0; - - window = gtk_application_window_new(app); - gtk_window_set_default_size(GTK_WINDOW(window), 400, 600); - gtk_window_set_title(GTK_WINDOW(window), "GemGL (essais pour Gem-graph en OpenGL)"); - g_signal_connect(window, "destroy", G_CALLBACK(on_close_window), NULL); - - box = gtk_box_new(GTK_ORIENTATION_VERTICAL, FALSE); - gtk_widget_set_margin_start(box, 12); - gtk_widget_set_margin_end(box, 12); - gtk_widget_set_margin_top(box, 12); - gtk_widget_set_margin_bottom(box, 12); - gtk_box_set_spacing(GTK_BOX(box), 6); - gtk_window_set_child(GTK_WINDOW(window), box); - - gl_area = gtk_gl_area_new(); - gtk_gl_area_set_required_version( GTK_GL_AREA(gl_area), minor, major); - gtk_gl_area_get_required_version( GTK_GL_AREA(gl_area), &minor, &major); - gtk_widget_set_hexpand(gl_area, TRUE); - gtk_widget_set_vexpand(gl_area, TRUE); - gtk_widget_set_size_request(gl_area, 100, 200); - gtk_box_append(GTK_BOX(box), gl_area); - - // We need to initialize and free GL resources, so we use - // the realize and unrealize signals on the widget - // - g_signal_connect(gl_area, "realize", G_CALLBACK(on_realize), NULL); - g_signal_connect(gl_area, "unrealize", G_CALLBACK(on_unrealize), NULL); - - // The main "draw" call for GtkGLArea - g_signal_connect(gl_area, "render", G_CALLBACK(on_render), NULL); - - controls = gtk_box_new(GTK_ORIENTATION_VERTICAL, FALSE); - gtk_box_append(GTK_BOX(box), controls); - gtk_widget_set_hexpand(controls, TRUE); - - for(i = 0; i < N_AXIS; i++) - gtk_box_append(GTK_BOX(controls), create_axis_slider(i)); - - button = gtk_button_new_with_label("Fermer"); - gtk_widget_set_hexpand(button, TRUE); - gtk_box_append(GTK_BOX(box), button); - g_signal_connect_swapped(button, "clicked", G_CALLBACK(gtk_window_destroy), window); - - gtk_widget_show(window); -} - /* -------------------------------------------------------------------------- */ struct _GemGraphClientWindow @@ -209,6 +159,8 @@ struct _GemGraphClientWindow GtkRevealer *toast_revealer; GtkToggleButton *toast_close_button; GtkLabel *toast_text; + GtkGLArea *run_glarea; + GtkBox *run_controls; }; G_DEFINE_FINAL_TYPE (GemGraphClientWindow, @@ -257,6 +209,12 @@ static void gem_graph_client_window_class_init(GemGraphClientWindowClass *klass) gtk_widget_class_bind_template_child(widget_class, GemGraphClientWindow, toast_text); + gtk_widget_class_bind_template_child(widget_class, + GemGraphClientWindow, + run_glarea); + gtk_widget_class_bind_template_child(widget_class, + GemGraphClientWindow, + run_controls); } static void gem_graph_client_window_init(GemGraphClientWindow *self) @@ -264,6 +222,8 @@ static void gem_graph_client_window_init(GemGraphClientWindow *self) gtk_widget_init_template(GTK_WIDGET(self)); window = self; + + ui_setup_glarea(); } /* -------------------------------------------------------------------------- */ @@ -339,3 +299,41 @@ void ui_close_internal_notification(void) gtk_revealer_set_reveal_child(window->toast_revealer, false); } + +void ui_setup_glarea() +{ + int i, minor=4, major=0; + GtkWidget * controls; + gint height; + gint width; + + gl_area = GTK_WIDGET(window->run_glarea); + controls = GTK_WIDGET(window->run_controls); + gtk_widget_set_hexpand(gl_area, TRUE); + gtk_widget_set_vexpand(gl_area, TRUE); + gtk_widget_set_halign(gl_area, GTK_ALIGN_CENTER); + gtk_widget_set_valign(gl_area, GTK_ALIGN_CENTER); + + gtk_widget_set_size_request(gl_area, 500, 500); + + // We need to initialize and free GL resources, so we use + // the realize and unrealize signals on the widget + // + g_signal_connect(gl_area, "realize", G_CALLBACK(on_realize), NULL); + g_signal_connect(gl_area, "unrealize", G_CALLBACK(on_unrealize), NULL); + + // The main "draw" call for GtkGLArea + g_signal_connect(gl_area, "render", G_CALLBACK(on_render), NULL); + + gtk_widget_set_hexpand(controls, TRUE); + + for(i = 0; i < N_AXIS; i++) + gtk_box_append(GTK_BOX(controls), create_axis_slider(i)); + + gtk_gl_area_set_auto_render(window->run_glarea, true); + + gtk_widget_show(GTK_WIDGET(gl_area)); + gtk_gl_area_set_required_version( GTK_GL_AREA(gl_area), minor, major); + gtk_gl_area_get_required_version( GTK_GL_AREA(gl_area), &minor, &major); +} +